HuanjingTowerLogic.lua 33 KB

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