| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- --------------------------------
- -- 文件名 : MiddleCommonLogic
- -- 文件说明 : 跨服相关-通用管理(用于处理比较杂项的数据)
- -- 创建时间 : 2025/02/26
- -- 创建人 : FC
- --------------------------------
- local Config = require("Config")
- local Log = require("common.Log")
- local CommonDB = require("common.CommonDB")
- local InnerMsg = require("core.InnerMsg")
- local RoleLogic = require("role.RoleLogic")
- local Msg = require("core.Msg")
- local ObjHuman = require("core.ObjHuman")
- local CombatDefine = require("combat.CombatDefine")
- local Util = require("common.Util")
- local Broadcast = require("broadcast.Broadcast")
- local Lang = require("common.Lang")
- local CombatLogic = require("combat.CombatLogic")
- local CombatPosLogic = require("combat.CombatPosLogic")
- local MiddleDefine = require("middle.MiddleDefine")
- local YunYingLogic = require("yunying.YunYingLogic")
- local TriggerDefine = require("trigger.TriggerDefine")
- local TriggerLogic = require("trigger.TriggerLogic")
- local MIDDLE_FRIEND_FIGHT_MAP = 1001
- ---- 战斗相关缓存
- local MIDDLECOMMONCOMBAT =
- {
- --[[
- -- 请求者UID
- [nSrcUID] =
- {
- nDesUID, -- 请求对战角色UID
- nCombatType, -- 战斗类型
- nTime, -- 请求的时间
- }
- ]]
- }
- -- 内部写日志说明
- local function MiddleCommonLogic_WRITELOG(szText)
- Log.write(Log.LOGID_OSS_COMMON, "跨服通用管理"..szText)
- end
- -- 是否可以进行战斗
- local function MiddleCommonLogic_CanCombatType(nCombatType)
- if not MiddleDefine.MIDDLE_CAN_COMBAT[nCombatType] then
- return false
- end
- return true
- end
- -- 是否有缓存
- local function MiddleCommonLogic_IsCache(nSrcUID)
- return MIDDLECOMMONCOMBAT[nSrcUID]
- end
- -- 清理战斗缓存
- local function MiddleCommonLogic_ClearCache(nSrcUID)
- MIDDLECOMMONCOMBAT[nSrcUID] = nil
- end
- -- 设置战斗缓存
- local function MiddleCommonLogic_SetCache(nSrcUID, nDesUID, nCombatType)
- MIDDLECOMMONCOMBAT[nSrcUID] =
- {
- nDesUID = nDesUID,
- nCombatType = nCombatType,
- nTime = os.time()
- }
- end
- -- 弹失败提示
- local function MiddleCommonLogic_PopTips(human, nResult)
- if MiddleDefine.MIDDLE_GET_COMBAT_ERR_ONE == nResult then
- Broadcast.sendDown(human, Lang.MIDDLE_COMBAT_NOHUMAN)
- elseif MiddleDefine.MIDDLE_GET_COMBAT_ERR_TWO == nResult then
- Broadcast.sendDown(human, Lang.MIDDLE_COMBAT_NOFANSHOU)
- elseif MiddleDefine.MIDDLE_GET_COMBAT_ERR_THREE == nResult then
- Broadcast.sendDown(human, Lang.MIDDLE_COMBAT_NOHUMAN)
- elseif MiddleDefine.MIDDLE_GET_COMBAT_ERR_FOUR == nResult then
- Broadcast.sendDown(human, Lang.MIDDLE_COMBAT_NOHUMAN)
- end
- end
- ---------------------------- 点击玩家头像处理开始 ------------------------
- ---
- -- 跨服获取玩家信息(源->中心服)
- function MiddleCommonLogic_GetChatPlayInfo_LW(human, msg)
- local tMsgData = InnerMsg.lw.LW_CHAT_PLAYER_INFO
- tMsgData.nSrcUID = human.db._id
- tMsgData.nDesUID = msg.uuid
- tMsgData.nSrcServerID = Config.SVR_INDEX
- tMsgData.nDesServerID = msg.nServerIndex
- print("[MiddleCommonLogic_GetChatPlayInfo_LW] ", tMsgData.nSrcUID, tMsgData.nDesUID, tMsgData.nSrcServerID, tMsgData.nDesServerID)
- InnerMsg.sendMsg(0, tMsgData)
- end
- -- 跨服获取玩家信息(中心服->目标)
- function MiddleCommonLogic_GetChatPlayInfo_WL(fd, msg)
- local msgRet = Msg.gc.GC_CHAT_PLAYER_INFO
- if not RoleLogic.makePlayInfo(msgRet.data, msg.nDesUID) then
- MiddleCommonLogic_WRITELOG("跨服获取玩家数据失败 nDesUID = "..msg.nDesUID.." nSrcUID = "..msg.nSrcUID.." nSrcServerID = "..msg.nSrcServerID)
- return
- end
- -- 获取数据发回中心服
- local tMsgData = InnerMsg.lw.LW_CHAT_PLAYER_INFO_SEND
- tMsgData.nSrcUID = msg.nSrcUID
- tMsgData.nSrcServerID = msg.nSrcServerID
- tMsgData.tData = msgRet
- InnerMsg.sendMsg(0, tMsgData)
- print("[MiddleCommonLogic_GetChatPlayInfo_WL] 跨服获取玩家信息(中心服->目标)")
- end
- -- 获取到数据发送给请求的玩家
- function MiddleCommonLogic_SendChatPlayInfo_WL(fd, msg)
- local nSrcUID = msg.nSrcUID
- local human = ObjHuman.onlineUuid[nSrcUID]
- if not human then
- print("[MiddleCommonLogic_SendChatPlayInfo_WL] 玩家不在线直接返回")
- return
- end
- local msgRet = Msg.gc.GC_CHAT_PLAYER_INFO
- msgRet.data = msg.tData.data
- Msg.send(msgRet, human.fd)
- print("[MiddleCommonLogic_SendChatPlayInfo_WL] 获取到数据发送给请求的玩家")
- end
- ---------------------------- 点击玩家头像处理结束 ------------------------
- ---------------------------- 战斗相关开始 --------------------------------
- function MiddleCommonLogic_CombatBegin_LW(human, msg)
- if false == MiddleCommonLogic_CanCombatType(msg.combatType) then
- print("[MiddleCommonLogic_CombatBegin] 不用处理的对战类型直接返回 combatType = "..msg.combatType)
- return
- end
- local tCombatCache = MiddleCommonLogic_IsCache(human)
- if tCombatCache then
- local nNowTime = os.time()
- if tCombatCache.nTime + MiddleDefine.MIDDLE_GET_COMBAT_TIME <= nNowTime then
- MiddleCommonLogic_ClearCache(human.db._id)
- else
- return Broadcast.sendDown(human, Lang.MIDDLE_COMBAT_WAIT)
- end
- end
- local args = Util.split(msg.param, "|")
- MiddleCommonLogic_SetCache(human.db._id, args[1], msg.combatType)
- local tMsgData = InnerMsg.lw.LW_COMBAT_GETINFO
- tMsgData.nSrcUID = human.db._id
- tMsgData.nDesUID = args[1]
- tMsgData.nSrcServerID = Config.SVR_INDEX
- tMsgData.nDesServerID = msg.nServerIndex
- tMsgData.nCombatType = msg.combatType
- InnerMsg.sendMsg(0, tMsgData)
- print("[MiddleCommonLogic_CombatBegin_LW] 发送给中心服 = ")
- end
- -- msg = WL_COMBAT_GETINFO
- function MiddleCommonLogic_CombatBegin_WL(fd, msg)
- local tMsgData = InnerMsg.lw.LW_COMBAT_GETINFO_SEND
- tMsgData.nSrcUID = msg.nSrcUID
- tMsgData.nSrcServerID = msg.nSrcServerID
- local nDesUID = msg.nDesUID
- local fakeHuman = CombatLogic.createCombatFakeHuman(nDesUID)
- if not fakeHuman then
- tMsgData.nResult = MiddleDefine.MIDDLE_GET_COMBAT_ERR_ONE
- print("[MiddleCommonLogic_CombatBegin_WL] 没有获取到对应玩家")
- InnerMsg.sendMsg(0, tMsgData)
- return
- end
- local combatHero = CombatPosLogic.getCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE1, nil, true)
- if not combatHero or not next(combatHero) then
- print("[MiddleCommonLogic_CombatBegin_WL] 没有获取到对应玩家的英雄列表")
- tMsgData.nResult = MiddleDefine.MIDDLE_GET_COMBAT_ERR_TWO
- InnerMsg.sendMsg(0, tMsgData)
- return
- end
- local moduleFn = CombatLogic.getModule(msg.nCombatType)
- if not moduleFn or not moduleFn.getCombatObjList then
- print("[MiddleCommonLogic_CombatBegin_WL] 未实现的获取战斗对象函数")
- tMsgData.nResult = MiddleDefine.MIDDLE_GET_COMBAT_ERR_THREE
- MiddleCommonLogic_WRITELOG("[MiddleCommonLogic_CombatBegin_WL] 未实现的获取战斗对象函数 nCombatType = "..msg.nCombatType)
- InnerMsg.sendMsg(0, tMsgData)
- return
- else
- local args = {
- [1] = nDesUID
- }
- local objList, helpList, rolebase, formation,jiban = moduleFn.getCombatObjList(nil, CombatDefine.DEFEND_SIDE, args, msg.nCombatType)
- if objList then
- tMsgData.nResult = MiddleDefine.MIDDLE_GET_COMBAT_OK
- tMsgData.tObjList = objList
- tMsgData.tHelpList = helpList
- tMsgData.tRoleBase = rolebase
- tMsgData.formation = formation
- tMsgData.tJiBan = jiban
- InnerMsg.sendMsg(0, tMsgData)
- else
- print("[MiddleCommonLogic_CombatBegin_WL] 获取对战英雄列表失败")
- MiddleCommonLogic_WRITELOG("[MiddleCommonLogic_CombatBegin_WL] 未实现的获取战斗对象列表失败 nCombatType = "..msg.nCombatType)
- tMsgData.nResult = MiddleDefine.MIDDLE_GET_COMBAT_ERR_FOUR
- InnerMsg.sendMsg(0, tMsgData)
- return
- end
- end
- end
- function MiddleCommonLogic_CombatBegin_SendWL(fd, msg)
- local nSrcUID = msg.nSrcUID
- local human = ObjHuman.onlineUuid[nSrcUID]
- if not human then
- print("[MiddleCommonLogic_CombatBegin_SendWL] 玩家不在线直接返回")
- return
- end
- print("[MiddleCommonLogic_CombatBegin_SendWL] 收到信息进行打印")
- local tCombatCache = MiddleCommonLogic_IsCache(nSrcUID)
- if not tCombatCache then
- print("[MiddleCommonLogic_CombatBegin_SendWL] 不存在对应的战斗缓存信息")
- return
- else
- local nNowTime = os.time()
- -- 已经超时
- if tCombatCache.nTime + MiddleDefine.MIDDLE_GET_COMBAT_TIME <= nNowTime then
- print("[MiddleCommonLogic_CombatBegin_SendWL] 已经超时")
- MiddleCommonLogic_ClearCache(nSrcUID)
- return
- end
- end
- local nResult = msg.nResult
- if MiddleDefine.MIDDLE_GET_COMBAT_OK ~= nResult then
- print("[MiddleCommonLogic_CombatBegin_SendWL] 获取的数据不正确,弹Tips并返回")
- MiddleCommonLogic_PopTips(human, nResult)
- return
- end
- local args = {
- defender = msg.tObjList,
- defHelp = msg.tHelpList,
- defRBase = msg.tRoleBase,
- defFormation = msg.formation,
- defJiban = msg.tJiBan,
- }
- YunYingLogic.onCallBack(human, "friendCombat", 1)
- TriggerLogic.PublishEvent(TriggerDefine.FRIEND_COMBAT, human.db._id, 1)
- print("[MiddleCommonLogic_CombatBegin_SendWL] 开始进行战斗")
- CombatLogic.combatBegin(human, MIDDLE_FRIEND_FIGHT_MAP, args, tCombatCache.nCombatType, tCombatCache.nDesUID)
- MiddleCommonLogic_ClearCache(nSrcUID)
- print("[MiddleCommonLogic_CombatBegin_SendWL] 战斗结束清理数据")
- end
- ---------------------------- 战斗相关结束 --------------------------------
|