lostTempleLogic.lua 35 KB

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