gameActorMonsterGate.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. local gameActorMonster = require("actor/gameActorMonster")
  2. local gameActorMonsterGate = class('gameActorMonsterGate', gameActorMonster)
  3. local optionsUtils = requireProxy("optionsUtils")
  4. function gameActorMonsterGate:ctor()
  5. self.mOpenState = false
  6. gameActorMonsterGate.super.ctor(self)
  7. end
  8. function gameActorMonsterGate:init()
  9. gameActorMonsterGate.super.init(self)
  10. self.mOpenState = false
  11. end
  12. function gameActorMonsterGate:SetAnimAct(newAnim)
  13. if self.mAnimAct ~= newAnim then
  14. self.mAnimAct = newAnim
  15. -- in die anim, zOrder is lowest
  16. if newAnim == global.MMO.ANIM_DIE then
  17. self:GetNode():setLocalZOrder(-self:GetNode():getPositionY() + self:GetAdditionZorder() + global.MMO.DieAddZorder)
  18. end
  19. self:dirtyAnimFlag()
  20. end
  21. end
  22. function gameActorMonsterGate:convertAnimAct(anim)
  23. if anim == global.MMO.ANIM_IDLE then
  24. if self:getGateOpenState() then
  25. return global.MMO.ANIM_BORN
  26. end
  27. return global.MMO.ANIM_STUCK
  28. end
  29. return anim
  30. end
  31. --动画的方向
  32. function gameActorMonsterGate:getAnimDir()
  33. if self.mAction == global.MMO.ACTION_BORN then
  34. if self:getGateOpenState() then
  35. return 0
  36. else
  37. return 1
  38. end
  39. elseif self.mAction == global.MMO.ACTION_DIE then
  40. return 0
  41. elseif self.mAction == global.MMO.ACTION_IDLE and self:getGateOpenState() then
  42. return 0
  43. end
  44. local percent = self:GetHP() / self:GetMaxHP()
  45. if percent >= 0.5 then
  46. return 0
  47. else
  48. return 1
  49. end
  50. return 0
  51. end
  52. --城门打开状态
  53. function gameActorMonsterGate:setGateOpenState(state)
  54. self.mOpenState = state
  55. global.sceneManager:changeGateState(self:GetMapX(), self:GetMapY(), false)
  56. end
  57. function gameActorMonsterGate:getGateOpenState()
  58. return self.mOpenState
  59. end
  60. function gameActorMonsterGate:StopAllAnimation(frameIndex)
  61. local animAct = self:convertAnimAct(self.mAnimAct)
  62. local animDir = self:getAnimDir()
  63. if self.mAnimation then
  64. self.mAnimation:Stop(frameIndex, animAct, animDir)
  65. end
  66. if self.mAttachAnim then
  67. self.mAttachAnim:Stop(frameIndex, animAct, animDir)
  68. end
  69. end
  70. function gameActorMonsterGate:updateAnimation()
  71. -- speed
  72. local isLoop = false
  73. local speed = 1
  74. local animAct = self:convertAnimAct(self.mAnimAct)
  75. local animDir = self:getAnimDir()
  76. if self.mAnimation then
  77. self.mAnimation:Play(animAct, animDir, isLoop, speed)
  78. end
  79. if self.mAttachAnim then
  80. self.mAttachAnim:Play(animAct, animDir, isLoop, speed)
  81. end
  82. if self.mStopAnimFrameIndex then
  83. self:StopAllAnimation(self.mStopAnimFrameIndex)
  84. elseif self.mAction == global.MMO.ACTION_IDLE then
  85. if self:getGateOpenState() then
  86. self:StopAllAnimation(-1)
  87. else
  88. self:StopAllAnimation(1)
  89. end
  90. end
  91. if self.mAction == global.MMO.ACTION_DIE then
  92. global.sceneManager:changeGateState(self:GetMapX(), self:GetMapY(), true)
  93. end
  94. end
  95. return gameActorMonsterGate