lostTempleLogic.lua 34 KB

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