| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- ------------------------------------------------------
- -- 兵书逻辑
- ------------------------------------------------------
- local FuwenExcel = require("excel.fuwen")
- local HeroExcel = require("excel.hero")
- local Lang = require("common.Lang")
- local Util = require("common.Util")
- local Msg = require("core.Msg")
- local ObjHuman = require("core.ObjHuman")
- local Broadcast = require("broadcast.Broadcast")
- local Grid = require("bag.Grid")
- local BagLogic = require("bag.BagLogic")
- local BingshuGrid = require("fuwen.BingshuGrid")
- local HeroLogic = require("hero.HeroLogic")
- local LiLianLogic = require("dailyTask.LiLianLogic")
- BINGSHU_MAXCNT = 3 -- 最多x个兵书
- BINGSHU_OPEN_LIST = {6, 11, 13}
- ------------------------------------- config ------------------------------------------
- -- 获取可以激活的技能列表
- local CAN_LEARN_LIST = nil
- function getCanLearnList()
- if not CAN_LEARN_LIST then
- CAN_LEARN_LIST = {}
- for id, config in Util.pairsByKeys(FuwenExcel.skill) do
- if config.isBingshuSkill == 1 and config.lv == 1 then
- CAN_LEARN_LIST[#CAN_LEARN_LIST + 1] = id
- end
- end
- end
- return CAN_LEARN_LIST
- end
- -- 获取下一级技能
- function getNextSkillID(skillID)
- local tconfig = FuwenExcel.skill[skillID]
- if not tconfig then return end
- for id, config in pairs(FuwenExcel.skill) do
- if (config.isBingshuSkill == 1) and
- (config.groupID == tconfig.groupID) and
- (config.lv == tconfig.lv + 1) and
- (#config.bingshuUpNeed > 0) then
- return id
- end
- end
- end
- ----------------------------------------- db -------------------------------------------------
- -- 获取兵书grid
- function getBingshuGrid(heroGrid, index)
- if not heroGrid then return end
- if not heroGrid.bingshu then return end
- return index and heroGrid.bingshu[index]
- end
- -- 是否已经学过某个技能
- function isLearnSkill(heroGrid, skillID)
- if not heroGrid then return end
- if not heroGrid.bingshu then return end
- local skillConfig = FuwenExcel.skill[skillID]
- for _, grid in pairs(heroGrid.bingshu) do
- local tconfig = FuwenExcel.skill[grid.skillID]
- if tconfig.groupID == skillConfig.groupID then
- return true
- end
- end
- end
- ----------------------------------------- msg -------------------------------------------------
- -- 查询
- function sendQuery(human, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if not heroGrid then return end
- local msgRet = Msg.gc.GC_BINGSHU_QUERY
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- msgRet.skills[0] = 0
- for i = 1, BINGSHU_MAXCNT do
- local grid = getBingshuGrid(heroGrid, i)
- if grid then
- msgRet.skills[0] = msgRet.skills[0] + 1
- BingshuGrid.makeBingshuNet(msgRet.skills[msgRet.skills[0]], grid, i)
- end
- end
- msgRet.openList[0] = BINGSHU_MAXCNT
- for i = 1, msgRet.openList[0] do
- msgRet.openList[i] = BINGSHU_OPEN_LIST[i] or 0
- end
- for i = 1, BINGSHU_MAXCNT do
- msgRet.red[i] = isBingShuDotByIndex(human, heroGrid, i) and 1 or 0
- end
- msgRet.red[0] = BINGSHU_MAXCNT
- -- Msg.trace(msgRet)
- Msg.send(msgRet, human.fd)
- end
- -- 可激活列表
- function sendLearnList(human, heroID, heroIndex, index)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if not heroGrid then return end
- local learnList = getCanLearnList()
- local msgRet = Msg.gc.GC_BINGSHU_LEARN_LIST
- msgRet.list[0] = 0
- for _, skillID in ipairs(learnList) do
- if msgRet.list[0] >= #msgRet.list then
- break
- end
- if not isLearnSkill(heroGrid, skillID) then
- msgRet.list[0] = msgRet.list[0] + 1
- BingshuGrid.makeBingshuLearnNet(msgRet.list[msgRet.list[0]], skillID)
- end
- end
- msgRet.index = index
- -- Msg.trace(msgRet)
- Msg.send(msgRet, human.fd)
- end
- -- 学习技能
- function learnSkill(human, heroID, heroIndex, index, skillID)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if not heroGrid then return end
- if index < 1 or index > BINGSHU_MAXCNT then
- return
- end
- local heroConfig = HeroExcel.hero[heroGrid.id]
- if heroGrid.star < BINGSHU_OPEN_LIST[index] then
- return
- end
- if getBingshuGrid(heroGrid, index) then
- return Broadcast.sendErr(human, Lang.BINGSHU_LEARN_ERR_HAD)
- end
- local config = FuwenExcel.skill[skillID]
- if not config then return end
- if config.isBingshuSkill ~= 1 then return end
- if config.lv ~= 1 then return end
- for _, item in ipairs(config.bingshuUpNeed) do
- local itemID = item[1]
- local itemCnt = item[2]
- if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
- return
- end
- end
- for _, item in ipairs(config.bingshuUpNeed) do
- local itemID = item[1]
- local itemCnt = item[2]
- BagLogic.delItem(human, itemID, itemCnt, "bingshu")
- end
- local grid = BingshuGrid.create(skillID)
- heroGrid.bingshu = heroGrid.bingshu or {}
- heroGrid.bingshu[index] = grid
- local msgRet = Msg.gc.GC_BINGSHU_LEARN
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- BingshuGrid.makeBingshuNet(msgRet.data, grid, index)
- -- Msg.trace(msgRet)
- Msg.send(msgRet, human.fd)
- ObjHuman.doCalcHero(human, heroIndex)
- local newcf = FuwenExcel.skill[grid.skillID]
- LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID28,1,newcf.lv)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- sendQuery(human, heroID, heroIndex)
- end
- function getForgetCost(lv)
- local costs = FuwenExcel.define[1].bingshuForgetCosts
- return costs[lv] or costs[#costs]
- end
- -- 升级查询
- function sendLevelUpQuery(human, heroID, heroIndex, index)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if not heroGrid then return end
- local grid = getBingshuGrid(heroGrid, index)
- if not grid then return end
- local config = FuwenExcel.skill[grid.skillID]
- local nextSkillID = getNextSkillID(grid.skillID)
- local nextConfig = nextSkillID and FuwenExcel.skill[nextSkillID]
- local msgRet = Msg.gc.GC_BINGSHU_LEVELUP_QUERY
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- BingshuGrid.makeBingshuNet(msgRet.bingshu, grid, index)
- msgRet.upData[0] = 0
- if nextConfig then
- msgRet.upData[0] = 1
- BingshuGrid.makeBingshuLearnNet(msgRet.upData[1], nextSkillID)
- end
- msgRet.forgetCost = getForgetCost(config.lv)
- msgRet.returnItems[0] = config and #config.bingshuForgetReturn or 0
- for i = 1, msgRet.returnItems[0] do
- local itemID = config.bingshuForgetReturn[i][1]
- local itemCnt = config.bingshuForgetReturn[i][2]
- Grid.makeItem(msgRet.returnItems[i], itemID, itemCnt)
- end
- -- Msg.trace(msgRet)
- Msg.send(msgRet, human.fd)
- end
- -- 升级
- function levelUp(human, heroID, heroIndex, index)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if not heroGrid then return end
- local grid = getBingshuGrid(heroGrid, index)
- if not grid then return end
- local nextSkillID = getNextSkillID(grid.skillID)
- local nextConfig = nextSkillID and FuwenExcel.skill[nextSkillID]
- if not nextConfig then
- return Broadcast.sendErr(human, Lang.BINGSHU_LEVELUP_ERR_FULL)
- end
- for _, item in ipairs(nextConfig.bingshuUpNeed) do
- local itemID = item[1]
- local itemCnt = item[2]
- if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
- return
- end
- end
- for _, item in ipairs(nextConfig.bingshuUpNeed) do
- local itemID = item[1]
- local itemCnt = item[2]
- BagLogic.delItem(human, itemID, itemCnt, "bingshu")
- end
- grid.skillID = nextSkillID
- local msgRet = Msg.gc.GC_BINGSHU_LEVELUP
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- BingshuGrid.makeBingshuNet(msgRet.bingshu, grid, index)
- -- Msg.trace(msgRet)
- Msg.send(msgRet, human.fd)
- ObjHuman.doCalcHero(human, heroIndex)
- sendLevelUpQuery(human, heroID, heroIndex, index)
- sendQuery(human, heroID, heroIndex)
-
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- end
- -- 遗忘
- function forget(human, heroID, heroIndex, index)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if not heroGrid then return end
- local grid = getBingshuGrid(heroGrid, index)
- if not grid then return end
- local config = FuwenExcel.skill[grid.skillID]
- local needZuanshi = getForgetCost(config.lv)
- if not ObjHuman.checkRMB(human, needZuanshi) then
- return
- end
- ObjHuman.decZuanshi(human, -needZuanshi, "bingshu")
- heroGrid.bingshu[index] = nil
- BagLogic.addItemList(human, config.bingshuForgetReturn, "bingshu")
- local msgRet = Msg.gc.GC_BINGSHU_FORGET
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- msgRet.index = index
- Msg.send(msgRet, human.fd)
- ObjHuman.doCalcHero(human, heroIndex)
-
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- end
- BINGSHU_OPEN_TIME = nil
- function isBingShuDot(human, heroGrid)
- if not BINGSHU_OPEN_TIME then
- -- local d = os.date("*t",time)
- local tmpDate = {}
- tmpDate.year = 2022
- tmpDate.month = 1
- tmpDate.day = 31
- tmpDate.hour = 0
- tmpDate.min = 0
- tmpDate.sec = 0
- BINGSHU_OPEN_TIME = os.time(tmpDate)
- end
-
- if os.time() <= BINGSHU_OPEN_TIME then return -1 end
- if not heroGrid then return end
- if heroGrid.star < BINGSHU_OPEN_LIST[1] then return end
- for i = 1, BINGSHU_MAXCNT do
- if heroGrid.star < BINGSHU_OPEN_LIST[i] then return end
- local grid = getBingshuGrid(heroGrid, i)
- if grid then
- -- 检测是否能升级
- local nextSkillID = getNextSkillID(grid.skillID)
- local nextConfig = nextSkillID and FuwenExcel.skill[nextSkillID]
- if nextConfig then
- local canUp = true
- for _, item in ipairs(nextConfig.bingshuUpNeed) do
- local itemID = item[1]
- local itemCnt = item[2]
- if BagLogic.getItemCnt(human, itemID) < itemCnt then
- canUp = false
- end
- end
- if canUp then
- return true
- end
- end
- else
- local learnList = getCanLearnList()
- local canUp = true
- for i, skillID in ipairs(learnList) do
- canUp = true
- local config = FuwenExcel.skill[skillID]
- for k, v in ipairs(config.bingshuUpNeed) do
- local itemID = v[1]
- local itemCnt = v[2]
- if BagLogic.getItemCnt(human, itemID) < itemCnt then
- canUp = false
- end
- end
-
- if canUp then
- return true
- end
- end
-
- end
- end
- end
- function isBingShuDotByIndex(human, heroGrid, index)
- if not BINGSHU_OPEN_TIME then
- -- local d = os.date("*t",time)
- local tmpDate = {}
- tmpDate.year = 2022
- tmpDate.month = 1
- tmpDate.day = 31
- tmpDate.hour = 0
- tmpDate.min = 0
- tmpDate.sec = 0
- BINGSHU_OPEN_TIME = os.time(tmpDate)
- end
- if os.time() <= BINGSHU_OPEN_TIME then return end
- if not heroGrid then return end
- if heroGrid.star < BINGSHU_OPEN_LIST[index] then return end
- local grid = getBingshuGrid(heroGrid, index)
- if grid then
- -- 检测是否能升级
- local nextSkillID = getNextSkillID(grid.skillID)
- local nextConfig = nextSkillID and FuwenExcel.skill[nextSkillID]
- if nextConfig then
- local canUp = true
- for _, item in ipairs(nextConfig.bingshuUpNeed) do
- local itemID = item[1]
- local itemCnt = item[2]
- if BagLogic.getItemCnt(human, itemID) < itemCnt then
- canUp = false
- end
- end
- if canUp then
- return true
- end
- end
- else
- local learnList = getCanLearnList()
- local canUp = true
- for i, skillID in ipairs(learnList) do
- canUp = true
- local config = FuwenExcel.skill[skillID]
- for k, v in ipairs(config.bingshuUpNeed) do
- local itemID = v[1]
- local itemCnt = v[2]
- if BagLogic.getItemCnt(human, itemID) < itemCnt then
- canUp = false
- end
- end
-
- if canUp then
- return true
- end
- end
-
- end
- end
|