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