SceneEffectProxy.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local SceneEffectProxy = class("SceneEffectProxy", RemoteProxy)
  3. SceneEffectProxy.NAME = global.ProxyTable.SceneEffectProxy
  4. function SceneEffectProxy:ctor()
  5. SceneEffectProxy.super.ctor(self)
  6. self._mapEffectList = {}
  7. end
  8. function SceneEffectProxy:GetWeatherEffList(...)
  9. return self._mapEffectList
  10. end
  11. function SceneEffectProxy:ClearWeatherEffList()
  12. self._mapEffectList = {}
  13. end
  14. function SceneEffectProxy:handle_MSG_SC_SCREEN_EFFECT_PLAY(msg)
  15. local data = ParseRawMsgToJson(msg)
  16. dump(data)
  17. if not data or not next(data) then
  18. return nil
  19. end
  20. local item = {
  21. id = data.nEffectItemId,
  22. effectId = data.nEffectId,
  23. x = data.nClientX,
  24. y = data.nClientY,
  25. speed = data.nPlaySpeed,
  26. times = data.nPlayCount,
  27. mode = data.nPlayMode,
  28. }
  29. PlayEffectOnScreen(item)
  30. end
  31. function SceneEffectProxy:handle_MSG_SC_SCREEN_EFFECT_REMOVE(msg)
  32. local data = ParseRawMsgToJson(msg)
  33. dump(data)
  34. if not data or not next(data) then
  35. return nil
  36. end
  37. local removeName = tostring(data.nEffectItemId)
  38. global.Facade:sendNotification(global.NoticeTable.Layer_Notice_RemoveChild, removeName)
  39. end
  40. function SceneEffectProxy:handle_MSG_SC_PLAY_WEATHER_EFFECT(msg)
  41. local header = msg:GetHeader()
  42. local msgLen = msg:GetDataLength()
  43. local dataString = msg:GetData():ReadString(msgLen)
  44. local time = header.param1
  45. local mode = header.recog -- 1黄沙 2花瓣 3下雪
  46. local mapID = dataString
  47. if not self._mapEffectList[mapID] then
  48. self._mapEffectList[mapID] = {}
  49. end
  50. table.insert(self._mapEffectList[mapID], { mapID = mapID, time = time, mode = mode })
  51. local weather = { mapID = mapID, time = time, mode = mode }
  52. global.Facade:sendNotification(global.NoticeTable.Scene_Weather_Effect_Add, { params = weather })
  53. end
  54. function SceneEffectProxy:handle_MSG_SC_PLAY_MAP_ALL_WEATHER(msg)
  55. local header = msg:GetHeader()
  56. local num = header.recog -- 数量
  57. local msgLen = msg:GetDataLength()
  58. local dataString = msg:GetData():ReadString(msgLen) -- 格式:ID,time,map;ID,time,map
  59. local list = string.split(dataString, ";")
  60. for _, data in ipairs(list) do
  61. if data and string.len(data) > 0 then
  62. local params = string.split(data, ",")
  63. if params[1] and params[2] and params[3] then
  64. local mapID = params[3]
  65. if not self._mapEffectList[mapID] then
  66. self._mapEffectList[mapID] = {}
  67. end
  68. table.insert(self._mapEffectList[mapID], { mapID = mapID, time = tonumber(params[2]), mode = tonumber(params[1]) })
  69. end
  70. end
  71. end
  72. global.Facade:sendNotification(global.NoticeTable.Scene_Weather_Effect_Add, { init = true })
  73. end
  74. function SceneEffectProxy:handle_MSG_SC_CLEAR_WEATHER_BY_MAP(msg)
  75. local header = msg:GetHeader()
  76. local mode = header.recog -- 特效ID -- 0:全清理
  77. local msgLen = msg:GetDataLength()
  78. local dataString = msg:GetData():ReadString(msgLen)
  79. local mapID = dataString
  80. if mode and mode == 0 then
  81. self._mapEffectList[mapID] = nil
  82. else
  83. if self._mapEffectList[mapID] and next(self._mapEffectList[mapID]) then
  84. local list = clone(self._mapEffectList[mapID])
  85. for _, data in ipairs(list) do
  86. if mode and data.mode == mode then
  87. table.remove(list, _)
  88. end
  89. end
  90. self._mapEffectList[mapID] = list
  91. end
  92. end
  93. global.Facade:sendNotification(global.NoticeTable.Scene_Weather_Effect_Remove, mode)
  94. end
  95. function SceneEffectProxy:onRegister()
  96. SceneEffectProxy.super.onRegister(self)
  97. local msgType = global.MsgType
  98. LuaRegisterMsgHandler(msgType.MSG_SC_SCREEN_EFFECT_PLAY, handler(self, self.handle_MSG_SC_SCREEN_EFFECT_PLAY))
  99. LuaRegisterMsgHandler(msgType.MSG_SC_SCREEN_EFFECT_REMOVE, handler(self, self.handle_MSG_SC_SCREEN_EFFECT_REMOVE))
  100. LuaRegisterMsgHandler(msgType.MSG_SC_PLAY_WEATHER_EFFECT, handler(self, self.handle_MSG_SC_PLAY_WEATHER_EFFECT))
  101. LuaRegisterMsgHandler(msgType.MSG_SC_PLAY_MAP_ALL_WEATHER, handler(self, self.handle_MSG_SC_PLAY_MAP_ALL_WEATHER))
  102. LuaRegisterMsgHandler(msgType.MSG_SC_CLEAR_WEATHER_BY_MAP, handler(self, self.handle_MSG_SC_CLEAR_WEATHER_BY_MAP))
  103. end
  104. return SceneEffectProxy