HuanjingTowerLogic.lua 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. -- 奖励状态
  55. REWARD_STATUS_NONE = 0 -- 不可领
  56. REWARD_STATUS_GET = 1 -- 可领
  57. REWARD_STATUS_HADGET = 2 -- 已领
  58. TOWER_TONGGUAN_TYPE = 1 -- 通关奖励
  59. TOWER_KING_TYPE = 2 -- 通关王者奖励
  60. -- 用于弹窗触发类型 @ma 是否需要同意定义枚举
  61. local EVAL_TOWER_EVENT = 2
  62. local DEVIL_ORDER_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. -- 首次通关触发弹窗礼包
  472. GiftLogic.trigger(human,EVAL_TOWER_EVENT,{id = param})
  473. WarOrder.trigger(human,DEVIL_ORDER_TYPE)
  474. end
  475. --TODO:记录恶魔之塔
  476. Log.write(Log.LOGID_OSS_BATTLE_DEMONTOWER, human.db._id, human.db.account, human.db.name, human.db.tower.lv)
  477. -- 挑战成功,则保存战斗信息
  478. combatInfo.defender.name = Util.format(Lang.COMBAT_TOWER_NAME, param)
  479. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_9, param)
  480. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_2, param)
  481. JibanLogic.onCallback(human, 3, param)
  482. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_5, 1)
  483. YunYingLogic.onCallBack(human, "onHuangjingTower",1)
  484. end
  485. LiLianLogic.onCallbackByCombat(human, combatInfo)
  486. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1203)
  487. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  488. end
  489. -- 获取该层 已存的 玩家头像数据条数
  490. function getHeadNum(data)
  491. local len = 0
  492. if data.headList then
  493. for _, _ in pairs(data.headList) do
  494. len = len + 1
  495. end
  496. end
  497. return len
  498. end
  499. -- 检查该玩家在 该层塔 有 头像数据
  500. function checkTowerDBHaveByUuid(uuid, data)
  501. if data.headList and data.headList[uuid] then
  502. return true
  503. end
  504. return false
  505. end
  506. -- 更新层数 头像
  507. function towerHeadChange(human, oldLv, lv)
  508. if lv <= 1 then
  509. return
  510. end
  511. local data = HuanjingTowerDB.query(lv)
  512. local have = getHeadNum(data)
  513. if have < TOWER_LV_HEAD_MAX and not data.headList[human.db._id] then
  514. data.headList[human.db._id] = {}
  515. local new = data.headList[human.db._id]
  516. new.head = human.db.head
  517. new.headFrame = human.db.headFrame
  518. new.time = os.time()
  519. HuanjingTowerDB.updateDB(data)
  520. end
  521. if oldLv > 1 then
  522. local oldData = HuanjingTowerDB.query(oldLv)
  523. if checkTowerDBHaveByUuid(human.db._id, oldData) then
  524. oldData.headList[human.db._id] = nil
  525. HuanjingTowerDB.updateDB(oldData)
  526. end
  527. end
  528. end
  529. function queryFightData(human, towerId)
  530. local data = HuanjingTowerDB.query(towerId)
  531. if not data then
  532. return
  533. end
  534. local msgRet = Msg.gc.GC_HUANGJINGTOWER_QUERY_FIGHT_DATA
  535. msgRet.lv = towerId
  536. local len = 0
  537. for k, v in ipairs(data.combatVideo) do
  538. len = len + 1
  539. local net = msgRet.list[len]
  540. net.index = k
  541. net.zhanli = v.zhandouli
  542. net.time = v.time
  543. net.useTime = v.combatTime
  544. RoleLogic.getRoleBaseByUuid(v.uuid, net.roleBase)
  545. end
  546. msgRet.list[0] = len
  547. Msg.send(msgRet, human.fd)
  548. end
  549. function readFightVideo(human, towerId, index)
  550. local data = HuanjingTowerDB.query(towerId)
  551. if not data then
  552. return
  553. end
  554. if data.combatVideo and data.combatVideo[index] then
  555. local combatInfo = data.combatVideo[index].combatVideo
  556. combatInfo.isVideo = true
  557. -- combatInfo.videoUuid = videoUuid
  558. -- combatInfo.lookType = lookType
  559. human.combat = combatInfo
  560. CombatLogic.sendCombatData(human, combatInfo)
  561. CombatLogic.sendCombatFinish(human, combatInfo)
  562. end
  563. end
  564. -- 幻境之塔购买体力查询
  565. function buyTiliQuery(human)
  566. local msgRet = Msg.gc.GC_HUANGJINGTOWER_BUY_TILI_QUERY
  567. local buyCnt = getBuyCnt(human)
  568. msgRet.needItemID = BUY_TILI_ITEM_ID
  569. msgRet.needItemCnt = BUY_TILI_ITEM_CNT + buyCnt * 10
  570. Msg.send(msgRet, human.fd)
  571. end
  572. -- 幻境之塔购买体力
  573. function buyTiliDo(human, buyCnt)
  574. local buyCnt = getBuyCnt(human)
  575. local maxBuyCnt = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER3)
  576. if buyCnt >= maxBuyCnt then
  577. return
  578. end
  579. local needZuanshi = BUY_TILI_ITEM_CNT + buyCnt * 10
  580. if not ObjHuman.checkRMB(human, needZuanshi) then
  581. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  582. end
  583. ObjHuman.decZuanshi(human, -needZuanshi, "tower_buy_liti")
  584. addBuyCnt(human, 1)
  585. local msgRet = Msg.gc.GC_HUANGJINGTOWER_BUY_TILI_DO
  586. local buyCnt = getBuyCnt(human)
  587. msgRet.buyCost = BUY_TILI_BUY_ZUANSHI[buyCnt + 1] or BUY_TILI_BUY_ZUANSHI[1]
  588. msgRet.cnt = getCurCnt(human)
  589. msgRet.canBuy = math.max(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER3) - getBuyCnt(human), 0)
  590. Msg.send(msgRet, human.fd)
  591. -- query(human)
  592. end
  593. -- 挑战结果
  594. function updateResult(human, result, combatInfo, param)
  595. -- 当前胜利关卡已通关
  596. if human.db.tower and human.db.tower.lv and human.db.tower.lv >= param then
  597. -- 增加挑战次数
  598. addTili(human, 1)
  599. end
  600. if result == CombatDefine.RESULT_WIN then
  601. human.db.tower = human.db.tower or {}
  602. human.db.tower.lv = human.db.tower.lv or 0
  603. local oldLv = human.db.tower.lv
  604. -- 当前胜利关卡未通关
  605. if oldLv < param then
  606. human.db.tower.lv = human.db.tower.lv + 1
  607. towerHeadChange(human, oldLv, human.db.tower.lv)
  608. end
  609. human.db.tower.usetime = CombatLogic.getCombatUseTime(combatInfo)
  610. local data = HuanjingTowerDB.query(human.db.tower.lv)
  611. local zhandouli = combatInfo.attacker.zhandouli
  612. local timeUp, zhanliUp = checkUpdeType(data, human.db.tower.usetime, zhandouli) -- combatTime , zhandouli
  613. local combatVideo = Util.copyTable(combatInfo)
  614. HuanjingTowerDB.addVideoToTower(
  615. data,
  616. human.db._id,
  617. os.time(),
  618. timeUp,
  619. zhanliUp,
  620. human.db.tower.usetime,
  621. zhandouli,
  622. combatVideo
  623. )
  624. HuanjingTowerDB.updateDB(data)
  625. -- 更新爬塔榜
  626. BRoleLogic.updateData(BillboardDefine.TYPE_TOWER, human.db)
  627. end
  628. end
  629. -- 更新动态数据
  630. function updateDaily(human)
  631. if human.db.tower then
  632. human.db.tower.tili = 0
  633. human.db.tower.buyCnt = 0
  634. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1203)
  635. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  636. end
  637. end
  638. --处理无法完成新成就任务问题
  639. function onLogin(human)
  640. if human.db.tower and human.db.tower.lv and human.db.tower.lv > 0 then
  641. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_9, human.db.tower.lv)
  642. end
  643. end
  644. function addBuyCnt(human, add)
  645. human.db.tower = human.db.tower or {}
  646. human.db.tower.buyCnt = human.db.tower.buyCnt or 0
  647. human.db.tower.buyCnt = human.db.tower.buyCnt + add
  648. end
  649. function addTili(human, add)
  650. human.db.tower = human.db.tower or {}
  651. human.db.tower.tili = human.db.tower.tili or 0
  652. human.db.tower.tili = human.db.tower.tili + add
  653. end
  654. -- 获取当前挑战次数
  655. function getTili(human)
  656. if human.db.tower == nil or human.db.tower.tili == nil then
  657. return 0
  658. end
  659. return human.db.tower.tili
  660. end
  661. -- 获取购买次数
  662. function getBuyCnt(human)
  663. if human.db.tower == nil or human.db.tower.buyCnt == nil then
  664. return 0
  665. end
  666. return human.db.tower.buyCnt
  667. end
  668. function getMaxCnt(human)
  669. local buyCnt = getBuyCnt(human)
  670. return TILI_FREE + buyCnt
  671. end
  672. -- 获取剩余可挑战或者扫荡次数
  673. function getCurCnt(human)
  674. local tili = getTili(human)
  675. local max = getMaxCnt(human)
  676. return max - tili
  677. end
  678. -- 读取 刷新玩家领取记录
  679. function readUpdateGetDb(human, type)
  680. local db
  681. local getList
  682. if type == TOWER_TONGGUAN_TYPE and not human.towerTongGet then
  683. db = human.db.tower.tongGet
  684. human.towerTongGet = {}
  685. getList = human.towerTongGet
  686. elseif type == TOWER_KING_TYPE and not human.towerKingGet then
  687. db = human.db.tower.kingGet
  688. human.towerKingGet = {}
  689. getList = human.towerKingGet
  690. end
  691. if not db or db == "" then
  692. return
  693. end
  694. local list = Util.split(db, "|")
  695. for _, key in ipairs(list) do
  696. getList[tonumber(key)] = 1
  697. end
  698. end
  699. function isGetReward(human, type, id)
  700. if not human.db.tower then
  701. return
  702. end
  703. readUpdateGetDb(human, type)
  704. local db = {}
  705. if type == TOWER_TONGGUAN_TYPE then
  706. db = human.towerTongGet
  707. elseif type == TOWER_KING_TYPE then
  708. db = human.towerKingGet
  709. end
  710. if db and db[id] then
  711. return REWARD_STATUS_HADGET
  712. else
  713. return REWARD_STATUS_GET
  714. end
  715. end
  716. -- 领取奖励 存db
  717. function setGetReward(human, type, id)
  718. human.db.tower = human.db.tower or {}
  719. readUpdateGetDb(human, type)
  720. if type == TOWER_TONGGUAN_TYPE then
  721. human.db.tower.tongGet = human.db.tower.tongGet or ""
  722. human.db.tower.tongGet = human.db.tower.tongGet .. id .. "|"
  723. human.towerTongGet[id] = 1
  724. elseif type == TOWER_KING_TYPE then
  725. human.db.tower.kingGet = human.db.tower.kingGet or ""
  726. human.db.tower.kingGet = human.db.tower.kingGet .. id .. "|"
  727. human.towerKingGet[id] = 1
  728. end
  729. end
  730. -- 检查是否有奖励可以领取
  731. function checkHaveCanGetReward(human, type)
  732. if not human.db.tower or not human.db.tower.lv then
  733. return
  734. end
  735. local lv = human.db.tower.lv
  736. readUpdateGetDb(human, type)
  737. for k, config in ipairs(HuanjingTowerExcel.tongGuan) do
  738. if lv < config.tower then
  739. return
  740. end
  741. if isGetReward(human, type, k) == REWARD_STATUS_GET then
  742. return true, k
  743. end
  744. end
  745. end
  746. -- GM
  747. function setTowerByGm(human, lv)
  748. if not lv or lv < 0 then
  749. return
  750. end
  751. local towerConfig = HuanjingTowerExcel.huanjingTower[lv]
  752. if not towerConfig then
  753. return
  754. end
  755. human.db.tower = human.db.tower or {}
  756. local oldLv = human.db.tower.lv or 0
  757. human.db.tower.lv = lv
  758. towerHeadChange(human, oldLv, lv)
  759. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_9, lv)
  760. end
  761. function isDot(human)
  762. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1203) then
  763. return
  764. end
  765. if getCurCnt(human) > 0 then
  766. return true
  767. end
  768. if not human.db.tower then
  769. return
  770. end
  771. local lv = human.db.tower.lv
  772. if not lv then
  773. return
  774. end
  775. if checkHaveCanGetReward(human, TOWER_TONGGUAN_TYPE) then
  776. return true
  777. end
  778. --[[ if human.db.tower.vip and human.db.tower.vip == 1 then
  779. local kingGetId = human.db.tower.kingGet or 0
  780. local config = HuanjingTowerExcel.towerKing[kingGetId + 1]
  781. if config and lv >= config.tower then
  782. return true
  783. end
  784. end
  785. ]]
  786. --
  787. end
  788. function isDotReward(human)
  789. if not human.db.tower then
  790. return
  791. end
  792. local lv = human.db.tower.lv
  793. if not lv then
  794. return
  795. end
  796. if checkHaveCanGetReward(human, TOWER_TONGGUAN_TYPE) then
  797. return true
  798. end
  799. --[[ if human.db.tower.vip and human.db.tower.vip == 1 then
  800. local kingGetId = human.db.tower.kingGet or 0
  801. local config = HuanjingTowerExcel.towerKing[kingGetId + 1]
  802. if config and lv >= config.tower then
  803. return true
  804. end
  805. end
  806. ]]
  807. --
  808. end
  809. function isDotByType(human, type)
  810. if not human.db.tower then
  811. return
  812. end
  813. local lv = human.db.tower.lv
  814. if not lv then
  815. return
  816. end
  817. if type == TOWER_TONGGUAN_TYPE then
  818. if checkHaveCanGetReward(human, TOWER_TONGGUAN_TYPE) then
  819. return true
  820. end
  821. elseif type == TOWER_KING_TYPE then
  822. if checkHaveCanGetReward(human, TOWER_KING_TYPE) then
  823. return true
  824. end
  825. end
  826. end
  827. local QueryRoleByTower = {}
  828. function getAllHumanByLv(human, lv)
  829. local data = HuanjingTowerDB.query(lv)
  830. if not data then
  831. return
  832. end
  833. local msgRet = Msg.gc.GC_HUANGJINGTOWER_LV_ALLHUMAN
  834. local len = 0
  835. for uuid, _ in pairs(data.headList) do
  836. if len >= 10 then
  837. break
  838. end
  839. local db = RoleDBLogic.getDb(uuid, RoleLogic.FieldRoleBase)
  840. if db then
  841. len = len + 1
  842. RoleLogic.makeRoleBase(db, msgRet.role[len])
  843. end
  844. end
  845. msgRet.role[0] = len
  846. Msg.send(msgRet, human.fd)
  847. end
  848. --对外接口, 获取当前层数
  849. function getTowerLevel(human)
  850. local lv = 0
  851. if human.db.tower then
  852. lv = human.db.tower.lv or 0
  853. end
  854. return lv
  855. end
  856. --------------------------------------------- combat ----------------------------------------------
  857. function getCombatMonsterOutID(human, side, args)
  858. if side ~= CombatDefine.DEFEND_SIDE then
  859. return
  860. end
  861. local lv = tonumber(args[1] or 0)
  862. -- local lv = (human.db.tower and human.db.tower.lv or 0) + 1
  863. local config = HuanjingTowerExcel.huanjingTower[lv]
  864. if not config then
  865. return
  866. end
  867. return config.monsterOutID, config.zhandouli
  868. end
  869. function checkCombatPos(human, args)
  870. local lv = tonumber(args[1] or 0)
  871. local count = tonumber(args[2] or 0)
  872. local config = HuanjingTowerExcel.huanjingTower[lv]
  873. if not config then
  874. return
  875. end
  876. -- 判断挑战等级 不可越级挑战
  877. if lv > (human.db.tower and human.db.tower.lv or 0) + 1 then
  878. return Broadcast.sendErr(human, Lang.COPY_FIGHT_ERR_PREID)
  879. end
  880. -- 判断是否为 挑战已经通关的等级 已通关的关卡需要消耗次数
  881. if lv < (human.db.tower and human.db.tower.lv or 0) + 1 then
  882. local cnt = getCurCnt(human)
  883. if cnt < 1 then
  884. buyTiliDo(human)
  885. cnt = getCurCnt(human)
  886. if cnt < 1 then
  887. return Broadcast.sendErr(human, Lang.HUANJINGTOWER_NO_TILI_CNT)
  888. end
  889. end
  890. end
  891. -- 挑战不消耗次数
  892. -- if getCurCnt(human) < 1 then
  893. -- return Broadcast.sendErr(human, Lang.HUANJINGTOWER_NO_TILI_CNT)
  894. -- end
  895. return true, lv, config, count
  896. end