AnotherWorldBattleNS.lua 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009
  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 myUnionAwardNum
  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 genAwardObjArr(unionOccupyInfo)
  365. local function calcMinute(timeArr)
  366. local minuteVal = 0
  367. for _, timeTb in ipairs(timeArr or {}) do
  368. local sec = (timeTb[2] or 0) - (timeTb[1] or 0)
  369. if sec > 0 then
  370. minuteVal = minuteVal + sec
  371. end
  372. end
  373. return math.floor(minuteVal / 60)
  374. end
  375. -- 没有玩家参与
  376. if not unionOccupyInfo.playerInfoArr or #unionOccupyInfo.playerInfoArr <= 0 then
  377. return
  378. end
  379. local itemList = {}
  380. local occupyCityInfo = {0,0,0,0,0}
  381. local item_185_Id = 185
  382. local item_185_Num = 0
  383. occupyCityInfo[1] = unionOccupyInfo.occuoyPointNum
  384. -- 额外奖励
  385. item_185_Num = item_185_Num + (unionOccupyInfo.occuoyPointNum or 0)
  386. for _, cityId in ipairs(unionOccupyInfo.occupyCityArr) do
  387. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  388. if cityCfg then
  389. if cityCfg.isBaseCity == 1 then
  390. item_185_Num = item_185_Num + 20
  391. else
  392. if cityCfg.cityLv == 2 then
  393. item_185_Num = item_185_Num + 2
  394. occupyCityInfo[2] = occupyCityInfo[2] + 1
  395. elseif cityCfg.cityLv == 3 then
  396. item_185_Num = item_185_Num + 3
  397. occupyCityInfo[3] = occupyCityInfo[3] + 1
  398. elseif cityCfg.cityLv == 4 then
  399. item_185_Num = item_185_Num + 5
  400. occupyCityInfo[4] = occupyCityInfo[4] + 1
  401. elseif cityCfg.cityLv == 5 then
  402. item_185_Num = item_185_Num + 20
  403. occupyCityInfo[5] = occupyCityInfo[5] + 1
  404. end
  405. end
  406. end
  407. end
  408. -- 占领据点每分钟的奖励
  409. for _, pointInfo in ipairs(unionOccupyInfo.point2CityIdArr) do
  410. local cityId = pointInfo[1]
  411. local occupyTimeArr = pointInfo[2]
  412. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  413. local totalMinVal = calcMinute(occupyTimeArr)
  414. if totalMinVal > 0 then
  415. local itemId, itemNum = cityCfg.cityAward[1], cityCfg.cityAward[2]
  416. itemList[itemId] = (itemList[itemId] or 0) + totalMinVal * itemNum
  417. end
  418. end
  419. if item_185_Num > 0 then
  420. itemList[item_185_Id] = item_185_Num
  421. end
  422. local itemArr = {}
  423. for itemId, itemNum in pairs(itemList) do
  424. itemArr[#itemArr+1] = { itemId, itemNum }
  425. end
  426. local rankReward = AnotherWorldBattleConfig.rankReward
  427. local awardObjArr = {}
  428. for _, playerInfo in ipairs(unionOccupyInfo.playerInfoArr) do
  429. local playerUuid = playerInfo[1]
  430. local playerRank = playerInfo[2]
  431. -- 据点每分钟奖励 + 额外奖励
  432. awardObjArr[#awardObjArr+1] = {playerUuid, itemArr, AnotherWorldBattleDefine.AB_AWARD_MAIL_ID}
  433. -- 公会排名奖励
  434. -- local itemId, itemNum = getRankAward(rankReward, 1, unionOccupyInfo.unionRank)
  435. -- if itemId and itemNum then
  436. -- awardObjArr[#awardObjArr+1] = {playerUuid, {{itemId, itemNum}}, AnotherWorldBattleDefine.AB_UNIONRANK_AWARD_MAIL_ID, unionOccupyInfo.unionRank}
  437. -- end
  438. local itemTb = getRankAward(rankReward, 1, unionOccupyInfo.unionRank)
  439. if itemTb then
  440. local items
  441. for _, itemInfo in ipairs(itemTb) do
  442. items = items or {}
  443. items[#items+1] = {itemInfo[1], itemInfo[2]}
  444. end
  445. if items then
  446. awardObjArr[#awardObjArr+1] = {playerUuid, items, AnotherWorldBattleDefine.AB_UNIONRANK_AWARD_MAIL_ID, unionOccupyInfo.unionRank}
  447. end
  448. end
  449. -- 玩家排名奖励
  450. -- local itemId2, itemNum2 = getRankAward(rankReward, 2, playerRank)
  451. -- if itemId2 and itemNum2 then
  452. -- awardObjArr[#awardObjArr+1] = {playerUuid, {{itemId2, itemNum2}}, AnotherWorldBattleDefine.AB_PLAYERRANK_AWARD_MAIL_ID, playerRank}
  453. -- end
  454. itemTb = getRankAward(rankReward, 2, playerRank)
  455. if itemTb then
  456. local items
  457. for _, itemInfo in ipairs(itemTb) do
  458. items = items or {}
  459. items[#items+1] = {itemInfo[1], itemInfo[2]}
  460. end
  461. if items then
  462. awardObjArr[#awardObjArr+1] = {playerUuid, items, AnotherWorldBattleDefine.AB_PLAYERRANK_AWARD_MAIL_ID, playerRank}
  463. end
  464. end
  465. end
  466. return awardObjArr, occupyCityInfo
  467. end
  468. -- 活动是否处于开启中
  469. function IsRuning(joinTime)
  470. if not joinTime then
  471. return true
  472. end
  473. local wDay = getWDay()
  474. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  475. return false
  476. end
  477. local now = os.time()
  478. local toDayStartTime = Util.getDayStartTime(now)
  479. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  480. return false
  481. end
  482. local diffDays = Util.diffDay(joinTime)
  483. -- local joinWday = Util.getWeekDay(joinTime)
  484. -- 如果是周六加入则相差6天, 如果是周日加入则相差5天。 当前时间与加入时间相差6或5天, 则都表示当前可能是活动最后一天, 如果当前时间 > 结束时间则活动结束
  485. -- if (diffDays == AnotherWorldBattleDefine.AB_OPEN_DAYS and joinWday == 7) or (diffDays == (AnotherWorldBattleDefine.AB_OPEN_DAYS-1) and joinWday == 1) then
  486. -- if now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  487. -- return false
  488. -- end
  489. -- end
  490. -- < 6天说明处于本轮活动开启时间范围, > 6天说明活动已经结束
  491. if diffDays > AnotherWorldBattleDefine.AB_OPEN_DAYS then
  492. return false
  493. end
  494. return true
  495. end
  496. --检测上阵英雄
  497. function checkUpdatePos(human, msg)
  498. local heroList = Util.split(msg.heroList, ",")
  499. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  500. local uuid = heroList[i] or ""
  501. if uuid ~= "0" and uuid ~= "" then
  502. if isDefHero(human, uuid) then
  503. return false
  504. end
  505. end
  506. end
  507. return true
  508. end
  509. -- 公会战力更新
  510. function UnionPowerChange(unionId, newPower)
  511. if not actStartTimeCheck() then
  512. return false
  513. end
  514. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  515. msgData.myUnionId = unionId
  516. msgData.updateData = {}
  517. msgData.updateData.power = newPower
  518. InnerMsg.sendMsg(0, msgData)
  519. end
  520. -- 玩家战力更新
  521. function PlayerPowerChange(human)
  522. if not baseCondCheck(human) then
  523. return false
  524. end
  525. if not actStartTimeCheck() then
  526. return false
  527. end
  528. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  529. msgData.playerUuid = human.db._id
  530. msgData.myUnionId = human.db.unionUuid
  531. msgData.updateData = {}
  532. msgData.updateData.power = human.db.zhandouli
  533. InnerMsg.sendMsg(0, msgData)
  534. end
  535. -- 英雄更新
  536. function HeroDataUpdate(human, heroUuid)
  537. if not baseCondCheck(human) then
  538. return false
  539. end
  540. if not actStartTimeCheck() then
  541. return false
  542. end
  543. local cityId, pointIdx = isDefHero(human, heroUuid)
  544. if not cityId then
  545. return
  546. end
  547. HeroLogic = HeroLogic or require("hero.HeroLogic")
  548. local heroGrid = HeroLogic.getHeroGridByUuid(human, heroUuid)
  549. if heroGrid then
  550. RoleAttr.calcHeroGrid(heroGrid, nil, human)
  551. local heroInfo = {
  552. heroUuid = heroUuid,
  553. heroStar = heroGrid.star,
  554. heroLevel = heroGrid.lv,
  555. heroPower = heroGrid.zhandouli,
  556. }
  557. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_HERO
  558. msgData.playerUuid = human.db._id
  559. msgData.targetCityId = cityId
  560. msgData.targetPointIdx = pointIdx
  561. msgData.heroData = heroInfo
  562. InnerMsg.sendMsg(0, msgData)
  563. end
  564. end
  565. -- 玩家改名
  566. function PlayerChangeName(human)
  567. if not baseCondCheck(human) then
  568. return false
  569. end
  570. if not actStartTimeCheck() then
  571. return false
  572. end
  573. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  574. msgData.playerUuid = human.db._id
  575. msgData.myUnionId = human.db.unionUuid
  576. msgData.updateData = {}
  577. msgData.updateData.name = human.db.name
  578. InnerMsg.sendMsg(0, msgData)
  579. end
  580. -- 公会改名
  581. function UnionChangeName(unionId, newName)
  582. if not actStartTimeCheck() then
  583. return false
  584. end
  585. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  586. msgData.myUnionId = unionId
  587. msgData.updateData = {}
  588. msgData.updateData.name = newName
  589. InnerMsg.sendMsg(0, msgData)
  590. end
  591. function isDot(human)
  592. if not baseCondCheck(human) then
  593. return false
  594. end
  595. if not actStartTimeCheck() then
  596. return false
  597. end
  598. return true
  599. end
  600. function onLogin(human)
  601. formationDataCheeck(human)
  602. sendDefHeroArr(human)
  603. notifyTips(human)
  604. end
  605. -- 请求状态
  606. function AB_GetState(human, isTips)
  607. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_STATE
  608. msgData.sourceServerId = Config.SVR_INDEX
  609. msgData.playerUuid = human.db._id
  610. msgData.myUnionId = human.db.unionUuid or ""
  611. msgData.isTips = isTips and 1 or 0
  612. InnerMsg.sendMsg(0, msgData)
  613. end
  614. -- 报名
  615. function AB_Join(human)
  616. local unionId = human.db.unionUuid
  617. local msgRet = Msg.gc.GC_AB_JOIN
  618. if not unionId then
  619. msgRet.Joinstate = 3
  620. return Msg.send(msgRet, human.fd)
  621. end
  622. local wDay = getWDay()
  623. -- if wDay ~= AnotherWorldBattleDefine.AB_JOIN_WDAY then
  624. -- msgRet.Joinstate = 5
  625. -- return Msg.send(msgRet, human.fd)
  626. -- end
  627. if not table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  628. msgRet.Joinstate = 5
  629. return Msg.send(msgRet, human.fd)
  630. end
  631. -- 公会排名前二才能参加
  632. if not isTopTwoUnion(human) then
  633. msgRet.Joinstate = 2
  634. return Msg.send(msgRet, human.fd)
  635. end
  636. -- 会长/副会长才能报名
  637. if not UnionLogic.IsTopTwoManager(human, unionId) then
  638. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  639. end
  640. local queryFiles = {name = 1, zhandouli = 1}
  641. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  642. if not unionInfo then
  643. return Broadcast.sendErr(human, Lang.DATA_ERR)
  644. end
  645. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_JOIN
  646. msgData.sourceServerId = Config.SVR_INDEX
  647. msgData.playerUuid = human.db._id
  648. msgData.unionInfo = {
  649. name = unionInfo.name,
  650. power = unionInfo.zhandouli,
  651. unionId = unionId
  652. }
  653. InnerMsg.sendMsg(0, msgData)
  654. end
  655. -- 查询所有城池信息
  656. function AB_AllCity_Query(human)
  657. if not human.db.unionUuid then
  658. return
  659. end
  660. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  661. msgData.sourceServerId = Config.SVR_INDEX
  662. msgData.playerUuid = human.db._id
  663. msgData.myUnionId = human.db.unionUuid
  664. InnerMsg.sendMsg(0, msgData)
  665. -- 报名状态查询
  666. -- local msgData2 = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_JOIN_STATE
  667. -- msgData2.sourceServerId = Config.SVR_INDEX
  668. -- msgData2.playerUuid = human.db._id
  669. -- msgData2.myUnionId = human.db.unionUuid
  670. -- InnerMsg.sendMsg(0, msgData2)
  671. end
  672. -- 查询单个城池的详细信息
  673. function AB_CityDetailed_Query(human, targetCityId)
  674. if not AnotherWorldBattleConfig.city[targetCityId] then
  675. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  676. end
  677. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  678. msgData.sourceServerId = Config.SVR_INDEX
  679. msgData.playerUuid = human.db._id
  680. msgData.myUnionId = human.db.unionUuid
  681. msgData.targetCityId = targetCityId
  682. InnerMsg.sendMsg(0, msgData)
  683. end
  684. -- 查询某个城池的某个据点的详细信息
  685. function AB_PointDetailed_Query(human, targetCityId, targetPointIdx)
  686. if not AnotherWorldBattleConfig.city[targetCityId] then
  687. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  688. end
  689. if 0 >= targetPointIdx or AnotherWorldBattleDefine.AB_POINT_MAX_NUM < targetPointIdx then
  690. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  691. end
  692. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINTtDETAILED_QUERY
  693. msgData.sourceServerId = Config.SVR_INDEX
  694. msgData.playerUuid = human.db._id
  695. msgData.myUnionId = human.db.unionUuid
  696. msgData.targetCityId = targetCityId
  697. msgData.targetPointIdx = targetPointIdx
  698. InnerMsg.sendMsg(0, msgData)
  699. end
  700. -- 查询本公会出生点信息
  701. function AB_BaseCity_Query(human)
  702. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_BASECITY_QUERY
  703. msgData.sourceServerId = Config.SVR_INDEX
  704. msgData.playerUuid = human.db._id
  705. msgData.myUnionId = human.db.unionUuid
  706. InnerMsg.sendMsg(0, msgData)
  707. end
  708. -- 查询玩家占领的所有据点信息
  709. function AB_PlayerOccupyPOint_Query(human)
  710. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  711. msgData.sourceServerId = Config.SVR_INDEX
  712. msgData.playerUuid = human.db._id
  713. msgData.myUnionId = human.db.unionUuid
  714. InnerMsg.sendMsg(0, msgData)
  715. end
  716. -- 查询公会排行榜
  717. function AB_UnionRank_Query(human)
  718. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  719. msgData.sourceServerId = Config.SVR_INDEX
  720. msgData.playerUuid = human.db._id
  721. msgData.myUnionId = human.db.unionUuid
  722. InnerMsg.sendMsg(0, msgData)
  723. end
  724. -- 查询玩家排行榜
  725. function AB_PlayerRank_Query(human)
  726. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  727. msgData.sourceServerId = Config.SVR_INDEX
  728. msgData.playerUuid = human.db._id
  729. msgData.myUnionId = human.db.unionUuid
  730. InnerMsg.sendMsg(0, msgData)
  731. end
  732. -- 发起集结
  733. function AB_Gather(human, targetCityId, opType)
  734. if not AnotherWorldBattleConfig.city[targetCityId] then
  735. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  736. end
  737. if opType ~= 1 and opType ~= 2 then
  738. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  739. end
  740. local unionId = human.db.unionUuid
  741. if not unionId then
  742. return Broadcast.sendErr(human, Lang.AB_NO_UNION)
  743. end
  744. -- 会长/副会长才能集结
  745. if not UnionLogic.IsTopTwoManager(human, unionId) then
  746. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANAGER)
  747. end
  748. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GATHER
  749. msgData.sourceServerId = Config.SVR_INDEX
  750. msgData.playerUuid = human.db._id
  751. msgData.myUnionId = human.db.unionUuid
  752. msgData.targetCityId = targetCityId
  753. msgData.opType = opType
  754. InnerMsg.sendMsg(0, msgData)
  755. end
  756. -- 请求挑战某个据点
  757. function AB_TryChallengePoint(human, targetCityId, targetPointIdx)
  758. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  759. if not combatHero or not next(combatHero) then
  760. return Broadcast.sendErr(human, Lang.COMBAT_NEED_FIGHT_HERO)
  761. end
  762. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  763. msgData.sourceServerId = Config.SVR_INDEX
  764. msgData.playerUuid = human.db._id
  765. msgData.myUnionId = human.db.unionUuid
  766. msgData.targetCityId = targetCityId
  767. msgData.targetPointIdx = targetPointIdx
  768. InnerMsg.sendMsg(0, msgData)
  769. end
  770. -- 战斗结束
  771. local function challenge_End(human, args)
  772. local cityId = args.cityId
  773. local pointIdx = args.pointIdx
  774. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_CHALLENGE_END
  775. msgData.sourceServerId = Config.SVR_INDEX
  776. msgData.playerUuid = human.db._id
  777. msgData.myUnionId = human.db.unionUuid
  778. msgData.targetCityId = cityId
  779. msgData.targetPointIdx = pointIdx
  780. msgData.challengeRes = args.challengeRes
  781. -- 挑战没有胜利
  782. if args.challengeRes ~= CombatDefine.RESULT_WIN then
  783. -- 说明之前已经在跨服上保存玩家的基础数据了
  784. -- if human.db.anotherWorlBattle then
  785. -- return
  786. -- end
  787. msgData.playerShowInfo = {
  788. name = human.db.name,
  789. lv = human.db.lv,
  790. power = human.db.zhandouli,
  791. }
  792. return InnerMsg.sendMsg(0, msgData)
  793. end
  794. if not human.db.anotherWorlBattle then
  795. human.db.anotherWorlBattle = {
  796. startTime = os.time(),
  797. formation = {}
  798. }
  799. end
  800. -- 把当前战斗阵容数据保存到当前模块,作为防守阵容
  801. local combatData = CombatPosLogic.getCombatHeroDB(human, CombatDefine.COMBAT_TYPE35)
  802. local formationData = human.db.anotherWorlBattle.formation or {}
  803. formationData[cityId] = formationData[cityId] or {}
  804. formationData[cityId][pointIdx] = Util.copyTable(combatData)
  805. -- 把最新的防守英雄uuid列表推送给客户端
  806. sendDefHeroArr(human)
  807. --同步到跨服
  808. msgData.playerShowInfo = generateShowInfo(human)
  809. InnerMsg.sendMsg(0, msgData)
  810. -- 清空战斗阵容
  811. CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  812. end
  813. -- 更换据点的防守阵容
  814. function AB_UpdateLineup(human, msg)
  815. if not isBattleStage() then
  816. return Broadcast.sendErr(human, Lang.AB_NOT_BATTLE_TIME)
  817. end
  818. local anotherWorlBattle = human.db.anotherWorlBattle
  819. if not anotherWorlBattle or not anotherWorlBattle.formation then
  820. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  821. end
  822. local cityId = msg.cityId
  823. local pointIdx = msg.pointIdx
  824. local formationData = anotherWorlBattle.formation
  825. if not formationData[cityId] or not formationData[cityId][pointIdx] then
  826. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  827. end
  828. local res, heroList, helpList = CombatPosLogic.CheckUpdatePos(human, msg)
  829. if not res then
  830. return Broadcast.sendErr(human, Lang.COMBAT_POS__ERR)
  831. end
  832. local len = 0
  833. local heroArr = {}
  834. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  835. local uuid = heroList[i] or ""
  836. if uuid ~= "0" and uuid ~= "" then
  837. if isDefHero(human, uuid, cityId, pointIdx) then
  838. return Broadcast.sendErr(human, Lang.AB_HERO_IN_OTHER_POINT)
  839. end
  840. len = len + 1
  841. heroArr[len] = getHeroInfo(human, uuid)
  842. end
  843. end
  844. if len == 0 then
  845. return
  846. end
  847. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_POINT_LINEIP
  848. msgData.sourceServerId = Config.SVR_INDEX
  849. msgData.playerUuid = human.db._id
  850. msgData.heroArr = heroArr
  851. msgData.targetCityId = cityId
  852. msgData.targetPointIdx = pointIdx
  853. msgData.formation = msg.formation
  854. msgData.heroList = heroList
  855. msgData.helpList = helpList
  856. InnerMsg.sendMsg(0, msgData)
  857. end
  858. -- 放弃据点
  859. function AB_LeavePoint(human, msg)
  860. local targetCityId = msg.cityId
  861. if not AnotherWorldBattleConfig.city[targetCityId] then
  862. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  863. end
  864. local targetPointIdx = msg.pointIdx
  865. if targetPointIdx <= 0 or targetPointIdx > AnotherWorldBattleDefine.AB_POINT_MAX_NUM then
  866. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  867. end
  868. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_LEAVE_POINT
  869. msgData.sourceServerId = Config.SVR_INDEX
  870. msgData.playerUuid = human.db._id
  871. msgData.myUnionId = human.db.unionUuid
  872. msgData.targetCityId = targetCityId
  873. msgData.targetPointIdx = targetPointIdx
  874. InnerMsg.sendMsg(0, msgData)
  875. end
  876. --获取据点的防守阵容数据
  877. function AB_GetPointLineup(human, msg)
  878. local targetCityId = msg.cityId
  879. local targetPointIdx = msg.pointIdx
  880. local anotherWorlBattle = human.db.anotherWorlBattle
  881. local formationData = anotherWorlBattle.formation
  882. if not formationData[targetCityId] or not formationData[targetCityId][targetPointIdx] then
  883. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  884. end
  885. local extraArgs = {
  886. cityId = targetCityId,
  887. pointIdx = targetPointIdx
  888. }
  889. CombatPosLogic.posQuery(human, msg.type, msg.groupID, msg.param, 1, extraArgs)
  890. end
  891. -- 请求公会士气信息
  892. function AB_GetMyUnionMoraleInfo(human)
  893. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_MYUIONMORALE
  894. msgData.sourceServerId = Config.SVR_INDEX
  895. msgData.playerUuid = human.db._id
  896. msgData.myUnionId = human.db.unionUuid
  897. InnerMsg.sendMsg(0, msgData)
  898. end
  899. -- 给本公会加士气
  900. function AB_Morale_Do(human)
  901. local unionId = human.db.unionUuid
  902. if not UnionLogic.IsTopTwoManager(human, unionId) then
  903. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  904. end
  905. -- 先扣除道具
  906. local moraleCostCfg = AnotherWorldBattleConfig.var[1].moraleCost
  907. if not moraleCostCfg then
  908. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  909. end
  910. local itemId, itemNum = moraleCostCfg[1], moraleCostCfg[2]
  911. if BagLogic.getItemCnt(human, itemId) < itemNum then
  912. return Broadcast.sendErr(human, COMMON_ITEM_NOT_ENOUGH)
  913. end
  914. BagLogic.delItem(human, itemId, itemNum, LOGTAG)
  915. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UIONMORALE_DO
  916. msgData.sourceServerId = Config.SVR_INDEX
  917. msgData.playerUuid = human.db._id
  918. msgData.myUnionId = human.db.unionUuid
  919. InnerMsg.sendMsg(0, msgData)
  920. end
  921. -- 查询据点羁绊数据
  922. function AB_PointLine_JiBan_Query(human, msg)
  923. if not isBattleStage() then
  924. return
  925. end
  926. JibanLogic = JibanLogic or require("combat.JibanLogic")
  927. local extraArgs = {
  928. cityId = msg.cityId,
  929. pointIdx = msg.pointIdx,
  930. }
  931. JibanLogic.query(human, msg.combatType, msg.heroID, extraArgs)
  932. end
  933. -- 更新据点羁绊
  934. function AB_PointLine_JiBan_Update(human, msg)
  935. if not isBattleStage() then
  936. return
  937. end
  938. JibanLogic = JibanLogic or require("combat.JibanLogic")
  939. local extraArgs = {
  940. cityId = msg.cityId,
  941. pointIdx = msg.pointIdx,
  942. }
  943. JibanLogic.update(human, msg.combatType, msg.jibanList, msg.heroIdArr, extraArgs)
  944. end
  945. -- 查询据点精灵数据
  946. function AB_PointLine_Elf_Query(human, msg)
  947. if not isBattleStage() then
  948. return
  949. end
  950. local extraArgs = {
  951. cityId = msg.cityId,
  952. pointIdx = msg.pointIdx,
  953. }
  954. CombatPosLogic.Elf_Pos_Query(human, msg.combatType, extraArgs)
  955. end
  956. -- 更新据点精灵
  957. function AB_PointLine_Elf_Update(human, msg)
  958. if not isBattleStage() then
  959. return
  960. end
  961. local extraArgs = {
  962. cityId = msg.cityId,
  963. pointIdx = msg.pointIdx,
  964. }
  965. CombatPosLogic.Elf_Pos_Update(human, msg.combatType, msg.elfPosArr, extraArgs)
  966. end
  967. ------------------------------------C2N---------------------------------------------------
  968. -- 跨服通知活动开启
  969. function C2N_Act_Start(msg)
  970. local startTime = msg.startTime
  971. if not startTime or startTime == 0 then
  972. return
  973. end
  974. CommonDB.updateValue(CommonDB.KEY_ANOTHERWORLDBATTLE_START_TI, startTime)
  975. end
  976. -- 错误提示
  977. function C2N_ErrTips(msg)
  978. local human = ObjHuman.onlineUuid[msg.playerUuid]
  979. if not human then
  980. return
  981. end
  982. local tips = Lang.DATA_ERR
  983. local errCode = msg.errCode
  984. if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
  985. tips = Lang.AB_NOT_OPEN_TIME
  986. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
  987. tips = Lang.AB_NOT_UNION_NUM_EXCEED
  988. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
  989. tips = Lang.AB_UNION_NO_JOIN
  990. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
  991. tips = Lang.DATA_ERR
  992. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
  993. tips = Lang.AB_NOT_OCCUPY_POINT
  994. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
  995. tips = Lang.AB_GATHER_CD
  996. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
  997. tips = Lang.AB_CITY_NOT_ADDJION
  998. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
  999. tips = Lang.AB_JOINED
  1000. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_9 then
  1001. tips = Lang.AB_CITY_NO_GATHER
  1002. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_10 then
  1003. tips = Lang.AB_OCCUPY_POINT_MAX
  1004. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_11 then
  1005. tips = Lang.AB_POINT_CHALLENGING
  1006. end
  1007. Broadcast.sendErr(human, tips)
  1008. end
  1009. -- 跨服返回状态
  1010. function C2N_State_Response(msg)
  1011. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1012. if not human then
  1013. return
  1014. end
  1015. -- 只用于弹出提示框
  1016. if msg.isTips and msg.isTips == 1 then
  1017. if (msg.systemState > 0 and msg.systemState <= 2) and msg.joinState <= 1 then
  1018. local msgRet = Msg.gc.GC_AB_TIPS
  1019. Msg.send(msgRet, human.fd)
  1020. end
  1021. return
  1022. end
  1023. local msgRet = Msg.gc.GC_AB_GetState
  1024. msgRet.joinState = msg.joinState
  1025. msgRet.systemState = msg.systemState
  1026. if msgRet.joinState == 0 then
  1027. local unionId = human.db.unionUuid
  1028. if not unionId then
  1029. msgRet.Joinstate = 2
  1030. return Msg.send(msgRet, human.fd)
  1031. end
  1032. -- 公会排名前二才行
  1033. if not isTopTwoUnion(human) then
  1034. msgRet.Joinstate = 2
  1035. return Msg.send(msgRet, human.fd)
  1036. end
  1037. end
  1038. Msg.send(msgRet, human.fd)
  1039. end
  1040. -- 报名成功
  1041. function C2N_Join_Response(msg)
  1042. local now = os.time()
  1043. local unionId = msg.myUnionId
  1044. UnionLogic.UpdateJoinAbTime(unionId, now)
  1045. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1046. if not human then
  1047. return
  1048. end
  1049. local msgRet = Msg.gc.GC_AB_JOIN
  1050. msgRet.Joinstate = 1
  1051. Msg.send(msgRet, human.fd)
  1052. end
  1053. -- 跨服返回的所有城池数据
  1054. function C2N_AllCity_Response(msg)
  1055. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1056. if not human then
  1057. return
  1058. end
  1059. local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
  1060. msgRet.myBaseCityId = msg.myUnionBaseCityId
  1061. msgRet.hasPointNum = msg.hasPointNum
  1062. msgRet.challengeTimes = msg.challengeTimes
  1063. local now = os.time()
  1064. msgRet.leftTime = msg.lastTime
  1065. if msgRet.leftTime ~= 0 then
  1066. msgRet.leftTime = (msg.lastTime + AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC) - now
  1067. end
  1068. msgRet.cityArr[0] = 0
  1069. local cityArrMsg = msgRet.cityArr
  1070. for cityId, cityInfo in ipairs(msg.cityArr) do
  1071. cityArrMsg[0] = cityId
  1072. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1073. cityArrMsg[cityId].cityId = cityId
  1074. cityArrMsg[cityId].cityName = cityCfg.cityName
  1075. cityArrMsg[cityId].cityLv = cityCfg.cityLv
  1076. cityArrMsg[cityId].occupyPointNum = cityInfo.occupyPointNum or 0
  1077. cityArrMsg[cityId].occupyUnionName = cityInfo.occupyUnionName or ""
  1078. cityArrMsg[cityId].cityState = cityInfo.cityState
  1079. cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
  1080. for i, cId in ipairs(cityCfg.adJoinCityArr) do
  1081. cityArrMsg[cityId].adJoinCityArr[i] = cId
  1082. end
  1083. end
  1084. msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
  1085. for i, cityId in ipairs(msg.myOccupyCityArr) do
  1086. msgRet.myOccupyCityArr[i] = cityId
  1087. end
  1088. -- 据点每分钟的奖励
  1089. local itemId, itemNum = 0, 0
  1090. local cityCfg = AnotherWorldBattleConfig.city[1]
  1091. itemId = cityCfg.cityAward[1]
  1092. for _, pointInfo in ipairs(msg.occupyPointData) do
  1093. local cityId = pointInfo[1]
  1094. local occupyTimeArr = pointInfo[2]
  1095. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1096. local minuteVal = 0
  1097. for _, timeTb in ipairs(occupyTimeArr) do
  1098. local sec = (timeTb[2] or now) - (timeTb[1] or now)
  1099. if sec > 0 then
  1100. minuteVal = minuteVal + sec
  1101. end
  1102. minuteVal = math.floor(minuteVal / 60)
  1103. end
  1104. itemNum = itemNum + minuteVal * cityCfg.cityAward[2]
  1105. end
  1106. Grid.makeItem(msgRet.myUnionAward, itemId, itemNum)
  1107. Msg.send(msgRet, human.fd)
  1108. end
  1109. -- 跨服返回某个城池详细数据
  1110. function C2N_CityDetailed_Response(msg)
  1111. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1112. if not human then
  1113. return
  1114. end
  1115. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  1116. local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
  1117. msgRet.cityId = msg.targetCityId
  1118. msgRet.cityLv = cityCfg.cityLv
  1119. msgRet.cityIconId = cityCfg.cityIconId
  1120. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM )
  1121. local myUnionAwardNum = calcPointAward(msg.myUnionOccupyArr)
  1122. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  1123. -- 活动没有进入战斗阶段时, 使用默认数据
  1124. if #msg.pointArr == 0 then
  1125. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  1126. msg.pointArr[i] = {}
  1127. end
  1128. end
  1129. msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  1130. for pointIdx, pointInfo in ipairs(msg.pointArr) do
  1131. if pointInfo.occupyUnionName then
  1132. msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
  1133. msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
  1134. msgRet.pointArr[pointIdx].power = pointInfo.power
  1135. msgRet.pointArr[pointIdx].state = pointInfo.state
  1136. else
  1137. msgRet.pointArr[pointIdx].occupyUnionName = ""
  1138. msgRet.pointArr[pointIdx].occupyPlayerName = AnotherWorldBattleDefine.AB_DEF_NAME_STR.. pointIdx
  1139. msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
  1140. msgRet.pointArr[pointIdx].state = pointInfo.state
  1141. end
  1142. end
  1143. msgRet.gatherState = msg.gatherState
  1144. if msg.gatherState == 1 then
  1145. -- 公会会长/副会长才能集结
  1146. if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
  1147. msgRet.gatherState = 0
  1148. end
  1149. end
  1150. msgRet.gatherLeftTime = msg.gatherTime
  1151. if msg.gatherTime ~= -1 then
  1152. local now = os.time()
  1153. local subSec = msg.gatherTime + AnotherWorldBattleDefine.AB_GATHER_CD_SEC - now
  1154. msgRet.gatherLeftTime = subSec > 0 and subSec or 0
  1155. end
  1156. Msg.send(msgRet, human.fd)
  1157. end
  1158. -- 跨服返回某个据点数据
  1159. function C2N_PointDetailed_Response(msg)
  1160. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1161. if not human then
  1162. return
  1163. end
  1164. local pointInfo = msg.pointInfo
  1165. local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
  1166. msgRet.state = pointInfo.state
  1167. if pointInfo.name then
  1168. msgRet.name = pointInfo.name
  1169. msgRet.power = pointInfo.power
  1170. msgRet.head = pointInfo.head
  1171. msgRet.headFrame = pointInfo.headFrame
  1172. msgRet.defLv = pointInfo.defLv
  1173. msgRet.heroArr[0] = #pointInfo.heroArr
  1174. for i, heroInfo in ipairs(pointInfo.heroArr) do
  1175. msgRet.heroArr[i].heroBody = heroInfo.heroBody
  1176. msgRet.heroArr[i].heroStar = heroInfo.heroStar
  1177. msgRet.heroArr[i].heroLv = heroInfo.heroLv
  1178. msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
  1179. msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
  1180. msgRet.heroArr[i].heroId = heroInfo.heroId
  1181. msgRet.heroArr[i].heroQuality = heroInfo.heroQuality
  1182. end
  1183. else
  1184. msgRet.name = AnotherWorldBattleDefine.AB_DEF_NAME_STR .. msg.targetPointIdx
  1185. msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
  1186. msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
  1187. msgRet.defLv = 200
  1188. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  1189. msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
  1190. msgRet.heroArr[0] = 0
  1191. local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
  1192. for idx, monsterInfo in ipairs(monsterOutConfig.member) do
  1193. if idx > 6 then
  1194. break
  1195. end
  1196. msgRet.heroArr[0] = idx
  1197. local monsterID = monsterInfo[1]
  1198. local mcf = MonsterExcel.monster[monsterID]
  1199. msgRet.heroArr[idx].heroBody = mcf.body
  1200. msgRet.heroArr[idx].heroStar = mcf.star
  1201. msgRet.heroArr[idx].heroLv = monsterInfo[2]
  1202. msgRet.heroArr[idx].heroCamp = mcf.camp
  1203. msgRet.heroArr[idx].heroIcon = mcf.head
  1204. msgRet.heroArr[idx].heroId = monsterID
  1205. msgRet.heroArr[idx].heroQuality = mcf.heroQuality or 1
  1206. end
  1207. end
  1208. Msg.send(msgRet, human.fd)
  1209. end
  1210. -- 跨服返回公会出生点数据
  1211. function C2N_BaseCity_Response(msg)
  1212. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1213. if not human then
  1214. return
  1215. end
  1216. local baseCityInfo = msg.baseCityInfo
  1217. local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
  1218. local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
  1219. msgRet.cityIconId = cityCfg.cityIconId
  1220. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM)
  1221. local myUnionAwardNum = calcPointAward(baseCityInfo.myUnionOccupyArr)
  1222. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  1223. msgRet.cityIconId = baseCityInfo.occupyPointNum
  1224. msgRet.occupyPointNum = baseCityInfo.occupyPointNum
  1225. msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
  1226. msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
  1227. msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
  1228. msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
  1229. Msg.send(msgRet, human.fd)
  1230. end
  1231. -- 跨服返回玩家占领的据点数据
  1232. function C2N_PlayerOccupyPoint_Response(msg)
  1233. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1234. if not human then
  1235. return
  1236. end
  1237. local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
  1238. local myPointArr = msgRet.myPointArr
  1239. myPointArr[0] = 0
  1240. for idx, pointInfo in ipairs(msg.occupyPointArr) do
  1241. myPointArr[0] = idx
  1242. local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
  1243. myPointArr[idx].cityIconId = cityCfg.cityIconId
  1244. myPointArr[idx].cityName = cityCfg.cityName
  1245. myPointArr[idx].cityLv = cityCfg.cityLv
  1246. myPointArr[idx].pointIdx = pointInfo.pointIdx
  1247. myPointArr[idx].power = pointInfo.power
  1248. myPointArr[idx].cityId = pointInfo.cityId
  1249. myPointArr[idx].heroArr[0] = #pointInfo.heroArr
  1250. for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
  1251. local hero = myPointArr[idx].heroArr[heroIdx]
  1252. hero.heroBody = heroInfo.heroBody
  1253. hero.heroStar = heroInfo.heroStar
  1254. hero.heroLv = heroInfo.heroLv
  1255. hero.heroCamp = heroInfo.heroCamp
  1256. hero.heroIcon = heroInfo.heroIcon
  1257. hero.heroId = heroInfo.heroId
  1258. hero.heroQuality = heroInfo.heroQuality
  1259. end
  1260. end
  1261. Msg.send(msgRet, human.fd)
  1262. end
  1263. -- 跨服返回集结/取消集结成功
  1264. function C2N_Gather_Response(msg)
  1265. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1266. if not human then
  1267. return
  1268. end
  1269. local targetCityId = msg.targetCityId
  1270. local cityCfg = AnotherWorldBattleConfig.city[targetCityId]
  1271. local msgRet = Msg.gc.GC_AB_GARHER
  1272. msgRet.cityId = targetCityId
  1273. msgRet.cityName = cityCfg.cityName
  1274. msgRet.opType = msg.opType
  1275. Msg.send(msgRet, human.fd)
  1276. end
  1277. --跨服返回公会排行榜数据
  1278. function C2N_UnionRank_Response(msg)
  1279. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1280. if not human then
  1281. return
  1282. end
  1283. -- local itemId, itemNum = 184, 0
  1284. local rankReward = AnotherWorldBattleConfig.rankReward
  1285. local itemArr = getRankGenericAwadId(rankReward, 1)
  1286. local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
  1287. msgRet.unionRankArr[0] = 0
  1288. msgRet.myUnionRank = msg.myUnionRank
  1289. msgRet.myData.name = ""
  1290. msgRet.myData.power = 0
  1291. msgRet.myData.cityNum = 0
  1292. msgRet.myData.pointNum = 0
  1293. msgRet.myData.rankAward[0] = 0
  1294. for i, itemInfo in ipairs(itemArr or {}) do
  1295. msgRet.myData.rankAward[0] = i
  1296. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1297. end
  1298. for rank, rankdData in ipairs(msg.unionRankArr) do
  1299. msgRet.unionRankArr[0] = rank
  1300. msgRet.unionRankArr[rank].name = rankdData.name
  1301. msgRet.unionRankArr[rank].power = rankdData.power
  1302. msgRet.unionRankArr[rank].cityNum = rankdData.cityNum
  1303. msgRet.unionRankArr[rank].pointNum = rankdData.pointNum
  1304. -- Grid.makeItem(msgRet.unionRankArr[rank].rankAward, itemId, itemNum)
  1305. msgRet.unionRankArr[rank].rankAward[0] = 0
  1306. itemArr = getRankAward(rankReward, 1, rank)
  1307. for i, itemInfo in ipairs(itemArr or {}) do
  1308. msgRet.unionRankArr[rank].rankAward[0] = i
  1309. Grid.makeItem(msgRet.unionRankArr[rank].rankAward[i], itemInfo[1], itemInfo[2])
  1310. end
  1311. if rank == msg.myUnionRank then
  1312. msgRet.myData.name = rankdData.name
  1313. msgRet.myData.power = rankdData.power
  1314. msgRet.myData.cityNum = rankdData.cityNum
  1315. msgRet.myData.pointNum = rankdData.pointNum
  1316. -- Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1317. msgRet.myData.rankAward[0] = 0
  1318. for i, itemInfo in ipairs(itemArr or {}) do
  1319. msgRet.myData.rankAward[0] = i
  1320. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1321. end
  1322. end
  1323. end
  1324. if msgRet.myData.power == 0 then
  1325. local unionId = human.db.unionUuid
  1326. local queryFiles = {name = 1, zhandouli = 1}
  1327. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  1328. msgRet.myData.name = unionInfo and unionInfo.name or ""
  1329. msgRet.myData.power = unionInfo and unionInfo.zhandouli or 0
  1330. end
  1331. Msg.send(msgRet, human.fd)
  1332. end
  1333. --跨服返回玩家排行榜数据
  1334. function C2N_PlayerRank_Response(msg)
  1335. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1336. if not human then
  1337. return
  1338. end
  1339. -- local itemId, itemNum = 184, 0
  1340. local rankReward = AnotherWorldBattleConfig.rankReward
  1341. local itemArr = getRankGenericAwadId(rankReward, 2)
  1342. local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
  1343. msgRet.playerRankArr[0] = 0
  1344. msgRet.myRank = msg.myRank
  1345. msgRet.myData.name = human.db.name
  1346. msgRet.myData.power = human.db.zhandouli
  1347. msgRet.myData.pointNum = 0
  1348. msgRet.myData.pointWeight = 0
  1349. msgRet.myData.rankAward[0] = 0
  1350. for i, itemInfo in ipairs(itemArr or {}) do
  1351. msgRet.myData.rankAward[0] = i
  1352. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1353. end
  1354. for rank, rankdData in ipairs(msg.playerRankArr) do
  1355. msgRet.playerRankArr[0] = rank
  1356. msgRet.playerRankArr[rank].name = rankdData.name
  1357. msgRet.playerRankArr[rank].power = rankdData.power
  1358. msgRet.playerRankArr[rank].pointNum = rankdData.pointNum
  1359. msgRet.playerRankArr[rank].pointWeight = rankdData.pointWeight
  1360. -- itemId, itemNum = getRankAward(rankReward, 2, rank)
  1361. -- Grid.makeItem(msgRet.playerRankArr[rank].rankAward, itemId, itemNum)
  1362. itemArr = getRankAward(rankReward, 2, rank)
  1363. msgRet.playerRankArr[rank].rankAward[0] = 0
  1364. for i, itemInfo in ipairs(itemArr or {}) do
  1365. msgRet.playerRankArr[rank].rankAward[0] = i
  1366. Grid.makeItem(msgRet.playerRankArr[rank].rankAward[i], itemInfo[1], itemInfo[2])
  1367. end
  1368. if rank == msg.myRank then
  1369. msgRet.myData.pointNum = rankdData.pointNum
  1370. msgRet.myData.pointWeight = rankdData.pointWeight
  1371. -- Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1372. msgRet.myData.rankAward[0] = 0
  1373. for i, itemInfo in ipairs(itemArr or {}) do
  1374. msgRet.myData.rankAward[0] = i
  1375. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1376. end
  1377. end
  1378. end
  1379. Msg.send(msgRet, human.fd)
  1380. end
  1381. -- 跨服返回要挑战的据点的数据(据点可以被挑战)
  1382. function C2N_TryChallengePoint_Response(msg)
  1383. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1384. if not human then
  1385. return
  1386. end
  1387. local pointInfo = msg.pointInfo
  1388. human.AB_Battle_Cache = {
  1389. isGather = pointInfo.isGather,
  1390. cityId = pointInfo.targetCityId,
  1391. pointIdx = pointInfo.targetPointIdx,
  1392. defMoraleAttrIdx = pointInfo.defMoraleAttrIdx,
  1393. atkMoraleAttrIdx = pointInfo.atkMoraleAttrIdx,
  1394. }
  1395. if pointInfo.occupySrvId then -- 玩家占领
  1396. local args = {
  1397. combatType = CombatDefine.COMBAT_TYPE35,
  1398. nServerIndex = pointInfo.occupySrvId,
  1399. param = pointInfo.occupyPlayerUuid,
  1400. extraArgs = {
  1401. cityId = pointInfo.targetCityId,
  1402. pointIdx = pointInfo.targetPointIdx,
  1403. useDef = true,
  1404. }
  1405. }
  1406. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
  1407. else
  1408. -- 机器人
  1409. CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
  1410. end
  1411. end
  1412. -- 跨服通知据点被别的玩家占领了
  1413. function C2N_PointLose_Response(msg)
  1414. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1415. if not human then
  1416. local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
  1417. if not db then
  1418. return
  1419. end
  1420. human = {}
  1421. human.db = db
  1422. end
  1423. -- 更新防守阵容数据
  1424. local loseCityId = msg.loseCityId
  1425. local losePointIdx = msg.losePointIdx
  1426. local formationData = human.db.anotherWorlBattle.formation
  1427. formationData[loseCityId][losePointIdx] = nil
  1428. -- 玩家不在线, 手动保存数据
  1429. if not human.fd then
  1430. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1431. end
  1432. local cityCfg = AnotherWorldBattleConfig.city[loseCityId]
  1433. -- 发邮件
  1434. local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
  1435. local content = Util.format(mailCfg.content, cityCfg and cityCfg.cityName or "", loseCityId)
  1436. MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, content, nil, mailCfg.senderName or "GM")
  1437. -- 把最新的防守阵容数据推给客户端
  1438. if human.fd then
  1439. sendDefHeroArr(human)
  1440. end
  1441. end
  1442. -- 跨服通知可以更换据点的防守阵容数据
  1443. function C2N_UpdatePointLineup_Response(msg)
  1444. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1445. if not human then
  1446. local db = RoleDBLogic.getDb(msg.playerUuid)
  1447. if not db then
  1448. return
  1449. end
  1450. human = {}
  1451. human.db = db
  1452. end
  1453. local anotherWorlBattle = human.db.anotherWorlBattle
  1454. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1455. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  1456. end
  1457. local cityId = msg.targetCityId
  1458. local pointIdx = msg.targetPointIdx
  1459. if not anotherWorlBattle.formation[cityId] or not anotherWorlBattle.formation[cityId][pointIdx] then
  1460. return
  1461. end
  1462. local pointLinupData = anotherWorlBattle.formation[cityId][pointIdx]
  1463. pointLinupData.list = msg.heroList
  1464. pointLinupData.helpList = msg.helpList
  1465. pointLinupData.formation = msg.formation
  1466. if not human.fd then
  1467. ObjHuman.save(human)
  1468. end
  1469. sendDefHeroArr(human)
  1470. Broadcast.sendCenter(human, Lang.AB_UPDATE_LINEUP_SUCC)
  1471. end
  1472. -- 跨服通知放弃据点成功
  1473. function C2N_LeavePoint_Response(msg)
  1474. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1475. if not human then
  1476. local db = RoleDBLogic.getDb(msg.playerUuid)
  1477. if not db then
  1478. return
  1479. end
  1480. human = {}
  1481. human.db = db
  1482. end
  1483. local anotherWorlBattle = human.db.anotherWorlBattle
  1484. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1485. return
  1486. end
  1487. local cityId = msg.targetCityId
  1488. local pointIdx = msg.targetPointIdx
  1489. anotherWorlBattle.formation[cityId][pointIdx] = nil
  1490. if not next(anotherWorlBattle.formation[cityId]) then
  1491. anotherWorlBattle.formation[cityId] = nil
  1492. end
  1493. -- 玩家不在线, 手动保存数据
  1494. if not human.fd then
  1495. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1496. else
  1497. -- 把最新的防守阵容数据推给客户端
  1498. sendDefHeroArr(human)
  1499. end
  1500. end
  1501. -- 跨服返回本公会士气信息
  1502. function C2N_MyUnionMoraleInfo_Response(msg)
  1503. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1504. if not human then
  1505. return
  1506. end
  1507. local varCfg = AnotherWorldBattleConfig.var[1]
  1508. local msgRet = Msg.gc.GC_AB_GET_MORALE_INFO
  1509. msgRet.moraleState = msg.moraleState
  1510. msgRet.leftTime = 0
  1511. local now = os.time()
  1512. local leftTime = msg.moraleStartTime + AnotherWorldBattleDefine.AB_MORALE_DURATION - now
  1513. if leftTime > 0 then
  1514. msgRet.leftTime = leftTime
  1515. end
  1516. local itemCfg = varCfg.moraleCost
  1517. local itemId = itemCfg and itemCfg[1] or 101
  1518. local itemNum = itemCfg and itemCfg[2] or 0
  1519. Grid.makeItem(msgRet.moraleCost, itemId, itemNum)
  1520. msgRet.moraleAttrs[0] = 0
  1521. local moraleAttrCfg = varCfg.moraleAtrrs
  1522. if moraleAttrCfg then
  1523. local attrArr = moraleAttrCfg[msg.moraleAttrIdx] or moraleAttrCfg[1]
  1524. for i, attrTb in ipairs(attrArr) do
  1525. msgRet.moraleAttrs[0] = i
  1526. msgRet.moraleAttrs[i].key = attrTb[1]
  1527. msgRet.moraleAttrs[i].value = attrTb[2]
  1528. end
  1529. end
  1530. Msg.send(msgRet, human.fd)
  1531. end
  1532. -- 跨服返回加士气结果
  1533. function C2N_UnionMorale_Response(msg)
  1534. if msg.opRes == 0 then
  1535. return
  1536. end
  1537. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1538. if not human then
  1539. local db = RoleDBLogic.getDb(msg.playerUuid)
  1540. if not db then
  1541. return
  1542. end
  1543. human = {}
  1544. human.db = db
  1545. end
  1546. local moraleCostCfg = AnotherWorldBattleConfig.var[1].moraleCost
  1547. local itemId, itemNum = moraleCostCfg[1], moraleCostCfg[2]
  1548. BagLogic.addItem(human, itemId, itemNum, LOGTAG)
  1549. if not human.fd then
  1550. ObjHuman.save(human)
  1551. end
  1552. end
  1553. -- 跨服通知给玩家发奖
  1554. function C2N_IssueReward(msg)
  1555. -- 删除公会参加异界之战活动时间
  1556. UnionLogic.UpdateJoinAbTime(msg.unionOccupyInfo.unionId, nil)
  1557. resetDefData(msg.unionOccupyInfo.playerInfoArr)
  1558. -- 发奖
  1559. local awardObjArr, occupyCityInfo = genAwardObjArr(msg.unionOccupyInfo)
  1560. if awardObjArr then
  1561. local issueRewardQueue = createRewardQueue()
  1562. issueRewardQueue.extraInfo = occupyCityInfo
  1563. for _, obj in ipairs(awardObjArr) do
  1564. issueRewardQueue:add(obj)
  1565. end
  1566. issueRewardQueue:insertDB()
  1567. end
  1568. end
  1569. -------------------------------------------战斗---------------------------------
  1570. function getCombatMonsterOutID(human, side, args)
  1571. if side ~= CombatDefine.DEFEND_SIDE then return end
  1572. local cityId = args[2]
  1573. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1574. return cityCfg and cityCfg.pointMonsterId
  1575. end
  1576. function getCombatObjList(human, side, args, combatType, extraArgs)
  1577. if side == CombatDefine.ATTACK_SIDE and not human then return end
  1578. if side == CombatDefine.DEFEND_SIDE and human then
  1579. return
  1580. end
  1581. if not human then
  1582. local uuid = args[1]
  1583. local db = RoleDBLogic.getDb(uuid)
  1584. if not db then
  1585. return
  1586. end
  1587. human = {}
  1588. human.db = db
  1589. end
  1590. return CombatLogic.getHumanObjList(human, combatType, extraArgs)
  1591. end
  1592. function getCombatHeros(human, combatType, args)
  1593. if not human.db.anotherWorlBattle then
  1594. return
  1595. end
  1596. if not args then
  1597. return
  1598. end
  1599. local formation = human.db.anotherWorlBattle.formation
  1600. if not formation then
  1601. return
  1602. end
  1603. local cityId, pointIdx = args.cityId, args.pointIdx
  1604. if formation[cityId] and formation[cityId][pointIdx] then
  1605. local combatHeroDB = formation[cityId][pointIdx]
  1606. return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
  1607. end
  1608. end
  1609. function onFightBegin(human, cbParam, combatType, param)
  1610. 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
  1611. return
  1612. end
  1613. local function addAttr(obj, attrs)
  1614. for _, atrrTb in ipairs(attrs or {}) do
  1615. local attrId, attrVal = atrrTb[1], atrrTb[2]
  1616. obj.sysAttr[attrId] = (obj.sysAttr[attrId] or 0) + attrVal
  1617. end
  1618. end
  1619. local atkGatherAttrs, atkMoraleAttrs, defMoraleAttrs
  1620. local varCfg = AnotherWorldBattleConfig.var[1]
  1621. if human.AB_Battle_Cache.isGather then
  1622. atkGatherAttrs = varCfg.gatherAttrs
  1623. end
  1624. if human.AB_Battle_Cache.atkMoraleAttrIdx then
  1625. local idx = human.AB_Battle_Cache.atkMoraleAttrIdx
  1626. atkMoraleAttrs = varCfg.moraleAtrrs and varCfg.moraleAtrrs[idx]
  1627. end
  1628. if human.AB_Battle_Cache.defMoraleAttrIdx then
  1629. local idx = human.AB_Battle_Cache.defMoraleAttrIdx
  1630. defMoraleAttrs = varCfg.moraleAtrrs and varCfg.moraleAtrrs[idx]
  1631. end
  1632. for index = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  1633. local side = index > CombatDefine.COMBAT_HERO_CNT and CombatDefine.DEFEND_SIDE or CombatDefine.ATTACK_SIDE
  1634. local realPos = CombatLogic.getPos(side, index)
  1635. local obj = CombatImpl.objList[realPos]
  1636. if obj then
  1637. if side == CombatDefine.ATTACK_SIDE then
  1638. if atkGatherAttrs or atkMoraleAttrs then
  1639. addAttr(obj, atkGatherAttrs)
  1640. addAttr(obj, atkMoraleAttrs)
  1641. obj.isSysAttrChange = true
  1642. end
  1643. else
  1644. if defMoraleAttrs then
  1645. addAttr(obj, defMoraleAttrs)
  1646. obj.isSysAttrChange = true
  1647. end
  1648. end
  1649. end
  1650. end
  1651. end
  1652. function onFightEnd(human, result, type, cbParam, combatInfo)
  1653. -- if result == CombatDefine.RESULT_WIN then
  1654. -- challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
  1655. -- end
  1656. local args = {
  1657. cityId = human.AB_Battle_Cache.cityId,
  1658. pointIdx = human.AB_Battle_Cache.pointIdx,
  1659. challengeRes = result
  1660. }
  1661. human.AB_Battle_Cache = nil
  1662. challenge_End(human, args)
  1663. end