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