BuffManager.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. local DebugMediator = requireMediator("DebugMediator")
  2. local BuffManager = class("BuffManager", DebugMediator)
  3. BuffManager.NAME = "BuffManager"
  4. local cjson = require("cjson")
  5. local BuffEntityIce = require("buff/BuffEntityIce")
  6. local BuffEntityAnim = require("buff/BuffEntityAnim")
  7. local BuffEntityColor = require("buff/BuffEntityColor")
  8. local BuffEntityColors = require("buff/BuffEntityColors")
  9. local BuffEntityFreezed = require("buff/BuffEntityFreezed")
  10. local BuffEntityCloaking = require("buff/BuffEntityCloaking")
  11. local BuffEntityPoisonTransparent = require("buff/BuffEntityPoisonTransparent")
  12. local BuffEntityStoneMode = require("buff/BuffEntityStoneMode")
  13. local BuffEntityAvatar = require("buff/BuffEntityAvatar")
  14. local BuffEntitySneak = require("buff/BuffEntitySneak")
  15. local BuffEntityHorse = require("buff/BuffEntityHorse")
  16. local mmo = global.MMO
  17. local facade = global.Facade
  18. local noticeTable = global.NoticeTable
  19. function BuffManager:ctor()
  20. BuffManager.super.ctor(self, self.NAME)
  21. self._buffItems = {}
  22. self._handleOnMainActBegin = {} --潜行buff 需监听主玩家位置
  23. end
  24. function BuffManager:destory()
  25. if BuffManager.instance then
  26. global.Facade:removeMediator(BuffManager.NAME)
  27. BuffManager.instance = nil
  28. end
  29. end
  30. function BuffManager:Inst()
  31. if not BuffManager.instance then
  32. BuffManager.instance = BuffManager.new()
  33. global.Facade:registerMediator(BuffManager.instance)
  34. end
  35. return BuffManager.instance
  36. end
  37. function BuffManager:listNotificationInterests()
  38. return {
  39. noticeTable.AddBuffEntity,
  40. noticeTable.ActorBuffPresentUpdate,
  41. noticeTable.DropItemOutOfView,
  42. noticeTable.ActorOutOfView,
  43. noticeTable.RefreshActorHP,
  44. noticeTable.RefreshBuffVisible,
  45. noticeTable.MainPlayerActionBegan,
  46. }
  47. end
  48. function BuffManager:handleNotification(notification)
  49. local id = notification:getName()
  50. local data = notification:getBody()
  51. if noticeTable.AddBuffEntity == id then
  52. self:AddBuff(data)
  53. elseif noticeTable.ActorBuffPresentUpdate == id then
  54. self:OnActorBuffPresentUpdate(data)
  55. elseif noticeTable.DropItemOutOfView == id then
  56. self:OnDropItemOutOfView(data)
  57. elseif noticeTable.ActorOutOfView == id then
  58. self:OnActorOutOfView(data)
  59. elseif noticeTable.RefreshActorHP == id then
  60. self:OnRefreshActorHP(data)
  61. elseif noticeTable.RefreshBuffVisible == id then
  62. self:OnRefreshBuffVisible(data)
  63. elseif noticeTable.MainPlayerActionBegan == id then
  64. self:OnMainActBeginHanlder(data)
  65. end
  66. end
  67. function BuffManager:Tick(dt)
  68. local removed = {}
  69. for actorID, items in pairs(self._buffItems) do
  70. for buffID, item in pairs(items) do
  71. if item:IsInvalid() then
  72. table.insert(removed, { actorID = actorID, buffID = buffID })
  73. else
  74. item:Tick(dt)
  75. end
  76. end
  77. end
  78. for _, v in pairs(removed) do
  79. self:RmvBuff({ actorID = v.actorID, buffID = v.buffID })
  80. end
  81. end
  82. function BuffManager:CreateBuffItem(data)
  83. local actorID = data.actorID
  84. local buffID = data.buffID
  85. local item = nil
  86. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  87. if buffID == mmo.BUFF_ID_FREEZED_GRAY then
  88. item = BuffEntityFreezed.new(data)
  89. elseif buffID == mmo.BUFF_ID_CLOAKING then
  90. item = BuffEntityCloaking.new(data)
  91. elseif buffID == mmo.BUFF_ID_POISONING_RED then
  92. item = BuffEntityColor.new(data)
  93. elseif buffID == mmo.BUFF_ID_POISONING_GREEN then
  94. item = BuffEntityColor.new(data)
  95. elseif buffID == mmo.BUFF_ID_COLOR then
  96. item = BuffEntityColor.new(data)
  97. elseif buffID == mmo.BUFF_ID_ICE then
  98. item = BuffEntityIce.new(data)
  99. elseif buffID == mmo.BUFF_ID_COLORS then
  100. item = BuffEntityColors.new(data)
  101. elseif buffID == mmo.BUFF_ID_POISON_TRANSPARENT then
  102. item = BuffEntityPoisonTransparent.new(data)
  103. elseif buffID == mmo.BUFF_ID_STONE_MODE then
  104. item = BuffEntityStoneMode.new(data)
  105. elseif buffID == mmo.BUFF_ID_THUNDER_SWORD then
  106. item = BuffEntityColor.new(data)
  107. elseif buffID == mmo.BUFF_ID_SNEAK then
  108. item = BuffEntitySneak.new(data)
  109. elseif buffID == mmo.BUFF_ID_HORSE then
  110. item = BuffEntityHorse.new(data)
  111. elseif buffID == mmo.BUFF_ID_POISONING_PURPLE then
  112. item = BuffEntityColor.new(data)
  113. elseif BuffProxy:IsAvatarBuff(buffID) then
  114. item = BuffEntityAvatar.new(data)
  115. else
  116. item = BuffEntityAnim.new(data)
  117. end
  118. return item
  119. end
  120. --------------------------------------------------------
  121. function BuffManager:GetDataByUID(uid)
  122. local data = {}
  123. if self:IsEmpty(uid) then
  124. return data
  125. end
  126. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  127. local config = BuffProxy:GetConfig()
  128. local items = self:GetItemsByActorID(uid)
  129. for k, v in pairs(config) do
  130. if items[v.ID] and v.buffshow ~= 1 then
  131. local bdata = items[v.ID]:GetData()
  132. local endTime = items[v.ID]:GetEndTime()
  133. local ol = items[v.ID]:GetOl()
  134. table.insert(data, {id = v.ID, param = bdata.param, endTime = endTime, ol = ol})
  135. end
  136. end
  137. return data
  138. end
  139. function BuffManager:GetCountByUID(uid)
  140. local items = self:GetDataByUID(uid)
  141. return #items
  142. end
  143. --------------------------------------------------------
  144. --------------------------------------------------------
  145. local emptyT = {}
  146. function BuffManager:GetItemsByActorID(actorID, isAddEmpty)
  147. if not self._buffItems[actorID] then
  148. if isAddEmpty then
  149. self._buffItems[actorID] = {}
  150. else
  151. return emptyT
  152. end
  153. end
  154. return self._buffItems[actorID]
  155. end
  156. function BuffManager:GetItem(actorID, buffID)
  157. local items = self:GetItemsByActorID(actorID)
  158. return items[buffID]
  159. end
  160. function BuffManager:IsEmpty(actorID)
  161. return (not self._buffItems[actorID]) or (not next(self._buffItems[actorID]))
  162. end
  163. --------------------------------------------------------
  164. --------------------------------------------------------
  165. function BuffManager:CleanupByActorID(actorID)
  166. if (self:IsEmpty(actorID)) then
  167. return
  168. end
  169. local items = self:GetItemsByActorID(actorID)
  170. local removed = {}
  171. for _, item in pairs(items) do
  172. table.insert(removed, { actorID = item:GetActorID(), buffID = item:GetBuffID() })
  173. end
  174. for _, v in pairs(removed) do
  175. self:RmvBuff(v)
  176. end
  177. end
  178. function BuffManager:Cleanup()
  179. local removed = {}
  180. for _, items in pairs(self._buffItems) do
  181. for _, item in pairs(items) do
  182. table.insert(removed, item:GetActorID())
  183. end
  184. end
  185. for _, actorID in pairs(removed) do
  186. self:CleanupByActorID(actorID)
  187. end
  188. self._buffItems = {}
  189. self._handleOnMainActBegin = {}
  190. end
  191. --------------------------------------------------------
  192. --------------------------------------------------------
  193. function BuffManager:AddBuff(data)
  194. -- print("buff began, actorID: " .. data.actorID .. " buffID:" .. data.buffID)
  195. local actorID = data.actorID
  196. local buffID = data.buffID
  197. local param = data.param
  198. local ol = data.ol
  199. local actor = global.actorManager:GetActor(actorID)
  200. if not actor then
  201. return nil
  202. end
  203. -- empty
  204. if self:IsEmpty(actorID) then
  205. self._buffItems[actorID] = {}
  206. end
  207. -- exist, update it
  208. if self:GetItem(actorID, buffID) then
  209. self:UpdateBuff(data)
  210. return
  211. end
  212. local items = self:GetItemsByActorID(actorID, true)
  213. local item = self:CreateBuffItem(data)
  214. items[buffID] = item
  215. item:OnEnter()
  216. -- 主玩家Buff同步
  217. if actorID == global.gamePlayerController:GetMainPlayerID() then
  218. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  219. BuffProxy:AddBuffItem({ id = buffID, param = param, ol = ol })
  220. ssr.ssrBridge:OnMainPlayerBuffChange()
  221. SLBridge:onLUAEvent(LUA_EVENT_MAINBUFFUPDATE, { actorID = actorID, buffID = buffID, type = 1 })
  222. end
  223. -- 主玩家英雄buff提示
  224. if actor:IsHero() and actor:GetMasterID() == global.gamePlayerController:GetMainPlayerID() and data.isInit ~= true then
  225. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  226. BuffProxy:AddBuffItem({ id = buffID, param = param, ol = ol }, true)
  227. end
  228. -- notice
  229. global.Facade:sendNotification(global.NoticeTable.BuffEntitiesChange, { actorID = actorID })
  230. SLBridge:onLUAEvent(LUA_EVENT_BUFFUPDATE, { actorID = actorID, buffID = buffID, type = 1 })
  231. return true
  232. end
  233. function BuffManager:UpdateBuff(data)
  234. local actorID = data.actorID
  235. local buffID = data.buffID
  236. local param = data.param
  237. local ol = data.ol -- buff 层级
  238. if (self:IsEmpty(actorID)) then
  239. return false
  240. end
  241. local item = self:GetItem(actorID, buffID)
  242. if item then
  243. item:UpdateParam(param)
  244. item:UpdateOl(ol)
  245. item:UpdatePresent()
  246. end
  247. -- 主玩家Buff同步
  248. if actorID == global.gamePlayerController:GetMainPlayerID() then
  249. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  250. BuffProxy:UpdateBuffItem({ id = buffID, param = param, ol = ol })
  251. ssr.ssrBridge:OnMainPlayerBuffChange()
  252. SLBridge:onLUAEvent(LUA_EVENT_MAINBUFFUPDATE, { actorID = actorID, buffID = buffID, type = 2 })
  253. end
  254. -- notice
  255. global.Facade:sendNotification(global.NoticeTable.BuffEntitiesChange, { actorID = actorID })
  256. SLBridge:onLUAEvent(LUA_EVENT_BUFFUPDATE, { actorID = actorID, buffID = buffID, type = 2 })
  257. end
  258. function BuffManager:RmvBuff(data)
  259. -- print("buff ended, actorID: " .. data.actorID .. " buffID:" .. data.buffID)
  260. local actorID = data.actorID
  261. local buffID = data.buffID
  262. -- not exist
  263. if (self:IsEmpty(actorID)) then
  264. return false
  265. end
  266. -- do exist & delete it
  267. local items = self:GetItemsByActorID(actorID)
  268. local item = items[buffID]
  269. if item then
  270. items[buffID] = nil
  271. item:OnExit()
  272. end
  273. if self:IsEmpty(actorID) then
  274. self._buffItems[actorID] = nil
  275. end
  276. -- 主玩家Buff同步
  277. if actorID == global.gamePlayerController:GetMainPlayerID() then
  278. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  279. BuffProxy:RmvBuffItem({ id = buffID })
  280. ssr.ssrBridge:OnMainPlayerBuffChange()
  281. SLBridge:onLUAEvent(LUA_EVENT_MAINBUFFUPDATE, { actorID = actorID, buffID = buffID, type = 0 })
  282. end
  283. -- notice
  284. global.Facade:sendNotification(global.NoticeTable.BuffEntitiesChange, { actorID = actorID })
  285. SLBridge:onLUAEvent(LUA_EVENT_BUFFUPDATE, { actorID = actorID, buffID = buffID, type = 0 })
  286. return true
  287. end
  288. --------------------------------------------------------
  289. --------------------------------------------------------
  290. function BuffManager:handleBuffInit(msgHdr, msgData)
  291. if msgData == "" then
  292. return nil
  293. end
  294. fixNetMsgHeader(msgHdr)
  295. local jsonData = cjson.decode(msgData)
  296. if not jsonData or not jsonData.UserID or not jsonData.buff then
  297. return nil
  298. end
  299. local actorID = jsonData.UserID
  300. local items = {}
  301. if not self:IsEmpty(actorID) then
  302. items = self:GetItemsByActorID(actorID)
  303. end
  304. if #jsonData.buff == 0 and not next(items) then
  305. return nil
  306. end
  307. local buffData = jsonData.buff
  308. local added = {}
  309. local removed = {}
  310. local changed = {}
  311. -- check added & changed
  312. for _, v in pairs(buffData) do
  313. if v.param and tonumber(v.param) then
  314. v.param = fixMinusNumber(tonumber(v.param))
  315. end
  316. if (not items[v.id]) then
  317. added[v.id] = v
  318. else
  319. changed[v.id] = v
  320. end
  321. end
  322. -- custom buff
  323. local customBuff = {
  324. [mmo.BUFF_ID_HORSE] = mmo.BUFF_ID_HORSE
  325. }
  326. -- check removed
  327. local tmp = {}
  328. for _, v in pairs(buffData) do
  329. tmp[v.id] = 1
  330. end
  331. for _, v in pairs(items) do
  332. if not tmp[v:GetBuffID()] and not customBuff[v:GetBuffID()] then
  333. table.insert(removed, v:GetBuffID())
  334. end
  335. end
  336. for _, v in pairs(changed) do
  337. self:AddBuff({ actorID = actorID, buffID = v.id, param = v.param, ol = v.ol, replaceId = v.p1, isInit = true })
  338. end
  339. for _, v in pairs(added) do
  340. self:AddBuff({ actorID = actorID, buffID = v.id, param = v.param, ol = v.ol, replaceId = v.p1, isInit = true })
  341. end
  342. for _, v in pairs(removed) do
  343. self:RmvBuff({ actorID = actorID, buffID = v })
  344. end
  345. end
  346. function BuffManager:handleBuffAdd(msgHdr, msgData)
  347. if "" == msgData then
  348. return nil
  349. end
  350. fixNetMsgHeader(msgHdr)
  351. local buffID = msgHdr.recog
  352. local param = msgHdr.param1
  353. local userId = msgData
  354. local ol = msgHdr.param2
  355. local replaceId = msgHdr.param3 --替换buffid特效 魔法盾需要显示其它的特效
  356. -- 新增/更新
  357. self:AddBuff({actorID = userId, buffID = buffID, param = param, ol = ol, replaceId = replaceId})
  358. --
  359. -- print("----------------------BUFF add", buffID, param, userId)
  360. end
  361. function BuffManager:handleBuffRmv(msgHdr, msgData)
  362. if "" == msgData then
  363. return nil
  364. end
  365. local buffID = msgHdr.recog
  366. local userId = msgData
  367. --
  368. self:RmvBuff({ actorID = userId, buffID = buffID })
  369. --
  370. -- print("----------------------BUFF rmv", buffID, userId)
  371. end
  372. --------------------------------------------------------
  373. --------------------------------------------------------
  374. function BuffManager:OnActorBuffPresentUpdate(actorID)
  375. -- 更新buff表现,外观改变需要更新buff表现....
  376. if self:IsEmpty(actorID) then
  377. return
  378. end
  379. local items = self:GetItemsByActorID(actorID)
  380. for _, v in pairs(items) do
  381. v:UpdatePresent()
  382. end
  383. end
  384. function BuffManager:UpdateBuffSfxDir(actorID)
  385. if self:IsEmpty(actorID) then
  386. return
  387. end
  388. local items = self:GetItemsByActorID(actorID)
  389. for _, v in pairs(items) do
  390. v:UpdateSfxDir()
  391. end
  392. end
  393. function BuffManager:setPosition(actorID, x, y)
  394. -- 更新buff表现,外观改变需要更新buff表现....
  395. if self:IsEmpty(actorID) then
  396. return
  397. end
  398. local offx, offy = 0,0
  399. local items = self:GetItemsByActorID(actorID)
  400. for _, v in pairs(items) do
  401. if GUIFunction.GetBuffAvatarSacleOffset then
  402. offx, offy = GUIFunction:GetBuffAvatarSacleOffset(actorID, v:GetBuffID())
  403. end
  404. v:setPosition(x + offx, y + offy)
  405. end
  406. end
  407. function BuffManager:OnRefreshActorHP(data)
  408. if not data.isDamage then
  409. return
  410. end
  411. if self:IsEmpty(data.actorID) then
  412. return
  413. end
  414. local items = self:GetItemsByActorID(data.actorID)
  415. for _, v in pairs(items) do
  416. v:OnActorStuck()
  417. end
  418. end
  419. function BuffManager:OnDropItemOutOfView(data)
  420. self:CleanupByActorID(data.actorID)
  421. end
  422. function BuffManager:OnActorOutOfView(data)
  423. self:CleanupByActorID(data.actorID)
  424. end
  425. function BuffManager:OnRefreshBuffVisible(data)
  426. if data and (data:IsDeath() or data:IsDie()) then
  427. local isHide = tonumber(SL:GetMetaValue("GAME_DATA", "MonsterDieHideAnim")) == 1
  428. if isHide then
  429. self:UpdateBuffItemVisible(data:GetID(), not isHide)
  430. end
  431. end
  432. end
  433. --------------------------------------------------------
  434. function BuffManager:IsAllowAnimUpdate(actorID)
  435. if self:IsEmpty(actorID) then
  436. return true
  437. end
  438. local items = self:GetItemsByActorID(actorID)
  439. for _, v in pairs(items) do
  440. if not v:IsAllowAnimUpdate() then
  441. return false
  442. end
  443. end
  444. return true
  445. end
  446. -- 是否中毒
  447. function BuffManager:IsPoisoning(actorID)
  448. if self:IsEmpty(actorID) then
  449. return false
  450. end
  451. local items = self:GetItemsByActorID(actorID)
  452. for _, v in pairs(items) do
  453. if v:GetBuffID() == mmo.BUFF_ID_POISONING_RED or v:GetBuffID() == mmo.BUFF_ID_POISONING_GREEN then
  454. return true
  455. end
  456. end
  457. return false
  458. end
  459. -- 是否中红毒
  460. function BuffManager:IsPoisoningRed(actorID)
  461. return self:IsHaveOneBuff(actorID, mmo.BUFF_ID_POISONING_RED)
  462. end
  463. -- 是否中绿毒
  464. function BuffManager:IsPoisoningGreen(actorID)
  465. return self:IsHaveOneBuff(actorID, mmo.BUFF_ID_POISONING_GREEN)
  466. end
  467. -- 是否有护盾
  468. function BuffManager:IsHaveShield(actorID)
  469. return self:IsHaveOneBuff(actorID, mmo.BUFF_ID_MAGIC_SHIELD)
  470. end
  471. -- 是否麻痹
  472. function BuffManager:IsFreezed(actorID)
  473. return self:IsHaveOneBuff(actorID, mmo.BUFF_ID_FREEZED_GRAY)
  474. end
  475. -- 神圣战甲术
  476. function BuffManager:IsHaveAngelShield(actorID)
  477. return self:IsHaveOneBuff(actorID, mmo.BUFF_ID_ANGEL_SHIELD)
  478. end
  479. -- 是否有幽灵盾
  480. function BuffManager:IsHaveGhostShield(actorID)
  481. return self:IsHaveOneBuff(actorID, mmo.BUFF_ID_GHOST_SHIELD)
  482. end
  483. -- 是否某个buff
  484. function BuffManager:IsHaveOneBuff(actorID, buffID)
  485. if self:IsEmpty(actorID) then
  486. return false
  487. end
  488. local items = self:GetItemsByActorID(actorID)
  489. for _, v in pairs(items) do
  490. if v:GetBuffID() == buffID then
  491. return true
  492. end
  493. end
  494. return false
  495. end
  496. -- 自动释放该技能是否有该buff
  497. function BuffManager:CheckAutoBuffBySkillID(actorID, skillID)
  498. if self:IsEmpty(actorID) then
  499. return false
  500. end
  501. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  502. local skillBuff = BuffProxy:GetNoSkillAuto( skillID )
  503. if not skillBuff then
  504. return false
  505. end
  506. local items = self:GetItemsByActorID(actorID)
  507. for _, v in pairs(items) do
  508. local buffID = v:GetBuffID()
  509. if skillBuff[buffID] then
  510. return buffID
  511. end
  512. end
  513. return false
  514. end
  515. -- 释放该技能是否有该buff
  516. function BuffManager:CheckLaunchBuffBySkillID(actorID, skillID)
  517. if self:IsEmpty(actorID) then
  518. return false
  519. end
  520. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  521. local skillBuff = BuffProxy:GetNoSkillLaunch( skillID )
  522. if not skillBuff then
  523. return false
  524. end
  525. local items = self:GetItemsByActorID(actorID)
  526. for _, v in pairs(items) do
  527. local buffID = v:GetBuffID()
  528. if skillBuff[buffID] then
  529. return buffID
  530. end
  531. end
  532. return false
  533. end
  534. function BuffManager:IsInColorBuff(actorID)
  535. -- 是否在变色buff
  536. if self:IsEmpty(actorID) then
  537. return false
  538. end
  539. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  540. local items = self:GetItemsByActorID(actorID)
  541. for _, v in pairs(items) do
  542. if v:GetBuffID() == mmo.BUFF_ID_FREEZED_GRAY then
  543. -- 麻痹
  544. return true
  545. elseif v:GetBuffID() == mmo.BUFF_ID_POISONING_RED then
  546. -- 红毒
  547. return true
  548. elseif v:GetBuffID() == mmo.BUFF_ID_POISONING_GREEN then
  549. -- 绿毒
  550. return true
  551. elseif v:GetBuffID() == mmo.BUFF_ID_COLORS then
  552. -- 换色
  553. return true
  554. elseif v:GetBuffID() == mmo.BUFF_ID_COLOR then
  555. -- 变色
  556. return true
  557. elseif v:GetBuffID() == mmo.BUFF_ID_THUNDER_SWORD then
  558. -- 雷霆
  559. return true
  560. elseif v:GetBuffID() == mmo.BUFF_ID_ICE then
  561. -- 冰冻
  562. return true
  563. elseif v:GetBuffID() == mmo.BUFF_ID_POISONING_PURPLE then
  564. -- 紫毒
  565. return true
  566. elseif BuffProxy:GetBuffColorByID(v:GetBuffID()) then
  567. -- buff表配置了颜色
  568. return true
  569. end
  570. end
  571. return false
  572. end
  573. local ignoreBuffMap = {
  574. [mmo.BUFF_ID_POISON_TRANSPARENT] = true,
  575. [mmo.BUFF_ID_STONE_MODE] = true,
  576. [mmo.BUFF_ID_SNEAK] = true,
  577. }
  578. local ColorCache = {}
  579. -- changeColorID: 循环变色buff 当前颜色ID
  580. function BuffManager:CheckBuffColor(actorID, changeColorID)
  581. -- 是否某个buff
  582. local color = cc.c3b(255, 255, 255)
  583. if self:IsEmpty(actorID) then
  584. return color
  585. end
  586. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  587. local items = self:GetItemsByActorID(actorID)
  588. local buffColorList = {}
  589. for _, v in pairs(items) do
  590. local buffColorOrder = BuffProxy:GetBuffColorOrderByID(v:GetBuffID())
  591. if v:GetBuffID() == mmo.BUFF_ID_COLOR then
  592. if not ColorCache[v:GetParam()] then
  593. ColorCache[v:GetParam()] = GET_COLOR_BYID_C3B(v:GetParam())
  594. end
  595. local buffColor = ColorCache[v:GetParam()]
  596. table.insert(buffColorList, {color = buffColor, colorOrder = buffColorOrder})
  597. elseif v:GetBuffID() == mmo.BUFF_ID_COLORS and changeColorID then
  598. if not ColorCache[changeColorID] then
  599. ColorCache[changeColorID] = GET_COLOR_BYID_C3B(changeColorID)
  600. end
  601. local buffColor = ColorCache[changeColorID]
  602. table.insert(buffColorList, {color = buffColor, colorOrder = buffColorOrder})
  603. elseif not ignoreBuffMap[v:GetBuffID()] then
  604. local buffColor = BuffProxy:GetBuffColorByID(v:GetBuffID())
  605. if buffColor then
  606. table.insert(buffColorList, {color = buffColor, colorOrder = buffColorOrder})
  607. end
  608. end
  609. end
  610. table.sort(buffColorList, function(a, b)
  611. return a.colorOrder > b.colorOrder
  612. end)
  613. if buffColorList and buffColorList[1] and buffColorList[1].color then
  614. color = buffColorList[1].color
  615. end
  616. return color
  617. end
  618. -- 通过buff id获取buff color
  619. function BuffManager:CheckBuffColorByID(actorID, buffID)
  620. if not self:IsHaveOneBuff(buffID) then
  621. return self:CheckBuffColor(actorID)
  622. end
  623. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  624. local buffColor = BuffProxy:GetBuffColorByID(v:GetBuffID())
  625. if buffColor then
  626. return buffColor
  627. end
  628. return self:CheckBuffColor(actorID)
  629. end
  630. function BuffManager:CheckBuffAvatar(actorID, buffID)
  631. -- 是否某个buff
  632. if self:IsEmpty(actorID) then
  633. return nil
  634. end
  635. -- 骑马
  636. local actor = global.actorManager:GetActor(actorID)
  637. if actor and actor:IsPlayer() and (actor:GetHorseMasterID() or actor:IsHoreseCopilot()) then
  638. return {
  639. avatarType = 1,
  640. avatarID = actor:GetMonsterFeatureID()
  641. }
  642. end
  643. local ret = nil
  644. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  645. local items = self:GetItemsByActorID(actorID)
  646. for _, v in pairs(items) do
  647. local avatar = BuffProxy:GetBuffAvatarByID(v:GetBuffID())
  648. if avatar then
  649. ret = avatar
  650. end
  651. if v:GetBuffID() == buffID then
  652. break
  653. end
  654. end
  655. return ret
  656. end
  657. function BuffManager:CheckBuffScale(actorID, buffID)
  658. -- 是否没有buff
  659. if self:IsEmpty(actorID) then
  660. return 1
  661. end
  662. local ret = 1
  663. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  664. local items = self:GetItemsByActorID(actorID)
  665. for _, v in pairs(items) do
  666. local scale = BuffProxy:GetBuffScaleByID(v:GetBuffID())
  667. if scale then
  668. ret = scale
  669. end
  670. if v:GetBuffID() == buffID then
  671. break
  672. end
  673. end
  674. return ret
  675. end
  676. -- 检测变形类型是否要删除,人物 -> 怪物 / 怪物 -> 人物是时需要
  677. function BuffManager:CheckRmvBuffAvatar(actorID, avatar)
  678. if not actorID then
  679. return false
  680. end
  681. local actor = global.actorManager:GetActor(actorID)
  682. if not actor then
  683. return false
  684. end
  685. if not avatar then
  686. avatar = {}
  687. end
  688. local sex = nil
  689. if avatar.avatarType == 0 then
  690. sex = avatar.avatarSex or actor:GetSexID()
  691. end
  692. local oldSex = actor:GetValueByKey(global.MMO.BUFF_PLAYER_AVATAR_SEX)
  693. actor:SetKeyValue( global.MMO.BUFF_PLAYER_AVATAR_SEX,sex )
  694. if (not oldSex and sex) or (not sex and oldSex) then
  695. return true
  696. end
  697. return false
  698. end
  699. function BuffManager:AddHandleOnMainActBegin(actorid,func)
  700. if not actorid then
  701. return
  702. end
  703. self._handleOnMainActBegin[actorid] = func
  704. end
  705. function BuffManager:RemoveHandleOnMainActBegin(actorid,func)
  706. if not actorid then
  707. return
  708. end
  709. self._handleOnMainActBegin[actorid] = nil
  710. end
  711. function BuffManager:OnMainActBeginHanlder(act)
  712. for k,v in pairs(self._handleOnMainActBegin) do
  713. v(act)
  714. end
  715. end
  716. function BuffManager:UpdateBuffItemVisible(actorID, allVisible)
  717. if allVisible == nil then
  718. -- 检测是不是副驾的玩家 副驾玩家的buff特效都不显示出来
  719. allVisible = true
  720. local actor = global.actorManager:GetActor(actorID)
  721. if actor and actor:IsPlayer() and actor:IsHoreseCopilot() then
  722. allVisible = false
  723. end
  724. end
  725. local visible = allVisible == true
  726. local items = self:GetItemsByActorID(actorID)
  727. for _, _item in pairs(items) do
  728. _item:setVisible(visible)
  729. _item:updatePosition()
  730. end
  731. end
  732. function BuffManager.OnUnloaded()
  733. BuffManager.super.OnUnloaded()
  734. global.BuffManager = nil
  735. global.Facade:removeMediator(BuffManager.NAME)
  736. end
  737. function BuffManager.Onloaded()
  738. BuffManager.super.Onloaded()
  739. local mediator = BuffManager.new()
  740. global.Facade:registerMediator(mediator)
  741. global.BuffManager = mediator
  742. end
  743. return BuffManager