| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- -------------------------------------------------------
- -- 战报
- --
- -------------------------------------------------------
- local LuaMongo = _G.lua_mongo
- local WarReportLogic = require("warReport.WarReportLogic")
- local InnerMsg = require("core.InnerMsg")
- local ObjHuman = require("core.ObjHuman")
- local CombatLogic = require("combat.CombatLogic")
- local DB = require("common.DB")
- local PanelDefine = require("broadcast.PanelDefine")
- local war_count_query = { war = 1 }
- local war_report_id = { _id = nil }
- local war_report_query = { war_index = nil, type = nil }
- -- 获取战报数据
- local function getWarReport(id)
- war_report_id._id = id
- local war_report_data = { }
- LuaMongo.find(DB.db_war_report, war_report_id)
- if not LuaMongo.next(war_report_data) then
- return
- end
- return war_report_data
- end
- -- 收藏
- local function collectDo(type, id, op)
- if op ~= WarReportLogic.WAR_OP_CONFIRM and op ~= WarReportLogic.WAR_OP_CANCEL then
- return
- end
- local addValue = 1
- if op == WarReportLogic.WAR_OP_CONFIRM then
- addValue = 1
- elseif op == WarReportLogic.WAR_OP_CANCEL then
- addValue = -1
- end
- war_report_id._id = id
- local update_data = { ["$inc"] = { ["collect"] = addValue } }
- LuaMongo.update(DB.db_war_report, war_report_id, update_data)
- return true
- end
- -- 点赞确认
- local function admire(id, uuid)
- local war_report_data = getWarReport(id)
- if not war_report_data then return end
- -- 已经点赞
- if war_report_data.admireList and
- war_report_data.admireList[uuid] then
- return
- end
- war_report_id._id = id
- local update_data = { ["$inc"] = { ["admire"] = 1 }, ["$set"] = { ["admireList." .. uuid] = 1 } }
- LuaMongo.update(DB.db_war_report, war_report_id, update_data)
- return true
- end
- -- 添加数据
- function LW_WARREPORT_ADD(type, combatInfo, atkRank, defRank)
-
- -- 没有索引 返回
- local war_data = { }
- LuaMongo.find(DB.db_war_report, war_count_query)
- if not LuaMongo.next(war_data) then
- return
- end
- local war_index = war_data.war_report_count[type]
- if not war_index then return end
- war_report_query.war_index = war_index
- war_report_query.type = type
- local war_report_data = { }
- LuaMongo.find(DB.db_war_report, war_report_query)
- local warReport = { }
- warReport.type = type
- warReport.war_index = war_index
- warReport.atkUuid = combatInfo.attacker.uuid or ""
- warReport.defUuid = combatInfo.defender.uuid or ""
- warReport.combatInfo = combatInfo
- warReport.atkRank = atkRank
- warReport.defRank = defRank
- warReport.time = os.time()
- -- 覆盖掉最后一场 减少录像数据
- if LuaMongo.next(war_report_data) then
- if war_report_data.collect and war_report_data.collect > 0 then
- -- 有收藏的 删掉索引
- LuaMongo.update(DB.db_war_report, war_report_query, { ["$unset"] = { ["war_index"] = 1 } })
- -- 插入新的数据
- LuaMongo.insert(DB.db_war_report, warReport)
- else
- -- 没有收藏的覆盖掉
- LuaMongo.update(DB.db_war_report, war_report_query, warReport)
- end
- else
- LuaMongo.insert(DB.db_war_report, warReport)
- end
- -- 更新索引
- if war_index >= WarReportLogic.WAR_COUNT_MAX then
- war_index = 1
- else
- war_index = war_index + 1
- end
- war_data.war_report_count[type] = war_index
- LuaMongo.update(DB.db_war_report, war_count_query, war_data)
- end
- -- [战报] 请求数据
- function LW_WARREPORT_QUERY(fd, type, uuid, warReport, questType)
- local war_data_list = nil
- if questType == 1 then
- war_data_list = WarReportLogic.makeReport(type)
- elseif questType == 2 then
- war_data_list = WarReportLogic.makeCollectReport(warReport)
- elseif questType == 3 then
- war_data_list = WarReportLogic.makeMyReport(uuid)
- end
- if not war_data_list then return end
- local msgInner = InnerMsg.wl.WL_WARREPORT_QUERY
- msgInner.uuid = uuid
- msgInner.warReport = war_data_list
- msgInner.questType = questType
- InnerMsg.sendMsg(fd, msgInner)
- end
- -- [战报] 数据返回
- function WL_WARREPORT_QUERY(fd, msg)
- local human = ObjHuman.onlineUuid[msg.uuid]
- if not human then return end
- WarReportLogic.sendReport(human, msg.warReport, msg.questType)
- end
- -- [战报] 战斗伤害记录
- function LW_WARREPORT_GET_COMBATINFO(fd, msg)
- local war_report_data = getWarReport(msg.id)
- if not war_report_data then return end
- local msgInner = InnerMsg.wl.WL_WARREPORT_GET_COMBATINFO
- msgInner.uuid = msg.uuid
- msgInner.mode = msg.mode
- msgInner.combatInfo = war_report_data.combatInfo
- InnerMsg.sendMsg(fd, msgInner)
- end
- -- [战报] 战斗伤害记录 回放
- function WL_WARREPORT_GET_COMBATINFO(fd, msg)
- local human = ObjHuman.onlineUuid[msg.uuid]
- if not human then return end
-
- if msg.mode == WarReportLogic.WAR_COMBATINFO_PLAYBACK then
- msg.combatInfo.panelID = PanelDefine.PANEL_ID_1018
- CombatLogic.repeatCombat(human, msg.combatInfo)
- elseif msg.mode == WarReportLogic.WAR_COMBATINFO_HARM then
- WarReportLogic.sendFinish(human, msg.combatInfo)
- end
- end
- -- [战报] 收藏
- function LW_WARREPORT_COLLECT(fd, msg)
- local war_report_data = getWarReport(msg.id)
- if not war_report_data then return end
- if not collectDo(msg.type, msg.id, msg.op) then
- return
- end
- local msgInner = InnerMsg.wl.WL_WARREPORT_COLLECT
- msgInner.uuid = msg.uuid
- msgInner.type = msg.type
- msgInner.id = msg.id
- msgInner.op = msg.op
- InnerMsg.sendMsg(fd, msgInner)
- end
- -- [战报] 收藏
- function WL_WARREPORT_COLLECT(fd, msg)
- local human = ObjHuman.onlineUuid[msg.uuid]
- if not human then return end
- WarReportLogic.collectHumanDo(human, msg.type, msg.id, msg.op)
- end
- -- [战报] 点赞
- function LW_WARREPORT_ADMIRE(fd, msg)
- if not admire(msg.id, msg.uuid) then
- return
- end
- local msgInner = InnerMsg.wl.WL_WARREPORT_ADMIRE
- msgInner.uuid = msg.uuid
- msgInner.id = msg.id
- InnerMsg.sendMsg(fd, msgInner)
- end
- -- [战报] 点赞
- function WL_WARREPORT_ADMIRE(fd, msg)
- local human = ObjHuman.onlineUuid[msg.uuid]
- if not human then return end
- WarReportLogic.admireDo(human, msg.id)
- end
- -- 战报清除
- local delQuery = {war = { ["$exists"] = 0}, war_index = { ["$exists"] = 0}, ["$or"] = {{collect = {["$exists"]=0}}, {collect = 0}}}
- function onZero()
- if _G.is_middle ~= true then
- return
- end
- -- 0点清除 没有索引 且没有收藏的 数据
- LuaMongo.remove(DB.db_war_report, delQuery)
- end
|