HuanjingTowerLogic.lua 30 KB

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