| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336 |
- -- 异界之战(跨服)
- local InnerMsg = require("core.InnerMsg")
- local Log = require("common.Log")
- local Timer = require("core.Timer")
- local Util = require("common.Util")
- local MiddleManager = require("middle.MiddleManager")
- local AnotherWorldBattleDB = require("anotherWorldBattle.AnotherWorldBattleDB")
- local AnotherWorldBattleDefine = require("anotherWorldBattle.AnotherWorldBattleDefine")
- local CombatDefine = require("combat.CombatDefine")
- local AnotherWorldBattleConfig = require("excel.anotherWorldBattle")
- -- 当天处于星期几(星期六为7, 星期天为1)
- local wDay
- local function updateWDay()
- wDay = Util.getWeekDay()
- end
- local function getTodayStartTime()
- local now = os.time()
- return Util.getDayStartTime(now)
- end
- local function isOpen()
- if not wDay then
- updateWDay()
- end
- if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
- return false
- end
- local now = os.time()
- local toDayStartTime = getTodayStartTime()
- if wDay == AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] and now < (toDayStartTime + AnotherWorldBattleDefine.AB_START_SEC) then
- return false
- end
- -- 周三23点过后暂时不算结束
- -- if wDay == AnotherWorldBattleDefine.OPEN_WDAY_AREA[2] and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
- -- return false
- -- end
- local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
- if lastRoundStartTime ~= 0 then
- local diffDays = Util.diffDay(lastRoundStartTime)
- -- < 5天说明处于本轮活动的开启时间
- if diffDays > 5 and diffDays <= AnotherWorldBattleDefine.AB_SUB_DAY then
- return false
- end
- end
- return true
- end
- local function isRunning()
- if not isOpen() then
- return false
- end
- -- 周三23点过后暂时不算结束
- local now = os.time()
- local toDayStartTime = getTodayStartTime()
- if wDay == AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
- return false
- end
- return true
- end
- -- 进入新一轮的处理
- local function newRoundHandle()
- local stage = AnotherWorldBattleDB.GetStage()
- -- 上一轮奖励没有发放, 在新一轮开始时, 先发奖
- if stage == AnotherWorldBattleDefine.AB_STATE_AWARD then
- -- AwardPrizesHandle()
- end
- -- 重置数据
- AnotherWorldBattleDB.ResetData()
- -- 更新状态
- AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_JOIN)
- -- 更新活动开始时间
- local now = os.time()
- AnotherWorldBattleDB.UpdateLastRoundStartTime(now)
- end
- -- 能否进入新一轮的报名阶段
- local function joinStageCheck()
- local stage = AnotherWorldBattleDB.GetStage()
- if stage ~= AnotherWorldBattleDefine.AB_STATE_END and stage ~= AnotherWorldBattleDefine.AB_STATE_AWARD then
- return
- end
- -- local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
- -- local diffDays = Util.diffDay(lastRoundStartTime)
- -- 上一轮活动结束时间为0 或 当前时间 - 上一轮活动开启时间 > 9天, 开启新一轮活动
- -- if lastRoundStartTime == 0 or diffDays > AnotherWorldBattleDefine.AB_SUB_DAY then
- newRoundHandle()
- -- end
- end
- -- 公会分组算法
- local function groupingAlgorithm(unionArray, len)
- local usedTb = {}
- local groupArr = {}
- local function getNextUnuseIdx(nowIdx)
- for i=nowIdx, len do
- if not usedTb[i] then
- return i
- end
- end
- end
- local function checkRandIdx(startIdx, endIdx)
- local tbl= {}
- for i= startIdx, endIdx do
- if not usedTb[i] then
- table.insert(tbl, i)
- end
- end
- return tbl
- end
- local currentIdx = 1
- local selectNum, cnt = 0, 0
- while currentIdx <= len do
- currentIdx = getNextUnuseIdx(currentIdx)
- if not currentIdx then
- break
- end
- local startIdx = currentIdx + 1
- local endIdx = math.min(currentIdx + 19, len)
- groupArr[#groupArr+1] = { unionArray[currentIdx] }
- selectNum = selectNum + 1
- cnt = math.min(AnotherWorldBattleDefine.AB_GROUP_UNION_NUM - 1, len - selectNum )
- for i=1, cnt do
- local correctTb = checkRandIdx(startIdx, endIdx)
- local matchIdx = correctTb[math.random(1, #correctTb)]
- usedTb[currentIdx] = true
- usedTb[matchIdx] = true
- table.insert(groupArr[#groupArr], unionArray[matchIdx])
- selectNum = selectNum + 1
- end
- currentIdx = currentIdx + 1
- end
- return groupArr
- end
- -- 分组
- local function grouping()
- local function genUnionIdArray(sourceUnionArr, targetUnionArr)
- for k, v in ipairs(sourceUnionArr) do
- targetUnionArr[k] = v.unionId
- end
- end
- local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
- if not joinUnionArr then
- -- 没有公会参加, 本轮活动结束
- local now = os.time()
- AnotherWorldBattleDB.UpdateLastRoundStartTime(now)
- return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
- end
- local len = #joinUnionArr
- if len > AnotherWorldBattleDefine.AB_GROUP_UNION_NUM then
- table.sort(joinUnionArr, function (a, b)
- return a.power > b.power
- end)
- end
- local unionIdArr = {}
- genUnionIdArray(joinUnionArr, unionIdArr)
- local newGroupArray
- if len > AnotherWorldBattleDefine.AB_GROUP_UNION_NUM then
- newGroupArray = groupingAlgorithm(unionIdArr, len)
- else
- newGroupArray = { unionIdArr }
- end
- AnotherWorldBattleDB.UpdateGroupArray(newGroupArray)
- end
- -- 给各个分组中的公会随机分配出生点
- local function randomBaseCity()
- local baseCityIdArr = {}
- for cityId, cityCfg in ipairs(AnotherWorldBattleConfig.city) do
- if cityCfg.isBaseCity == 1 then
- baseCityIdArr[#baseCityIdArr+1] = cityId
- end
- end
- local now = os.time()
- local groupArray = AnotherWorldBattleDB.GetGroupArray()
- for _, unionIdArr in ipairs(groupArray) do
- -- 乱序
- table.shuffle(baseCityIdArr)
- for i, unionId in ipairs(unionIdArr) do
- local union = AnotherWorldBattleDB.GetUnionData(unionId)
- if union then
- union.baseCityId = baseCityIdArr[i]
- union.baseCityStartTime = now
- AnotherWorldBattleDB.UpdateUnionData(unionId, union)
- end
- end
- end
- end
- -- 统计单个公会的占领情况, 用于发放奖励
- local function genUnionOccupyInfo(unionId, union)
- local occupyTb = {
- occupyCityArr = {}, -- 曾占领, 当前还占领的城池列表
- occuoyPointNum = 0,
- playerUuidArr = {},
- }
- local now = os.time()
- local tbl = occupyTb.occupyCityArr
- tbl[#tbl+1] = { union.baseCityId, { {union.baseCityStartTime, union.baseCityEndTime or now} }, true }
- for cityId, cityIno in pairs(union.occupCityList or {}) do
- if cityIno.isOccupy or cityIno.occupyTimeArr then
- -- 更新目前还占领的城池的占领结束时间
- local lastTimeTb = cityIno.occupyTimeArr[#cityIno.occupyTimeArr]
- if #lastTimeTb == 1 then
- lastTimeTb[2] = now
- end
- tbl[#tbl+1] = { cityId, cityIno.occupyTimeArr, cityIno.isOccupy }
- end
- for _,_ in pairs(cityIno.occupyPointList) do
- occupyTb.occuoyPointNum = occupyTb.occuoyPointNum + 1
- end
- end
- local tbl2 = occupyTb.playerUuidArr
- for playerUuid in pairs(union.playerList) do
- tbl2[#tbl2+1] = playerUuid
- end
- -- 防止本次没有正常发放奖励,后续补发时, 结束时间异常的情况
- union.baseCityEndTime = now
- AnotherWorldBattleDB.UpdateUnionData(unionId, union)
- return occupyTb
- end
- -- 发奖
- local function issueReward(sourceServerId, occupyInfo)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ISSUEREWARD
- msgData.unionOccupyInfo = occupyInfo
- local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 奖励发放管理函数
- local function issueRewardManager()
- local delay_sec = 0
- local unionList = AnotherWorldBattleDB.GetUnionList()
- for unionId, union in pairs(unionList) do
- local occupyInfo = genUnionOccupyInfo(unionId, union)
- delay_sec = delay_sec + 5
- Timer.addLater(delay_sec, issueReward, union.serverId, occupyInfo)
- end
- end
- function oneMin()
- if _G.is_middle ~= true then return end
- if not isOpen() then
- return
- end
- -- 与 onHour() 处理错开
- if Util.getMin() == 0 then
- return
- end
- -- 处于报名阶段
- if table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
- joinStageCheck()
- end
- local now = os.time()
- -- 报名阶段 -> 战斗阶段
- if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
- local stage = AnotherWorldBattleDB.GetStage()
- local toDayStartTime = getTodayStartTime()
- if stage == AnotherWorldBattleDefine.AB_STATE_JOIN and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_START_SEC) then
- -- 分组
- grouping()
- -- 给各个分组中的公会随机分配出生点
- randomBaseCity()
- -- 最后更新活动阶段
- return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_BATTLE)
- end
- end
- -- 战斗阶段 -> 发奖阶段
- local toDayStartTime = getTodayStartTime()
- if wDay == AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
- local stage = AnotherWorldBattleDB.GetStage()
- if stage == AnotherWorldBattleDefine.AB_STATE_BATTLE then
- -- 改为发奖阶段
- AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_AWARD)
- -- 开始发奖
- issueRewardManager()
- -- 改为结束阶段
- return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
- end
- end
- end
- function onHour(hour)
- if _G.is_middle ~= true then return end
- if hour == 0 or not wDay then
- updateWDay()
- end
- if not isOpen() then
- return
- end
- -- 处于报名阶段
- if table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
- joinStageCheck()
- end
- local now = os.time()
- -- 报名阶段 -> 战斗阶段
- if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
- local stage = AnotherWorldBattleDB.GetStage()
- local toDayStartTime = getTodayStartTime()
- if stage == AnotherWorldBattleDefine.AB_STATE_JOIN and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_START_SEC) then
- -- 分组
- grouping()
- -- 给各个分组中的公会随机分配出生点
- randomBaseCity()
- -- 最后更新活动阶段
- return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_BATTLE)
- end
- end
- -- 战斗阶段 -> 发奖阶段
- local toDayStartTime = getTodayStartTime()
- if wDay == AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
- local stage = AnotherWorldBattleDB.GetStage()
- if stage == AnotherWorldBattleDefine.AB_STATE_BATTLE then
- AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_AWARD)
- -- 开始发奖
- issueRewardManager()
- -- 改为结束阶段
- return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
- end
- end
- end
- ------------------------------------C2N---------------------------------------------------
- -- 错误提示
- local function errTips(sourceServerId, playerUuid, errCode)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_TIPS
- msgData.playerUuid = playerUuid
- msgData.errCode = errCode
- local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 通知玩家,据点被别的玩家占领了
- local function pointLose(sourceServerId, playerUuid, loseCityId, losePointIdx)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINT_LOSE
- msgData.playerUuid = playerUuid
- msgData.loseCityId = loseCityId
- msgData.losePointIdx = losePointIdx
- local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- ------------------------------------N2C---------------------------------------------------
- -- 统计单个服公会报名数量
- local function calcSvrUnionJoinNum(serverId)
- local num = 0
- local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
- if not joinUnionArr then
- return num
- end
- for _, unionInfo in ipairs(joinUnionArr) do
- if unionInfo.serverId == serverId then
- num = num + 1
- end
- end
- return num
- end
- -- 计算多个英雄的总战力
- local function calcHerosPower(heroArr)
- local power = 0
- for _, v in ipairs(heroArr) do
- power = power + v.heroPower
- end
- return power
- end
- -- 统计公会占领不同等级的城池数量
- local function calcOccupyCityNum(occupCityList, cityLv)
- if not occupCityList then
- return 0
- end
- local num = 0
- for cityId, occupyInfo in pairs(occupCityList) do
- if occupyInfo.isOccupy then
- local cityCfg = AnotherWorldBattleConfig.city[cityId]
- if cityCfg.cityLv == cityLv then
- num = num + 1
- end
- end
- end
- return num
- end
- -- 统计公会占领的据点数量
- local function calcOccupyPointNum(occupCityList)
- if not occupCityList then
- return 0
- end
- local num = 0
- for cityId, occupyInfo in pairs(occupCityList) do
- for _,_ in pairs(occupyInfo.occupyPointList) do
- num = num + 1
- end
- end
- return num
- end
- -- 获取公会占领的城池列表
- local function getUnionOccupyArr(unionId)
- local union = AnotherWorldBattleDB.GetUnionData(unionId)
- if not union then
- return
- end
- local occupyCityArr = {}
- occupyCityArr[#occupyCityArr+1] = union.baseCityId
- for cityId, occupyInfo in pairs(union.occupCityList or {}) do
- if occupyInfo.isOccupy then
- occupyCityArr[#occupyCityArr+1] = cityId
- end
- end
- return occupyCityArr
- end
- -- 检查某个城池与公会占领的城池是否相邻
- local function isadJoin(cityIdArr, targetCityId)
- if not cityIdArr then
- return false
- end
- local targetCityCfg = AnotherWorldBattleConfig.city[targetCityId]
- if not targetCityCfg then
- return false
- end
- for _, cityId in ipairs(targetCityCfg.adJoinCityArr) do
- if table.find(cityIdArr, cityId) then
- return true
- end
- end
- return false
- end
- -- 检查某个据点是否能被玩家挑战
- local function isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, playerUuid)
- -- 活动未开启
- if not isRunning() then
- return false
- end
- -- 公会没有参加活动
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- return false
- end
- local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- local tagetCityData = cityList[targetCityId]
- if not tagetCityData then
- return false
- end
- -- 城池已被本公会占领
- if tagetCityData.occupyUnion and tagetCityData.occupyUnion == myUnionId then
- return false
- end
- local targetPointData = tagetCityData.pointArr[targetPointIdx]
- if not targetPointData then
- return false
- end
- -- 据点已被本公会占领
- if targetPointData.unionId and targetPointData.unionId == myUnionId then
- return false
- end
- local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
- if not myUnionData then
- return false
- end
- -- 城池是否相邻
- local occupyCityArr = getUnionOccupyArr(myUnionId)
- if not isadJoin(occupyCityArr, targetCityId) then
- return false
- end
- -- 每个玩家最多占领据点数量是否超出
- local playerOccupyPonitNum = 0
- if myUnionData.playerList and myUnionData.playerList[playerUuid] then
- local heroList = myUnionData.playerList[playerUuid].heroList
- for cityId, pointList in pairs(heroList) do
- for _, _ in pairs(pointList) do
- playerOccupyPonitNum = playerOccupyPonitNum + 1
- end
- end
- end
- if playerOccupyPonitNum >= AnotherWorldBattleDefine.AB_PLAYER_OCCUPY_POINT_MAX_NUM then
- return false
- end
- return true
- end
- -- 公会是否能报名
- local function isCanJoin(sourceServerId, myUnionId)
- if not isRunning() then
- return 2
- end
- local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
- for _, unionData in ipairs(joinUnionArr or {}) do
- if unionData.unionId == myUnionId then
- return 1
- end
- end
- local num = calcSvrUnionJoinNum(sourceServerId)
- if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
- return 2
- end
- return 0
- end
- -- 检查城池是否被己方公会完全占领
- local function isCompleteOccupy(cityData, myUnionId)
- for _, pointInfo in ipairs(cityData.pointArr) do
- if not pointInfo.unionId or pointInfo.unionId ~= myUnionId then
- return false
- end
- end
- return true
- end
- -- 查询玩家是否上榜
- local function getPlayerRank(playerRankList, playerUuid)
- for _, rankData in ipairs(playerRankList) do
- if rankData.playerUuid == playerUuid then
- return true
- end
- end
- return false
- end
- -- 更新公会排行榜数据
- local function updateUnionRanktData(unionRankList, unionId, cityNum, pointNum)
- for rank, rankData in ipairs(unionRankList) do
- if rankData.unionId == unionId then
- unionRankList[rank].occupyCityNum = unionRankList[rank].occupyCityNum + cityNum
- unionRankList[rank].occupyPointNum = unionRankList[rank].occupyPointNum + pointNum
- end
- end
- end
- -- 更新玩家排行榜数据
- local function updatePlayerRanktData(playerRankList, playerUuid, pointNum, pointWeight)
- local playerRank = 0
- for rank, rankData in ipairs(playerRankList) do
- if rankData.playerUuid == playerUuid then
- playerRank = rank
- end
- end
- if playerRank ~= 0 then
- playerRankList[playerRank].pointNum = playerRankList[playerRank].pointNum + pointNum
- playerRankList[playerRank].pointAllWeight = playerRankList[playerRank].pointAllWeight + pointWeight
- end
- end
- -- 查询状态
- function N2C_Get_State(msg)
- local sourceServerId = msg.sourceServerId
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_GET_STATE
- msgData.playerUuid = msg.playerUuid
- local stage = AnotherWorldBattleDB.GetStage()
- msgData.systemState = stage
- msgData.joinState = 0
- if stage == 0 then
- local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
- if lastRoundStartTime == 0 then
- msgData.systemState = 0
- end
- end
- local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
- for _, unionData in ipairs(joinUnionArr or {}) do
- if unionData.unionId == msg.myUnionId then
- msgData.joinState = 1
- end
- end
- local num = calcSvrUnionJoinNum(sourceServerId)
- if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
- msgData.joinState = 2
- end
- local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 报名
- function N2C_Join(msg)
- local sourceServerId = msg.sourceServerId
- local playerUuid = msg.playerUuid
- local unionInfo = msg.unionInfo
- local state = isCanJoin(sourceServerId, unionInfo.unionId)
- if state == 2 then
- return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_1)
- elseif state == 1 then
- return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_8)
- end
- local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
- joinUnionArr = joinUnionArr or {}
- joinUnionArr[#joinUnionArr+1] = {
- unionId = unionInfo.unionId,
- power = unionInfo.power,
- serverId = sourceServerId
- }
- AnotherWorldBattleDB.UpdateJoinUnionArr(joinUnionArr)
- local unionList = AnotherWorldBattleDB.GetUnionList()
- unionList = unionList or {}
- unionList[unionInfo.unionId] = {
- serverId = sourceServerId,
- power = unionInfo.power,
- name = unionInfo.name,
- }
- AnotherWorldBattleDB.UpdateUnionList(unionList)
- -- 通知报名成功
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_JOIN
- msgData.playerUuid = playerUuid
- msgData.myUnionId = unionInfo.unionId
- local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询所有城池信息
- function N2C_AllCity_Query(msg)
- local myUnionId = msg.myUnionId
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ALLCITY_QUERY
- msgData.cityArr = {}
- msgData.playerUuid = msg.playerUuid
- msgData.myUnionBaseCityId = 0
- msgData.myOccupyCityArr = {}
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- -- 报名阶段, 或者活动开未开启过处于默认的结束状态
- local stage = AnotherWorldBattleDB.GetStage()
- if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
- return InnerMsg.sendMsg(fd, msgData)
- end
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- if not cityList then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- local cityArrMsg = msgData.cityArr
- local unionList = AnotherWorldBattleDB.GetUnionList()
- msgData.myUnionBaseCityId = unionList[myUnionId] and unionList[myUnionId].baseCityId or 0
- for cityId, cityInfo in ipairs(cityList) do
- cityArrMsg[cityId] = { occupyPointNum = 0 }
- if cityInfo.occupyUnion then
- cityArrMsg[cityId].occupyUnionName = unionList[cityInfo.occupyUnion] and unionList[cityInfo.occupyUnion].name
- end
- for _, pointInfo in ipairs(cityInfo.pointArr) do
- if pointInfo.unionId and pointInfo.unionId == myUnionId then
- cityArrMsg[cityId].occupyPointNum = cityArrMsg[cityId].occupyPointNum + 1
- end
- end
- end
- msgData.myOccupyCityArr = getUnionOccupyArr(myUnionId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询某个城池的详细信息
- function N2C_CityDetailed_Query(msg)
- local myUnionId = msg.myUnionId
- local playerUuid = msg.playerUuid
- local targetCityId = msg.targetCityId
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
- msgData.playerUuid = playerUuid
- msgData.targetCityId = targetCityId
- msgData.myUnionOccupyArr = {}
- msgData.pointArr = {}
- msgData.gatherState = 0
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- -- 报名阶段, 或者活动开未开启过处于默认的结束状态
- local stage = AnotherWorldBattleDB.GetStage()
- if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
- return InnerMsg.sendMsg(fd, msgData)
- end
- return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- if not cityList or not cityList[targetCityId] then
- return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- local cityData = cityList[targetCityId]
- local myUnionOccupyArr = getUnionOccupyArr(myUnionId)
- msgData.myUnionOccupyArr = myUnionOccupyArr
- local pointArrMsg = msgData.pointArr
- for pointIdx, occupyInfo in ipairs(cityData.pointArr) do
- pointArrMsg[pointIdx] = {}
- local bl = isCanChallengePoint(targetCityId, pointIdx, myUnionId, playerUuid)
- pointArrMsg[pointIdx].isCanChallenge = bl and 1 or 0
- if occupyInfo.unionId and occupyInfo.playerUuid then
- local occupyUnionData = AnotherWorldBattleDB.GetUnionData(occupyInfo.unionId)
- if occupyUnionData then
- pointArrMsg[pointIdx].occupyUnionName = occupyUnionData.name
- pointArrMsg[pointIdx].occupyPlayerName = occupyUnionData.playerList[occupyInfo.playerUuid].name
- pointArrMsg[pointIdx].power = 0
- local heroList = occupyUnionData.playerList[occupyInfo.playerUuid].heroList
- if heroList and heroList[targetCityId] and heroList[targetCityId][pointIdx] then
- pointArrMsg[pointIdx].power = calcHerosPower(heroList[targetCityId][pointIdx])
- end
- end
- end
- end
- local isOk = isRunning()
- if isOk then
- local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
- local occupyCityArr = getUnionOccupyArr(myUnionId)
- isOk = isadJoin(occupyCityArr, targetCityId)
- if isOk then
- if not cityData.occupyUnion or cityData.occupyUnion ~= myUnionId then
- if not myUnionData.gatherInfo then
- msgData.gatherState = 1
- else
- if myUnionData.gatherInfo.gatherCity == targetCityId then
- msgData.gatherState = 2
- else
- local now = os.time()
- if now - myUnionData.gatherInfo.gatherTime >= AnotherWorldBattleDefine.AB_GATHER_CD_SEC then
- msgData.gatherState = 1
- end
- end
- end
- end
- end
- end
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询某个据点信息
- function N2C_PointDetailed_Query(msg)
- local myUnionId = msg.myUnionId
- local targetCityId = msg.targetCityId
- local targetPointIdx = msg.targetPointIdx
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINTDETAILED_QUERY
- msgData.playerUuid = msg.playerUuid
- msgData.targetCityId = targetCityId
- msgData.targetPointIdx = targetPointIdx
- msgData.pointInfo = {}
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- -- 报名阶段, 或者活动开未开启过处于默认的结束状态
- local stage = AnotherWorldBattleDB.GetStage()
- if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
- return InnerMsg.sendMsg(fd, msgData)
- end
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- if not cityList or not cityList[targetCityId] then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- local cityData = cityList[targetCityId]
- local pointData = cityData.pointArr[targetPointIdx]
- if not pointData then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- local pointInfoMsg = msgData.pointInfo
- if pointData.unionId and pointData.playerUuid then
- local union = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
- if not union then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- local playerData = union.playerList and union.playerList[pointData.playerUuid]
- if not playerData then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- pointInfoMsg.name = playerData.name
- pointInfoMsg.head = playerData.head
- pointInfoMsg.headFrame = playerData.headFrame
- pointInfoMsg.defLv = playerData.lv
- local targetHeroArr = playerData.heroList[targetCityId][targetPointIdx]
- if not targetHeroArr then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- pointInfoMsg.power = calcHerosPower(targetHeroArr)
- pointInfoMsg.heroArr = {}
- for i, heroInfo in ipairs(targetHeroArr) do
- pointInfoMsg.heroArr[i] = {
- heroBody = heroInfo.heroBody,
- heroStar = heroInfo.heroStar,
- heroLv = heroInfo.heroLevel,
- heroCamp = heroInfo.heroCamp,
- heroIcon = heroInfo.heroIcon,
- }
- end
- end
- local isCanChallenge = isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, msg.playerUuid)
- pointInfoMsg.isCanChallenge = isCanChallenge and 1 or 0
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询公会出生点信息
- function N2C_BaseCity_Query(msg)
- local myUnionId = msg.myUnionId
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_BASECITY_QUERY
- msgData.playerUuid = msg.playerUuid
- local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
- if not union then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local baseCityInfo = {}
- msgData.baseCityInfo = baseCityInfo
- baseCityInfo.cityId = union.baseCityId
- baseCityInfo.occupyPointNum = calcOccupyPointNum(union.occupCityList)
- baseCityInfo.myUnionOccupyArr = getUnionOccupyArr(myUnionId)
- baseCityInfo.occupyCityLv2Num = calcOccupyCityNum(union.occupCityList, 2)
- baseCityInfo.occupyCityLv3Num = calcOccupyCityNum(union.occupCityList, 3)
- baseCityInfo.occupyCityLv4Num = calcOccupyCityNum(union.occupCityList, 4)
- baseCityInfo.occupyCityLv5Num = calcOccupyCityNum(union.occupCityList, 5)
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询玩家占领的所有据点信息
- function N2C_PlayerOccupyPoint_Query(msg)
- local myUnionId = msg.myUnionId
- local playerUuid = msg.playerUuid
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
- msgData.playerUuid = playerUuid
- msgData.occupyPointArr = {}
- local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
- if not union then
- -- 报名阶段, 或者活动开未开启过处于默认的结束状态
- local stage = AnotherWorldBattleDB.GetStage()
- if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
- return InnerMsg.sendMsg(fd, msgData)
- end
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local playerList = union.playerList
- if not playerList[playerUuid] then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
- end
- local heroList = playerList[playerUuid].heroList
- if not heroList then
- return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- local occupyPointArrMsg = msgData.occupyPointArr
- for cityId, pointList in pairs(heroList) do
- for pointIdx, heroInfoArr in pairs(pointList) do
- occupyPointArrMsg[#occupyPointArrMsg+1] = {
- cityId = cityId,
- pointIdx = pointIdx,
- power = calcHerosPower(heroInfoArr),
- heroArr = {},
- }
- local TargetHeroArr = occupyPointArrMsg[#occupyPointArrMsg].heroArr
- for _, heroInfo in ipairs(heroInfoArr) do
- TargetHeroArr[#TargetHeroArr+1] = {
- heroBody = heroInfo.heroBody,
- heroStar = heroInfo.heroStar,
- heroLv = heroInfo.heroLevel,
- heroCamp = heroInfo.heroCamp,
- heroIcon = heroInfo.heroIcon,
- }
- end
- end
- end
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询公会排行榜
- function N2C_UnionRank_Query(msg)
- local myUnionId = msg.myUnionId
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local unionRankList = AnotherWorldBattleDB.GetUnionRankList(groupId)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
- msgData.playerUuid = msg.playerUuid
- msgData.myUnionRank = 0
- msgData.unionRankArr = {}
- for rank, randkData in ipairs(unionRankList) do
- if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
- break
- end
- local unionName = AnotherWorldBattleDB.GetUnionName(randkData.unionId)
- msgData.unionRankArr[rank] = {
- name = unionName,
- power = randkData.power,
- cityNum = randkData.occupyCityNum,
- pointNum = randkData.occupyPointNum,
- }
- if randkData.unionId == myUnionId then
- msgData.myUnionRank = rank
- end
- end
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询玩家排行榜
- function N2C_PlayerRank_Query(msg)
- local myUnionId = msg.myUnionId
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local playerRankList = AnotherWorldBattleDB.GetPlayerRankList(groupId)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
- msgData.playerUuid = msg.playerUuid
- msgData.myRank = 0
- msgData.playerRankArr = {}
- for rank, randkData in ipairs(playerRankList) do
- if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
- break
- end
- local playerName = AnotherWorldBattleDB.GetPlayerName(randkData.unionId, randkData.playerUuid)
- msgData.unionRankArr[rank] = {
- name = playerName,
- power = randkData.power,
- pointNum = randkData.occupyPointNum,
- pointWeight = randkData.pointAllWeight,
- }
- if randkData.playerUuid == msg.playerUuid then
- msgData.myRank = rank
- end
- end
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 集结
- function N2C_Gather(msg)
- local sourceServerId = msg.sourceServerId
- local playerUuid = msg.playerUuid
- local myUnionId = msg.myUnionId
- if not isRunning() then
- return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_1)
- end
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local targetCityId = msg.targetCityId
- local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
- if not myUnionData then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local now = os.time()
- if myUnionData.gatherInfo then
- local gatherTime = myUnionData.gatherInfo.gatherTime
- if now - gatherTime < AnotherWorldBattleDefine.AB_GATHER_CD_SEC then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_6)
- end
- end
- local occupCityyArr = getUnionOccupyArr(myUnionId)
- if not isadJoin(occupCityyArr, targetCityId) then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_7)
- end
- myUnionData.gatherInfo = myUnionData.gatherInfo or {}
- myUnionData.gatherInfo.gatherTime = now
- myUnionData.gatherInfo.gatherCity = targetCityId
- AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
- N2C_CityDetailed_Query(msg)
- end
- -- 查询据点是否可以被挑战
- function N2C_Try_Challengde_Point(msg)
- local playerUuid = msg.playerUuid
- local myUnionId = msg.myUnionId
- local targetCityId = msg.targetCityId
- local targetPointIdx = msg.targetPointIdx
- local isCanChallenge = isCanChallengePoint(targetCityId, msg.targetPointIdx, msg.myUnionId, playerUuid)
- if not isCanChallenge then
- return
- end
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- local targetPointData = cityList[targetCityId].pointArr[targetPointIdx]
- local pointOccupyInfo = {targetCityId = targetCityId, targetPointIdx = targetPointIdx}
- if targetPointData.unionId then
- local occupyUnionData = AnotherWorldBattleDB.GetUnionData(targetPointData.unionId)
- pointOccupyInfo.occupySrvId = occupyUnionData.serverId
- pointOccupyInfo.occupyPlayerUuid = targetPointData.playerUuid
- end
- local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
- if myUnionData.gatherInfo and myUnionData.gatherInfo.gatherCity == targetCityId then
- pointOccupyInfo.isGather = 1
- end
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
- msgData.playerUuid = playerUuid
- msgData.targetCityId = targetCityId
- msgData.targetPointIdx = targetPointIdx
- msgData.pointInfo = pointOccupyInfo
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 玩家挑战据点胜利
- function N2C_Point_Challenge_Win(msg)
- local playerUuid = msg.playerUuid
- local myUnionId = msg.myUnionId
- local targetCityId = msg.targetCityId
- local targetPointIdx = msg.targetPointIdx
- local playerShowInfo = msg.playerShowInfo
- if not isRunning() then
- return
- end
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- if not groupId then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
- if not myUnionData then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
- end
- local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- local cityData = cityList[targetCityId]
- local pointData = cityData.pointArr[targetPointIdx]
- local unionRankList = AnotherWorldBattleDB.GetUnionRankList(groupId)
- local playerRankList = AnotherWorldBattleDB.GetPlayerRankList(groupId)
- local pointWeight = AnotherWorldBattleConfig.city[targetCityId].pointWeight
- -- 防守方是真实玩家
- if pointData.unionId and pointData.playerUuid then
- -- 更新防守方公会数据
- local defUnionData = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
- local defOccupCityList = defUnionData.occupCityList
- local cityNum, pointNum = 0, -1
- -- 防守方之前占领了城池
- if defOccupCityList[targetCityId].isOccupy then
- -- 修改防守方的占领状态
- defOccupCityList[targetCityId].isOccupy = false
- -- 更新防守方对该城池的最后占领时间
- local defOccupyTimeArr = defOccupCityList[targetCityId].occupyTimeArr
- defOccupyTimeArr[#defOccupyTimeArr][2] = os.time()
- -- 删除防守方的该据点的占领者
- local defOccupyPointList = defOccupCityList[targetCityId].occupyPointList
- defOccupyPointList[targetCityId] = nil
- -- 删除防守方玩家的防守阵容数据
- local defPlayData = defUnionData.playerList[pointData.playerUuid]
- defPlayData.heroList[targetCityId][targetPointIdx] = nil
- cityNum = -1
- end
- -- 更新排行榜数据
- updateUnionRanktData(unionRankList, pointData.unionId, cityNum, pointNum)
- updatePlayerRanktData(playerRankList, pointData.playerUuid, pointNum, -pointWeight)
- -- 通知玩家
- pointLose(defUnionData.serverId, pointData.playerUuid, targetCityId, targetPointIdx)
- -- 更新防守方公会数据
- AnotherWorldBattleDB.UpdateUnionData(pointData.unionId, defUnionData)
- end
- -- 更新据点最新占领者数据
- pointData.unionId = myUnionId
- pointData.playerUuid = playerUuid
- -- 更新进攻方公会数据——据点占有者
- myUnionData.occupCityList = myUnionData.occupCityList or {}
- local occupCityList = myUnionData.occupCityList
- occupCityList[targetCityId] = occupCityList[targetCityId] or {}
- occupCityList[targetCityId].occupyPointList = occupCityList[targetCityId].occupyPointList or {}
- occupCityList[targetCityId].occupyPointList[targetPointIdx] = playerUuid
- --更新进攻者的展示数据
- myUnionData.playerList = myUnionData.playerList or {}
- myUnionData.playerList[playerUuid] = myUnionData.playerList[playerUuid] or {}
- local playerData = myUnionData.playerList[playerUuid]
- playerData.name = playerShowInfo.name
- playerData.lv = playerShowInfo.lv
- playerData.head = playerShowInfo.head
- playerData.headFrame = playerShowInfo.headFrame
- playerData.power = playerShowInfo.power
- playerData.heroList = playerData.heroList or {}
- playerData.heroList[targetCityId] = playerData.heroList[targetCityId] or {}
- playerData.heroList[targetCityId][targetPointIdx] = playerShowInfo.heroArr
- -- 更新公会排行榜数据: 进攻方公会占领据点数量+1
- updateUnionRanktData(unionRankList, myUnionId, 0, 1)
- local bl = getPlayerRank(playerRankList, playerUuid)
- if not bl then -- 如果玩家是第一次挑战据点, 则把玩家加入到玩家排行榜中
- playerRankList[#playerRankList+1] = {
- unionId = myUnionId,
- playerUuid = playerUuid,
- pointNum = 1,
- pointAllWeight = pointWeight,
- power = playerData.power
- }
- else
- updatePlayerRanktData(playerRankList, playerUuid, 1, pointWeight)
- end
- -- 进攻方完全占领城池了
- if isCompleteOccupy(cityData, myUnionId) then
- -- 更新城池的占领公会
- cityData.occupyUnion = myUnionId
- -- 更新进攻方公会对该城池的占领状态
- occupCityList[targetCityId].isOccupy = true
- -- 增加进攻方公会对该城池的占领开始时间戳
- local now = os.time()
- occupCityList[targetCityId].occupyTimeArr = occupCityList[targetCityId].occupyTimeArr or {}
- local occupyTimeArr = occupCityList[targetCityId].occupyTimeArr
- occupyTimeArr[#occupyTimeArr+1] = { now }
- -- 如果占领的是发起集结的城池, 那么取消集结
- if myUnionData.gatherInfo and myUnionData.gatherInfo.gatherCity == targetCityId then
- myUnionData.gatherInfo.gatherCity = 0
- end
- -- 更新公会排行榜数据
- updateUnionRanktData(unionRankList, myUnionId, 1, 0)
- end
- -- 更新进攻方公会数据
- AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
- -- 更新城池数据
- AnotherWorldBattleDB.UpdateCityList(groupId, cityList)
- -- 更新公会/个人排行榜
- AnotherWorldBattleDB.UpdateUnionRankList(groupId, unionRankList)
- AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerRankList)
- end
|