HuanjingTowerLogic.lua 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. --
  2. -- human.db.tower.tili
  3. -- human.db.tower.ts
  4. -- human.db.tower.rewards
  5. -- human.db.tower.lv
  6. -- human.db.tower.usetime
  7. local Lang = require("common.Lang")
  8. local Util = require("common.Util")
  9. local Msg = require("core.Msg")
  10. local LuaMongo = _G.lua_mongo
  11. local DB = require("common.DB")
  12. local ObjHuman = require("core.ObjHuman")
  13. local HuanjingTowerExcel = require("excel.huanjingTower")
  14. local MonsterExcel = require("excel.monster")
  15. local Broadcast = require("broadcast.Broadcast")
  16. local CombatDefine = require("combat.CombatDefine")
  17. local CombatLogic = require("combat.CombatLogic")
  18. local CombatVideo = require("combat.CombatVideo")
  19. local BagLogic = require("bag.BagLogic")
  20. local Grid = require("bag.Grid")
  21. local ItemDefine = require("bag.ItemDefine")
  22. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  23. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  24. local BattleLogic = require("battle.BattleLogic")
  25. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  26. local RoleLogic = require("role.RoleLogic")
  27. local BRoleLogic = require("billboard.BRoleLogic")
  28. local BillboardDefine = require("billboard.BillboardDefine")
  29. local Log = require("common.Log")
  30. local TuiSongLiBao = require("present.TuiSongLiBao")
  31. local HuanjingTowerDB = require("huanjingTower.HuanjingTowerDB")
  32. local VipLogic = require("vip.VipLogic")
  33. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  34. local LiLianLogic = require("dailyTask.LiLianLogic")
  35. local HeroGrid = require("hero.HeroGrid")
  36. local BillboardDB = require("billboard.BillboardDB")
  37. local BillboardDefine = require("billboard.BillboardDefine")
  38. local BuyLogic = require("topup.BuyLogic")
  39. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  40. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  41. local JibanLogic = require("combat.JibanLogic")
  42. local RoleDBLogic = require("role.RoleDBLogic")
  43. local MengxinLogic = require("present.MengxinLogic")
  44. local YunYingLogic = require("yunying.YunYingLogic")
  45. local GiftLogic = require("topup.GiftLogic")
  46. local WarOrder = require("shop.WarOrder")
  47. TOWER_LV_HEAD_MAX = 15 -- 每层 储存 玩家头像数据
  48. TILI_MAX_CNT = 10 -- 最大体力
  49. BUY_TILI_ITEM_ID = 102 -- 购买体力花费的物品ID
  50. BUY_TILI_ITEM_CNT = 20 -- 购买一次体力所需的钻石
  51. TILI_RECOVER_TIME = 1800 -- 体力恢复时间
  52. BUY_TILI_BUY_ZUANSHI = {20, 30, 40}
  53. TILI_FREE = 2 -- 每天最大 免费次数
  54. -- 奖励状态
  55. REWARD_STATUS_NONE = 0 -- 不可领
  56. REWARD_STATUS_GET = 1 -- 可领
  57. REWARD_STATUS_HADGET = 2 -- 已领
  58. TOWER_TONGGUAN_TYPE = 1 -- 通关奖励
  59. TOWER_KING_TYPE = 2 -- 通关王者奖励
  60. -- 用于弹窗触发类型 @ma 是否需要同意定义枚举
  61. local EVAL_TOWER_EVENT = 2
  62. local DEVIL_ORDER_TYPE = 2
  63. function initSeverTower(nowLv)
  64. local towerDB = HuanjingTowerDB.query(#HuanjingTowerExcel.huanjingTower)
  65. if towerDB then
  66. return
  67. end
  68. local msg = {}
  69. nowLv = nowLv or 1
  70. for i = nowLv, #HuanjingTowerExcel.huanjingTower do
  71. local config = HuanjingTowerExcel.huanjingTower[i]
  72. if config then
  73. msg = {}
  74. msg.lv = i
  75. msg.combatVideo = {}
  76. msg.headNum = 0
  77. msg.headList = {}
  78. msg.roleNum = 0
  79. HuanjingTowerDB.addTower(msg)
  80. else
  81. break
  82. end
  83. end
  84. end
  85. -- 玩家修改 头像 后续处理
  86. function changeHeadAfter(human)
  87. if not human.db.tower or not human.db.tower.lv then
  88. return
  89. end
  90. local data = HuanjingTowerDB.query(human.db.tower.lv)
  91. if checkTowerDBHaveByUuid(human.db._id, data) then
  92. local new = data.headList[human.db._id]
  93. new.head = human.db.head
  94. new.headFrame = human.db.headFrame
  95. HuanjingTowerDB.updateDB(data)
  96. end
  97. end
  98. -- 幻境之塔查询
  99. function query(human)
  100. local flag = RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1203)
  101. if flag ~= true then
  102. return Broadcast.sendErr(human, Lang.HUANJINGTOWER_OPEN_NEED_LV)
  103. end
  104. local msgRet = Msg.gc.GC_HUANGJINGTOWER_QUERY
  105. local buyCnt = getBuyCnt(human)
  106. msgRet.buyCost = BUY_TILI_BUY_ZUANSHI[buyCnt + 1] or BUY_TILI_BUY_ZUANSHI[1]
  107. msgRet.cnt = getCurCnt(human)
  108. msgRet.cntMax = getMaxCnt(human)
  109. local nowLv = 1
  110. if human.db.tower and human.db.tower.lv then
  111. nowLv = human.db.tower.lv + 1
  112. end
  113. msgRet.mylv = nowLv
  114. local thisTowerConfig = HuanjingTowerExcel.huanjingTower[nowLv]
  115. if not thisTowerConfig then
  116. return
  117. end
  118. --- 等排行榜写完 读取前三
  119. msgRet.rank[0] = 0
  120. local board = BillboardDB.getBoard(BillboardDefine.TYPE_TOWER)
  121. if board then
  122. for k = 1, 3 do
  123. local rankData = board.rank2data[k]
  124. if rankData then
  125. msgRet.rank[0] = msgRet.rank[0] + 1
  126. local net = msgRet.rank[msgRet.rank[0]]
  127. if rankData and rankData.roleBase then
  128. RoleLogic.makeRoleBase(rankData.roleBase, net.roleBase)
  129. else
  130. local roleUuid = rankData and rankData.uuid or ""
  131. RoleLogic.getRoleBaseByUuid(roleUuid, net.roleBase)
  132. end
  133. net.lv = rankData and rankData.value1 or 0
  134. end
  135. end
  136. end
  137. local cnt = 0
  138. local thisMax = nowLv + 28
  139. local thisMin = nowLv - 1
  140. if thisMin <= 0 then
  141. thisMin = 1
  142. thisMax = thisMin + 29
  143. elseif thisMax > #HuanjingTowerExcel.huanjingTower then
  144. thisMax = #HuanjingTowerExcel.huanjingTower
  145. thisMin = thisMax - 29
  146. end
  147. msgRet.canBuy = math.max(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER3) - getBuyCnt(human), 0)
  148. msgRet.maxLv = #HuanjingTowerExcel.huanjingTower
  149. for i = thisMin, thisMax do
  150. local config = HuanjingTowerExcel.huanjingTower[i]
  151. cnt = cnt + 1
  152. msgRet.list[cnt].lv = i
  153. msgRet.list[cnt].head[0] = 0
  154. msgRet.list[cnt].reward[0] = 0
  155. msgRet.list[cnt].body = HeroGrid.getMonsterOutIDBody(config.monsterOutID)
  156. local data = HuanjingTowerDB.query(i)
  157. local have = data.roleNum
  158. have = have > 0 and have or 0
  159. have = have < 3 and have or 3
  160. for _, v in pairs(data.headList) do
  161. local head = v.head
  162. msgRet.list[cnt].head[0] = msgRet.list[cnt].head[0] + 1
  163. msgRet.list[cnt].head[msgRet.list[cnt].head[0]] = head
  164. end
  165. local len = 0
  166. if nowLv <= i then
  167. for j, h in ipairs(config.firstReward) do
  168. len = len + 1
  169. Grid.makeItem(msgRet.list[cnt].reward[len], h[1], h[2])
  170. msgRet.list[cnt].reward[0] = len
  171. end
  172. end
  173. end
  174. msgRet.list[0] = cnt
  175. msgRet.hasReward = isDotReward(human) and 1 or 0
  176. -- Msg.trace(msgRet)
  177. Msg.send(msgRet, human.fd)
  178. end
  179. function getRewardStatus(human, type, id, needLv)
  180. local lv = human.db.tower and human.db.tower.lv or 0
  181. if type == TOWER_KING_TYPE and (not human.db.tower or not human.db.tower.vip) then
  182. return REWARD_STATUS_NONE
  183. end
  184. if needLv > lv then
  185. return REWARD_STATUS_NONE
  186. end
  187. if isGetReward(human, type, id) then
  188. return isGetReward(human, type, id)
  189. end
  190. return REWARD_STATUS_NONE
  191. end
  192. -- 通关奖励查询 or 冲塔王者 查询
  193. function sendRewardQuery(human, type)
  194. local lv = human.db.tower and human.db.tower.lv or 0
  195. local msgRet = Msg.gc.GC_HUANGJINGTOWER_REWARD_QUERY
  196. msgRet.type = type
  197. msgRet.state = 1
  198. msgRet.kingNeed = HuanjingTowerExcel.towerKing[1].tower
  199. local config = HuanjingTowerExcel.tongGuan
  200. if type == 2 then
  201. config = HuanjingTowerExcel.towerKing
  202. msgRet.state = human.db.tower.vip and 1 or 0
  203. end
  204. msgRet.isEnd = 0
  205. msgRet.lvMax = 0
  206. msgRet.hasRed[0] = 0
  207. local len = 0
  208. for k, v in ipairs(config) do
  209. len = len + 1
  210. local net = msgRet.list[len]
  211. net.id = k
  212. net.status = getRewardStatus(human, type, k, v.tower)
  213. net.needLv = v.tower
  214. net.reward[0] = 0
  215. for j, h in ipairs(v.reward) do
  216. net.reward[0] = net.reward[0] + 1
  217. Grid.makeItem(net.reward[net.reward[0]], h[1], h[2])
  218. end
  219. if len >= 30 then
  220. msgRet.list[0] = len
  221. Msg.send(msgRet, human.fd)
  222. len = 0
  223. end
  224. end
  225. msgRet.list[0] = len
  226. msgRet.hasRed[0] = 0
  227. for i = 1, 2 do
  228. local isRed = isDotByType(human, i)
  229. if isRed then
  230. msgRet.hasRed[0] = msgRet.hasRed[0] + 1
  231. msgRet.hasRed[msgRet.hasRed[0]] = i
  232. end
  233. end
  234. msgRet.isEnd = 1
  235. msgRet.lvMax = lv
  236. --Msg.trace(msgRet)
  237. Msg.send(msgRet, human.fd)
  238. end
  239. -- 获取 奖励
  240. function getReward(human, type, id)
  241. local config = HuanjingTowerExcel.tongGuan[id]
  242. local logStr = "tower_reward"
  243. if type == 2 then
  244. config = HuanjingTowerExcel.towerKing[id]
  245. logStr = "tower_king_reward"
  246. end
  247. if not config then
  248. return
  249. end
  250. local status = getRewardStatus(human, type, id, config.tower)
  251. if status == REWARD_STATUS_NONE then
  252. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  253. end
  254. if status == REWARD_STATUS_HADGET then
  255. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  256. end
  257. setGetReward(human, type, id)
  258. BagLogic.addItemList(human, config.reward, logStr)
  259. --- 此处 后续优化 不发送 sendRewardQuery
  260. --- GC_HUANGJINGTOWER_REWARD_GET 新增 type id 客户端 做处理更新界面 等客户端 有时间了改
  261. --sendRewardQuery(human, type)
  262. local msgRet = Msg.gc.GC_HUANGJINGTOWER_REWARD_GET
  263. msgRet.hasReward = isDotReward(human) and 1 or 0
  264. Msg.send(msgRet, human.fd)
  265. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1203)
  266. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  267. end
  268. TOWER_KING_ALL_REWARD = nil
  269. function unlockTowerKingQuery(human)
  270. if not human.db.tower then
  271. return
  272. end
  273. if human.db.tower.vip and human.db.tower.vip == 1 then
  274. return
  275. end
  276. local msgRet = Msg.gc.GC_HUANGJINGTOWER_KING_REWARD
  277. local config = HuanjingTowerExcel.towerKing[1]
  278. msgRet.reward[0] = config.activeReward
  279. for k, v in ipairs(config.activeReward) do
  280. Grid.makeItem(msgRet.reward[k], v[1], v[2])
  281. end
  282. if not TOWER_KING_ALL_REWARD then
  283. TOWER_KING_ALL_REWARD = {}
  284. local have = {}
  285. for k, v in ipairs(HuanjingTowerExcel.towerKing) do
  286. if have[v[1]] then
  287. local index = have[v[1]]
  288. TOWER_KING_ALL_REWARD[index].itemCnt = TOWER_KING_ALL_REWARD[index].itemCnt + v[2]
  289. else
  290. local tolal = TOWER_KING_ALL_REWARD[0] + 1
  291. TOWER_KING_ALL_REWARD[tolal] = {}
  292. TOWER_KING_ALL_REWARD[tolal].itemID = v[1]
  293. TOWER_KING_ALL_REWARD[tolal].itemCnt = v[2]
  294. TOWER_KING_ALL_REWARD[0] = tolal
  295. have[v[1]] = tolal
  296. end
  297. end
  298. end
  299. msgRet.allItem[0] = #TOWER_KING_ALL_REWARD
  300. for k, v in ipairs(TOWER_KING_ALL_REWARD) do
  301. Grid.makeItem(msgRet.allItem[k], v.itemID, v.itemCnt)
  302. end
  303. BuyLogic.fontBuyItem(human, msgRet.buyItem, config.buyID)
  304. Msg.send(msgRet, human.fd)
  305. end
  306. -- 解锁通关王者
  307. function unlockTowerKing(human)
  308. if not human.db.tower then
  309. return
  310. end
  311. local config = HuanjingTowerExcel.towerKing[1]
  312. local kingNeed = config.tower
  313. if human.db.tower.lv < kingNeed then
  314. return
  315. end
  316. human.db.tower.vip = 1
  317. BagLogic.addItemList(human, config.activeReward, "tower_king_unlock")
  318. sendRewardQuery(human, TOWER_KING_TYPE)
  319. end
  320. function getSaoDangState(human, lv)
  321. local nowLv = 1
  322. if human.db.tower and human.db.tower.lv then
  323. nowLv = human.db.tower.lv + 1
  324. end
  325. if nowLv > lv then
  326. return 1
  327. end
  328. return 0
  329. end
  330. -- 战斗查询
  331. function fightQuery(human, lv)
  332. local huanjingTowerConfig = HuanjingTowerExcel.huanjingTower[lv]
  333. if not huanjingTowerConfig then
  334. return
  335. end
  336. local buyCnt = getBuyCnt(human)
  337. local msgRet = Msg.gc.GC_HUANGJINGTOWER_FIGHT_QUERY
  338. msgRet.lv = lv
  339. msgRet.zhandouli = huanjingTowerConfig.zhandouli
  340. msgRet.isSaoDang = getSaoDangState(human, lv)
  341. msgRet.buyCost = BUY_TILI_BUY_ZUANSHI[buyCnt + 1] or BUY_TILI_BUY_ZUANSHI[1]
  342. msgRet.canBuy = math.max(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER3) - getBuyCnt(human), 0)
  343. local monsterOutID = huanjingTowerConfig.monsterOutID
  344. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  345. if not monsterOutConfig then
  346. assert()
  347. end
  348. local cnt = 0
  349. for key, member in ipairs(monsterOutConfig.member) do
  350. local value = member[1]
  351. if value ~= 0 then
  352. cnt = cnt + 1
  353. local tempMonsterConfig = MonsterExcel.monster[value]
  354. if not tempMonsterConfig then
  355. assert()
  356. end
  357. local other = {}
  358. other.lv = member[2]
  359. HeroGrid.makeHeroSimpleByMonsterID(msgRet.monsterList[cnt], value, other)
  360. end
  361. end
  362. msgRet.monsterList[0] = cnt
  363. for key, value in ipairs(huanjingTowerConfig.reward) do
  364. Grid.makeItem(msgRet.rewardList[key], value[1], value[2])
  365. end
  366. msgRet.rewardList[0] = #huanjingTowerConfig.reward
  367. msgRet.fristReward[0] = 0
  368. local myLv = human.db.tower and human.db.tower.lv or 0
  369. if myLv < lv then
  370. for j, h in ipairs(huanjingTowerConfig.firstReward) do
  371. Grid.makeItem(msgRet.fristReward[j], h[1], h[2])
  372. end
  373. msgRet.fristReward[0] = #huanjingTowerConfig.firstReward
  374. end
  375. Msg.send(msgRet, human.fd)
  376. end
  377. -- 扫荡挑战
  378. function saodangDO(human, lv)
  379. local cnt = getCurCnt(human)
  380. if cnt < 1 then
  381. buyTiliDo(human)
  382. cnt = getCurCnt(human)
  383. if cnt < 1 then
  384. return
  385. end
  386. end
  387. local config = HuanjingTowerExcel.huanjingTower[lv]
  388. if not config then
  389. return
  390. end
  391. local myLv = human.db.tower and human.db.tower.lv or 0
  392. if myLv < lv then
  393. return
  394. end
  395. -- 增加次数
  396. addTili(human, 1)
  397. -- 发放奖励
  398. BagLogic.addItemList(human, config.reward, "tower_win_reward")
  399. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_5, 1)
  400. YunYingLogic.onCallBack(human, "onHuangjingTower",1)
  401. query(human)
  402. fightQuery(human, lv)
  403. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1203)
  404. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  405. end
  406. -- 挑战
  407. function fight(human, args)
  408. local isok, lv, config, count = checkCombatPos(human, args)
  409. if not isok then
  410. return
  411. end
  412. -- 调用战斗接口
  413. CombatLogic.combatBegin(human, config.mapID, args, CombatDefine.COMBAT_TYPE6, lv)
  414. end
  415. -- 获取当前地图ID
  416. function getMapID(human, args)
  417. local isok, lv, config = checkCombatPos(human, args)
  418. if not isok then
  419. return
  420. end
  421. return config.mapID
  422. end
  423. -- 检查 战斗录像是否需要保存
  424. function checkUpdeType(db, combatTime, zhandouli)
  425. local timeUp = combatTime
  426. local zhanliUp = zhandouli
  427. if db.combatVideo and db.combatVideo[1] and combatTime >= db.combatVideo[1].time then
  428. timeUp = 0
  429. end
  430. if db.combatVideo and db.combatVideo[2] and zhandouli >= db.combatVideo[2].zhandouli then
  431. zhanliUp = 0
  432. end
  433. return timeUp, zhanliUp
  434. end
  435. -- 挑战结束
  436. function onFightEnd(human, result, fightTypeID, param, combatInfo, args)
  437. local rewardItem = combatInfo.rewardItem
  438. if fightTypeID ~= CombatDefine.COMBAT_TYPE6 then
  439. return
  440. end
  441. local huanjingTowerConfig = HuanjingTowerExcel.huanjingTower[param]
  442. if not huanjingTowerConfig then
  443. return
  444. end
  445. local oldLv = human.db.tower and human.db.tower.lv or 0
  446. -- 改db
  447. updateResult(human, result, combatInfo, param)
  448. local count = tonumber(args[2] or 0)
  449. combatInfo.endParam = tostring(count)
  450. -- 给奖励
  451. if CombatDefine.RESULT_WIN == result then
  452. local rewardList = {}
  453. for _, value in ipairs(huanjingTowerConfig.reward) do
  454. local itemID = value[1]
  455. local itemCnt = value[2]
  456. rewardList[itemID] = rewardList[itemID] or 0
  457. rewardList[itemID] = rewardList[itemID] + itemCnt
  458. BagLogic.addItem(human, itemID, itemCnt, "tower_win_reward")
  459. combatInfo.rewardItem[#combatInfo.rewardItem + 1] = {itemID, itemCnt}
  460. end
  461. oldLv = oldLv or 0
  462. if oldLv < param then
  463. for _, value in ipairs(huanjingTowerConfig.firstReward) do
  464. local itemID = value[1]
  465. local itemCnt = value[2]
  466. rewardList[itemID] = rewardList[itemID] or 0
  467. rewardList[itemID] = rewardList[itemID] + itemCnt
  468. BagLogic.addItem(human, itemID, itemCnt, "tower_win_reward")
  469. combatInfo.rewardItem[#combatInfo.rewardItem + 1] = {itemID, itemCnt}
  470. end
  471. -- 首次通关触发弹窗礼包
  472. GiftLogic.trigger(human,EVAL_TOWER_EVENT,{id = param})
  473. WarOrder.trigger(human,DEVIL_ORDER_TYPE)
  474. end
  475. --TODO:记录恶魔之塔
  476. Log.write(Log.LOGID_OSS_BATTLE_DEMONTOWER, human.db._id, human.db.account, human.db.name, human.db.tower.lv)
  477. -- 挑战成功,则保存战斗信息
  478. combatInfo.defender.name = Util.format(Lang.COMBAT_TOWER_NAME, param)
  479. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_9, param)
  480. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_2, param)
  481. JibanLogic.onCallback(human, 3, param)
  482. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_5, 1)
  483. YunYingLogic.onCallBack(human, "onHuangjingTower",1)
  484. end
  485. LiLianLogic.onCallbackByCombat(human, combatInfo)
  486. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1203)
  487. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  488. end
  489. -- 获取该层 已存的 玩家头像数据条数
  490. function getHeadNum(data)
  491. local len = 0
  492. if data.headList then
  493. for _, _ in pairs(data.headList) do
  494. len = len + 1
  495. end
  496. end
  497. return len
  498. end
  499. -- 检查该玩家在 该层塔 有 头像数据
  500. function checkTowerDBHaveByUuid(uuid, data)
  501. if data.headList and data.headList[uuid] then
  502. return true
  503. end
  504. return false
  505. end
  506. -- 更新层数 头像
  507. function towerHeadChange(human, oldLv, lv)
  508. if lv <= 1 then
  509. return
  510. end
  511. local data = HuanjingTowerDB.query(lv)
  512. local have = getHeadNum(data)
  513. if have < TOWER_LV_HEAD_MAX and not data.headList[human.db._id] then
  514. data.headList[human.db._id] = {}
  515. local new = data.headList[human.db._id]
  516. new.head = human.db.head
  517. new.headFrame = human.db.headFrame
  518. new.time = os.time()
  519. HuanjingTowerDB.updateDB(data)
  520. end
  521. if oldLv > 1 then
  522. local oldData = HuanjingTowerDB.query(oldLv)
  523. if checkTowerDBHaveByUuid(human.db._id, oldData) then
  524. oldData.headList[human.db._id] = nil
  525. HuanjingTowerDB.updateDB(oldData)
  526. end
  527. end
  528. end
  529. function queryFightData(human, towerId)
  530. local data = HuanjingTowerDB.query(towerId)
  531. if not data then
  532. return
  533. end
  534. local msgRet = Msg.gc.GC_HUANGJINGTOWER_QUERY_FIGHT_DATA
  535. msgRet.lv = towerId
  536. local len = 0
  537. for k, v in ipairs(data.combatVideo) do
  538. len = len + 1
  539. local net = msgRet.list[len]
  540. net.index = k
  541. net.zhanli = v.zhandouli
  542. net.time = v.time
  543. net.useTime = v.combatTime
  544. RoleLogic.getRoleBaseByUuid(v.uuid, net.roleBase)
  545. end
  546. msgRet.list[0] = len
  547. Msg.send(msgRet, human.fd)
  548. end
  549. function readFightVideo(human, towerId, index)
  550. local data = HuanjingTowerDB.query(towerId)
  551. if not data then
  552. return
  553. end
  554. if data.combatVideo and data.combatVideo[index] then
  555. local combatInfo = data.combatVideo[index].combatVideo
  556. combatInfo.isVideo = true
  557. -- combatInfo.videoUuid = videoUuid
  558. -- combatInfo.lookType = lookType
  559. human.combat = combatInfo
  560. CombatLogic.sendCombatData(human, combatInfo)
  561. CombatLogic.sendCombatFinish(human, combatInfo)
  562. end
  563. end
  564. -- 幻境之塔购买体力查询
  565. function buyTiliQuery(human)
  566. local msgRet = Msg.gc.GC_HUANGJINGTOWER_BUY_TILI_QUERY
  567. local buyCnt = getBuyCnt(human)
  568. msgRet.needItemID = BUY_TILI_ITEM_ID
  569. msgRet.needItemCnt = BUY_TILI_ITEM_CNT + buyCnt * 10
  570. Msg.send(msgRet, human.fd)
  571. end
  572. -- 幻境之塔购买体力
  573. function buyTiliDo(human, buyCnt)
  574. local buyCnt = getBuyCnt(human)
  575. local maxBuyCnt = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER3)
  576. if buyCnt >= maxBuyCnt then
  577. return
  578. end
  579. local needZuanshi = BUY_TILI_ITEM_CNT + buyCnt * 10
  580. if not ObjHuman.checkRMB(human, needZuanshi) then
  581. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  582. end
  583. ObjHuman.decZuanshi(human, -needZuanshi, "tower_buy_liti")
  584. addBuyCnt(human, 1)
  585. local msgRet = Msg.gc.GC_HUANGJINGTOWER_BUY_TILI_DO
  586. local buyCnt = getBuyCnt(human)
  587. msgRet.buyCost = BUY_TILI_BUY_ZUANSHI[buyCnt + 1] or BUY_TILI_BUY_ZUANSHI[1]
  588. msgRet.cnt = getCurCnt(human)
  589. msgRet.canBuy = math.max(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER3) - getBuyCnt(human), 0)
  590. Msg.send(msgRet, human.fd)
  591. -- query(human)
  592. end
  593. -- 挑战结果
  594. function updateResult(human, result, combatInfo, param)
  595. -- 当前胜利关卡已通关
  596. if human.db.tower and human.db.tower.lv and human.db.tower.lv >= param then
  597. -- 增加挑战次数
  598. addTili(human, 1)
  599. end
  600. if result == CombatDefine.RESULT_WIN then
  601. human.db.tower = human.db.tower or {}
  602. human.db.tower.lv = human.db.tower.lv or 0
  603. local oldLv = human.db.tower.lv
  604. -- 当前胜利关卡未通关
  605. if oldLv < param then
  606. human.db.tower.lv = human.db.tower.lv + 1
  607. towerHeadChange(human, oldLv, human.db.tower.lv)
  608. end
  609. human.db.tower.usetime = CombatLogic.getCombatUseTime(combatInfo)
  610. local data = HuanjingTowerDB.query(human.db.tower.lv)
  611. local zhandouli = combatInfo.attacker.zhandouli
  612. local timeUp, zhanliUp = checkUpdeType(data, human.db.tower.usetime, zhandouli) -- combatTime , zhandouli
  613. local combatVideo = Util.copyTable(combatInfo)
  614. HuanjingTowerDB.addVideoToTower(
  615. data,
  616. human.db._id,
  617. os.time(),
  618. timeUp,
  619. zhanliUp,
  620. human.db.tower.usetime,
  621. zhandouli,
  622. combatVideo
  623. )
  624. HuanjingTowerDB.updateDB(data)
  625. -- 更新爬塔榜
  626. BRoleLogic.updateData(BillboardDefine.TYPE_TOWER, human.db)
  627. end
  628. end
  629. -- 更新动态数据
  630. function updateDaily(human)
  631. if human.db.tower then
  632. human.db.tower.tili = 0
  633. human.db.tower.buyCnt = 0
  634. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1203)
  635. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  636. end
  637. end
  638. function addBuyCnt(human, add)
  639. human.db.tower = human.db.tower or {}
  640. human.db.tower.buyCnt = human.db.tower.buyCnt or 0
  641. human.db.tower.buyCnt = human.db.tower.buyCnt + add
  642. end
  643. function addTili(human, add)
  644. human.db.tower = human.db.tower or {}
  645. human.db.tower.tili = human.db.tower.tili or 0
  646. human.db.tower.tili = human.db.tower.tili + add
  647. end
  648. -- 获取当前挑战次数
  649. function getTili(human)
  650. if human.db.tower == nil or human.db.tower.tili == nil then
  651. return 0
  652. end
  653. return human.db.tower.tili
  654. end
  655. -- 获取购买次数
  656. function getBuyCnt(human)
  657. if human.db.tower == nil or human.db.tower.buyCnt == nil then
  658. return 0
  659. end
  660. return human.db.tower.buyCnt
  661. end
  662. function getMaxCnt(human)
  663. local buyCnt = getBuyCnt(human)
  664. return TILI_FREE + buyCnt
  665. end
  666. -- 获取剩余可挑战或者扫荡次数
  667. function getCurCnt(human)
  668. local tili = getTili(human)
  669. local max = getMaxCnt(human)
  670. return max - tili
  671. end
  672. -- 读取 刷新玩家领取记录
  673. function readUpdateGetDb(human, type)
  674. local db
  675. local getList
  676. if type == TOWER_TONGGUAN_TYPE and not human.towerTongGet then
  677. db = human.db.tower.tongGet
  678. human.towerTongGet = {}
  679. getList = human.towerTongGet
  680. elseif type == TOWER_KING_TYPE and not human.towerKingGet then
  681. db = human.db.tower.kingGet
  682. human.towerKingGet = {}
  683. getList = human.towerKingGet
  684. end
  685. if not db or db == "" then
  686. return
  687. end
  688. local list = Util.split(db, "|")
  689. for _, key in ipairs(list) do
  690. getList[tonumber(key)] = 1
  691. end
  692. end
  693. function isGetReward(human, type, id)
  694. if not human.db.tower then
  695. return
  696. end
  697. readUpdateGetDb(human, type)
  698. local db = {}
  699. if type == TOWER_TONGGUAN_TYPE then
  700. db = human.towerTongGet
  701. elseif type == TOWER_KING_TYPE then
  702. db = human.towerKingGet
  703. end
  704. if db and db[id] then
  705. return REWARD_STATUS_HADGET
  706. else
  707. return REWARD_STATUS_GET
  708. end
  709. end
  710. -- 领取奖励 存db
  711. function setGetReward(human, type, id)
  712. human.db.tower = human.db.tower or {}
  713. readUpdateGetDb(human, type)
  714. if type == TOWER_TONGGUAN_TYPE then
  715. human.db.tower.tongGet = human.db.tower.tongGet or ""
  716. human.db.tower.tongGet = human.db.tower.tongGet .. id .. "|"
  717. human.towerTongGet[id] = 1
  718. elseif type == TOWER_KING_TYPE then
  719. human.db.tower.kingGet = human.db.tower.kingGet or ""
  720. human.db.tower.kingGet = human.db.tower.kingGet .. id .. "|"
  721. human.towerKingGet[id] = 1
  722. end
  723. end
  724. -- 检查是否有奖励可以领取
  725. function checkHaveCanGetReward(human, type)
  726. if not human.db.tower or not human.db.tower.lv then
  727. return
  728. end
  729. local lv = human.db.tower.lv
  730. readUpdateGetDb(human, type)
  731. for k, config in ipairs(HuanjingTowerExcel.tongGuan) do
  732. if lv < config.tower then
  733. return
  734. end
  735. if isGetReward(human, type, k) == REWARD_STATUS_GET then
  736. return true, k
  737. end
  738. end
  739. end
  740. -- GM
  741. function setTowerByGm(human, lv)
  742. if not lv or lv < 0 then
  743. return
  744. end
  745. local towerConfig = HuanjingTowerExcel.huanjingTower[lv]
  746. if not towerConfig then
  747. return
  748. end
  749. human.db.tower = human.db.tower or {}
  750. local oldLv = human.db.tower.lv or 0
  751. human.db.tower.lv = lv
  752. towerHeadChange(human, oldLv, lv)
  753. end
  754. function isDot(human)
  755. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1203) then
  756. return
  757. end
  758. if getCurCnt(human) > 0 then
  759. return true
  760. end
  761. if not human.db.tower then
  762. return
  763. end
  764. local lv = human.db.tower.lv
  765. if not lv then
  766. return
  767. end
  768. if checkHaveCanGetReward(human, TOWER_TONGGUAN_TYPE) then
  769. return true
  770. end
  771. --[[ if human.db.tower.vip and human.db.tower.vip == 1 then
  772. local kingGetId = human.db.tower.kingGet or 0
  773. local config = HuanjingTowerExcel.towerKing[kingGetId + 1]
  774. if config and lv >= config.tower then
  775. return true
  776. end
  777. end
  778. ]]
  779. --
  780. end
  781. function isDotReward(human)
  782. if not human.db.tower then
  783. return
  784. end
  785. local lv = human.db.tower.lv
  786. if not lv then
  787. return
  788. end
  789. if checkHaveCanGetReward(human, TOWER_TONGGUAN_TYPE) then
  790. return true
  791. end
  792. --[[ if human.db.tower.vip and human.db.tower.vip == 1 then
  793. local kingGetId = human.db.tower.kingGet or 0
  794. local config = HuanjingTowerExcel.towerKing[kingGetId + 1]
  795. if config and lv >= config.tower then
  796. return true
  797. end
  798. end
  799. ]]
  800. --
  801. end
  802. function isDotByType(human, type)
  803. if not human.db.tower then
  804. return
  805. end
  806. local lv = human.db.tower.lv
  807. if not lv then
  808. return
  809. end
  810. if type == TOWER_TONGGUAN_TYPE then
  811. if checkHaveCanGetReward(human, TOWER_TONGGUAN_TYPE) then
  812. return true
  813. end
  814. elseif type == TOWER_KING_TYPE then
  815. if checkHaveCanGetReward(human, TOWER_KING_TYPE) then
  816. return true
  817. end
  818. end
  819. end
  820. local QueryRoleByTower = {}
  821. function getAllHumanByLv(human, lv)
  822. local data = HuanjingTowerDB.query(lv)
  823. if not data then
  824. return
  825. end
  826. local msgRet = Msg.gc.GC_HUANGJINGTOWER_LV_ALLHUMAN
  827. local len = 0
  828. for uuid, _ in pairs(data.headList) do
  829. if len >= 10 then
  830. break
  831. end
  832. local db = RoleDBLogic.getDb(uuid, RoleLogic.FieldRoleBase)
  833. if db then
  834. len = len + 1
  835. RoleLogic.makeRoleBase(db, msgRet.role[len])
  836. end
  837. end
  838. msgRet.role[0] = len
  839. Msg.send(msgRet, human.fd)
  840. end
  841. --------------------------------------------- combat ----------------------------------------------
  842. function getCombatMonsterOutID(human, side, args)
  843. if side ~= CombatDefine.DEFEND_SIDE then
  844. return
  845. end
  846. local lv = tonumber(args[1] or 0)
  847. -- local lv = (human.db.tower and human.db.tower.lv or 0) + 1
  848. local config = HuanjingTowerExcel.huanjingTower[lv]
  849. if not config then
  850. return
  851. end
  852. return config.monsterOutID, config.zhandouli
  853. end
  854. function checkCombatPos(human, args)
  855. local lv = tonumber(args[1] or 0)
  856. local count = tonumber(args[2] or 0)
  857. local config = HuanjingTowerExcel.huanjingTower[lv]
  858. if not config then
  859. return
  860. end
  861. -- 判断挑战等级 不可越级挑战
  862. if lv > (human.db.tower and human.db.tower.lv or 0) + 1 then
  863. return Broadcast.sendErr(human, Lang.COPY_FIGHT_ERR_PREID)
  864. end
  865. -- 判断是否为 挑战已经通关的等级 已通关的关卡需要消耗次数
  866. if lv < (human.db.tower and human.db.tower.lv or 0) + 1 then
  867. local cnt = getCurCnt(human)
  868. if cnt < 1 then
  869. buyTiliDo(human)
  870. cnt = getCurCnt(human)
  871. if cnt < 1 then
  872. return Broadcast.sendErr(human, Lang.HUANJINGTOWER_NO_TILI_CNT)
  873. end
  874. end
  875. end
  876. -- 挑战不消耗次数
  877. -- if getCurCnt(human) < 1 then
  878. -- return Broadcast.sendErr(human, Lang.HUANJINGTOWER_NO_TILI_CNT)
  879. -- end
  880. return true, lv, config, count
  881. end