lostTempleLogic.lua 35 KB

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