AnotherWorldBattleNS.lua 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  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 function writeLog(logStr)
  50. Log.write(Log.LOGID_OSS_ANOTHERWORLDBATTLE, logStr)
  51. end
  52. local function sendMail(mailId, receiverUuid, itemArray, extraInfo)
  53. if not mailId or not receiverUuid then
  54. return
  55. end
  56. local v1,v2,v3,v4,v5 = extraInfo and extraInfo[1] or 0, extraInfo and extraInfo[2] or 0, extraInfo and extraInfo[3] or 0, extraInfo and extraInfo[4] or 0, extraInfo and extraInfo[5] or 0
  57. local mailCfg = MailExcel.mail[mailId]
  58. local content = Util.format(mailCfg.content, v1,v2,v3,v4,v5)
  59. MailManager.add(MailManager.SYSTEM, receiverUuid, mailCfg.title, content, itemArray, mailCfg.senderName or "GM")
  60. end
  61. local function createRewardQueue()
  62. local issueRewardQueue = {
  63. playerArray = {},
  64. insertMaxNum = 100, -- 一次最多插入数据库的邮件数量
  65. repeatMaxTimes = 3, -- 重试次数
  66. repeatTb = {},
  67. extraInfo = {},
  68. }
  69. function issueRewardQueue:add(playerInfo)
  70. table.insert(self.playerArray, playerInfo)
  71. end
  72. function issueRewardQueue:insertDB()
  73. local maxNum = math.min(self.insertMaxNum, #self.playerArray)
  74. for i=1, maxNum do
  75. local resTag = AnotherWorldBattleDefine.AB_MAIL_SUCC_TAG
  76. local playerInfo = table.remove(self.playerArray)
  77. local uuid = playerInfo[1]
  78. local ok, err = pcall(sendMail, AnotherWorldBattleDefine.AB_AWARD_MAIL_ID, uuid, playerInfo[2], issueRewardQueue.extraInfo)
  79. if not ok then
  80. if not self.repeatTb[uuid] or self.repeatTb[uuid] < self.repeatMaxTimes then
  81. issueRewardQueue:add(playerInfo)
  82. self.repeatTb[uuid] = (self.repeatTb[uuid] or 0) + 1
  83. end
  84. resTag = AnotherWorldBattleDefine.AB_MAIL_FAIL_TAG
  85. end
  86. local str = string.format("Result: %s, playerUuid: %s, insertErrTimes: %d, errInfo: %s",
  87. resTag, uuid, self.repeatTb[uuid] or 0, err)
  88. writeLog(str)
  89. end
  90. if #self.playerArray > 0 then
  91. Timer.addLater(3, self.insertDB, self)
  92. end
  93. end
  94. return issueRewardQueue
  95. end
  96. -- 获取当天是星期几
  97. local function getWDay()
  98. return Util.getWeekDay()
  99. end
  100. -- 计算怪物战力
  101. local function calcMonsterPower(monsterOutID)
  102. local power = 0
  103. local objList = MonsterGrid.createMonsterObjListByMonsterOutID(monsterOutID)
  104. if not objList then
  105. return power
  106. end
  107. for _, monster in ipairs(objList) do
  108. power = power + (monster.power or 0)
  109. end
  110. return power
  111. end
  112. -- 根据据点所属城池,计算多个据点每分钟产出道具数量之和
  113. local function calcPointAward(cityIdArr)
  114. local myUnionAwardNum = 0
  115. if cityIdArr then
  116. for _, cityId in ipairs(cityIdArr) do
  117. local targetCityCfg = AnotherWorldBattleConfig.city[cityId]
  118. if targetCityCfg.isBaseCity == 1 then
  119. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  120. else
  121. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2]
  122. end
  123. end
  124. end
  125. return myUnionAwardNum
  126. end
  127. -- 获取展示部位的固定Id
  128. local function getDefaultShowId(showType, idx)
  129. local targetCfg
  130. if showType == 1 then
  131. targetCfg = RoleConfig.head
  132. else
  133. targetCfg = RoleConfig.headFrame
  134. end
  135. local t = {}
  136. for k in pairs(targetCfg) do
  137. t[#t+1] = k
  138. end
  139. table.sort(t)
  140. return t[idx] or t[1]
  141. end
  142. -- 单个英雄数据
  143. local function getHeroInfo(human, targetHeroUuid)
  144. local HeroLogic = require("hero.HeroLogic")
  145. local heroGrid = HeroLogic.getHeroGridByUuid(human, targetHeroUuid)
  146. if heroGrid then
  147. local heroCfg = HeroExcel.hero[heroGrid.id]
  148. RoleAttr.calcHeroGrid(heroGrid, nil, human)
  149. local heroInfo = {
  150. heroUuid = targetHeroUuid,
  151. heroStar = heroGrid.star,
  152. heroLevel = heroGrid.lv,
  153. heroCamp = heroGrid.camp or heroCfg.camp,
  154. heroBody = heroCfg.body,
  155. heroIcon = heroGrid.head or heroCfg.head,
  156. heroPower = heroGrid.zhandouli,
  157. heroId = heroGrid.id,
  158. heroQuality = heroCfg.grade,
  159. }
  160. return heroInfo
  161. end
  162. end
  163. -- 获取上阵英雄数据
  164. local function getHeroListInfo(human, targetHeroUuid)
  165. local len = 0
  166. local heroArr = {}
  167. local heroList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  168. if not next(heroList) then
  169. return heroArr
  170. end
  171. for _, heroUuid in pairs(heroList) do
  172. if (heroUuid ~= "" and heroUuid ~= "0") and (not targetHeroUuid or targetHeroUuid == heroUuid) then
  173. len = len + 1
  174. heroArr[len] = getHeroInfo(human, heroUuid)
  175. end
  176. end
  177. if len == 0 then
  178. return
  179. end
  180. return heroArr
  181. end
  182. -- 生成展示数据
  183. local function generateShowInfo(human)
  184. local showInfo = {
  185. name = human.db.name,
  186. lv = human.db.lv,
  187. power = human.db.zhandouli,
  188. }
  189. showInfo.head = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_1)
  190. showInfo.headFrame = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_2)
  191. -- showInfo.body = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_3)
  192. showInfo.heroArr = getHeroListInfo(human)
  193. return showInfo
  194. end
  195. -- 阵容数据检查,如果不在 "活动开启且战斗阶段" 则清空
  196. local function formationDataCheeck(human)
  197. if not human.db.anotherWorlBattle then
  198. return
  199. end
  200. -- 不在战斗阶段时间范围
  201. local wDay = getWDay()
  202. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] > wDay and AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] < wDay then
  203. human.db.anotherWorlBattle = nil
  204. end
  205. -- 处于战斗阶段最后一天, 但是活动已经结束
  206. local now = os.time()
  207. local toDayStartTime = Util.getDayStartTime(now)
  208. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  209. human.db.anotherWorlBattle = nil
  210. end
  211. -- 处于战斗阶段时间范围内, 但是活动未开(因为每两轮活动时间间隔至少9天)
  212. local startTime = human.db.anotherWorlBattle.startTime
  213. local diffDays = Util.diffDay(startTime)
  214. if diffDays > 3 then
  215. human.db.anotherWorlBattle = nil
  216. end
  217. end
  218. -- 把玩家最新的异界之战所有防守英雄uuid推给客户端
  219. local function sendDefHeroArr(human)
  220. if not human.db.anotherWorlBattle then
  221. return
  222. end
  223. local len = 0
  224. local msgRet = Msg.gc.GC_AB_DEF_HERO_QUERY
  225. local heroUuidArrMsg = msgRet.heroUuidArr
  226. heroUuidArrMsg[0] = 0
  227. for _, pointList in pairs(human.db.anotherWorlBattle.formation) do
  228. for _, combatData in pairs(pointList) do
  229. local heroList = combatData.list
  230. for _, heroUuid in pairs(heroList) do
  231. if heroUuid ~= "" and heroUuid ~= "0" then
  232. len = len + 1
  233. heroUuidArrMsg[len] = heroUuid
  234. end
  235. end
  236. end
  237. end
  238. heroUuidArrMsg[0] = len
  239. Msg.send(msgRet, human.fd)
  240. end
  241. -- 是否是防守阵容中的英雄
  242. local function isDefHero(human, checkHeroUuid, excludeCityId, excludePointIdx)
  243. if not human.db.anotherWorlBattle then
  244. return false
  245. end
  246. for cityId, pointList in pairs(human.db.anotherWorlBattle.formation) do
  247. for pointIdx, combatData in pairs(pointList) do
  248. if (excludeCityId and excludeCityId == cityId) and (excludePointIdx and excludePointIdx == pointIdx) then
  249. break
  250. end
  251. local heroList = combatData.list
  252. for _, heroUuid in pairs(heroList) do
  253. if heroUuid == checkHeroUuid then
  254. return true
  255. end
  256. end
  257. end
  258. end
  259. return false
  260. end
  261. -- 是否是公会前二名
  262. local function isTopTwoUnion(human)
  263. local unionRanList = BillboardLogic.GetRankList(BillboardDefine.TYPE_UNION)
  264. if not unionRanList then
  265. return false
  266. end
  267. local unionId = human.db.unionUuid
  268. local isTopTwo = false
  269. for i=1, 2 do
  270. if unionRanList[i].uuid == unionId then
  271. isTopTwo = true
  272. break
  273. end
  274. end
  275. return isTopTwo
  276. end
  277. -- 是否处于战斗阶段
  278. local function isBattleStage()
  279. local wDay = getWDay()
  280. if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
  281. return true
  282. end
  283. return false
  284. end
  285. -- 生成奖励发放对象列表
  286. local function genAwardObjArr(unionOccupyInfo)
  287. local function calcMinute(timeArr)
  288. local minuteVal = 0
  289. for _, timeTb in ipairs(timeArr or {}) do
  290. local sec = timeTb[2] - timeTb[1]
  291. if sec > 0 then
  292. minuteVal = minuteVal + sec
  293. end
  294. end
  295. return math.floor(minuteVal / 60)
  296. end
  297. if not unionOccupyInfo.playerUuidArr or #unionOccupyInfo.playerUuidArr <= 0 then
  298. return
  299. end
  300. local itemList = {}
  301. local occupyCityInfo = {0,0,0,0,0}
  302. local item_185_Id = 185
  303. local item_185_Num = 0
  304. item_185_Num = item_185_Num + (unionOccupyInfo.occuoyPointNum or 0) -- 待优化
  305. -- 额外奖励
  306. for _, cityId in ipairs(unionOccupyInfo.occupyCityArr) do
  307. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  308. if cityCfg then
  309. if cityCfg.isBaseCity == 1 then
  310. item_185_Num = item_185_Num + 20
  311. occupyCityInfo[1] = occupyCityInfo[1] + 1
  312. else
  313. if cityCfg.cityLv == 2 then
  314. item_185_Num = item_185_Num + 2
  315. occupyCityInfo[2] = occupyCityInfo[2] + 1
  316. elseif cityCfg.cityLv == 3 then
  317. item_185_Num = item_185_Num + 3
  318. occupyCityInfo[3] = occupyCityInfo[3] + 1
  319. elseif cityCfg.cityLv == 4 then
  320. item_185_Num = item_185_Num + 5
  321. occupyCityInfo[4] = occupyCityInfo[4] + 1
  322. elseif cityCfg.cityLv == 5 then
  323. item_185_Num = item_185_Num + 20
  324. occupyCityInfo[5] = occupyCityInfo[5] + 1
  325. end
  326. end
  327. end
  328. end
  329. -- 占领据点每分钟的奖励
  330. for _, pointInfo in ipairs(unionOccupyInfo.point2CityIdArr) do
  331. local cityId = pointInfo[1]
  332. local occupyTimeArr = pointInfo[2]
  333. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  334. local totalMinVal = calcMinute(occupyTimeArr)
  335. if totalMinVal > 0 then
  336. local itemId, itemNum = cityCfg.cityAward[1], cityCfg.cityAward[2]
  337. itemList[itemId] = totalMinVal * itemNum
  338. end
  339. end
  340. if item_185_Num > 0 then
  341. itemList[item_185_Id] = item_185_Num
  342. end
  343. local itemArr = {}
  344. for itemId, itemNum in pairs(itemList) do
  345. itemArr[#itemArr+1] = { itemId, itemNum }
  346. end
  347. local awardObjArr = {}
  348. for _, playerUuid in ipairs(unionOccupyInfo.playerUuidArr) do
  349. awardObjArr[#awardObjArr+1] = {playerUuid, itemArr}
  350. end
  351. return awardObjArr, occupyCityInfo
  352. end
  353. -- 活动是否处于开启中
  354. function IsRuning(joinTime)
  355. local wDay = getWDay()
  356. if not table.find(AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA, wDay) then
  357. return false
  358. end
  359. local diffDays = Util.diffDay(joinTime)
  360. -- 活动最后一天, 如果当前时间 > 结束时间则标识活动结束
  361. if diffDays == 5 then
  362. local now = os.time()
  363. local toDayStartTime = Util.getDayStartTime(now)
  364. if now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  365. return false
  366. end
  367. end
  368. -- < 5天说明处于本轮活动的开启时间
  369. if diffDays > 5 then
  370. return false
  371. end
  372. return true
  373. end
  374. --检测上阵英雄
  375. function checkUpdatePos(human, msg)
  376. local heroList = Util.split(msg.heroList, ",")
  377. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  378. local uuid = heroList[i] or ""
  379. if uuid ~= "0" and uuid ~= "" then
  380. if isDefHero(human, uuid) then
  381. return false
  382. end
  383. end
  384. end
  385. return true
  386. end
  387. -- 公会战力更新
  388. function UnionPowerChange(unionId, newPower)
  389. if not isBattleStage() then
  390. return
  391. end
  392. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  393. msgData.myUnionId = unionId
  394. msgData.updateData = {}
  395. msgData.updateData.power = newPower
  396. InnerMsg.sendMsg(0, msgData)
  397. end
  398. -- 玩家战力更新
  399. function PlayerPowerChange(human)
  400. if not isBattleStage() then
  401. return
  402. end
  403. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  404. msgData.playerUuid = human.db._id
  405. msgData.myUnionId = human.db.unionUuid
  406. msgData.updateData = {}
  407. msgData.updateData.power = human.db.zhandouli
  408. InnerMsg.sendMsg(0, msgData)
  409. end
  410. function isOpen(human)
  411. return RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1306) -- 待改
  412. end
  413. function onLogin(human)
  414. formationDataCheeck(human)
  415. sendDefHeroArr(human)
  416. end
  417. -- 请求状态
  418. function AB_GetState(human)
  419. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_STATE
  420. msgData.sourceServerId = Config.SVR_INDEX
  421. msgData.playerUuid = human.db._id
  422. msgData.myUnionId = human.db.unionUuid or ""
  423. InnerMsg.sendMsg(0, msgData)
  424. end
  425. -- 报名
  426. function AB_Join(human)
  427. local unionId = human.db.unionUuid
  428. local msgRet = Msg.gc.GC_AB_JOIN
  429. if not unionId then
  430. msgRet.Joinstate = 3
  431. return Msg.send(msgRet, human.fd)
  432. end
  433. -- if not isOpen(human) then
  434. -- return Broadcast.sendErr(human, Lang.AB_JOIN_COND_NOT_SATIFY)
  435. -- end
  436. local wDay = getWDay()
  437. -- if not table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  438. -- msgRet.Joinstate = 5
  439. -- return Msg.send(msgRet, human.fd)
  440. -- end
  441. if wDay ~= AnotherWorldBattleDefine.AB_JOIN_WDAY then
  442. msgRet.Joinstate = 5
  443. return Msg.send(msgRet, human.fd)
  444. end
  445. -- 公会排名前二才能参加
  446. if not isTopTwoUnion(human) then
  447. msgRet.Joinstate = 2
  448. return Msg.send(msgRet, human.fd)
  449. end
  450. -- 会长/副会长才能报名
  451. if not UnionLogic.IsTopTwoManager(human, unionId) then
  452. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  453. end
  454. local queryFiles = {name = 1, zhandouli = 1}
  455. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  456. if not unionInfo then
  457. return Broadcast.sendErr(human, Lang.DATA_ERR)
  458. end
  459. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_JOIN
  460. msgData.sourceServerId = Config.SVR_INDEX
  461. msgData.playerUuid = human.db._id
  462. msgData.unionInfo = {
  463. name = unionInfo.name,
  464. power = unionInfo.zhandouli,
  465. unionId = unionId
  466. }
  467. InnerMsg.sendMsg(0, msgData)
  468. end
  469. -- 查询所有城池信息
  470. function AB_AllCity_Query(human)
  471. if not human.db.unionUuid then
  472. return
  473. end
  474. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  475. msgData.sourceServerId = Config.SVR_INDEX
  476. msgData.playerUuid = human.db._id
  477. msgData.myUnionId = human.db.unionUuid
  478. InnerMsg.sendMsg(0, msgData)
  479. -- 报名状态查询
  480. -- local msgData2 = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_JOIN_STATE
  481. -- msgData2.sourceServerId = Config.SVR_INDEX
  482. -- msgData2.playerUuid = human.db._id
  483. -- msgData2.myUnionId = human.db.unionUuid
  484. -- InnerMsg.sendMsg(0, msgData2)
  485. end
  486. -- 查询单个城池的详细信息
  487. function AB_CityDetailed_Query(human, targetCityId)
  488. if not AnotherWorldBattleConfig.city[targetCityId] then
  489. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  490. end
  491. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  492. msgData.sourceServerId = Config.SVR_INDEX
  493. msgData.playerUuid = human.db._id
  494. msgData.myUnionId = human.db.unionUuid
  495. msgData.targetCityId = targetCityId
  496. InnerMsg.sendMsg(0, msgData)
  497. end
  498. -- 查询某个城池的某个据点的详细信息
  499. function AB_PointDetailed_Query(human, targetCityId, targetPointIdx)
  500. if not AnotherWorldBattleConfig.city[targetCityId] then
  501. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  502. end
  503. if 0 >= targetPointIdx or AnotherWorldBattleDefine.AB_POINT_MAX_NUM < targetPointIdx then
  504. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  505. end
  506. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINTtDETAILED_QUERY
  507. msgData.sourceServerId = Config.SVR_INDEX
  508. msgData.playerUuid = human.db._id
  509. msgData.myUnionId = human.db.unionUuid
  510. msgData.targetCityId = targetCityId
  511. msgData.targetPointIdx = targetPointIdx
  512. InnerMsg.sendMsg(0, msgData)
  513. end
  514. -- 查询本公会出生点信息
  515. function AB_BaseCity_Query(human)
  516. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_BASECITY_QUERY
  517. msgData.sourceServerId = Config.SVR_INDEX
  518. msgData.playerUuid = human.db._id
  519. msgData.myUnionId = human.db.unionUuid
  520. InnerMsg.sendMsg(0, msgData)
  521. end
  522. -- 查询玩家占领的所有据点信息
  523. function AB_PlayerOccupyPOint_Query(human)
  524. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  525. msgData.sourceServerId = Config.SVR_INDEX
  526. msgData.playerUuid = human.db._id
  527. msgData.myUnionId = human.db.unionUuid
  528. InnerMsg.sendMsg(0, msgData)
  529. end
  530. -- 查询公会排行榜
  531. function AB_UnionRank_Query(human)
  532. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  533. msgData.sourceServerId = Config.SVR_INDEX
  534. msgData.playerUuid = human.db._id
  535. msgData.myUnionId = human.db.unionUuid
  536. InnerMsg.sendMsg(0, msgData)
  537. end
  538. -- 查询玩家排行榜
  539. function AB_PlayerRank_Query(human)
  540. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  541. msgData.sourceServerId = Config.SVR_INDEX
  542. msgData.playerUuid = human.db._id
  543. msgData.myUnionId = human.db.unionUuid
  544. InnerMsg.sendMsg(0, msgData)
  545. end
  546. -- 发起集结
  547. function AB_Gather(human, targetCityId, opType)
  548. if not AnotherWorldBattleConfig.city[targetCityId] then
  549. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  550. end
  551. if opType ~= 1 and opType ~= 2 then
  552. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  553. end
  554. local unionId = human.db.unionUuid
  555. if not unionId then
  556. return Broadcast.sendErr(human, Lang.AB_NO_UNION)
  557. end
  558. -- 会长/副会长才能集结
  559. if not UnionLogic.IsTopTwoManager(human, unionId) then
  560. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANAGER)
  561. end
  562. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GATHER
  563. msgData.sourceServerId = Config.SVR_INDEX
  564. msgData.playerUuid = human.db._id
  565. msgData.myUnionId = human.db.unionUuid
  566. msgData.targetCityId = targetCityId
  567. msgData.opType = opType
  568. InnerMsg.sendMsg(0, msgData)
  569. end
  570. -- 请求挑战某个据点
  571. function AB_Try_Challenge_Point(human, targetCityId, targetPointIdx)
  572. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  573. if not combatHero or not next(combatHero) then
  574. return Broadcast.sendErr(human, Lang.COMBAT_NEED_FIGHT_HERO)
  575. end
  576. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  577. msgData.sourceServerId = Config.SVR_INDEX
  578. msgData.playerUuid = human.db._id
  579. msgData.myUnionId = human.db.unionUuid
  580. msgData.targetCityId = targetCityId
  581. msgData.targetPointIdx = targetPointIdx
  582. InnerMsg.sendMsg(0, msgData)
  583. end
  584. -- 战斗结束
  585. local function challenge_End(human, args)
  586. local cityId = args.cityId
  587. local pointIdx = args.pointIdx
  588. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_CHALLENGE_END
  589. msgData.sourceServerId = Config.SVR_INDEX
  590. msgData.playerUuid = human.db._id
  591. msgData.myUnionId = human.db.unionUuid
  592. msgData.targetCityId = cityId
  593. msgData.targetPointIdx = pointIdx
  594. msgData.challengeRes = args.challengeRes
  595. -- 挑战没有胜利
  596. if args.challengeRes ~= CombatDefine.RESULT_WIN then
  597. -- 说明之前已经在跨服上保存玩家的基础数据了
  598. if human.db.anotherWorlBattle then
  599. return
  600. end
  601. msgData.playerShowInfo = {
  602. name = human.db.name,
  603. lv = human.db.lv,
  604. power = human.db.zhandouli,
  605. }
  606. return InnerMsg.sendMsg(0, msgData)
  607. end
  608. if not human.db.anotherWorlBattle then
  609. human.db.anotherWorlBattle = {
  610. startTime = os.time(),
  611. formation = {}
  612. }
  613. end
  614. -- 把当前战斗阵容数据保存到当前模块,作为防守阵容
  615. local combatData = CombatPosLogic.getCombatHeroDB(human, CombatDefine.COMBAT_TYPE35)
  616. local formationData = human.db.anotherWorlBattle.formation or {}
  617. formationData[cityId] = formationData[cityId] or {}
  618. formationData[cityId][pointIdx] = Util.copyTable(combatData)
  619. -- 把最新的防守英雄uuid列表推送给客户端
  620. sendDefHeroArr(human)
  621. --同步到跨服
  622. msgData.playerShowInfo = generateShowInfo(human)
  623. InnerMsg.sendMsg(0, msgData)
  624. -- 清空战斗阵容
  625. CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  626. end
  627. -- 更换据点的防守阵容
  628. function AB_Update_Lineup(human, msg)
  629. if not isBattleStage() then
  630. return Broadcast.sendErr(human, Lang.AB_NOT_BATTLE_TIME)
  631. end
  632. local anotherWorlBattle = human.db.anotherWorlBattle
  633. if not anotherWorlBattle or not anotherWorlBattle.formation then
  634. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  635. end
  636. local cityId = msg.cityId
  637. local pointIdx = msg.pointIdx
  638. local formationData = anotherWorlBattle.formation
  639. if not formationData[cityId] or not formationData[cityId][pointIdx] then
  640. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  641. end
  642. local res, heroList, helpList = CombatPosLogic.CheckUpdatePos(human, msg)
  643. if not res then
  644. return Broadcast.sendErr(human, Lang.COMBAT_POS__ERR)
  645. end
  646. local len = 0
  647. local heroArr = {}
  648. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  649. local uuid = heroList[i] or ""
  650. if uuid ~= "0" and uuid ~= "" then
  651. if isDefHero(human, uuid, cityId, pointIdx) then
  652. return Broadcast.sendErr(human, Lang.AB_HERO_IN_OTHER_POINT)
  653. end
  654. len = len + 1
  655. heroArr[len] = getHeroInfo(human, uuid)
  656. end
  657. end
  658. if len == 0 then
  659. return
  660. end
  661. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_POINT_LINEIP
  662. msgData.sourceServerId = Config.SVR_INDEX
  663. msgData.playerUuid = human.db._id
  664. msgData.heroArr = heroArr
  665. msgData.targetCityId = cityId
  666. msgData.targetPointIdx = pointIdx
  667. msgData.formation = msg.formation
  668. msgData.heroList = heroList
  669. msgData.helpList = helpList
  670. InnerMsg.sendMsg(0, msgData)
  671. end
  672. ------------------------------------C2N---------------------------------------------------
  673. -- 错误提示
  674. function C2N_ErrTips(msg)
  675. local human = ObjHuman.onlineUuid[msg.playerUuid]
  676. if not human then
  677. return
  678. end
  679. local tips = Lang.DATA_ERR
  680. local errCode = msg.errCode
  681. if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
  682. tips = Lang.AB_NOT_OPEN_TIME
  683. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
  684. tips = Lang.AB_NOT_UNION_NUM_EXCEED
  685. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
  686. tips = Lang.AB_UNION_NO_JOIN
  687. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
  688. tips = Lang.DATA_ERR
  689. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
  690. tips = Lang.AB_NOT_OCCUPY_POINT
  691. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
  692. tips = Lang.AB_GATHER_CD
  693. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
  694. tips = Lang.AB_CITY_NOT_ADDJION
  695. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
  696. tips = Lang.AB_JOINED
  697. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_9 then
  698. tips = Lang.AB_CITY_NO_GATHER
  699. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_10 then
  700. tips = Lang.AB_OCCUPY_POINT_MAX
  701. end
  702. Broadcast.sendErr(human, tips)
  703. end
  704. -- 跨服返回状态
  705. function C2N_State(msg)
  706. local human = ObjHuman.onlineUuid[msg.playerUuid]
  707. if not human then
  708. return
  709. end
  710. local msgRet = Msg.gc.GC_AB_GetState
  711. msgRet.joinState = msg.joinState
  712. msgRet.systemState = msg.systemState
  713. if msgRet.joinState == 0 then
  714. local unionId = human.db.unionUuid
  715. if not unionId then
  716. msgRet.Joinstate = 2
  717. return Msg.send(msgRet, human.fd)
  718. end
  719. -- 公会排名前二才行
  720. if not isTopTwoUnion(human) then
  721. msgRet.Joinstate = 2
  722. return Msg.send(msgRet, human.fd)
  723. end
  724. end
  725. Msg.send(msgRet, human.fd)
  726. end
  727. -- 报名成功
  728. function C2N_Join_Succ(msg)
  729. local now = os.time()
  730. local unionId = msg.myUnionId
  731. UnionLogic.UpdateJoinAbTime(unionId, now)
  732. local human = ObjHuman.onlineUuid[msg.playerUuid]
  733. if not human then
  734. return
  735. end
  736. local msgRet = Msg.gc.GC_AB_JOIN
  737. msgRet.Joinstate = 1
  738. Msg.send(msgRet, human.fd)
  739. end
  740. -- 跨服返回的所有城池数据
  741. function C2N_AllCity_Query(msg)
  742. local human = ObjHuman.onlineUuid[msg.playerUuid]
  743. if not human then
  744. return
  745. end
  746. local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
  747. msgRet.myBaseCityId = msg.myUnionBaseCityId
  748. msgRet.hasPointNum = msg.hasPointNum
  749. msgRet.challengeTimes = msg.challengeTimes
  750. local now = os.time()
  751. msgRet.leftTime = msg.lastTime
  752. if msgRet.leftTime ~= 0 then
  753. msgRet.leftTime = (msg.lastTime + AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC) - now
  754. end
  755. msgRet.cityArr[0] = 0
  756. local cityArrMsg = msgRet.cityArr
  757. for cityId, cityInfo in ipairs(msg.cityArr) do
  758. cityArrMsg[0] = cityId
  759. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  760. cityArrMsg[cityId].cityId = cityId
  761. cityArrMsg[cityId].cityName = cityCfg.cityName
  762. cityArrMsg[cityId].cityLv = cityCfg.cityLv
  763. cityArrMsg[cityId].occupyPointNum = cityInfo.occupyPointNum or 0
  764. cityArrMsg[cityId].occupyUnionName = cityInfo.occupyUnionName or ""
  765. cityArrMsg[cityId].cityState = cityInfo.cityState
  766. cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
  767. for i, cId in ipairs(cityCfg.adJoinCityArr) do
  768. cityArrMsg[cityId].adJoinCityArr[i] = cId
  769. end
  770. end
  771. msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
  772. for i, cityId in ipairs(msg.myOccupyCityArr) do
  773. msgRet.myOccupyCityArr[i] = cityId
  774. end
  775. Msg.send(msgRet, human.fd)
  776. end
  777. -- 跨服返回某个城池详细数据
  778. function C2N_CityDetailed_Query(msg)
  779. local human = ObjHuman.onlineUuid[msg.playerUuid]
  780. if not human then
  781. return
  782. end
  783. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  784. local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
  785. msgRet.cityId = msg.targetCityId
  786. msgRet.cityLv = cityCfg.cityLv
  787. msgRet.cityIconId = cityCfg.cityIconId
  788. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM )
  789. local myUnionAwardNum = calcPointAward(msg.myUnionOccupyArr)
  790. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  791. -- 活动没有进入战斗阶段时, 使用默认数据
  792. if #msg.pointArr == 0 then
  793. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  794. msg.pointArr[i] = {}
  795. end
  796. end
  797. msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  798. for pointIdx, pointInfo in ipairs(msg.pointArr) do
  799. if pointInfo.occupyUnionName then
  800. msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
  801. msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
  802. msgRet.pointArr[pointIdx].power = pointInfo.power
  803. msgRet.pointArr[pointIdx].state = pointInfo.state
  804. else
  805. msgRet.pointArr[pointIdx].occupyUnionName = ""
  806. msgRet.pointArr[pointIdx].occupyPlayerName = AnotherWorldBattleDefine.AB_DEF_NAME_STR.. pointIdx
  807. msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
  808. msgRet.pointArr[pointIdx].state = pointInfo.state
  809. end
  810. end
  811. msgRet.gatherState = msg.gatherState
  812. if msg.gatherState == 1 then
  813. -- 公会会长/副会长才能集结
  814. if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
  815. msgRet.gatherState = 0
  816. end
  817. end
  818. Msg.send(msgRet, human.fd)
  819. end
  820. -- 跨服返回某个据点数据
  821. function C2N_PointDetailed_Query(msg)
  822. local human = ObjHuman.onlineUuid[msg.playerUuid]
  823. if not human then
  824. return
  825. end
  826. local pointInfo = msg.pointInfo
  827. local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
  828. msgRet.state = pointInfo.state
  829. if pointInfo.name then
  830. msgRet.name = pointInfo.name
  831. msgRet.power = pointInfo.power
  832. msgRet.head = pointInfo.head
  833. msgRet.headFrame = pointInfo.headFrame
  834. msgRet.defLv = pointInfo.defLv
  835. msgRet.heroArr[0] = #pointInfo.heroArr
  836. for i, heroInfo in ipairs(pointInfo.heroArr) do
  837. msgRet.heroArr[i].heroBody = heroInfo.heroBody
  838. msgRet.heroArr[i].heroStar = heroInfo.heroStar
  839. msgRet.heroArr[i].heroLv = heroInfo.heroLv
  840. msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
  841. msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
  842. msgRet.heroArr[i].heroId = heroInfo.heroId
  843. msgRet.heroArr[i].heroQuality = heroInfo.heroQuality
  844. end
  845. else
  846. msgRet.name = AnotherWorldBattleDefine.AB_DEF_NAME_STR .. msg.targetPointIdx
  847. msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
  848. msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
  849. msgRet.defLv = 200
  850. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  851. msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
  852. msgRet.heroArr[0] = 0
  853. local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
  854. for idx, monsterInfo in ipairs(monsterOutConfig.member) do
  855. if idx > 6 then
  856. break
  857. end
  858. msgRet.heroArr[0] = idx
  859. local monsterID = monsterInfo[1]
  860. local mcf = MonsterExcel.monster[monsterID]
  861. msgRet.heroArr[idx].heroBody = mcf.body
  862. msgRet.heroArr[idx].heroStar = mcf.star
  863. msgRet.heroArr[idx].heroLv = monsterInfo[2]
  864. msgRet.heroArr[idx].heroCamp = mcf.camp
  865. msgRet.heroArr[idx].heroIcon = mcf.head
  866. msgRet.heroArr[idx].heroId = monsterID
  867. msgRet.heroArr[idx].heroQuality = mcf.heroQuality or 1
  868. end
  869. end
  870. Msg.send(msgRet, human.fd)
  871. end
  872. -- 跨服返回公会出生点数据
  873. function C2N_BaseCity_Query(msg)
  874. local human = ObjHuman.onlineUuid[msg.playerUuid]
  875. if not human then
  876. return
  877. end
  878. local baseCityInfo = msg.baseCityInfo
  879. local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
  880. local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
  881. msgRet.cityIconId = cityCfg.cityIconId
  882. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM)
  883. local myUnionAwardNum = calcPointAward(baseCityInfo.myUnionOccupyArr)
  884. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  885. msgRet.cityIconId = baseCityInfo.occupyPointNum
  886. msgRet.occupyPointNum = baseCityInfo.occupyPointNum
  887. msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
  888. msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
  889. msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
  890. msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
  891. Msg.send(msgRet, human.fd)
  892. end
  893. -- 跨服返回玩家占领的据点数据
  894. function C2N_PlayerOccupyPoint_Query(msg)
  895. local human = ObjHuman.onlineUuid[msg.playerUuid]
  896. if not human then
  897. return
  898. end
  899. local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
  900. local myPointArr = msgRet.myPointArr
  901. myPointArr[0] = 0
  902. for idx, pointInfo in ipairs(msg.occupyPointArr) do
  903. myPointArr[0] = idx
  904. local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
  905. myPointArr[idx].cityIconId = cityCfg.cityIconId
  906. myPointArr[idx].cityName = cityCfg.cityName
  907. myPointArr[idx].cityLv = cityCfg.cityLv
  908. myPointArr[idx].pointIdx = pointInfo.pointIdx
  909. myPointArr[idx].power = pointInfo.power
  910. myPointArr[idx].cityId = pointInfo.cityId
  911. myPointArr[idx].heroArr[0] = #pointInfo.heroArr
  912. for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
  913. local hero = myPointArr[idx].heroArr[heroIdx]
  914. hero.heroBody = heroInfo.heroBody
  915. hero.heroStar = heroInfo.heroStar
  916. hero.heroLv = heroInfo.heroLv
  917. hero.heroCamp = heroInfo.heroCamp
  918. hero.heroIcon = heroInfo.heroIcon
  919. hero.heroId = heroInfo.heroId
  920. hero.heroQuality = heroInfo.heroQuality
  921. end
  922. end
  923. Msg.send(msgRet, human.fd)
  924. end
  925. -- 跨服返回集结/取消集结成功
  926. function C2N_Gather_End(msg)
  927. local human = ObjHuman.onlineUuid[msg.playerUuid]
  928. if not human then
  929. return
  930. end
  931. local targetCityId = msg.targetCityId
  932. local cityCfg = AnotherWorldBattleConfig.city[targetCityId]
  933. local msgRet = Msg.gc.GC_AB_GARHER
  934. msgRet.cityId = targetCityId
  935. msgRet.cityName = cityCfg.cityName
  936. msgRet.opType = msg.opType
  937. Msg.send(msgRet, human.fd)
  938. end
  939. --跨服返回公会排行榜数据
  940. function C2N_UnionRank_Query(msg)
  941. local human = ObjHuman.onlineUuid[msg.playerUuid]
  942. if not human then
  943. return
  944. end
  945. local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
  946. msgRet.unionRankArr[0] = 0
  947. msgRet.myUnionRank = msg.myUnionRank
  948. msgRet.myData = { name = "", power = 0, cityNum = 0, pointNum = 0 }
  949. for rank, rankdData in ipairs(msg.unionRankArr) do
  950. msgRet.unionRankArr[0] = rank
  951. msgRet.unionRankArr[rank] = {
  952. name = rankdData.name,
  953. power = rankdData.power,
  954. cityNum = rankdData.cityNum,
  955. pointNum = rankdData.pointNum,
  956. }
  957. if rank == msg.myUnionRank then
  958. msgRet.myData.name = rankdData.name
  959. msgRet.myData.power = rankdData.power
  960. msgRet.myData.cityNum = rankdData.cityNum
  961. msgRet.myData.pointNum = rankdData.pointNum
  962. end
  963. end
  964. if msgRet.myData.power == 0 then
  965. local unionId = human.db.unionUuid
  966. local queryFiles = {name = 1, zhandouli = 1}
  967. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  968. msgRet.myData.name = unionInfo and unionInfo.name or ""
  969. msgRet.myData.power = unionInfo and unionInfo.zhandouli or 0
  970. end
  971. Msg.send(msgRet, human.fd)
  972. end
  973. --跨服返回玩家排行榜数据
  974. function C2N_PlayerRank_Query(msg)
  975. local human = ObjHuman.onlineUuid[msg.playerUuid]
  976. if not human then
  977. return
  978. end
  979. local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
  980. msgRet.playerRankArr[0] = 0
  981. msgRet.myRank = msg.myRank
  982. msgRet.myData = {
  983. name = human.db.name,
  984. power = human.db.zhandouli,
  985. pointNum = 0,
  986. pointWeight = 0,
  987. }
  988. for rank, rankdData in ipairs(msg.playerRankArr) do
  989. msgRet.playerRankArr[0] = rank
  990. msgRet.playerRankArr[rank] = {
  991. name = rankdData.name,
  992. power = rankdData.power,
  993. pointNum = rankdData.pointNum,
  994. pointWeight = rankdData.pointWeight,
  995. }
  996. if rank == msg.myRank then
  997. msgRet.myData.pointNum = rankdData.pointNum
  998. msgRet.myData.pointWeight = rankdData.pointWeight
  999. end
  1000. end
  1001. Msg.send(msgRet, human.fd)
  1002. end
  1003. -- 跨服返回要挑战的据点的数据(据点可以被挑战)
  1004. function C2N_Challenge_Point_OK(msg)
  1005. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1006. if not human then
  1007. return
  1008. end
  1009. local pointInfo = msg.pointInfo
  1010. human.AB_Battle_Cache = {
  1011. isGather = pointInfo.isGather,
  1012. cityId = pointInfo.targetCityId,
  1013. pointIdx = pointInfo.targetPointIdx,
  1014. }
  1015. if pointInfo.occupySrvId then -- 玩家占领
  1016. local args = {
  1017. combatType = CombatDefine.COMBAT_TYPE35,
  1018. nServerIndex = pointInfo.occupySrvId,
  1019. param = pointInfo.occupyPlayerUuid,
  1020. extraArgs = {
  1021. cityId = pointInfo.targetCityId,
  1022. pointIdx = pointInfo.targetPointIdx,
  1023. useDef = true,
  1024. }
  1025. }
  1026. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
  1027. else
  1028. -- 机器人
  1029. CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
  1030. end
  1031. end
  1032. -- 跨服通知据点被别的玩家占领了
  1033. function C2N_Point_Lose(msg)
  1034. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1035. if not human then
  1036. local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
  1037. if not db then
  1038. return
  1039. end
  1040. human = {}
  1041. human.db = db
  1042. end
  1043. -- 更新防守阵容数据
  1044. local loseCityId = msg.loseCityId
  1045. local losePointIdx = msg.losePointIdx
  1046. local formationData = human.db.anotherWorlBattle.formation
  1047. formationData[loseCityId][losePointIdx] = nil
  1048. -- 玩家不在线, 手动保存数据
  1049. if not human.fd then
  1050. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1051. end
  1052. -- 发邮件
  1053. local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
  1054. local content = Util.format(mailCfg.content, losePointIdx)
  1055. MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, content, nil, mailCfg.senderName or "GM")
  1056. -- 把最新的防守阵容数据推给客户端
  1057. if human.fd then
  1058. sendDefHeroArr(human)
  1059. end
  1060. end
  1061. -- 跨服通知可以更换据点的防守阵容数据
  1062. function C2N_Update_Point_Lineup(msg)
  1063. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1064. if not human then
  1065. local db = RoleDBLogic.getDb(msg.playerUuid)
  1066. if not db then
  1067. return
  1068. end
  1069. human = {}
  1070. human.db = db
  1071. end
  1072. local anotherWorlBattle = human.db.anotherWorlBattle
  1073. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1074. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  1075. end
  1076. local cityId = msg.targetCityId
  1077. local pointIdx = msg.targetPointIdx
  1078. if not anotherWorlBattle.formation[cityId] or not anotherWorlBattle.formation[cityId][pointIdx] then
  1079. return
  1080. end
  1081. local pointLinupData = anotherWorlBattle.formation[cityId][pointIdx]
  1082. pointLinupData.list = msg.heroList
  1083. pointLinupData.helpList = msg.helpList
  1084. pointLinupData.formation = msg.formation
  1085. if not human.fd then
  1086. ObjHuman.save(human)
  1087. end
  1088. sendDefHeroArr(human)
  1089. Broadcast.sendCenter(human, Lang.AB_UPDATE_LINEUP_SUCC)
  1090. end
  1091. -- 跨服通知给玩家发奖
  1092. function C2N_IssueReward(msg)
  1093. -- 删除公会参加异界之战活动时间
  1094. UnionLogic.UpdateJoinAbTime(msg.unionId, nil)
  1095. -- 发奖
  1096. local awardObjArr, occupyCityInfo = genAwardObjArr(msg.unionOccupyInfo)
  1097. if awardObjArr then
  1098. local issueRewardQueue = createRewardQueue()
  1099. issueRewardQueue.extraInfo = occupyCityInfo
  1100. for _, obj in ipairs(awardObjArr) do
  1101. issueRewardQueue:add(obj)
  1102. end
  1103. issueRewardQueue:insertDB()
  1104. end
  1105. end
  1106. -------------------------------------------战斗---------------------------------
  1107. function getCombatMonsterOutID(human, side, args)
  1108. if side ~= CombatDefine.DEFEND_SIDE then return end
  1109. local cityId = args[2]
  1110. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1111. return cityCfg.pointMonsterId
  1112. end
  1113. function getCombatObjList(human, side, args, combatType, extraArgs)
  1114. if side == CombatDefine.ATTACK_SIDE and not human then return end
  1115. if side == CombatDefine.DEFEND_SIDE and human then
  1116. return
  1117. end
  1118. if not human then
  1119. local uuid = args[1]
  1120. local db = RoleDBLogic.getDb(uuid)
  1121. if not db then
  1122. return
  1123. end
  1124. human = {}
  1125. human.db = db
  1126. end
  1127. return CombatLogic.getHumanObjList(human, combatType, extraArgs)
  1128. end
  1129. function getCombatHeros(human, combatType, args)
  1130. if not human.db.anotherWorlBattle then
  1131. return
  1132. end
  1133. local formation = human.db.anotherWorlBattle.formation
  1134. if not formation then
  1135. return
  1136. end
  1137. local cityId, pointIdx = args.cityId, args.pointIdx
  1138. if formation[cityId] and formation[cityId][pointIdx] then
  1139. local combatHeroDB = formation[cityId][pointIdx]
  1140. return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
  1141. end
  1142. end
  1143. function onFightBegin(human, cbParam, combatType, param)
  1144. if not human.AB_Battle_Cache or human.AB_Battle_Cache.isGather ~= 1 then
  1145. return
  1146. end
  1147. local gatherAttrs = AnotherWorldBattleConfig.var[1].gatherAttrs
  1148. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  1149. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  1150. local atkObj = CombatImpl.objList[atkPos]
  1151. if atkObj then
  1152. for _, atrrTb in ipairs(gatherAttrs) do
  1153. local attrId, attrVal = atrrTb[1], atrrTb[2]
  1154. atkObj.sysAttr[attrId] = (atkObj.sysAttr[attrId] or 0) + attrVal
  1155. end
  1156. atkObj.isSysAttrChange = true
  1157. end
  1158. end
  1159. end
  1160. function onFightEnd(human, result, type, cbParam, combatInfo)
  1161. -- if result == CombatDefine.RESULT_WIN then
  1162. -- challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
  1163. -- end
  1164. local args = {
  1165. cityId = human.AB_Battle_Cache.cityId,
  1166. pointIdx = human.AB_Battle_Cache.pointIdx,
  1167. challengeRes = result
  1168. }
  1169. human.AB_Battle_Cache = nil
  1170. challenge_End(human, args)
  1171. end