HuanjingTowerLogic.lua 31 KB

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