lostTempleLogic.lua 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. --[[
  2. 失落神庙
  3. ]]
  4. local Msg = require("core.Msg")
  5. local LuaMongo = _G.lua_mongo
  6. local DB = require("common.DB")
  7. local LostTempleExcel = require("excel.lostTemple")
  8. local ElementExcel = require("excel.lostTemple").Element
  9. local CombatPosLogic = require("combat.CombatPosLogic")
  10. local CombatDefine = require("combat.CombatDefine")
  11. local MonsterOutExcel = require("excel.monster").monsterOut
  12. local HeroLogic = require("hero.HeroLogic")
  13. local MonsterExcel = require("excel.monster")
  14. local CombatLogic = require("combat.CombatLogic")
  15. local Grid = require("bag.Grid")
  16. local HeroGrid = require("hero.HeroGrid")
  17. local CombatPosExcel = require("excel.combatPos")
  18. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  19. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  20. local Util = require("common.Util")
  21. local LostTempleCombatLogic = require("lostTemple.lostTempleCombatLogic")
  22. local HeroDefine = require("hero.HeroDefine")
  23. local BagLogic = require("bag.BagLogic")
  24. local Broadcast = require("broadcast.Broadcast")
  25. local Lang = require("common.Lang")
  26. local CommonDB = require("common.CommonDB")
  27. local Lost_Handle_Func = { }
  28. QUEUE_LEN = 3 -- 每次推送的横向队列数
  29. START_X = 1 -- 起始横向位置
  30. START_LAYER = 1 -- 起始层数
  31. OP_QUERY = 0
  32. OP_CONFIRM = 1
  33. INIT_HP_MAX = 100
  34. DAY_7s = 604800
  35. DAY_2s = 172800
  36. DAY_1s = 86400
  37. --跳过战斗需要的战力
  38. local SHOWQUICKPOWER = 2000000
  39. function initAfterHot()
  40. end
  41. function getLeftTime()
  42. local openDay = CommonDB.getServerOpenDay()
  43. if not openDay then
  44. return 0
  45. end
  46. local curTime = os.time()
  47. local tNowDate = os.date("*t", curTime)
  48. tNowDate.hour = 0
  49. tNowDate.min = 0
  50. tNowDate.sec = 0
  51. if openDay % 2 == 1 then
  52. tNowDate.day = tNowDate.day + 2
  53. else
  54. tNowDate.day = tNowDate.day + 1
  55. end
  56. local nEndTime = os.time(tNowDate)
  57. return nEndTime - curTime
  58. end
  59. --
  60. local function isOpen(human)
  61. --[[
  62. local openDay = CommonDB.getServerOpenDay()
  63. if not openDay then
  64. return
  65. end
  66. if openDay < 7 then
  67. return
  68. end
  69. ---- 已经开启
  70. if (openDay - 7 + 1) % 2 ~= 1 then
  71. return
  72. end
  73. ]]
  74. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1208) then
  75. return
  76. end
  77. return true
  78. end
  79. function onZero()
  80. local openDay = CommonDB.getServerOpenDay()
  81. if not openDay then
  82. return
  83. end
  84. print("[lostTempleLogic - onZero] 失落神庙零点刷新开始 openDay = "..openDay)
  85. -- 奇数天刷新
  86. if openDay % 2 == 1 then
  87. print("[lostTempleLogic - onZero] 失落神庙零点, 当前为奇数天移除DB数据\n")
  88. LuaMongo.remove(DB.db_lost_temple)
  89. end
  90. -- 已经关闭
  91. -- if (openDay - 7 + 1) % 2 ~= 0 then
  92. -- return
  93. -- end
  94. end
  95. function updateDaily(human)
  96. if not isOpen(human) then
  97. return
  98. end
  99. print("[lostTempleLogic - updateDaily] 天数刷新 玩家移除lostTemple数据 name = "..human.db.name)
  100. human.lostTemple = nil
  101. local msgRet = Msg.gc.GC_LOST_TEMPLE_CLOSE
  102. Msg.send(msgRet, human.fd)
  103. end
  104. -- db
  105. local QueryByUuid = { _id = nil }
  106. -- 插入新的数据
  107. function dbRead(human)
  108. if not isOpen(human) then return end
  109. human.lostTemple = { }
  110. QueryByUuid._id = human.db._id
  111. LuaMongo.find(DB.db_lost_temple, QueryByUuid)
  112. if not LuaMongo.next(human.lostTemple) then
  113. human.lostTemple = nil
  114. end
  115. end
  116. --
  117. local DB_DATA = { }
  118. function dbSave(human)
  119. if not human.lostTemple then return end
  120. if not human.db then return end
  121. DB_DATA = { }
  122. LuaMongo.find(DB.db_lost_temple, QueryByUuid)
  123. -- if not LuaMongo.next(DB_DATA) then
  124. -- human.lostTemple._id = human.db._id
  125. -- LuaMongo.insert(DB.db_lost_temple, human.lostTemple)
  126. -- return
  127. -- end
  128. if not LuaMongo.next(DB_DATA) then
  129. -- 检查 human.db._id 是否已经存在
  130. local exists = false
  131. local tempQuery = { _id = human.db._id }
  132. LuaMongo.find(DB.db_lost_temple, tempQuery)
  133. if LuaMongo.next(DB_DATA) then
  134. exists = true
  135. end
  136. if exists then
  137. -- 如果存在,更新文档
  138. LuaMongo.update(DB.db_lost_temple, tempQuery, human.lostTemple)
  139. else
  140. -- 如果不存在,插入新文档
  141. human.lostTemple._id = human.db._id
  142. LuaMongo.insert(DB.db_lost_temple, human.lostTemple)
  143. end
  144. return
  145. end
  146. QueryByUuid._id = human.db._id
  147. LuaMongo.update(DB.db_lost_temple, QueryByUuid, human.lostTemple)
  148. end
  149. -- db
  150. function onLogin(human)
  151. if not isOpen(human) then return end
  152. dbRead(human)
  153. end
  154. -- 初始化玩家当前格子
  155. local function printGrid(human)
  156. if not human.lostTemple then return end
  157. local startX = human.lostTemple.x + 1
  158. local endX = human.lostTemple.x + QUEUE_LEN
  159. local layer = human.lostTemple.layer
  160. local random = human.lostTemple.random
  161. local LostTempleConfig = LostTempleExcel[layer]
  162. if not LostTempleConfig then return end
  163. local LostTemple = LostTempleConfig[random]
  164. if not LostTemple then return end
  165. print("layler=", human.lostTemple.layer, "random=", human.lostTemple.random, "playerX=", human.lostTemple.x, "playerY=", human.lostTemple.y)
  166. for x = startX, endX do
  167. human.lostTemple.grid[x] = human.lostTemple.grid[x] or { }
  168. local LostTempleX = LostTemple[x]
  169. if LostTempleX then
  170. for y = 1, LostTemple.vertical do
  171. if LostTempleX[y] then
  172. print("x=", x, "y=", y, "id=", human.lostTemple.grid[x][y].id)
  173. end
  174. end
  175. end
  176. end
  177. return true
  178. end
  179. --
  180. local function makeMonsterGrid(human, cmd)
  181. if not human.lostTemple then return end
  182. local x = human.lostTemple.x
  183. local layer = human.lostTemple.layer
  184. local LostTempleMonster = LostTempleExcel.Lost[x]
  185. if not LostTempleMonster then return end
  186. -- 取共鸣英雄的等级
  187. local totalLv = 0
  188. local equally = 0
  189. local equallyLv = 0
  190. local db = human.db.xingYaoGongMing
  191. if db and db.defList then
  192. for heroIndex in pairs(db.defList) do
  193. local heroGrid = human.db.heroBag[heroIndex]
  194. if heroGrid then
  195. totalLv = totalLv + heroGrid.lv
  196. equally = equally + 1
  197. end
  198. end
  199. end
  200. local randomId = 0
  201. if cmd == "nomalMonster" then
  202. randomId = math.random(LostTempleMonster.nomal[layer][1], LostTempleMonster.nomal[layer][2])
  203. elseif cmd == "eliteMonster" then
  204. randomId = math.random(LostTempleMonster.elite[layer][1], LostTempleMonster.elite[layer][2])
  205. elseif cmd == "eliteBoss" then
  206. randomId = math.random(LostTempleMonster.elite[layer][1], LostTempleMonster.elite[layer][2])
  207. end
  208. equallyLv = math.ceil(totalLv / equally * randomId / 10000)
  209. local monsterOutID = 0
  210. for i = 1, #LostTempleExcel.Monster do
  211. if equallyLv >= LostTempleExcel.Monster[i].lvminmax[1] and equallyLv <= LostTempleExcel.Monster[i].lvminmax[2] then
  212. local randomIndex = math.random(1, #LostTempleExcel.Monster[i].monsteroutid)
  213. monsterOutID = LostTempleExcel.Monster[i].monsteroutid[randomIndex]
  214. break
  215. end
  216. end
  217. if monsterOutID == 0 then
  218. assert(nil, "monsterOutID is error equallyLv=" .. equallyLv .. "-randomId=" .. randomId)
  219. end
  220. return monsterOutID
  221. end
  222. -- 制造一个召唤祭坛
  223. local function makeSummonHeroGrid(human)
  224. -- 取共鸣英雄的等级
  225. local totalLv = 0
  226. local equally = 0
  227. local equallyLv = 0
  228. local db = human.db.xingYaoGongMing
  229. if db and db.defList then
  230. for heroIndex in pairs(db.defList) do
  231. local heroGrid = human.db.heroBag[heroIndex]
  232. if heroGrid then
  233. totalLv = totalLv + heroGrid.lv
  234. equally = equally + 1
  235. end
  236. end
  237. end
  238. equallyLv = math.ceil(totalLv / equally)
  239. local heroIndex = nil
  240. for i = 1, #LostTempleExcel.Hero do
  241. if equallyLv >= LostTempleExcel.Hero[i].lvminmax[1] and equallyLv <= LostTempleExcel.Hero[i].lvminmax[2] then
  242. heroIndex = i
  243. break
  244. end
  245. end
  246. if heroIndex == nil then
  247. assert(nil, "heroid is error equallyLv=" .. equallyLv)
  248. end
  249. --
  250. local summonHero = { }
  251. local weightHeroTb = Util.copyTable(LostTempleExcel.Hero[heroIndex].heroid)
  252. -- 根据权重取出4英雄
  253. local totalWeight = 0
  254. for i = 1, #weightHeroTb do
  255. totalWeight = totalWeight + weightHeroTb[i][4]
  256. end
  257. -- 取4次
  258. local len = 0
  259. for k = 1, 4 do
  260. local random = math.random(1, totalWeight)
  261. for i = 1, #weightHeroTb do
  262. if random <= weightHeroTb[i][4] then
  263. len = len + 1
  264. summonHero[len] = { }
  265. summonHero[len].id = weightHeroTb[i][1]
  266. summonHero[len].lv = weightHeroTb[i][2]
  267. local maxStar = HeroDefine.getMaxHeroStar(weightHeroTb[i][1])
  268. summonHero[len].star = maxStar > weightHeroTb[i][3] and weightHeroTb[i][3] or maxStar
  269. -- 最后一个放入到 这一个里面 删掉最后一个
  270. totalWeight = totalWeight - weightHeroTb[i][4]
  271. weightHeroTb[i] = weightHeroTb[#weightHeroTb]
  272. weightHeroTb[#weightHeroTb] = nil
  273. break
  274. end
  275. random = random - weightHeroTb[i][4]
  276. end
  277. end
  278. if #summonHero == 0 then
  279. assert(nil, "summonHero is error equallyLv=" .. equallyLv)
  280. end
  281. return summonHero
  282. end
  283. -- 制造一个智慧树
  284. local function makeSummonTreeGrid(human)
  285. --
  286. local summonTree = { }
  287. local weightTreeTb = Util.copyTable(LostTempleExcel.Tree)
  288. -- 根据权重取出4英雄
  289. local totalWeight = 0
  290. for i = 1, #weightTreeTb do
  291. totalWeight = totalWeight + weightTreeTb[i].weight
  292. end
  293. -- 取3次
  294. local len = 0
  295. for k = 1, 3 do
  296. local random = math.random(1, totalWeight)
  297. for i = 1, #weightTreeTb do
  298. if random <= weightTreeTb[i].weight then
  299. len = len + 1
  300. summonTree[len] = i
  301. -- 最后一个放入到 这一个里面 删掉最后一个
  302. totalWeight = totalWeight - weightTreeTb[i].weight
  303. weightTreeTb[i] = weightTreeTb[#weightTreeTb]
  304. weightTreeTb[#weightTreeTb] = nil
  305. break
  306. end
  307. random = random - weightTreeTb[i].weight
  308. end
  309. end
  310. if #summonTree == 0 then
  311. assert(nil, "summonTree is error")
  312. end
  313. return summonTree
  314. end
  315. -- 神界商店
  316. local function makeSummonShopGrid(human)
  317. --
  318. local summonShop = { }
  319. local weightShopTb = Util.copyTable(LostTempleExcel.LostShop)
  320. -- 根据权重取出4英雄
  321. local totalWeight = 0
  322. for i = 1, #weightShopTb do
  323. totalWeight = totalWeight + weightShopTb[i].weight
  324. end
  325. -- 取3次
  326. local len = 0
  327. for k = 1, 4 do
  328. local random = math.random(1, totalWeight)
  329. for i = 1, #weightShopTb do
  330. if random <= weightShopTb[i].weight then
  331. len = len + 1
  332. summonShop[len] = i
  333. -- 最后一个放入到 这一个里面 删掉最后一个
  334. totalWeight = totalWeight - weightShopTb[i].weight
  335. weightShopTb[i] = weightShopTb[#weightShopTb]
  336. weightShopTb[#weightShopTb] = nil
  337. break
  338. end
  339. random = random - weightShopTb[i].weight
  340. end
  341. end
  342. if #summonShop == 0 then
  343. assert(nil, "summonShop is error")
  344. end
  345. return summonShop
  346. end
  347. -- 制造一个宝箱
  348. local function makeBoxGrid(human)
  349. for i = 1, #ElementExcel do
  350. local element = ElementExcel[i]
  351. if element.cmd == "summonBox" then
  352. return i
  353. end
  354. end
  355. end
  356. -- 制造一个传送门
  357. local function makeConverDoorGrid(human)
  358. for i = 1, #ElementExcel do
  359. local element = ElementExcel[i]
  360. if element.cmd == "conveyDoor" then
  361. return i
  362. end
  363. end
  364. end
  365. -- 初始化玩家当前格子
  366. local function makeGrid(human)
  367. if not human.lostTemple then return end
  368. local layer = human.lostTemple.layer
  369. local random = human.lostTemple.random
  370. local LostTempleConfig = LostTempleExcel[layer]
  371. if not LostTempleConfig then return end
  372. local LostTemple = LostTempleConfig[random]
  373. if not LostTemple then return end
  374. -- 清除玩家当前位置的数据
  375. human.lostTemple.grid = human.lostTemple.grid or { }
  376. human.lostTemple.grid[human.lostTemple.x] = nil
  377. local startX = human.lostTemple.x + 1
  378. local endX = human.lostTemple.x + QUEUE_LEN
  379. for x = startX, endX do
  380. local LostTempleX = LostTemple[x]
  381. if LostTempleX then
  382. human.lostTemple.grid[x] = human.lostTemple.grid[x] or { }
  383. for y = 1, LostTemple.vertical do
  384. if LostTempleX[y] then
  385. if not human.lostTemple.grid[x][y] then
  386. human.lostTemple.grid[x][y] = { id = LostTempleX[y][1] }
  387. end
  388. local element = ElementExcel[LostTempleX[y][1]]
  389. -- 召唤神坛
  390. if element.cmd == "summonHero" then
  391. human.lostTemple.grid[x][y].summonHero = makeSummonHeroGrid(human)
  392. end
  393. -- 智慧树
  394. if element.cmd == "summonTree" then
  395. human.lostTemple.grid[x][y].summonTree = makeSummonTreeGrid(human)
  396. end
  397. -- 神界商店
  398. if element.cmd == "summonShop" then
  399. human.lostTemple.grid[x][y].summonShop = makeSummonShopGrid(human)
  400. end
  401. --只生成 第一层的怪物
  402. if x == startX then
  403. if element.cmd == "nomalMonster" or element.cmd == "eliteMonster" or element.cmd == "eliteBoss" then
  404. human.lostTemple.grid[x][y].monsterOutID = makeMonsterGrid(human, element.cmd)
  405. end
  406. end
  407. end
  408. end
  409. end
  410. end
  411. return true
  412. end
  413. -- 制造一个默认的位置数据
  414. local function makeLostTempLe(layer)
  415. -- 第一层
  416. local LostTempleConfig = LostTempleExcel[layer]
  417. if not LostTempleConfig then
  418. assert(nil, "lostTemple startLayer error = " .. layer)
  419. end
  420. -- 随机一张地图
  421. local startRandom = math.random(1, #LostTempleConfig)
  422. local LostTemple = LostTempleConfig[startRandom]
  423. if not LostTemple then return end
  424. -- 起始位置
  425. local LostTempleX = LostTemple[START_X]
  426. if not LostTempleX then
  427. assert(nil, "lostTemple startX error = " .. START_LAYER)
  428. end
  429. -- 找到纵向可以站立的位置
  430. local startY = 1
  431. for y = 1, LostTemple.vertical do
  432. if LostTempleX[y] and LostTempleX[y][1] == 0 then
  433. startY = y
  434. break
  435. end
  436. end
  437. return layer, START_X, startY, startRandom
  438. end
  439. -- 初始化
  440. local function initDB(human)
  441. if human.lostTemple then return end
  442. local lostLayer, lostX, lostY, lostRandom = makeLostTempLe(START_LAYER)
  443. if not lostLayer then return end
  444. human.lostTemple = { layer = lostLayer, x = lostX, y = lostY, random = lostRandom, box = nil, grid = nil }
  445. makeGrid(human)
  446. dbSave(human)
  447. end
  448. -- human = { }
  449. -- initDB(human)
  450. -- printGrid(human)
  451. -- print("-----------------------------")
  452. -- 下一格
  453. function nextGrid(human, y)
  454. if not human.lostTemple then return end
  455. local layer = human.lostTemple.layer
  456. local LostTempleConfig = LostTempleExcel[layer]
  457. if not LostTempleConfig then
  458. assert(nil, "lostTemple startLayer error = " .. layer)
  459. end
  460. local random = human.lostTemple.random
  461. local LostTemple = LostTempleConfig[random]
  462. if not LostTemple then return end
  463. local x = human.lostTemple.x + 1
  464. local LostTempleX = LostTemple[x]
  465. if not LostTempleX then return end
  466. local LostTempleY = LostTempleX[y]
  467. if not LostTempleY then return end
  468. human.lostTemple.x = x
  469. human.lostTemple.y = y
  470. makeGrid(human)
  471. end
  472. -- 下一层
  473. local function nextDB(human)
  474. if not human.lostTemple then return end
  475. local nextLayer = human.lostTemple.layer + 1
  476. local LostTempleConfig = LostTempleExcel[nextLayer]
  477. if not LostTempleConfig then return end
  478. local lostLayer, lostX, lostY, lostRandom = makeLostTempLe(nextLayer)
  479. if not lostLayer then return end
  480. human.lostTemple.layer = lostLayer
  481. human.lostTemple.x = lostX
  482. human.lostTemple.y = lostY
  483. human.lostTemple.random = lostRandom
  484. human.lostTemple.grid = nil
  485. makeGrid(human)
  486. end
  487. --
  488. local function makeGridNet(human, net)
  489. if not human.lostTemple then return end
  490. local startX = human.lostTemple.x + 1
  491. local endX = human.lostTemple.x + QUEUE_LEN
  492. local layer = human.lostTemple.layer
  493. local random = human.lostTemple.random
  494. local LostTempleConfig = LostTempleExcel[layer]
  495. if not LostTempleConfig then return end
  496. local LostTemple = LostTempleConfig[random]
  497. if not LostTemple then return end
  498. net[0] = 0
  499. local len = 0
  500. for x = startX, endX do
  501. if human.lostTemple.grid[x] then
  502. for y = 1, LostTemple.vertical do
  503. if human.lostTemple.grid[x][y] then
  504. len = len + 1
  505. local grid = human.lostTemple.grid[x][y]
  506. local element = ElementExcel[grid.id]
  507. if not element then
  508. assert(nil, "lostTemple element error = " .. grid.id)
  509. end
  510. net[len].id = grid.id
  511. net[len].name = element.name
  512. net[len].type = element.type
  513. net[len].desc = element.desc
  514. net[len].x = x
  515. net[len].y = y
  516. net[len].body = 0
  517. if grid.monsterOutID then
  518. if not MonsterOutExcel[grid.monsterOutID] then
  519. assert(nil, "lostTemple monsterOutID error = " .. grid.monsterOutID)
  520. end
  521. local monsterConfig = MonsterExcel.monster[MonsterOutExcel[grid.monsterOutID].member[1][1]]
  522. if not monsterConfig then
  523. assert(nil, "lostTemple monsterOutID error = " .. MonsterOutExcel[grid.monsterOutID].member[1][1])
  524. end
  525. net[len].body = monsterConfig.body
  526. end
  527. end
  528. end
  529. end
  530. end
  531. net[0] = len
  532. return true
  533. end
  534. --通关
  535. function IsPass(human)
  536. initDB(human)
  537. if not human.lostTemple then return end
  538. local startX = human.lostTemple.x + 1
  539. local endX = human.lostTemple.x + QUEUE_LEN
  540. local layer = human.lostTemple.layer
  541. local random = human.lostTemple.random
  542. local LostTempleConfig = LostTempleExcel[layer]
  543. if not LostTempleConfig then return end
  544. local LostTemple = LostTempleConfig[random]
  545. if not LostTemple then return end
  546. local type = 0
  547. local len = 0
  548. for x = startX, endX do
  549. if human.lostTemple.grid[x] then
  550. for y = 1, LostTemple.vertical do
  551. if human.lostTemple.grid[x][y] then
  552. len = len + 1
  553. local grid = human.lostTemple.grid[x][y]
  554. local element = ElementExcel[grid.id]
  555. if not element then
  556. return false
  557. end
  558. type = element.type
  559. end
  560. end
  561. end
  562. end
  563. if len == 1 and type == 6 and layer >= 3 then
  564. return true
  565. end
  566. return false
  567. end
  568. -- 查询
  569. function query(human)
  570. if not isOpen(human) then
  571. return
  572. end
  573. -- 没有共鸣
  574. local db = human.db.xingYaoGongMing
  575. if not db or not db.defList then
  576. return
  577. end
  578. initDB(human)
  579. local leftTime = getLeftTime()
  580. local msgRet = Msg.gc.GC_LOST_TEMPLE_QUERY
  581. msgRet.leftTime = leftTime
  582. if not makeGridNet(human, msgRet.list) then return end
  583. msgRet.playerX = human.lostTemple.x
  584. msgRet.playerY = human.lostTemple.y
  585. msgRet.layer = human.lostTemple.layer
  586. msgRet.leftTime = leftTime
  587. Msg.send(msgRet, human.fd)
  588. sendHeroStatus(human)
  589. end
  590. -- 更新
  591. function update(human)
  592. if not human.lostTemple then
  593. return
  594. end
  595. local msgRet = Msg.gc.GC_LOST_TEMPLE_UPDATE
  596. if not makeGridNet(human, msgRet.list) then
  597. return
  598. end
  599. local leftTime = getLeftTime()
  600. msgRet.leftTime = leftTime
  601. msgRet.playerX = human.lostTemple.x
  602. msgRet.playerY = human.lostTemple.y
  603. msgRet.layer = human.lostTemple.layer
  604. Msg.send(msgRet, human.fd)
  605. end
  606. -- 检测点击格子是否合法
  607. function checkPutByY(human, y)
  608. local startX = human.lostTemple.x + 1
  609. if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
  610. local grid = human.lostTemple.grid[startX][y]
  611. -- 检测点击位置是否合法
  612. return grid
  613. end
  614. -- 检测点击格子是否合法
  615. function checkPut(human, x, y)
  616. local startX = x
  617. if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
  618. local grid = human.lostTemple.grid[startX][y]
  619. -- 检测点击位置是否合法
  620. return grid
  621. end
  622. -- 设置格子
  623. function putSet(human, y, cmd)
  624. local startX = human.lostTemple.x + 1
  625. if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
  626. if cmd == "eliteBoss" then
  627. human.lostTemple.grid[startX][y] = { id = makeBoxGrid(human) }
  628. return true
  629. end
  630. if cmd == "summonBox" then
  631. human.lostTemple.grid[startX][y] = { id = makeConverDoorGrid(human) }
  632. return true
  633. end
  634. end
  635. -- 走到下一步
  636. function put(human, op, x, y, arg)
  637. if not isOpen(human) then return end
  638. if not human.lostTemple then return end
  639. if op ~= OP_QUERY and op ~= OP_CONFIRM then return end
  640. local grid = checkPut(human, x, y)
  641. if not grid then return end
  642. local elementConfig = ElementExcel[grid.id]
  643. if not elementConfig then return end
  644. local ret = nil
  645. if Lost_Handle_Func[elementConfig.cmd] then
  646. ret = Lost_Handle_Func[elementConfig.cmd](human, op, y, grid, arg, elementConfig)
  647. end
  648. if ret then
  649. nextGrid(human, y)
  650. dbSave(human)
  651. update(human)
  652. end
  653. end
  654. -- 怪物面板
  655. local function monsterQuery(human, grid, elementConfig)
  656. if not human.lostTemple then return end
  657. if not grid.monsterOutID then return end
  658. local rewardConfig = LostTempleExcel.Drop[elementConfig.arg[1]]
  659. if not rewardConfig then return end
  660. local msgRet = Msg.gc.GC_LOST_TEMPLE_MONSTER
  661. msgRet.gdReward[0] = 0
  662. for _, item in ipairs(rewardConfig.drop) do
  663. msgRet.gdReward[0] = msgRet.gdReward[0] + 1
  664. Grid.makeItem(msgRet.gdReward[msgRet.gdReward[0]], item[1], item[2])
  665. end
  666. msgRet.randomReward[0] = 0
  667. for _, item in ipairs(rewardConfig.randomdrop) do
  668. if type(item) == "table" then
  669. msgRet.randomReward[0] = msgRet.randomReward[0] + 1
  670. Grid.makeItem(msgRet.randomReward[msgRet.randomReward[0]], item[1], item[2])
  671. end
  672. end
  673. local monsterOutConfig = MonsterOutExcel[grid.monsterOutID]
  674. if not monsterOutConfig then return end
  675. local formation = monsterOutConfig.formation
  676. formation = formation == 0 and 1 or formation
  677. local mationConfig = CombatPosExcel.formation[formation]
  678. local posList = mationConfig.pos
  679. if not posList then return end
  680. msgRet.list[0] = 0
  681. for i, member in ipairs(monsterOutConfig.member) do
  682. local monsterID = member[1]
  683. local monsterConfig = MonsterExcel.monster[monsterID]
  684. if posList[i] then
  685. local defPos = CombatLogic.getPos(CombatDefine.DEFEND_SIDE, posList[i])
  686. local monsterLv = member[2]
  687. local obj = grid.objStatus and grid.objStatus[defPos] or nil
  688. local hpRate = obj and obj.hpRate or 1
  689. local hp = math.ceil(INIT_HP_MAX * hpRate)
  690. local hpMax = INIT_HP_MAX
  691. local others = HeroGrid.createOthers(monsterLv, hp, hpMax, monsterConfig.star)
  692. msgRet.list[0] = msgRet.list[0] + 1
  693. HeroGrid.makeHeroSimpleByMonsterID(msgRet.list[msgRet.list[0]], monsterID, others)
  694. end
  695. end
  696. msgRet.showNext = 0
  697. if human.db.zhandouli >= SHOWQUICKPOWER then
  698. msgRet.showNext = 1
  699. end
  700. msgRet.quick = 0
  701. if human.db.combatQuick[CombatDefine.COMBAT_TYPE24] == 1 then
  702. msgRet.quick = 1
  703. end
  704. Msg.send(msgRet, human.fd)
  705. end
  706. -- 英雄列表
  707. function sendHeroStatus(human)
  708. if not human.lostTemple then return end
  709. local msgRet = Msg.gc.GC_LOST_TEMPLE_HERO_STATUS
  710. msgRet.list[0] = 0
  711. msgRet.isEnd = 0
  712. local len = 0
  713. if human.lostTemple.heroStatus then
  714. for k, hpRate in pairs(human.lostTemple.heroStatus) do
  715. local hp = math.ceil(INIT_HP_MAX * hpRate)
  716. local hpMax = INIT_HP_MAX
  717. len = len + 1
  718. local net = msgRet.list[len]
  719. net.hp = hp
  720. net.hpMax = hpMax
  721. net.uuid = k
  722. if len >= 30 then
  723. msgRet.isEnd = 0
  724. msgRet.list[0] = len
  725. Msg.send(msgRet, human.fd)
  726. len = 0
  727. end
  728. end
  729. end
  730. msgRet.isEnd = 1
  731. msgRet.list[0] = len
  732. Msg.send(msgRet, human.fd)
  733. end
  734. -- 推送召唤祭坛英雄列表
  735. function sendSummonHeroList(human)
  736. if not human.lostTemple then return end
  737. if not human.lostTemple.summonHero then return end
  738. local msgRet = Msg.gc.GC_LOST_TEMPLE_SUMMON_LIST
  739. msgRet.list[0] = 0
  740. for index = 1, human.lostTemple.summonHero[0] do
  741. msgRet.list[0] = msgRet.list[0] + 1
  742. HeroGrid.makeHeroSimple(msgRet.list[msgRet.list[0]], human.lostTemple.summonHero[index], index)
  743. end
  744. Msg.send(msgRet, human.fd)
  745. end
  746. -- 推送buff属性
  747. function sendSummonTreeList(human)
  748. if not human.lostTemple then return end
  749. if not human.lostTemple.summonTree then return end
  750. local msgRet = Msg.gc.GC_LOST_TEMPLE_BUFF_LIST
  751. msgRet.list[0] = 0
  752. for k, v in pairs(human.lostTemple.summonTree) do
  753. msgRet.list[0] = msgRet.list[0] + 1
  754. local net = msgRet.list[msgRet.list[0]]
  755. net.attr.key = k
  756. net.attr.value = v
  757. net.name = ""
  758. for i = 1, #LostTempleExcel.Tree do
  759. if LostTempleExcel.Tree[i].icon == k then
  760. net.name = LostTempleExcel.Tree[i].buffname
  761. break
  762. end
  763. end
  764. end
  765. Msg.send(msgRet, human.fd)
  766. end
  767. -- 随机奖励宝箱
  768. function sendRandomBox(human)
  769. if not human.lostTemple then return end
  770. local msgRet = Msg.gc.GC_LOGT_TEMPLE_RANDOM_BOX
  771. local len = 0
  772. if human.lostTemple.randomReward then
  773. for k, v in pairs(human.lostTemple.randomReward) do
  774. len = len + 1
  775. Grid.makeItem(msgRet.randomReward[len], k, v)
  776. end
  777. end
  778. msgRet.randomReward[0] = len
  779. Msg.send(msgRet, human.fd)
  780. end
  781. --
  782. function Lost_Handle_Func.nomalMonster(human, op, y, grid, arg, elementConfig)
  783. if op == OP_QUERY then
  784. monsterQuery(human, grid, elementConfig)
  785. end
  786. end
  787. --
  788. function Lost_Handle_Func.eliteMonster(human, op, y, grid, arg, elementConfig)
  789. if op == OP_QUERY then
  790. monsterQuery(human, grid, elementConfig)
  791. end
  792. end
  793. --
  794. function Lost_Handle_Func.eliteBoss(human, op, y, grid, arg, elementConfig)
  795. if op == OP_QUERY then
  796. monsterQuery(human, grid, elementConfig)
  797. end
  798. end
  799. --
  800. function Lost_Handle_Func.summonHero(human, op, y, grid, arg, elementConfig)
  801. -- 召唤神坛查询
  802. if op == OP_QUERY then
  803. if not grid.summonHero then return end
  804. local msgRet = Msg.gc.GC_LOST_TEMPLE_SUMMON
  805. msgRet.list[0] = 0
  806. for i = 1, #grid.summonHero do
  807. local hero = grid.summonHero[i]
  808. msgRet.list[0] = msgRet.list[0] + 1
  809. local others = HeroGrid.createOthers(hero.lv, INIT_HP_MAX, INIT_HP_MAX, hero.star)
  810. HeroGrid.makeHeroSimpleByID(msgRet.list[msgRet.list[0]], hero.id, i, others)
  811. end
  812. Msg.send(msgRet, human.fd)
  813. return
  814. end
  815. -- 添加召唤英雄
  816. if op == OP_CONFIRM then
  817. local index = tonumber(arg)
  818. if not grid.summonHero then return end
  819. local hero = grid.summonHero[index]
  820. if not hero then return end
  821. local heroGrid = HeroGrid.createHeroGrid(hero.id, hero.star)
  822. if not heroGrid then return end
  823. heroGrid.isLostTemple = 1
  824. -- 初始化属性
  825. local attrConfig = HeroDefine.getAttrConfig(hero.id, heroGrid.star)
  826. if not attrConfig then return end
  827. local quality = HeroGrid.getMaxQualityByLv(heroGrid.star, hero.lv)
  828. local maxLv = HeroGrid.getMaxLv(heroGrid.star, quality)
  829. heroGrid.lv = math.min(maxLv, hero.lv or 0)
  830. heroGrid.quality = math.max(heroGrid.quality, quality or 0)
  831. -- 加入装备
  832. -- 加入到英雄队列
  833. human.lostTemple.summonHero = human.lostTemple.summonHero or { }
  834. human.lostTemple.summonHero[0] = human.lostTemple.summonHero[0] or 0
  835. human.lostTemple.summonHero[0] = human.lostTemple.summonHero[0] + 1
  836. local addIndex = human.lostTemple.summonHero[0]
  837. human.lostTemple.summonHero[addIndex] = heroGrid
  838. heroGrid.bagIndex = addIndex
  839. -- 计算属性
  840. LostTempleCombatLogic.getHeroAttrs(human, addIndex)
  841. -- 通知客户端
  842. sendSummonHeroList(human)
  843. return true
  844. end
  845. end
  846. -- 智慧树
  847. function Lost_Handle_Func.summonTree(human, op, y, grid, arg, elementConfig)
  848. -- 召唤神坛查询
  849. if op == OP_QUERY then
  850. if not grid.summonTree then return end
  851. local msgRet = Msg.gc.GC_LOST_TEMPLE_BUFF
  852. msgRet.list[0] = 0
  853. for i = 1, #grid.summonTree do
  854. local hero = grid.summonTree[i]
  855. msgRet.list[0] = msgRet.list[0] + 1
  856. local config = LostTempleExcel.Tree[grid.summonTree[i]]
  857. local net = msgRet.list[msgRet.list[0]]
  858. net.id = i
  859. net.icon = config.icon
  860. net.name = config.buffname
  861. net.attr[0] = #config.Buffid
  862. for i = 1, #config.Buffid do
  863. net.attr[i].key = config.Buffid[i][1]
  864. net.attr[i].value = config.Buffid[i][2]
  865. end
  866. end
  867. Msg.send(msgRet, human.fd)
  868. return
  869. end
  870. -- 添加召唤英雄
  871. if op == OP_CONFIRM then
  872. local index = tonumber(arg)
  873. if not grid.summonTree then return end
  874. local buffID = grid.summonTree[index]
  875. if not buffID then return end
  876. local config = LostTempleExcel.Tree[buffID]
  877. if not config then return end
  878. human.lostTemple.summonTree = human.lostTemple.summonTree or { }
  879. for i = 1, #config.Buffid do
  880. local key = config.Buffid[i][1]
  881. local value = config.Buffid[i][2]
  882. human.lostTemple.summonTree[key] = human.lostTemple.summonTree[key] or 0
  883. human.lostTemple.summonTree[key] = human.lostTemple.summonTree[key] + value
  884. end
  885. sendSummonTreeList(human)
  886. return true
  887. end
  888. end
  889. -- 炽天使
  890. function Lost_Handle_Func.treatRevive(human, op, y, grid, arg, elementConfig)
  891. if op == OP_QUERY then
  892. return
  893. end
  894. -- 复活治疗
  895. if op == OP_CONFIRM then
  896. local opType = tonumber(arg)
  897. local heroStatus = human.lostTemple.heroStatus
  898. if not heroStatus then return true end
  899. -- 复活
  900. if opType == 1 then
  901. local len = 0
  902. local cnt = 0
  903. local revice = {}
  904. local hpList = {}
  905. for k, hpRate in pairs(heroStatus) do
  906. if hpRate <= 0.0 then
  907. len = len + 1
  908. revice[len]=k
  909. else
  910. if hpRate < 1.0 then
  911. cnt = cnt + 1
  912. hpList[cnt] = k
  913. end
  914. end
  915. end
  916. if #revice > 0 then
  917. local random = math.random(1, #revice)
  918. heroStatus[revice[random]] = nil
  919. elseif #hpList > 0 then
  920. local random = math.random(1, #hpList)
  921. heroStatus[hpList[random]] = nil
  922. end
  923. end
  924. -- 治疗
  925. if opType == 2 then
  926. for k, hpRate in pairs(heroStatus) do
  927. if heroStatus[k] > 0.0 then
  928. heroStatus[k] = hpRate + 0.5
  929. if heroStatus[k] >= 1.0 then
  930. heroStatus[k] = nil
  931. end
  932. end
  933. end
  934. end
  935. sendHeroStatus(human)
  936. return true
  937. end
  938. end
  939. -- 神界商店
  940. function Lost_Handle_Func.summonShop(human, op, y, grid, arg, elementConfig)
  941. if op == OP_QUERY then
  942. if not grid.summonShop then return end
  943. local msgRet = Msg.gc.GC_LOST_TEMPLE_SHOP
  944. msgRet.list[0] = 0
  945. for i = 1, #grid.summonShop do
  946. msgRet.list[0] = msgRet.list[0] + 1
  947. local config = LostTempleExcel.LostShop[grid.summonShop[i]]
  948. local net = msgRet.list[msgRet.list[0]]
  949. Grid.makeItem(net.item, config.itemid, config.itemnum)
  950. Grid.makeItem(net.needItem, config.spenditem, config.spendnum)
  951. net.discount = config.discount
  952. net.id = i
  953. end
  954. Msg.send(msgRet, human.fd)
  955. return
  956. end
  957. -- 购买东西
  958. if op == OP_CONFIRM then
  959. local index = tonumber(arg)
  960. if not grid.summonShop then return end
  961. local shopID = grid.summonShop[index]
  962. if not shopID then return end
  963. local config = LostTempleExcel.LostShop[shopID]
  964. if not config then return end
  965. if not BagLogic.checkItemCnt(human, config.spenditem, config.spendnum) then
  966. return
  967. end
  968. BagLogic.delItem(human, config.spenditem, config.spendnum, "lostTemple")
  969. BagLogic.addItem(human, config.itemid, config.itemnum, "lostTemple")
  970. return true
  971. end
  972. end
  973. -- -- 宝箱
  974. function Lost_Handle_Func.summonBox(human, op, y, grid, arg, elementConfig)
  975. if op == OP_QUERY then
  976. sendRandomBox(human)
  977. return
  978. end
  979. --
  980. if op == OP_CONFIRM then
  981. if human.lostTemple.randomReward then
  982. local item = { }
  983. local len = 0
  984. for k, v in pairs(human.lostTemple.randomReward) do
  985. len = len + 1
  986. item[len] = { k, v }
  987. end
  988. BagLogic.addItemList(human, item, "lostTemple")
  989. human.lostTemple.randomReward = nil
  990. end
  991. -- 判定有没有下一程
  992. local nextLayer = human.lostTemple.layer + 1
  993. local LostTempleConfig = LostTempleExcel[nextLayer]
  994. if LostTempleConfig then
  995. -- 变成传送门
  996. putSet(human, y, elementConfig.cmd)
  997. end
  998. dbSave(human)
  999. update(human)
  1000. end
  1001. end
  1002. -- 传送门
  1003. function Lost_Handle_Func.conveyDoor(human, op, y, grid, arg, elementConfig)
  1004. if op == OP_QUERY then
  1005. return
  1006. end
  1007. -- 进入下一层
  1008. if op == OP_CONFIRM then
  1009. nextDB(human)
  1010. dbSave(human)
  1011. update(human)
  1012. end
  1013. end
  1014. function lostTempleRevice(human)
  1015. if not human.lostTemple then return end
  1016. human.lostTemple.heroStatus = nil
  1017. sendHeroStatus(human)
  1018. end