HuanjingTowerLogic.lua 31 KB

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