gameActorDropItem.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. local gameActor = require("actor/gameActor")
  2. local gameActorDropItem = class('gameActorDropItem', gameActor)
  3. function gameActorDropItem:ctor()
  4. gameActorDropItem.super.ctor(self)
  5. end
  6. function gameActorDropItem:init()
  7. gameActorDropItem.super.init(self)
  8. self.mFeatureDirty = false
  9. self.mCurrActorSprite = nil
  10. self.mOwnerID = global.MMO.ACTOR_ID_INVALID
  11. self.mOwnerName = ""
  12. self.mPickState = 0
  13. self.mPickTimeout = false
  14. self.mPickBornStamp = nil
  15. self.mMakeIndex = 0
  16. self.mClothID = nil
  17. self.mDropShake = nil
  18. end
  19. function gameActorDropItem:destory()
  20. gameActorDropItem.super.destory(self)
  21. -- remove hud
  22. global.HUDManager:RemoveActorAllHUD(self.mID)
  23. end
  24. function gameActorDropItem:Tick(dt)
  25. gameActorDropItem.super.Tick(self, dt)
  26. if self.mFeatureDirty then
  27. self.mFeatureDirty = false
  28. self:checkFeature()
  29. end
  30. end
  31. function gameActorDropItem:setPosition(x, y)
  32. gameActorDropItem.super.setPosition(self, x, y)
  33. -- update hud pos
  34. global.HUDManager:setPosition(self.mID, x, y + global.MMO.HUD_DROPITEM_OFFSET_Y)
  35. -- update buff pos
  36. global.BuffManager:setPosition(self:GetID(), x, y)
  37. global.ActorEffectManager:setPosition(self:GetID(), x, y)
  38. end
  39. function gameActorDropItem:InitParam(param)
  40. self.mCurrActorNode = cc.Node:create()
  41. self.mClothID = tonumber(param.cloth) or 1
  42. -- set zOrder by clothID
  43. self:GetNode():setLocalZOrder(self.mClothID)
  44. self.mCurrMountNode = cc.Node:create()
  45. self.mCurrActorNode:addChild(self.mCurrMountNode)
  46. self.mCurrMountNode:setTag(global.MMO.DROP_MOUNT_TAG)
  47. -- Store owner id
  48. self.mOwnerID = param.ownerID
  49. return 1
  50. end
  51. function gameActorDropItem:dirtyFeature()
  52. self.mFeatureDirty = true
  53. end
  54. function gameActorDropItem:checkFeature()
  55. self:updateActorSprite()
  56. end
  57. function gameActorDropItem:updateActorSprite()
  58. if self.mCurrActorSprite then
  59. self.mCurrActorSprite:removeFromParent()
  60. self.mCurrActorSprite = nil
  61. end
  62. local groundFile = global.dropItemController:GetItemGroundFile(self.mClothID)
  63. local dropItemTexc = ccui.ImageView:create(groundFile)
  64. local itemScale = SL:GetMetaValue("GAME_DATA","itemGroundSacle") or (global.isWinPlayMode and 0.5 or 0.8)
  65. if nil == dropItemTexc then
  66. groundFile = "res/item/un_define.pvr.ccz"
  67. dropItemTexc = ccui.ImageView:create(groundFile)
  68. print("Failed to load drop item avatar:" .. groundFile .. "\n")
  69. end
  70. self.mCurrActorSprite = dropItemTexc
  71. self.mCurrActorSprite:setScale(itemScale)
  72. self.mCurrActorSprite.GetBoundingBox = self.mCurrActorSprite.getBoundingBox
  73. self.mCurrActorNode:addChild(self.mCurrActorSprite)
  74. -- 掉落动画
  75. if (self:GetDropShake() == 1 and (tonumber(SL:GetMetaValue("GAME_DATA", "NoShowItemDropEff"))) ~= 1) then
  76. local actorPos = self:getPosition()
  77. local interval = 1 / 30
  78. local max = 50
  79. local distance = max
  80. local count = 2
  81. local action = nil
  82. local speed = 1
  83. local flag = 1
  84. self:setPosition(actorPos.x, actorPos.y + distance)
  85. action = schedule(self.mCurrActorNode, function()
  86. speed = speed + 1
  87. distance = distance - flag * max * interval * (3 + speed * interval)
  88. self:setPosition(actorPos.x, actorPos.y + distance)
  89. if count == 2 then
  90. if distance <= 0 then
  91. count = count - 1
  92. max = max / 2
  93. distance = 0
  94. flag = -1
  95. speed = 60
  96. end
  97. elseif count == 1 then
  98. if distance >= max then
  99. count = count - 1
  100. distance = max
  101. speed = 30
  102. flag = 1
  103. end
  104. else
  105. if distance <= 0 then
  106. self:setPosition(actorPos.x, actorPos.y)
  107. self.mCurrActorNode:stopActionByTag(689)
  108. end
  109. end
  110. end, interval)
  111. action:setTag(689)
  112. end
  113. end
  114. --获取animation,其实是Sprite,用于检测鼠标经过
  115. function gameActorDropItem:GetAnimation()
  116. return self.mCurrActorSprite
  117. end
  118. function gameActorDropItem:GetType()
  119. return global.MMO.ACTOR_DROPITEM
  120. end
  121. function gameActorDropItem:SetMakeIndex(MakeIndex)
  122. self.mMakeIndex = MakeIndex
  123. end
  124. function gameActorDropItem:GetMakeIndex()
  125. return self.mMakeIndex
  126. end
  127. function gameActorDropItem:SetName(name)
  128. self.mName = name or ""
  129. end
  130. function gameActorDropItem:SetOwnerName(name)
  131. self.mOwnerName = name or ""
  132. end
  133. function gameActorDropItem:GetOwnerName()
  134. return self.mOwnerName
  135. end
  136. function gameActorDropItem:GetOwnerID()
  137. return self.mOwnerID
  138. end
  139. function gameActorDropItem:CheckOwnerID(id)
  140. return "0" == self.mOwnerID or nil == self.mOwnerID or id == self.mOwnerID
  141. end
  142. function gameActorDropItem:ResetPickState()
  143. self.mPickState = 0
  144. end
  145. function gameActorDropItem:GetPickState()
  146. return self.mPickState
  147. end
  148. function gameActorDropItem:PickStateMark()
  149. self.mPickState = self.mPickState + 1
  150. end
  151. function gameActorDropItem:ResetPickTimeout()
  152. self.mPickTimeout = false
  153. end
  154. function gameActorDropItem:IsPickTimeout()
  155. return self.mPickTimeout
  156. end
  157. function gameActorDropItem:SetPickTimeout()
  158. self.mPickTimeout = true
  159. end
  160. function gameActorDropItem:SetBornStamp(time)
  161. self.mPickBornStamp = time
  162. end
  163. function gameActorDropItem:GetBornStamp()
  164. return self.mPickBornStamp
  165. end
  166. function gameActorDropItem:IsPickEnable()
  167. if nil == self.mPickBornStamp then
  168. return true
  169. end
  170. -- 2sec pick CD
  171. if GetServerTime() - self.mPickBornStamp >= 2 then
  172. return true
  173. end
  174. return false
  175. end
  176. function gameActorDropItem:SetDropShake(v)
  177. self.mDropShake = v
  178. end
  179. function gameActorDropItem:GetDropShake()
  180. return self.mDropShake
  181. end
  182. return gameActorDropItem