lostTempleLogic.lua 34 KB

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