lostTempleLogic.lua 36 KB

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