| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436 |
- --[[
- 失落神庙
- ]]
- local Msg = require("core.Msg")
- local LuaMongo = _G.lua_mongo
- local DB = require("common.DB")
- local LostTempleExcel = require("excel.lostTemple")
- local ElementExcel = require("excel.lostTemple").Element
- local CombatPosLogic = require("combat.CombatPosLogic")
- local CombatDefine = require("combat.CombatDefine")
- local MonsterOutExcel = require("excel.monster").monsterOut
- local HeroLogic = require("hero.HeroLogic")
- local MonsterExcel = require("excel.monster")
- local CombatLogic = require("combat.CombatLogic")
- local Grid = require("bag.Grid")
- local HeroGrid = require("hero.HeroGrid")
- local CombatPosExcel = require("excel.combatPos")
- local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
- local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
- local Util = require("common.Util")
- local LostTempleCombatLogic = require("lostTemple.lostTempleCombatLogic")
- local HeroDefine = require("hero.HeroDefine")
- local BagLogic = require("bag.BagLogic")
- local Broadcast = require("broadcast.Broadcast")
- local Lang = require("common.Lang")
- local CommonDB = require("common.CommonDB")
- local TriggerDefine = require("trigger.TriggerDefine")
- local TriggerLogic = require("trigger.TriggerLogic")
- local HeroGrowUp = require("absAct.HeroGrowUp")
- local YunYingLogic = require("yunying.YunYingLogic")
- local Timer = require("core.Timer")
- local Lost_Handle_Func = { }
- QUEUE_LEN = 3 -- 每次推送的横向队列数
- START_X = 1 -- 起始横向位置
- START_LAYER = 1 -- 起始层数
- OP_QUERY = 0
- OP_CONFIRM = 1
- INIT_HP_MAX = 100
- DAY_7s = 604800
- DAY_2s = 172800
- DAY_1s = 86400
- --跳过战斗需要的战力
- local SHOWQUICKPOWER = 0 --2000000
- local function resetDB(human)
- local query = { _id = human.db._id }
- LuaMongo.remove(DB.db_lost_temple, query)
- end
- function initAfterHot()
- end
- function getLeftTime()
- local openDay = CommonDB.getServerOpenDay()
- if not openDay then
- return 0
- end
- local curTime = os.time()
- local tNowDate = os.date("*t", curTime)
- tNowDate.hour = 0
- tNowDate.min = 0
- tNowDate.sec = 0
- -- if openDay % 2 == 1 then
- -- tNowDate.day = tNowDate.day + 2
- -- else
- -- tNowDate.day = tNowDate.day + 1
- -- end
- tNowDate.day = tNowDate.day + 1
- local nEndTime = os.time(tNowDate)
- return nEndTime - curTime
- end
- --
- local function isOpen(human)
- --[[
- local openDay = CommonDB.getServerOpenDay()
- if not openDay then
- return
- end
-
- if openDay < 7 then
- return
- end
-
- ---- 已经开启
- if (openDay - 7 + 1) % 2 ~= 1 then
- return
- end
- ]]
- if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1208) then
- return
- end
- return true
- end
- function onZero()
- local openDay = CommonDB.getServerOpenDay()
- if not openDay then
- return
- end
- -- print("[lostTempleLogic - onZero] 失落神庙零点刷新开始 openDay = "..openDay)
- -- -- 奇数天刷新
- -- if openDay % 2 == 1 then
- -- print("[lostTempleLogic - onZero] 失落神庙零点, 当前为奇数天移除DB数据\n")
- -- LuaMongo.remove(DB.db_lost_temple)
- -- end
- -- 修改: 每日刷新
- -- LuaMongo.remove(DB.db_lost_temple)
- -- 修改: 延迟60s再清除数据
- -- Timer.addLater(60, LuaMongo.remove, DB.db_lost_temple)
- -- 已经关闭
- -- if (openDay - 7 + 1) % 2 ~= 0 then
- -- return
- -- end
- end
- function updateDaily(human)
- if not isOpen(human) then
- return
- end
- resetDB(human)
- print("[lostTempleLogic - updateDaily] 天数刷新 玩家移除lostTemple数据 name = "..human.db.name)
- human.lostTemple = nil
-
- local msgRet = Msg.gc.GC_LOST_TEMPLE_CLOSE
- Msg.send(msgRet, human.fd)
- end
- -- db
- local QueryByUuid = { _id = nil }
- -- 插入新的数据
- function dbRead(human)
- if not isOpen(human) then return end
- human.lostTemple = { }
- QueryByUuid._id = human.db._id
- LuaMongo.find(DB.db_lost_temple, QueryByUuid)
- if not LuaMongo.next(human.lostTemple) then
- human.lostTemple = nil
- end
- end
- --
- local DB_DATA = { }
- function dbSave(human)
- if not human.lostTemple then return end
- if not human.db then return end
- DB_DATA = { }
- LuaMongo.find(DB.db_lost_temple, QueryByUuid)
- -- if not LuaMongo.next(DB_DATA) then
- -- human.lostTemple._id = human.db._id
- -- LuaMongo.insert(DB.db_lost_temple, human.lostTemple)
- -- return
- -- end
- if not LuaMongo.next(DB_DATA) then
- -- 检查 human.db._id 是否已经存在
- local exists = false
- local tempQuery = { _id = human.db._id }
- LuaMongo.find(DB.db_lost_temple, tempQuery)
- if LuaMongo.next(DB_DATA) then
- exists = true
- end
- if exists then
- -- 如果存在,更新文档
- LuaMongo.update(DB.db_lost_temple, tempQuery, human.lostTemple)
- else
- -- 如果不存在,插入新文档
- human.lostTemple._id = human.db._id
- LuaMongo.insert(DB.db_lost_temple, human.lostTemple)
- end
- return
- end
- QueryByUuid._id = human.db._id
- LuaMongo.update(DB.db_lost_temple, QueryByUuid, human.lostTemple)
- end
- -- db
- function onLogin(human)
- if not isOpen(human) then return end
- dbRead(human)
- end
- -- 初始化玩家当前格子
- local function printGrid(human)
- if not human.lostTemple then return end
- local startX = human.lostTemple.x + 1
- local endX = human.lostTemple.x + QUEUE_LEN
- local layer = human.lostTemple.layer
- local random = human.lostTemple.random
- local LostTempleConfig = LostTempleExcel[layer]
- if not LostTempleConfig then return end
- local LostTemple = LostTempleConfig[random]
- if not LostTemple then return end
- print("layler=", human.lostTemple.layer, "random=", human.lostTemple.random, "playerX=", human.lostTemple.x, "playerY=", human.lostTemple.y)
- for x = startX, endX do
- human.lostTemple.grid[x] = human.lostTemple.grid[x] or { }
- local LostTempleX = LostTemple[x]
- if LostTempleX then
- for y = 1, LostTemple.vertical do
- if LostTempleX[y] then
- print("x=", x, "y=", y, "id=", human.lostTemple.grid[x][y].id)
- end
- end
- end
- end
- return true
- end
- --
- local function makeMonsterGrid(human, cmd)
- if not human.lostTemple then return end
- local x = human.lostTemple.x
- local layer = human.lostTemple.layer
- local LostTempleMonster = LostTempleExcel.Lost[x]
- if not LostTempleMonster then return end
- -- 取共鸣英雄的等级
- local totalLv = 0
- local equally = 0
- local equallyLv = 0
- local db = human.db.xingYaoGongMing
- if db and db.defList then
- for heroIndex in pairs(db.defList) do
- local heroGrid = human.db.heroBag[heroIndex]
- if heroGrid then
- totalLv = totalLv + heroGrid.lv
- equally = equally + 1
- end
- end
- end
- local randomId = 0
- if cmd == "nomalMonster" then
- randomId = math.random(LostTempleMonster.nomal[layer][1], LostTempleMonster.nomal[layer][2])
- elseif cmd == "eliteMonster" then
- randomId = math.random(LostTempleMonster.elite[layer][1], LostTempleMonster.elite[layer][2])
- elseif cmd == "eliteBoss" then
- randomId = math.random(LostTempleMonster.elite[layer][1], LostTempleMonster.elite[layer][2])
- end
- equallyLv = math.ceil(totalLv / equally * randomId / 10000)
- local monsterOutID = 0
- for i = 1, #LostTempleExcel.Monster do
- if equallyLv >= LostTempleExcel.Monster[i].lvminmax[1] and equallyLv <= LostTempleExcel.Monster[i].lvminmax[2] then
- local randomIndex = math.random(1, #LostTempleExcel.Monster[i].monsteroutid)
- monsterOutID = LostTempleExcel.Monster[i].monsteroutid[randomIndex]
- break
- end
- end
- if monsterOutID == 0 then
- assert(nil, "monsterOutID is error equallyLv=" .. equallyLv .. "-randomId=" .. randomId)
- end
- return monsterOutID
- end
- -- 制造一个召唤祭坛
- local function makeSummonHeroGrid(human)
- -- 取共鸣英雄的等级
- local totalLv = 0
- local equally = 0
- local equallyLv = 0
- local db = human.db.xingYaoGongMing
- if db and db.defList then
- for heroIndex in pairs(db.defList) do
- local heroGrid = human.db.heroBag[heroIndex]
- if heroGrid then
- totalLv = totalLv + heroGrid.lv
- equally = equally + 1
- end
- end
- end
- equallyLv = math.ceil(totalLv / equally)
- local heroIndex = nil
- for i = 1, #LostTempleExcel.Hero do
- if equallyLv >= LostTempleExcel.Hero[i].lvminmax[1] and equallyLv <= LostTempleExcel.Hero[i].lvminmax[2] then
- heroIndex = i
- break
- end
- end
- if heroIndex == nil then
- assert(nil, "heroid is error equallyLv=" .. equallyLv)
- end
- --
- local summonHero = { }
- local weightHeroTb = Util.copyTable(LostTempleExcel.Hero[heroIndex].heroid)
- -- 根据权重取出4英雄
- local totalWeight = 0
- for i = 1, #weightHeroTb do
- totalWeight = totalWeight + weightHeroTb[i][4]
- end
- -- 取4次
- local len = 0
- for k = 1, 4 do
- local random = math.random(1, totalWeight)
- for i = 1, #weightHeroTb do
- if random <= weightHeroTb[i][4] then
- len = len + 1
- summonHero[len] = { }
- summonHero[len].id = weightHeroTb[i][1]
- summonHero[len].lv = weightHeroTb[i][2]
- local maxStar = HeroDefine.getMaxHeroStar(weightHeroTb[i][1])
- summonHero[len].star = maxStar > weightHeroTb[i][3] and weightHeroTb[i][3] or maxStar
- -- 最后一个放入到 这一个里面 删掉最后一个
- totalWeight = totalWeight - weightHeroTb[i][4]
- weightHeroTb[i] = weightHeroTb[#weightHeroTb]
- weightHeroTb[#weightHeroTb] = nil
- break
- end
- random = random - weightHeroTb[i][4]
- end
- end
- if #summonHero == 0 then
- assert(nil, "summonHero is error equallyLv=" .. equallyLv)
- end
- return summonHero
- end
- -- 制造一个智慧树
- local function makeSummonTreeGrid(human)
- --
- local summonTree = { }
- local weightTreeTb = Util.copyTable(LostTempleExcel.Tree)
- -- 根据权重取出4英雄
- local totalWeight = 0
- for i = 1, #weightTreeTb do
- totalWeight = totalWeight + weightTreeTb[i].weight
- end
- -- 取3次
- local len = 0
- for k = 1, 3 do
- local random = math.random(1, totalWeight)
- for i = 1, #weightTreeTb do
- if random <= weightTreeTb[i].weight then
- len = len + 1
- summonTree[len] = i
- -- 最后一个放入到 这一个里面 删掉最后一个
- totalWeight = totalWeight - weightTreeTb[i].weight
- weightTreeTb[i] = weightTreeTb[#weightTreeTb]
- weightTreeTb[#weightTreeTb] = nil
- break
- end
- random = random - weightTreeTb[i].weight
- end
- end
- if #summonTree == 0 then
- assert(nil, "summonTree is error")
- end
- return summonTree
- end
- -- 神界商店
- local function makeSummonShopGrid(human)
- --
- local summonShop = { }
- local weightShopTb = Util.copyTable(LostTempleExcel.LostShop)
- -- 根据权重取出4英雄
- local totalWeight = 0
- for i = 1, #weightShopTb do
- totalWeight = totalWeight + weightShopTb[i].weight
- end
- -- 取3次
- local len = 0
- for k = 1, 4 do
- local random = math.random(1, totalWeight)
- for i = 1, #weightShopTb do
- if random <= weightShopTb[i].weight then
- len = len + 1
- summonShop[len] = i
- -- 最后一个放入到 这一个里面 删掉最后一个
- totalWeight = totalWeight - weightShopTb[i].weight
- weightShopTb[i] = weightShopTb[#weightShopTb]
- weightShopTb[#weightShopTb] = nil
- break
- end
- random = random - weightShopTb[i].weight
- end
- end
- if #summonShop == 0 then
- assert(nil, "summonShop is error")
- end
- return summonShop
- end
- -- 制造一个宝箱
- local function makeBoxGrid(human)
- for i = 1, #ElementExcel do
- local element = ElementExcel[i]
- if element.cmd == "summonBox" then
- return i
- end
- end
- end
- -- 制造一个传送门
- local function makeConverDoorGrid(human)
- for i = 1, #ElementExcel do
- local element = ElementExcel[i]
- if element.cmd == "conveyDoor" then
- return i
- end
- end
- end
- -- 初始化玩家当前格子
- local function makeGrid(human)
- if not human.lostTemple then return end
- local layer = human.lostTemple.layer
- local random = human.lostTemple.random
- local LostTempleConfig = LostTempleExcel[layer]
- if not LostTempleConfig then return end
- local LostTemple = LostTempleConfig[random]
- if not LostTemple then return end
- -- 清除玩家当前位置的数据
- human.lostTemple.grid = human.lostTemple.grid or { }
- human.lostTemple.grid[human.lostTemple.x] = nil
- local startX = human.lostTemple.x + 1
- local endX = human.lostTemple.x + QUEUE_LEN
- for x = startX, endX do
- local LostTempleX = LostTemple[x]
- if LostTempleX then
- human.lostTemple.grid[x] = human.lostTemple.grid[x] or { }
- for y = 1, LostTemple.vertical do
- if LostTempleX[y] then
- if not human.lostTemple.grid[x][y] then
- human.lostTemple.grid[x][y] = { id = LostTempleX[y][1] }
- end
- local element = ElementExcel[LostTempleX[y][1]]
- -- 召唤神坛
- if element.cmd == "summonHero" then
- human.lostTemple.grid[x][y].summonHero = makeSummonHeroGrid(human)
- end
- -- 智慧树
- if element.cmd == "summonTree" then
- human.lostTemple.grid[x][y].summonTree = makeSummonTreeGrid(human)
- end
- -- 神界商店
- if element.cmd == "summonShop" then
- human.lostTemple.grid[x][y].summonShop = makeSummonShopGrid(human)
- end
- --只生成 第一层的怪物
- if x == startX then
- if element.cmd == "nomalMonster" or element.cmd == "eliteMonster" or element.cmd == "eliteBoss" then
- human.lostTemple.grid[x][y].monsterOutID = makeMonsterGrid(human, element.cmd)
- end
- end
- end
- end
- end
- end
- return true
- end
- -- 制造一个默认的位置数据
- local function makeLostTempLe(layer)
- -- 第一层
- local LostTempleConfig = LostTempleExcel[layer]
- if not LostTempleConfig then
- assert(nil, "lostTemple startLayer error = " .. layer)
- end
- -- 随机一张地图
- local startRandom = math.random(1, #LostTempleConfig)
- local LostTemple = LostTempleConfig[startRandom]
- if not LostTemple then return end
- -- 起始位置
- local LostTempleX = LostTemple[START_X]
- if not LostTempleX then
- assert(nil, "lostTemple startX error = " .. START_LAYER)
- end
- -- 找到纵向可以站立的位置
- local startY = 1
- for y = 1, LostTemple.vertical do
- if LostTempleX[y] and LostTempleX[y][1] == 0 then
- startY = y
- break
- end
- end
- return layer, START_X, startY, startRandom
- end
- -- 初始化
- local function initDB(human)
- if human.lostTemple then return end
- local lostLayer, lostX, lostY, lostRandom = makeLostTempLe(START_LAYER)
- if not lostLayer then return end
- human.lostTemple = { layer = lostLayer, x = lostX, y = lostY, random = lostRandom, box = nil, grid = nil }
- makeGrid(human)
- dbSave(human)
- end
- -- 重置之后的Y值
- local function getStartYVal(mapIdx)
- local LostTempleConfig = LostTempleExcel[START_LAYER]
- if not LostTempleConfig then
- return -1
- end
- local LostTemple = LostTempleConfig[mapIdx]
- if not LostTemple then
- return -1
- end
- local LostTempleX = LostTemple[START_X]
- if not LostTempleX then
- return -1
- end
- local startY = -1
- for y = 1, LostTemple.vertical do
- if LostTempleX[y] and LostTempleX[y][1] == 0 then
- startY = y
- break
- end
- end
- return startY
- end
- -- 是否已经挑战过
- local function isChallenge(human)
- if not human.lostTemple then
- return false
- end
- -- 层数判断
- local layer = human.lostTemple.layer or 0
- if layer > 1 then
- return true
- end
- -- X 值判断
- local start_X_Val = human.lostTemple.x or 0
- if start_X_Val ~= START_X then
- return true
- end
- local y_Val = human.lostTemple.y or 0
- local mapIdx = human.lostTemple.random or 0
- local start_Y_Val = getStartYVal(mapIdx)
- if start_Y_Val == -1 then
- assert(false, "失落神庙数据异常")
- end
- -- Y 值判断
- if y_Val ~= start_Y_Val then
- return true
- end
- return false
- end
- -- human = { }
- -- initDB(human)
- -- printGrid(human)
- -- print("-----------------------------")
- -- 下一格
- function nextGrid(human, y)
- if not human.lostTemple then return end
- local layer = human.lostTemple.layer
- local LostTempleConfig = LostTempleExcel[layer]
- if not LostTempleConfig then
- assert(nil, "lostTemple startLayer error = " .. layer)
- end
- local random = human.lostTemple.random
- local LostTemple = LostTempleConfig[random]
- if not LostTemple then return end
- local x = human.lostTemple.x + 1
- local LostTempleX = LostTemple[x]
- if not LostTempleX then return end
- local LostTempleY = LostTempleX[y]
- if not LostTempleY then return end
- human.lostTemple.x = x
- human.lostTemple.y = y
- makeGrid(human)
- end
- -- 下一层
- local function nextDB(human)
- if not human.lostTemple then return end
- local nextLayer = human.lostTemple.layer + 1
- local LostTempleConfig = LostTempleExcel[nextLayer]
- if not LostTempleConfig then return end
- local lostLayer, lostX, lostY, lostRandom = makeLostTempLe(nextLayer)
- if not lostLayer then return end
- -- TriggerLogic.PublishEvent(TriggerDefine.LOSTTEMPLE_PASS_LAYER, human.db._id, 1)
- human.lostTemple.layer = lostLayer
- human.lostTemple.x = lostX
- human.lostTemple.y = lostY
- human.lostTemple.random = lostRandom
- human.lostTemple.grid = nil
- makeGrid(human)
- end
- --
- local function makeGridNet(human, net)
- if not human.lostTemple then return end
- local startX = human.lostTemple.x + 1
- local endX = human.lostTemple.x + QUEUE_LEN
- local layer = human.lostTemple.layer
- local random = human.lostTemple.random
- local LostTempleConfig = LostTempleExcel[layer]
- if not LostTempleConfig then return end
- local LostTemple = LostTempleConfig[random]
- if not LostTemple then return end
- net[0] = 0
- local len = 0
- for x = startX, endX do
- if human.lostTemple.grid[x] then
- for y = 1, LostTemple.vertical do
- if human.lostTemple.grid[x][y] then
- len = len + 1
- local grid = human.lostTemple.grid[x][y]
- local element = ElementExcel[grid.id]
- if not element then
- assert(nil, "lostTemple element error = " .. grid.id)
- end
- net[len].id = grid.id
- net[len].name = element.name
- net[len].type = element.type
- net[len].desc = element.desc
- net[len].x = x
- net[len].y = y
- net[len].body = 0
- if grid.monsterOutID then
- if not MonsterOutExcel[grid.monsterOutID] then
- assert(nil, "lostTemple monsterOutID error = " .. grid.monsterOutID)
- end
- local monsterConfig = MonsterExcel.monster[MonsterOutExcel[grid.monsterOutID].member[1][1]]
- if not monsterConfig then
- assert(nil, "lostTemple monsterOutID error = " .. MonsterOutExcel[grid.monsterOutID].member[1][1])
- end
- net[len].body = monsterConfig.body
- end
- end
- end
- end
- end
- net[0] = len
- return true
- end
- --通关
- function IsPass(human)
- -- initDB(human)
- if not human.lostTemple then return false end
- if human.lostTemple.oneClickSweep then
- return true
- end
- local startX = human.lostTemple.x + 1
- local endX = human.lostTemple.x + QUEUE_LEN
- local layer = human.lostTemple.layer
- local random = human.lostTemple.random
- local LostTempleConfig = LostTempleExcel[layer]
- if not LostTempleConfig then return end
- local LostTemple = LostTempleConfig[random]
- if not LostTemple then return end
- local type = 0
- local len = 0
- for x = startX, endX do
- if human.lostTemple.grid[x] then
- for y = 1, LostTemple.vertical do
- if human.lostTemple.grid[x][y] then
- len = len + 1
- local grid = human.lostTemple.grid[x][y]
- local element = ElementExcel[grid.id]
- if not element then
- return false
- end
- type = element.type
- end
- end
- end
- end
- if len == 1 and type == 6 and layer >= 3 then
- return true
- end
- return false
- end
- -- 查询
- function query(human)
- if not isOpen(human) then
- return
- end
- -- 没有共鸣
- local db = human.db.xingYaoGongMing
- if not db or not db.defList then
- return
- end
- initDB(human)
- local leftTime = getLeftTime()
- local msgRet = Msg.gc.GC_LOST_TEMPLE_QUERY
- msgRet.leftTime = leftTime
-
- if not makeGridNet(human, msgRet.list) then return end
- msgRet.playerX = human.lostTemple.x
- msgRet.playerY = human.lostTemple.y
- msgRet.layer = human.lostTemple.layer
- msgRet.leftTime = leftTime
- Msg.send(msgRet, human.fd)
- sendHeroStatus(human)
- end
- -- 更新
- function update(human)
- if not human.lostTemple then
- return
- end
-
- local msgRet = Msg.gc.GC_LOST_TEMPLE_UPDATE
- if not makeGridNet(human, msgRet.list) then
- return
- end
- local leftTime = getLeftTime()
- msgRet.leftTime = leftTime
- msgRet.playerX = human.lostTemple.x
- msgRet.playerY = human.lostTemple.y
- msgRet.layer = human.lostTemple.layer
- Msg.send(msgRet, human.fd)
- end
- -- 检测点击格子是否合法
- function checkPutByY(human, y)
- local startX = human.lostTemple.x + 1
- if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
- local grid = human.lostTemple.grid[startX][y]
- -- 检测点击位置是否合法
- return grid
- end
- -- 检测点击格子是否合法
- function checkPut(human, x, y)
- local startX = x
- if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
- local grid = human.lostTemple.grid[startX][y]
- local nNowX = human.lostTemple.x
- local nNowY = human.lostTemple.y
- if nNowX + 1 ~= x then
- print("[checkPut] x ="..x.." nNowX="..nNowX.." y="..y.." nNowY="..nNowY)
- return
- end
- -- 检测点击位置是否合法
- return grid
- end
- -- 设置格子
- function putSet(human, y, cmd)
- local startX = human.lostTemple.x + 1
- if not human.lostTemple.grid or not human.lostTemple.grid[startX] or not human.lostTemple.grid[startX][y] then return end
- if cmd == "eliteBoss" then
- human.lostTemple.grid[startX][y] = { id = makeBoxGrid(human) }
- return true
- end
- if cmd == "summonBox" then
- human.lostTemple.grid[startX][y] = { id = makeConverDoorGrid(human) }
- return true
- end
- end
- -- 走到下一步
- function put(human, op, x, y, arg)
- if not isOpen(human) then return end
- if not human.lostTemple then return end
- if op ~= OP_QUERY and op ~= OP_CONFIRM then return end
- local grid = checkPut(human, x, y)
- if not grid then return end
- local elementConfig = ElementExcel[grid.id]
- if not elementConfig then return end
- local ret = nil
- if Lost_Handle_Func[elementConfig.cmd] then
- ret = Lost_Handle_Func[elementConfig.cmd](human, op, y, grid, arg, elementConfig)
- end
- if ret then
- nextGrid(human, y)
- dbSave(human)
- update(human)
- end
- end
- -- 怪物面板
- local function monsterQuery(human, grid, elementConfig)
- if not human.lostTemple then return end
- if not grid.monsterOutID then return end
- local rewardConfig = LostTempleExcel.Drop[elementConfig.arg[1]]
- if not rewardConfig then return end
- local msgRet = Msg.gc.GC_LOST_TEMPLE_MONSTER
- msgRet.gdReward[0] = 0
- for _, item in ipairs(rewardConfig.drop) do
- msgRet.gdReward[0] = msgRet.gdReward[0] + 1
- Grid.makeItem(msgRet.gdReward[msgRet.gdReward[0]], item[1], item[2])
- end
- msgRet.randomReward[0] = 0
- for _, item in ipairs(rewardConfig.randomdrop) do
- if type(item) == "table" then
- msgRet.randomReward[0] = msgRet.randomReward[0] + 1
- Grid.makeItem(msgRet.randomReward[msgRet.randomReward[0]], item[1], item[2])
- end
- end
- local monsterOutConfig = MonsterOutExcel[grid.monsterOutID]
- if not monsterOutConfig then return end
- local formation = monsterOutConfig.formation
- formation = formation == 0 and 1 or formation
- local mationConfig = CombatPosExcel.formation[formation]
- local posList = mationConfig.pos
- if not posList then return end
- msgRet.list[0] = 0
- for i, member in ipairs(monsterOutConfig.member) do
- local monsterID = member[1]
- local monsterConfig = MonsterExcel.monster[monsterID]
- if posList[i] then
- local defPos = CombatLogic.getPos(CombatDefine.DEFEND_SIDE, posList[i])
- local monsterLv = member[2]
- local obj = grid.objStatus and grid.objStatus[defPos] or nil
- local hpRate = obj and obj.hpRate or 1
- local hp = math.ceil(INIT_HP_MAX * hpRate)
- local hpMax = INIT_HP_MAX
- local others = HeroGrid.createOthers(monsterLv, hp, hpMax, monsterConfig.star)
- msgRet.list[0] = msgRet.list[0] + 1
- HeroGrid.makeHeroSimpleByMonsterID(msgRet.list[msgRet.list[0]], monsterID, others)
- end
- end
- msgRet.showNext = 0
- if human.db.zhandouli >= SHOWQUICKPOWER then
- msgRet.showNext = 1
- end
- msgRet.quick = 0
- if human.db.combatQuick[CombatDefine.COMBAT_TYPE24] == 1 then
- msgRet.quick = 1
- end
- Msg.send(msgRet, human.fd)
- end
- -- 英雄列表
- function sendHeroStatus(human)
- if not human.lostTemple then return end
- local msgRet = Msg.gc.GC_LOST_TEMPLE_HERO_STATUS
- msgRet.list[0] = 0
- msgRet.isEnd = 0
- local len = 0
- if human.lostTemple.heroStatus then
- for k, hpRate in pairs(human.lostTemple.heroStatus) do
- local hp = math.ceil(INIT_HP_MAX * hpRate)
- local hpMax = INIT_HP_MAX
-
- len = len + 1
- local net = msgRet.list[len]
- net.hp = hp
- net.hpMax = hpMax
- net.uuid = k
-
- if len >= 30 then
- msgRet.isEnd = 0
- msgRet.list[0] = len
- Msg.send(msgRet, human.fd)
- len = 0
- end
- end
- end
- msgRet.isEnd = 1
- msgRet.list[0] = len
- Msg.send(msgRet, human.fd)
- end
- -- 推送召唤祭坛英雄列表
- function sendSummonHeroList(human)
- if not human.lostTemple then return end
- if not human.lostTemple.summonHero then return end
- local msgRet = Msg.gc.GC_LOST_TEMPLE_SUMMON_LIST
- msgRet.list[0] = 0
- for index = 1, human.lostTemple.summonHero[0] do
- msgRet.list[0] = msgRet.list[0] + 1
- HeroGrid.makeHeroSimple(msgRet.list[msgRet.list[0]], human.lostTemple.summonHero[index], index)
- end
- Msg.send(msgRet, human.fd)
- end
- -- 推送buff属性
- function sendSummonTreeList(human)
- if not human.lostTemple then return end
- if not human.lostTemple.summonTree then return end
- local msgRet = Msg.gc.GC_LOST_TEMPLE_BUFF_LIST
- msgRet.list[0] = 0
- for k, v in pairs(human.lostTemple.summonTree) do
- msgRet.list[0] = msgRet.list[0] + 1
- local net = msgRet.list[msgRet.list[0]]
- net.attr.key = k
- net.attr.value = v
- net.name = ""
- for i = 1, #LostTempleExcel.Tree do
- if LostTempleExcel.Tree[i].icon == k then
- net.name = LostTempleExcel.Tree[i].buffname
- break
- end
- end
- end
- Msg.send(msgRet, human.fd)
- end
- -- 随机奖励宝箱
- function sendRandomBox(human)
- if not human.lostTemple then return end
- local msgRet = Msg.gc.GC_LOGT_TEMPLE_RANDOM_BOX
- local len = 0
- if human.lostTemple.randomReward then
- for k, v in pairs(human.lostTemple.randomReward) do
- len = len + 1
- Grid.makeItem(msgRet.randomReward[len], k, v)
- end
- end
- msgRet.randomReward[0] = len
- Msg.send(msgRet, human.fd)
- end
- --
- function Lost_Handle_Func.nomalMonster(human, op, y, grid, arg, elementConfig)
- if op == OP_QUERY then
- monsterQuery(human, grid, elementConfig)
- end
- end
- --
- function Lost_Handle_Func.eliteMonster(human, op, y, grid, arg, elementConfig)
- if op == OP_QUERY then
- monsterQuery(human, grid, elementConfig)
- end
- end
- --
- function Lost_Handle_Func.eliteBoss(human, op, y, grid, arg, elementConfig)
- if op == OP_QUERY then
- monsterQuery(human, grid, elementConfig)
- end
- end
- --
- function Lost_Handle_Func.summonHero(human, op, y, grid, arg, elementConfig)
- -- 召唤神坛查询
- if op == OP_QUERY then
- if not grid.summonHero then return end
- local msgRet = Msg.gc.GC_LOST_TEMPLE_SUMMON
- msgRet.list[0] = 0
- for i = 1, #grid.summonHero do
- local hero = grid.summonHero[i]
- msgRet.list[0] = msgRet.list[0] + 1
- local others = HeroGrid.createOthers(hero.lv, INIT_HP_MAX, INIT_HP_MAX, hero.star)
- HeroGrid.makeHeroSimpleByID(msgRet.list[msgRet.list[0]], hero.id, i, others)
- end
- Msg.send(msgRet, human.fd)
- return
- end
- -- 添加召唤英雄
- if op == OP_CONFIRM then
- local index = tonumber(arg)
- if not grid.summonHero then return end
- local hero = grid.summonHero[index]
- if not hero then return end
- local heroGrid = HeroGrid.createHeroGrid(hero.id, hero.star)
- if not heroGrid then return end
- heroGrid.isLostTemple = 1
- -- 初始化属性
- local attrConfig = HeroDefine.getAttrConfig(hero.id, heroGrid.star)
- if not attrConfig then return end
- local quality = HeroGrid.getMaxQualityByLv(heroGrid.star, hero.lv)
- local maxLv = HeroGrid.getMaxLv(heroGrid.star, quality)
- heroGrid.lv = math.min(maxLv, hero.lv or 0)
- heroGrid.quality = math.max(heroGrid.quality, quality or 0)
- -- 加入装备
- -- 加入到英雄队列
- human.lostTemple.summonHero = human.lostTemple.summonHero or { }
- human.lostTemple.summonHero[0] = human.lostTemple.summonHero[0] or 0
- human.lostTemple.summonHero[0] = human.lostTemple.summonHero[0] + 1
- local addIndex = human.lostTemple.summonHero[0]
- human.lostTemple.summonHero[addIndex] = heroGrid
- heroGrid.bagIndex = addIndex
- -- 计算属性
- LostTempleCombatLogic.getHeroAttrs(human, addIndex)
- -- 通知客户端
- sendSummonHeroList(human)
- return true
- end
- end
- -- 智慧树
- function Lost_Handle_Func.summonTree(human, op, y, grid, arg, elementConfig)
- -- 召唤神坛查询
- if op == OP_QUERY then
- if not grid.summonTree then return end
- local msgRet = Msg.gc.GC_LOST_TEMPLE_BUFF
- msgRet.list[0] = 0
- for i = 1, #grid.summonTree do
- local hero = grid.summonTree[i]
- msgRet.list[0] = msgRet.list[0] + 1
- local config = LostTempleExcel.Tree[grid.summonTree[i]]
- local net = msgRet.list[msgRet.list[0]]
- net.id = i
- net.icon = config.icon
- net.name = config.buffname
- net.attr[0] = #config.Buffid
- for i = 1, #config.Buffid do
- net.attr[i].key = config.Buffid[i][1]
- net.attr[i].value = config.Buffid[i][2]
- end
- end
- Msg.send(msgRet, human.fd)
- return
- end
- -- 添加召唤英雄
- if op == OP_CONFIRM then
- local index = tonumber(arg)
- if not grid.summonTree then return end
- local buffID = grid.summonTree[index]
- if not buffID then return end
- local config = LostTempleExcel.Tree[buffID]
- if not config then return end
- human.lostTemple.summonTree = human.lostTemple.summonTree or { }
- for i = 1, #config.Buffid do
- local key = config.Buffid[i][1]
- local value = config.Buffid[i][2]
- human.lostTemple.summonTree[key] = human.lostTemple.summonTree[key] or 0
- human.lostTemple.summonTree[key] = human.lostTemple.summonTree[key] + value
- end
- sendSummonTreeList(human)
- return true
- end
- end
- -- 炽天使
- function Lost_Handle_Func.treatRevive(human, op, y, grid, arg, elementConfig)
- if op == OP_QUERY then
- return
- end
- -- 复活治疗
- if op == OP_CONFIRM then
- local opType = tonumber(arg)
- local heroStatus = human.lostTemple.heroStatus
- if not heroStatus then return true end
- -- 复活
- if opType == 1 then
- local len = 0
- local cnt = 0
- local revice = {}
- local hpList = {}
- for k, hpRate in pairs(heroStatus) do
- if hpRate <= 0.0 then
- len = len + 1
- revice[len]=k
- else
- if hpRate < 1.0 then
- cnt = cnt + 1
- hpList[cnt] = k
- end
- end
- end
- if #revice > 0 then
- local random = math.random(1, #revice)
- heroStatus[revice[random]] = nil
- elseif #hpList > 0 then
- local random = math.random(1, #hpList)
- heroStatus[hpList[random]] = nil
- end
- end
- -- 治疗
- if opType == 2 then
- for k, hpRate in pairs(heroStatus) do
- if heroStatus[k] > 0.0 then
- heroStatus[k] = hpRate + 0.5
- if heroStatus[k] >= 1.0 then
- heroStatus[k] = nil
- end
- end
- end
- end
- sendHeroStatus(human)
- return true
- end
- end
- -- 神界商店
- function Lost_Handle_Func.summonShop(human, op, y, grid, arg, elementConfig)
- if op == OP_QUERY then
- if not grid.summonShop then return end
- local msgRet = Msg.gc.GC_LOST_TEMPLE_SHOP
- msgRet.list[0] = 0
- for i = 1, #grid.summonShop do
- msgRet.list[0] = msgRet.list[0] + 1
- local config = LostTempleExcel.LostShop[grid.summonShop[i]]
- local net = msgRet.list[msgRet.list[0]]
- Grid.makeItem(net.item, config.itemid, config.itemnum)
- Grid.makeItem(net.needItem, config.spenditem, config.spendnum)
- net.discount = config.discount
- net.id = i
- end
- Msg.send(msgRet, human.fd)
- return
- end
- -- 购买东西
- if op == OP_CONFIRM then
- local index = tonumber(arg)
- if not grid.summonShop then return end
- local shopID = grid.summonShop[index]
- if not shopID then return end
- local config = LostTempleExcel.LostShop[shopID]
- if not config then return end
- if not BagLogic.checkItemCnt(human, config.spenditem, config.spendnum) then
- return
- end
- BagLogic.delItem(human, config.spenditem, config.spendnum, "lostTemple")
- BagLogic.addItem(human, config.itemid, config.itemnum, "lostTemple")
- return true
- end
- end
- -- -- 宝箱
- function Lost_Handle_Func.summonBox(human, op, y, grid, arg, elementConfig)
- if op == OP_QUERY then
- sendRandomBox(human)
- return
- end
- --
- if op == OP_CONFIRM then
- if human.lostTemple.randomReward then
- local item = { }
- local len = 0
- for k, v in pairs(human.lostTemple.randomReward) do
- len = len + 1
- item[len] = { k, v }
- end
- BagLogic.addItemList(human, item, "lostTemple")
- human.lostTemple.randomReward = nil
- TriggerLogic.PublishEvent(TriggerDefine.LOSTTEMPLE_PASS_LAYER, human.db._id, 1)
- end
- -- 判定有没有下一程
- local nextLayer = human.lostTemple.layer + 1
- local LostTempleConfig = LostTempleExcel[nextLayer]
- if LostTempleConfig then
- -- 变成传送门
- putSet(human, y, elementConfig.cmd)
- end
- dbSave(human)
- update(human)
- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1208)
- end
- end
- -- 传送门
- function Lost_Handle_Func.conveyDoor(human, op, y, grid, arg, elementConfig)
- if op == OP_QUERY then
- return
- end
- -- 进入下一层
- if op == OP_CONFIRM then
- nextDB(human)
- dbSave(human)
- update(human)
- end
- end
- function lostTempleRevice(human)
- if not human.lostTemple then return end
- human.lostTemple.heroStatus = nil
- sendHeroStatus(human)
- end
- -- 查询一键扫荡状态
- function LostTemple_OneClickSweep_Query(human)
- if not isOpen(human) then
- return Broadcast.sendErr(human, Lang.COMMOM_NOT_ENABLED)
- end
- local msgRet = Msg.gc.GC_LOGT_TEMPLE_ONECLICK_SWEEP_QUERY
- msgRet.state = 0
- if human.lostTemple and human.lostTemple.oneClickSweep then
- msgRet.state = 2
- else
- local isBuyKing = HeroGrowUp.isBuyKing(human)
- if isBuyKing and isBuyKing == 1 then
- msgRet.state = 1
- end
- end
- Msg.send(msgRet, human.fd)
- end
- -- 查询一键扫荡奖励
- function LostTemple_OneClickSweep_Award(human)
- if not isOpen(human) then
- return Broadcast.sendErr(human, Lang.COMMOM_NOT_ENABLED)
- end
- local msgRet = Msg.gc.GC_LOGT_TEMPLE_ONECLICK_SWEEP_AWARD
- msgRet.awardArr[0] = 0
- local awardCfg = LostTempleExcel.Saodang[1].reward
- msgRet.awardArr[0] = #awardCfg
- for idx, itemTb in ipairs(awardCfg) do
- Grid.makeItem(msgRet.awardArr[idx], itemTb[1], itemTb[2])
- end
- Msg.send(msgRet, human.fd)
- end
- -- 进行一键扫荡
- function LostTemple_OneClickSweep_Do(human)
- if not isOpen(human) then
- return Broadcast.sendErr(human, Lang.COMMOM_NOT_ENABLED)
- end
- local isBuyKing = HeroGrowUp.isBuyKing(human)
- if not isBuyKing or isBuyKing ~= 1 then
- return Broadcast.sendErr(human, Lang.LOST_NO_BUY)
- end
- local lostTempleData = human.lostTemple
- if lostTempleData and lostTempleData.oneClickSweep then
- return Broadcast.sendErr(human, Lang.LOST_HAS_ONECLICKSWEEP)
- end
- if isChallenge(human) then
- return Broadcast.sendErr(human, Lang.LOST_HAS_CHALLENGE)
- end
- -- 更新数据
- --human.lostTemple = { layer = lostLayer, x = lostX, y = lostY, random = lostRandom, box = nil, grid = nil }
- initDB(human)
- -- lostTempleData = human.lostTemple
- -- lostTempleData.layer = 3
- -- lostTempleData.x = 10
- -- lostTempleData.y = 4
- for i=1, 2 do
- nextDB(human)
- end
- human.lostTemple.oneClickSweep = true
- dbSave(human)
- update(human)
- local awardArr = {}
- local awardCfg = LostTempleExcel.Saodang[1].reward
- for idx, itemTb in ipairs(awardCfg) do
- awardArr[idx] = {itemTb[1], itemTb[2]}
- end
- BagLogic.addItemList(human, awardArr, "lostTemple")
- YunYingLogic.onCallBack(human, "lostTempleCombat", 1)
- LostTemple_OneClickSweep_Query(human)
- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1208)
- end
|