HuanjingTowerLogic.lua 32 KB

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