lostTempleLogic.lua 35 KB

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