lostTempleLogic.lua 34 KB

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