RefreshActorHPCommand.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. local RefreshActorHPCommand = class('RefreshActorHPCommand', framework.SimpleCommand)
  2. function RefreshActorHPCommand:ctor()
  3. end
  4. function RefreshActorHPCommand:execute(notification)
  5. local data = notification:getBody()
  6. local actorID = data.actorID
  7. local isDamage = data.isDamage
  8. local HP = data.HP
  9. local MP = data.MP
  10. local maxHP = data.maxHP
  11. local maxMP = data.maxMP
  12. local unAattack = data.unAattack -- 受到攻击
  13. local level = data.level or 0
  14. local actor = global.actorManager:GetActor(actorID)
  15. if not actor then
  16. return false
  17. end
  18. if not (actor:IsPlayer() or actor:IsMonster()) then
  19. return false
  20. end
  21. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  22. local HeroPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  23. local HeroID = HeroPropertyProxy:GetRoleUID()
  24. if mainPlayerID == actorID then
  25. local propertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  26. propertyProxy:SetRoleMana(HP, maxHP, MP, maxMP)
  27. if isDamage then
  28. global.Facade:sendNotification(global.NoticeTable.PlayerBeDamaged)
  29. end
  30. elseif HeroID == actorID then
  31. HeroPropertyProxy:SetRoleMana(HP, maxHP, MP, maxMP)
  32. if isDamage then
  33. global.Facade:sendNotification(global.NoticeTable.HeroBeDamaged)
  34. end
  35. end
  36. if actor.SetDamage and unAattack then
  37. actor:SetDamage(unAattack)
  38. --设置护身状态
  39. local huShen = data.huShen
  40. if huShen and actor.SetHuShen then
  41. local lastStatus = actor:IsHuShen()
  42. actor:SetHuShen(huShen)
  43. if lastStatus ~= actor:IsHuShen() then
  44. if global.gamePlayerController:GetMainPlayerID() == actor:GetID() then
  45. SL:onLUAEvent(LUA_EVENT_PLAYER_HUSHEN_STATUS_CHANGE)
  46. else
  47. SL:onLUAEvent(LUA_EVENT_NET_PLAYER_HUSHEN_STATUS_CHANGE, {id = actor:GetID()})
  48. end
  49. end
  50. end
  51. end
  52. local lastLevel = actor:GetLevel()
  53. if level > 0 and level ~= lastLevel then
  54. actor:SetLevel(level)
  55. end
  56. if actor:IsPlayer() then
  57. actor:SetShieldHUD(MP, maxMP)
  58. end
  59. actor:SetHPHUD(HP, maxHP)
  60. end
  61. return RefreshActorHPCommand