lostTempleLogic.lua 35 KB

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