lostTempleLogic.lua 36 KB

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