lostTempleLogic.lua 33 KB

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