AnotherWorldBattleNS.lua 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  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] or 0) - (timeTb[1] or 0)
  291. if sec > 0 then
  292. minuteVal = minuteVal + sec
  293. end
  294. end
  295. return math.floor(minuteVal / 60)
  296. end
  297. -- 没有玩家参与
  298. if not unionOccupyInfo.playerUuidArr or #unionOccupyInfo.playerUuidArr <= 0 then
  299. return
  300. end
  301. local itemList = {}
  302. local occupyCityInfo = {0,0,0,0,0}
  303. local item_185_Id = 185
  304. local item_185_Num = 0
  305. occupyCityInfo[1] = unionOccupyInfo.occuoyPointNum
  306. -- 额外奖励
  307. item_185_Num = item_185_Num + (unionOccupyInfo.occuoyPointNum or 0)
  308. for _, cityId in ipairs(unionOccupyInfo.occupyCityArr) do
  309. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  310. if cityCfg then
  311. if cityCfg.isBaseCity == 1 then
  312. item_185_Num = item_185_Num + 20
  313. else
  314. if cityCfg.cityLv == 2 then
  315. item_185_Num = item_185_Num + 2
  316. occupyCityInfo[2] = occupyCityInfo[2] + 1
  317. elseif cityCfg.cityLv == 3 then
  318. item_185_Num = item_185_Num + 3
  319. occupyCityInfo[3] = occupyCityInfo[3] + 1
  320. elseif cityCfg.cityLv == 4 then
  321. item_185_Num = item_185_Num + 5
  322. occupyCityInfo[4] = occupyCityInfo[4] + 1
  323. elseif cityCfg.cityLv == 5 then
  324. item_185_Num = item_185_Num + 20
  325. occupyCityInfo[5] = occupyCityInfo[5] + 1
  326. end
  327. end
  328. end
  329. end
  330. -- 占领据点每分钟的奖励
  331. for _, pointInfo in ipairs(unionOccupyInfo.point2CityIdArr) do
  332. local cityId = pointInfo[1]
  333. local occupyTimeArr = pointInfo[2]
  334. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  335. local totalMinVal = calcMinute(occupyTimeArr)
  336. if totalMinVal > 0 then
  337. local itemId, itemNum = cityCfg.cityAward[1], cityCfg.cityAward[2]
  338. itemList[itemId] = (itemList[itemId] or 0) + totalMinVal * itemNum
  339. end
  340. end
  341. if item_185_Num > 0 then
  342. itemList[item_185_Id] = item_185_Num
  343. end
  344. local itemArr = {}
  345. for itemId, itemNum in pairs(itemList) do
  346. itemArr[#itemArr+1] = { itemId, itemNum }
  347. end
  348. local awardObjArr = {}
  349. for _, playerUuid in ipairs(unionOccupyInfo.playerUuidArr) do
  350. awardObjArr[#awardObjArr+1] = {playerUuid, itemArr}
  351. end
  352. return awardObjArr, occupyCityInfo
  353. end
  354. -- 活动是否处于开启中
  355. function IsRuning(joinTime)
  356. local wDay = getWDay()
  357. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  358. return false
  359. end
  360. local diffDays = Util.diffDay(joinTime)
  361. -- 活动最后一天, 如果当前时间 > 结束时间则标识活动结束
  362. if diffDays == 5 then
  363. local now = os.time()
  364. local toDayStartTime = Util.getDayStartTime(now)
  365. if now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  366. return false
  367. end
  368. end
  369. -- < 5天说明处于本轮活动的开启时间
  370. if diffDays > 5 then
  371. return false
  372. end
  373. return true
  374. end
  375. --检测上阵英雄
  376. function checkUpdatePos(human, msg)
  377. local heroList = Util.split(msg.heroList, ",")
  378. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  379. local uuid = heroList[i] or ""
  380. if uuid ~= "0" and uuid ~= "" then
  381. if isDefHero(human, uuid) then
  382. return false
  383. end
  384. end
  385. end
  386. return true
  387. end
  388. -- 公会战力更新
  389. function UnionPowerChange(unionId, newPower)
  390. if not isBattleStage() then
  391. return
  392. end
  393. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  394. msgData.myUnionId = unionId
  395. msgData.updateData = {}
  396. msgData.updateData.power = newPower
  397. InnerMsg.sendMsg(0, msgData)
  398. end
  399. -- 玩家战力更新
  400. function PlayerPowerChange(human)
  401. if not isBattleStage() then
  402. return
  403. end
  404. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  405. msgData.playerUuid = human.db._id
  406. msgData.myUnionId = human.db.unionUuid
  407. msgData.updateData = {}
  408. msgData.updateData.power = human.db.zhandouli
  409. InnerMsg.sendMsg(0, msgData)
  410. end
  411. function isOpen(human)
  412. return RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1306) -- 待改
  413. end
  414. function onLogin(human)
  415. formationDataCheeck(human)
  416. sendDefHeroArr(human)
  417. end
  418. -- 请求状态
  419. function AB_GetState(human)
  420. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_STATE
  421. msgData.sourceServerId = Config.SVR_INDEX
  422. msgData.playerUuid = human.db._id
  423. msgData.myUnionId = human.db.unionUuid or ""
  424. InnerMsg.sendMsg(0, msgData)
  425. end
  426. -- 报名
  427. function AB_Join(human)
  428. local unionId = human.db.unionUuid
  429. local msgRet = Msg.gc.GC_AB_JOIN
  430. if not unionId then
  431. msgRet.Joinstate = 3
  432. return Msg.send(msgRet, human.fd)
  433. end
  434. -- if not isOpen(human) then
  435. -- return Broadcast.sendErr(human, Lang.AB_JOIN_COND_NOT_SATIFY)
  436. -- end
  437. local wDay = getWDay()
  438. -- if not table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  439. -- msgRet.Joinstate = 5
  440. -- return Msg.send(msgRet, human.fd)
  441. -- end
  442. if wDay ~= AnotherWorldBattleDefine.AB_JOIN_WDAY then
  443. msgRet.Joinstate = 5
  444. return Msg.send(msgRet, human.fd)
  445. end
  446. -- 公会排名前二才能参加
  447. if not isTopTwoUnion(human) then
  448. msgRet.Joinstate = 2
  449. return Msg.send(msgRet, human.fd)
  450. end
  451. -- 会长/副会长才能报名
  452. if not UnionLogic.IsTopTwoManager(human, unionId) then
  453. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  454. end
  455. local queryFiles = {name = 1, zhandouli = 1}
  456. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  457. if not unionInfo then
  458. return Broadcast.sendErr(human, Lang.DATA_ERR)
  459. end
  460. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_JOIN
  461. msgData.sourceServerId = Config.SVR_INDEX
  462. msgData.playerUuid = human.db._id
  463. msgData.unionInfo = {
  464. name = unionInfo.name,
  465. power = unionInfo.zhandouli,
  466. unionId = unionId
  467. }
  468. InnerMsg.sendMsg(0, msgData)
  469. end
  470. -- 查询所有城池信息
  471. function AB_AllCity_Query(human)
  472. if not human.db.unionUuid then
  473. return
  474. end
  475. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  476. msgData.sourceServerId = Config.SVR_INDEX
  477. msgData.playerUuid = human.db._id
  478. msgData.myUnionId = human.db.unionUuid
  479. InnerMsg.sendMsg(0, msgData)
  480. -- 报名状态查询
  481. -- local msgData2 = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_JOIN_STATE
  482. -- msgData2.sourceServerId = Config.SVR_INDEX
  483. -- msgData2.playerUuid = human.db._id
  484. -- msgData2.myUnionId = human.db.unionUuid
  485. -- InnerMsg.sendMsg(0, msgData2)
  486. end
  487. -- 查询单个城池的详细信息
  488. function AB_CityDetailed_Query(human, targetCityId)
  489. if not AnotherWorldBattleConfig.city[targetCityId] then
  490. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  491. end
  492. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  493. msgData.sourceServerId = Config.SVR_INDEX
  494. msgData.playerUuid = human.db._id
  495. msgData.myUnionId = human.db.unionUuid
  496. msgData.targetCityId = targetCityId
  497. InnerMsg.sendMsg(0, msgData)
  498. end
  499. -- 查询某个城池的某个据点的详细信息
  500. function AB_PointDetailed_Query(human, targetCityId, targetPointIdx)
  501. if not AnotherWorldBattleConfig.city[targetCityId] then
  502. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  503. end
  504. if 0 >= targetPointIdx or AnotherWorldBattleDefine.AB_POINT_MAX_NUM < targetPointIdx then
  505. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  506. end
  507. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINTtDETAILED_QUERY
  508. msgData.sourceServerId = Config.SVR_INDEX
  509. msgData.playerUuid = human.db._id
  510. msgData.myUnionId = human.db.unionUuid
  511. msgData.targetCityId = targetCityId
  512. msgData.targetPointIdx = targetPointIdx
  513. InnerMsg.sendMsg(0, msgData)
  514. end
  515. -- 查询本公会出生点信息
  516. function AB_BaseCity_Query(human)
  517. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_BASECITY_QUERY
  518. msgData.sourceServerId = Config.SVR_INDEX
  519. msgData.playerUuid = human.db._id
  520. msgData.myUnionId = human.db.unionUuid
  521. InnerMsg.sendMsg(0, msgData)
  522. end
  523. -- 查询玩家占领的所有据点信息
  524. function AB_PlayerOccupyPOint_Query(human)
  525. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  526. msgData.sourceServerId = Config.SVR_INDEX
  527. msgData.playerUuid = human.db._id
  528. msgData.myUnionId = human.db.unionUuid
  529. InnerMsg.sendMsg(0, msgData)
  530. end
  531. -- 查询公会排行榜
  532. function AB_UnionRank_Query(human)
  533. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  534. msgData.sourceServerId = Config.SVR_INDEX
  535. msgData.playerUuid = human.db._id
  536. msgData.myUnionId = human.db.unionUuid
  537. InnerMsg.sendMsg(0, msgData)
  538. end
  539. -- 查询玩家排行榜
  540. function AB_PlayerRank_Query(human)
  541. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  542. msgData.sourceServerId = Config.SVR_INDEX
  543. msgData.playerUuid = human.db._id
  544. msgData.myUnionId = human.db.unionUuid
  545. InnerMsg.sendMsg(0, msgData)
  546. end
  547. -- 发起集结
  548. function AB_Gather(human, targetCityId, opType)
  549. if not AnotherWorldBattleConfig.city[targetCityId] then
  550. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  551. end
  552. if opType ~= 1 and opType ~= 2 then
  553. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  554. end
  555. local unionId = human.db.unionUuid
  556. if not unionId then
  557. return Broadcast.sendErr(human, Lang.AB_NO_UNION)
  558. end
  559. -- 会长/副会长才能集结
  560. if not UnionLogic.IsTopTwoManager(human, unionId) then
  561. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANAGER)
  562. end
  563. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GATHER
  564. msgData.sourceServerId = Config.SVR_INDEX
  565. msgData.playerUuid = human.db._id
  566. msgData.myUnionId = human.db.unionUuid
  567. msgData.targetCityId = targetCityId
  568. msgData.opType = opType
  569. InnerMsg.sendMsg(0, msgData)
  570. end
  571. -- 请求挑战某个据点
  572. function AB_Try_Challenge_Point(human, targetCityId, targetPointIdx)
  573. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  574. if not combatHero or not next(combatHero) then
  575. return Broadcast.sendErr(human, Lang.COMBAT_NEED_FIGHT_HERO)
  576. end
  577. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  578. msgData.sourceServerId = Config.SVR_INDEX
  579. msgData.playerUuid = human.db._id
  580. msgData.myUnionId = human.db.unionUuid
  581. msgData.targetCityId = targetCityId
  582. msgData.targetPointIdx = targetPointIdx
  583. InnerMsg.sendMsg(0, msgData)
  584. end
  585. -- 战斗结束
  586. local function challenge_End(human, args)
  587. local cityId = args.cityId
  588. local pointIdx = args.pointIdx
  589. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_CHALLENGE_END
  590. msgData.sourceServerId = Config.SVR_INDEX
  591. msgData.playerUuid = human.db._id
  592. msgData.myUnionId = human.db.unionUuid
  593. msgData.targetCityId = cityId
  594. msgData.targetPointIdx = pointIdx
  595. msgData.challengeRes = args.challengeRes
  596. -- 挑战没有胜利
  597. if args.challengeRes ~= CombatDefine.RESULT_WIN then
  598. -- 说明之前已经在跨服上保存玩家的基础数据了
  599. -- if human.db.anotherWorlBattle then
  600. -- return
  601. -- end
  602. msgData.playerShowInfo = {
  603. name = human.db.name,
  604. lv = human.db.lv,
  605. power = human.db.zhandouli,
  606. }
  607. return InnerMsg.sendMsg(0, msgData)
  608. end
  609. if not human.db.anotherWorlBattle then
  610. human.db.anotherWorlBattle = {
  611. startTime = os.time(),
  612. formation = {}
  613. }
  614. end
  615. -- 把当前战斗阵容数据保存到当前模块,作为防守阵容
  616. local combatData = CombatPosLogic.getCombatHeroDB(human, CombatDefine.COMBAT_TYPE35)
  617. local formationData = human.db.anotherWorlBattle.formation or {}
  618. formationData[cityId] = formationData[cityId] or {}
  619. formationData[cityId][pointIdx] = Util.copyTable(combatData)
  620. -- 把最新的防守英雄uuid列表推送给客户端
  621. sendDefHeroArr(human)
  622. --同步到跨服
  623. msgData.playerShowInfo = generateShowInfo(human)
  624. InnerMsg.sendMsg(0, msgData)
  625. -- 清空战斗阵容
  626. CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  627. end
  628. -- 更换据点的防守阵容
  629. function AB_Update_Lineup(human, msg)
  630. if not isBattleStage() then
  631. return Broadcast.sendErr(human, Lang.AB_NOT_BATTLE_TIME)
  632. end
  633. local anotherWorlBattle = human.db.anotherWorlBattle
  634. if not anotherWorlBattle or not anotherWorlBattle.formation then
  635. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  636. end
  637. local cityId = msg.cityId
  638. local pointIdx = msg.pointIdx
  639. local formationData = anotherWorlBattle.formation
  640. if not formationData[cityId] or not formationData[cityId][pointIdx] then
  641. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  642. end
  643. local res, heroList, helpList = CombatPosLogic.CheckUpdatePos(human, msg)
  644. if not res then
  645. return Broadcast.sendErr(human, Lang.COMBAT_POS__ERR)
  646. end
  647. local len = 0
  648. local heroArr = {}
  649. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  650. local uuid = heroList[i] or ""
  651. if uuid ~= "0" and uuid ~= "" then
  652. if isDefHero(human, uuid, cityId, pointIdx) then
  653. return Broadcast.sendErr(human, Lang.AB_HERO_IN_OTHER_POINT)
  654. end
  655. len = len + 1
  656. heroArr[len] = getHeroInfo(human, uuid)
  657. end
  658. end
  659. if len == 0 then
  660. return
  661. end
  662. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_POINT_LINEIP
  663. msgData.sourceServerId = Config.SVR_INDEX
  664. msgData.playerUuid = human.db._id
  665. msgData.heroArr = heroArr
  666. msgData.targetCityId = cityId
  667. msgData.targetPointIdx = pointIdx
  668. msgData.formation = msg.formation
  669. msgData.heroList = heroList
  670. msgData.helpList = helpList
  671. InnerMsg.sendMsg(0, msgData)
  672. end
  673. ------------------------------------C2N---------------------------------------------------
  674. -- 错误提示
  675. function C2N_ErrTips(msg)
  676. local human = ObjHuman.onlineUuid[msg.playerUuid]
  677. if not human then
  678. return
  679. end
  680. local tips = Lang.DATA_ERR
  681. local errCode = msg.errCode
  682. if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
  683. tips = Lang.AB_NOT_OPEN_TIME
  684. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
  685. tips = Lang.AB_NOT_UNION_NUM_EXCEED
  686. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
  687. tips = Lang.AB_UNION_NO_JOIN
  688. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
  689. tips = Lang.DATA_ERR
  690. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
  691. tips = Lang.AB_NOT_OCCUPY_POINT
  692. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
  693. tips = Lang.AB_GATHER_CD
  694. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
  695. tips = Lang.AB_CITY_NOT_ADDJION
  696. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
  697. tips = Lang.AB_JOINED
  698. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_9 then
  699. tips = Lang.AB_CITY_NO_GATHER
  700. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_10 then
  701. tips = Lang.AB_OCCUPY_POINT_MAX
  702. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_11 then
  703. tips = Lang.AB_POINT_CHALLENGING
  704. end
  705. Broadcast.sendErr(human, tips)
  706. end
  707. -- 跨服返回状态
  708. function C2N_State(msg)
  709. local human = ObjHuman.onlineUuid[msg.playerUuid]
  710. if not human then
  711. return
  712. end
  713. local msgRet = Msg.gc.GC_AB_GetState
  714. msgRet.joinState = msg.joinState
  715. msgRet.systemState = msg.systemState
  716. if msgRet.joinState == 0 then
  717. local unionId = human.db.unionUuid
  718. if not unionId then
  719. msgRet.Joinstate = 2
  720. return Msg.send(msgRet, human.fd)
  721. end
  722. -- 公会排名前二才行
  723. if not isTopTwoUnion(human) then
  724. msgRet.Joinstate = 2
  725. return Msg.send(msgRet, human.fd)
  726. end
  727. end
  728. Msg.send(msgRet, human.fd)
  729. end
  730. -- 报名成功
  731. function C2N_Join_Succ(msg)
  732. local now = os.time()
  733. local unionId = msg.myUnionId
  734. UnionLogic.UpdateJoinAbTime(unionId, now)
  735. local human = ObjHuman.onlineUuid[msg.playerUuid]
  736. if not human then
  737. return
  738. end
  739. local msgRet = Msg.gc.GC_AB_JOIN
  740. msgRet.Joinstate = 1
  741. Msg.send(msgRet, human.fd)
  742. end
  743. -- 跨服返回的所有城池数据
  744. function C2N_AllCity_Query(msg)
  745. local human = ObjHuman.onlineUuid[msg.playerUuid]
  746. if not human then
  747. return
  748. end
  749. local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
  750. msgRet.myBaseCityId = msg.myUnionBaseCityId
  751. msgRet.hasPointNum = msg.hasPointNum
  752. msgRet.challengeTimes = msg.challengeTimes
  753. local now = os.time()
  754. msgRet.leftTime = msg.lastTime
  755. if msgRet.leftTime ~= 0 then
  756. msgRet.leftTime = (msg.lastTime + AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC) - now
  757. end
  758. msgRet.cityArr[0] = 0
  759. local cityArrMsg = msgRet.cityArr
  760. for cityId, cityInfo in ipairs(msg.cityArr) do
  761. cityArrMsg[0] = cityId
  762. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  763. cityArrMsg[cityId].cityId = cityId
  764. cityArrMsg[cityId].cityName = cityCfg.cityName
  765. cityArrMsg[cityId].cityLv = cityCfg.cityLv
  766. cityArrMsg[cityId].occupyPointNum = cityInfo.occupyPointNum or 0
  767. cityArrMsg[cityId].occupyUnionName = cityInfo.occupyUnionName or ""
  768. cityArrMsg[cityId].cityState = cityInfo.cityState
  769. cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
  770. for i, cId in ipairs(cityCfg.adJoinCityArr) do
  771. cityArrMsg[cityId].adJoinCityArr[i] = cId
  772. end
  773. end
  774. msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
  775. for i, cityId in ipairs(msg.myOccupyCityArr) do
  776. msgRet.myOccupyCityArr[i] = cityId
  777. end
  778. Msg.send(msgRet, human.fd)
  779. end
  780. -- 跨服返回某个城池详细数据
  781. function C2N_CityDetailed_Query(msg)
  782. local human = ObjHuman.onlineUuid[msg.playerUuid]
  783. if not human then
  784. return
  785. end
  786. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  787. local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
  788. msgRet.cityId = msg.targetCityId
  789. msgRet.cityLv = cityCfg.cityLv
  790. msgRet.cityIconId = cityCfg.cityIconId
  791. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM )
  792. local myUnionAwardNum = calcPointAward(msg.myUnionOccupyArr)
  793. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  794. -- 活动没有进入战斗阶段时, 使用默认数据
  795. if #msg.pointArr == 0 then
  796. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  797. msg.pointArr[i] = {}
  798. end
  799. end
  800. msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  801. for pointIdx, pointInfo in ipairs(msg.pointArr) do
  802. if pointInfo.occupyUnionName then
  803. msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
  804. msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
  805. msgRet.pointArr[pointIdx].power = pointInfo.power
  806. msgRet.pointArr[pointIdx].state = pointInfo.state
  807. else
  808. msgRet.pointArr[pointIdx].occupyUnionName = ""
  809. msgRet.pointArr[pointIdx].occupyPlayerName = AnotherWorldBattleDefine.AB_DEF_NAME_STR.. pointIdx
  810. msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
  811. msgRet.pointArr[pointIdx].state = pointInfo.state
  812. end
  813. end
  814. msgRet.gatherState = msg.gatherState
  815. if msg.gatherState == 1 then
  816. -- 公会会长/副会长才能集结
  817. if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
  818. msgRet.gatherState = 0
  819. end
  820. end
  821. Msg.send(msgRet, human.fd)
  822. end
  823. -- 跨服返回某个据点数据
  824. function C2N_PointDetailed_Query(msg)
  825. local human = ObjHuman.onlineUuid[msg.playerUuid]
  826. if not human then
  827. return
  828. end
  829. local pointInfo = msg.pointInfo
  830. local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
  831. msgRet.state = pointInfo.state
  832. if pointInfo.name then
  833. msgRet.name = pointInfo.name
  834. msgRet.power = pointInfo.power
  835. msgRet.head = pointInfo.head
  836. msgRet.headFrame = pointInfo.headFrame
  837. msgRet.defLv = pointInfo.defLv
  838. msgRet.heroArr[0] = #pointInfo.heroArr
  839. for i, heroInfo in ipairs(pointInfo.heroArr) do
  840. msgRet.heroArr[i].heroBody = heroInfo.heroBody
  841. msgRet.heroArr[i].heroStar = heroInfo.heroStar
  842. msgRet.heroArr[i].heroLv = heroInfo.heroLv
  843. msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
  844. msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
  845. msgRet.heroArr[i].heroId = heroInfo.heroId
  846. msgRet.heroArr[i].heroQuality = heroInfo.heroQuality
  847. end
  848. else
  849. msgRet.name = AnotherWorldBattleDefine.AB_DEF_NAME_STR .. msg.targetPointIdx
  850. msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
  851. msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
  852. msgRet.defLv = 200
  853. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  854. msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
  855. msgRet.heroArr[0] = 0
  856. local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
  857. for idx, monsterInfo in ipairs(monsterOutConfig.member) do
  858. if idx > 6 then
  859. break
  860. end
  861. msgRet.heroArr[0] = idx
  862. local monsterID = monsterInfo[1]
  863. local mcf = MonsterExcel.monster[monsterID]
  864. msgRet.heroArr[idx].heroBody = mcf.body
  865. msgRet.heroArr[idx].heroStar = mcf.star
  866. msgRet.heroArr[idx].heroLv = monsterInfo[2]
  867. msgRet.heroArr[idx].heroCamp = mcf.camp
  868. msgRet.heroArr[idx].heroIcon = mcf.head
  869. msgRet.heroArr[idx].heroId = monsterID
  870. msgRet.heroArr[idx].heroQuality = mcf.heroQuality or 1
  871. end
  872. end
  873. Msg.send(msgRet, human.fd)
  874. end
  875. -- 跨服返回公会出生点数据
  876. function C2N_BaseCity_Query(msg)
  877. local human = ObjHuman.onlineUuid[msg.playerUuid]
  878. if not human then
  879. return
  880. end
  881. local baseCityInfo = msg.baseCityInfo
  882. local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
  883. local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
  884. msgRet.cityIconId = cityCfg.cityIconId
  885. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM)
  886. local myUnionAwardNum = calcPointAward(baseCityInfo.myUnionOccupyArr)
  887. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  888. msgRet.cityIconId = baseCityInfo.occupyPointNum
  889. msgRet.occupyPointNum = baseCityInfo.occupyPointNum
  890. msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
  891. msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
  892. msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
  893. msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
  894. Msg.send(msgRet, human.fd)
  895. end
  896. -- 跨服返回玩家占领的据点数据
  897. function C2N_PlayerOccupyPoint_Query(msg)
  898. local human = ObjHuman.onlineUuid[msg.playerUuid]
  899. if not human then
  900. return
  901. end
  902. local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
  903. local myPointArr = msgRet.myPointArr
  904. myPointArr[0] = 0
  905. for idx, pointInfo in ipairs(msg.occupyPointArr) do
  906. myPointArr[0] = idx
  907. local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
  908. myPointArr[idx].cityIconId = cityCfg.cityIconId
  909. myPointArr[idx].cityName = cityCfg.cityName
  910. myPointArr[idx].cityLv = cityCfg.cityLv
  911. myPointArr[idx].pointIdx = pointInfo.pointIdx
  912. myPointArr[idx].power = pointInfo.power
  913. myPointArr[idx].cityId = pointInfo.cityId
  914. myPointArr[idx].heroArr[0] = #pointInfo.heroArr
  915. for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
  916. local hero = myPointArr[idx].heroArr[heroIdx]
  917. hero.heroBody = heroInfo.heroBody
  918. hero.heroStar = heroInfo.heroStar
  919. hero.heroLv = heroInfo.heroLv
  920. hero.heroCamp = heroInfo.heroCamp
  921. hero.heroIcon = heroInfo.heroIcon
  922. hero.heroId = heroInfo.heroId
  923. hero.heroQuality = heroInfo.heroQuality
  924. end
  925. end
  926. Msg.send(msgRet, human.fd)
  927. end
  928. -- 跨服返回集结/取消集结成功
  929. function C2N_Gather_End(msg)
  930. local human = ObjHuman.onlineUuid[msg.playerUuid]
  931. if not human then
  932. return
  933. end
  934. local targetCityId = msg.targetCityId
  935. local cityCfg = AnotherWorldBattleConfig.city[targetCityId]
  936. local msgRet = Msg.gc.GC_AB_GARHER
  937. msgRet.cityId = targetCityId
  938. msgRet.cityName = cityCfg.cityName
  939. msgRet.opType = msg.opType
  940. Msg.send(msgRet, human.fd)
  941. end
  942. --跨服返回公会排行榜数据
  943. function C2N_UnionRank_Query(msg)
  944. local human = ObjHuman.onlineUuid[msg.playerUuid]
  945. if not human then
  946. return
  947. end
  948. local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
  949. msgRet.unionRankArr[0] = 0
  950. msgRet.myUnionRank = msg.myUnionRank
  951. msgRet.myData = { name = "", power = 0, cityNum = 0, pointNum = 0 }
  952. for rank, rankdData in ipairs(msg.unionRankArr) do
  953. msgRet.unionRankArr[0] = rank
  954. msgRet.unionRankArr[rank] = {
  955. name = rankdData.name,
  956. power = rankdData.power,
  957. cityNum = rankdData.cityNum,
  958. pointNum = rankdData.pointNum,
  959. }
  960. if rank == msg.myUnionRank then
  961. msgRet.myData.name = rankdData.name
  962. msgRet.myData.power = rankdData.power
  963. msgRet.myData.cityNum = rankdData.cityNum
  964. msgRet.myData.pointNum = rankdData.pointNum
  965. end
  966. end
  967. if msgRet.myData.power == 0 then
  968. local unionId = human.db.unionUuid
  969. local queryFiles = {name = 1, zhandouli = 1}
  970. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  971. msgRet.myData.name = unionInfo and unionInfo.name or ""
  972. msgRet.myData.power = unionInfo and unionInfo.zhandouli or 0
  973. end
  974. Msg.send(msgRet, human.fd)
  975. end
  976. --跨服返回玩家排行榜数据
  977. function C2N_PlayerRank_Query(msg)
  978. local human = ObjHuman.onlineUuid[msg.playerUuid]
  979. if not human then
  980. return
  981. end
  982. local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
  983. msgRet.playerRankArr[0] = 0
  984. msgRet.myRank = msg.myRank
  985. msgRet.myData = {
  986. name = human.db.name,
  987. power = human.db.zhandouli,
  988. pointNum = 0,
  989. pointWeight = 0,
  990. }
  991. for rank, rankdData in ipairs(msg.playerRankArr) do
  992. msgRet.playerRankArr[0] = rank
  993. msgRet.playerRankArr[rank] = {
  994. name = rankdData.name,
  995. power = rankdData.power,
  996. pointNum = rankdData.pointNum,
  997. pointWeight = rankdData.pointWeight,
  998. }
  999. if rank == msg.myRank then
  1000. msgRet.myData.pointNum = rankdData.pointNum
  1001. msgRet.myData.pointWeight = rankdData.pointWeight
  1002. end
  1003. end
  1004. Msg.send(msgRet, human.fd)
  1005. end
  1006. -- 跨服返回要挑战的据点的数据(据点可以被挑战)
  1007. function C2N_Challenge_Point_OK(msg)
  1008. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1009. if not human then
  1010. return
  1011. end
  1012. local pointInfo = msg.pointInfo
  1013. human.AB_Battle_Cache = {
  1014. isGather = pointInfo.isGather,
  1015. cityId = pointInfo.targetCityId,
  1016. pointIdx = pointInfo.targetPointIdx,
  1017. }
  1018. if pointInfo.occupySrvId then -- 玩家占领
  1019. local args = {
  1020. combatType = CombatDefine.COMBAT_TYPE35,
  1021. nServerIndex = pointInfo.occupySrvId,
  1022. param = pointInfo.occupyPlayerUuid,
  1023. extraArgs = {
  1024. cityId = pointInfo.targetCityId,
  1025. pointIdx = pointInfo.targetPointIdx,
  1026. useDef = true,
  1027. }
  1028. }
  1029. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
  1030. else
  1031. -- 机器人
  1032. CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
  1033. end
  1034. end
  1035. -- 跨服通知据点被别的玩家占领了
  1036. function C2N_Point_Lose(msg)
  1037. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1038. if not human then
  1039. local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
  1040. if not db then
  1041. return
  1042. end
  1043. human = {}
  1044. human.db = db
  1045. end
  1046. -- 更新防守阵容数据
  1047. local loseCityId = msg.loseCityId
  1048. local losePointIdx = msg.losePointIdx
  1049. local formationData = human.db.anotherWorlBattle.formation
  1050. formationData[loseCityId][losePointIdx] = nil
  1051. -- 玩家不在线, 手动保存数据
  1052. if not human.fd then
  1053. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1054. end
  1055. local cityCfg = AnotherWorldBattleConfig.city[loseCityId]
  1056. -- 发邮件
  1057. local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
  1058. local content = Util.format(mailCfg.content, cityCfg and cityCfg.cityName or "", loseCityId)
  1059. MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, content, nil, mailCfg.senderName or "GM")
  1060. -- 把最新的防守阵容数据推给客户端
  1061. if human.fd then
  1062. sendDefHeroArr(human)
  1063. end
  1064. end
  1065. -- 跨服通知可以更换据点的防守阵容数据
  1066. function C2N_Update_Point_Lineup(msg)
  1067. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1068. if not human then
  1069. local db = RoleDBLogic.getDb(msg.playerUuid)
  1070. if not db then
  1071. return
  1072. end
  1073. human = {}
  1074. human.db = db
  1075. end
  1076. local anotherWorlBattle = human.db.anotherWorlBattle
  1077. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1078. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  1079. end
  1080. local cityId = msg.targetCityId
  1081. local pointIdx = msg.targetPointIdx
  1082. if not anotherWorlBattle.formation[cityId] or not anotherWorlBattle.formation[cityId][pointIdx] then
  1083. return
  1084. end
  1085. local pointLinupData = anotherWorlBattle.formation[cityId][pointIdx]
  1086. pointLinupData.list = msg.heroList
  1087. pointLinupData.helpList = msg.helpList
  1088. pointLinupData.formation = msg.formation
  1089. if not human.fd then
  1090. ObjHuman.save(human)
  1091. end
  1092. sendDefHeroArr(human)
  1093. Broadcast.sendCenter(human, Lang.AB_UPDATE_LINEUP_SUCC)
  1094. end
  1095. -- 跨服通知给玩家发奖
  1096. function C2N_IssueReward(msg)
  1097. -- 删除公会参加异界之战活动时间
  1098. UnionLogic.UpdateJoinAbTime(msg.unionId, nil)
  1099. -- 发奖
  1100. local awardObjArr, occupyCityInfo = genAwardObjArr(msg.unionOccupyInfo)
  1101. if awardObjArr then
  1102. local issueRewardQueue = createRewardQueue()
  1103. issueRewardQueue.extraInfo = occupyCityInfo
  1104. for _, obj in ipairs(awardObjArr) do
  1105. issueRewardQueue:add(obj)
  1106. end
  1107. issueRewardQueue:insertDB()
  1108. end
  1109. end
  1110. -------------------------------------------战斗---------------------------------
  1111. function getCombatMonsterOutID(human, side, args)
  1112. if side ~= CombatDefine.DEFEND_SIDE then return end
  1113. local cityId = args[2]
  1114. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1115. return cityCfg.pointMonsterId
  1116. end
  1117. function getCombatObjList(human, side, args, combatType, extraArgs)
  1118. if side == CombatDefine.ATTACK_SIDE and not human then return end
  1119. if side == CombatDefine.DEFEND_SIDE and human then
  1120. return
  1121. end
  1122. if not human then
  1123. local uuid = args[1]
  1124. local db = RoleDBLogic.getDb(uuid)
  1125. if not db then
  1126. return
  1127. end
  1128. human = {}
  1129. human.db = db
  1130. end
  1131. return CombatLogic.getHumanObjList(human, combatType, extraArgs)
  1132. end
  1133. function getCombatHeros(human, combatType, args)
  1134. if not human.db.anotherWorlBattle then
  1135. return
  1136. end
  1137. local formation = human.db.anotherWorlBattle.formation
  1138. if not formation then
  1139. return
  1140. end
  1141. local cityId, pointIdx = args.cityId, args.pointIdx
  1142. if formation[cityId] and formation[cityId][pointIdx] then
  1143. local combatHeroDB = formation[cityId][pointIdx]
  1144. return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
  1145. end
  1146. end
  1147. function onFightBegin(human, cbParam, combatType, param)
  1148. if not human.AB_Battle_Cache or human.AB_Battle_Cache.isGather ~= 1 then
  1149. return
  1150. end
  1151. local gatherAttrs = AnotherWorldBattleConfig.var[1].gatherAttrs
  1152. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  1153. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  1154. local atkObj = CombatImpl.objList[atkPos]
  1155. if atkObj then
  1156. for _, atrrTb in ipairs(gatherAttrs) do
  1157. local attrId, attrVal = atrrTb[1], atrrTb[2]
  1158. atkObj.sysAttr[attrId] = (atkObj.sysAttr[attrId] or 0) + attrVal
  1159. end
  1160. atkObj.isSysAttrChange = true
  1161. end
  1162. end
  1163. end
  1164. function onFightEnd(human, result, type, cbParam, combatInfo)
  1165. -- if result == CombatDefine.RESULT_WIN then
  1166. -- challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
  1167. -- end
  1168. local args = {
  1169. cityId = human.AB_Battle_Cache.cityId,
  1170. pointIdx = human.AB_Battle_Cache.pointIdx,
  1171. challengeRes = result
  1172. }
  1173. human.AB_Battle_Cache = nil
  1174. challenge_End(human, args)
  1175. end