lostTempleLogic.lua 35 KB

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