WarReportMiddle.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. -------------------------------------------------------
  2. -- ս��
  3. --
  4. -------------------------------------------------------
  5. local LuaMongo = _G.lua_mongo
  6. local WarReportLogic = require("warReport.WarReportLogic")
  7. local InnerMsg = require("core.InnerMsg")
  8. local ObjHuman = require("core.ObjHuman")
  9. local CombatLogic = require("combat.CombatLogic")
  10. local DB = require("common.DB")
  11. local PanelDefine = require("broadcast.PanelDefine")
  12. local war_count_query = { war = 1 }
  13. local war_report_id = { _id = nil }
  14. local war_report_query = { war_index = nil, type = nil }
  15. -- ��ȡս������
  16. local function getWarReport(id)
  17. war_report_id._id = id
  18. local war_report_data = { }
  19. LuaMongo.find(DB.db_war_report, war_report_id)
  20. if not LuaMongo.next(war_report_data) then
  21. return
  22. end
  23. return war_report_data
  24. end
  25. -- �ղ�
  26. local function collectDo(type, id, op)
  27. if op ~= WarReportLogic.WAR_OP_CONFIRM and op ~= WarReportLogic.WAR_OP_CANCEL then
  28. return
  29. end
  30. local addValue = 1
  31. if op == WarReportLogic.WAR_OP_CONFIRM then
  32. addValue = 1
  33. elseif op == WarReportLogic.WAR_OP_CANCEL then
  34. addValue = -1
  35. end
  36. war_report_id._id = id
  37. local update_data = { ["$inc"] = { ["collect"] = addValue } }
  38. LuaMongo.update(DB.db_war_report, war_report_id, update_data)
  39. return true
  40. end
  41. -- ����ȷ��
  42. local function admire(id, uuid)
  43. local war_report_data = getWarReport(id)
  44. if not war_report_data then return end
  45. -- �Ѿ�����
  46. if war_report_data.admireList and
  47. war_report_data.admireList[uuid] then
  48. return
  49. end
  50. war_report_id._id = id
  51. local update_data = { ["$inc"] = { ["admire"] = 1 }, ["$set"] = { ["admireList." .. uuid] = 1 } }
  52. LuaMongo.update(DB.db_war_report, war_report_id, update_data)
  53. return true
  54. end
  55. -- ��������
  56. function LW_WARREPORT_ADD(type, combatInfo, atkRank, defRank)
  57. -- û������ ����
  58. local war_data = { }
  59. LuaMongo.find(DB.db_war_report, war_count_query)
  60. if not LuaMongo.next(war_data) then
  61. return
  62. end
  63. local war_index = war_data.war_report_count[type]
  64. if not war_index then return end
  65. war_report_query.war_index = war_index
  66. war_report_query.type = type
  67. local war_report_data = { }
  68. LuaMongo.find(DB.db_war_report, war_report_query)
  69. local warReport = { }
  70. warReport.type = type
  71. warReport.war_index = war_index
  72. warReport.atkUuid = combatInfo.attacker.uuid or ""
  73. warReport.defUuid = combatInfo.defender.uuid or ""
  74. warReport.combatInfo = combatInfo
  75. warReport.atkRank = atkRank
  76. warReport.defRank = defRank
  77. warReport.time = os.time()
  78. -- ���ǵ����һ�� ����¼������
  79. if LuaMongo.next(war_report_data) then
  80. if war_report_data.collect and war_report_data.collect > 0 then
  81. -- ���ղص� ɾ������
  82. LuaMongo.update(DB.db_war_report, war_report_query, { ["$unset"] = { ["war_index"] = 1 } })
  83. -- �����µ�����
  84. LuaMongo.insert(DB.db_war_report, warReport)
  85. else
  86. -- û���ղصĸ��ǵ�
  87. LuaMongo.update(DB.db_war_report, war_report_query, warReport)
  88. end
  89. else
  90. LuaMongo.insert(DB.db_war_report, warReport)
  91. end
  92. -- ��������
  93. if war_index >= WarReportLogic.WAR_COUNT_MAX then
  94. war_index = 1
  95. else
  96. war_index = war_index + 1
  97. end
  98. war_data.war_report_count[type] = war_index
  99. LuaMongo.update(DB.db_war_report, war_count_query, war_data)
  100. end
  101. -- [ս��] ��������
  102. function LW_WARREPORT_QUERY(fd, type, uuid, warReport, questType)
  103. local war_data_list = nil
  104. if questType == 1 then
  105. war_data_list = WarReportLogic.makeReport(type)
  106. elseif questType == 2 then
  107. war_data_list = WarReportLogic.makeCollectReport(warReport)
  108. elseif questType == 3 then
  109. war_data_list = WarReportLogic.makeMyReport(uuid)
  110. end
  111. if not war_data_list then return end
  112. --local msgInner = InnerMsg.wl.WL_WARREPORT_QUERY
  113. local msgInner = {}
  114. msgInner.uuid = uuid
  115. msgInner.warReport = war_data_list
  116. msgInner.questType = questType
  117. --InnerMsg.sendMsg(fd, msgInner)
  118. WL_WARREPORT_QUERY(_,msgInner)
  119. end
  120. -- [ս��] ���ݷ���
  121. function WL_WARREPORT_QUERY(fd, msg)
  122. local human = ObjHuman.onlineUuid[msg.uuid]
  123. if not human then return end
  124. WarReportLogic.sendReport(human, msg.warReport, msg.questType)
  125. end
  126. -- [ս��] ս���˺���¼
  127. function LW_WARREPORT_GET_COMBATINFO(fd, msg)
  128. local war_report_data = getWarReport(msg.id)
  129. if not war_report_data then return end
  130. local msgInner = {} --InnerMsg.wl.WL_WARREPORT_GET_COMBATINFO
  131. msgInner.uuid = msg.uuid
  132. msgInner.mode = msg.mode
  133. msgInner.combatInfo = war_report_data.combatInfo
  134. --InnerMsg.sendMsg(fd, msgInner)
  135. WL_WARREPORT_GET_COMBATINFO(fd,msgInner)
  136. end
  137. -- [ս��] ս���˺���¼ �ط�
  138. function WL_WARREPORT_GET_COMBATINFO(fd, msg)
  139. local human = ObjHuman.onlineUuid[msg.uuid]
  140. if not human then return end
  141. if msg.mode == WarReportLogic.WAR_COMBATINFO_PLAYBACK then
  142. msg.combatInfo.panelID = PanelDefine.PANEL_ID_1018
  143. CombatLogic.repeatCombat(human, msg.combatInfo)
  144. elseif msg.mode == WarReportLogic.WAR_COMBATINFO_HARM then
  145. WarReportLogic.sendFinish(human, msg.combatInfo)
  146. end
  147. end
  148. -- [ս��] �ղ�
  149. function LW_WARREPORT_COLLECT(fd, msg)
  150. local war_report_data = getWarReport(msg.id)
  151. if not war_report_data then return end
  152. if not collectDo(msg.type, msg.id, msg.op) then
  153. return
  154. end
  155. local msgInner = {} --InnerMsg.wl.WL_WARREPORT_COLLECT
  156. msgInner.uuid = msg.uuid
  157. msgInner.type = msg.type
  158. msgInner.id = msg.id
  159. msgInner.op = msg.op
  160. --InnerMsg.sendMsg(fd, msgInner)
  161. WL_WARREPORT_COLLECT(fd,msgInner)
  162. end
  163. -- [ս��] �ղ�
  164. function WL_WARREPORT_COLLECT(fd, msg)
  165. local human = ObjHuman.onlineUuid[msg.uuid]
  166. if not human then return end
  167. WarReportLogic.collectHumanDo(human, msg.type, msg.id, msg.op)
  168. end
  169. -- [ս��] ����
  170. function LW_WARREPORT_ADMIRE(fd, msg)
  171. if not admire(msg.id, msg.uuid) then
  172. return
  173. end
  174. local msgInner = {} --InnerMsg.wl.WL_WARREPORT_ADMIRE
  175. msgInner.uuid = msg.uuid
  176. msgInner.id = msg.id
  177. --InnerMsg.sendMsg(fd, msgInner)
  178. WL_WARREPORT_ADMIRE(fd,msgInner)
  179. end
  180. -- [ս��] ����
  181. function WL_WARREPORT_ADMIRE(fd, msg)
  182. local human = ObjHuman.onlineUuid[msg.uuid]
  183. if not human then return end
  184. WarReportLogic.admireDo(human, msg.id)
  185. end
  186. -- ս�����
  187. local delQuery = {war = { ["$exists"] = 0}, war_index = { ["$exists"] = 0}, ["$or"] = {{collect = {["$exists"]=0}}, {collect = 0}}}
  188. function onZero()
  189. if _G.is_middle ~= true then
  190. return
  191. end
  192. -- 0����� û������ ��û���ղص� ����
  193. LuaMongo.remove(DB.db_war_report, delQuery)
  194. end