HuanjingTowerLogic.lua 31 KB

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