| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532 |
- -- 异界之战(跨服)
- 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)
- 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, playerListData)
- local occupyTb = {
- occupyCityArr = {}, -- 当前还占领的城池列表
- point2CityIdArr = {}, -- 曾占领/当前还占领的据点的所属城池Id列表
- occuoyPointNum = 0,
- playerUuidArr = {},
- unionId = unionId,
- }
- local now = os.time()
- local tbl = occupyTb.occupyCityArr
- tbl[#tbl+1] = union.baseCityId
- local tbl2 = occupyTb.point2CityIdArr
- for cityId, cityIno in pairs(union.occupCityList or {}) do
- if cityIno.isOccupy then
- tbl[#tbl+1] = cityId
- end
- for _, pointInfo in pairs(cityIno.occupyPointList) do
- if pointInfo.playerUuid then
- occupyTb.occuoyPointNum = occupyTb.occuoyPointNum + 1
- -- 更新据点最新占领时间段的结束时间
- local occupyTimeArr = pointInfo.occupyTimeArr
- local lastTimeTb = occupyTimeArr[#occupyTimeArr]
- if #lastTimeTb == 1 then
- occupyTimeArr[#occupyTimeArr][2] = now
- end
- end
- tbl2[#tbl2+1] = {cityId, pointInfo.occupyTimeArr}
- end
- end
- -- 出生点算5个据点
- local baseCiyuTimeArr = { {union.baseCityStartTime, union.baseCityEndTime or now } }
- for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
- tbl2[#tbl2+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
- ------------------------------------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
- -- 统计公会占领的据点所属城池数组
- 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 cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- local tagetCityData = cityList[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_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_TIMES)
- playerData.lastTime = playerData.lastTime + addTimes* AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC
- if playerData.challengeTimes == AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_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
- -- 查询状态
- 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
- 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 cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- if not cityList or not cityList[targetCityId] 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 cityData = cityList[targetCityId]
- 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 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 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 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
- -- 玩家挑战据点胜利
- 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 cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
- local cityData = cityList[targetCityId]
- local pointData = cityData.pointArr[targetPointIdx]
- local now = os.time()
- local cityNum, pointNum = 0, 1
- local pointWeight = AnotherWorldBattleConfig.city[targetCityId].pointWeight
- -- 防守方是真实玩家
- if pointData.unionId and pointData.playerUuid then
- -- 更新防守方公会数据
- local defUnionData = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
- local defOccupCityList = defUnionData.occupCityList
- -- 防守方之前占领了城池
- if defOccupCityList[targetCityId].isOccupy then
- -- 修改防守方的占领状态
- defOccupCityList[targetCityId].isOccupy = false
- -- 更新防守方对该城池的最后占领时间
- local defOccupyPointList = defOccupCityList[targetCityId].occupyPointList
- local defPointInfo = defOccupyPointList[targetPointIdx]
- local defOccupyTimeArr = defPointInfo.occupyTimeArr
- defOccupyTimeArr[#defOccupyTimeArr][2] = now
- -- 删除防守方的该据点的占领者
- defPointInfo.playerUuid = nil
- -- 删除防守方玩家的防守阵容数据
- local defPlayData = AnotherWorldBattleDB.GetPlayerData(pointData.playerUuid)
- if defPlayData then
- defPlayData.heroList[targetCityId][targetPointIdx] = nil
- AnotherWorldBattleDB.UpdatePlayerData(pointData.playerUuid, defPlayData)
- end
- cityNum = -1
- end
- -- 更新防守方公会的排行榜数据
- AnotherWorldBattleDB.UpdateUnionRankList(groupId, pointData.unionId, cityNum, pointNum)
- -- 更新防守方玩家的排行榜数据
- AnotherWorldBattleDB.UpdatePlayerRankList(groupId, 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] = 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_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)
- -- 更新城池数据
- AnotherWorldBattleDB.UpdateCityList(groupId, cityList)
- end
- -- 玩家挑战据点失败
- local function challenge_Fail(msg)
- local playerUuid = msg.playerUuid
- local myUnionId = msg.myUnionId
- local groupId = getMyUnionGourpId(myUnionId)
- if not groupId then
- return
- 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_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)
- 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 isUpdatePower = false
- for k,v in pairs(msg.updateData) do
- if k == "power" then
- isUpdatePower = true
- end
- playerData[k] = v
- end
- AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
- -- 如果是战力更新, 更新玩家排行榜
- if isUpdatePower 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 isUpdatePower = false
- for k,v in pairs(msg.updateData) do
- if k == "power" then
- isUpdatePower = true
- end
- unionData[k] = v
- end
- AnotherWorldBattleDB.UpdateUnionData(myUnionId, unionData)
- -- 如果是战力更新, 更新公会排行榜
- if isUpdatePower 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
|