Explorar o código

在家跨服获取玩家战斗数据功能

gitxsm hai 7 meses
pai
achega
cd84fb6e13

+ 47 - 0
script/module/battleDataManager/BattleDataCS.lua

@@ -0,0 +1,47 @@
+-- 用于跨服通知普通服上传玩家战斗数据及收到数据后的处理
+
+local InnerMsg = require("core.InnerMsg")
+local MiddleManager = require("middle.MiddleManager")
+local AreaBattleCS = require("areaBattle.AreaBattleCS")
+
+
+AREABTTLE_TAG = 1
+
+
+
+
+
+function NotifyNormalSrv(fd, playerUuid, moduleTag, combatType, extraAgrs)
+    local msgData = InnerMsg.wl.WL_COMBAT_DATA
+    msgData.playerUuid = playerUuid
+    msgData.moduleTag = moduleTag
+    msgData.combatType = combatType
+    msgData.extraAgrs = extraAgrs
+    InnerMsg.sendMsg(fd, msgData)
+end
+
+-- 其他模块调用,用于请求所需战斗数据
+function GetPlayerCombatData(serverId, playerUuid, moduleTag, combatType, extraAgrs)
+    if not serverId or not playerUuid or not moduleTag then
+        return
+    end
+
+    -- 后续再扩展
+    if moduleTag ~= AREABTTLE_TAG then
+        return
+    end
+
+    local fd = MiddleManager.getFDBySvrIndex(serverId)
+    if not fd then
+        return
+    end
+
+    NotifyNormalSrv(fd, playerUuid, moduleTag, combatType, extraAgrs)
+end
+
+-- 收到普通服上传的战斗数据
+function BattleDataHandleManager(fd, msg)
+    if msg.moduleTag == AREABTTLE_TAG then
+        AreaBattleCS.BattleDataHanle(msg)
+    end
+end

+ 67 - 0
script/module/battleDataManager/BattleDataNS.lua

@@ -0,0 +1,67 @@
+-- 用于普通服收到跨服通知上传战斗数据的处理
+
+local InnerMsg = require("core.InnerMsg")
+local CombatDefine = require("combat.CombatDefine")
+local CombatLogic = require("combat.CombatLogic")
+local MiddleDefine = require("middle.MiddleDefine")
+local CombatPosLogic = require("combat.CombatPosLogic")
+
+
+
+
+function CreateBattleData(fd, msg)
+    local tMsgData = InnerMsg.lw.LW_COMBAT_DATA
+    tMsgData.moduleTag = msg.moduleTag
+    tMsgData.extraArgs = msg.extraArgs
+
+    local playerUuid = msg.playerUuid
+    local nCombatType = msg.nCombatType or CombatDefine.COMBAT_TYPE1
+    local fakeHuman = CombatLogic.createCombatFakeHuman(playerUuid)
+
+	if not fakeHuman then
+        tMsgData.errCode = MiddleDefine.MIDDLE_GET_COMBAT_ERR_ONE
+        print("[BattleDataNS] 没有获取到对应玩家")
+        InnerMsg.sendMsg(0, tMsgData)
+        return
+    end
+
+	-- local combatHero = CombatPosLogic.getCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE1, nil, true)
+    local combatHero = CombatPosLogic.getCombatHeros(fakeHuman, nCombatType, nil, true)
+	if not combatHero or not next(combatHero) then
+        print("[BattleDataNS] 没有获取到对应玩家的英雄列表, 取默认战斗列表")
+        combatHero = CombatPosLogic.getCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE1, nil, true)
+        if not combatHero or not next(combatHero) then
+            print("[BattleDataNS] 取默认战斗列表还是没有获取到英雄列表")
+            tMsgData.errCode = MiddleDefine.MIDDLE_GET_COMBAT_ERR_TWO
+            InnerMsg.sendMsg(0, tMsgData)
+            return
+        end
+	end
+
+    local moduleFn = CombatLogic.getModule(msg.combatType)
+    if not moduleFn or not moduleFn.getCombatObjList then
+        print("[BattleDataNS] 未实现的获取战斗对象函数")
+        tMsgData.errCode = MiddleDefine.MIDDLE_GET_COMBAT_ERR_THREE
+        InnerMsg.sendMsg(0, tMsgData)
+        return
+    else
+        local args  = {
+            [1] = playerUuid
+        }
+        local objList, helpList, rolebase, formation,jiban = moduleFn.getCombatObjList(nil, CombatDefine.DEFEND_SIDE, args, msg.combatType)
+        if objList then
+            tMsgData.errCode = MiddleDefine.MIDDLE_GET_COMBAT_OK
+            tMsgData.objList = objList
+            tMsgData.helpList = helpList
+            tMsgData.roleBase = rolebase
+            tMsgData.formation = formation
+            tMsgData.jiBan = jiban
+            InnerMsg.sendMsg(0, tMsgData)
+        else
+            print("[BattleDataNS] 获取对战英雄列表失败")
+            tMsgData.errCode = MiddleDefine.MIDDLE_GET_COMBAT_ERR_FOUR
+            InnerMsg.sendMsg(0, tMsgData)
+            return
+        end
+    end
+end