lostTempleLogic.lua 35 KB

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