PickupSpriteProxy.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local PickupSpriteProxy = class("PickupSpriteProxy", RemoteProxy)
  3. PickupSpriteProxy.NAME = global.ProxyTable.PickupSpriteProxy
  4. local cjson = require("cjson")
  5. function PickupSpriteProxy:ctor()
  6. PickupSpriteProxy.super.ctor(self)
  7. self._tickTime = 0
  8. self._mainID = 0
  9. self._uiID = 0
  10. self._metaPos = nil
  11. end
  12. function PickupSpriteProxy:setMetaPositon(x, y)
  13. x = x or 0
  14. y = y or 0
  15. self._metaPos = cc.p(x, y)
  16. end
  17. function PickupSpriteProxy:getMetaPositon()
  18. return self._metaPos
  19. end
  20. function PickupSpriteProxy:onRegister()
  21. PickupSpriteProxy.super.onRegister(self)
  22. end
  23. function PickupSpriteProxy:handle_MSG_SC_PICKUP_SPRITE(msg)
  24. local header = msg:GetHeader()
  25. -- dump(header,"handle_MSG_SC_PICKUP_SPRITE__")
  26. self._pickSprite = header.recog == 1 --是否开启
  27. self._pickSpriteDelay = header.param1 -- 时间间隔
  28. self._pickSpriteRange = header.param2--拾取范围
  29. self._pickSpriteMode = header.param3 -- 拾取模式 1 小精灵附近 0 自己附近 2(自己附近)一个个拾取 3(小精灵附近)一个个拾取
  30. local len = msg:GetDataLength()
  31. if len > 0 then
  32. local jsdata = msg:GetData():ReadString(len)
  33. self._pickSpriteID = jsdata
  34. end
  35. if self._pickSprite then
  36. self._tickTime = 0
  37. end
  38. end
  39. function PickupSpriteProxy:FindWidget(mainID, uiID)
  40. local GuideWidgetConfig = requireConfig("GuideWidgetConfig.lua")
  41. mainID = tonumber(mainID)
  42. local getNodesFunc = GuideWidgetConfig[mainID]
  43. if not getNodesFunc then
  44. return
  45. end
  46. local temp = { typeassist = uiID }
  47. local widget, parent = getNodesFunc(temp)
  48. return widget
  49. end
  50. function PickupSpriteProxy:handle_MSG_CS_PICKSPRITE_PICKUP_ANI(msg)
  51. local header = msg:GetHeader()
  52. local len = msg:GetDataLength()
  53. if self._mainID == 0 or self._uiID == 0 then
  54. return
  55. end
  56. if len > 0 then
  57. -----------------
  58. local items = {}
  59. local dd = msg:GetData():ReadString(len)
  60. local all = string.split(dd, ";")
  61. for i, v in ipairs(all) do
  62. local param = string.split(v, ",")
  63. table.insert(items, { id = param[1], mapX = param[2], mapY = param[3] })
  64. end
  65. -----------------
  66. local targetPos
  67. if self._metaPos then --优先使用原变量设置的坐标
  68. targetPos = self._metaPos
  69. else
  70. local widget = self:FindWidget(self._mainID, self._uiID)
  71. if widget then
  72. targetPos = widget:getWorldPosition()
  73. local box = widget:getBoundingBox()
  74. local anchor = widget:getAnchorPoint()
  75. local subX = 0.5 - anchor.x
  76. local subY = 0.5 - anchor.y
  77. targetPos.x = subX * box.width + targetPos.x
  78. targetPos.y = subY * box.height + targetPos.y
  79. end
  80. end
  81. if targetPos then
  82. ShowFakeDropItemsJustFly2(targetPos, items)
  83. end
  84. end
  85. end
  86. function PickupSpriteProxy:handle_MSG_SC_SET_PICKSPRITE_FLY_DST(msg)
  87. local header = msg:GetHeader()
  88. self._mainID = header.recog --主界面id
  89. self._uiID = header.param1 -- 控件id
  90. end
  91. function PickupSpriteProxy:getPickSpriteMode()
  92. return self._pickSpriteMode
  93. end
  94. function PickupSpriteProxy:getMainID()
  95. return self._mainID
  96. end
  97. function PickupSpriteProxy:getUIID()
  98. return self._uiID
  99. end
  100. function PickupSpriteProxy:getPickSpriteID()
  101. return self._pickSpriteID
  102. end
  103. function PickupSpriteProxy:getDelayTime()
  104. return self._pickSpriteDelay
  105. end
  106. function PickupSpriteProxy:getTickTime()
  107. return self._tickTime
  108. end
  109. function PickupSpriteProxy:setTickTime(TIME)
  110. self._tickTime = TIME
  111. end
  112. function PickupSpriteProxy:getPickupRange()
  113. return self._pickSpriteRange
  114. end
  115. function PickupSpriteProxy:getPickupSpriteState()
  116. return self._pickSprite
  117. end
  118. function PickupSpriteProxy:ReqPickUpSomething(Names)
  119. --自动捡取
  120. LuaSendMsg(global.MsgType.MSG_CS_PICKSPRITE_PICKUP, 0, 0, 0, 0, Names, string.len(Names))
  121. end
  122. function PickupSpriteProxy:RegisterMsgHandler()
  123. PickupSpriteProxy.super.RegisterMsgHandler(self)
  124. local msgType = global.MsgType
  125. LuaRegisterMsgHandler(msgType.MSG_SC_PICKUP_SPRITE, handler(self, self.handle_MSG_SC_PICKUP_SPRITE)) -- 拾取精灵
  126. LuaRegisterMsgHandler(msgType.MSG_CS_PICKSPRITE_PICKUP_ANI, handler(self, self.handle_MSG_CS_PICKSPRITE_PICKUP_ANI)) -- 拾取精灵动画
  127. LuaRegisterMsgHandler(msgType.MSG_SC_SET_PICKSPRITE_FLY_DST, handler(self, self.handle_MSG_SC_SET_PICKSPRITE_FLY_DST)) -- 拾取精灵动画
  128. end
  129. return PickupSpriteProxy