HuanjingTowerLogic.lua 33 KB

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