AnotherWorldBattleNS.lua 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011
  1. -- 异界之战
  2. --db
  3. --[=[
  4. human.db.anotherWorlBattle = {
  5. startTime = nil,
  6. formation = {
  7. [cityId1] = {
  8. [pointIdx1] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  9. [pointIdx2] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  10. },
  11. [cityId2] = {
  12. [pointIdx1] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  13. [pointIdx2] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  14. },
  15. }
  16. }
  17. ]=]--
  18. local Config = require("Config")
  19. local Msg = require("core.Msg")
  20. local Lang = require("common.Lang")
  21. local ObjHuman = require("core.ObjHuman")
  22. local Broadcast = require("broadcast.Broadcast")
  23. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  24. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  25. local CombatDefine = require("combat.CombatDefine")
  26. local RoleDBLogic = require("role.RoleDBLogic")
  27. local CombatPosLogic = require("combat.CombatPosLogic")
  28. local CombatLogic = require("combat.CombatLogic")
  29. local MailExcel = require("excel.mail")
  30. local Util = require("common.Util")
  31. local InnerMsg = require("core.InnerMsg")
  32. local RoleHeadLogic = require("role.RoleHeadLogic")
  33. local MailManager = require("mail.MailManager")
  34. local Log = require("common.Log")
  35. local Timer = require("core.Timer")
  36. local Grid = require("bag.Grid")
  37. local UnionLogic = require("union.UnionLogic")
  38. local BillboardLogic = require("billboard.BillboardLogic")
  39. local BillboardDefine = require("billboard.BillboardDefine")
  40. local AnotherWorldBattleDefine = require("anotherWorldBattle.AnotherWorldBattleDefine")
  41. local AnotherWorldBattleConfig = require("excel.anotherWorldBattle")
  42. local MonsterGrid = require("monster.MonsterGrid")
  43. local RoleConfig = require("excel.role")
  44. local MonsterExcel = require("excel.monster")
  45. local HeroExcel = require("excel.hero")
  46. local MiddleCommonLogic = require("middle.MiddleCommonLogic")
  47. local CombatImpl = require("combat.CombatImpl")
  48. local RoleAttr = require("role.RoleAttr")
  49. local CommonDB = require("common.CommonDB")
  50. local BagLogic = require("bag.BagLogic")
  51. local HeroLogic
  52. local JibanLogic
  53. local LOGTAG = "AnotherWorldBattleNS"
  54. local function writeLog(logStr)
  55. Log.write(Log.LOGID_OSS_ANOTHERWORLDBATTLE, logStr)
  56. end
  57. local function sendMail(mailId, receiverUuid, itemArray, extraInfo, rank)
  58. if not mailId or not receiverUuid then
  59. return
  60. end
  61. local mailCfg = MailExcel.mail[mailId]
  62. local content = mailCfg.content
  63. if mailId == AnotherWorldBattleDefine.AB_AWARD_MAIL_ID then
  64. local v1,v2,v3,v4,v5
  65. v1,v2,v3 = extraInfo and extraInfo[1] or 0, extraInfo and extraInfo[2] or 0, extraInfo and extraInfo[3] or 0
  66. v4,v5 = extraInfo and extraInfo[4] or 0, extraInfo and extraInfo[5] or 0
  67. content = Util.format(content, v1,v2,v3,v4,v5)
  68. elseif mailId == AnotherWorldBattleDefine.AB_UNIONRANK_AWARD_MAIL_ID then
  69. content = Util.format(content, rank)
  70. else
  71. if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
  72. rank = "50+"
  73. end
  74. content = Util.format(content, rank)
  75. end
  76. MailManager.add(MailManager.SYSTEM, receiverUuid, mailCfg.title, content, itemArray, mailCfg.senderName or "GM")
  77. end
  78. local function createRewardQueue()
  79. local issueRewardQueue = {
  80. playerArray = {},
  81. insertMaxNum = 100, -- 一次最多插入数据库的邮件数量
  82. repeatMaxTimes = 3, -- 重试次数
  83. repeatTb = {},
  84. extraInfo = {},
  85. }
  86. function issueRewardQueue:add(playerInfo)
  87. table.insert(self.playerArray, playerInfo)
  88. end
  89. function issueRewardQueue:insertDB()
  90. local maxNum = math.min(self.insertMaxNum, #self.playerArray)
  91. for i=1, maxNum do
  92. local resTag = AnotherWorldBattleDefine.AB_MAIL_SUCC_TAG
  93. local playerInfo = table.remove(self.playerArray)
  94. local playerUuid = playerInfo[1]
  95. local mailId = playerInfo[3]
  96. local rank = playerInfo[4]
  97. local ok, err = pcall(sendMail, mailId, playerUuid, playerInfo[2], issueRewardQueue.extraInfo, rank)
  98. if not ok then
  99. if not self.repeatTb[playerUuid] or self.repeatTb[playerUuid] < self.repeatMaxTimes then
  100. issueRewardQueue:add(playerInfo)
  101. self.repeatTb[playerUuid] = (self.repeatTb[playerUuid] or 0) + 1
  102. end
  103. resTag = AnotherWorldBattleDefine.AB_MAIL_FAIL_TAG
  104. end
  105. -- 写入日志
  106. local str = string.format("Result: %s, playerUuid: %s, mailId: %d, insertErrTimes: %d, errInfo: %s",
  107. resTag, playerUuid, mailId, self.repeatTb[playerUuid] or 0, err)
  108. writeLog(str)
  109. end
  110. if #self.playerArray > 0 then
  111. Timer.addLater(2, self.insertDB, self)
  112. end
  113. end
  114. return issueRewardQueue
  115. end
  116. -- 获取当天是星期几
  117. local function getWDay()
  118. return Util.getWeekDay()
  119. end
  120. -- 开服天数和玩家等级检查
  121. local function baseCondCheck(human)
  122. return RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1216)
  123. end
  124. -- 根据最近一轮活动开启时间, 判断当前是否处于活动开启时间范围
  125. local function actStartTimeCheck()
  126. local wDay = getWDay()
  127. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  128. return false
  129. end
  130. local startTime = CommonDB.getValueByKey(CommonDB.KEY_ANOTHERWORLDBATTLE_START_TI)
  131. if not startTime then
  132. return false
  133. end
  134. if not IsRuning(startTime) then
  135. return false
  136. end
  137. return true
  138. end
  139. -- 计算怪物战力
  140. local function calcMonsterPower(monsterOutID)
  141. local power = 0
  142. local objList = MonsterGrid.createMonsterObjListByMonsterOutID(monsterOutID)
  143. if not objList then
  144. return power
  145. end
  146. for _, monster in ipairs(objList) do
  147. power = power + (monster.power or 0)
  148. end
  149. return power
  150. end
  151. -- 根据据点所属城池,计算多个据点每分钟产出道具数量之和
  152. local function calcPointAward(cityIdArr)
  153. local myUnionAwardNum = 0
  154. if cityIdArr then
  155. for _, cityId in ipairs(cityIdArr) do
  156. local targetCityCfg = AnotherWorldBattleConfig.city[cityId]
  157. if targetCityCfg.isBaseCity == 1 then
  158. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  159. else
  160. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2]
  161. end
  162. end
  163. end
  164. return myUnionAwardNum
  165. end
  166. -- 获取展示部位的固定Id
  167. local function getDefaultShowId(showType, idx)
  168. local targetCfg
  169. if showType == 1 then
  170. targetCfg = RoleConfig.head
  171. else
  172. targetCfg = RoleConfig.headFrame
  173. end
  174. local t = {}
  175. for k in pairs(targetCfg) do
  176. t[#t+1] = k
  177. end
  178. table.sort(t)
  179. return t[idx] or t[1]
  180. end
  181. -- 单个英雄数据
  182. local function getHeroInfo(human, targetHeroUuid)
  183. HeroLogic = HeroLogic or require("hero.HeroLogic")
  184. local heroGrid = HeroLogic.getHeroGridByUuid(human, targetHeroUuid)
  185. if heroGrid then
  186. local heroCfg = HeroExcel.hero[heroGrid.id]
  187. RoleAttr.calcHeroGrid(heroGrid, nil, human)
  188. local heroInfo = {
  189. heroUuid = targetHeroUuid,
  190. heroStar = heroGrid.star,
  191. heroLevel = heroGrid.lv,
  192. heroCamp = heroGrid.camp or heroCfg.camp,
  193. heroBody = heroCfg.body,
  194. heroIcon = heroGrid.head or heroCfg.head,
  195. heroPower = heroGrid.zhandouli,
  196. heroId = heroGrid.id,
  197. heroQuality = heroCfg.grade,
  198. }
  199. return heroInfo
  200. end
  201. end
  202. -- 获取上阵英雄数据
  203. local function getHeroListInfo(human, targetHeroUuid)
  204. local len = 0
  205. local heroArr = {}
  206. local heroList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  207. if not next(heroList) then
  208. return heroArr
  209. end
  210. for _, heroUuid in pairs(heroList) do
  211. if (heroUuid ~= "" and heroUuid ~= "0") and (not targetHeroUuid or targetHeroUuid == heroUuid) then
  212. len = len + 1
  213. heroArr[len] = getHeroInfo(human, heroUuid)
  214. end
  215. end
  216. if len == 0 then
  217. return
  218. end
  219. return heroArr
  220. end
  221. -- 生成展示数据
  222. local function generateShowInfo(human)
  223. local showInfo = {
  224. name = human.db.name,
  225. lv = human.db.lv,
  226. power = human.db.zhandouli,
  227. }
  228. showInfo.head = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_1)
  229. showInfo.headFrame = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_2)
  230. -- showInfo.body = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_3)
  231. showInfo.heroArr = getHeroListInfo(human)
  232. return showInfo
  233. end
  234. -- 阵容数据检查,如果不在 "活动开启且战斗阶段" 则清空
  235. local function formationDataCheeck(human)
  236. if not human.db.anotherWorlBattle then
  237. return
  238. end
  239. -- 不在战斗阶段时间范围
  240. local wDay = getWDay()
  241. if not (AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] <= wDay and AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] >= wDay) then
  242. human.db.anotherWorlBattle = nil
  243. return
  244. end
  245. -- 处于战斗阶段最后一天, 但是活动已经结束
  246. local now = os.time()
  247. local toDayStartTime = Util.getDayStartTime(now)
  248. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  249. human.db.anotherWorlBattle = nil
  250. return
  251. end
  252. -- 处于战斗阶段时间范围内, 但是活动未开(因为两轮活动时间间隔至少9天)
  253. local startTime = human.db.anotherWorlBattle.startTime
  254. local diffDays = Util.diffDay(startTime)
  255. if diffDays > AnotherWorldBattleDefine.AB_BATTLE_DAYS then
  256. human.db.anotherWorlBattle = nil
  257. end
  258. end
  259. -- 把玩家最新的异界之战所有防守英雄uuid推给客户端
  260. local function sendDefHeroArr(human)
  261. local msgRet = Msg.gc.GC_AB_DEF_HERO_QUERY
  262. msgRet.heroUuidArr[0] = 0
  263. if not human.db.anotherWorlBattle then
  264. return Msg.send(msgRet, human.fd)
  265. end
  266. local len = 0
  267. local heroUuidArrMsg = msgRet.heroUuidArr
  268. for _, pointList in pairs(human.db.anotherWorlBattle.formation) do
  269. for _, combatData in pairs(pointList) do
  270. local heroList = combatData.list
  271. for _, heroUuid in pairs(heroList) do
  272. if heroUuid ~= "" and heroUuid ~= "0" then
  273. len = len + 1
  274. heroUuidArrMsg[len] = heroUuid
  275. end
  276. end
  277. end
  278. end
  279. heroUuidArrMsg[0] = len
  280. Msg.send(msgRet, human.fd)
  281. end
  282. -- 如果活动开启时间范围内, 则通知客户端弹出提示框
  283. local function notifyTips(human)
  284. if not baseCondCheck(human) then
  285. return
  286. end
  287. local wDay = getWDay()
  288. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  289. return
  290. end
  291. AB_GetState(human, true)
  292. end
  293. -- 是否是防守阵容中的英雄
  294. local function isDefHero(human, checkHeroUuid, excludeCityId, excludePointIdx)
  295. if not human.db.anotherWorlBattle then
  296. return
  297. end
  298. for cityId, pointList in pairs(human.db.anotherWorlBattle.formation) do
  299. for pointIdx, combatData in pairs(pointList) do
  300. if (excludeCityId and excludeCityId == cityId) and (excludePointIdx and excludePointIdx == pointIdx) then
  301. break
  302. end
  303. local heroList = combatData.list
  304. for _, heroUuid in pairs(heroList) do
  305. if heroUuid == checkHeroUuid then
  306. return cityId, pointIdx
  307. end
  308. end
  309. end
  310. end
  311. return
  312. end
  313. -- 是否是公会前二名
  314. local function isTopTwoUnion(human)
  315. local unionRanList = BillboardLogic.GetRankList(BillboardDefine.TYPE_UNION)
  316. if not unionRanList then
  317. return false
  318. end
  319. local unionId = human.db.unionUuid
  320. local isTopTwo = false
  321. for i=1, 2 do
  322. if unionRanList[i].uuid == unionId then
  323. isTopTwo = true
  324. break
  325. end
  326. end
  327. return isTopTwo
  328. end
  329. -- 是否处于战斗阶段
  330. local function isBattleStage()
  331. local wDay = getWDay()
  332. if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
  333. return true
  334. end
  335. return false
  336. end
  337. -- 重置在线玩家的防守数据
  338. local function resetDefData(playerInfoArr)
  339. for _, playerInfo in ipairs(playerInfoArr or {}) do
  340. local playerUuid = playerInfo[1]
  341. local human = ObjHuman.onlineUuid[playerUuid]
  342. if human then
  343. onLogin(human)
  344. end
  345. end
  346. end
  347. -- 获取公会/个人排行榜通用的奖励Id
  348. local function getRankGenericAwadId(rankRewardList, rankType)
  349. for _, v in ipairs(rankRewardList) do
  350. if v.nRankType == rankType then
  351. return v.Prize
  352. end
  353. end
  354. end
  355. -- 获取排名奖励
  356. local function getRankAward(rankRewardList, rankType, targetRank)
  357. for _, v in ipairs(rankRewardList) do
  358. if v.nRankType == rankType and (targetRank >= v.nOrder[1] and targetRank <= v.nOrder[2]) then
  359. return v.Prize
  360. end
  361. end
  362. end
  363. -- 生成奖励发放对象列表
  364. local function genAwardObjArr(unionOccupyInfo)
  365. local function calcMinute(timeArr)
  366. local minuteVal = 0
  367. for _, timeTb in ipairs(timeArr or {}) do
  368. local sec = (timeTb[2] or 0) - (timeTb[1] or 0)
  369. if sec > 0 then
  370. minuteVal = minuteVal + sec
  371. end
  372. end
  373. return math.floor(minuteVal / 60)
  374. end
  375. -- 没有玩家参与
  376. if not unionOccupyInfo.playerInfoArr or #unionOccupyInfo.playerInfoArr <= 0 then
  377. return
  378. end
  379. local itemList = {}
  380. local occupyCityInfo = {0,0,0,0,0}
  381. local item_185_Id = 185
  382. local item_185_Num = 0
  383. occupyCityInfo[1] = unionOccupyInfo.occuoyPointNum
  384. -- 额外奖励
  385. item_185_Num = item_185_Num + (unionOccupyInfo.occuoyPointNum or 0)
  386. for _, cityId in ipairs(unionOccupyInfo.occupyCityArr) do
  387. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  388. if cityCfg then
  389. if cityCfg.isBaseCity == 1 then
  390. item_185_Num = item_185_Num + 20
  391. else
  392. if cityCfg.cityLv == 2 then
  393. item_185_Num = item_185_Num + 2
  394. occupyCityInfo[2] = occupyCityInfo[2] + 1
  395. elseif cityCfg.cityLv == 3 then
  396. item_185_Num = item_185_Num + 3
  397. occupyCityInfo[3] = occupyCityInfo[3] + 1
  398. elseif cityCfg.cityLv == 4 then
  399. item_185_Num = item_185_Num + 5
  400. occupyCityInfo[4] = occupyCityInfo[4] + 1
  401. elseif cityCfg.cityLv == 5 then
  402. item_185_Num = item_185_Num + 20
  403. occupyCityInfo[5] = occupyCityInfo[5] + 1
  404. end
  405. end
  406. end
  407. end
  408. -- 占领据点每分钟的奖励
  409. for _, pointInfo in ipairs(unionOccupyInfo.point2CityIdArr) do
  410. local cityId = pointInfo[1]
  411. local occupyTimeArr = pointInfo[2]
  412. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  413. local totalMinVal = calcMinute(occupyTimeArr)
  414. if totalMinVal > 0 then
  415. local itemId, itemNum = cityCfg.cityAward[1], cityCfg.cityAward[2]
  416. itemList[itemId] = (itemList[itemId] or 0) + totalMinVal * itemNum
  417. end
  418. end
  419. if item_185_Num > 0 then
  420. itemList[item_185_Id] = item_185_Num
  421. end
  422. local itemArr = {}
  423. for itemId, itemNum in pairs(itemList) do
  424. itemArr[#itemArr+1] = { itemId, itemNum }
  425. end
  426. local rankReward = AnotherWorldBattleConfig.rankReward
  427. local awardObjArr = {}
  428. for _, playerInfo in ipairs(unionOccupyInfo.playerInfoArr) do
  429. local playerUuid = playerInfo[1]
  430. local playerRank = playerInfo[2]
  431. -- 据点每分钟奖励 + 额外奖励
  432. awardObjArr[#awardObjArr+1] = {playerUuid, itemArr, AnotherWorldBattleDefine.AB_AWARD_MAIL_ID}
  433. -- 公会排名奖励
  434. -- local itemId, itemNum = getRankAward(rankReward, 1, unionOccupyInfo.unionRank)
  435. -- if itemId and itemNum then
  436. -- awardObjArr[#awardObjArr+1] = {playerUuid, {{itemId, itemNum}}, AnotherWorldBattleDefine.AB_UNIONRANK_AWARD_MAIL_ID, unionOccupyInfo.unionRank}
  437. -- end
  438. local itemTb = getRankAward(rankReward, 1, unionOccupyInfo.unionRank)
  439. if itemTb then
  440. local items
  441. for _, itemInfo in ipairs(itemTb) do
  442. items = items or {}
  443. items[#items+1] = {itemInfo[1], itemInfo[2]}
  444. end
  445. if items then
  446. awardObjArr[#awardObjArr+1] = {playerUuid, items, AnotherWorldBattleDefine.AB_UNIONRANK_AWARD_MAIL_ID, unionOccupyInfo.unionRank}
  447. end
  448. end
  449. -- 玩家排名奖励
  450. -- local itemId2, itemNum2 = getRankAward(rankReward, 2, playerRank)
  451. -- if itemId2 and itemNum2 then
  452. -- awardObjArr[#awardObjArr+1] = {playerUuid, {{itemId2, itemNum2}}, AnotherWorldBattleDefine.AB_PLAYERRANK_AWARD_MAIL_ID, playerRank}
  453. -- end
  454. itemTb = getRankAward(rankReward, 2, playerRank)
  455. if itemTb then
  456. local items
  457. for _, itemInfo in ipairs(itemTb) do
  458. items = items or {}
  459. items[#items+1] = {itemInfo[1], itemInfo[2]}
  460. end
  461. if items then
  462. awardObjArr[#awardObjArr+1] = {playerUuid, items, AnotherWorldBattleDefine.AB_PLAYERRANK_AWARD_MAIL_ID, playerRank}
  463. end
  464. end
  465. end
  466. return awardObjArr, occupyCityInfo
  467. end
  468. -- 活动是否处于开启中
  469. function IsRuning(joinTime)
  470. if not joinTime then
  471. return true
  472. end
  473. local wDay = getWDay()
  474. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  475. return false
  476. end
  477. local now = os.time()
  478. local toDayStartTime = Util.getDayStartTime(now)
  479. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  480. return false
  481. end
  482. local diffDays = Util.diffDay(joinTime)
  483. -- local joinWday = Util.getWeekDay(joinTime)
  484. -- 如果是周六加入则相差6天, 如果是周日加入则相差5天。 当前时间与加入时间相差6或5天, 则都表示当前可能是活动最后一天, 如果当前时间 > 结束时间则活动结束
  485. -- if (diffDays == AnotherWorldBattleDefine.AB_OPEN_DAYS and joinWday == 7) or (diffDays == (AnotherWorldBattleDefine.AB_OPEN_DAYS-1) and joinWday == 1) then
  486. -- if now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  487. -- return false
  488. -- end
  489. -- end
  490. -- < 6天说明处于本轮活动开启时间范围, > 6天说明活动已经结束
  491. if diffDays > AnotherWorldBattleDefine.AB_OPEN_DAYS then
  492. return false
  493. end
  494. return true
  495. end
  496. --检测上阵英雄
  497. function checkUpdatePos(human, msg)
  498. local heroList = Util.split(msg.heroList, ",")
  499. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  500. local uuid = heroList[i] or ""
  501. if uuid ~= "0" and uuid ~= "" then
  502. if isDefHero(human, uuid) then
  503. return false
  504. end
  505. end
  506. end
  507. return true
  508. end
  509. -- 公会战力更新
  510. function UnionPowerChange(unionId, newPower)
  511. if not actStartTimeCheck() then
  512. return false
  513. end
  514. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  515. msgData.myUnionId = unionId
  516. msgData.updateData = {}
  517. msgData.updateData.power = newPower
  518. InnerMsg.sendMsg(0, msgData)
  519. end
  520. -- 玩家战力更新
  521. function PlayerPowerChange(human)
  522. if not baseCondCheck(human) then
  523. return false
  524. end
  525. if not actStartTimeCheck() then
  526. return false
  527. end
  528. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  529. msgData.playerUuid = human.db._id
  530. msgData.myUnionId = human.db.unionUuid
  531. msgData.updateData = {}
  532. msgData.updateData.power = human.db.zhandouli
  533. InnerMsg.sendMsg(0, msgData)
  534. end
  535. -- 英雄更新
  536. function HeroDataUpdate(human, heroUuid)
  537. if not baseCondCheck(human) then
  538. return false
  539. end
  540. if not actStartTimeCheck() then
  541. return false
  542. end
  543. local cityId, pointIdx = isDefHero(human, heroUuid)
  544. if not cityId then
  545. return
  546. end
  547. HeroLogic = HeroLogic or require("hero.HeroLogic")
  548. local heroGrid = HeroLogic.getHeroGridByUuid(human, heroUuid)
  549. if heroGrid then
  550. RoleAttr.calcHeroGrid(heroGrid, nil, human)
  551. local heroInfo = {
  552. heroUuid = heroUuid,
  553. heroStar = heroGrid.star,
  554. heroLevel = heroGrid.lv,
  555. heroPower = heroGrid.zhandouli,
  556. }
  557. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_HERO
  558. msgData.playerUuid = human.db._id
  559. msgData.targetCityId = cityId
  560. msgData.targetPointIdx = pointIdx
  561. msgData.heroData = heroInfo
  562. InnerMsg.sendMsg(0, msgData)
  563. end
  564. end
  565. -- 玩家改名
  566. function PlayerChangeName(human)
  567. if not baseCondCheck(human) then
  568. return false
  569. end
  570. if not actStartTimeCheck() then
  571. return false
  572. end
  573. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  574. msgData.playerUuid = human.db._id
  575. msgData.myUnionId = human.db.unionUuid
  576. msgData.updateData = {}
  577. msgData.updateData.name = human.db.name
  578. InnerMsg.sendMsg(0, msgData)
  579. end
  580. -- 公会改名
  581. function UnionChangeName(unionId, newName)
  582. if not actStartTimeCheck() then
  583. return false
  584. end
  585. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  586. msgData.myUnionId = unionId
  587. msgData.updateData = {}
  588. msgData.updateData.name = newName
  589. InnerMsg.sendMsg(0, msgData)
  590. end
  591. function isDot(human)
  592. if not baseCondCheck(human) then
  593. return false
  594. end
  595. if not actStartTimeCheck() then
  596. return false
  597. end
  598. return true
  599. end
  600. function onLogin(human)
  601. formationDataCheeck(human)
  602. sendDefHeroArr(human)
  603. notifyTips(human)
  604. end
  605. -- 请求状态
  606. function AB_GetState(human, isTips)
  607. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_STATE
  608. msgData.sourceServerId = Config.SVR_INDEX
  609. msgData.playerUuid = human.db._id
  610. msgData.myUnionId = human.db.unionUuid or ""
  611. msgData.isTips = isTips and 1 or 0
  612. InnerMsg.sendMsg(0, msgData)
  613. end
  614. -- 报名
  615. function AB_Join(human)
  616. local unionId = human.db.unionUuid
  617. local msgRet = Msg.gc.GC_AB_JOIN
  618. if not unionId then
  619. msgRet.Joinstate = 3
  620. return Msg.send(msgRet, human.fd)
  621. end
  622. local wDay = getWDay()
  623. -- if wDay ~= AnotherWorldBattleDefine.AB_JOIN_WDAY then
  624. -- msgRet.Joinstate = 5
  625. -- return Msg.send(msgRet, human.fd)
  626. -- end
  627. if not table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  628. msgRet.Joinstate = 5
  629. return Msg.send(msgRet, human.fd)
  630. end
  631. -- 公会排名前二才能参加
  632. if not isTopTwoUnion(human) then
  633. msgRet.Joinstate = 2
  634. return Msg.send(msgRet, human.fd)
  635. end
  636. -- 会长/副会长才能报名
  637. if not UnionLogic.IsTopTwoManager(human, unionId) then
  638. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  639. end
  640. local queryFiles = {name = 1, zhandouli = 1}
  641. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  642. if not unionInfo then
  643. return Broadcast.sendErr(human, Lang.DATA_ERR)
  644. end
  645. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_JOIN
  646. msgData.sourceServerId = Config.SVR_INDEX
  647. msgData.playerUuid = human.db._id
  648. msgData.unionInfo = {
  649. name = unionInfo.name,
  650. power = unionInfo.zhandouli,
  651. unionId = unionId
  652. }
  653. InnerMsg.sendMsg(0, msgData)
  654. end
  655. -- 查询所有城池信息
  656. function AB_AllCity_Query(human)
  657. if not human.db.unionUuid then
  658. return
  659. end
  660. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  661. msgData.sourceServerId = Config.SVR_INDEX
  662. msgData.playerUuid = human.db._id
  663. msgData.myUnionId = human.db.unionUuid
  664. InnerMsg.sendMsg(0, msgData)
  665. -- 报名状态查询
  666. -- local msgData2 = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_JOIN_STATE
  667. -- msgData2.sourceServerId = Config.SVR_INDEX
  668. -- msgData2.playerUuid = human.db._id
  669. -- msgData2.myUnionId = human.db.unionUuid
  670. -- InnerMsg.sendMsg(0, msgData2)
  671. end
  672. -- 查询单个城池的详细信息
  673. function AB_CityDetailed_Query(human, targetCityId)
  674. if not AnotherWorldBattleConfig.city[targetCityId] then
  675. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  676. end
  677. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  678. msgData.sourceServerId = Config.SVR_INDEX
  679. msgData.playerUuid = human.db._id
  680. msgData.myUnionId = human.db.unionUuid
  681. msgData.targetCityId = targetCityId
  682. InnerMsg.sendMsg(0, msgData)
  683. end
  684. -- 查询某个城池的某个据点的详细信息
  685. function AB_PointDetailed_Query(human, targetCityId, targetPointIdx)
  686. if not AnotherWorldBattleConfig.city[targetCityId] then
  687. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  688. end
  689. if 0 >= targetPointIdx or AnotherWorldBattleDefine.AB_POINT_MAX_NUM < targetPointIdx then
  690. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  691. end
  692. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINTtDETAILED_QUERY
  693. msgData.sourceServerId = Config.SVR_INDEX
  694. msgData.playerUuid = human.db._id
  695. msgData.myUnionId = human.db.unionUuid
  696. msgData.targetCityId = targetCityId
  697. msgData.targetPointIdx = targetPointIdx
  698. InnerMsg.sendMsg(0, msgData)
  699. end
  700. -- 查询本公会出生点信息
  701. function AB_BaseCity_Query(human)
  702. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_BASECITY_QUERY
  703. msgData.sourceServerId = Config.SVR_INDEX
  704. msgData.playerUuid = human.db._id
  705. msgData.myUnionId = human.db.unionUuid
  706. InnerMsg.sendMsg(0, msgData)
  707. end
  708. -- 查询玩家占领的所有据点信息
  709. function AB_PlayerOccupyPOint_Query(human)
  710. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  711. msgData.sourceServerId = Config.SVR_INDEX
  712. msgData.playerUuid = human.db._id
  713. msgData.myUnionId = human.db.unionUuid
  714. InnerMsg.sendMsg(0, msgData)
  715. end
  716. -- 查询公会排行榜
  717. function AB_UnionRank_Query(human)
  718. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  719. msgData.sourceServerId = Config.SVR_INDEX
  720. msgData.playerUuid = human.db._id
  721. msgData.myUnionId = human.db.unionUuid
  722. InnerMsg.sendMsg(0, msgData)
  723. end
  724. -- 查询玩家排行榜
  725. function AB_PlayerRank_Query(human)
  726. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  727. msgData.sourceServerId = Config.SVR_INDEX
  728. msgData.playerUuid = human.db._id
  729. msgData.myUnionId = human.db.unionUuid
  730. InnerMsg.sendMsg(0, msgData)
  731. end
  732. -- 发起集结
  733. function AB_Gather(human, targetCityId, opType)
  734. if not AnotherWorldBattleConfig.city[targetCityId] then
  735. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  736. end
  737. if opType ~= 1 and opType ~= 2 then
  738. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  739. end
  740. local unionId = human.db.unionUuid
  741. if not unionId then
  742. return Broadcast.sendErr(human, Lang.AB_NO_UNION)
  743. end
  744. -- 会长/副会长才能集结
  745. if not UnionLogic.IsTopTwoManager(human, unionId) then
  746. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANAGER)
  747. end
  748. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GATHER
  749. msgData.sourceServerId = Config.SVR_INDEX
  750. msgData.playerUuid = human.db._id
  751. msgData.myUnionId = human.db.unionUuid
  752. msgData.targetCityId = targetCityId
  753. msgData.opType = opType
  754. InnerMsg.sendMsg(0, msgData)
  755. end
  756. -- 请求挑战某个据点
  757. function AB_TryChallengePoint(human, targetCityId, targetPointIdx)
  758. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  759. if not combatHero or not next(combatHero) then
  760. return Broadcast.sendErr(human, Lang.COMBAT_NEED_FIGHT_HERO)
  761. end
  762. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  763. msgData.sourceServerId = Config.SVR_INDEX
  764. msgData.playerUuid = human.db._id
  765. msgData.myUnionId = human.db.unionUuid
  766. msgData.targetCityId = targetCityId
  767. msgData.targetPointIdx = targetPointIdx
  768. InnerMsg.sendMsg(0, msgData)
  769. end
  770. -- 战斗结束
  771. local function challenge_End(human, args)
  772. local cityId = args.cityId
  773. local pointIdx = args.pointIdx
  774. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_CHALLENGE_END
  775. msgData.sourceServerId = Config.SVR_INDEX
  776. msgData.playerUuid = human.db._id
  777. msgData.myUnionId = human.db.unionUuid
  778. msgData.targetCityId = cityId
  779. msgData.targetPointIdx = pointIdx
  780. msgData.challengeRes = args.challengeRes
  781. -- 挑战没有胜利
  782. if args.challengeRes ~= CombatDefine.RESULT_WIN then
  783. -- 说明之前已经在跨服上保存玩家的基础数据了
  784. -- if human.db.anotherWorlBattle then
  785. -- return
  786. -- end
  787. msgData.playerShowInfo = {
  788. name = human.db.name,
  789. lv = human.db.lv,
  790. power = human.db.zhandouli,
  791. }
  792. return InnerMsg.sendMsg(0, msgData)
  793. end
  794. if not human.db.anotherWorlBattle then
  795. human.db.anotherWorlBattle = {
  796. startTime = os.time(),
  797. formation = {}
  798. }
  799. end
  800. -- 把当前战斗阵容数据保存到当前模块,作为防守阵容
  801. local combatData = CombatPosLogic.getCombatHeroDB(human, CombatDefine.COMBAT_TYPE35)
  802. local formationData = human.db.anotherWorlBattle.formation or {}
  803. formationData[cityId] = formationData[cityId] or {}
  804. formationData[cityId][pointIdx] = Util.copyTable(combatData)
  805. -- 把最新的防守英雄uuid列表推送给客户端
  806. sendDefHeroArr(human)
  807. --同步到跨服
  808. msgData.playerShowInfo = generateShowInfo(human)
  809. InnerMsg.sendMsg(0, msgData)
  810. -- 清空战斗阵容
  811. CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  812. end
  813. -- 更换据点的防守阵容
  814. function AB_UpdateLineup(human, msg)
  815. if not isBattleStage() then
  816. return Broadcast.sendErr(human, Lang.AB_NOT_BATTLE_TIME)
  817. end
  818. local anotherWorlBattle = human.db.anotherWorlBattle
  819. if not anotherWorlBattle or not anotherWorlBattle.formation then
  820. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  821. end
  822. local cityId = msg.cityId
  823. local pointIdx = msg.pointIdx
  824. local formationData = anotherWorlBattle.formation
  825. if not formationData[cityId] or not formationData[cityId][pointIdx] then
  826. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  827. end
  828. local res, heroList, helpList = CombatPosLogic.CheckUpdatePos(human, msg)
  829. if not res then
  830. return Broadcast.sendErr(human, Lang.COMBAT_POS__ERR)
  831. end
  832. local len = 0
  833. local heroArr = {}
  834. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  835. local uuid = heroList[i] or ""
  836. if uuid ~= "0" and uuid ~= "" then
  837. if isDefHero(human, uuid, cityId, pointIdx) then
  838. return Broadcast.sendErr(human, Lang.AB_HERO_IN_OTHER_POINT)
  839. end
  840. len = len + 1
  841. heroArr[len] = getHeroInfo(human, uuid)
  842. end
  843. end
  844. if len == 0 then
  845. return
  846. end
  847. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_POINT_LINEIP
  848. msgData.sourceServerId = Config.SVR_INDEX
  849. msgData.playerUuid = human.db._id
  850. msgData.heroArr = heroArr
  851. msgData.targetCityId = cityId
  852. msgData.targetPointIdx = pointIdx
  853. msgData.formation = msg.formation
  854. msgData.heroList = heroList
  855. msgData.helpList = helpList
  856. InnerMsg.sendMsg(0, msgData)
  857. end
  858. -- 放弃据点
  859. function AB_LeavePoint(human, msg)
  860. local targetCityId = msg.cityId
  861. if not AnotherWorldBattleConfig.city[targetCityId] then
  862. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  863. end
  864. local targetPointIdx = msg.pointIdx
  865. if targetPointIdx <= 0 or targetPointIdx > AnotherWorldBattleDefine.AB_POINT_MAX_NUM then
  866. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  867. end
  868. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_LEAVE_POINT
  869. msgData.sourceServerId = Config.SVR_INDEX
  870. msgData.playerUuid = human.db._id
  871. msgData.myUnionId = human.db.unionUuid
  872. msgData.targetCityId = targetCityId
  873. msgData.targetPointIdx = targetPointIdx
  874. InnerMsg.sendMsg(0, msgData)
  875. end
  876. --获取据点的防守阵容数据
  877. function AB_GetPointLineup(human, msg)
  878. local targetCityId = msg.cityId
  879. local targetPointIdx = msg.pointIdx
  880. local anotherWorlBattle = human.db.anotherWorlBattle
  881. local formationData = anotherWorlBattle.formation
  882. if not formationData[targetCityId] or not formationData[targetCityId][targetPointIdx] then
  883. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  884. end
  885. local extraArgs = {
  886. cityId = targetCityId,
  887. pointIdx = targetPointIdx
  888. }
  889. CombatPosLogic.posQuery(human, msg.type, msg.groupID, msg.param, 1, extraArgs)
  890. end
  891. -- 请求公会士气信息
  892. function AB_GetMyUnionMoraleInfo(human)
  893. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_MYUIONMORALE
  894. msgData.sourceServerId = Config.SVR_INDEX
  895. msgData.playerUuid = human.db._id
  896. msgData.myUnionId = human.db.unionUuid
  897. InnerMsg.sendMsg(0, msgData)
  898. end
  899. -- 给本公会加士气
  900. function AB_Morale_Do(human)
  901. local unionId = human.db.unionUuid
  902. if not UnionLogic.IsTopTwoManager(human, unionId) then
  903. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  904. end
  905. -- 先扣除道具
  906. local moraleCostCfg = AnotherWorldBattleConfig.var[1].moraleCost
  907. if not moraleCostCfg then
  908. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  909. end
  910. local itemId, itemNum = moraleCostCfg[1], moraleCostCfg[2]
  911. if BagLogic.getItemCnt(human, itemId) < itemNum then
  912. return Broadcast.sendErr(human, COMMON_ITEM_NOT_ENOUGH)
  913. end
  914. BagLogic.delItem(human, itemId, itemNum, LOGTAG)
  915. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UIONMORALE_DO
  916. msgData.sourceServerId = Config.SVR_INDEX
  917. msgData.playerUuid = human.db._id
  918. msgData.myUnionId = human.db.unionUuid
  919. InnerMsg.sendMsg(0, msgData)
  920. end
  921. -- 查询据点羁绊数据
  922. function AB_PointLine_JiBan_Query(human, msg)
  923. if not isBattleStage() then
  924. return
  925. end
  926. JibanLogic = JibanLogic or require("combat.JibanLogic")
  927. local extraArgs = {
  928. cityId = msg.cityId,
  929. pointIdx = msg.pointIdx,
  930. }
  931. JibanLogic.query(human, msg.combatType, msg.heroID, extraArgs)
  932. end
  933. -- 更新据点羁绊
  934. function AB_PointLine_JiBan_Update(human, msg)
  935. if not isBattleStage() then
  936. return
  937. end
  938. JibanLogic = JibanLogic or require("combat.JibanLogic")
  939. local extraArgs = {
  940. cityId = msg.cityId,
  941. pointIdx = msg.pointIdx,
  942. }
  943. JibanLogic.update(human, msg.combatType, msg.jibanList, msg.heroIdArr, extraArgs)
  944. end
  945. -- 查询据点精灵数据
  946. function AB_PointLine_Elf_Query(human, msg)
  947. if not isBattleStage() then
  948. return
  949. end
  950. local extraArgs = {
  951. cityId = msg.cityId,
  952. pointIdx = msg.pointIdx,
  953. }
  954. CombatPosLogic.Elf_Pos_Query(human, msg.combatType, extraArgs)
  955. end
  956. -- 更新据点精灵
  957. function AB_PointLine_Elf_Update(human, msg)
  958. if not isBattleStage() then
  959. return
  960. end
  961. local extraArgs = {
  962. cityId = msg.cityId,
  963. pointIdx = msg.pointIdx,
  964. }
  965. CombatPosLogic.Elf_Pos_Update(human, msg.combatType, msg.elfPosArr, extraArgs)
  966. end
  967. ------------------------------------C2N---------------------------------------------------
  968. -- 跨服通知活动开启
  969. function C2N_Act_Start(msg)
  970. local startTime = msg.startTime
  971. if not startTime or startTime == 0 then
  972. return
  973. end
  974. CommonDB.updateValue(CommonDB.KEY_ANOTHERWORLDBATTLE_START_TI, startTime)
  975. end
  976. -- 错误提示
  977. function C2N_ErrTips(msg)
  978. local human = ObjHuman.onlineUuid[msg.playerUuid]
  979. if not human then
  980. return
  981. end
  982. local tips = Lang.DATA_ERR
  983. local errCode = msg.errCode
  984. if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
  985. tips = Lang.AB_NOT_OPEN_TIME
  986. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
  987. tips = Lang.AB_NOT_UNION_NUM_EXCEED
  988. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
  989. tips = Lang.AB_UNION_NO_JOIN
  990. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
  991. tips = Lang.DATA_ERR
  992. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
  993. tips = Lang.AB_NOT_OCCUPY_POINT
  994. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
  995. tips = Lang.AB_GATHER_CD
  996. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
  997. tips = Lang.AB_CITY_NOT_ADDJION
  998. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
  999. tips = Lang.AB_JOINED
  1000. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_9 then
  1001. tips = Lang.AB_CITY_NO_GATHER
  1002. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_10 then
  1003. tips = Lang.AB_OCCUPY_POINT_MAX
  1004. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_11 then
  1005. tips = Lang.AB_POINT_CHALLENGING
  1006. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_12 then
  1007. tips = Lang.AB_CHALLENGING_TIMES_NOT_ENOUGH
  1008. end
  1009. Broadcast.sendErr(human, tips)
  1010. end
  1011. -- 跨服返回状态
  1012. function C2N_State_Response(msg)
  1013. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1014. if not human then
  1015. return
  1016. end
  1017. -- 只用于弹出提示框
  1018. if msg.isTips and msg.isTips == 1 then
  1019. if (msg.systemState > 0 and msg.systemState <= 2) and msg.joinState <= 1 then
  1020. local msgRet = Msg.gc.GC_AB_TIPS
  1021. Msg.send(msgRet, human.fd)
  1022. end
  1023. return
  1024. end
  1025. local msgRet = Msg.gc.GC_AB_GetState
  1026. msgRet.joinState = msg.joinState
  1027. msgRet.systemState = msg.systemState
  1028. if msgRet.joinState == 0 then
  1029. local unionId = human.db.unionUuid
  1030. if not unionId then
  1031. msgRet.Joinstate = 2
  1032. return Msg.send(msgRet, human.fd)
  1033. end
  1034. -- 公会排名前二才行
  1035. if not isTopTwoUnion(human) then
  1036. msgRet.Joinstate = 2
  1037. return Msg.send(msgRet, human.fd)
  1038. end
  1039. end
  1040. Msg.send(msgRet, human.fd)
  1041. end
  1042. -- 报名成功
  1043. function C2N_Join_Response(msg)
  1044. local now = os.time()
  1045. local unionId = msg.myUnionId
  1046. UnionLogic.UpdateJoinAbTime(unionId, now)
  1047. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1048. if not human then
  1049. return
  1050. end
  1051. local msgRet = Msg.gc.GC_AB_JOIN
  1052. msgRet.Joinstate = 1
  1053. Msg.send(msgRet, human.fd)
  1054. end
  1055. -- 跨服返回的所有城池数据
  1056. function C2N_AllCity_Response(msg)
  1057. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1058. if not human then
  1059. return
  1060. end
  1061. local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
  1062. msgRet.myBaseCityId = msg.myUnionBaseCityId
  1063. msgRet.hasPointNum = msg.hasPointNum
  1064. msgRet.challengeTimes = msg.challengeTimes
  1065. local now = os.time()
  1066. msgRet.leftTime = msg.lastTime
  1067. if msgRet.leftTime ~= 0 then
  1068. msgRet.leftTime = (msg.lastTime + AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC) - now
  1069. end
  1070. msgRet.cityArr[0] = 0
  1071. local cityArrMsg = msgRet.cityArr
  1072. for cityId, cityInfo in ipairs(msg.cityArr) do
  1073. cityArrMsg[0] = cityId
  1074. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1075. cityArrMsg[cityId].cityId = cityId
  1076. cityArrMsg[cityId].cityName = cityCfg.cityName
  1077. cityArrMsg[cityId].cityLv = cityCfg.cityLv
  1078. cityArrMsg[cityId].occupyPointNum = cityInfo.occupyPointNum or 0
  1079. cityArrMsg[cityId].occupyUnionName = cityInfo.occupyUnionName or ""
  1080. cityArrMsg[cityId].cityState = cityInfo.cityState
  1081. cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
  1082. for i, cId in ipairs(cityCfg.adJoinCityArr) do
  1083. cityArrMsg[cityId].adJoinCityArr[i] = cId
  1084. end
  1085. end
  1086. msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
  1087. for i, cityId in ipairs(msg.myOccupyCityArr) do
  1088. msgRet.myOccupyCityArr[i] = cityId
  1089. end
  1090. -- 据点每分钟的奖励
  1091. local itemId, itemNum = 0, 0
  1092. local cityCfg = AnotherWorldBattleConfig.city[1]
  1093. itemId = cityCfg.cityAward[1]
  1094. for _, pointInfo in ipairs(msg.occupyPointData) do
  1095. local cityId = pointInfo[1]
  1096. local occupyTimeArr = pointInfo[2]
  1097. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1098. local minuteVal = 0
  1099. for _, timeTb in ipairs(occupyTimeArr) do
  1100. local sec = (timeTb[2] or now) - (timeTb[1] or now)
  1101. if sec > 0 then
  1102. minuteVal = minuteVal + sec
  1103. end
  1104. minuteVal = math.floor(minuteVal / 60)
  1105. end
  1106. itemNum = itemNum + minuteVal * cityCfg.cityAward[2]
  1107. end
  1108. Grid.makeItem(msgRet.myUnionAward, itemId, itemNum)
  1109. Msg.send(msgRet, human.fd)
  1110. end
  1111. -- 跨服返回某个城池详细数据
  1112. function C2N_CityDetailed_Response(msg)
  1113. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1114. if not human then
  1115. return
  1116. end
  1117. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  1118. local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
  1119. msgRet.cityId = msg.targetCityId
  1120. msgRet.cityLv = cityCfg.cityLv
  1121. msgRet.cityIconId = cityCfg.cityIconId
  1122. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM )
  1123. local myUnionAwardNum = calcPointAward(msg.myUnionOccupyArr)
  1124. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  1125. -- 活动没有进入战斗阶段时, 使用默认数据
  1126. if #msg.pointArr == 0 then
  1127. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  1128. msg.pointArr[i] = {}
  1129. end
  1130. end
  1131. msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  1132. for pointIdx, pointInfo in ipairs(msg.pointArr) do
  1133. if pointInfo.occupyUnionName then
  1134. msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
  1135. msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
  1136. msgRet.pointArr[pointIdx].power = pointInfo.power
  1137. msgRet.pointArr[pointIdx].state = pointInfo.state
  1138. else
  1139. msgRet.pointArr[pointIdx].occupyUnionName = ""
  1140. msgRet.pointArr[pointIdx].occupyPlayerName = AnotherWorldBattleDefine.AB_DEF_NAME_STR.. pointIdx
  1141. msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
  1142. msgRet.pointArr[pointIdx].state = pointInfo.state
  1143. end
  1144. end
  1145. msgRet.gatherState = msg.gatherState
  1146. if msg.gatherState == 1 then
  1147. -- 公会会长/副会长才能集结
  1148. if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
  1149. msgRet.gatherState = 0
  1150. end
  1151. end
  1152. msgRet.gatherLeftTime = msg.gatherTime
  1153. if msg.gatherTime ~= -1 then
  1154. local now = os.time()
  1155. local subSec = msg.gatherTime + AnotherWorldBattleDefine.AB_GATHER_CD_SEC - now
  1156. msgRet.gatherLeftTime = subSec > 0 and subSec or 0
  1157. end
  1158. Msg.send(msgRet, human.fd)
  1159. end
  1160. -- 跨服返回某个据点数据
  1161. function C2N_PointDetailed_Response(msg)
  1162. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1163. if not human then
  1164. return
  1165. end
  1166. local pointInfo = msg.pointInfo
  1167. local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
  1168. msgRet.state = pointInfo.state
  1169. if pointInfo.name then
  1170. msgRet.name = pointInfo.name
  1171. msgRet.power = pointInfo.power
  1172. msgRet.head = pointInfo.head
  1173. msgRet.headFrame = pointInfo.headFrame
  1174. msgRet.defLv = pointInfo.defLv
  1175. msgRet.heroArr[0] = #pointInfo.heroArr
  1176. for i, heroInfo in ipairs(pointInfo.heroArr) do
  1177. msgRet.heroArr[i].heroBody = heroInfo.heroBody
  1178. msgRet.heroArr[i].heroStar = heroInfo.heroStar
  1179. msgRet.heroArr[i].heroLv = heroInfo.heroLv
  1180. msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
  1181. msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
  1182. msgRet.heroArr[i].heroId = heroInfo.heroId
  1183. msgRet.heroArr[i].heroQuality = heroInfo.heroQuality
  1184. end
  1185. else
  1186. msgRet.name = AnotherWorldBattleDefine.AB_DEF_NAME_STR .. msg.targetPointIdx
  1187. msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
  1188. msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
  1189. msgRet.defLv = 200
  1190. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  1191. msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
  1192. msgRet.heroArr[0] = 0
  1193. local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
  1194. for idx, monsterInfo in ipairs(monsterOutConfig.member) do
  1195. if idx > 6 then
  1196. break
  1197. end
  1198. msgRet.heroArr[0] = idx
  1199. local monsterID = monsterInfo[1]
  1200. local mcf = MonsterExcel.monster[monsterID]
  1201. msgRet.heroArr[idx].heroBody = mcf.body
  1202. msgRet.heroArr[idx].heroStar = mcf.star
  1203. msgRet.heroArr[idx].heroLv = monsterInfo[2]
  1204. msgRet.heroArr[idx].heroCamp = mcf.camp
  1205. msgRet.heroArr[idx].heroIcon = mcf.head
  1206. msgRet.heroArr[idx].heroId = monsterID
  1207. msgRet.heroArr[idx].heroQuality = mcf.heroQuality or 1
  1208. end
  1209. end
  1210. Msg.send(msgRet, human.fd)
  1211. end
  1212. -- 跨服返回公会出生点数据
  1213. function C2N_BaseCity_Response(msg)
  1214. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1215. if not human then
  1216. return
  1217. end
  1218. local baseCityInfo = msg.baseCityInfo
  1219. local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
  1220. local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
  1221. msgRet.cityIconId = cityCfg.cityIconId
  1222. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM)
  1223. local myUnionAwardNum = calcPointAward(baseCityInfo.myUnionOccupyArr)
  1224. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  1225. msgRet.cityIconId = baseCityInfo.occupyPointNum
  1226. msgRet.occupyPointNum = baseCityInfo.occupyPointNum
  1227. msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
  1228. msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
  1229. msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
  1230. msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
  1231. Msg.send(msgRet, human.fd)
  1232. end
  1233. -- 跨服返回玩家占领的据点数据
  1234. function C2N_PlayerOccupyPoint_Response(msg)
  1235. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1236. if not human then
  1237. return
  1238. end
  1239. local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
  1240. local myPointArr = msgRet.myPointArr
  1241. myPointArr[0] = 0
  1242. for idx, pointInfo in ipairs(msg.occupyPointArr) do
  1243. myPointArr[0] = idx
  1244. local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
  1245. myPointArr[idx].cityIconId = cityCfg.cityIconId
  1246. myPointArr[idx].cityName = cityCfg.cityName
  1247. myPointArr[idx].cityLv = cityCfg.cityLv
  1248. myPointArr[idx].pointIdx = pointInfo.pointIdx
  1249. myPointArr[idx].power = pointInfo.power
  1250. myPointArr[idx].cityId = pointInfo.cityId
  1251. myPointArr[idx].heroArr[0] = #pointInfo.heroArr
  1252. for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
  1253. local hero = myPointArr[idx].heroArr[heroIdx]
  1254. hero.heroBody = heroInfo.heroBody
  1255. hero.heroStar = heroInfo.heroStar
  1256. hero.heroLv = heroInfo.heroLv
  1257. hero.heroCamp = heroInfo.heroCamp
  1258. hero.heroIcon = heroInfo.heroIcon
  1259. hero.heroId = heroInfo.heroId
  1260. hero.heroQuality = heroInfo.heroQuality
  1261. end
  1262. end
  1263. Msg.send(msgRet, human.fd)
  1264. end
  1265. -- 跨服返回集结/取消集结成功
  1266. function C2N_Gather_Response(msg)
  1267. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1268. if not human then
  1269. return
  1270. end
  1271. local targetCityId = msg.targetCityId
  1272. local cityCfg = AnotherWorldBattleConfig.city[targetCityId]
  1273. local msgRet = Msg.gc.GC_AB_GARHER
  1274. msgRet.cityId = targetCityId
  1275. msgRet.cityName = cityCfg.cityName
  1276. msgRet.opType = msg.opType
  1277. Msg.send(msgRet, human.fd)
  1278. end
  1279. --跨服返回公会排行榜数据
  1280. function C2N_UnionRank_Response(msg)
  1281. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1282. if not human then
  1283. return
  1284. end
  1285. -- local itemId, itemNum = 184, 0
  1286. local rankReward = AnotherWorldBattleConfig.rankReward
  1287. local itemArr = getRankGenericAwadId(rankReward, 1)
  1288. local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
  1289. msgRet.unionRankArr[0] = 0
  1290. msgRet.myUnionRank = msg.myUnionRank
  1291. msgRet.myData.name = ""
  1292. msgRet.myData.power = 0
  1293. msgRet.myData.cityNum = 0
  1294. msgRet.myData.pointNum = 0
  1295. msgRet.myData.rankAward[0] = 0
  1296. for i, itemInfo in ipairs(itemArr or {}) do
  1297. msgRet.myData.rankAward[0] = i
  1298. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1299. end
  1300. for rank, rankdData in ipairs(msg.unionRankArr) do
  1301. msgRet.unionRankArr[0] = rank
  1302. msgRet.unionRankArr[rank].name = rankdData.name
  1303. msgRet.unionRankArr[rank].power = rankdData.power
  1304. msgRet.unionRankArr[rank].cityNum = rankdData.cityNum
  1305. msgRet.unionRankArr[rank].pointNum = rankdData.pointNum
  1306. -- Grid.makeItem(msgRet.unionRankArr[rank].rankAward, itemId, itemNum)
  1307. msgRet.unionRankArr[rank].rankAward[0] = 0
  1308. itemArr = getRankAward(rankReward, 1, rank)
  1309. for i, itemInfo in ipairs(itemArr or {}) do
  1310. msgRet.unionRankArr[rank].rankAward[0] = i
  1311. Grid.makeItem(msgRet.unionRankArr[rank].rankAward[i], itemInfo[1], itemInfo[2])
  1312. end
  1313. if rank == msg.myUnionRank then
  1314. msgRet.myData.name = rankdData.name
  1315. msgRet.myData.power = rankdData.power
  1316. msgRet.myData.cityNum = rankdData.cityNum
  1317. msgRet.myData.pointNum = rankdData.pointNum
  1318. -- Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1319. msgRet.myData.rankAward[0] = 0
  1320. for i, itemInfo in ipairs(itemArr or {}) do
  1321. msgRet.myData.rankAward[0] = i
  1322. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1323. end
  1324. end
  1325. end
  1326. if msgRet.myData.power == 0 then
  1327. local unionId = human.db.unionUuid
  1328. local queryFiles = {name = 1, zhandouli = 1}
  1329. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  1330. msgRet.myData.name = unionInfo and unionInfo.name or ""
  1331. msgRet.myData.power = unionInfo and unionInfo.zhandouli or 0
  1332. end
  1333. Msg.send(msgRet, human.fd)
  1334. end
  1335. --跨服返回玩家排行榜数据
  1336. function C2N_PlayerRank_Response(msg)
  1337. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1338. if not human then
  1339. return
  1340. end
  1341. -- local itemId, itemNum = 184, 0
  1342. local rankReward = AnotherWorldBattleConfig.rankReward
  1343. local itemArr = getRankGenericAwadId(rankReward, 2)
  1344. local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
  1345. msgRet.playerRankArr[0] = 0
  1346. msgRet.myRank = msg.myRank
  1347. msgRet.myData.name = human.db.name
  1348. msgRet.myData.power = human.db.zhandouli
  1349. msgRet.myData.pointNum = 0
  1350. msgRet.myData.pointWeight = 0
  1351. msgRet.myData.rankAward[0] = 0
  1352. for i, itemInfo in ipairs(itemArr or {}) do
  1353. msgRet.myData.rankAward[0] = i
  1354. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1355. end
  1356. for rank, rankdData in ipairs(msg.playerRankArr) do
  1357. msgRet.playerRankArr[0] = rank
  1358. msgRet.playerRankArr[rank].name = rankdData.name
  1359. msgRet.playerRankArr[rank].power = rankdData.power
  1360. msgRet.playerRankArr[rank].pointNum = rankdData.pointNum
  1361. msgRet.playerRankArr[rank].pointWeight = rankdData.pointWeight
  1362. -- itemId, itemNum = getRankAward(rankReward, 2, rank)
  1363. -- Grid.makeItem(msgRet.playerRankArr[rank].rankAward, itemId, itemNum)
  1364. itemArr = getRankAward(rankReward, 2, rank)
  1365. msgRet.playerRankArr[rank].rankAward[0] = 0
  1366. for i, itemInfo in ipairs(itemArr or {}) do
  1367. msgRet.playerRankArr[rank].rankAward[0] = i
  1368. Grid.makeItem(msgRet.playerRankArr[rank].rankAward[i], itemInfo[1], itemInfo[2])
  1369. end
  1370. if rank == msg.myRank then
  1371. msgRet.myData.pointNum = rankdData.pointNum
  1372. msgRet.myData.pointWeight = rankdData.pointWeight
  1373. -- Grid.makeItem(msgRet.myData.rankAward, itemId, itemNum)
  1374. msgRet.myData.rankAward[0] = 0
  1375. for i, itemInfo in ipairs(itemArr or {}) do
  1376. msgRet.myData.rankAward[0] = i
  1377. Grid.makeItem(msgRet.myData.rankAward[i], itemInfo[1], itemInfo[2])
  1378. end
  1379. end
  1380. end
  1381. Msg.send(msgRet, human.fd)
  1382. end
  1383. -- 跨服返回要挑战的据点的数据(据点可以被挑战)
  1384. function C2N_TryChallengePoint_Response(msg)
  1385. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1386. if not human then
  1387. return
  1388. end
  1389. local pointInfo = msg.pointInfo
  1390. human.AB_Battle_Cache = {
  1391. isGather = pointInfo.isGather,
  1392. cityId = pointInfo.targetCityId,
  1393. pointIdx = pointInfo.targetPointIdx,
  1394. defMoraleAttrIdx = pointInfo.defMoraleAttrIdx,
  1395. atkMoraleAttrIdx = pointInfo.atkMoraleAttrIdx,
  1396. }
  1397. if pointInfo.occupySrvId then -- 玩家占领
  1398. local args = {
  1399. combatType = CombatDefine.COMBAT_TYPE35,
  1400. nServerIndex = pointInfo.occupySrvId,
  1401. param = pointInfo.occupyPlayerUuid,
  1402. extraArgs = {
  1403. cityId = pointInfo.targetCityId,
  1404. pointIdx = pointInfo.targetPointIdx,
  1405. useDef = true,
  1406. }
  1407. }
  1408. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
  1409. else
  1410. -- 机器人
  1411. CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
  1412. end
  1413. end
  1414. -- 跨服通知据点被别的玩家占领了
  1415. function C2N_PointLose_Response(msg)
  1416. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1417. if not human then
  1418. local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
  1419. if not db then
  1420. return
  1421. end
  1422. human = {}
  1423. human.db = db
  1424. end
  1425. -- 更新防守阵容数据
  1426. local loseCityId = msg.loseCityId
  1427. local losePointIdx = msg.losePointIdx
  1428. local formationData = human.db.anotherWorlBattle.formation
  1429. formationData[loseCityId][losePointIdx] = nil
  1430. -- 玩家不在线, 手动保存数据
  1431. if not human.fd then
  1432. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1433. end
  1434. local cityCfg = AnotherWorldBattleConfig.city[loseCityId]
  1435. -- 发邮件
  1436. local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
  1437. local content = Util.format(mailCfg.content, cityCfg and cityCfg.cityName or "", loseCityId)
  1438. MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, content, nil, mailCfg.senderName or "GM")
  1439. -- 把最新的防守阵容数据推给客户端
  1440. if human.fd then
  1441. sendDefHeroArr(human)
  1442. end
  1443. end
  1444. -- 跨服通知可以更换据点的防守阵容数据
  1445. function C2N_UpdatePointLineup_Response(msg)
  1446. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1447. if not human then
  1448. local db = RoleDBLogic.getDb(msg.playerUuid)
  1449. if not db then
  1450. return
  1451. end
  1452. human = {}
  1453. human.db = db
  1454. end
  1455. local anotherWorlBattle = human.db.anotherWorlBattle
  1456. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1457. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  1458. end
  1459. local cityId = msg.targetCityId
  1460. local pointIdx = msg.targetPointIdx
  1461. if not anotherWorlBattle.formation[cityId] or not anotherWorlBattle.formation[cityId][pointIdx] then
  1462. return
  1463. end
  1464. local pointLinupData = anotherWorlBattle.formation[cityId][pointIdx]
  1465. pointLinupData.list = msg.heroList
  1466. pointLinupData.helpList = msg.helpList
  1467. pointLinupData.formation = msg.formation
  1468. if not human.fd then
  1469. ObjHuman.save(human)
  1470. end
  1471. sendDefHeroArr(human)
  1472. Broadcast.sendCenter(human, Lang.AB_UPDATE_LINEUP_SUCC)
  1473. end
  1474. -- 跨服通知放弃据点成功
  1475. function C2N_LeavePoint_Response(msg)
  1476. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1477. if not human then
  1478. local db = RoleDBLogic.getDb(msg.playerUuid)
  1479. if not db then
  1480. return
  1481. end
  1482. human = {}
  1483. human.db = db
  1484. end
  1485. local anotherWorlBattle = human.db.anotherWorlBattle
  1486. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1487. return
  1488. end
  1489. local cityId = msg.targetCityId
  1490. local pointIdx = msg.targetPointIdx
  1491. anotherWorlBattle.formation[cityId][pointIdx] = nil
  1492. if not next(anotherWorlBattle.formation[cityId]) then
  1493. anotherWorlBattle.formation[cityId] = nil
  1494. end
  1495. -- 玩家不在线, 手动保存数据
  1496. if not human.fd then
  1497. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1498. else
  1499. -- 把最新的防守阵容数据推给客户端
  1500. sendDefHeroArr(human)
  1501. end
  1502. end
  1503. -- 跨服返回本公会士气信息
  1504. function C2N_MyUnionMoraleInfo_Response(msg)
  1505. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1506. if not human then
  1507. return
  1508. end
  1509. local varCfg = AnotherWorldBattleConfig.var[1]
  1510. local msgRet = Msg.gc.GC_AB_GET_MORALE_INFO
  1511. msgRet.moraleState = msg.moraleState
  1512. msgRet.leftTime = 0
  1513. local now = os.time()
  1514. local leftTime = msg.moraleStartTime + AnotherWorldBattleDefine.AB_MORALE_DURATION - now
  1515. if leftTime > 0 then
  1516. msgRet.leftTime = leftTime
  1517. end
  1518. local itemCfg = varCfg.moraleCost
  1519. local itemId = itemCfg and itemCfg[1] or 101
  1520. local itemNum = itemCfg and itemCfg[2] or 0
  1521. Grid.makeItem(msgRet.moraleCost, itemId, itemNum)
  1522. msgRet.moraleAttrs[0] = 0
  1523. local moraleAttrCfg = varCfg.moraleAtrrs
  1524. if moraleAttrCfg then
  1525. local attrArr = moraleAttrCfg[msg.moraleAttrIdx] or moraleAttrCfg[1]
  1526. for i, attrTb in ipairs(attrArr) do
  1527. msgRet.moraleAttrs[0] = i
  1528. msgRet.moraleAttrs[i].key = attrTb[1]
  1529. msgRet.moraleAttrs[i].value = attrTb[2]
  1530. end
  1531. end
  1532. Msg.send(msgRet, human.fd)
  1533. end
  1534. -- 跨服返回加士气结果
  1535. function C2N_UnionMorale_Response(msg)
  1536. if msg.opRes == 0 then
  1537. return
  1538. end
  1539. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1540. if not human then
  1541. local db = RoleDBLogic.getDb(msg.playerUuid)
  1542. if not db then
  1543. return
  1544. end
  1545. human = {}
  1546. human.db = db
  1547. end
  1548. local moraleCostCfg = AnotherWorldBattleConfig.var[1].moraleCost
  1549. local itemId, itemNum = moraleCostCfg[1], moraleCostCfg[2]
  1550. BagLogic.addItem(human, itemId, itemNum, LOGTAG)
  1551. if not human.fd then
  1552. ObjHuman.save(human)
  1553. end
  1554. end
  1555. -- 跨服通知给玩家发奖
  1556. function C2N_IssueReward(msg)
  1557. -- 删除公会参加异界之战活动时间
  1558. UnionLogic.UpdateJoinAbTime(msg.unionOccupyInfo.unionId, nil)
  1559. resetDefData(msg.unionOccupyInfo.playerInfoArr)
  1560. -- 发奖
  1561. local awardObjArr, occupyCityInfo = genAwardObjArr(msg.unionOccupyInfo)
  1562. if awardObjArr then
  1563. local issueRewardQueue = createRewardQueue()
  1564. issueRewardQueue.extraInfo = occupyCityInfo
  1565. for _, obj in ipairs(awardObjArr) do
  1566. issueRewardQueue:add(obj)
  1567. end
  1568. issueRewardQueue:insertDB()
  1569. end
  1570. end
  1571. -------------------------------------------战斗---------------------------------
  1572. function getCombatMonsterOutID(human, side, args)
  1573. if side ~= CombatDefine.DEFEND_SIDE then return end
  1574. local cityId = args[2]
  1575. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1576. return cityCfg and cityCfg.pointMonsterId
  1577. end
  1578. function getCombatObjList(human, side, args, combatType, extraArgs)
  1579. if side == CombatDefine.ATTACK_SIDE and not human then return end
  1580. if side == CombatDefine.DEFEND_SIDE and human then
  1581. return
  1582. end
  1583. if not human then
  1584. local uuid = args[1]
  1585. local db = RoleDBLogic.getDb(uuid)
  1586. if not db then
  1587. return
  1588. end
  1589. human = {}
  1590. human.db = db
  1591. end
  1592. return CombatLogic.getHumanObjList(human, combatType, extraArgs)
  1593. end
  1594. function getCombatHeros(human, combatType, args)
  1595. if not human.db.anotherWorlBattle then
  1596. return
  1597. end
  1598. if not args then
  1599. return
  1600. end
  1601. local formation = human.db.anotherWorlBattle.formation
  1602. if not formation then
  1603. return
  1604. end
  1605. local cityId, pointIdx = args.cityId, args.pointIdx
  1606. if formation[cityId] and formation[cityId][pointIdx] then
  1607. local combatHeroDB = formation[cityId][pointIdx]
  1608. return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
  1609. end
  1610. end
  1611. function onFightBegin(human, cbParam, combatType, param)
  1612. if not human.AB_Battle_Cache or (not human.AB_Battle_Cache.isGather and not human.AB_Battle_Cache.defMoraleAttrIdx and not human.AB_Battle_Cache.atkMoraleAttrIdx) then
  1613. return
  1614. end
  1615. local function addAttr(obj, attrs)
  1616. for _, atrrTb in ipairs(attrs or {}) do
  1617. local attrId, attrVal = atrrTb[1], atrrTb[2]
  1618. obj.sysAttr[attrId] = (obj.sysAttr[attrId] or 0) + attrVal
  1619. end
  1620. end
  1621. local atkGatherAttrs, atkMoraleAttrs, defMoraleAttrs
  1622. local varCfg = AnotherWorldBattleConfig.var[1]
  1623. if human.AB_Battle_Cache.isGather then
  1624. atkGatherAttrs = varCfg.gatherAttrs
  1625. end
  1626. if human.AB_Battle_Cache.atkMoraleAttrIdx then
  1627. local idx = human.AB_Battle_Cache.atkMoraleAttrIdx
  1628. atkMoraleAttrs = varCfg.moraleAtrrs and varCfg.moraleAtrrs[idx]
  1629. end
  1630. if human.AB_Battle_Cache.defMoraleAttrIdx then
  1631. local idx = human.AB_Battle_Cache.defMoraleAttrIdx
  1632. defMoraleAttrs = varCfg.moraleAtrrs and varCfg.moraleAtrrs[idx]
  1633. end
  1634. for index = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  1635. local side = index > CombatDefine.COMBAT_HERO_CNT and CombatDefine.DEFEND_SIDE or CombatDefine.ATTACK_SIDE
  1636. local realPos = CombatLogic.getPos(side, index)
  1637. local obj = CombatImpl.objList[realPos]
  1638. if obj then
  1639. if side == CombatDefine.ATTACK_SIDE then
  1640. if atkGatherAttrs or atkMoraleAttrs then
  1641. addAttr(obj, atkGatherAttrs)
  1642. addAttr(obj, atkMoraleAttrs)
  1643. obj.isSysAttrChange = true
  1644. end
  1645. else
  1646. if defMoraleAttrs then
  1647. addAttr(obj, defMoraleAttrs)
  1648. obj.isSysAttrChange = true
  1649. end
  1650. end
  1651. end
  1652. end
  1653. end
  1654. function onFightEnd(human, result, type, cbParam, combatInfo)
  1655. -- if result == CombatDefine.RESULT_WIN then
  1656. -- challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
  1657. -- end
  1658. local args = {
  1659. cityId = human.AB_Battle_Cache.cityId,
  1660. pointIdx = human.AB_Battle_Cache.pointIdx,
  1661. challengeRes = result
  1662. }
  1663. human.AB_Battle_Cache = nil
  1664. challenge_End(human, args)
  1665. end