AnotherWorldBattleNS.lua 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066
  1. -- 异界之战
  2. --db
  3. --[=[
  4. human.db.anotherWorlBattle = {
  5. startTime = nil,
  6. formation = {
  7. [cityId1] = {
  8. [pointIdx1] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  9. [pointIdx2] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  10. },
  11. [cityId2] = {
  12. [pointIdx1] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  13. [pointIdx2] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  14. },
  15. }
  16. }
  17. ]=]--
  18. local Config = require("Config")
  19. local Msg = require("core.Msg")
  20. local Lang = require("common.Lang")
  21. local ObjHuman = require("core.ObjHuman")
  22. local Broadcast = require("broadcast.Broadcast")
  23. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  24. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  25. local CombatDefine = require("combat.CombatDefine")
  26. local RoleDBLogic = require("role.RoleDBLogic")
  27. local CombatPosLogic = require("combat.CombatPosLogic")
  28. local CombatLogic = require("combat.CombatLogic")
  29. local MailExcel = require("excel.mail")
  30. local Util = require("common.Util")
  31. local InnerMsg = require("core.InnerMsg")
  32. local RoleHeadLogic = require("role.RoleHeadLogic")
  33. local MailManager = require("mail.MailManager")
  34. local Log = require("common.Log")
  35. local Timer = require("core.Timer")
  36. local Grid = require("bag.Grid")
  37. local UnionLogic = require("union.UnionLogic")
  38. local BillboardLogic = require("billboard.BillboardLogic")
  39. local BillboardDefine = require("billboard.BillboardDefine")
  40. local AnotherWorldBattleDefine = require("anotherWorldBattle.AnotherWorldBattleDefine")
  41. local AnotherWorldBattleConfig = require("excel.anotherWorldBattle")
  42. local MonsterGrid = require("monster.MonsterGrid")
  43. local RoleConfig = require("excel.role")
  44. local MonsterExcel = require("excel.monster")
  45. local HeroExcel = require("excel.hero")
  46. local MiddleCommonLogic = require("middle.MiddleCommonLogic")
  47. local CombatImpl = require("combat.CombatImpl")
  48. local RoleAttr = require("role.RoleAttr")
  49. local CommonDB = require("common.CommonDB")
  50. local BagLogic = require("bag.BagLogic")
  51. local HeroLogic
  52. local JibanLogic
  53. local LOGTAG = "AnotherWorldBattleNS"
  54. local function writeLog(logStr)
  55. Log.write(Log.LOGID_OSS_ANOTHERWORLDBATTLE, logStr)
  56. end
  57. local function sendMail(mailId, receiverUuid, itemArray, extraInfo, rank)
  58. if not mailId or not receiverUuid then
  59. return
  60. end
  61. local mailCfg = MailExcel.mail[mailId]
  62. local content = mailCfg.content
  63. if mailId == AnotherWorldBattleDefine.AB_AWARD_MAIL_ID then
  64. local v1,v2,v3,v4,v5
  65. v1,v2,v3 = extraInfo and extraInfo[1] or 0, extraInfo and extraInfo[2] or 0, extraInfo and extraInfo[3] or 0
  66. v4,v5 = extraInfo and extraInfo[4] or 0, extraInfo and extraInfo[5] or 0
  67. content = Util.format(content, v1,v2,v3,v4,v5)
  68. elseif mailId == AnotherWorldBattleDefine.AB_UNIONRANK_AWARD_MAIL_ID then
  69. content = Util.format(content, rank)
  70. else
  71. if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
  72. rank = "50+"
  73. end
  74. content = Util.format(content, rank)
  75. end
  76. MailManager.add(MailManager.SYSTEM, receiverUuid, mailCfg.title, content, itemArray, mailCfg.senderName or "GM")
  77. end
  78. local function createRewardQueue()
  79. local issueRewardQueue = {
  80. playerArray = {},
  81. insertMaxNum = 100, -- 一次最多插入数据库的邮件数量
  82. repeatMaxTimes = 3, -- 重试次数
  83. repeatTb = {},
  84. extraInfo = {},
  85. }
  86. function issueRewardQueue:add(playerInfo)
  87. table.insert(self.playerArray, playerInfo)
  88. end
  89. function issueRewardQueue:insertDB()
  90. local maxNum = math.min(self.insertMaxNum, #self.playerArray)
  91. for i=1, maxNum do
  92. local resTag = AnotherWorldBattleDefine.AB_MAIL_SUCC_TAG
  93. local playerInfo = table.remove(self.playerArray)
  94. local playerUuid = playerInfo[1]
  95. local mailId = playerInfo[3]
  96. local rank = playerInfo[4]
  97. local ok, err = pcall(sendMail, mailId, playerUuid, playerInfo[2], issueRewardQueue.extraInfo, rank)
  98. if not ok then
  99. if not self.repeatTb[playerUuid] or self.repeatTb[playerUuid] < self.repeatMaxTimes then
  100. issueRewardQueue:add(playerInfo)
  101. self.repeatTb[playerUuid] = (self.repeatTb[playerUuid] or 0) + 1
  102. end
  103. resTag = AnotherWorldBattleDefine.AB_MAIL_FAIL_TAG
  104. end
  105. -- 写入日志
  106. local str = string.format("Result: %s, playerUuid: %s, mailId: %d, insertErrTimes: %d, errInfo: %s",
  107. resTag, playerUuid, mailId, self.repeatTb[playerUuid] or 0, err)
  108. writeLog(str)
  109. end
  110. if #self.playerArray > 0 then
  111. Timer.addLater(2, self.insertDB, self)
  112. end
  113. end
  114. return issueRewardQueue
  115. end
  116. -- 获取当天是星期几
  117. local function getWDay()
  118. return Util.getWeekDay()
  119. end
  120. -- 开服天数和玩家等级检查
  121. local function baseCondCheck(human)
  122. return RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1216)
  123. end
  124. -- 根据最近一轮活动开启时间, 判断当前是否处于活动开启时间范围
  125. local function actStartTimeCheck()
  126. local wDay = getWDay()
  127. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  128. return false
  129. end
  130. local startTime = CommonDB.getValueByKey(CommonDB.KEY_ANOTHERWORLDBATTLE_START_TI)
  131. if not startTime then
  132. return false
  133. end
  134. if not IsRuning(startTime) then
  135. return false
  136. end
  137. return true
  138. end
  139. -- 计算怪物战力
  140. local function calcMonsterPower(monsterOutID)
  141. local power = 0
  142. local objList = MonsterGrid.createMonsterObjListByMonsterOutID(monsterOutID)
  143. if not objList then
  144. return power
  145. end
  146. for _, monster in ipairs(objList) do
  147. power = power + (monster.power or 0)
  148. end
  149. return power
  150. end
  151. -- 根据据点所属城池,计算多个据点每分钟产出道具数量之和
  152. local function calcPointAward(cityIdArr)
  153. local myUnionAwardNum = 0
  154. if cityIdArr then
  155. for _, cityId in ipairs(cityIdArr) do
  156. local targetCityCfg = AnotherWorldBattleConfig.city[cityId]
  157. if targetCityCfg.isBaseCity == 1 then
  158. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  159. else
  160. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2]
  161. end
  162. end
  163. end
  164. return math.min(myUnionAwardNum, AnotherWorldBattleDefine.AB_MIN_ITEM_MAX_NUM)
  165. end
  166. -- 获取展示部位的固定Id
  167. local function getDefaultShowId(showType, idx)
  168. local targetCfg
  169. if showType == 1 then
  170. targetCfg = RoleConfig.head
  171. else
  172. targetCfg = RoleConfig.headFrame
  173. end
  174. local t = {}
  175. for k in pairs(targetCfg) do
  176. t[#t+1] = k
  177. end
  178. table.sort(t)
  179. return t[idx] or t[1]
  180. end
  181. -- 单个英雄数据
  182. local function getHeroInfo(human, targetHeroUuid)
  183. HeroLogic = HeroLogic or require("hero.HeroLogic")
  184. local heroGrid = HeroLogic.getHeroGridByUuid(human, targetHeroUuid)
  185. if heroGrid then
  186. local heroCfg = HeroExcel.hero[heroGrid.id]
  187. RoleAttr.calcHeroGrid(heroGrid, nil, human)
  188. local heroInfo = {
  189. heroUuid = targetHeroUuid,
  190. heroStar = heroGrid.star,
  191. heroLevel = heroGrid.lv,
  192. heroCamp = heroGrid.camp or heroCfg.camp,
  193. heroBody = heroCfg.body,
  194. heroIcon = heroGrid.head or heroCfg.head,
  195. heroPower = heroGrid.zhandouli,
  196. heroId = heroGrid.id,
  197. heroQuality = heroCfg.grade,
  198. }
  199. return heroInfo
  200. end
  201. end
  202. -- 获取上阵英雄数据
  203. local function getHeroListInfo(human, targetHeroUuid)
  204. local len = 0
  205. local heroArr = {}
  206. local heroList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  207. if not next(heroList) then
  208. return heroArr
  209. end
  210. for _, heroUuid in pairs(heroList) do
  211. if (heroUuid ~= "" and heroUuid ~= "0") and (not targetHeroUuid or targetHeroUuid == heroUuid) then
  212. len = len + 1
  213. heroArr[len] = getHeroInfo(human, heroUuid)
  214. end
  215. end
  216. if len == 0 then
  217. return
  218. end
  219. return heroArr
  220. end
  221. -- 生成展示数据
  222. local function generateShowInfo(human)
  223. local showInfo = {
  224. name = human.db.name,
  225. lv = human.db.lv,
  226. power = human.db.zhandouli,
  227. }
  228. showInfo.head = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_1)
  229. showInfo.headFrame = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_2)
  230. -- showInfo.body = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_3)
  231. showInfo.heroArr = getHeroListInfo(human)
  232. return showInfo
  233. end
  234. -- 阵容数据检查,如果不在 "活动开启且战斗阶段" 则清空
  235. local function formationDataCheeck(human)
  236. if not human.db.anotherWorlBattle then
  237. return
  238. end
  239. -- 不在战斗阶段时间范围
  240. local wDay = getWDay()
  241. if not (AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] <= wDay and AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] >= wDay) then
  242. human.db.anotherWorlBattle = nil
  243. return
  244. end
  245. -- 处于战斗阶段最后一天, 但是活动已经结束
  246. local now = os.time()
  247. local toDayStartTime = Util.getDayStartTime(now)
  248. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  249. human.db.anotherWorlBattle = nil
  250. return
  251. end
  252. -- 处于战斗阶段时间范围内, 但是活动未开(因为两轮活动时间间隔至少9天)
  253. local startTime = human.db.anotherWorlBattle.startTime
  254. local diffDays = Util.diffDay(startTime)
  255. if diffDays > AnotherWorldBattleDefine.AB_BATTLE_DAYS then
  256. human.db.anotherWorlBattle = nil
  257. end
  258. end
  259. -- 把玩家最新的异界之战所有防守英雄uuid推给客户端
  260. local function sendDefHeroArr(human)
  261. local msgRet = Msg.gc.GC_AB_DEF_HERO_QUERY
  262. msgRet.heroUuidArr[0] = 0
  263. if not human.db.anotherWorlBattle then
  264. return Msg.send(msgRet, human.fd)
  265. end
  266. local len = 0
  267. local heroUuidArrMsg = msgRet.heroUuidArr
  268. for _, pointList in pairs(human.db.anotherWorlBattle.formation) do
  269. for _, combatData in pairs(pointList) do
  270. local heroList = combatData.list
  271. for _, heroUuid in pairs(heroList) do
  272. if heroUuid ~= "" and heroUuid ~= "0" then
  273. len = len + 1
  274. heroUuidArrMsg[len] = heroUuid
  275. end
  276. end
  277. end
  278. end
  279. heroUuidArrMsg[0] = len
  280. Msg.send(msgRet, human.fd)
  281. end
  282. -- 如果活动开启时间范围内, 则通知客户端弹出提示框
  283. local function notifyTips(human)
  284. if not baseCondCheck(human) then
  285. return
  286. end
  287. local wDay = getWDay()
  288. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  289. return
  290. end
  291. AB_GetState(human, true)
  292. end
  293. -- 是否是防守阵容中的英雄
  294. local function isDefHero(human, checkHeroUuid, excludeCityId, excludePointIdx)
  295. if not human.db.anotherWorlBattle then
  296. return
  297. end
  298. for cityId, pointList in pairs(human.db.anotherWorlBattle.formation) do
  299. for pointIdx, combatData in pairs(pointList) do
  300. if (excludeCityId and excludeCityId == cityId) and (excludePointIdx and excludePointIdx == pointIdx) then
  301. break
  302. end
  303. local heroList = combatData.list
  304. for _, heroUuid in pairs(heroList) do
  305. if heroUuid == checkHeroUuid then
  306. return cityId, pointIdx
  307. end
  308. end
  309. end
  310. end
  311. return
  312. end
  313. -- 是否是公会前二名
  314. local function isTopTwoUnion(human)
  315. local unionRanList = BillboardLogic.GetRankList(BillboardDefine.TYPE_UNION)
  316. if not unionRanList then
  317. return false
  318. end
  319. local unionId = human.db.unionUuid
  320. local isTopTwo = false
  321. for i=1, 2 do
  322. if unionRanList[i].uuid == unionId then
  323. isTopTwo = true
  324. break
  325. end
  326. end
  327. return isTopTwo
  328. end
  329. -- 是否处于战斗阶段
  330. local function isBattleStage()
  331. local wDay = getWDay()
  332. if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
  333. return true
  334. end
  335. return false
  336. end
  337. -- 重置在线玩家的防守数据
  338. local function resetDefData(playerInfoArr)
  339. for _, playerInfo in ipairs(playerInfoArr or {}) do
  340. local playerUuid = playerInfo[1]
  341. local human = ObjHuman.onlineUuid[playerUuid]
  342. if human then
  343. onLogin(human)
  344. end
  345. end
  346. end
  347. -- 获取公会/个人排行榜通用的奖励Id
  348. local function getRankGenericAwadId(rankRewardList, rankType)
  349. for _, v in ipairs(rankRewardList) do
  350. if v.nRankType == rankType then
  351. return v.Prize
  352. end
  353. end
  354. end
  355. -- 获取排名奖励
  356. local function getRankAward(rankRewardList, rankType, targetRank)
  357. for _, v in ipairs(rankRewardList) do
  358. if v.nRankType == rankType and (targetRank >= v.nOrder[1] and targetRank <= v.nOrder[2]) then
  359. return v.Prize
  360. end
  361. end
  362. end
  363. -- 计算整个战斗阶段占据据点的最大产出数量
  364. local function calcRewardMax()
  365. local totalSec = AnotherWorldBattleDefine.AB_BATTLE_DAYS * 86400
  366. totalSec = totalSec - AnotherWorldBattleDefine.AB_START_SEC -- 第一天0:10分才开始
  367. totalSec = totalSec - (86400 - AnotherWorldBattleDefine.AB_BATTLE_END_SEC) -- 最后一天只到23点
  368. local itemCntMax = math.floor(totalSec / 60) * AnotherWorldBattleDefine.AB_MIN_ITEM_MAX_NUM
  369. return itemCntMax
  370. end
  371. -- 计算当前占领的据点最大产出数量
  372. local function calcRewardNow()
  373. local now = os.time()
  374. local toDayStartTime = Util.getDayStartTime(now)
  375. local wDay = getWDay()
  376. local subDay = wDay - AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1]
  377. local battleStageStartTime = toDayStartTime - (subDay * 86400)
  378. battleStageStartTime = battleStageStartTime + AnotherWorldBattleDefine.AB_START_SEC
  379. local subSec = now - battleStageStartTime
  380. local itemCntMax = math.floor(subSec / 60) * AnotherWorldBattleDefine.AB_MIN_ITEM_MAX_NUM
  381. return itemCntMax
  382. end
  383. -- 生成奖励发放对象列表
  384. local function genAwardObjArr(unionOccupyInfo)
  385. local function calcMinute(timeArr)
  386. local minuteVal = 0
  387. for _, timeTb in ipairs(timeArr or {}) do
  388. local sec = (timeTb[2] or 0) - (timeTb[1] or 0)
  389. if sec > 0 then
  390. minuteVal = minuteVal + sec
  391. end
  392. end
  393. return math.floor(minuteVal / 60)
  394. end
  395. -- 没有玩家参与
  396. if not unionOccupyInfo.playerInfoArr or #unionOccupyInfo.playerInfoArr <= 0 then
  397. return
  398. end
  399. local itemList = {}
  400. local occupyCityInfo = {0,0,0,0,0}
  401. local item_185_Id = 185
  402. local item_185_Num = 0
  403. occupyCityInfo[1] = unionOccupyInfo.occuoyPointNum
  404. -- 额外奖励
  405. item_185_Num = item_185_Num + (unionOccupyInfo.occuoyPointNum or 0)
  406. for _, cityId in ipairs(unionOccupyInfo.occupyCityArr) do
  407. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  408. if cityCfg then
  409. if cityCfg.isBaseCity == 1 then
  410. item_185_Num = item_185_Num + 20
  411. else
  412. if cityCfg.cityLv == 2 then
  413. item_185_Num = item_185_Num + 2
  414. occupyCityInfo[2] = occupyCityInfo[2] + 1
  415. elseif cityCfg.cityLv == 3 then
  416. item_185_Num = item_185_Num + 3
  417. occupyCityInfo[3] = occupyCityInfo[3] + 1
  418. elseif cityCfg.cityLv == 4 then
  419. item_185_Num = item_185_Num + 5
  420. occupyCityInfo[4] = occupyCityInfo[4] + 1
  421. elseif cityCfg.cityLv == 5 then
  422. item_185_Num = item_185_Num + 20
  423. occupyCityInfo[5] = occupyCityInfo[5] + 1
  424. end
  425. end
  426. end
  427. end
  428. -- 占领据点每分钟的奖励
  429. local minuteAwardId, minuteAwardNum = 0, 0
  430. for _, pointInfo in ipairs(unionOccupyInfo.point2CityIdArr) do
  431. local cityId = pointInfo[1]
  432. local occupyTimeArr = pointInfo[2]
  433. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  434. local totalMinVal = calcMinute(occupyTimeArr)
  435. if totalMinVal > 0 then
  436. local itemId, itemNum = cityCfg.cityAward[1], cityCfg.cityAward[2]
  437. minuteAwardId = itemId
  438. minuteAwardNum = minuteAwardNum + totalMinVal * itemNum
  439. -- itemList[itemId] = (itemList[itemId] or 0) + totalMinVal * itemNum
  440. end
  441. end
  442. local maxNum = calcRewardMax()
  443. if maxNum > 0 then
  444. minuteAwardNum = math.min(minuteAwardNum, maxNum)
  445. end
  446. itemList[minuteAwardId] = (itemList[minuteAwardId] or 0) + minuteAwardNum
  447. if item_185_Num > 0 then
  448. itemList[item_185_Id] = item_185_Num
  449. end
  450. local itemArr = {}
  451. for itemId, itemNum in pairs(itemList) do
  452. itemArr[#itemArr+1] = { itemId, itemNum }
  453. end
  454. local rankReward = AnotherWorldBattleConfig.rankReward
  455. local awardObjArr = {}
  456. for _, playerInfo in ipairs(unionOccupyInfo.playerInfoArr) do
  457. local playerUuid = playerInfo[1]
  458. local playerRank = playerInfo[2]
  459. -- 据点每分钟奖励 + 额外奖励
  460. awardObjArr[#awardObjArr+1] = {playerUuid, itemArr, AnotherWorldBattleDefine.AB_AWARD_MAIL_ID}
  461. -- 公会排名奖励
  462. -- local itemId, itemNum = getRankAward(rankReward, 1, unionOccupyInfo.unionRank)
  463. -- if itemId and itemNum then
  464. -- awardObjArr[#awardObjArr+1] = {playerUuid, {{itemId, itemNum}}, AnotherWorldBattleDefine.AB_UNIONRANK_AWARD_MAIL_ID, unionOccupyInfo.unionRank}
  465. -- end
  466. local itemTb = getRankAward(rankReward, 1, unionOccupyInfo.unionRank)
  467. if itemTb then
  468. local items
  469. for _, itemInfo in ipairs(itemTb) do
  470. items = items or {}
  471. items[#items+1] = {itemInfo[1], itemInfo[2]}
  472. end
  473. if items then
  474. awardObjArr[#awardObjArr+1] = {playerUuid, items, AnotherWorldBattleDefine.AB_UNIONRANK_AWARD_MAIL_ID, unionOccupyInfo.unionRank}
  475. end
  476. end
  477. -- 玩家排名奖励
  478. -- local itemId2, itemNum2 = getRankAward(rankReward, 2, playerRank)
  479. -- if itemId2 and itemNum2 then
  480. -- awardObjArr[#awardObjArr+1] = {playerUuid, {{itemId2, itemNum2}}, AnotherWorldBattleDefine.AB_PLAYERRANK_AWARD_MAIL_ID, playerRank}
  481. -- end
  482. itemTb = getRankAward(rankReward, 2, playerRank)
  483. if itemTb then
  484. local items
  485. for _, itemInfo in ipairs(itemTb) do
  486. items = items or {}
  487. items[#items+1] = {itemInfo[1], itemInfo[2]}
  488. end
  489. if items then
  490. awardObjArr[#awardObjArr+1] = {playerUuid, items, AnotherWorldBattleDefine.AB_PLAYERRANK_AWARD_MAIL_ID, playerRank}
  491. end
  492. end
  493. end
  494. return awardObjArr, occupyCityInfo
  495. end
  496. -- 活动是否处于开启中
  497. function IsRuning(joinTime)
  498. if not joinTime then
  499. return true
  500. end
  501. local wDay = getWDay()
  502. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  503. return false
  504. end
  505. local now = os.time()
  506. local toDayStartTime = Util.getDayStartTime(now)
  507. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  508. return false
  509. end
  510. local diffDays = Util.diffDay(joinTime)
  511. -- local joinWday = Util.getWeekDay(joinTime)
  512. -- 如果是周六加入则相差6天, 如果是周日加入则相差5天。 当前时间与加入时间相差6或5天, 则都表示当前可能是活动最后一天, 如果当前时间 > 结束时间则活动结束
  513. -- if (diffDays == AnotherWorldBattleDefine.AB_OPEN_DAYS and joinWday == 7) or (diffDays == (AnotherWorldBattleDefine.AB_OPEN_DAYS-1) and joinWday == 1) then
  514. -- if now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  515. -- return false
  516. -- end
  517. -- end
  518. -- < 6天说明处于本轮活动开启时间范围, > 6天说明活动已经结束
  519. if diffDays > AnotherWorldBattleDefine.AB_OPEN_DAYS then
  520. return false
  521. end
  522. return true
  523. end
  524. --检测上阵英雄
  525. function checkUpdatePos(human, msg)
  526. local heroList = Util.split(msg.heroList, ",")
  527. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  528. local uuid = heroList[i] or ""
  529. if uuid ~= "0" and uuid ~= "" then
  530. if isDefHero(human, uuid) then
  531. return false
  532. end
  533. end
  534. end
  535. return true
  536. end
  537. -- 公会战力更新
  538. function UnionPowerChange(unionId, newPower)
  539. if not actStartTimeCheck() then
  540. return false
  541. end
  542. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  543. msgData.myUnionId = unionId
  544. msgData.updateData = {}
  545. msgData.updateData.power = newPower
  546. InnerMsg.sendMsg(0, msgData)
  547. end
  548. -- 玩家战力更新
  549. function PlayerPowerChange(human)
  550. if not human.db.anotherWorlBattle then
  551. return
  552. end
  553. if not baseCondCheck(human) then
  554. return false
  555. end
  556. if not actStartTimeCheck() then
  557. return false
  558. end
  559. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  560. msgData.playerUuid = human.db._id
  561. msgData.myUnionId = human.db.unionUuid
  562. msgData.updateData = {}
  563. msgData.updateData.power = human.db.zhandouli
  564. InnerMsg.sendMsg(0, msgData)
  565. end
  566. -- 英雄更新
  567. function HeroDataUpdate(human, heroUuid)
  568. if not baseCondCheck(human) then
  569. return false
  570. end
  571. if not actStartTimeCheck() then
  572. return false
  573. end
  574. local cityId, pointIdx = isDefHero(human, heroUuid)
  575. if not cityId then
  576. return
  577. end
  578. HeroLogic = HeroLogic or require("hero.HeroLogic")
  579. local heroGrid = HeroLogic.getHeroGridByUuid(human, heroUuid)
  580. if heroGrid then
  581. RoleAttr.calcHeroGrid(heroGrid, nil, human)
  582. local heroInfo = {
  583. heroUuid = heroUuid,
  584. heroStar = heroGrid.star,
  585. heroLevel = heroGrid.lv,
  586. heroPower = heroGrid.zhandouli,
  587. }
  588. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_HERO
  589. msgData.playerUuid = human.db._id
  590. msgData.targetCityId = cityId
  591. msgData.targetPointIdx = pointIdx
  592. msgData.heroData = heroInfo
  593. InnerMsg.sendMsg(0, msgData)
  594. end
  595. end
  596. -- 玩家改名
  597. function PlayerChangeName(human)
  598. if not human.db.anotherWorlBattle then
  599. return
  600. end
  601. if not baseCondCheck(human) then
  602. return false
  603. end
  604. if not actStartTimeCheck() then
  605. return false
  606. end
  607. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  608. msgData.playerUuid = human.db._id
  609. msgData.myUnionId = human.db.unionUuid
  610. msgData.updateData = {}
  611. msgData.updateData.name = human.db.name
  612. InnerMsg.sendMsg(0, msgData)
  613. end
  614. -- 公会改名
  615. function UnionChangeName(unionId, newName)
  616. if not actStartTimeCheck() then
  617. return false
  618. end
  619. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  620. msgData.myUnionId = unionId
  621. msgData.updateData = {}
  622. msgData.updateData.name = newName
  623. InnerMsg.sendMsg(0, msgData)
  624. end
  625. function isDot(human)
  626. if not baseCondCheck(human) then
  627. return false
  628. end
  629. if not actStartTimeCheck() then
  630. return false
  631. end
  632. return true
  633. end
  634. function onLogin(human)
  635. formationDataCheeck(human)
  636. sendDefHeroArr(human)
  637. notifyTips(human)
  638. end
  639. -- 请求状态
  640. function AB_GetState(human, isTips)
  641. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_STATE
  642. msgData.sourceServerId = Config.SVR_INDEX
  643. msgData.playerUuid = human.db._id
  644. msgData.myUnionId = human.db.unionUuid or ""
  645. msgData.isTips = isTips and 1 or 0
  646. InnerMsg.sendMsg(0, msgData)
  647. end
  648. -- 报名
  649. function AB_Join(human)
  650. local unionId = human.db.unionUuid
  651. local msgRet = Msg.gc.GC_AB_JOIN
  652. if not unionId then
  653. msgRet.Joinstate = 3
  654. return Msg.send(msgRet, human.fd)
  655. end
  656. local wDay = getWDay()
  657. -- if wDay ~= AnotherWorldBattleDefine.AB_JOIN_WDAY then
  658. -- msgRet.Joinstate = 5
  659. -- return Msg.send(msgRet, human.fd)
  660. -- end
  661. if not table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  662. msgRet.Joinstate = 5
  663. return Msg.send(msgRet, human.fd)
  664. end
  665. -- 公会排名前二才能参加
  666. if not isTopTwoUnion(human) then
  667. msgRet.Joinstate = 2
  668. return Msg.send(msgRet, human.fd)
  669. end
  670. -- 会长/副会长才能报名
  671. if not UnionLogic.IsTopTwoManager(human, unionId) then
  672. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  673. end
  674. local queryFiles = {name = 1, zhandouli = 1}
  675. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  676. if not unionInfo then
  677. return Broadcast.sendErr(human, Lang.DATA_ERR)
  678. end
  679. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_JOIN
  680. msgData.sourceServerId = Config.SVR_INDEX
  681. msgData.playerUuid = human.db._id
  682. msgData.unionInfo = {
  683. name = unionInfo.name,
  684. power = unionInfo.zhandouli,
  685. unionId = unionId
  686. }
  687. InnerMsg.sendMsg(0, msgData)
  688. end
  689. -- 查询所有城池信息
  690. function AB_AllCity_Query(human)
  691. if not human.db.unionUuid then
  692. return
  693. end
  694. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  695. msgData.sourceServerId = Config.SVR_INDEX
  696. msgData.playerUuid = human.db._id
  697. msgData.myUnionId = human.db.unionUuid
  698. InnerMsg.sendMsg(0, msgData)
  699. -- 报名状态查询
  700. -- local msgData2 = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_JOIN_STATE
  701. -- msgData2.sourceServerId = Config.SVR_INDEX
  702. -- msgData2.playerUuid = human.db._id
  703. -- msgData2.myUnionId = human.db.unionUuid
  704. -- InnerMsg.sendMsg(0, msgData2)
  705. end
  706. -- 查询单个城池的详细信息
  707. function AB_CityDetailed_Query(human, targetCityId)
  708. if not AnotherWorldBattleConfig.city[targetCityId] then
  709. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  710. end
  711. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  712. msgData.sourceServerId = Config.SVR_INDEX
  713. msgData.playerUuid = human.db._id
  714. msgData.myUnionId = human.db.unionUuid
  715. msgData.targetCityId = targetCityId
  716. InnerMsg.sendMsg(0, msgData)
  717. end
  718. -- 查询某个城池的某个据点的详细信息
  719. function AB_PointDetailed_Query(human, targetCityId, targetPointIdx)
  720. if not AnotherWorldBattleConfig.city[targetCityId] then
  721. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  722. end
  723. if 0 >= targetPointIdx or AnotherWorldBattleDefine.AB_POINT_MAX_NUM < targetPointIdx then
  724. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  725. end
  726. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINTtDETAILED_QUERY
  727. msgData.sourceServerId = Config.SVR_INDEX
  728. msgData.playerUuid = human.db._id
  729. msgData.myUnionId = human.db.unionUuid
  730. msgData.targetCityId = targetCityId
  731. msgData.targetPointIdx = targetPointIdx
  732. InnerMsg.sendMsg(0, msgData)
  733. end
  734. -- 查询本公会出生点信息
  735. function AB_BaseCity_Query(human)
  736. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_BASECITY_QUERY
  737. msgData.sourceServerId = Config.SVR_INDEX
  738. msgData.playerUuid = human.db._id
  739. msgData.myUnionId = human.db.unionUuid
  740. InnerMsg.sendMsg(0, msgData)
  741. end
  742. -- 查询玩家占领的所有据点信息
  743. function AB_PlayerOccupyPOint_Query(human)
  744. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  745. msgData.sourceServerId = Config.SVR_INDEX
  746. msgData.playerUuid = human.db._id
  747. msgData.myUnionId = human.db.unionUuid
  748. InnerMsg.sendMsg(0, msgData)
  749. end
  750. -- 查询公会排行榜
  751. function AB_UnionRank_Query(human)
  752. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  753. msgData.sourceServerId = Config.SVR_INDEX
  754. msgData.playerUuid = human.db._id
  755. msgData.myUnionId = human.db.unionUuid
  756. InnerMsg.sendMsg(0, msgData)
  757. end
  758. -- 查询玩家排行榜
  759. function AB_PlayerRank_Query(human)
  760. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  761. msgData.sourceServerId = Config.SVR_INDEX
  762. msgData.playerUuid = human.db._id
  763. msgData.myUnionId = human.db.unionUuid
  764. InnerMsg.sendMsg(0, msgData)
  765. end
  766. -- 发起集结
  767. function AB_Gather(human, targetCityId, opType)
  768. if not AnotherWorldBattleConfig.city[targetCityId] then
  769. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  770. end
  771. if opType ~= 1 and opType ~= 2 then
  772. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  773. end
  774. local unionId = human.db.unionUuid
  775. if not unionId then
  776. return Broadcast.sendErr(human, Lang.AB_NO_UNION)
  777. end
  778. -- 会长/副会长才能集结
  779. if not UnionLogic.IsTopTwoManager(human, unionId) then
  780. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANAGER)
  781. end
  782. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GATHER
  783. msgData.sourceServerId = Config.SVR_INDEX
  784. msgData.playerUuid = human.db._id
  785. msgData.myUnionId = human.db.unionUuid
  786. msgData.targetCityId = targetCityId
  787. msgData.opType = opType
  788. InnerMsg.sendMsg(0, msgData)
  789. end
  790. -- 请求挑战某个据点
  791. function AB_TryChallengePoint(human, targetCityId, targetPointIdx)
  792. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  793. if not combatHero or not next(combatHero) then
  794. return Broadcast.sendErr(human, Lang.COMBAT_NEED_FIGHT_HERO)
  795. end
  796. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  797. msgData.sourceServerId = Config.SVR_INDEX
  798. msgData.playerUuid = human.db._id
  799. msgData.myUnionId = human.db.unionUuid
  800. msgData.targetCityId = targetCityId
  801. msgData.targetPointIdx = targetPointIdx
  802. InnerMsg.sendMsg(0, msgData)
  803. end
  804. -- 战斗结束
  805. local function challenge_End(human, args)
  806. local cityId = args.cityId
  807. local pointIdx = args.pointIdx
  808. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_CHALLENGE_END
  809. msgData.sourceServerId = Config.SVR_INDEX
  810. msgData.playerUuid = human.db._id
  811. msgData.myUnionId = human.db.unionUuid
  812. msgData.targetCityId = cityId
  813. msgData.targetPointIdx = pointIdx
  814. msgData.challengeRes = args.challengeRes
  815. -- 挑战没有胜利
  816. if args.challengeRes ~= CombatDefine.RESULT_WIN then
  817. -- 说明之前已经在跨服上保存玩家的基础数据了
  818. -- if human.db.anotherWorlBattle then
  819. -- return
  820. -- end
  821. msgData.playerShowInfo = {
  822. name = human.db.name,
  823. lv = human.db.lv,
  824. power = human.db.zhandouli,
  825. }
  826. return InnerMsg.sendMsg(0, msgData)
  827. end
  828. if not human.db.anotherWorlBattle then
  829. human.db.anotherWorlBattle = {
  830. startTime = os.time(),
  831. formation = {}
  832. }
  833. end
  834. -- 把当前战斗阵容数据保存到当前模块,作为防守阵容
  835. local combatData = CombatPosLogic.getCombatHeroDB(human, CombatDefine.COMBAT_TYPE35)
  836. local formationData = human.db.anotherWorlBattle.formation or {}
  837. formationData[cityId] = formationData[cityId] or {}
  838. formationData[cityId][pointIdx] = Util.copyTable(combatData)
  839. -- 把最新的防守英雄uuid列表推送给客户端
  840. sendDefHeroArr(human)
  841. --同步到跨服
  842. msgData.playerShowInfo = generateShowInfo(human)
  843. InnerMsg.sendMsg(0, msgData)
  844. -- 清空战斗阵容
  845. CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  846. end
  847. -- 更换据点的防守阵容
  848. function AB_UpdateLineup(human, msg)
  849. if not isBattleStage() then
  850. return Broadcast.sendErr(human, Lang.AB_NOT_BATTLE_TIME)
  851. end
  852. local anotherWorlBattle = human.db.anotherWorlBattle
  853. if not anotherWorlBattle or not anotherWorlBattle.formation then
  854. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  855. end
  856. local cityId = msg.cityId
  857. local pointIdx = msg.pointIdx
  858. local formationData = anotherWorlBattle.formation
  859. if not formationData[cityId] or not formationData[cityId][pointIdx] then
  860. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  861. end
  862. local res, heroList, helpList = CombatPosLogic.CheckUpdatePos(human, msg)
  863. if not res then
  864. return Broadcast.sendErr(human, Lang.COMBAT_POS__ERR)
  865. end
  866. local len = 0
  867. local heroArr = {}
  868. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  869. local uuid = heroList[i] or ""
  870. if uuid ~= "0" and uuid ~= "" then
  871. if isDefHero(human, uuid, cityId, pointIdx) then
  872. return Broadcast.sendErr(human, Lang.AB_HERO_IN_OTHER_POINT)
  873. end
  874. len = len + 1
  875. heroArr[len] = getHeroInfo(human, uuid)
  876. end
  877. end
  878. if len == 0 then
  879. return
  880. end
  881. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_POINT_LINEIP
  882. msgData.sourceServerId = Config.SVR_INDEX
  883. msgData.playerUuid = human.db._id
  884. msgData.heroArr = heroArr
  885. msgData.targetCityId = cityId
  886. msgData.targetPointIdx = pointIdx
  887. msgData.formation = msg.formation
  888. msgData.heroList = heroList
  889. msgData.helpList = helpList
  890. InnerMsg.sendMsg(0, msgData)
  891. end
  892. -- 放弃据点
  893. function AB_LeavePoint(human, msg)
  894. local targetCityId = msg.cityId
  895. if not AnotherWorldBattleConfig.city[targetCityId] then
  896. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  897. end
  898. local targetPointIdx = msg.pointIdx
  899. if targetPointIdx <= 0 or targetPointIdx > AnotherWorldBattleDefine.AB_POINT_MAX_NUM then
  900. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  901. end
  902. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_LEAVE_POINT
  903. msgData.sourceServerId = Config.SVR_INDEX
  904. msgData.playerUuid = human.db._id
  905. msgData.myUnionId = human.db.unionUuid
  906. msgData.targetCityId = targetCityId
  907. msgData.targetPointIdx = targetPointIdx
  908. InnerMsg.sendMsg(0, msgData)
  909. end
  910. --获取据点的防守阵容数据
  911. function AB_GetPointLineup(human, msg)
  912. local targetCityId = msg.cityId
  913. local targetPointIdx = msg.pointIdx
  914. local anotherWorlBattle = human.db.anotherWorlBattle
  915. local formationData = anotherWorlBattle.formation
  916. if not formationData[targetCityId] or not formationData[targetCityId][targetPointIdx] then
  917. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  918. end
  919. local extraArgs = {
  920. cityId = targetCityId,
  921. pointIdx = targetPointIdx
  922. }
  923. CombatPosLogic.posQuery(human, msg.type, msg.groupID, msg.param, 1, extraArgs)
  924. end
  925. -- 请求公会士气信息
  926. function AB_GetMyUnionMoraleInfo(human)
  927. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_MYUIONMORALE
  928. msgData.sourceServerId = Config.SVR_INDEX
  929. msgData.playerUuid = human.db._id
  930. msgData.myUnionId = human.db.unionUuid
  931. InnerMsg.sendMsg(0, msgData)
  932. end
  933. -- 给本公会加士气
  934. function AB_Morale_Do(human)
  935. local unionId = human.db.unionUuid
  936. if not UnionLogic.IsTopTwoManager(human, unionId) then
  937. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  938. end
  939. -- 先扣除道具
  940. local moraleCostCfg = AnotherWorldBattleConfig.var[1].moraleCost
  941. if not moraleCostCfg then
  942. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  943. end
  944. local itemId, itemNum = moraleCostCfg[1], moraleCostCfg[2]
  945. if BagLogic.getItemCnt(human, itemId) < itemNum then
  946. return Broadcast.sendErr(human, COMMON_ITEM_NOT_ENOUGH)
  947. end
  948. BagLogic.delItem(human, itemId, itemNum, LOGTAG)
  949. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UIONMORALE_DO
  950. msgData.sourceServerId = Config.SVR_INDEX
  951. msgData.playerUuid = human.db._id
  952. msgData.myUnionId = human.db.unionUuid
  953. InnerMsg.sendMsg(0, msgData)
  954. end
  955. -- 查询据点羁绊数据
  956. function AB_PointLine_JiBan_Query(human, msg)
  957. if not isBattleStage() then
  958. return
  959. end
  960. JibanLogic = JibanLogic or require("combat.JibanLogic")
  961. local extraArgs = {
  962. cityId = msg.cityId,
  963. pointIdx = msg.pointIdx,
  964. }
  965. JibanLogic.query(human, msg.combatType, msg.heroID, extraArgs)
  966. end
  967. -- 更新据点羁绊
  968. function AB_PointLine_JiBan_Update(human, msg)
  969. if not isBattleStage() then
  970. return
  971. end
  972. JibanLogic = JibanLogic or require("combat.JibanLogic")
  973. local extraArgs = {
  974. cityId = msg.cityId,
  975. pointIdx = msg.pointIdx,
  976. }
  977. JibanLogic.update(human, msg.combatType, msg.jibanList, msg.heroIdArr, extraArgs)
  978. end
  979. -- 查询据点精灵数据
  980. function AB_PointLine_Elf_Query(human, msg)
  981. if not isBattleStage() then
  982. return
  983. end
  984. local extraArgs = {
  985. cityId = msg.cityId,
  986. pointIdx = msg.pointIdx,
  987. }
  988. CombatPosLogic.Elf_Pos_Query(human, msg.combatType, extraArgs)
  989. end
  990. -- 更新据点精灵
  991. function AB_PointLine_Elf_Update(human, msg)
  992. if not isBattleStage() then
  993. return
  994. end
  995. local extraArgs = {
  996. cityId = msg.cityId,
  997. pointIdx = msg.pointIdx,
  998. }
  999. CombatPosLogic.Elf_Pos_Update(human, msg.combatType, msg.elfPosArr, extraArgs)
  1000. end
  1001. ------------------------------------C2N---------------------------------------------------
  1002. -- 跨服通知活动开启
  1003. function C2N_Act_Start(msg)
  1004. local startTime = msg.startTime
  1005. if not startTime or startTime == 0 then
  1006. return
  1007. end
  1008. CommonDB.updateValue(CommonDB.KEY_ANOTHERWORLDBATTLE_START_TI, startTime)
  1009. end
  1010. -- 错误提示
  1011. function C2N_ErrTips(msg)
  1012. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1013. if not human then
  1014. return
  1015. end
  1016. local tips = Lang.DATA_ERR
  1017. local errCode = msg.errCode
  1018. if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
  1019. tips = Lang.AB_NOT_OPEN_TIME
  1020. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
  1021. tips = Lang.AB_NOT_UNION_NUM_EXCEED
  1022. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
  1023. tips = Lang.AB_UNION_NO_JOIN
  1024. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
  1025. tips = Lang.DATA_ERR
  1026. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
  1027. tips = Lang.AB_NOT_OCCUPY_POINT
  1028. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
  1029. tips = Lang.AB_GATHER_CD
  1030. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
  1031. tips = Lang.AB_CITY_NOT_ADDJION
  1032. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
  1033. tips = Lang.AB_JOINED
  1034. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_9 then
  1035. tips = Lang.AB_CITY_NO_GATHER
  1036. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_10 then
  1037. tips = Lang.AB_OCCUPY_POINT_MAX
  1038. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_11 then
  1039. tips = Lang.AB_POINT_CHALLENGING
  1040. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_12 then
  1041. tips = Lang.AB_CHALLENGING_TIMES_NOT_ENOUGH
  1042. end
  1043. Broadcast.sendErr(human, tips)
  1044. end
  1045. -- 跨服返回状态
  1046. function C2N_State_Response(msg)
  1047. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1048. if not human then
  1049. return
  1050. end
  1051. -- 只用于弹出提示框
  1052. if msg.isTips and msg.isTips == 1 then
  1053. if (msg.systemState > 0 and msg.systemState <= 2) and msg.joinState <= 1 then
  1054. local msgRet = Msg.gc.GC_AB_TIPS
  1055. Msg.send(msgRet, human.fd)
  1056. end
  1057. return
  1058. end
  1059. local msgRet = Msg.gc.GC_AB_GetState
  1060. msgRet.joinState = msg.joinState
  1061. msgRet.systemState = msg.systemState
  1062. if msgRet.joinState == 0 then
  1063. local unionId = human.db.unionUuid
  1064. if not unionId then
  1065. msgRet.Joinstate = 2
  1066. return Msg.send(msgRet, human.fd)
  1067. end
  1068. -- 公会排名前二才行
  1069. if not isTopTwoUnion(human) then
  1070. msgRet.Joinstate = 2
  1071. return Msg.send(msgRet, human.fd)
  1072. end
  1073. end
  1074. Msg.send(msgRet, human.fd)
  1075. end
  1076. -- 报名成功
  1077. function C2N_Join_Response(msg)
  1078. local now = os.time()
  1079. local unionId = msg.myUnionId
  1080. UnionLogic.UpdateJoinAbTime(unionId, now)
  1081. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1082. if not human then
  1083. return
  1084. end
  1085. local msgRet = Msg.gc.GC_AB_JOIN
  1086. msgRet.Joinstate = 1
  1087. Msg.send(msgRet, human.fd)
  1088. end
  1089. -- 跨服返回的所有城池数据
  1090. function C2N_AllCity_Response(msg)
  1091. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1092. if not human then
  1093. return
  1094. end
  1095. local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
  1096. msgRet.myBaseCityId = msg.myUnionBaseCityId
  1097. msgRet.hasPointNum = msg.hasPointNum
  1098. msgRet.challengeTimes = msg.challengeTimes
  1099. local now = os.time()
  1100. msgRet.leftTime = msg.lastTime
  1101. if msgRet.leftTime ~= 0 then
  1102. msgRet.leftTime = (msg.lastTime + AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC) - now
  1103. end
  1104. msgRet.cityArr[0] = 0
  1105. local cityArrMsg = msgRet.cityArr
  1106. for cityId, cityInfo in ipairs(msg.cityArr) do
  1107. cityArrMsg[0] = cityId
  1108. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1109. cityArrMsg[cityId].cityId = cityId
  1110. cityArrMsg[cityId].cityName = cityCfg.cityName
  1111. cityArrMsg[cityId].cityLv = cityCfg.cityLv
  1112. cityArrMsg[cityId].occupyPointNum = cityInfo.occupyPointNum or 0
  1113. cityArrMsg[cityId].occupyUnionName = cityInfo.occupyUnionName or ""
  1114. cityArrMsg[cityId].cityState = cityInfo.cityState
  1115. cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
  1116. for i, cId in ipairs(cityCfg.adJoinCityArr) do
  1117. cityArrMsg[cityId].adJoinCityArr[i] = cId
  1118. end
  1119. end
  1120. msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
  1121. for i, cityId in ipairs(msg.myOccupyCityArr) do
  1122. msgRet.myOccupyCityArr[i] = cityId
  1123. end
  1124. -- 占领据点奖励
  1125. local itemId, itemNum = 0, 0
  1126. local cityCfg = AnotherWorldBattleConfig.city[1]
  1127. itemId = cityCfg.cityAward[1]
  1128. for _, pointInfo in ipairs(msg.occupyPointData) do
  1129. local cityId = pointInfo[1]
  1130. local occupyTimeArr = pointInfo[2]
  1131. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1132. local minuteVal = 0
  1133. for _, timeTb in ipairs(occupyTimeArr) do
  1134. local sec = (timeTb[2] or now) - (timeTb[1] or now)
  1135. if sec > 0 then
  1136. minuteVal = minuteVal + sec
  1137. end
  1138. minuteVal = math.floor(minuteVal / 60)
  1139. end
  1140. itemNum = itemNum + minuteVal * cityCfg.cityAward[2]
  1141. end
  1142. local itemNumMax = calcRewardMax()
  1143. local isRun = actStartTimeCheck()
  1144. local isBattle = isBattleStage()
  1145. if isRun and isBattle then
  1146. itemNumMax = calcRewardNow()
  1147. end
  1148. if itemNumMax > 0 then
  1149. itemNum = math.min(itemNum, itemNumMax)
  1150. end
  1151. Grid.makeItem(msgRet.myUnionAward, itemId, itemNum)
  1152. Msg.send(msgRet, human.fd)
  1153. end
  1154. -- 跨服返回某个城池详细数据
  1155. function C2N_CityDetailed_Response(msg)
  1156. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1157. if not human then
  1158. return
  1159. end
  1160. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  1161. local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
  1162. msgRet.cityId = msg.targetCityId
  1163. msgRet.cityLv = cityCfg.cityLv
  1164. msgRet.cityIconId = cityCfg.cityIconId
  1165. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM )
  1166. local myUnionAwardNum = calcPointAward(msg.myUnionOccupyArr)
  1167. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  1168. -- 活动没有进入战斗阶段时, 使用默认数据
  1169. if #msg.pointArr == 0 then
  1170. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  1171. msg.pointArr[i] = {}
  1172. end
  1173. end
  1174. msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  1175. for pointIdx, pointInfo in ipairs(msg.pointArr) do
  1176. if pointInfo.occupyUnionName then
  1177. msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
  1178. msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
  1179. msgRet.pointArr[pointIdx].power = pointInfo.power
  1180. msgRet.pointArr[pointIdx].state = pointInfo.state
  1181. else
  1182. msgRet.pointArr[pointIdx].occupyUnionName = ""
  1183. msgRet.pointArr[pointIdx].occupyPlayerName = AnotherWorldBattleDefine.AB_DEF_NAME_STR.. pointIdx
  1184. msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
  1185. msgRet.pointArr[pointIdx].state = pointInfo.state
  1186. end
  1187. end
  1188. msgRet.gatherState = msg.gatherState
  1189. if msg.gatherState == 1 then
  1190. -- 公会会长/副会长才能集结
  1191. if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
  1192. msgRet.gatherState = 0
  1193. end
  1194. end
  1195. msgRet.gatherLeftTime = msg.gatherTime
  1196. if msg.gatherTime ~= -1 then
  1197. local now = os.time()
  1198. local subSec = msg.gatherTime + AnotherWorldBattleDefine.AB_GATHER_CD_SEC - now
  1199. msgRet.gatherLeftTime = subSec > 0 and subSec or 0
  1200. end
  1201. Msg.send(msgRet, human.fd)
  1202. end
  1203. -- 跨服返回某个据点数据
  1204. function C2N_PointDetailed_Response(msg)
  1205. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1206. if not human then
  1207. return
  1208. end
  1209. local pointInfo = msg.pointInfo
  1210. local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
  1211. msgRet.state = pointInfo.state
  1212. if pointInfo.name then
  1213. msgRet.name = pointInfo.name
  1214. msgRet.power = pointInfo.power
  1215. msgRet.head = pointInfo.head
  1216. msgRet.headFrame = pointInfo.headFrame
  1217. msgRet.defLv = pointInfo.defLv
  1218. msgRet.heroArr[0] = #pointInfo.heroArr
  1219. for i, heroInfo in ipairs(pointInfo.heroArr) do
  1220. msgRet.heroArr[i].heroBody = heroInfo.heroBody
  1221. msgRet.heroArr[i].heroStar = heroInfo.heroStar
  1222. msgRet.heroArr[i].heroLv = heroInfo.heroLv
  1223. msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
  1224. msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
  1225. msgRet.heroArr[i].heroId = heroInfo.heroId
  1226. msgRet.heroArr[i].heroQuality = heroInfo.heroQuality
  1227. end
  1228. else
  1229. msgRet.name = AnotherWorldBattleDefine.AB_DEF_NAME_STR .. msg.targetPointIdx
  1230. msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
  1231. msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
  1232. msgRet.defLv = 200
  1233. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  1234. msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
  1235. msgRet.heroArr[0] = 0
  1236. local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
  1237. for idx, monsterInfo in ipairs(monsterOutConfig.member) do
  1238. if idx > 6 then
  1239. break
  1240. end
  1241. msgRet.heroArr[0] = idx
  1242. local monsterID = monsterInfo[1]
  1243. local mcf = MonsterExcel.monster[monsterID]
  1244. msgRet.heroArr[idx].heroBody = mcf.body
  1245. msgRet.heroArr[idx].heroStar = mcf.star
  1246. msgRet.heroArr[idx].heroLv = monsterInfo[2]
  1247. msgRet.heroArr[idx].heroCamp = mcf.camp
  1248. msgRet.heroArr[idx].heroIcon = mcf.head
  1249. msgRet.heroArr[idx].heroId = monsterID
  1250. msgRet.heroArr[idx].heroQuality = mcf.heroQuality or 1
  1251. end
  1252. end
  1253. Msg.send(msgRet, human.fd)
  1254. end
  1255. -- 跨服返回公会出生点数据
  1256. function C2N_BaseCity_Response(msg)
  1257. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1258. if not human then
  1259. return
  1260. end
  1261. local baseCityInfo = msg.baseCityInfo
  1262. local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
  1263. local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
  1264. msgRet.cityIconId = cityCfg.cityIconId
  1265. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM)
  1266. local myUnionAwardNum = calcPointAward(baseCityInfo.myUnionOccupyArr)
  1267. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  1268. -- msgRet.cityIconId = baseCityInfo.occupyPointNum
  1269. msgRet.occupyPointNum = baseCityInfo.occupyPointNum
  1270. msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
  1271. msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
  1272. msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
  1273. msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
  1274. Msg.send(msgRet, human.fd)
  1275. end
  1276. -- 跨服返回玩家占领的据点数据
  1277. function C2N_PlayerOccupyPoint_Response(msg)
  1278. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1279. if not human then
  1280. return
  1281. end
  1282. local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
  1283. local myPointArr = msgRet.myPointArr
  1284. myPointArr[0] = 0
  1285. for idx, pointInfo in ipairs(msg.occupyPointArr) do
  1286. myPointArr[0] = idx
  1287. local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
  1288. myPointArr[idx].cityIconId = cityCfg.cityIconId
  1289. myPointArr[idx].cityName = cityCfg.cityName
  1290. myPointArr[idx].cityLv = cityCfg.cityLv
  1291. myPointArr[idx].pointIdx = pointInfo.pointIdx
  1292. myPointArr[idx].power = pointInfo.power
  1293. myPointArr[idx].cityId = pointInfo.cityId
  1294. myPointArr[idx].heroArr[0] = #pointInfo.heroArr
  1295. for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
  1296. local hero = myPointArr[idx].heroArr[heroIdx]
  1297. hero.heroBody = heroInfo.heroBody
  1298. hero.heroStar = heroInfo.heroStar
  1299. hero.heroLv = heroInfo.heroLv
  1300. hero.heroCamp = heroInfo.heroCamp
  1301. hero.heroIcon = heroInfo.heroIcon
  1302. hero.heroId = heroInfo.heroId
  1303. hero.heroQuality = heroInfo.heroQuality
  1304. end
  1305. end
  1306. Msg.send(msgRet, human.fd)
  1307. end
  1308. -- 跨服返回集结/取消集结成功
  1309. function C2N_Gather_Response(msg)
  1310. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1311. if not human then
  1312. return
  1313. end
  1314. local targetCityId = msg.targetCityId
  1315. local cityCfg = AnotherWorldBattleConfig.city[targetCityId]
  1316. local msgRet = Msg.gc.GC_AB_GARHER
  1317. msgRet.cityId = targetCityId
  1318. msgRet.cityName = cityCfg.cityName
  1319. msgRet.opType = msg.opType
  1320. Msg.send(msgRet, human.fd)
  1321. end
  1322. --跨服返回公会排行榜数据
  1323. function C2N_UnionRank_Response(msg)
  1324. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1325. if not human then
  1326. return
  1327. end
  1328. -- local itemId, itemNum = 184, 0
  1329. local rankReward = AnotherWorldBattleConfig.rankReward
  1330. local itemArr = getRankGenericAwadId(rankReward, 1)
  1331. local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
  1332. msgRet.unionRankArr[0] = 0
  1333. msgRet.myUnionRank = msg.myUnionRank
  1334. msgRet.myData.name = ""
  1335. msgRet.myData.power = 0
  1336. msgRet.myData.cityNum = 0
  1337. msgRet.myData.pointNum = 0
  1338. msgRet.myData.rankAward[0] = 0
  1339. for i, itemInfo in ipairs(itemArr or {}) do
  1340. msgRet.myData.rankAward[0] = i
  1341. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1342. end
  1343. for rank, rankdData in ipairs(msg.unionRankArr) do
  1344. msgRet.unionRankArr[0] = rank
  1345. msgRet.unionRankArr[rank].name = rankdData.name
  1346. msgRet.unionRankArr[rank].power = rankdData.power
  1347. msgRet.unionRankArr[rank].cityNum = rankdData.cityNum
  1348. msgRet.unionRankArr[rank].pointNum = rankdData.pointNum
  1349. -- Grid.makeItem(msgRet.unionRankArr[rank].rankAward, itemId, itemNum)
  1350. msgRet.unionRankArr[rank].rankAward[0] = 0
  1351. itemArr = getRankAward(rankReward, 1, rank)
  1352. for i, itemInfo in ipairs(itemArr or {}) do
  1353. msgRet.unionRankArr[rank].rankAward[0] = i
  1354. Grid.makeItem(msgRet.unionRankArr[rank].rankAward[i], itemInfo[1], itemInfo[2])
  1355. end
  1356. if rank == msg.myUnionRank then
  1357. msgRet.myData.name = rankdData.name
  1358. msgRet.myData.power = rankdData.power
  1359. msgRet.myData.cityNum = rankdData.cityNum
  1360. msgRet.myData.pointNum = rankdData.pointNum
  1361. -- Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1362. msgRet.myData.rankAward[0] = 0
  1363. for i, itemInfo in ipairs(itemArr or {}) do
  1364. msgRet.myData.rankAward[0] = i
  1365. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1366. end
  1367. end
  1368. end
  1369. if msgRet.myData.power == 0 then
  1370. local unionId = human.db.unionUuid
  1371. local queryFiles = {name = 1, zhandouli = 1}
  1372. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  1373. msgRet.myData.name = unionInfo and unionInfo.name or ""
  1374. msgRet.myData.power = unionInfo and unionInfo.zhandouli or 0
  1375. end
  1376. Msg.send(msgRet, human.fd)
  1377. end
  1378. --跨服返回玩家排行榜数据
  1379. function C2N_PlayerRank_Response(msg)
  1380. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1381. if not human then
  1382. return
  1383. end
  1384. -- local itemId, itemNum = 184, 0
  1385. local rankReward = AnotherWorldBattleConfig.rankReward
  1386. local itemArr = getRankGenericAwadId(rankReward, 2)
  1387. local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
  1388. msgRet.playerRankArr[0] = 0
  1389. msgRet.myRank = msg.myRank
  1390. msgRet.myData.name = human.db.name
  1391. msgRet.myData.power = human.db.zhandouli
  1392. msgRet.myData.pointNum = 0
  1393. msgRet.myData.pointWeight = 0
  1394. msgRet.myData.rankAward[0] = 0
  1395. for i, itemInfo in ipairs(itemArr or {}) do
  1396. msgRet.myData.rankAward[0] = i
  1397. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1398. end
  1399. for rank, rankdData in ipairs(msg.playerRankArr) do
  1400. msgRet.playerRankArr[0] = rank
  1401. msgRet.playerRankArr[rank].name = rankdData.name
  1402. msgRet.playerRankArr[rank].power = rankdData.power
  1403. msgRet.playerRankArr[rank].pointNum = rankdData.pointNum
  1404. msgRet.playerRankArr[rank].pointWeight = rankdData.pointWeight
  1405. -- itemId, itemNum = getRankAward(rankReward, 2, rank)
  1406. -- Grid.makeItem(msgRet.playerRankArr[rank].rankAward, itemId, itemNum)
  1407. itemArr = getRankAward(rankReward, 2, rank)
  1408. msgRet.playerRankArr[rank].rankAward[0] = 0
  1409. for i, itemInfo in ipairs(itemArr or {}) do
  1410. msgRet.playerRankArr[rank].rankAward[0] = i
  1411. Grid.makeItem(msgRet.playerRankArr[rank].rankAward[i], itemInfo[1], itemInfo[2])
  1412. end
  1413. if rank == msg.myRank then
  1414. msgRet.myData.pointNum = rankdData.pointNum
  1415. msgRet.myData.pointWeight = rankdData.pointWeight
  1416. -- Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1417. msgRet.myData.rankAward[0] = 0
  1418. for i, itemInfo in ipairs(itemArr or {}) do
  1419. msgRet.myData.rankAward[0] = i
  1420. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1421. end
  1422. end
  1423. end
  1424. Msg.send(msgRet, human.fd)
  1425. end
  1426. -- 跨服返回要挑战的据点的数据(据点可以被挑战)
  1427. function C2N_TryChallengePoint_Response(msg)
  1428. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1429. if not human then
  1430. return
  1431. end
  1432. local pointInfo = msg.pointInfo
  1433. human.AB_Battle_Cache = {
  1434. isGather = pointInfo.isGather,
  1435. cityId = pointInfo.targetCityId,
  1436. pointIdx = pointInfo.targetPointIdx,
  1437. defMoraleAttrIdx = pointInfo.defMoraleAttrIdx,
  1438. atkMoraleAttrIdx = pointInfo.atkMoraleAttrIdx,
  1439. }
  1440. if pointInfo.occupySrvId then -- 玩家占领
  1441. local args = {
  1442. combatType = CombatDefine.COMBAT_TYPE35,
  1443. nServerIndex = pointInfo.occupySrvId,
  1444. param = pointInfo.occupyPlayerUuid,
  1445. extraArgs = {
  1446. cityId = pointInfo.targetCityId,
  1447. pointIdx = pointInfo.targetPointIdx,
  1448. useDef = true,
  1449. }
  1450. }
  1451. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
  1452. else
  1453. -- 机器人
  1454. CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
  1455. end
  1456. end
  1457. -- 跨服通知据点被别的玩家占领了
  1458. function C2N_PointLose_Response(msg)
  1459. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1460. if not human then
  1461. local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
  1462. if not db then
  1463. return
  1464. end
  1465. human = {}
  1466. human.db = db
  1467. end
  1468. -- 更新防守阵容数据
  1469. local loseCityId = msg.loseCityId
  1470. local losePointIdx = msg.losePointIdx
  1471. local formationData = human.db.anotherWorlBattle.formation
  1472. formationData[loseCityId][losePointIdx] = nil
  1473. -- 玩家不在线, 手动保存数据
  1474. if not human.fd then
  1475. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1476. end
  1477. local cityCfg = AnotherWorldBattleConfig.city[loseCityId]
  1478. -- 发邮件
  1479. local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
  1480. local content = Util.format(mailCfg.content, cityCfg and cityCfg.cityName or "", loseCityId)
  1481. MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, content, nil, mailCfg.senderName or "GM")
  1482. -- 把最新的防守阵容数据推给客户端
  1483. if human.fd then
  1484. sendDefHeroArr(human)
  1485. end
  1486. end
  1487. -- 跨服通知可以更换据点的防守阵容数据
  1488. function C2N_UpdatePointLineup_Response(msg)
  1489. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1490. if not human then
  1491. local db = RoleDBLogic.getDb(msg.playerUuid)
  1492. if not db then
  1493. return
  1494. end
  1495. human = {}
  1496. human.db = db
  1497. end
  1498. local anotherWorlBattle = human.db.anotherWorlBattle
  1499. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1500. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  1501. end
  1502. local cityId = msg.targetCityId
  1503. local pointIdx = msg.targetPointIdx
  1504. if not anotherWorlBattle.formation[cityId] or not anotherWorlBattle.formation[cityId][pointIdx] then
  1505. return
  1506. end
  1507. local pointLinupData = anotherWorlBattle.formation[cityId][pointIdx]
  1508. pointLinupData.list = msg.heroList
  1509. pointLinupData.helpList = msg.helpList
  1510. pointLinupData.formation = msg.formation
  1511. if not human.fd then
  1512. ObjHuman.save(human)
  1513. end
  1514. sendDefHeroArr(human)
  1515. Broadcast.sendCenter(human, Lang.AB_UPDATE_LINEUP_SUCC)
  1516. end
  1517. -- 跨服通知放弃据点成功
  1518. function C2N_LeavePoint_Response(msg)
  1519. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1520. if not human then
  1521. local db = RoleDBLogic.getDb(msg.playerUuid)
  1522. if not db then
  1523. return
  1524. end
  1525. human = {}
  1526. human.db = db
  1527. end
  1528. local anotherWorlBattle = human.db.anotherWorlBattle
  1529. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1530. return
  1531. end
  1532. local cityId = msg.targetCityId
  1533. local pointIdx = msg.targetPointIdx
  1534. anotherWorlBattle.formation[cityId][pointIdx] = nil
  1535. if not next(anotherWorlBattle.formation[cityId]) then
  1536. anotherWorlBattle.formation[cityId] = nil
  1537. end
  1538. -- 玩家不在线, 手动保存数据
  1539. if not human.fd then
  1540. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1541. else
  1542. -- 把最新的防守阵容数据推给客户端
  1543. sendDefHeroArr(human)
  1544. end
  1545. end
  1546. -- 跨服返回本公会士气信息
  1547. function C2N_MyUnionMoraleInfo_Response(msg)
  1548. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1549. if not human then
  1550. return
  1551. end
  1552. local varCfg = AnotherWorldBattleConfig.var[1]
  1553. local msgRet = Msg.gc.GC_AB_GET_MORALE_INFO
  1554. msgRet.moraleState = msg.moraleState
  1555. msgRet.leftTime = 0
  1556. local now = os.time()
  1557. local leftTime = msg.moraleStartTime + AnotherWorldBattleDefine.AB_MORALE_DURATION - now
  1558. if leftTime > 0 then
  1559. msgRet.leftTime = leftTime
  1560. end
  1561. local itemCfg = varCfg.moraleCost
  1562. local itemId = itemCfg and itemCfg[1] or 101
  1563. local itemNum = itemCfg and itemCfg[2] or 0
  1564. Grid.makeItem(msgRet.moraleCost, itemId, itemNum)
  1565. msgRet.moraleAttrs[0] = 0
  1566. local moraleAttrCfg = varCfg.moraleAtrrs
  1567. if moraleAttrCfg then
  1568. local attrArr = moraleAttrCfg[msg.moraleAttrIdx] or moraleAttrCfg[1]
  1569. for i, attrTb in ipairs(attrArr) do
  1570. msgRet.moraleAttrs[0] = i
  1571. msgRet.moraleAttrs[i].key = attrTb[1]
  1572. msgRet.moraleAttrs[i].value = attrTb[2]
  1573. end
  1574. end
  1575. Msg.send(msgRet, human.fd)
  1576. end
  1577. -- 跨服返回加士气结果
  1578. function C2N_UnionMorale_Response(msg)
  1579. if msg.opRes == 0 then
  1580. return
  1581. end
  1582. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1583. if not human then
  1584. local db = RoleDBLogic.getDb(msg.playerUuid)
  1585. if not db then
  1586. return
  1587. end
  1588. human = {}
  1589. human.db = db
  1590. end
  1591. local moraleCostCfg = AnotherWorldBattleConfig.var[1].moraleCost
  1592. local itemId, itemNum = moraleCostCfg[1], moraleCostCfg[2]
  1593. BagLogic.addItem(human, itemId, itemNum, LOGTAG)
  1594. if not human.fd then
  1595. ObjHuman.save(human)
  1596. end
  1597. end
  1598. -- 跨服通知给玩家发奖
  1599. function C2N_IssueReward(msg)
  1600. -- 删除公会参加异界之战活动时间
  1601. UnionLogic.UpdateJoinAbTime(msg.unionOccupyInfo.unionId, nil)
  1602. resetDefData(msg.unionOccupyInfo.playerInfoArr)
  1603. -- 发奖
  1604. local awardObjArr, occupyCityInfo = genAwardObjArr(msg.unionOccupyInfo)
  1605. if awardObjArr then
  1606. local issueRewardQueue = createRewardQueue()
  1607. issueRewardQueue.extraInfo = occupyCityInfo
  1608. for _, obj in ipairs(awardObjArr) do
  1609. issueRewardQueue:add(obj)
  1610. end
  1611. issueRewardQueue:insertDB()
  1612. end
  1613. end
  1614. -------------------------------------------战斗---------------------------------
  1615. function getCombatMonsterOutID(human, side, args)
  1616. if side ~= CombatDefine.DEFEND_SIDE then return end
  1617. local cityId = args[2]
  1618. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1619. return cityCfg and cityCfg.pointMonsterId
  1620. end
  1621. function getCombatObjList(human, side, args, combatType, extraArgs)
  1622. if side == CombatDefine.ATTACK_SIDE and not human then return end
  1623. if side == CombatDefine.DEFEND_SIDE and human then
  1624. return
  1625. end
  1626. if not human then
  1627. local uuid = args[1]
  1628. local db = RoleDBLogic.getDb(uuid)
  1629. if not db then
  1630. return
  1631. end
  1632. human = {}
  1633. human.db = db
  1634. end
  1635. return CombatLogic.getHumanObjList(human, combatType, extraArgs)
  1636. end
  1637. function getCombatHeros(human, combatType, args)
  1638. if not human.db.anotherWorlBattle then
  1639. return
  1640. end
  1641. if not args then
  1642. return
  1643. end
  1644. local formation = human.db.anotherWorlBattle.formation
  1645. if not formation then
  1646. return
  1647. end
  1648. local cityId, pointIdx = args.cityId, args.pointIdx
  1649. if formation[cityId] and formation[cityId][pointIdx] then
  1650. local combatHeroDB = formation[cityId][pointIdx]
  1651. return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
  1652. end
  1653. end
  1654. function onFightBegin(human, cbParam, combatType, param)
  1655. if not human.AB_Battle_Cache or (not human.AB_Battle_Cache.isGather and not human.AB_Battle_Cache.defMoraleAttrIdx and not human.AB_Battle_Cache.atkMoraleAttrIdx) then
  1656. return
  1657. end
  1658. local function addAttr(obj, attrs)
  1659. for _, atrrTb in ipairs(attrs or {}) do
  1660. local attrId, attrVal = atrrTb[1], atrrTb[2]
  1661. obj.sysAttr[attrId] = (obj.sysAttr[attrId] or 0) + attrVal
  1662. end
  1663. end
  1664. local atkGatherAttrs, atkMoraleAttrs, defMoraleAttrs
  1665. local varCfg = AnotherWorldBattleConfig.var[1]
  1666. if human.AB_Battle_Cache.isGather then
  1667. atkGatherAttrs = varCfg.gatherAttrs
  1668. end
  1669. if human.AB_Battle_Cache.atkMoraleAttrIdx then
  1670. local idx = human.AB_Battle_Cache.atkMoraleAttrIdx
  1671. atkMoraleAttrs = varCfg.moraleAtrrs and varCfg.moraleAtrrs[idx]
  1672. end
  1673. if human.AB_Battle_Cache.defMoraleAttrIdx then
  1674. local idx = human.AB_Battle_Cache.defMoraleAttrIdx
  1675. defMoraleAttrs = varCfg.moraleAtrrs and varCfg.moraleAtrrs[idx]
  1676. end
  1677. for index = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  1678. local side = index > CombatDefine.COMBAT_HERO_CNT and CombatDefine.DEFEND_SIDE or CombatDefine.ATTACK_SIDE
  1679. local realPos = CombatLogic.getPos(side, index)
  1680. local obj = CombatImpl.objList[realPos]
  1681. if obj then
  1682. if side == CombatDefine.ATTACK_SIDE then
  1683. if atkGatherAttrs or atkMoraleAttrs then
  1684. addAttr(obj, atkGatherAttrs)
  1685. addAttr(obj, atkMoraleAttrs)
  1686. obj.isSysAttrChange = true
  1687. end
  1688. else
  1689. if defMoraleAttrs then
  1690. addAttr(obj, defMoraleAttrs)
  1691. obj.isSysAttrChange = true
  1692. end
  1693. end
  1694. end
  1695. end
  1696. end
  1697. function onFightEnd(human, result, type, cbParam, combatInfo)
  1698. -- if result == CombatDefine.RESULT_WIN then
  1699. -- challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
  1700. -- end
  1701. local args = {
  1702. cityId = human.AB_Battle_Cache.cityId,
  1703. pointIdx = human.AB_Battle_Cache.pointIdx,
  1704. challengeRes = result
  1705. }
  1706. human.AB_Battle_Cache = nil
  1707. challenge_End(human, args)
  1708. end