lostTempleLogic.lua 35 KB

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