MissionProxy.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local MissionProxy = class("MissionProxy", RemoteProxy)
  3. MissionProxy.NAME = global.ProxyTable.MissionProxy
  4. function MissionProxy:ctor()
  5. MissionProxy.super.ctor(self)
  6. self._data = {}
  7. self._data.items = {}
  8. end
  9. function MissionProxy:onRegister()
  10. MissionProxy.super.onRegister(self)
  11. end
  12. -- 任务置顶
  13. function MissionProxy:RespMissionTop(msg)
  14. local msgHdr = msg:GetHeader()
  15. local recog = msgHdr.recog
  16. global.Facade:sendNotification(global.NoticeTable.Layer_Assist_MissionTop, recog)
  17. SLBridge:onLUAEvent(LUA_EVENT_ASSIST_MISSION_TOP, recog)
  18. end
  19. function MissionProxy:CalcMissionOrderByID(id)
  20. local item = self:GetMissionByID(id)
  21. return item and item.order or 0
  22. end
  23. function MissionProxy:GetMissionByID(id)
  24. return self._data.items[id]
  25. end
  26. function MissionProxy:RequestSubmitMission(missionID)
  27. local item = self:GetMissionByID(missionID)
  28. self:SubmitMission(item)
  29. end
  30. function MissionProxy:SubmitMission(item)
  31. SendTableToServer(global.MsgType.MSG_SC_MISSION_SUBMIT, item)
  32. end
  33. function MissionProxy:RespMission(msg)
  34. local jsonData = ParseRawMsgToJson(msg)
  35. if not jsonData then
  36. return nil
  37. end
  38. self:UpdateMission(jsonData)
  39. end
  40. function MissionProxy:UpdateMission(item)
  41. -- item = {
  42. -- type = xx,
  43. -- head = {
  44. -- content = xx,
  45. -- color = xx,
  46. -- },
  47. -- body = {
  48. -- content = xx,
  49. -- color = xx,
  50. -- }
  51. -- flag = xx, 0 未接取 1进行中 2完成未提交
  52. -- }
  53. -- 有head表示增加或者修改
  54. -- 没有head表示删除
  55. -- 单条处理,有head就是新增或者修改,否则为删除
  56. if item.head then
  57. self:ChangeMissionItem(item)
  58. else
  59. -- 数据上报移除需要任务名
  60. if self._data.items[item.type] then
  61. local content = self._data.items[item.type].head and self._data.items[item.type].head.content
  62. item.oldHead = {
  63. content = content
  64. }
  65. end
  66. self:RemoveMissionItem(item)
  67. end
  68. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  69. local selSerInfo = loginProxy:GetSelectedServer()
  70. local main_servid = selSerInfo and selSerInfo.mainServerId
  71. local main_server_name = selSerInfo and selSerInfo.mainServerName
  72. item.main_servid = main_servid
  73. item.main_server_name = main_server_name
  74. local NativeBridgeProxy = global.Facade:retrieveProxy( global.ProxyTable.NativeBridgeProxy )
  75. NativeBridgeProxy:GN_Mission( item )
  76. end
  77. function MissionProxy:ChangeMissionItem(item)
  78. -- 任务是否已存在
  79. if self._data.items[item.type] then
  80. self._data.items[item.type] = item
  81. global.Facade:sendNotification(global.NoticeTable.Layer_Assist_MissionChange, item)
  82. SLBridge:onLUAEvent(LUA_EVENT_ASSIST_MISSION_CHANGE, item)
  83. else
  84. self._data.items[item.type] = item
  85. global.Facade:sendNotification(global.NoticeTable.Layer_Assist_MissionAdd, item)
  86. SLBridge:onLUAEvent(LUA_EVENT_ASSIST_MISSION_ADD, item)
  87. end
  88. end
  89. function MissionProxy:RemoveMissionItem(item)
  90. if not self._data.items[item.type] then
  91. return false
  92. end
  93. self._data.items[item.type] = nil
  94. global.Facade:sendNotification(global.NoticeTable.Layer_Assist_MissionRemove, item)
  95. SLBridge:onLUAEvent(LUA_EVENT_ASSIST_MISSION_REMOVE, item)
  96. end
  97. function MissionProxy:RegisterMsgHandler()
  98. MissionProxy.super.RegisterMsgHandler(self)
  99. local msgType = global.MsgType
  100. LuaRegisterMsgHandler(msgType.MSG_SC_MISSION_CHANGE, handler(self, self.RespMission))
  101. LuaRegisterMsgHandler(msgType.MSG_SC_MISSION_TOP, handler(self, self.RespMissionTop))
  102. end
  103. return MissionProxy