HuanjingTowerLogic.lua 31 KB

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