| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753 |
- -- 异界之战(跨服)
- 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
- IssueRewardManager()
- return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
- end
- -- 重置数据
- AnotherWorldBattleDB.ResetData()
- -- 更新状态
- AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_JOIN)
- -- 更新活动开始时间
- local now = os.time()
- AnotherWorldBattleDB.UpdateLastRoundStartTime(now)
- -- 通知所有普通服, 新一轮活动开启了
- ActOpen(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)
- if #correctTb == 0 then break end
- 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, playerListData)
- local occupyTb = {
- occupyCityArr = {}, -- 当前还占领的城池列表
- point2CityIdArr = {}, -- 曾占领/当前还占领的据点的所属城池Id列表
- occuoyPointNum = 0,
- playerUuidArr = {},
- unionId = unionId,
- }
- local now = os.time()
- local t1 = occupyTb.occupyCityArr
- local t2 = occupyTb.point2CityIdArr
- t1[#t1+1] = union.baseCityId
- for cityId, cityIno in pairs(union.occupCityList or {}) do
- if cityIno.isOccupy then
- t1[#t1+1] = cityId
- end
- for _, pointInfo in pairs(cityIno.occupyPointList) do
- if pointInfo.playerUuid then
- if not cityIno.isOccupy then
- occupyTb.occuoyPointNum = occupyTb.occuoyPointNum + 1
- end
- -- 更新据点最新占领时间段的结束时间
- local occupyTimeArr = pointInfo.occupyTimeArr
- local lastTimeTb = occupyTimeArr[#occupyTimeArr]
- if #lastTimeTb == 1 then
- occupyTimeArr[#occupyTimeArr][2] = now
- end
- end
- t2[#t2+1] = {cityId, pointInfo.occupyTimeArr}
- end
- end
- -- 出生点算5个据点
- local baseCiyuTimeArr = { {union.baseCityStartTime, union.baseCityEndTime or now } }
- for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
- t2[#t2+1] = {union.baseCityId, baseCiyuTimeArr}
- end
- for playerUuid, playerInfo in pairs(playerListData) do
- if playerInfo.unionId == unionId then
- occupyTb.playerUuidArr[#occupyTb.playerUuidArr+1] = playerUuid
- end
- 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
- -- 奖励发放管理函数
- function IssueRewardManager()
- local delay_sec = 0
- local unionList = AnotherWorldBattleDB.GetUnionList()
- local playerListData = AnotherWorldBattleDB.GetPlayerList()
- for unionId, union in pairs(unionList) do
- local occupyInfo = genUnionOccupyInfo(unionId, union, playerListData)
- delay_sec = delay_sec + 5
- Timer.addLater(delay_sec, issueReward, union.serverId, occupyInfo)
- end
- end
- -- 检测活动各阶段状态及相关处理
- local function timedStageHandle()
- -- 处于报名阶段
- if table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
- joinStageCheck()
- end
- -- if wDay == AnotherWorldBattleDefine.AB_JOIN_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 or stage == AnotherWorldBattleDefine.AB_STATE_AWARD then
- -- 改为发奖阶段
- AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_AWARD)
- -- 开始发奖
- IssueRewardManager()
- -- 改为结束阶段
- return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
- end
- 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
- timedStageHandle()
- 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
- timedStageHandle()
- 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
- -- 通知所有普通服, 活动开启
- function ActOpen(ti)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ACT_START
- msgData.startTime = ti or os.time()
- local fdList = MiddleManager.MiddleManager_GetAllFD()
- for _, fd in pairs(fdList) do
- InnerMsg.sendMsg(fd, msgData)
- end
- end
- ------------------------------------N2C---------------------------------------------------
- -- 获取自己公会所在分组的Id
- local function getMyUnionGourpId(myUnionId)
- local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
- return groupId
- end
- -- 获取自己公会/所在区服第一公会所在分组Id
- local function getGroupId(myUnionId, myServerId)
- local groupId = getMyUnionGourpId(myUnionId)
- if not groupId then
- groupId = AnotherWorldBattleDB.GetGroupIdByServerId(myServerId)
- end
- return groupId
- end
- -- 统计单个服公会报名数量
- 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
- -- 统计公会占领的据点所属城池Id数组
- local function calcOccupyPointArr(occupCityList)
- local pointInfoArr = {}
- if not occupCityList then
- return pointInfoArr
- end
- for cityId, occupyInfo in pairs(occupCityList) do
- for _, pointInfo in pairs(occupyInfo.occupyPointList) do
- if pointInfo.playerUuid then
- pointInfoArr[#pointInfoArr+1] = cityId
- end
- end
- end
- return pointInfoArr
- 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 calcPlayerOccupyPointNum(playerUuid)
- local playerOccupyPonitNum = 0
- local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- if playerData and playerData.heroList then
- for _, pointList in pairs(playerData.heroList) do
- for _, _ in pairs(pointList) do
- playerOccupyPonitNum = playerOccupyPonitNum + 1
- end
- end
- end
- return playerOccupyPonitNum
- end
- -- 检查某个据点是否能被玩家挑战
- local function isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, playerUuid)
- -- 活动未开启
- if not isRunning() then
- return -1
- end
- -- 公会没有参加活动
- local groupId = getMyUnionGourpId(myUnionId)
- if not groupId then
- return -2
- end
- local tagetCityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
- if not tagetCityData then
- return -3
- end
- local targetPointData = tagetCityData.pointArr[targetPointIdx]
- if not targetPointData then
- return -5
- end
- -- 自己占领了该据点
- if targetPointData.unionId and targetPointData.unionId == myUnionId and targetPointData.playerUuid == playerUuid then
- return 2
- end
- -- 城池已被本公会占领
- if tagetCityData.occupyUnion and tagetCityData.occupyUnion == myUnionId then
- return -4
- end
- -- 据点已被本公会占领
- if targetPointData.unionId and targetPointData.unionId == myUnionId then
- return -6
- end
- local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
- if not myUnionData then
- return -7
- end
- -- 城池是否相邻
- local occupyCityArr = getUnionOccupyArr(myUnionId)
- if not isadJoin(occupyCityArr, targetCityId) then
- return -8
- end
- return 1
- 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 getPlayerChallengeTimesInfo(playerUuid)
- local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- if not playerData then
- return AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_INIT_TIMES, 0
- end
- local now = os.time()
- local subSex = now - playerData.lastTime
- if subSex >= AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC then
- local addTimes = math.floor(subSex / AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC)
- playerData.challengeTimes = math.min(playerData.challengeTimes + addTimes, AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_MAX_TIMES)
- playerData.lastTime = playerData.lastTime + addTimes* AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC
- if playerData.challengeTimes == AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_MAX_TIMES then
- playerData.lastTime = 0
- end
- AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
- end
- return playerData.challengeTimes, playerData.lastTime
- end
- -- 获取城池被占领状态
- local function getCityState(cityData)
- local state = 0
- if cityData.occupyUnion then
- state = 1
- return state
- end
- local occupyPlayerUuid
- for _, pointInfo in ipairs(cityData.pointArr) do
- if pointInfo.playerUuid then
- if not occupyPlayerUuid then
- occupyPlayerUuid = pointInfo.playerUuid
- end
- if pointInfo.playerUuid ~= occupyPlayerUuid then
- state = 2
- break
- end
- end
- end
- return state
- end
- -- 获取公会占领据点的数据
- local function getOccupPointData(unionId)
- local t2 = {}
- local unionData = AnotherWorldBattleDB.GetUnionData(unionId)
- if not unionData then
- return t2
- end
- for cityId, cityIno in pairs(unionData.occupCityList or {}) do
- for _, pointInfo in pairs(cityIno.occupyPointList) do
- t2[#t2+1] = {cityId, pointInfo.occupyTimeArr}
- end
- end
- -- 出生点算5个据点
- local baseCiyuTimeArr = { {unionData.baseCityStartTime, unionData.baseCityEndTime or now } }
- for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
- t2[#t2+1] = {unionData.baseCityId, baseCiyuTimeArr}
- end
- return t2
- end
- -- 查询状态
- function N2C_Get_State(msg)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_GET_STATE
- msgData.playerUuid = msg.playerUuid
- msgData.systemState = 0
- msgData.joinState = 0
- local stage = AnotherWorldBattleDB.GetStage()
- msgData.systemState = stage
- if stage == 0 then
- local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
- if lastRoundStartTime == 0 then
- msgData.systemState = 0
- else
- msgData.systemState = 3
- end
- end
- local sourceServerId = msg.sourceServerId
- local num = calcSvrUnionJoinNum(sourceServerId)
- if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
- msgData.joinState = 2
- end
- local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
- for _, unionData in ipairs(joinUnionArr or {}) do
- if unionData.unionId == msg.myUnionId then
- msgData.joinState = 1
- end
- 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 newUnionData = {
- serverId = sourceServerId,
- power = unionInfo.power,
- name = unionInfo.name,
- }
- AnotherWorldBattleDB.UpdateUnionData(unionInfo.unionId, newUnionData)
- -- 通知报名成功
- 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 = {}
- msgData.hasPointNum = 0
- msgData.challengeTimes = 0
- msgData.lastTime = 0
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- local groupId = getGroupId(myUnionId, msg.sourceServerId)
- 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
- cityArrMsg[cityId].cityState = getCityState(cityInfo)
- end
- msgData.myOccupyCityArr = getUnionOccupyArr(myUnionId)
- msgData.hasPointNum = calcPlayerOccupyPointNum(msg.playerUuid)
- local challengeTimes, leftTime = getPlayerChallengeTimesInfo(msg.playerUuid)
- msgData.challengeTimes = challengeTimes
- msgData.lastTime = leftTime
- msgData.occupyPointData = getOccupPointData(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 = getGroupId(myUnionId, msg.sourceServerId)
- 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 cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
- if not cityData then
- return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
- local occupCityList = union and union.occupCityList
- local myUnionOccupyArr = calcOccupyPointArr(occupCityList)
- if union then
- myUnionOccupyArr[#myUnionOccupyArr+1] = union.baseCityId
- end
- msgData.myUnionOccupyArr = myUnionOccupyArr
- local pointArrMsg = msgData.pointArr
- for pointIdx, occupyInfo in ipairs(cityData.pointArr) do
- pointArrMsg[pointIdx] = {}
- local state = isCanChallengePoint(targetCityId, pointIdx, myUnionId, playerUuid)
- pointArrMsg[pointIdx].state = state < 0 and 0 or state
- if occupyInfo.unionId and occupyInfo.playerUuid then
- local occupyUnionData = AnotherWorldBattleDB.GetUnionData(occupyInfo.unionId)
- local occupyPlayerData = AnotherWorldBattleDB.GetPlayerData(occupyInfo.playerUuid)
- if occupyUnionData and occupyPlayerData then
- pointArrMsg[pointIdx].occupyUnionName = occupyUnionData.name
- pointArrMsg[pointIdx].occupyPlayerName = occupyPlayerData.name
- pointArrMsg[pointIdx].power = 0
- local heroList = occupyPlayerData.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 = getGroupId(myUnionId, msg.sourceServerId)
- 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 cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
- if not cityData then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
- end
- 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 playerData = AnotherWorldBattleDB.GetPlayerData(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,
- heroId = heroInfo.heroId,
- heroQuality = heroInfo.heroQuality,
- }
- end
- end
- local state = isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, msg.playerUuid)
- pointInfoMsg.state = state < 0 and 0 or state
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询公会出生点信息
- function N2C_BaseCity_Query(msg)
- local myUnionId = msg.myUnionId
- local groupId = getGroupId(myUnionId, msg.sourceServerId)
- 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
- local pointInfoArr = calcOccupyPointArr(union.occupCityList)
- baseCityInfo.occupyPointNum = #pointInfoArr
- baseCityInfo.myUnionOccupyArr = calcOccupyPointArr(union.occupCityList)
- baseCityInfo.myUnionOccupyArr[#baseCityInfo.myUnionOccupyArr+1] = baseCityInfo.cityId
- 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 playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- if not playerData then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
- end
- local heroList = playerData.heroList
- if not heroList then
- return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
- 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,
- heroId = heroInfo.heroId,
- heroQuality = heroInfo.heroQuality
- }
- end
- end
- end
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询公会排行榜
- function N2C_UnionRank_Query(msg)
- local myUnionId = msg.myUnionId
- local groupId = getGroupId(myUnionId, msg.sourceServerId)
- 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
- msgData.unionRankArr[rank] = {
- name = randkData.name,
- power = randkData.power,
- cityNum = randkData.occupyCityNum,
- pointNum = randkData.occupyPointNum,
- }
- if randkData.guildId == 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 = getGroupId(myUnionId, msg.sourceServerId)
- 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
- msgData.playerRankArr[rank] = {
- name = randkData.name,
- power = randkData.power,
- pointNum = randkData.pointNum,
- pointWeight = randkData.pointAllWeight,
- }
- if randkData.playerId == 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 = getMyUnionGourpId(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 gatherInfo = myUnionData.gatherInfo
- if msg.opType == 1 then --集结
- -- 集结冷却时间判断
- local now = os.time()
- if gatherInfo then
- local gatherTime = 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
- else
- -- 取消集结
- if not gatherInfo then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_9)
- end
- if targetCityId ~= gatherInfo.gatherCity then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_9)
- end
- gatherInfo.gatherCity = 0
- end
- AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
- -- 推送城池数据给客户端,刷新界面
- N2C_CityDetailed_Query(msg)
- -- 发给本地服, 用于在公会聊天频道生成链接
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_GATHER
- msgData.playerUuid = msg.playerUuid
- msgData.targetCityId = targetCityId
- msgData.opType = msg.opType
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 查询据点是否可以被挑战
- function N2C_Try_Challengde_Point(msg)
- local playerUuid = msg.playerUuid
- local myUnionId = msg.myUnionId
- local targetCityId = msg.targetCityId
- local targetPointIdx = msg.targetPointIdx
- local state = isCanChallengePoint(targetCityId, msg.targetPointIdx, msg.myUnionId, playerUuid)
- if state ~= 1 then
- return
- end
- local occupyPointNum = calcPlayerOccupyPointNum(msg.playerUuid)
- if occupyPointNum >= AnotherWorldBattleDefine.AB_PLAYER_OCCUPY_POINT_MAX_NUM then
- return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_10)
- end
- local groupId = getMyUnionGourpId(myUnionId)
- local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
- local targetPointData = cityData.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 now = os.time()
- local pointBattleTime = targetPointData.battleTime
- if pointBattleTime and now - pointBattleTime < AnotherWorldBattleDefine.AB_POINT_BATTLE_TIME then
- return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_11)
- end
- -- 更新据点被挑战时间
- targetPointData.battleTime = now
- AnotherWorldBattleDB.UpdateCityData(groupId, targetCityId, cityData)
- 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
- -- 玩家挑战据点胜利
- local function 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 = getMyUnionGourpId(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 cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
- local pointData = cityData.pointArr[targetPointIdx]
- local now = os.time()
- local cityNum, pointNum = 0, 1
- local pointWeight = AnotherWorldBattleConfig.city[targetCityId].pointWeight
- -- 如果城池之前被占领了, 则删除占领城池的公会Id
- if cityData.occupyUnion then
- cityData.occupyUnion = nil
- end
- -- 防守方是真实玩家
- if pointData.unionId and pointData.playerUuid then
- -- 更新防守方公会数据
- local defUnionData = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
- local defOccupCityList = defUnionData.occupCityList
- local defTargerCityData = defOccupCityList[targetCityId]
- -- 更新防守方公会对该据点的占领状态和最后占领时间
- if defTargerCityData and defTargerCityData.occupyPointList and defTargerCityData.occupyPointList[targetPointIdx] then
- local defTargetPointData = defTargerCityData.occupyPointList[targetPointIdx]
- if defTargetPointData then
- -- 删除占领该据点的玩家uuid
- defTargetPointData.playerUuid = nil
- -- 更新对该据点最后占领时间段的结束时间
- if defTargetPointData.occupyTimeArr then
- local lastOccupyTimeTb = defTargetPointData.occupyTimeArr[#defTargetPointData.occupyTimeArr]
- lastOccupyTimeTb[2] = now
- end
- end
- end
- -- 删除防守方玩家的防守阵容数据
- local defPlayData = AnotherWorldBattleDB.GetPlayerData(pointData.playerUuid)
- if defPlayData then
- defPlayData.heroList[targetCityId][targetPointIdx] = nil
- AnotherWorldBattleDB.UpdatePlayerData(pointData.playerUuid, defPlayData)
- end
- -- 如果防守方公会之前占领了城池, 则修改占领状态
- if defTargerCityData and defTargerCityData.isOccupy then
- defTargerCityData.isOccupy = false
- cityNum = -1
- end
- -- 更新防守方公会的排行榜数据
- AnotherWorldBattleDB.UpdateUnionRankList(groupId, pointData.unionId, cityNum, pointNum)
- -- 更新防守方玩家的排行榜数据
- AnotherWorldBattleDB.UpdatePlayerRankList(groupId, pointData.playerUuid, -pointNum, -pointWeight)
- -- 通知玩家
- pointLose(defUnionData.serverId, pointData.playerUuid, targetCityId, targetPointIdx)
- -- 更新防守方公会数据
- AnotherWorldBattleDB.UpdateUnionData(pointData.unionId, defUnionData)
- end
- -- 更新据点最新占领者数据
- pointData.unionId = myUnionId
- pointData.playerUuid = playerUuid
- -- 重置据点被挑战标识
- pointData.battleTime = nil
- -- 更新进攻方公会数据—— 据点占有者, 最新的据点占有时间
- 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] = occupCityList[targetCityId].occupyPointList[targetPointIdx] or {}
- local atkPointInfo = occupCityList[targetCityId].occupyPointList[targetPointIdx]
- atkPointInfo.playerUuid = playerUuid
- atkPointInfo.occupyTimeArr = atkPointInfo.occupyTimeArr or {}
- atkPointInfo.occupyTimeArr[#atkPointInfo.occupyTimeArr+1] = { now }
- --更新进攻者的展示数据
- local atkPlayerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- atkPlayerData = atkPlayerData or {}
- atkPlayerData.name = playerShowInfo.name
- atkPlayerData.lv = playerShowInfo.lv
- atkPlayerData.head = playerShowInfo.head
- atkPlayerData.headFrame = playerShowInfo.headFrame
- atkPlayerData.power = playerShowInfo.power
- atkPlayerData.unionId = myUnionId
- -- 更新挑战次数
- atkPlayerData.challengeTimes = (atkPlayerData.challengeTimes or AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_INIT_TIMES) - 1
- if not atkPlayerData.lastTime or atkPlayerData.lastTime == 0 then
- atkPlayerData.lastTime = os.time()
- end
- -- 增加防守阵容数据
- atkPlayerData.heroList = atkPlayerData.heroList or {}
- atkPlayerData.heroList[targetCityId] = atkPlayerData.heroList[targetCityId] or {}
- atkPlayerData.heroList[targetCityId][targetPointIdx] = playerShowInfo.heroArr
- cityNum = 0
- -- 进攻方完全占领城池了
- if isCompleteOccupy(cityData, myUnionId) then
- -- 更新城池的占领公会
- cityData.occupyUnion = myUnionId
- -- 更新进攻方公会对该城池的占领状态
- occupCityList[targetCityId].isOccupy = true
- -- 如果占领的是发起集结的城池, 那么取消集结
- if myUnionData.gatherInfo and myUnionData.gatherInfo.gatherCity == targetCityId then
- myUnionData.gatherInfo.gatherCity = 0
- end
- cityNum = 1
- end
- -- 更新进攻方公会数据
- AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
- -- 更新进攻方玩家数据
- AnotherWorldBattleDB.UpdatePlayerData(playerUuid, atkPlayerData)
- -- 更新进攻方公会的排行榜数据
- AnotherWorldBattleDB.UpdateUnionRankList(groupId, myUnionId, cityNum, pointNum)
- -- 更新进攻方玩家的排行榜数据
- AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerUuid, pointNum, pointWeight, playerShowInfo.power)
- -- 更新城池数据
- AnotherWorldBattleDB.UpdateCityData(groupId, targetCityId, cityData)
- end
- -- 玩家挑战据点失败
- local function challenge_Fail(msg)
- local playerUuid = msg.playerUuid
- local myUnionId = msg.myUnionId
- local targetCityId = msg.targetCityId
- local targetPointIdx = msg.targetPointIdx
- local groupId = getMyUnionGourpId(myUnionId)
- if not groupId then
- return
- end
- -- 据点挑战结束
- local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
- if cityData and cityData.pointArr[targetPointIdx] then
- local targetPointData = cityData.pointArr[targetPointIdx]
- targetPointData.battleTime = nil
- AnotherWorldBattleDB.UpdateCityData(groupId, targetCityId, cityData)
- end
- local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- playerData = playerData or {}
- playerData.name = playerData.name
- playerData.lv = playerData.lv
- playerData.power = playerData.power
- playerData.unionId = myUnionId
- playerData.challengeTimes = (playerData.challengeTimes or AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_INIT_TIMES) - 1
- if not playerData.lastTime or playerData.lastTime == 0 then
- playerData.lastTime = os.time()
- end
- AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
- -- 加入个人排行榜
- AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerUuid, 0, 0, playerData.power)
- end
- --挑战据点结束的处理函数
- function N2C_Point_Challenge_End_Handle(msg)
- if msg.challengeRes == CombatDefine.RESULT_WIN then
- challenge_Win(msg)
- else
- challenge_Fail(msg)
- end
- end
- -- 玩家数据更新
- function N2C_Update_Player_Data(msg)
- if not isRunning() then
- return
- end
- local playerUuid = msg.playerUuid
- local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- if not playerData then
- return
- end
- local groupId = getMyUnionGourpId(playerData.unionId)
- if not groupId then
- return
- end
- local isUpdate = false
- for k,v in pairs(msg.updateData) do
- if k == "power" or k == "name" then
- isUpdate = true
- end
- playerData[k] = v
- end
- AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
- -- 如果是战力/名字更新, 更新玩家排行榜
- if isUpdate then
- AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerUuid, 0, 0, playerData.power)
- end
- end
- -- 公会数据更新
- function N2C_Update_Union_Data(msg)
- if not isRunning() then
- return
- end
- local myUnionId = msg.myUnionId
- local unionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
- if not unionData then
- return
- end
- local groupId = getMyUnionGourpId(myUnionId)
- if not groupId then
- return
- end
- local isUpdate = false
- for k,v in pairs(msg.updateData) do
- if k == "power" or k == "name" then
- isUpdate = true
- end
- unionData[k] = v
- end
- AnotherWorldBattleDB.UpdateUnionData(myUnionId, unionData)
- -- 如果是战力更新, 更新公会排行榜
- if isUpdate then
- AnotherWorldBattleDB.UpdateUnionRankList(groupId, myUnionId, 0, 0, unionData.power)
- end
- end
- -- 更新玩家据点防守阵容数据
- function N2C_Update_Point_Lineup(msg)
- if not isRunning() then
- return
- end
- local playerUuid = msg.playerUuid
- local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- if not playerData or not playerData.heroList then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
- end
- local groupId = getMyUnionGourpId(playerData.unionId)
- if not groupId then
- return
- end
- local targetCityId, targetPointIdx = msg.targetCityId, msg.targetPointIdx
- local heroList = playerData.heroList
- if not heroList[targetCityId] or not heroList[targetCityId][targetPointIdx] then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
- end
- heroList[targetCityId][targetPointIdx] = msg.heroArr
- AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_UPDATE_POINT_LINEIP
- msgData.playerUuid = playerUuid
- msgData.targetCityId = targetCityId
- msgData.targetPointIdx = targetPointIdx
- msgData.formation = msg.formation
- msgData.heroList = msg.heroList
- msgData.helpList = msg.helpList
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- end
- -- 更新玩家英雄数据
- function N2C_Update_HeroData(msg)
- if not isRunning() then
- return
- end
- local playerUuid = msg.playerUuid
- local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- if not playerData then
- return
- end
- local heroList = playerData.heroList
- if not heroList then
- return
- end
- local targetCityId, targetPointIdx = msg.targetCityId, msg.targetPointIdx
- if not heroList[targetCityId] or not heroList[targetCityId][targetPointIdx] then
- return
- end
- local isUpdate = false
- local newHeroData = msg.heroData
- local heroArr = heroList[targetCityId][targetPointIdx]
- for _, heroData in ipairs(heroArr) do
- if heroData.heroUuid == newHeroData.heroUuid then
- for k, v in pairs(newHeroData) do
- heroData[k] = v
- end
- isUpdate = true
- break
- end
- end
- if isUpdate then
- AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
- end
- end
- -- 放弃据点
- function N2C_Leave_Point(msg)
- local playerUuid = msg.playerUuid
- local myUnionId = msg.myUnionId
- local targetCityId = msg.targetCityId
- local targetPointIdx = msg.targetPointIdx
- if not isRunning() then
- return
- end
- local groupId = getMyUnionGourpId(myUnionId)
- local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
- local targetPointData = cityData.pointArr[targetPointIdx]
- if not targetPointData.unionId or targetPointData.unionId ~= myUnionId or targetPointData.playerUuid ~= playerUuid then
- return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
- end
- local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
- if not playerData then
- return
- end
- local heroList = playerData.heroList
- if not heroList or not heroList[targetCityId] or not heroList[targetCityId][targetPointIdx] then
- return
- end
- local defUnionData = AnotherWorldBattleDB.GetUnionData(targetPointData.unionId)
- if not defUnionData then
- return
- end
- local defOccupCityList = defUnionData.occupCityList
- if not defOccupCityList then
- return
- end
- local defTargerCityData = defOccupCityList[targetCityId]
- if not defTargerCityData or not defTargerCityData.occupyPointList or not defTargerCityData.occupyPointList[targetPointIdx] then
- return
- end
- local cityNum, pointNum = 0, -1
- -- 更新城池数据, 如果城池之前被本公会占领了, 则删除
- if cityData.occupyUnion and cityData.occupyUnion == myUnionId then
- cityData.occupyUnion = nil
- end
- -- 更新据点数据, 删除据点的 unionId, playerUuid
- targetPointData.unionId = nil
- targetPointData.playerUuid = nil
- -- 更新公会数据, 删除公会数据中占领该据点的玩家uuid
- local defTargetPointData = defTargerCityData.occupyPointList[targetPointIdx]
- defTargetPointData.playerUuid = nil
- -- 更新公会数据, 更新该据点最后占领时间段的结束时间
- if defTargetPointData.occupyTimeArr then
- local lastOccupyTimeTb = defTargetPointData.occupyTimeArr[#defTargetPointData.occupyTimeArr]
- lastOccupyTimeTb[2] = now
- end
- -- 更新公会数据, 如果本公会之前占领了城池, 则修改占领状态
- if defTargerCityData and defTargerCityData.isOccupy then
- defTargerCityData.isOccupy = false
- cityNum = -1
- end
- -- 更新玩家数据, 删除玩家数据中该据点的防守数据
- heroList[targetCityId][targetPointIdx] = nil
- if not next(heroList[targetCityId]) then
- heroList[targetCityId] = nil
- end
- -- 更新公会数据
- AnotherWorldBattleDB.UpdateUnionData(myUnionId, defUnionData)
- -- 更新玩家数据
- AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
- -- 更新公会的排行榜数据
- AnotherWorldBattleDB.UpdateUnionRankList(groupId, myUnionId, cityNum, pointNum)
- -- 更新玩家的排行榜数据
- local pointWeight = AnotherWorldBattleConfig.city[targetCityId].pointWeight
- AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerUuid, pointNum, -pointWeight)
- -- 更新城池数据
- AnotherWorldBattleDB.UpdateCityData(groupId, targetCityId, cityData)
- -- 通知普通服, 放弃据点成功
- local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_LEAVE_POINT
- msgData.playerUuid = playerUuid
- msgData.targetCityId = targetCityId
- msgData.targetPointIdx = targetPointIdx
- local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
- InnerMsg.sendMsg(fd, msgData)
- N2C_AllCity_Query(msg)
- end
|