lostTempleLogic.lua 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  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 IsPass(human)
  540. initDB(human)
  541. if not human.lostTemple then return end
  542. local startX = human.lostTemple.x + 1
  543. local endX = human.lostTemple.x + QUEUE_LEN
  544. local layer = human.lostTemple.layer
  545. local random = human.lostTemple.random
  546. local LostTempleConfig = LostTempleExcel[layer]
  547. if not LostTempleConfig then return end
  548. local LostTemple = LostTempleConfig[random]
  549. if not LostTemple then return end
  550. local type = 0
  551. local len = 0
  552. for x = startX, endX do
  553. if human.lostTemple.grid[x] then
  554. for y = 1, LostTemple.vertical do
  555. if human.lostTemple.grid[x][y] then
  556. len = len + 1
  557. local grid = human.lostTemple.grid[x][y]
  558. local element = ElementExcel[grid.id]
  559. if not element then
  560. return false
  561. end
  562. type = element.type
  563. end
  564. end
  565. end
  566. end
  567. if len == 1 and type == 6 and layer >= 3 then
  568. return true
  569. end
  570. return false
  571. end
  572. -- ��ѯ
  573. function query(human)
  574. if not isOpen(human) then
  575. return
  576. end
  577. -- û�й���
  578. local db = human.db.xingYaoGongMing
  579. if not db or not db.defList then
  580. return
  581. end
  582. initDB(human)
  583. local leftTime = getLeftTime()
  584. local msgRet = Msg.gc.GC_LOST_TEMPLE_QUERY
  585. msgRet.leftTime = leftTime
  586. if not makeGridNet(human, msgRet.list) then return end
  587. msgRet.playerX = human.lostTemple.x
  588. msgRet.playerY = human.lostTemple.y
  589. msgRet.layer = human.lostTemple.layer
  590. msgRet.leftTime = leftTime
  591. Msg.send(msgRet, human.fd)
  592. sendHeroStatus(human)
  593. end
  594. -- ����
  595. function update(human)
  596. if not human.lostTemple then
  597. return
  598. end
  599. local msgRet = Msg.gc.GC_LOST_TEMPLE_UPDATE
  600. if not makeGridNet(human, msgRet.list) then
  601. return
  602. end
  603. local leftTime = getLeftTime()
  604. msgRet.leftTime = leftTime
  605. msgRet.playerX = human.lostTemple.x
  606. msgRet.playerY = human.lostTemple.y
  607. msgRet.layer = human.lostTemple.layer
  608. Msg.send(msgRet, human.fd)
  609. end
  610. -- ����������Ƿ�Ϸ�
  611. function checkPutByY(human, y)
  612. local startX = human.lostTemple.x + 1
  613. if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
  614. local grid = human.lostTemple.grid[startX][y]
  615. -- �����λ���Ƿ�Ϸ�
  616. return grid
  617. end
  618. -- ����������Ƿ�Ϸ�
  619. function checkPut(human, x, y)
  620. local startX = x
  621. if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
  622. local grid = human.lostTemple.grid[startX][y]
  623. -- �����λ���Ƿ�Ϸ�
  624. return grid
  625. end
  626. -- ���ø���
  627. function putSet(human, y, cmd)
  628. local startX = human.lostTemple.x + 1
  629. if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
  630. if cmd == "eliteBoss" then
  631. human.lostTemple.grid[startX][y] = { id = makeBoxGrid(human) }
  632. return true
  633. end
  634. if cmd == "summonBox" then
  635. human.lostTemple.grid[startX][y] = { id = makeConverDoorGrid(human) }
  636. return true
  637. end
  638. end
  639. -- �ߵ���һ��
  640. function put(human, op, x, y, arg)
  641. if not isOpen(human) then return end
  642. if not human.lostTemple then return end
  643. if op ~= OP_QUERY and op ~= OP_CONFIRM then return end
  644. local grid = checkPut(human, x, y)
  645. if not grid then return end
  646. local elementConfig = ElementExcel[grid.id]
  647. if not elementConfig then return end
  648. local ret = nil
  649. if Lost_Handle_Func[elementConfig.cmd] then
  650. ret = Lost_Handle_Func[elementConfig.cmd](human, op, y, grid, arg, elementConfig)
  651. end
  652. if ret then
  653. nextGrid(human, y)
  654. dbSave(human)
  655. update(human)
  656. end
  657. end
  658. -- �������
  659. local function monsterQuery(human, grid, elementConfig)
  660. if not human.lostTemple then return end
  661. if not grid.monsterOutID then return end
  662. local rewardConfig = LostTempleExcel.Drop[elementConfig.arg[1]]
  663. if not rewardConfig then return end
  664. local msgRet = Msg.gc.GC_LOST_TEMPLE_MONSTER
  665. msgRet.gdReward[0] = 0
  666. for _, item in ipairs(rewardConfig.drop) do
  667. msgRet.gdReward[0] = msgRet.gdReward[0] + 1
  668. Grid.makeItem(msgRet.gdReward[msgRet.gdReward[0]], item[1], item[2])
  669. end
  670. msgRet.randomReward[0] = 0
  671. for _, item in ipairs(rewardConfig.randomdrop) do
  672. if type(item) == "table" then
  673. msgRet.randomReward[0] = msgRet.randomReward[0] + 1
  674. Grid.makeItem(msgRet.randomReward[msgRet.randomReward[0]], item[1], item[2])
  675. end
  676. end
  677. local monsterOutConfig = MonsterOutExcel[grid.monsterOutID]
  678. if not monsterOutConfig then return end
  679. local formation = monsterOutConfig.formation
  680. formation = formation == 0 and 1 or formation
  681. local mationConfig = CombatPosExcel.formation[formation]
  682. local posList = mationConfig.pos
  683. if not posList then return end
  684. msgRet.list[0] = 0
  685. for i, member in ipairs(monsterOutConfig.member) do
  686. local monsterID = member[1]
  687. local monsterConfig = MonsterExcel.monster[monsterID]
  688. if posList[i] then
  689. local defPos = CombatLogic.getPos(CombatDefine.DEFEND_SIDE, posList[i])
  690. local monsterLv = member[2]
  691. local obj = grid.objStatus and grid.objStatus[defPos] or nil
  692. local hpRate = obj and obj.hpRate or 1
  693. local hp = math.ceil(INIT_HP_MAX * hpRate)
  694. local hpMax = INIT_HP_MAX
  695. local others = HeroGrid.createOthers(monsterLv, hp, hpMax, monsterConfig.star)
  696. msgRet.list[0] = msgRet.list[0] + 1
  697. HeroGrid.makeHeroSimpleByMonsterID(msgRet.list[msgRet.list[0]], monsterID, others)
  698. end
  699. end
  700. msgRet.showNext = 0
  701. if human.db.zhandouli >= SHOWQUICKPOWER then
  702. msgRet.showNext = 1
  703. end
  704. msgRet.quick = 0
  705. if human.db.combatQuick[CombatDefine.COMBAT_TYPE24] == 1 then
  706. msgRet.quick = 1
  707. end
  708. Msg.send(msgRet, human.fd)
  709. end
  710. -- Ӣ���б�
  711. function sendHeroStatus(human)
  712. if not human.lostTemple then return end
  713. local msgRet = Msg.gc.GC_LOST_TEMPLE_HERO_STATUS
  714. msgRet.list[0] = 0
  715. msgRet.isEnd = 0
  716. local len = 0
  717. if human.lostTemple.heroStatus then
  718. for k, hpRate in pairs(human.lostTemple.heroStatus) do
  719. local hp = math.ceil(INIT_HP_MAX * hpRate)
  720. local hpMax = INIT_HP_MAX
  721. len = len + 1
  722. local net = msgRet.list[len]
  723. net.hp = hp
  724. net.hpMax = hpMax
  725. net.uuid = k
  726. if len >= 30 then
  727. msgRet.isEnd = 0
  728. msgRet.list[0] = len
  729. Msg.send(msgRet, human.fd)
  730. len = 0
  731. end
  732. end
  733. end
  734. msgRet.isEnd = 1
  735. msgRet.list[0] = len
  736. Msg.send(msgRet, human.fd)
  737. end
  738. -- �����ٻ���̳Ӣ���б�
  739. function sendSummonHeroList(human)
  740. if not human.lostTemple then return end
  741. if not human.lostTemple.summonHero then return end
  742. local msgRet = Msg.gc.GC_LOST_TEMPLE_SUMMON_LIST
  743. msgRet.list[0] = 0
  744. for index = 1, human.lostTemple.summonHero[0] do
  745. msgRet.list[0] = msgRet.list[0] + 1
  746. HeroGrid.makeHeroSimple(msgRet.list[msgRet.list[0]], human.lostTemple.summonHero[index], index)
  747. end
  748. Msg.send(msgRet, human.fd)
  749. end
  750. -- ����buff����
  751. function sendSummonTreeList(human)
  752. if not human.lostTemple then return end
  753. if not human.lostTemple.summonTree then return end
  754. local msgRet = Msg.gc.GC_LOST_TEMPLE_BUFF_LIST
  755. msgRet.list[0] = 0
  756. for k, v in pairs(human.lostTemple.summonTree) do
  757. msgRet.list[0] = msgRet.list[0] + 1
  758. local net = msgRet.list[msgRet.list[0]]
  759. net.attr.key = k
  760. net.attr.value = v
  761. net.name = ""
  762. for i = 1, #LostTempleExcel.Tree do
  763. if LostTempleExcel.Tree[i].icon == k then
  764. net.name = LostTempleExcel.Tree[i].buffname
  765. break
  766. end
  767. end
  768. end
  769. Msg.send(msgRet, human.fd)
  770. end
  771. -- �����������
  772. function sendRandomBox(human)
  773. if not human.lostTemple then return end
  774. local msgRet = Msg.gc.GC_LOGT_TEMPLE_RANDOM_BOX
  775. local len = 0
  776. if human.lostTemple.randomReward then
  777. for k, v in pairs(human.lostTemple.randomReward) do
  778. len = len + 1
  779. Grid.makeItem(msgRet.randomReward[len], k, v)
  780. end
  781. end
  782. msgRet.randomReward[0] = len
  783. Msg.send(msgRet, human.fd)
  784. end
  785. --
  786. function Lost_Handle_Func.nomalMonster(human, op, y, grid, arg, elementConfig)
  787. if op == OP_QUERY then
  788. monsterQuery(human, grid, elementConfig)
  789. end
  790. end
  791. --
  792. function Lost_Handle_Func.eliteMonster(human, op, y, grid, arg, elementConfig)
  793. if op == OP_QUERY then
  794. monsterQuery(human, grid, elementConfig)
  795. end
  796. end
  797. --
  798. function Lost_Handle_Func.eliteBoss(human, op, y, grid, arg, elementConfig)
  799. if op == OP_QUERY then
  800. monsterQuery(human, grid, elementConfig)
  801. end
  802. end
  803. --
  804. function Lost_Handle_Func.summonHero(human, op, y, grid, arg, elementConfig)
  805. -- �ٻ���̳��ѯ
  806. if op == OP_QUERY then
  807. if not grid.summonHero then return end
  808. local msgRet = Msg.gc.GC_LOST_TEMPLE_SUMMON
  809. msgRet.list[0] = 0
  810. for i = 1, #grid.summonHero do
  811. local hero = grid.summonHero[i]
  812. msgRet.list[0] = msgRet.list[0] + 1
  813. local others = HeroGrid.createOthers(hero.lv, INIT_HP_MAX, INIT_HP_MAX, hero.star)
  814. HeroGrid.makeHeroSimpleByID(msgRet.list[msgRet.list[0]], hero.id, i, others)
  815. end
  816. Msg.send(msgRet, human.fd)
  817. return
  818. end
  819. -- ����ٻ�Ӣ��
  820. if op == OP_CONFIRM then
  821. local index = tonumber(arg)
  822. if not grid.summonHero then return end
  823. local hero = grid.summonHero[index]
  824. if not hero then return end
  825. local heroGrid = HeroGrid.createHeroGrid(hero.id, hero.star)
  826. if not heroGrid then return end
  827. heroGrid.isLostTemple = 1
  828. -- ��ʼ������
  829. local attrConfig = HeroDefine.getAttrConfig(hero.id, heroGrid.star)
  830. if not attrConfig then return end
  831. local quality = HeroGrid.getMaxQualityByLv(heroGrid.star, hero.lv)
  832. local maxLv = HeroGrid.getMaxLv(heroGrid.star, quality)
  833. heroGrid.lv = math.min(maxLv, hero.lv or 0)
  834. heroGrid.quality = math.max(heroGrid.quality, quality or 0)
  835. -- ����װ��
  836. -- ���뵽Ӣ�۶���
  837. human.lostTemple.summonHero = human.lostTemple.summonHero or { }
  838. human.lostTemple.summonHero[0] = human.lostTemple.summonHero[0] or 0
  839. human.lostTemple.summonHero[0] = human.lostTemple.summonHero[0] + 1
  840. local addIndex = human.lostTemple.summonHero[0]
  841. human.lostTemple.summonHero[addIndex] = heroGrid
  842. heroGrid.bagIndex = addIndex
  843. -- ��������
  844. LostTempleCombatLogic.getHeroAttrs(human, addIndex)
  845. -- ֪ͨ�ͻ���
  846. sendSummonHeroList(human)
  847. return true
  848. end
  849. end
  850. -- �ǻ���
  851. function Lost_Handle_Func.summonTree(human, op, y, grid, arg, elementConfig)
  852. -- �ٻ���̳��ѯ
  853. if op == OP_QUERY then
  854. if not grid.summonTree then return end
  855. local msgRet = Msg.gc.GC_LOST_TEMPLE_BUFF
  856. msgRet.list[0] = 0
  857. for i = 1, #grid.summonTree do
  858. local hero = grid.summonTree[i]
  859. msgRet.list[0] = msgRet.list[0] + 1
  860. local config = LostTempleExcel.Tree[grid.summonTree[i]]
  861. local net = msgRet.list[msgRet.list[0]]
  862. net.id = i
  863. net.icon = config.icon
  864. net.name = config.buffname
  865. net.attr[0] = #config.Buffid
  866. for i = 1, #config.Buffid do
  867. net.attr[i].key = config.Buffid[i][1]
  868. net.attr[i].value = config.Buffid[i][2]
  869. end
  870. end
  871. Msg.send(msgRet, human.fd)
  872. return
  873. end
  874. -- ����ٻ�Ӣ��
  875. if op == OP_CONFIRM then
  876. local index = tonumber(arg)
  877. if not grid.summonTree then return end
  878. local buffID = grid.summonTree[index]
  879. if not buffID then return end
  880. local config = LostTempleExcel.Tree[buffID]
  881. if not config then return end
  882. human.lostTemple.summonTree = human.lostTemple.summonTree or { }
  883. for i = 1, #config.Buffid do
  884. local key = config.Buffid[i][1]
  885. local value = config.Buffid[i][2]
  886. human.lostTemple.summonTree[key] = human.lostTemple.summonTree[key] or 0
  887. human.lostTemple.summonTree[key] = human.lostTemple.summonTree[key] + value
  888. end
  889. sendSummonTreeList(human)
  890. return true
  891. end
  892. end
  893. -- ����ʹ
  894. function Lost_Handle_Func.treatRevive(human, op, y, grid, arg, elementConfig)
  895. if op == OP_QUERY then
  896. return
  897. end
  898. -- ��������
  899. if op == OP_CONFIRM then
  900. local opType = tonumber(arg)
  901. local heroStatus = human.lostTemple.heroStatus
  902. if not heroStatus then return true end
  903. -- ����
  904. if opType == 1 then
  905. local len = 0
  906. local cnt = 0
  907. local revice = {}
  908. local hpList = {}
  909. for k, hpRate in pairs(heroStatus) do
  910. if hpRate <= 0.0 then
  911. len = len + 1
  912. revice[len]=k
  913. else
  914. if hpRate < 1.0 then
  915. cnt = cnt + 1
  916. hpList[cnt] = k
  917. end
  918. end
  919. end
  920. if #revice > 0 then
  921. local random = math.random(1, #revice)
  922. heroStatus[revice[random]] = nil
  923. elseif #hpList > 0 then
  924. local random = math.random(1, #hpList)
  925. heroStatus[hpList[random]] = nil
  926. end
  927. end
  928. -- ����
  929. if opType == 2 then
  930. for k, hpRate in pairs(heroStatus) do
  931. if heroStatus[k] > 0.0 then
  932. heroStatus[k] = hpRate + 0.5
  933. if heroStatus[k] >= 1.0 then
  934. heroStatus[k] = nil
  935. end
  936. end
  937. end
  938. end
  939. sendHeroStatus(human)
  940. return true
  941. end
  942. end
  943. -- ����̵�
  944. function Lost_Handle_Func.summonShop(human, op, y, grid, arg, elementConfig)
  945. if op == OP_QUERY then
  946. if not grid.summonShop then return end
  947. local msgRet = Msg.gc.GC_LOST_TEMPLE_SHOP
  948. msgRet.list[0] = 0
  949. for i = 1, #grid.summonShop do
  950. msgRet.list[0] = msgRet.list[0] + 1
  951. local config = LostTempleExcel.LostShop[grid.summonShop[i]]
  952. local net = msgRet.list[msgRet.list[0]]
  953. Grid.makeItem(net.item, config.itemid, config.itemnum)
  954. Grid.makeItem(net.needItem, config.spenditem, config.spendnum)
  955. net.discount = config.discount
  956. net.id = i
  957. end
  958. Msg.send(msgRet, human.fd)
  959. return
  960. end
  961. -- ������
  962. if op == OP_CONFIRM then
  963. local index = tonumber(arg)
  964. if not grid.summonShop then return end
  965. local shopID = grid.summonShop[index]
  966. if not shopID then return end
  967. local config = LostTempleExcel.LostShop[shopID]
  968. if not config then return end
  969. if not BagLogic.checkItemCnt(human, config.spenditem, config.spendnum) then
  970. return
  971. end
  972. BagLogic.delItem(human, config.spenditem, config.spendnum, "lostTemple")
  973. BagLogic.addItem(human, config.itemid, config.itemnum, "lostTemple")
  974. return true
  975. end
  976. end
  977. -- ����
  978. function Lost_Handle_Func.summonBox(human, op, y, grid, arg, elementConfig)
  979. if op == OP_QUERY then
  980. sendRandomBox(human)
  981. return
  982. end
  983. --
  984. if op == OP_CONFIRM then
  985. if human.lostTemple.randomReward then
  986. local item = { }
  987. local len = 0
  988. for k, v in pairs(human.lostTemple.randomReward) do
  989. len = len + 1
  990. item[len] = { k, v }
  991. end
  992. BagLogic.addItemList(human, item, "lostTemple")
  993. human.lostTemple.randomReward = nil
  994. end
  995. -- �ж���û����һ��
  996. local nextLayer = human.lostTemple.layer + 1
  997. local LostTempleConfig = LostTempleExcel[nextLayer]
  998. if LostTempleConfig then
  999. -- ��ɴ�����
  1000. putSet(human, y, elementConfig.cmd)
  1001. end
  1002. dbSave(human)
  1003. update(human)
  1004. end
  1005. end
  1006. -- ������
  1007. function Lost_Handle_Func.conveyDoor(human, op, y, grid, arg, elementConfig)
  1008. if op == OP_QUERY then
  1009. return
  1010. end
  1011. -- ������һ��
  1012. if op == OP_CONFIRM then
  1013. nextDB(human)
  1014. dbSave(human)
  1015. update(human)
  1016. end
  1017. end
  1018. function lostTempleRevice(human)
  1019. if not human.lostTemple then return end
  1020. human.lostTemple.heroStatus = nil
  1021. sendHeroStatus(human)
  1022. end