lostTempleLogic.lua 36 KB

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