AnotherWorldBattleNS.lua 60 KB

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