AnotherWorldBattleNS.lua 64 KB

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