| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203 |
- -- 异界之战
- --db
- --[=[
- human.db.anotherWorlBattle = {
- startTime = nil,
- formation = {
- [cityId1] = {
- [pointIdx1] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
- [pointIdx2] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
- },
- [cityId2] = {
- [pointIdx1] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
- [pointIdx2] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
- },
- }
- }
- ]=]--
- local Config = require("Config")
- local Msg = require("core.Msg")
- local Lang = require("common.Lang")
- local ObjHuman = require("core.ObjHuman")
- local Broadcast = require("broadcast.Broadcast")
- local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
- local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
- local CombatDefine = require("combat.CombatDefine")
- local RoleDBLogic = require("role.RoleDBLogic")
- local CombatPosLogic = require("combat.CombatPosLogic")
- local CombatLogic = require("combat.CombatLogic")
- local MailExcel = require("excel.mail")
- local Util = require("common.Util")
- local InnerMsg = require("core.InnerMsg")
- local RoleHeadLogic = require("role.RoleHeadLogic")
- local MailManager = require("mail.MailManager")
- local Log = require("common.Log")
- local Timer = require("core.Timer")
- local CommonDB = require("common.CommonDB")
- local RoleSystemExcel = require("excel.roleSystem")
- local Grid = require("bag.Grid")
- local UnionLogic = require("union.UnionLogic")
- local BillboardLogic = require("billboard.BillboardLogic")
- local BillboardDefine = require("billboard.BillboardDefine")
- local AnotherWorldBattleDefine = require("anotherWorldBattle.AnotherWorldBattleDefine")
- local AnotherWorldBattleConfig = require("excel.anotherWorldBattle")
- local MonsterGrid = require("monster.MonsterGrid")
- local RoleConfig = require("excel.role")
- local MonsterExcel = require("excel.monster")
- local HeroExcel = require("excel.hero")
- local MiddleCommonLogic = require("middle.MiddleCommonLogic")
- local CombatImpl = require("combat.CombatImpl")
- local RoleAttr = require("role.RoleAttr")
- local RoleDefine = require("role.RoleDefine")
- local function writeLog(str)
-
- end
- local function sendMail(mailId, receiverUuid, itemArray)
- if not mailId or not receiverUuid then
- return
- end
- local mailCfg = MailExcel.mail[mailId]
- local content = mailCfg.content
- MailManager.add(MailManager.SYSTEM, receiverUuid, mailCfg.title, content, itemArray, mailCfg.senderName or "GM")
- end
- local function createRewardQueue()
- local issueRewardQueue = {
- playerArray = {},
- insertMaxNum = 100, -- 一次最多插入数据库的邮件数量
- repeatMaxTimes = 3, -- 重试次数
- repeatTb = {}
- }
- function issueRewardQueue:add(playerInfo)
- table.insert(self.playerArray, playerInfo)
- end
- function issueRewardQueue:insertDB()
- local maxNum = math.min(self.insertMaxNum, #self.playerArray)
- for i=1, maxNum do
- local resTag = AnotherWorldBattleDefine.AB_MAIL_SUCC_TAG
- local playerInfo = table.remove(self.playerArray)
- local uuid = playerInfo[1]
- local ok, err = pcall(sendMail, AnotherWorldBattleDefine.AB_AWARD_MAIL_ID, uuid, playerInfo[2])
- if not ok then
- if not self.repeatTb[uuid] or self.repeatTb[uuid] < self.repeatMaxTimes then
- issueRewardQueue:add(playerInfo)
- self.repeatTb[uuid] = (self.repeatTb[uuid] or 0) + 1
- end
- resTag = AnotherWorldBattleDefine.AB_MAIL_FAIL_TAG
- end
- local str = string.format("Result: %s, playerUuid: %s, insertErrTimes: %d, errInfo: %s",
- resTag, uuid, self.repeatTb[uuid] or 0, err)
- writeLog(str)
- end
- if #self.playerArray > 0 then
- Timer.addLater(3, self.insertDB, self)
- end
- end
- return issueRewardQueue
- end
- -- 获取当天属于星期几
- local function getWDay()
- return Util.getWeekDay()
- end
- -- 计算怪物战力
- local function calcMonsterPower(monsterOutID)
- local power = 0
- local objList = MonsterGrid.createMonsterObjListByMonsterOutID(monsterOutID)
- if not objList then
- return power
- end
- for _, monster in ipairs(objList) do
- power = power + (monster.power or 0)
- end
- return power
- end
- -- 计算多个城池每分钟产出道具数量之和
- local function calcCitysAward(cityIdArr)
- local myUnionAwardNum = 0
- if cityIdArr then
- for _, cityId in ipairs(cityIdArr) do
- local targetCityCfg = AnotherWorldBattleConfig.city[cityId]
- myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2]
- end
- end
- return myUnionAwardNum
- end
- -- 获取展示部位的固定Id
- local function getDefaultShowId(showType, idx)
- local targetCfg
- if showType == 1 then
- targetCfg = RoleConfig.head
- else
- targetCfg = RoleConfig.headFrame
- end
- local t = {}
- for k in pairs(targetCfg) do
- t[#t+1] = k
- end
- table.sort(t)
- return t[idx] or t[1]
- end
- -- 单个英雄数据
- local function getHeroInfo(human, targetHeroUuid)
- local HeroLogic = require("hero.HeroLogic")
- local heroGrid = HeroLogic.getHeroGridByUuid(human, targetHeroUuid)
- if heroGrid then
- local heroCfg = HeroExcel.hero[heroGrid.id]
- RoleAttr.calcHeroGrid(heroGrid, nil, human)
- local heroInfo = {
- heroUuid = targetHeroUuid,
- heroStar = heroGrid.star,
- heroLevel = heroGrid.lv,
- heroCamp = heroGrid.camp or heroCfg.camp,
- heroBody = heroCfg.body,
- heroIcon = heroGrid.head or heroCfg.head,
- heroPower = heroGrid.zhandouli,
- }
- return heroInfo
- end
- end
- -- 获取上阵英雄数据
- local function getHeroListInfo(human, targetHeroUuid)
- local len = 0
- local heroArr = {}
- local heroList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
- if not next(heroList) then
- return heroArr
- end
- for _, heroUuid in pairs(heroList) do
- if (heroUuid ~= "" and heroUuid ~= "0") and (not targetHeroUuid or targetHeroUuid == heroUuid) then
- len = len + 1
- heroArr[len] = getHeroInfo(human, heroUuid)
- end
- end
- if len == 0 then
- return
- end
- return heroArr
- end
- -- 生成展示数据
- local function generateShowInfo(human)
- local showInfo = {
- name = human.db.name,
- lv = human.db.lv,
- power = human.db.zhandouli,
- }
- showInfo.head = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_1)
- showInfo.headFrame = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_2)
- -- showInfo.body = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_3)
- showInfo.heroArr = getHeroListInfo(human)
- return showInfo
- end
- -- 阵容数据检查,如果不在 "活动开启且战斗阶段" 则清空
- local function formationDataCheeck(human)
- if not human.db.anotherWorlBattle then
- return
- end
- -- 不在战斗阶段时间范围
- local wDay = getWDay()
- if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] > wDay and AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] < wDay then
- human.db.anotherWorlBattle = nil
- end
- -- 处于战斗阶段最后一天, 但是活动已经结束
- local now = os.time()
- local toDayStartTime = Util.getDayStartTime(now)
- if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
- human.db.anotherWorlBattle = nil
- end
- -- 处于战斗阶段时间范围内, 但是活动未开(因为每两轮活动时间间隔至少9天)
- local startTime = human.db.anotherWorlBattle.startTime
- local diffDays = Util.diffDay(startTime)
- if diffDays > 3 then
- human.db.anotherWorlBattle = nil
- end
- end
- -- 把玩家最新的异界之战所有防守英雄uuid推给客户端
- local function sendDefHeroArr(human)
- if not human.db.anotherWorlBattle then
- return
- end
- local len = 0
- local msgRet = Msg.gc.GC_AB_DEF_HERO_QUERY
- local heroUuidArrMsg = msgRet.heroUuidArr
- heroUuidArrMsg[0] = 0
- for _, pointList in pairs(human.db.anotherWorlBattle.formation) do
- for _, combatData in pairs(pointList) do
- local heroList = combatData.list
- for _, heroUuid in pairs(heroList) do
- if heroUuid ~= "" and heroUuid ~= "0" then
- len = len + 1
- heroUuidArrMsg[len] = heroUuid
- end
- end
- end
- end
- heroUuidArrMsg[0] = len
- Msg.send(msgRet, human.fd)
- end
- -- 是否是防守阵容中的英雄
- local function isDefHero(human, checkHeroUuid)
- if not human.db.anotherWorlBattle then
- return false
- end
- for _, pointList in pairs(human.db.anotherWorlBattle.formation) do
- for _, combatData in pairs(pointList) do
- local heroList = combatData.list
- for _, heroUuid in pairs(heroList) do
- if heroUuid == checkHeroUuid then
- return true
- end
- end
- end
- end
- return false
- end
- -- 是否是公会前二名
- local function isTopTwoUnion(human)
- local unionRanList = BillboardLogic.GetRankList(BillboardDefine.TYPE_UNION)
- if not unionRanList then
- return false
- end
- local unionId = human.db.unionUuid
- local isTopTwo = false
- for i=1, 2 do
- if unionRanList[i].uuid == unionId then
- isTopTwo = true
- break
- end
- end
- return isTopTwo
- end
- -- 是否处于战斗阶段
- local function isBattleStage()
- local wDay = getWDay()
- if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
- return true
- end
- return false
- end
- function IsRun(joinTime)
- if not isBattleStage() then
- return false
- end
- if joinTime then
- local diffDays = Util.diffDay(joinTime)
- --
- if diffDays == 5 then
- local now = os.time()
- local toDayStartTime = Util.getDayStartTime(now)
- if now < toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC then
- return false
- end
- end
- -- < 5天说明处于本轮活动的开启时间
- if diffDays > 5 and diffDays <= AnotherWorldBattleDefine.AB_SUB_DAY then
- return false
- end
- end
- return true
- end
- --检测上阵英雄
- function checkUpdatePos(human, msg)
- local heroList = Util.split(msg.heroList, ",")
- for i = 1, CombatDefine.COMBAT_HERO_CNT do
- local uuid = heroList[i] or ""
- if uuid ~= "0" and uuid ~= "" then
- if isDefHero(human, uuid) then
- return false
- end
- end
- end
- return true
- end
- -- 公会战力更新
- function UnionPowerChange(unionId)
- if not isBattleStage() then
- return
- end
- end
- function isOpen(human)
- return RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1306) -- 待改
- end
- function onLogin(human)
- formationDataCheeck(human)
- sendDefHeroArr(human)
- end
- -- 请求状态
- function AB_GetState(human)
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_STATE
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid or ""
- InnerMsg.sendMsg(0, msgData)
- end
- -- 报名
- function AB_Join(human)
- local unionId = human.db.unionUuid
- local msgRet = Msg.gc.GC_AB_JOIN
- if not unionId then
- msgRet.Joinstate = 3
- return Msg.send(msgRet, human.fd)
- end
- -- if not isOpen(human) then
- -- return Broadcast.sendErr(human, Lang.AB_JOIN_COND_NOT_SATIFY)
- -- end
- local wDay = getWDay()
- if not table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
- msgRet.Joinstate = 5
- return Msg.send(msgRet, human.fd)
- end
- -- 公会排名前二才能参加
- if not isTopTwoUnion(human) then
- msgRet.Joinstate = 2
- return Msg.send(msgRet, human.fd)
- end
- -- 会长/副会长才能报名
- if not UnionLogic.IsTopTwoManager(human, unionId) then
- return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
- end
- local queryFiles = {name = 1, zhandouli = 1}
- local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
- if not unionInfo then
- return Broadcast.sendErr(human, Lang.DATA_ERR)
- end
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_JOIN
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.unionInfo = {
- name = unionInfo.name,
- power = unionInfo.zhandouli,
- unionId = unionId
- }
- InnerMsg.sendMsg(0, msgData)
- end
- -- 查询所有城池信息
- function AB_AllCity_Query(human)
- if not human.db.unionUuid then
- return
- end
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_ALLCITY_QUERY
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- InnerMsg.sendMsg(0, msgData)
- -- 报名状态查询
- -- local msgData2 = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_JOIN_STATE
- -- msgData2.sourceServerId = Config.SVR_INDEX
- -- msgData2.playerUuid = human.db._id
- -- msgData2.myUnionId = human.db.unionUuid
- -- InnerMsg.sendMsg(0, msgData2)
- end
- -- 查询单个城池的详细信息
- function AB_CityDetailed_Query(human, targetCityId)
- if not AnotherWorldBattleConfig.city[targetCityId] then
- return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
- end
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- msgData.targetCityId = targetCityId
- InnerMsg.sendMsg(0, msgData)
- end
- -- 查询某个城池的某个据点的相信信息
- function AB_PointDetailed_Query(human, targetCityId, targetPointIdx)
- if not AnotherWorldBattleConfig.city[targetCityId] then
- return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
- end
- if 0 >= targetPointIdx or AnotherWorldBattleDefine.AB_POINT_MAX_NUM < targetPointIdx then
- return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
- end
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINTtDETAILED_QUERY
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- msgData.targetCityId = targetCityId
- msgData.targetPointIdx = targetPointIdx
- InnerMsg.sendMsg(0, msgData)
- end
- -- 查询本公会出生点信息
- function AB_BaseCity_Query(human)
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_BASECITY_QUERY
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- InnerMsg.sendMsg(0, msgData)
- end
- -- 查询玩家占领的所有据点信息
- function AB_PlayerOccupyPOint_Query(human)
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- InnerMsg.sendMsg(0, msgData)
- end
- -- 查询公会排行榜
- function AB_UnionRank_Query(human)
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- InnerMsg.sendMsg(0, msgData)
- end
- -- 查询玩家排行榜
- function AB_PlayerRank_Query(human)
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- InnerMsg.sendMsg(0, msgData)
- end
- -- 发起集结
- function AB_Gather(human, targetCityId)
- if not AnotherWorldBattleConfig.city[targetCityId] then
- return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
- end
- local unionId = human.db.unionUuid
- if not unionId then
- return Broadcast.sendErr(human, Lang.AB_NO_UNION)
- end
- -- 会长/副会长才能集结
- if not UnionLogic.IsTopTwoManager(human, unionId) then
- return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANAGER)
- end
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GATHER
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- msgData.targetCityId = targetCityId
- InnerMsg.sendMsg(0, msgData)
- end
- -- 请求挑战某个据点
- function AB_Try_Challenge_Point(human, targetCityId, targetPointIdx)
- local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
- if not combatHero or not next(combatHero) then
- return Broadcast.sendErr(human, Lang.COMBAT_NEED_FIGHT_HERO)
- end
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- msgData.targetCityId = targetCityId
- msgData.targetPointIdx = targetPointIdx
- InnerMsg.sendMsg(0, msgData)
- end
- -- 战斗胜利
- local function challenge_Win(human, args)
- if not human.db.anotherWorlBattle then
- human.db.anotherWorlBattle = {
- startTime = os.time(),
- formation = {}
- }
- end
- -- 把当前战斗阵容数据保存到当前模块,作为防守阵容
- local combatData = CombatPosLogic.getCombatHeroDB(human, CombatDefine.COMBAT_TYPE35)
- local cityId = args.cityId
- local pointIdx = args.pointIdx
- local formationData = human.db.anotherWorlBattle.formation or {}
- formationData[cityId] = formationData[cityId] or {}
- formationData[cityId][pointIdx] = Util.copyTable(combatData)
- -- 把最新的防守英雄uuid列表推送给客户端
- sendDefHeroArr(human)
- --同步到跨服
- local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_CHALLENGE_WIN
- msgData.sourceServerId = Config.SVR_INDEX
- msgData.playerUuid = human.db._id
- msgData.myUnionId = human.db.unionUuid
- msgData.targetCityId = cityId
- msgData.targetPointIdx = pointIdx
- msgData.playerShowInfo = generateShowInfo(human)
- InnerMsg.sendMsg(0, msgData)
- -- 清空战斗阵容
- CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE35)
- end
- ------------------------------------C2N---------------------------------------------------
- -- 错误提示
- function C2N_ErrTips(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local tips = Lang.DATA_ERR
- local errCode = msg.errCode
- if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
- tips = Lang.AB_NOT_OPEN_TIME
- elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
- tips = Lang.AB_NOT_UNION_NUM_EXCEED
- elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
- tips = Lang.AB_UNION_NO_JOIN
- elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
- tips = Lang.DATA_ERR
- elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
- tips = Lang.AB_NOT_OCCUPY_POINT
- elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
- tips = Lang.AB_GATHER_CD
- elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
- tips = Lang.AB_CITY_NOT_ADDJION
- elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
- tips = Lang.AB_JOINED
- end
- Broadcast.sendErr(human, tips)
- end
- -- 跨服返回状态
- function C2N_State(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local msgRet = Msg.gc.GC_AB_GetState
- msgRet.joinState = msg.joinState
- msgRet.systemState = msg.systemState
- if msgRet.joinState == 0 then
- local unionId = human.db.unionUuid
- if not unionId then
- msgRet.Joinstate = 2
- return Msg.send(msgRet, human.fd)
- end
- -- 公会排名前二才行
- if not isTopTwoUnion(human) then
- msgRet.Joinstate = 2
- return Msg.send(msgRet, human.fd)
- end
- end
- Msg.send(msgRet, human.fd)
- end
- -- 报名成功
- function C2N_Join_Succ(msg)
- local unionId = msg.myUnionId
- UnionLogic.Join_AB_Succ(unionId)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local msgRet = Msg.gc.GC_AB_JOIN
- msgRet.Joinstate = 1
- Msg.send(msgRet, human.fd)
- end
- -- 跨服返回的所有城池数据
- function C2N_AllCity_Query(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
- msgRet.myBaseCityId = msg.myUnionBaseCityId
- local cityArrMsg = msgRet.cityArr
- cityArrMsg[0] = 0
- local useCfg = false
- local cityData = msg.cityArr
- if #msg.cityArr <= 0 then
- useCfg = true
- cityData = AnotherWorldBattleConfig.city
- end
- for cityId, cityInfo in ipairs(cityData) do
- cityArrMsg[0] = cityId
- local cityCfg = AnotherWorldBattleConfig.city[cityId]
- cityArrMsg[cityId].cityId = cityId
- cityArrMsg[cityId].cityName = cityCfg.cityName
- cityArrMsg[cityId].cityLv = cityCfg.cityLv
- cityArrMsg[cityId].occupyPointNum = useCfg and 0 or cityInfo.occupyPointNum
- cityArrMsg[cityId].occupyUnionName = (useCfg and "" or cityInfo.occupyUnionName) or ""
- cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
- for i, cId in ipairs(cityCfg.adJoinCityArr) do
- cityArrMsg[cityId].adJoinCityArr[i] = cId
- end
- end
- msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
- for i, cityId in ipairs(msg.myOccupyCityArr) do
- msgRet.myOccupyCityArr[i] = cityId
- end
- Msg.send(msgRet, human.fd)
- end
- -- 跨服返回某个城池详细数据
- function C2N_CityDetailed_Query(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
- local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
- msgRet.cityId = msg.targetCityId
- msgRet.cityLv = cityCfg.cityLv
- msgRet.cityIconId = cityCfg.cityIconId
- Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2])
- local myUnionAwardNum = calcCitysAward(msg.myUnionOccupyArr)
- Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
- -- 活动没有进入战斗阶段时, 使用默认数据
- if #msg.pointArr == 0 then
- for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
- msg.pointArr[i] = {}
- end
- end
- msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
- for pointIdx, pointInfo in ipairs(msg.pointArr) do
- if pointInfo.occupyUnionName then
- msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
- msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
- msgRet.pointArr[pointIdx].power = pointInfo.power
- msgRet.pointArr[pointIdx].isCanChallenge = pointInfo.isCanChallenge
- else
- msgRet.pointArr[pointIdx].occupyUnionName = ""
- msgRet.pointArr[pointIdx].occupyPlayerName = "防守者".. pointIdx --待改
- msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
- msgRet.pointArr[pointIdx].isCanChallenge = pointInfo.isCanChallenge
- end
- end
- msgRet.gatherState = msg.gatherState
- if msg.gatherState == 1 then
- -- 公会会长/副会长才能集结
- if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
- msgRet.gatherState = 0
- end
- end
- Msg.send(msgRet, human.fd)
- end
- -- 跨服返回某个据点数据
- function C2N_PointDetailed_Query(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local pointInfo = msg.pointInfo
- local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
- msgRet.isCanChallenge = pointInfo.isCanChallenge or 0
- if pointInfo.name then
- msgRet.name = pointInfo.name
- msgRet.power = pointInfo.power
- msgRet.head = pointInfo.head
- msgRet.headFrame = pointInfo.headFrame
- msgRet.defLv = pointInfo.defLv
- msgRet.heroArr[0] = #pointInfo.heroArr
- for i, heroInfo in ipairs(pointInfo.heroArr) do
- msgRet.heroArr[i].heroBody = heroInfo.heroBody
- msgRet.heroArr[i].heroStar = heroInfo.heroStar
- msgRet.heroArr[i].heroLv = heroInfo.heroLv
- msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
- msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
- end
- else
- msgRet.name = "防守者" .. msg.targetPointIdx -- 待改
- msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
- msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
- msgRet.defLv = 200
- local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
- msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
- msgRet.heroArr[0] = 0
- local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
- for idx, monsterInfo in ipairs(monsterOutConfig.member) do
- if idx > 6 then
- break
- end
- msgRet.heroArr[0] = idx
- local monsterID = monsterInfo[1]
- local mcf = MonsterExcel.monster[monsterID]
- msgRet.heroArr[idx].heroBody = mcf.body
- msgRet.heroArr[idx].heroStar = mcf.star
- msgRet.heroArr[idx].heroLv = monsterInfo[2]
- msgRet.heroArr[idx].heroCamp = mcf.camp
- msgRet.heroArr[idx].heroIcon = mcf.head
- end
- end
- Msg.send(msgRet, human.fd)
- end
- -- 跨服返回公会出生点数据
- function C2N_BaseCity_Query(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local baseCityInfo = msg.baseCityInfo
- local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
- local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
- msgRet.cityIconId = cityCfg.cityIconId
- Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2])
- local myUnionAwardNum = calcCitysAward(baseCityInfo.myUnionOccupyArr)
- Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
- msgRet.cityIconId = baseCityInfo.occupyPointNum
- msgRet.occupyPointNum = baseCityInfo.occupyPointNum
- msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
- msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
- msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
- msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
- Msg.send(msgRet, human.fd)
- end
- -- 跨服返回玩家占领的据点数据
- function C2N_PlayerOccupyPoint_Query(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
- local myPointArr = msg.myPointArr
- myPointArr[0] = 0
- for idx, pointInfo in ipairs(msg.occupyPointArr) do
- myPointArr[0] = idx
- local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
- myPointArr[idx].cityIconId = cityCfg.cityIconId
- myPointArr[idx].cityLv = cityCfg.cityLv
- myPointArr[idx].pointIdx = pointInfo.pointIdx
- myPointArr[idx].power = pointInfo.power
- myPointArr[idx].heroArr[0] = #pointInfo.heroArr
- for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
- local hero = myPointArr[idx].heroArr[heroIdx]
- hero.heroBody = heroInfo.heroBody
- hero.heroStar = heroInfo.heroStar
- hero.heroLv = heroInfo.heroLv
- hero.heroCamp = heroInfo.heroCamp
- hero.heroIcon = heroInfo.heroIcon
- end
- end
- Msg.send(msgRet, human.fd)
- end
- --跨服返回公会排行榜数据
- function C2N_UnionRank_Query(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
- msgRet.unionRankArr[0] = 0
- msgRet.myUnionRank = msg.myUnionRank
- for rank, rankdData in ipairs(msg.unionRankArr) do
- msgRet.unionRankArr[0] = rank
- msgRet.unionRankArr[rank] = {
- name = rankdData.name,
- power = rankdData.power,
- cityNum = rankdData.occupyCityNum,
- pointNum = rankdData.occupyPointNum,
- }
- end
- Msg.send(msgRet, human.fd)
- end
- --跨服返回玩家排行榜数据
- function C2N_PlayerRank_Query(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
- msgRet.playerRankArr[0] = 0
- msgRet.myRank = msg.myRank
- for rank, rankdData in ipairs(msg.playerRankArr) do
- msgRet.playerRankArr[0] = rank
- msgRet.playerRankArr[rank] = {
- name = rankdData.name,
- power = rankdData.power,
- pointNum = rankdData.occupyPointNum,
- pointWeight = rankdData.pointWeight,
- }
- end
- Msg.send(msgRet, human.fd)
- end
- -- 跨服返回要挑战的据点的数据(据点可以被挑战)
- function C2N_Challenge_Point_OK(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- return
- end
- local pointInfo = msg.pointInfo
- human.AB_Battle_Cache = {
- isGather = pointInfo.isGather,
- cityId = pointInfo.targetCityId,
- pointIdx = pointInfo.targetPointIdx,
- }
- if pointInfo.occupySrvId then -- 玩家占领
- local args = {
- combatType = CombatDefine.COMBAT_TYPE35,
- nServerIndex = pointInfo.occupySrvId,
- param = pointInfo.occupyPlayerUuid,
- extraArgs = {
- cityId = pointInfo.targetCityId,
- pointIdx = pointInfo.targetPointIdx,
- useDef = true,
- }
- }
- MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
- else
- -- 机器人
- CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
- end
- end
- -- 跨服通知据点被别的玩家占领了
- function C2N_Point_Lose(msg)
- local human = ObjHuman.onlineUuid[msg.playerUuid]
- if not human then
- local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
- if not db then
- return
- end
- human = {}
- human.db = db
- end
- -- 更新防守阵容数据
- local loseCityId = msg.loseCityId
- local losePointIdx = msg.losePointIdx
- local formationData = human.db.anotherWorlBattle.formation
- formationData[loseCityId][losePointIdx] = nil
- -- 玩家不在线, 手动保存数据
- if not human.fd then
- ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
- end
- -- 发邮件
- local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
- MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, mailCfg.content, nil, mailCfg.senderName or "GM")
- -- 把最新的防守阵容数据推给客户端
- if human.fd then
- sendDefHeroArr(human)
- end
- end
- local function genAwardObjArr(unionOccupyInfo)
- local function calcMins(timeArr)
- local minuteVal = 0
- for _, timeTb in ipairs(timeArr or {}) do
- local sec = timeTb[2] - timeTb[1]
- if sec > 0 then
- minuteVal = minuteVal + math.floor(sec / 60)
- end
- end
- return minuteVal
- end
- if not unionOccupyInfo.playerUuidArr or #unionOccupyInfo.playerUuidArr <= 0 then
- return
- end
- local itemList = {}
- local item_185_Id = 185
- local item_185_Num = 0
- item_185_Num = item_185_Num + (unionOccupyInfo.occuoyPointNum or 0) -- 待优化
- for _, cityInfo in ipairs(unionOccupyInfo.occupyCityArr) do
- local cityId = cityInfo[1]
- local occupyTimeArr = cityInfo[2]
- local isOccupy = cityInfo[3]
- local cityCfg = AnotherWorldBattleConfig.city[cityId]
- local totalMinVal = calcMins(occupyTimeArr)
- if totalMinVal > 0 then
- local itemId, itemNum = cityCfg.cityAward[1], cityCfg.cityAward[2]
- itemList[itemId] = totalMinVal * itemNum
- end
- if cityCfg and isOccupy then
- if cityCfg.isBaseCity == 1 then
- item_185_Num = item_185_Num + 20
- else
- if cityCfg.cityLv == 2 then
- item_185_Num = item_185_Num + 2
- elseif cityCfg.cityLv == 3 then
- item_185_Num = item_185_Num + 3
- elseif cityCfg.cityLv == 4 then
- item_185_Num = item_185_Num + 5
- elseif cityCfg.cityLv == 5 then
- item_185_Num = item_185_Num + 20
- end
- end
- end
- end
- if item_185_Num > 0 then
- itemList[item_185_Id] = item_185_Num
- end
- local itemArr = {}
- for itemId, itemNum in pairs(itemList) do
- itemArr[#itemArr+1] = { itemId, itemNum }
- end
- local awardObjArr = {}
- for _, playerUuid in ipairs(unionOccupyInfo.playerUuidArr) do
- awardObjArr[#awardObjArr+1] = {playerUuid, itemArr}
- end
- return awardObjArr
- end
- -- 发奖
- function C2N_IssueReward(msg)
- local awardObjArr = genAwardObjArr(msg.unionOccupyInfo)
- if awardObjArr then
- local issueRewardQueue = createRewardQueue()
- for _, obj in ipairs(awardObjArr) do
- issueRewardQueue:add(obj)
- end
- issueRewardQueue:insertDB()
- end
- end
- -------------------------------------------战斗---------------------------------
- function getCombatMonsterOutID(human, side, args)
- if side ~= CombatDefine.DEFEND_SIDE then return end
- local cityId = args[2]
- local cityCfg = AnotherWorldBattleConfig.city[cityId]
- return cityCfg.pointMonsterId
- end
- function getCombatObjList(human, side, args, combatType, extraArgs)
- if side == CombatDefine.ATTACK_SIDE and not human then return end
- if side == CombatDefine.DEFEND_SIDE and human then
- return
- end
- if not human then
- local uuid = args[1]
- local db = RoleDBLogic.getDb(uuid)
- if not db then
- return
- end
- human = {}
- human.db = db
- end
- return CombatLogic.getHumanObjList(human, combatType, extraArgs)
- end
- function getCombatHeros(human, combatType, args)
- if not human.db.anotherWorlBattle then
- return
- end
- local formation = human.db.anotherWorlBattle.formation
- if not formation then
- return
- end
- local cityId, pointIdx = args.cityId, args.pointIdx
- if formation[cityId] and formation[cityId][pointIdx] then
- local combatHeroDB = formation[cityId][pointIdx]
- return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
- end
- end
- function onFightBegin(human, cbParam, combatType, param)
- if not human.AB_Battle_Cache or human.AB_Battle_Cache.isGather ~= 1 then
- return
- end
- local attrList = {
- [RoleDefine.HURT_RATE] = 1000,
- [RoleDefine.JIANSHANG_RATE] = 1000,
- }
- for index = 1, CombatDefine.COMBAT_HERO_CNT do
- local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
- local atkObj = CombatImpl.objList[atkPos]
- if atkObj then
- for attrId, attrVal in pairs(attrList) do
- atkObj.sysAttr[attrId] = (atkObj.sysAttr[attrId] or 0) + attrVal
- end
- atkObj.isSysAttrChange = true
- end
- end
- end
- function onFightEnd(human, result, type, cbParam, combatInfo)
- if result == CombatDefine.RESULT_WIN then
- challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
- end
- human.AB_Battle_Cache = nil
- end
|