AnotherWorldBattleNS.lua 33 KB

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