AnotherWorldBattleNS.lua 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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 CommonDB = require("common.CommonDB")
  37. local RoleSystemExcel = require("excel.roleSystem")
  38. local Grid = require("bag.Grid")
  39. local UnionLogic = require("union.UnionLogic")
  40. local BillboardLogic = require("billboard.BillboardLogic")
  41. local BillboardDefine = require("billboard.BillboardDefine")
  42. local AnotherWorldBattleDefine = require("anotherWorldBattle.AnotherWorldBattleDefine")
  43. local AnotherWorldBattleConfig = require("excel.anotherWorldBattle")
  44. local MonsterGrid = require("monster.MonsterGrid")
  45. local RoleConfig = require("excel.role")
  46. local MonsterExcel = require("excel.monster")
  47. local HeroExcel = require("excel.hero")
  48. local MiddleCommonLogic = require("middle.MiddleCommonLogic")
  49. local CombatImpl = require("combat.CombatImpl")
  50. local RoleAttr = require("role.RoleAttr")
  51. local RoleDefine = require("role.RoleDefine")
  52. local function writeLog(str)
  53. end
  54. local function sendMail(mailId, receiverUuid, itemArray)
  55. if not mailId or not receiverUuid then
  56. return
  57. end
  58. local mailCfg = MailExcel.mail[mailId]
  59. local content = mailCfg.content
  60. MailManager.add(MailManager.SYSTEM, receiverUuid, mailCfg.title, content, itemArray, mailCfg.senderName or "GM")
  61. end
  62. local function createRewardQueue()
  63. local issueRewardQueue = {
  64. playerArray = {},
  65. insertMaxNum = 100, -- 一次最多插入数据库的邮件数量
  66. repeatMaxTimes = 3, -- 重试次数
  67. repeatTb = {}
  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])
  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 calcCitysAward(cityIdArr)
  114. local myUnionAwardNum = 0
  115. if cityIdArr then
  116. for _, cityId in ipairs(cityIdArr) do
  117. local targetCityCfg = AnotherWorldBattleConfig.city[cityId]
  118. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2]
  119. end
  120. end
  121. return myUnionAwardNum
  122. end
  123. -- 获取展示部位的固定Id
  124. local function getDefaultShowId(showType, idx)
  125. local targetCfg
  126. if showType == 1 then
  127. targetCfg = RoleConfig.head
  128. else
  129. targetCfg = RoleConfig.headFrame
  130. end
  131. local t = {}
  132. for k in pairs(targetCfg) do
  133. t[#t+1] = k
  134. end
  135. table.sort(t)
  136. return t[idx] or t[1]
  137. end
  138. -- 单个英雄数据
  139. local function getHeroInfo(human, targetHeroUuid)
  140. local HeroLogic = require("hero.HeroLogic")
  141. local heroGrid = HeroLogic.getHeroGridByUuid(human, targetHeroUuid)
  142. if heroGrid then
  143. local heroCfg = HeroExcel.hero[heroGrid.id]
  144. RoleAttr.calcHeroGrid(heroGrid, nil, human)
  145. local heroInfo = {
  146. heroUuid = targetHeroUuid,
  147. heroStar = heroGrid.star,
  148. heroLevel = heroGrid.lv,
  149. heroCamp = heroGrid.camp or heroCfg.camp,
  150. heroBody = heroCfg.body,
  151. heroIcon = heroGrid.head or heroCfg.head,
  152. heroPower = heroGrid.zhandouli,
  153. }
  154. return heroInfo
  155. end
  156. end
  157. -- 获取上阵英雄数据
  158. local function getHeroListInfo(human, targetHeroUuid)
  159. local len = 0
  160. local heroArr = {}
  161. local heroList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  162. if not next(heroList) then
  163. return heroArr
  164. end
  165. for _, heroUuid in pairs(heroList) do
  166. if (heroUuid ~= "" and heroUuid ~= "0") and (not targetHeroUuid or targetHeroUuid == heroUuid) then
  167. len = len + 1
  168. heroArr[len] = getHeroInfo(human, heroUuid)
  169. end
  170. end
  171. if len == 0 then
  172. return
  173. end
  174. return heroArr
  175. end
  176. -- 生成展示数据
  177. local function generateShowInfo(human)
  178. local showInfo = {
  179. name = human.db.name,
  180. lv = human.db.lv,
  181. power = human.db.zhandouli,
  182. }
  183. showInfo.head = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_1)
  184. showInfo.headFrame = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_2)
  185. -- showInfo.body = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_3)
  186. showInfo.heroArr = getHeroListInfo(human)
  187. return showInfo
  188. end
  189. -- 阵容数据检查,如果不在 "活动开启且战斗阶段" 则清空
  190. local function formationDataCheeck(human)
  191. if not human.db.anotherWorlBattle then
  192. return
  193. end
  194. -- 不在战斗阶段时间范围
  195. local wDay = getWDay()
  196. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] > wDay and AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] < wDay then
  197. human.db.anotherWorlBattle = nil
  198. end
  199. -- 处于战斗阶段最后一天, 但是活动已经结束
  200. local now = os.time()
  201. local toDayStartTime = Util.getDayStartTime(now)
  202. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  203. human.db.anotherWorlBattle = nil
  204. end
  205. -- 处于战斗阶段时间范围内, 但是活动未开(因为每两轮活动时间间隔至少9天)
  206. local startTime = human.db.anotherWorlBattle.startTime
  207. local diffDays = Util.diffDay(startTime)
  208. if diffDays > 3 then
  209. human.db.anotherWorlBattle = nil
  210. end
  211. end
  212. -- 把玩家最新的异界之战所有防守英雄uuid推给客户端
  213. local function sendDefHeroArr(human)
  214. if not human.db.anotherWorlBattle then
  215. return
  216. end
  217. local len = 0
  218. local msgRet = Msg.gc.GC_AB_DEF_HERO_QUERY
  219. local heroUuidArrMsg = msgRet.heroUuidArr
  220. heroUuidArrMsg[0] = 0
  221. for _, pointList in pairs(human.db.anotherWorlBattle.formation) do
  222. for _, combatData in pairs(pointList) do
  223. local heroList = combatData.list
  224. for _, heroUuid in pairs(heroList) do
  225. if heroUuid ~= "" and heroUuid ~= "0" then
  226. len = len + 1
  227. heroUuidArrMsg[len] = heroUuid
  228. end
  229. end
  230. end
  231. end
  232. heroUuidArrMsg[0] = len
  233. Msg.send(msgRet, human.fd)
  234. end
  235. -- 是否是防守阵容中的英雄
  236. local function isDefHero(human, checkHeroUuid)
  237. if not human.db.anotherWorlBattle then
  238. return false
  239. end
  240. for _, pointList in pairs(human.db.anotherWorlBattle.formation) do
  241. for _, combatData in pairs(pointList) do
  242. local heroList = combatData.list
  243. for _, heroUuid in pairs(heroList) do
  244. if heroUuid == checkHeroUuid then
  245. return true
  246. end
  247. end
  248. end
  249. end
  250. return false
  251. end
  252. -- 是否是公会前二名
  253. local function isTopTwoUnion(human)
  254. local unionRanList = BillboardLogic.GetRankList(BillboardDefine.TYPE_UNION)
  255. if not unionRanList then
  256. return false
  257. end
  258. local unionId = human.db.unionUuid
  259. local isTopTwo = false
  260. for i=1, 2 do
  261. if unionRanList[i].uuid == unionId then
  262. isTopTwo = true
  263. break
  264. end
  265. end
  266. return isTopTwo
  267. end
  268. -- 是否处于战斗阶段
  269. local function isBattleStage()
  270. local wDay = getWDay()
  271. if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
  272. return true
  273. end
  274. return false
  275. end
  276. function IsRun(joinTime)
  277. if not isBattleStage() then
  278. return false
  279. end
  280. if joinTime then
  281. local diffDays = Util.diffDay(joinTime)
  282. --
  283. if diffDays == 5 then
  284. local now = os.time()
  285. local toDayStartTime = Util.getDayStartTime(now)
  286. if now < toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC then
  287. return false
  288. end
  289. end
  290. -- < 5天说明处于本轮活动的开启时间
  291. if diffDays > 5 and diffDays <= AnotherWorldBattleDefine.AB_SUB_DAY then
  292. return false
  293. end
  294. end
  295. return true
  296. end
  297. --检测上阵英雄
  298. function checkUpdatePos(human, msg)
  299. local heroList = Util.split(msg.heroList, ",")
  300. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  301. local uuid = heroList[i] or ""
  302. if uuid ~= "0" and uuid ~= "" then
  303. if isDefHero(human, uuid) then
  304. return false
  305. end
  306. end
  307. end
  308. return true
  309. end
  310. -- 公会战力更新
  311. function UnionPowerChange(unionId)
  312. if not isBattleStage() then
  313. return
  314. end
  315. end
  316. function isOpen(human)
  317. return RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1306) -- 待改
  318. end
  319. function onLogin(human)
  320. formationDataCheeck(human)
  321. sendDefHeroArr(human)
  322. end
  323. -- 请求状态
  324. function AB_GetState(human)
  325. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_STATE
  326. msgData.sourceServerId = Config.SVR_INDEX
  327. msgData.playerUuid = human.db._id
  328. msgData.myUnionId = human.db.unionUuid or ""
  329. InnerMsg.sendMsg(0, msgData)
  330. end
  331. -- 报名
  332. function AB_Join(human)
  333. local unionId = human.db.unionUuid
  334. local msgRet = Msg.gc.GC_AB_JOIN
  335. if not unionId then
  336. msgRet.Joinstate = 3
  337. return Msg.send(msgRet, human.fd)
  338. end
  339. -- if not isOpen(human) then
  340. -- return Broadcast.sendErr(human, Lang.AB_JOIN_COND_NOT_SATIFY)
  341. -- end
  342. local wDay = getWDay()
  343. if not table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  344. msgRet.Joinstate = 5
  345. return Msg.send(msgRet, human.fd)
  346. end
  347. -- 公会排名前二才能参加
  348. if not isTopTwoUnion(human) then
  349. msgRet.Joinstate = 2
  350. return Msg.send(msgRet, human.fd)
  351. end
  352. -- 会长/副会长才能报名
  353. if not UnionLogic.IsTopTwoManager(human, unionId) then
  354. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  355. end
  356. local queryFiles = {name = 1, zhandouli = 1}
  357. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  358. if not unionInfo then
  359. return Broadcast.sendErr(human, Lang.DATA_ERR)
  360. end
  361. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_JOIN
  362. msgData.sourceServerId = Config.SVR_INDEX
  363. msgData.playerUuid = human.db._id
  364. msgData.unionInfo = {
  365. name = unionInfo.name,
  366. power = unionInfo.zhandouli,
  367. unionId = unionId
  368. }
  369. InnerMsg.sendMsg(0, msgData)
  370. end
  371. -- 查询所有城池信息
  372. function AB_AllCity_Query(human)
  373. if not human.db.unionUuid then
  374. return
  375. end
  376. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  377. msgData.sourceServerId = Config.SVR_INDEX
  378. msgData.playerUuid = human.db._id
  379. msgData.myUnionId = human.db.unionUuid
  380. InnerMsg.sendMsg(0, msgData)
  381. -- 报名状态查询
  382. -- local msgData2 = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_JOIN_STATE
  383. -- msgData2.sourceServerId = Config.SVR_INDEX
  384. -- msgData2.playerUuid = human.db._id
  385. -- msgData2.myUnionId = human.db.unionUuid
  386. -- InnerMsg.sendMsg(0, msgData2)
  387. end
  388. -- 查询单个城池的详细信息
  389. function AB_CityDetailed_Query(human, targetCityId)
  390. if not AnotherWorldBattleConfig.city[targetCityId] then
  391. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  392. end
  393. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  394. msgData.sourceServerId = Config.SVR_INDEX
  395. msgData.playerUuid = human.db._id
  396. msgData.myUnionId = human.db.unionUuid
  397. msgData.targetCityId = targetCityId
  398. InnerMsg.sendMsg(0, msgData)
  399. end
  400. -- 查询某个城池的某个据点的相信信息
  401. function AB_PointDetailed_Query(human, targetCityId, targetPointIdx)
  402. if not AnotherWorldBattleConfig.city[targetCityId] then
  403. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  404. end
  405. if 0 >= targetPointIdx or AnotherWorldBattleDefine.AB_POINT_MAX_NUM < targetPointIdx then
  406. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  407. end
  408. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINTtDETAILED_QUERY
  409. msgData.sourceServerId = Config.SVR_INDEX
  410. msgData.playerUuid = human.db._id
  411. msgData.myUnionId = human.db.unionUuid
  412. msgData.targetCityId = targetCityId
  413. msgData.targetPointIdx = targetPointIdx
  414. InnerMsg.sendMsg(0, msgData)
  415. end
  416. -- 查询本公会出生点信息
  417. function AB_BaseCity_Query(human)
  418. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_BASECITY_QUERY
  419. msgData.sourceServerId = Config.SVR_INDEX
  420. msgData.playerUuid = human.db._id
  421. msgData.myUnionId = human.db.unionUuid
  422. InnerMsg.sendMsg(0, msgData)
  423. end
  424. -- 查询玩家占领的所有据点信息
  425. function AB_PlayerOccupyPOint_Query(human)
  426. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  427. msgData.sourceServerId = Config.SVR_INDEX
  428. msgData.playerUuid = human.db._id
  429. msgData.myUnionId = human.db.unionUuid
  430. InnerMsg.sendMsg(0, msgData)
  431. end
  432. -- 查询公会排行榜
  433. function AB_UnionRank_Query(human)
  434. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  435. msgData.sourceServerId = Config.SVR_INDEX
  436. msgData.playerUuid = human.db._id
  437. msgData.myUnionId = human.db.unionUuid
  438. InnerMsg.sendMsg(0, msgData)
  439. end
  440. -- 查询玩家排行榜
  441. function AB_PlayerRank_Query(human)
  442. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  443. msgData.sourceServerId = Config.SVR_INDEX
  444. msgData.playerUuid = human.db._id
  445. msgData.myUnionId = human.db.unionUuid
  446. InnerMsg.sendMsg(0, msgData)
  447. end
  448. -- 发起集结
  449. function AB_Gather(human, targetCityId)
  450. if not AnotherWorldBattleConfig.city[targetCityId] then
  451. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  452. end
  453. local unionId = human.db.unionUuid
  454. if not unionId then
  455. return Broadcast.sendErr(human, Lang.AB_NO_UNION)
  456. end
  457. -- 会长/副会长才能集结
  458. if not UnionLogic.IsTopTwoManager(human, unionId) then
  459. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANAGER)
  460. end
  461. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GATHER
  462. msgData.sourceServerId = Config.SVR_INDEX
  463. msgData.playerUuid = human.db._id
  464. msgData.myUnionId = human.db.unionUuid
  465. msgData.targetCityId = targetCityId
  466. InnerMsg.sendMsg(0, msgData)
  467. end
  468. -- 请求挑战某个据点
  469. function AB_Try_Challenge_Point(human, targetCityId, targetPointIdx)
  470. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  471. if not combatHero or not next(combatHero) then
  472. return Broadcast.sendErr(human, Lang.COMBAT_NEED_FIGHT_HERO)
  473. end
  474. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  475. msgData.sourceServerId = Config.SVR_INDEX
  476. msgData.playerUuid = human.db._id
  477. msgData.myUnionId = human.db.unionUuid
  478. msgData.targetCityId = targetCityId
  479. msgData.targetPointIdx = targetPointIdx
  480. InnerMsg.sendMsg(0, msgData)
  481. end
  482. -- 战斗胜利
  483. local function challenge_Win(human, args)
  484. if not human.db.anotherWorlBattle then
  485. human.db.anotherWorlBattle = {
  486. startTime = os.time(),
  487. formation = {}
  488. }
  489. end
  490. -- 把当前战斗阵容数据保存到当前模块,作为防守阵容
  491. local combatData = CombatPosLogic.getCombatHeroDB(human, CombatDefine.COMBAT_TYPE35)
  492. local cityId = args.cityId
  493. local pointIdx = args.pointIdx
  494. local formationData = human.db.anotherWorlBattle.formation or {}
  495. formationData[cityId] = formationData[cityId] or {}
  496. formationData[cityId][pointIdx] = Util.copyTable(combatData)
  497. -- 把最新的防守英雄uuid列表推送给客户端
  498. sendDefHeroArr(human)
  499. --同步到跨服
  500. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_CHALLENGE_WIN
  501. msgData.sourceServerId = Config.SVR_INDEX
  502. msgData.playerUuid = human.db._id
  503. msgData.myUnionId = human.db.unionUuid
  504. msgData.targetCityId = cityId
  505. msgData.targetPointIdx = pointIdx
  506. msgData.playerShowInfo = generateShowInfo(human)
  507. InnerMsg.sendMsg(0, msgData)
  508. -- 清空战斗阵容
  509. CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  510. end
  511. ------------------------------------C2N---------------------------------------------------
  512. -- 错误提示
  513. function C2N_ErrTips(msg)
  514. local human = ObjHuman.onlineUuid[msg.playerUuid]
  515. if not human then
  516. return
  517. end
  518. local tips = Lang.DATA_ERR
  519. local errCode = msg.errCode
  520. if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
  521. tips = Lang.AB_NOT_OPEN_TIME
  522. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
  523. tips = Lang.AB_NOT_UNION_NUM_EXCEED
  524. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
  525. tips = Lang.AB_UNION_NO_JOIN
  526. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
  527. tips = Lang.DATA_ERR
  528. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
  529. tips = Lang.AB_NOT_OCCUPY_POINT
  530. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
  531. tips = Lang.AB_GATHER_CD
  532. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
  533. tips = Lang.AB_CITY_NOT_ADDJION
  534. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
  535. tips = Lang.AB_JOINED
  536. end
  537. Broadcast.sendErr(human, tips)
  538. end
  539. -- 跨服返回状态
  540. function C2N_State(msg)
  541. local human = ObjHuman.onlineUuid[msg.playerUuid]
  542. if not human then
  543. return
  544. end
  545. local msgRet = Msg.gc.GC_AB_GetState
  546. msgRet.joinState = msg.joinState
  547. msgRet.systemState = msg.systemState
  548. if msgRet.joinState == 0 then
  549. local unionId = human.db.unionUuid
  550. if not unionId then
  551. msgRet.Joinstate = 2
  552. return Msg.send(msgRet, human.fd)
  553. end
  554. -- 公会排名前二才行
  555. if not isTopTwoUnion(human) then
  556. msgRet.Joinstate = 2
  557. return Msg.send(msgRet, human.fd)
  558. end
  559. end
  560. Msg.send(msgRet, human.fd)
  561. end
  562. -- 报名成功
  563. function C2N_Join_Succ(msg)
  564. local unionId = msg.myUnionId
  565. UnionLogic.Join_AB_Succ(unionId)
  566. local human = ObjHuman.onlineUuid[msg.playerUuid]
  567. if not human then
  568. return
  569. end
  570. local msgRet = Msg.gc.GC_AB_JOIN
  571. msgRet.Joinstate = 1
  572. Msg.send(msgRet, human.fd)
  573. end
  574. -- 跨服返回的所有城池数据
  575. function C2N_AllCity_Query(msg)
  576. local human = ObjHuman.onlineUuid[msg.playerUuid]
  577. if not human then
  578. return
  579. end
  580. local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
  581. msgRet.myBaseCityId = msg.myUnionBaseCityId
  582. local cityArrMsg = msgRet.cityArr
  583. cityArrMsg[0] = 0
  584. local useCfg = false
  585. local cityData = msg.cityArr
  586. if #msg.cityArr <= 0 then
  587. useCfg = true
  588. cityData = AnotherWorldBattleConfig.city
  589. end
  590. for cityId, cityInfo in ipairs(cityData) do
  591. cityArrMsg[0] = cityId
  592. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  593. cityArrMsg[cityId].cityId = cityId
  594. cityArrMsg[cityId].cityName = cityCfg.cityName
  595. cityArrMsg[cityId].cityLv = cityCfg.cityLv
  596. cityArrMsg[cityId].occupyPointNum = useCfg and 0 or cityInfo.occupyPointNum
  597. cityArrMsg[cityId].occupyUnionName = (useCfg and "" or cityInfo.occupyUnionName) or ""
  598. cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
  599. for i, cId in ipairs(cityCfg.adJoinCityArr) do
  600. cityArrMsg[cityId].adJoinCityArr[i] = cId
  601. end
  602. end
  603. msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
  604. for i, cityId in ipairs(msg.myOccupyCityArr) do
  605. msgRet.myOccupyCityArr[i] = cityId
  606. end
  607. Msg.send(msgRet, human.fd)
  608. end
  609. -- 跨服返回某个城池详细数据
  610. function C2N_CityDetailed_Query(msg)
  611. local human = ObjHuman.onlineUuid[msg.playerUuid]
  612. if not human then
  613. return
  614. end
  615. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  616. local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
  617. msgRet.cityId = msg.targetCityId
  618. msgRet.cityLv = cityCfg.cityLv
  619. msgRet.cityIconId = cityCfg.cityIconId
  620. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2])
  621. local myUnionAwardNum = calcCitysAward(msg.myUnionOccupyArr)
  622. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  623. -- 活动没有进入战斗阶段时, 使用默认数据
  624. if #msg.pointArr == 0 then
  625. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  626. msg.pointArr[i] = {}
  627. end
  628. end
  629. msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  630. for pointIdx, pointInfo in ipairs(msg.pointArr) do
  631. if pointInfo.occupyUnionName then
  632. msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
  633. msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
  634. msgRet.pointArr[pointIdx].power = pointInfo.power
  635. msgRet.pointArr[pointIdx].isCanChallenge = pointInfo.isCanChallenge
  636. else
  637. msgRet.pointArr[pointIdx].occupyUnionName = ""
  638. msgRet.pointArr[pointIdx].occupyPlayerName = "防守者".. pointIdx --待改
  639. msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
  640. msgRet.pointArr[pointIdx].isCanChallenge = pointInfo.isCanChallenge
  641. end
  642. end
  643. msgRet.gatherState = msg.gatherState
  644. if msg.gatherState == 1 then
  645. -- 公会会长/副会长才能集结
  646. if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
  647. msgRet.gatherState = 0
  648. end
  649. end
  650. Msg.send(msgRet, human.fd)
  651. end
  652. -- 跨服返回某个据点数据
  653. function C2N_PointDetailed_Query(msg)
  654. local human = ObjHuman.onlineUuid[msg.playerUuid]
  655. if not human then
  656. return
  657. end
  658. local pointInfo = msg.pointInfo
  659. local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
  660. msgRet.isCanChallenge = pointInfo.isCanChallenge or 0
  661. if pointInfo.name then
  662. msgRet.name = pointInfo.name
  663. msgRet.power = pointInfo.power
  664. msgRet.head = pointInfo.head
  665. msgRet.headFrame = pointInfo.headFrame
  666. msgRet.defLv = pointInfo.defLv
  667. msgRet.heroArr[0] = #pointInfo.heroArr
  668. for i, heroInfo in ipairs(pointInfo.heroArr) do
  669. msgRet.heroArr[i].heroBody = heroInfo.heroBody
  670. msgRet.heroArr[i].heroStar = heroInfo.heroStar
  671. msgRet.heroArr[i].heroLv = heroInfo.heroLv
  672. msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
  673. msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
  674. end
  675. else
  676. msgRet.name = "防守者" .. msg.targetPointIdx -- 待改
  677. msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
  678. msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
  679. msgRet.defLv = 200
  680. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  681. msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
  682. msgRet.heroArr[0] = 0
  683. local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
  684. for idx, monsterInfo in ipairs(monsterOutConfig.member) do
  685. if idx > 6 then
  686. break
  687. end
  688. msgRet.heroArr[0] = idx
  689. local monsterID = monsterInfo[1]
  690. local mcf = MonsterExcel.monster[monsterID]
  691. msgRet.heroArr[idx].heroBody = mcf.body
  692. msgRet.heroArr[idx].heroStar = mcf.star
  693. msgRet.heroArr[idx].heroLv = monsterInfo[2]
  694. msgRet.heroArr[idx].heroCamp = mcf.camp
  695. msgRet.heroArr[idx].heroIcon = mcf.head
  696. end
  697. end
  698. Msg.send(msgRet, human.fd)
  699. end
  700. -- 跨服返回公会出生点数据
  701. function C2N_BaseCity_Query(msg)
  702. local human = ObjHuman.onlineUuid[msg.playerUuid]
  703. if not human then
  704. return
  705. end
  706. local baseCityInfo = msg.baseCityInfo
  707. local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
  708. local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
  709. msgRet.cityIconId = cityCfg.cityIconId
  710. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2])
  711. local myUnionAwardNum = calcCitysAward(baseCityInfo.myUnionOccupyArr)
  712. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  713. msgRet.cityIconId = baseCityInfo.occupyPointNum
  714. msgRet.occupyPointNum = baseCityInfo.occupyPointNum
  715. msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
  716. msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
  717. msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
  718. msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
  719. Msg.send(msgRet, human.fd)
  720. end
  721. -- 跨服返回玩家占领的据点数据
  722. function C2N_PlayerOccupyPoint_Query(msg)
  723. local human = ObjHuman.onlineUuid[msg.playerUuid]
  724. if not human then
  725. return
  726. end
  727. local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
  728. local myPointArr = msg.myPointArr
  729. myPointArr[0] = 0
  730. for idx, pointInfo in ipairs(msg.occupyPointArr) do
  731. myPointArr[0] = idx
  732. local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
  733. myPointArr[idx].cityIconId = cityCfg.cityIconId
  734. myPointArr[idx].cityLv = cityCfg.cityLv
  735. myPointArr[idx].pointIdx = pointInfo.pointIdx
  736. myPointArr[idx].power = pointInfo.power
  737. myPointArr[idx].heroArr[0] = #pointInfo.heroArr
  738. for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
  739. local hero = myPointArr[idx].heroArr[heroIdx]
  740. hero.heroBody = heroInfo.heroBody
  741. hero.heroStar = heroInfo.heroStar
  742. hero.heroLv = heroInfo.heroLv
  743. hero.heroCamp = heroInfo.heroCamp
  744. hero.heroIcon = heroInfo.heroIcon
  745. end
  746. end
  747. Msg.send(msgRet, human.fd)
  748. end
  749. --跨服返回公会排行榜数据
  750. function C2N_UnionRank_Query(msg)
  751. local human = ObjHuman.onlineUuid[msg.playerUuid]
  752. if not human then
  753. return
  754. end
  755. local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
  756. msgRet.unionRankArr[0] = 0
  757. msgRet.myUnionRank = msg.myUnionRank
  758. for rank, rankdData in ipairs(msg.unionRankArr) do
  759. msgRet.unionRankArr[0] = rank
  760. msgRet.unionRankArr[rank] = {
  761. name = rankdData.name,
  762. power = rankdData.power,
  763. cityNum = rankdData.occupyCityNum,
  764. pointNum = rankdData.occupyPointNum,
  765. }
  766. end
  767. Msg.send(msgRet, human.fd)
  768. end
  769. --跨服返回玩家排行榜数据
  770. function C2N_PlayerRank_Query(msg)
  771. local human = ObjHuman.onlineUuid[msg.playerUuid]
  772. if not human then
  773. return
  774. end
  775. local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
  776. msgRet.playerRankArr[0] = 0
  777. msgRet.myRank = msg.myRank
  778. for rank, rankdData in ipairs(msg.playerRankArr) do
  779. msgRet.playerRankArr[0] = rank
  780. msgRet.playerRankArr[rank] = {
  781. name = rankdData.name,
  782. power = rankdData.power,
  783. pointNum = rankdData.occupyPointNum,
  784. pointWeight = rankdData.pointWeight,
  785. }
  786. end
  787. Msg.send(msgRet, human.fd)
  788. end
  789. -- 跨服返回要挑战的据点的数据(据点可以被挑战)
  790. function C2N_Challenge_Point_OK(msg)
  791. local human = ObjHuman.onlineUuid[msg.playerUuid]
  792. if not human then
  793. return
  794. end
  795. local pointInfo = msg.pointInfo
  796. human.AB_Battle_Cache = {
  797. isGather = pointInfo.isGather,
  798. cityId = pointInfo.targetCityId,
  799. pointIdx = pointInfo.targetPointIdx,
  800. }
  801. if pointInfo.occupySrvId then -- 玩家占领
  802. local args = {
  803. combatType = CombatDefine.COMBAT_TYPE35,
  804. nServerIndex = pointInfo.occupySrvId,
  805. param = pointInfo.occupyPlayerUuid,
  806. extraArgs = {
  807. cityId = pointInfo.targetCityId,
  808. pointIdx = pointInfo.targetPointIdx,
  809. useDef = true,
  810. }
  811. }
  812. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
  813. else
  814. -- 机器人
  815. CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
  816. end
  817. end
  818. -- 跨服通知据点被别的玩家占领了
  819. function C2N_Point_Lose(msg)
  820. local human = ObjHuman.onlineUuid[msg.playerUuid]
  821. if not human then
  822. local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
  823. if not db then
  824. return
  825. end
  826. human = {}
  827. human.db = db
  828. end
  829. -- 更新防守阵容数据
  830. local loseCityId = msg.loseCityId
  831. local losePointIdx = msg.losePointIdx
  832. local formationData = human.db.anotherWorlBattle.formation
  833. formationData[loseCityId][losePointIdx] = nil
  834. -- 玩家不在线, 手动保存数据
  835. if not human.fd then
  836. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  837. end
  838. -- 发邮件
  839. local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
  840. MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, mailCfg.content, nil, mailCfg.senderName or "GM")
  841. -- 把最新的防守阵容数据推给客户端
  842. if human.fd then
  843. sendDefHeroArr(human)
  844. end
  845. end
  846. local function genAwardObjArr(unionOccupyInfo)
  847. local function calcMins(timeArr)
  848. local minuteVal = 0
  849. for _, timeTb in ipairs(timeArr or {}) do
  850. local sec = timeTb[2] - timeTb[1]
  851. if sec > 0 then
  852. minuteVal = minuteVal + math.floor(sec / 60)
  853. end
  854. end
  855. return minuteVal
  856. end
  857. if not unionOccupyInfo.playerUuidArr or #unionOccupyInfo.playerUuidArr <= 0 then
  858. return
  859. end
  860. local itemList = {}
  861. local item_185_Id = 185
  862. local item_185_Num = 0
  863. item_185_Num = item_185_Num + (unionOccupyInfo.occuoyPointNum or 0) -- 待优化
  864. for _, cityInfo in ipairs(unionOccupyInfo.occupyCityArr) do
  865. local cityId = cityInfo[1]
  866. local occupyTimeArr = cityInfo[2]
  867. local isOccupy = cityInfo[3]
  868. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  869. local totalMinVal = calcMins(occupyTimeArr)
  870. if totalMinVal > 0 then
  871. local itemId, itemNum = cityCfg.cityAward[1], cityCfg.cityAward[2]
  872. itemList[itemId] = totalMinVal * itemNum
  873. end
  874. if cityCfg and isOccupy then
  875. if cityCfg.isBaseCity == 1 then
  876. item_185_Num = item_185_Num + 20
  877. else
  878. if cityCfg.cityLv == 2 then
  879. item_185_Num = item_185_Num + 2
  880. elseif cityCfg.cityLv == 3 then
  881. item_185_Num = item_185_Num + 3
  882. elseif cityCfg.cityLv == 4 then
  883. item_185_Num = item_185_Num + 5
  884. elseif cityCfg.cityLv == 5 then
  885. item_185_Num = item_185_Num + 20
  886. end
  887. end
  888. end
  889. end
  890. if item_185_Num > 0 then
  891. itemList[item_185_Id] = item_185_Num
  892. end
  893. local itemArr = {}
  894. for itemId, itemNum in pairs(itemList) do
  895. itemArr[#itemArr+1] = { itemId, itemNum }
  896. end
  897. local awardObjArr = {}
  898. for _, playerUuid in ipairs(unionOccupyInfo.playerUuidArr) do
  899. awardObjArr[#awardObjArr+1] = {playerUuid, itemArr}
  900. end
  901. return awardObjArr
  902. end
  903. -- 发奖
  904. function C2N_IssueReward(msg)
  905. local awardObjArr = genAwardObjArr(msg.unionOccupyInfo)
  906. if awardObjArr then
  907. local issueRewardQueue = createRewardQueue()
  908. for _, obj in ipairs(awardObjArr) do
  909. issueRewardQueue:add(obj)
  910. end
  911. issueRewardQueue:insertDB()
  912. end
  913. end
  914. -------------------------------------------战斗---------------------------------
  915. function getCombatMonsterOutID(human, side, args)
  916. if side ~= CombatDefine.DEFEND_SIDE then return end
  917. local cityId = args[2]
  918. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  919. return cityCfg.pointMonsterId
  920. end
  921. function getCombatObjList(human, side, args, combatType, extraArgs)
  922. if side == CombatDefine.ATTACK_SIDE and not human then return end
  923. if side == CombatDefine.DEFEND_SIDE and human then
  924. return
  925. end
  926. if not human then
  927. local uuid = args[1]
  928. local db = RoleDBLogic.getDb(uuid)
  929. if not db then
  930. return
  931. end
  932. human = {}
  933. human.db = db
  934. end
  935. return CombatLogic.getHumanObjList(human, combatType, extraArgs)
  936. end
  937. function getCombatHeros(human, combatType, args)
  938. if not human.db.anotherWorlBattle then
  939. return
  940. end
  941. local formation = human.db.anotherWorlBattle.formation
  942. if not formation then
  943. return
  944. end
  945. local cityId, pointIdx = args.cityId, args.pointIdx
  946. if formation[cityId] and formation[cityId][pointIdx] then
  947. local combatHeroDB = formation[cityId][pointIdx]
  948. return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
  949. end
  950. end
  951. function onFightBegin(human, cbParam, combatType, param)
  952. if not human.AB_Battle_Cache or human.AB_Battle_Cache.isGather ~= 1 then
  953. return
  954. end
  955. local attrList = {
  956. [RoleDefine.HURT_RATE] = 1000,
  957. [RoleDefine.JIANSHANG_RATE] = 1000,
  958. }
  959. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  960. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  961. local atkObj = CombatImpl.objList[atkPos]
  962. if atkObj then
  963. for attrId, attrVal in pairs(attrList) do
  964. atkObj.sysAttr[attrId] = (atkObj.sysAttr[attrId] or 0) + attrVal
  965. end
  966. atkObj.isSysAttrChange = true
  967. end
  968. end
  969. end
  970. function onFightEnd(human, result, type, cbParam, combatInfo)
  971. if result == CombatDefine.RESULT_WIN then
  972. challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
  973. end
  974. human.AB_Battle_Cache = nil
  975. end