AnotherWorldBattleNS.lua 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  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. ------------------------------------C2N---------------------------------------------------
  912. -- 跨服通知活动开启
  913. function C2N_Act_Start(msg)
  914. local startTime = msg.startTime
  915. if not startTime or startTime == 0 then
  916. return
  917. end
  918. CommonDB.updateValue(CommonDB.KEY_ANOTHERWORLDBATTLE_START_TI, startTime)
  919. end
  920. -- 错误提示
  921. function C2N_ErrTips(msg)
  922. local human = ObjHuman.onlineUuid[msg.playerUuid]
  923. if not human then
  924. return
  925. end
  926. local tips = Lang.DATA_ERR
  927. local errCode = msg.errCode
  928. if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
  929. tips = Lang.AB_NOT_OPEN_TIME
  930. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
  931. tips = Lang.AB_NOT_UNION_NUM_EXCEED
  932. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
  933. tips = Lang.AB_UNION_NO_JOIN
  934. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
  935. tips = Lang.DATA_ERR
  936. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
  937. tips = Lang.AB_NOT_OCCUPY_POINT
  938. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
  939. tips = Lang.AB_GATHER_CD
  940. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
  941. tips = Lang.AB_CITY_NOT_ADDJION
  942. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
  943. tips = Lang.AB_JOINED
  944. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_9 then
  945. tips = Lang.AB_CITY_NO_GATHER
  946. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_10 then
  947. tips = Lang.AB_OCCUPY_POINT_MAX
  948. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_11 then
  949. tips = Lang.AB_POINT_CHALLENGING
  950. end
  951. Broadcast.sendErr(human, tips)
  952. end
  953. -- 跨服返回状态
  954. function C2N_State_Response(msg)
  955. local human = ObjHuman.onlineUuid[msg.playerUuid]
  956. if not human then
  957. return
  958. end
  959. local msgRet = Msg.gc.GC_AB_GetState
  960. msgRet.joinState = msg.joinState
  961. msgRet.systemState = msg.systemState
  962. if msgRet.joinState == 0 then
  963. local unionId = human.db.unionUuid
  964. if not unionId then
  965. msgRet.Joinstate = 2
  966. return Msg.send(msgRet, human.fd)
  967. end
  968. -- 公会排名前二才行
  969. if not isTopTwoUnion(human) then
  970. msgRet.Joinstate = 2
  971. return Msg.send(msgRet, human.fd)
  972. end
  973. end
  974. Msg.send(msgRet, human.fd)
  975. end
  976. -- 报名成功
  977. function C2N_Join_Response(msg)
  978. local now = os.time()
  979. local unionId = msg.myUnionId
  980. UnionLogic.UpdateJoinAbTime(unionId, now)
  981. local human = ObjHuman.onlineUuid[msg.playerUuid]
  982. if not human then
  983. return
  984. end
  985. local msgRet = Msg.gc.GC_AB_JOIN
  986. msgRet.Joinstate = 1
  987. Msg.send(msgRet, human.fd)
  988. end
  989. -- 跨服返回的所有城池数据
  990. function C2N_AllCity_Response(msg)
  991. local human = ObjHuman.onlineUuid[msg.playerUuid]
  992. if not human then
  993. return
  994. end
  995. local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
  996. msgRet.myBaseCityId = msg.myUnionBaseCityId
  997. msgRet.hasPointNum = msg.hasPointNum
  998. msgRet.challengeTimes = msg.challengeTimes
  999. local now = os.time()
  1000. msgRet.leftTime = msg.lastTime
  1001. if msgRet.leftTime ~= 0 then
  1002. msgRet.leftTime = (msg.lastTime + AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC) - now
  1003. end
  1004. msgRet.cityArr[0] = 0
  1005. local cityArrMsg = msgRet.cityArr
  1006. for cityId, cityInfo in ipairs(msg.cityArr) do
  1007. cityArrMsg[0] = cityId
  1008. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1009. cityArrMsg[cityId].cityId = cityId
  1010. cityArrMsg[cityId].cityName = cityCfg.cityName
  1011. cityArrMsg[cityId].cityLv = cityCfg.cityLv
  1012. cityArrMsg[cityId].occupyPointNum = cityInfo.occupyPointNum or 0
  1013. cityArrMsg[cityId].occupyUnionName = cityInfo.occupyUnionName or ""
  1014. cityArrMsg[cityId].cityState = cityInfo.cityState
  1015. cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
  1016. for i, cId in ipairs(cityCfg.adJoinCityArr) do
  1017. cityArrMsg[cityId].adJoinCityArr[i] = cId
  1018. end
  1019. end
  1020. msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
  1021. for i, cityId in ipairs(msg.myOccupyCityArr) do
  1022. msgRet.myOccupyCityArr[i] = cityId
  1023. end
  1024. -- 据点每分钟的奖励
  1025. local itemId, itemNum = 0, 0
  1026. local cityCfg = AnotherWorldBattleConfig.city[1]
  1027. itemId = cityCfg.cityAward[1]
  1028. for _, pointInfo in ipairs(msg.occupyPointData) do
  1029. local cityId = pointInfo[1]
  1030. local occupyTimeArr = pointInfo[2]
  1031. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1032. local minuteVal = 0
  1033. for _, timeTb in ipairs(occupyTimeArr) do
  1034. local sec = (timeTb[2] or now) - (timeTb[1] or now)
  1035. if sec > 0 then
  1036. minuteVal = minuteVal + sec
  1037. end
  1038. minuteVal = math.floor(minuteVal / 60)
  1039. end
  1040. itemNum = itemNum + minuteVal * cityCfg.cityAward[2]
  1041. end
  1042. Grid.makeItem(msgRet.myUnionAward, itemId, itemNum)
  1043. Msg.send(msgRet, human.fd)
  1044. end
  1045. -- 跨服返回某个城池详细数据
  1046. function C2N_CityDetailed_Response(msg)
  1047. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1048. if not human then
  1049. return
  1050. end
  1051. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  1052. local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
  1053. msgRet.cityId = msg.targetCityId
  1054. msgRet.cityLv = cityCfg.cityLv
  1055. msgRet.cityIconId = cityCfg.cityIconId
  1056. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM )
  1057. local myUnionAwardNum = calcPointAward(msg.myUnionOccupyArr)
  1058. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  1059. -- 活动没有进入战斗阶段时, 使用默认数据
  1060. if #msg.pointArr == 0 then
  1061. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  1062. msg.pointArr[i] = {}
  1063. end
  1064. end
  1065. msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  1066. for pointIdx, pointInfo in ipairs(msg.pointArr) do
  1067. if pointInfo.occupyUnionName then
  1068. msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
  1069. msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
  1070. msgRet.pointArr[pointIdx].power = pointInfo.power
  1071. msgRet.pointArr[pointIdx].state = pointInfo.state
  1072. else
  1073. msgRet.pointArr[pointIdx].occupyUnionName = ""
  1074. msgRet.pointArr[pointIdx].occupyPlayerName = AnotherWorldBattleDefine.AB_DEF_NAME_STR.. pointIdx
  1075. msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
  1076. msgRet.pointArr[pointIdx].state = pointInfo.state
  1077. end
  1078. end
  1079. msgRet.gatherState = msg.gatherState
  1080. if msg.gatherState == 1 then
  1081. -- 公会会长/副会长才能集结
  1082. if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
  1083. msgRet.gatherState = 0
  1084. end
  1085. end
  1086. msgRet.gatherLeftTime = msg.gatherTime
  1087. if msg.gatherTime ~= -1 then
  1088. local now = os.time()
  1089. local subSec = msg.gatherTime + AnotherWorldBattleDefine.AB_GATHER_CD_SEC - now
  1090. msgRet.gatherLeftTime = subSec > 0 and subSec or 0
  1091. end
  1092. Msg.send(msgRet, human.fd)
  1093. end
  1094. -- 跨服返回某个据点数据
  1095. function C2N_PointDetailed_Response(msg)
  1096. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1097. if not human then
  1098. return
  1099. end
  1100. local pointInfo = msg.pointInfo
  1101. local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
  1102. msgRet.state = pointInfo.state
  1103. if pointInfo.name then
  1104. msgRet.name = pointInfo.name
  1105. msgRet.power = pointInfo.power
  1106. msgRet.head = pointInfo.head
  1107. msgRet.headFrame = pointInfo.headFrame
  1108. msgRet.defLv = pointInfo.defLv
  1109. msgRet.heroArr[0] = #pointInfo.heroArr
  1110. for i, heroInfo in ipairs(pointInfo.heroArr) do
  1111. msgRet.heroArr[i].heroBody = heroInfo.heroBody
  1112. msgRet.heroArr[i].heroStar = heroInfo.heroStar
  1113. msgRet.heroArr[i].heroLv = heroInfo.heroLv
  1114. msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
  1115. msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
  1116. msgRet.heroArr[i].heroId = heroInfo.heroId
  1117. msgRet.heroArr[i].heroQuality = heroInfo.heroQuality
  1118. end
  1119. else
  1120. msgRet.name = AnotherWorldBattleDefine.AB_DEF_NAME_STR .. msg.targetPointIdx
  1121. msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
  1122. msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
  1123. msgRet.defLv = 200
  1124. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  1125. msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
  1126. msgRet.heroArr[0] = 0
  1127. local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
  1128. for idx, monsterInfo in ipairs(monsterOutConfig.member) do
  1129. if idx > 6 then
  1130. break
  1131. end
  1132. msgRet.heroArr[0] = idx
  1133. local monsterID = monsterInfo[1]
  1134. local mcf = MonsterExcel.monster[monsterID]
  1135. msgRet.heroArr[idx].heroBody = mcf.body
  1136. msgRet.heroArr[idx].heroStar = mcf.star
  1137. msgRet.heroArr[idx].heroLv = monsterInfo[2]
  1138. msgRet.heroArr[idx].heroCamp = mcf.camp
  1139. msgRet.heroArr[idx].heroIcon = mcf.head
  1140. msgRet.heroArr[idx].heroId = monsterID
  1141. msgRet.heroArr[idx].heroQuality = mcf.heroQuality or 1
  1142. end
  1143. end
  1144. Msg.send(msgRet, human.fd)
  1145. end
  1146. -- 跨服返回公会出生点数据
  1147. function C2N_BaseCity_Response(msg)
  1148. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1149. if not human then
  1150. return
  1151. end
  1152. local baseCityInfo = msg.baseCityInfo
  1153. local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
  1154. local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
  1155. msgRet.cityIconId = cityCfg.cityIconId
  1156. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM)
  1157. local myUnionAwardNum = calcPointAward(baseCityInfo.myUnionOccupyArr)
  1158. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  1159. msgRet.cityIconId = baseCityInfo.occupyPointNum
  1160. msgRet.occupyPointNum = baseCityInfo.occupyPointNum
  1161. msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
  1162. msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
  1163. msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
  1164. msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
  1165. Msg.send(msgRet, human.fd)
  1166. end
  1167. -- 跨服返回玩家占领的据点数据
  1168. function C2N_PlayerOccupyPoint_Response(msg)
  1169. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1170. if not human then
  1171. return
  1172. end
  1173. local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
  1174. local myPointArr = msgRet.myPointArr
  1175. myPointArr[0] = 0
  1176. for idx, pointInfo in ipairs(msg.occupyPointArr) do
  1177. myPointArr[0] = idx
  1178. local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
  1179. myPointArr[idx].cityIconId = cityCfg.cityIconId
  1180. myPointArr[idx].cityName = cityCfg.cityName
  1181. myPointArr[idx].cityLv = cityCfg.cityLv
  1182. myPointArr[idx].pointIdx = pointInfo.pointIdx
  1183. myPointArr[idx].power = pointInfo.power
  1184. myPointArr[idx].cityId = pointInfo.cityId
  1185. myPointArr[idx].heroArr[0] = #pointInfo.heroArr
  1186. for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
  1187. local hero = myPointArr[idx].heroArr[heroIdx]
  1188. hero.heroBody = heroInfo.heroBody
  1189. hero.heroStar = heroInfo.heroStar
  1190. hero.heroLv = heroInfo.heroLv
  1191. hero.heroCamp = heroInfo.heroCamp
  1192. hero.heroIcon = heroInfo.heroIcon
  1193. hero.heroId = heroInfo.heroId
  1194. hero.heroQuality = heroInfo.heroQuality
  1195. end
  1196. end
  1197. Msg.send(msgRet, human.fd)
  1198. end
  1199. -- 跨服返回集结/取消集结成功
  1200. function C2N_Gather_Response(msg)
  1201. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1202. if not human then
  1203. return
  1204. end
  1205. local targetCityId = msg.targetCityId
  1206. local cityCfg = AnotherWorldBattleConfig.city[targetCityId]
  1207. local msgRet = Msg.gc.GC_AB_GARHER
  1208. msgRet.cityId = targetCityId
  1209. msgRet.cityName = cityCfg.cityName
  1210. msgRet.opType = msg.opType
  1211. Msg.send(msgRet, human.fd)
  1212. end
  1213. --跨服返回公会排行榜数据
  1214. function C2N_UnionRank_Response(msg)
  1215. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1216. if not human then
  1217. return
  1218. end
  1219. local itemId, itemNum = 184, 0
  1220. local rankReward = AnotherWorldBattleConfig.rankReward
  1221. itemId = getRankGenericAwadId(rankReward, 1)
  1222. local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
  1223. msgRet.unionRankArr[0] = 0
  1224. msgRet.myUnionRank = msg.myUnionRank
  1225. msgRet.myData.name = ""
  1226. msgRet.myData.power = 0
  1227. msgRet.myData.cityNum = 0
  1228. msgRet.myData.pointNum = 0
  1229. Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1230. for rank, rankdData in ipairs(msg.unionRankArr) do
  1231. msgRet.unionRankArr[0] = rank
  1232. msgRet.unionRankArr[rank].name = rankdData.name
  1233. msgRet.unionRankArr[rank].power = rankdData.power
  1234. msgRet.unionRankArr[rank].cityNum = rankdData.cityNum
  1235. msgRet.unionRankArr[rank].pointNum = rankdData.pointNum
  1236. itemId, itemNum = getRankAward(rankReward, 1, rank)
  1237. Grid.makeItem(msgRet.unionRankArr[rank].rankAward, itemId, itemNum)
  1238. if rank == msg.myUnionRank then
  1239. msgRet.myData.name = rankdData.name
  1240. msgRet.myData.power = rankdData.power
  1241. msgRet.myData.cityNum = rankdData.cityNum
  1242. msgRet.myData.pointNum = rankdData.pointNum
  1243. Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1244. end
  1245. end
  1246. if msgRet.myData.power == 0 then
  1247. local unionId = human.db.unionUuid
  1248. local queryFiles = {name = 1, zhandouli = 1}
  1249. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  1250. msgRet.myData.name = unionInfo and unionInfo.name or ""
  1251. msgRet.myData.power = unionInfo and unionInfo.zhandouli or 0
  1252. end
  1253. Msg.send(msgRet, human.fd)
  1254. end
  1255. --跨服返回玩家排行榜数据
  1256. function C2N_PlayerRank_Response(msg)
  1257. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1258. if not human then
  1259. return
  1260. end
  1261. local itemId, itemNum = 184, 0
  1262. local rankReward = AnotherWorldBattleConfig.rankReward
  1263. itemId = getRankGenericAwadId(rankReward, 2)
  1264. local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
  1265. msgRet.playerRankArr[0] = 0
  1266. msgRet.myRank = msg.myRank
  1267. msgRet.myData.name = human.db.name
  1268. msgRet.myData.power = human.db.zhandouli
  1269. msgRet.myData.pointNum = 0
  1270. msgRet.myData.pointWeight = 0
  1271. Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1272. for rank, rankdData in ipairs(msg.playerRankArr) do
  1273. msgRet.playerRankArr[0] = rank
  1274. msgRet.playerRankArr[rank].name = rankdData.name
  1275. msgRet.playerRankArr[rank].power = rankdData.power
  1276. msgRet.playerRankArr[rank].pointNum = rankdData.pointNum
  1277. msgRet.playerRankArr[rank].pointWeight = rankdData.pointWeight
  1278. itemId, itemNum = getRankAward(rankReward, 2, rank)
  1279. Grid.makeItem(msgRet.playerRankArr[rank].rankAward, itemId, itemNum)
  1280. if rank == msg.myRank then
  1281. msgRet.myData.pointNum = rankdData.pointNum
  1282. msgRet.myData.pointWeight = rankdData.pointWeight
  1283. Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1284. end
  1285. end
  1286. Msg.send(msgRet, human.fd)
  1287. end
  1288. -- 跨服返回要挑战的据点的数据(据点可以被挑战)
  1289. function C2N_TryChallengePoint_Response(msg)
  1290. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1291. if not human then
  1292. return
  1293. end
  1294. local pointInfo = msg.pointInfo
  1295. human.AB_Battle_Cache = {
  1296. isGather = pointInfo.isGather,
  1297. cityId = pointInfo.targetCityId,
  1298. pointIdx = pointInfo.targetPointIdx,
  1299. defMoraleAttrIdx = pointInfo.defMoraleAttrIdx,
  1300. atkMoraleAttrIdx = pointInfo.atkMoraleAttrIdx,
  1301. }
  1302. if pointInfo.occupySrvId then -- 玩家占领
  1303. local args = {
  1304. combatType = CombatDefine.COMBAT_TYPE35,
  1305. nServerIndex = pointInfo.occupySrvId,
  1306. param = pointInfo.occupyPlayerUuid,
  1307. extraArgs = {
  1308. cityId = pointInfo.targetCityId,
  1309. pointIdx = pointInfo.targetPointIdx,
  1310. useDef = true,
  1311. }
  1312. }
  1313. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
  1314. else
  1315. -- 机器人
  1316. CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
  1317. end
  1318. end
  1319. -- 跨服通知据点被别的玩家占领了
  1320. function C2N_PointLose_Response(msg)
  1321. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1322. if not human then
  1323. local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
  1324. if not db then
  1325. return
  1326. end
  1327. human = {}
  1328. human.db = db
  1329. end
  1330. -- 更新防守阵容数据
  1331. local loseCityId = msg.loseCityId
  1332. local losePointIdx = msg.losePointIdx
  1333. local formationData = human.db.anotherWorlBattle.formation
  1334. formationData[loseCityId][losePointIdx] = nil
  1335. -- 玩家不在线, 手动保存数据
  1336. if not human.fd then
  1337. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1338. end
  1339. local cityCfg = AnotherWorldBattleConfig.city[loseCityId]
  1340. -- 发邮件
  1341. local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
  1342. local content = Util.format(mailCfg.content, cityCfg and cityCfg.cityName or "", loseCityId)
  1343. MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, content, nil, mailCfg.senderName or "GM")
  1344. -- 把最新的防守阵容数据推给客户端
  1345. if human.fd then
  1346. sendDefHeroArr(human)
  1347. end
  1348. end
  1349. -- 跨服通知可以更换据点的防守阵容数据
  1350. function C2N_UpdatePointLineup_Response(msg)
  1351. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1352. if not human then
  1353. local db = RoleDBLogic.getDb(msg.playerUuid)
  1354. if not db then
  1355. return
  1356. end
  1357. human = {}
  1358. human.db = db
  1359. end
  1360. local anotherWorlBattle = human.db.anotherWorlBattle
  1361. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1362. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  1363. end
  1364. local cityId = msg.targetCityId
  1365. local pointIdx = msg.targetPointIdx
  1366. if not anotherWorlBattle.formation[cityId] or not anotherWorlBattle.formation[cityId][pointIdx] then
  1367. return
  1368. end
  1369. local pointLinupData = anotherWorlBattle.formation[cityId][pointIdx]
  1370. pointLinupData.list = msg.heroList
  1371. pointLinupData.helpList = msg.helpList
  1372. pointLinupData.formation = msg.formation
  1373. if not human.fd then
  1374. ObjHuman.save(human)
  1375. end
  1376. sendDefHeroArr(human)
  1377. Broadcast.sendCenter(human, Lang.AB_UPDATE_LINEUP_SUCC)
  1378. end
  1379. -- 跨服通知放弃据点成功
  1380. function C2N_LeavePoint_Response(msg)
  1381. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1382. if not human then
  1383. local db = RoleDBLogic.getDb(msg.playerUuid)
  1384. if not db then
  1385. return
  1386. end
  1387. human = {}
  1388. human.db = db
  1389. end
  1390. local anotherWorlBattle = human.db.anotherWorlBattle
  1391. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1392. return
  1393. end
  1394. local cityId = msg.targetCityId
  1395. local pointIdx = msg.targetPointIdx
  1396. anotherWorlBattle.formation[cityId][pointIdx] = nil
  1397. if not next(anotherWorlBattle.formation[cityId]) then
  1398. anotherWorlBattle.formation[cityId] = nil
  1399. end
  1400. -- 玩家不在线, 手动保存数据
  1401. if not human.fd then
  1402. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1403. else
  1404. -- 把最新的防守阵容数据推给客户端
  1405. sendDefHeroArr(human)
  1406. end
  1407. end
  1408. -- 跨服返回本公会士气信息
  1409. function C2N_MyUnionMoraleInfo_Response(msg)
  1410. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1411. if not human then
  1412. return
  1413. end
  1414. local varCfg = AnotherWorldBattleConfig.var[1]
  1415. local msgRet = Msg.gc.GC_AB_GET_MORALE_INFO
  1416. msgRet.moraleState = msg.moraleState
  1417. msgRet.leftTime = 0
  1418. local now = os.time()
  1419. local leftTime = msg.moraleStartTime + AnotherWorldBattleDefine.AB_MORALE_DURATION - now
  1420. if leftTime > 0 then
  1421. msgRet.leftTime = leftTime
  1422. end
  1423. local itemCfg = varCfg.moraleCost
  1424. local itemId = itemCfg and itemCfg[1] or 101
  1425. local itemNum = itemCfg and itemCfg[2] or 0
  1426. Grid.makeItem(msgRet.moraleCost, itemId, itemNum)
  1427. msgRet.moraleAttrs[0] = 0
  1428. local moraleAttrCfg = varCfg.moraleAtrrs
  1429. if moraleAttrCfg then
  1430. local attrArr = moraleAttrCfg[msg.moraleAttrIdx] or moraleAttrCfg[1]
  1431. for i, attrTb in ipairs(attrArr) do
  1432. msgRet.moraleAttrs[0] = i
  1433. msgRet.moraleAttrs[i].key = attrTb[1]
  1434. msgRet.moraleAttrs[i].value = attrTb[2]
  1435. end
  1436. end
  1437. Msg.send(msgRet, human.fd)
  1438. end
  1439. -- 跨服返回加士气结果
  1440. function C2N_UnionMorale_Response(msg)
  1441. if msg.opRes == 0 then
  1442. return
  1443. end
  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 moraleCostCfg = AnotherWorldBattleConfig.var[1].moraleCost
  1454. local itemId, itemNum = moraleCostCfg[1], moraleCostCfg[2]
  1455. BagLogic.addItem(human, itemId, itemNum, LOGTAG)
  1456. if not human.fd then
  1457. ObjHuman.save(human)
  1458. end
  1459. end
  1460. -- 跨服通知给玩家发奖
  1461. function C2N_IssueReward(msg)
  1462. -- 删除公会参加异界之战活动时间
  1463. UnionLogic.UpdateJoinAbTime(msg.unionOccupyInfo.unionId, nil)
  1464. resetDefData(msg.unionOccupyInfo.playerInfoArr)
  1465. -- 发奖
  1466. local awardObjArr, occupyCityInfo = genAwardObjArr(msg.unionOccupyInfo)
  1467. if awardObjArr then
  1468. local issueRewardQueue = createRewardQueue()
  1469. issueRewardQueue.extraInfo = occupyCityInfo
  1470. for _, obj in ipairs(awardObjArr) do
  1471. issueRewardQueue:add(obj)
  1472. end
  1473. issueRewardQueue:insertDB()
  1474. end
  1475. end
  1476. -------------------------------------------战斗---------------------------------
  1477. function getCombatMonsterOutID(human, side, args)
  1478. if side ~= CombatDefine.DEFEND_SIDE then return end
  1479. local cityId = args[2]
  1480. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1481. return cityCfg and cityCfg.pointMonsterId
  1482. end
  1483. function getCombatObjList(human, side, args, combatType, extraArgs)
  1484. if side == CombatDefine.ATTACK_SIDE and not human then return end
  1485. if side == CombatDefine.DEFEND_SIDE and human then
  1486. return
  1487. end
  1488. if not human then
  1489. local uuid = args[1]
  1490. local db = RoleDBLogic.getDb(uuid)
  1491. if not db then
  1492. return
  1493. end
  1494. human = {}
  1495. human.db = db
  1496. end
  1497. return CombatLogic.getHumanObjList(human, combatType, extraArgs)
  1498. end
  1499. function getCombatHeros(human, combatType, args)
  1500. if not human.db.anotherWorlBattle then
  1501. return
  1502. end
  1503. if not args then
  1504. return
  1505. end
  1506. local formation = human.db.anotherWorlBattle.formation
  1507. if not formation then
  1508. return
  1509. end
  1510. local cityId, pointIdx = args.cityId, args.pointIdx
  1511. if formation[cityId] and formation[cityId][pointIdx] then
  1512. local combatHeroDB = formation[cityId][pointIdx]
  1513. return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
  1514. end
  1515. end
  1516. function onFightBegin(human, cbParam, combatType, param)
  1517. 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
  1518. return
  1519. end
  1520. local function addAttr(obj, attrs)
  1521. for _, atrrTb in ipairs(attrs or {}) do
  1522. local attrId, attrVal = atrrTb[1], atrrTb[2]
  1523. obj.sysAttr[attrId] = (obj.sysAttr[attrId] or 0) + attrVal
  1524. end
  1525. end
  1526. local atkGatherAttrs, atkMoraleAttrs, defMoraleAttrs
  1527. local varCfg = AnotherWorldBattleConfig.var[1]
  1528. if human.AB_Battle_Cache.isGather then
  1529. atkGatherAttrs = varCfg.gatherAttrs
  1530. end
  1531. if human.AB_Battle_Cache.atkMoraleAttrIdx then
  1532. local idx = human.AB_Battle_Cache.atkMoraleAttrIdx
  1533. atkMoraleAttrs = varCfg.moraleAtrrs and varCfg.moraleAtrrs[idx]
  1534. end
  1535. if human.AB_Battle_Cache.defMoraleAttrIdx then
  1536. local idx = human.AB_Battle_Cache.defMoraleAttrIdx
  1537. defMoraleAttrs = varCfg.moraleAtrrs and varCfg.moraleAtrrs[idx]
  1538. end
  1539. for index = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  1540. local side = index > CombatDefine.COMBAT_HERO_CNT and CombatDefine.DEFEND_SIDE or CombatDefine.ATTACK_SIDE
  1541. local realPos = CombatLogic.getPos(side, index)
  1542. local obj = CombatImpl.objList[realPos]
  1543. if obj then
  1544. if side == CombatDefine.ATTACK_SIDE then
  1545. if atkGatherAttrs or atkMoraleAttrs then
  1546. addAttr(obj, atkGatherAttrs)
  1547. addAttr(obj, atkMoraleAttrs)
  1548. obj.isSysAttrChange = true
  1549. end
  1550. else
  1551. if defMoraleAttrs then
  1552. addAttr(obj, defMoraleAttrs)
  1553. obj.isSysAttrChange = true
  1554. end
  1555. end
  1556. end
  1557. end
  1558. end
  1559. function onFightEnd(human, result, type, cbParam, combatInfo)
  1560. -- if result == CombatDefine.RESULT_WIN then
  1561. -- challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
  1562. -- end
  1563. local args = {
  1564. cityId = human.AB_Battle_Cache.cityId,
  1565. pointIdx = human.AB_Battle_Cache.pointIdx,
  1566. challengeRes = result
  1567. }
  1568. human.AB_Battle_Cache = nil
  1569. challenge_End(human, args)
  1570. end