AnotherWorldBattleNS.lua 65 KB

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