lostTempleLogic.lua 37 KB

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