| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935 |
- ---------------------------------------------------------------
- -- 指引
- -- db.guide.id 指引id
- -- db.guide.step 步骤
- -- db.guide.state 状态
- -- db.guide.cmd2id cmd->id
- -- db.guide.flags 特殊指引标记,是否完成
- ---------------------------------------------------------------
- local Config = require("Config")
- Json = Json or require("common.Json")
- local GuideExcel = require("excel.guide")
- local Util = require("common.Util")
- local Log = require("common.Log")
- local Msg = require("core.Msg")
- local ObjHuman = require("core.ObjHuman")
- local Grid = require("bag.Grid")
- local BagLogic = require("bag.BagLogic")
- local ItemDefine = require("bag.ItemDefine")
- local BattleLogic = require("battle.BattleLogic")
- local LoginSignLogic = require("loginSign.LoginSignLogic")
- local PanelDefine = require("broadcast.PanelDefine")
- local SceneHandler = require("scene.Handler")
- local RoleExcel = require("excel.role")
- local CombatLogic = require("combat.CombatLogic")
- local HeroGrid = require("hero.HeroGrid")
- local HeroLogic = require("hero.HeroLogic")
- local CombatDefine = require("combat.CombatDefine")
- local CombatPosLogic = require("combat.CombatPosLogic")
- local RoleDefine = require("role.RoleDefine")
- local CombatExcel = require("excel.combat")
- local OpenActExcel = require("excel.openAct")
- local OpenAct = require("present.OpenAct")
- local CommonDB = require("common.CommonDB")
- local OpenServerGiftLogic = require("present.OpenServerGiftLogic")
- local GuideDefine = require("guide.GuideDefine")
- local WeiLen = 30
- local GUIDECMD_LIST = {"battle"}
- local GUIDEID_FIRST = 0
- -- 指引中断处理方式
- SKIPTYPE_RESET = 0 -- 该指引重新从第一步开始
- SKIPTYPE_JUMP = 1 -- 该指引直接跳过
- SKIPTYPE_JUMP_NAME = 2 -- 改名跳过该指引
- SKIPTYPE_JUMP_DRAW = 3 -- 期间进行过高级抽奖,直接跳过
- SKIPTYPE_JUMP_HERO = 4 -- 期间获得过英雄,直接跳过
- SKIPTYPE_JUMP_HEROUP = 5 -- 英雄升级指定次数
- SKIPTYPE_JUMP_BATTLE_REWARD = 7 -- 战役通关奖励
- SKIPTYPE_JUMP_SHOPBUY = 8 -- 商店购买
- SKIPTYPE_JUMP_OL_REWARD = 9 -- 在线奖励
- SKIPTYPE_JUMP_LOGINSIGN = 10 -- 签到
- SKIPTYPE_JUMP_BATTLE_SD = 11 -- 战役扫荡
- SKIPTYPE_JUMP_BATTLE = 12 -- 战役
- SKIPTYPE_JUMP_BATTLE_EXP = 13 -- 是否领取经验
- SKIPTYPE_JUMP_LEVEL_GIFT = 14 -- 领取等级礼包
- SKIPTYPE_JUMP_OPEN_SERVER_GIFT = 15 -- 领取开服有礼礼包
- SKIPTYPE_JUMP_UPGRADE = 16 -- 英雄指定进阶次数
- SKIPTYPE_JUMP_JIBAN_GROUP = 17 -- 添加过羁绊组合
- SKIPTYPE_JUMP_JIEFENG_BAOJU = 18 -- 解封过宝具奖励
- SKIPTYPE_JUMP_BATTLE_GUAJI = 19 -- 领取过挂机奖励
- SKIPTYPE_JUMP_BARTASK = 20 -- 悬赏
- SKIPTYPE_JUMP_FINISH = 21 -- 直接全部跳过
- -- 状态
- STATE_DOING = 1 -- 进行中
- STATE_FINISH = 2 -- 完成
- GUIDE_COMBAT_INFO = GUIDE_COMBAT_INFO or { db = {} }
- -- 开服第8天 除了取名的指引 其余一律跳过
- local function initGuideHeroList()
- local combatConf = CombatExcel.gm[888888]
- if not combatConf then return end
- GUIDE_COMBAT_INFO.attacker = {}
- GUIDE_COMBAT_INFO.defender = {}
- GUIDE_COMBAT_INFO.atkFormation = combatConf.atkF
- GUIDE_COMBAT_INFO.defFormation = combatConf.defF
- local atkConf = nil
- for i = 1, CombatDefine.COMBAT_HERO_CNT do
- atkConf = nil
- for k, v in ipairs(combatConf.atk) do
- if i == v[2] then
- atkConf = v
- break
- end
- end
- if atkConf then
- GUIDE_COMBAT_INFO.attacker[i] = CombatLogic.createHeroObj(GUIDE_COMBAT_INFO, atkConf[1], atkConf[3], atkConf[4], i)
- end
- atkConf = nil
- for k, v in ipairs(combatConf.def) do
- if i == v[2] then
- atkConf = v
- break
- end
- end
- if atkConf then
- GUIDE_COMBAT_INFO.defender[i] = CombatLogic.createHeroObj(GUIDE_COMBAT_INFO, atkConf[1], atkConf[3], atkConf[4], i)
- end
- end
-
- GUIDE_COMBAT_INFO.init = 1
- end
- function initAfterHot()
- if GUIDE_COMBAT_INFO.combat ~= nil then
- return
- end
- GuideExcel = require("excel.guide")
- -- 初始化剧情动画
- initGuideHeroList()
- if not GUIDE_COMBAT_INFO.init then return end
- CombatLogic.combatGuide(GUIDE_COMBAT_INFO, GUIDE_COMBAT_INFO.atkFormation, GUIDE_COMBAT_INFO.attacker,
- GUIDE_COMBAT_INFO.defFormation, GUIDE_COMBAT_INFO.defender)
- end
- ------------------------------ data --------------------------------------
- -- 设置指引
- function setGuide(human, id, state, skipType)
- local cf = GuideExcel.main_guide[id]
- if not cf then return end
- human.db.guide = human.db.guide or {}
- local oldstate = human.db.guide.state
- local oldid = human.db.guide.id
- if (oldid == id) and (oldstate == state) then
- return -- 老的和新的一致
- end
- local guide = human.db.guide
- local oldcmdid = getGuideIDByCmd(human, cf.cmd)
- guide.id = id
- guide.state = state
- guide.step = 0
- guide.cmd2id = guide.cmd2id or {}
- guide.cmd2id[cf.cmd] = id
- guide.flags = nil
- if state == STATE_DOING then
- if oldcmdid < id then
- -- 触发指引给东西
- BagLogic.addItemList(human, cf.items, "guide")
- end
- end
-
- if state == STATE_FINISH then
- Log.write(Log.LOGID_OSS_GUIDE_MAIN, human.db._id, human.db.account, human.db.name, human.db.lv, human.db.ip,
- human.pf or "", human.appid, id, skipType or 0)
- end
- end
- -- 获取id
- function getGuideID(human)
- if not human.db.guide then
- return
- end
- return human.db.guide.id
- end
- --
- function getGuideState(human)
- if not human.db.guide then
- return
- end
- return human.db.guide.state
- end
- function getGuideStep(human)
- if not human.db.guide then
- return 0
- end
- return human.db.guide.step or 0
- end
- function setGuideStep(human, step, sid)
- if not human.db.guide then
- return
- end
- human.db.guide.step = step
- if step then
- print("[setGuideStep] step = "..step)
- end
- if sid then
- print("[setGuideStep] sid = "..sid)
- end
-
- if sid then
- Log.write(Log.LOGID_OSS_GUIDE_SUB, human.db._id, human.db.account, human.db.name, human.db.lv, human.db.ip, human.pf or "", human.appid, sid)
- end
- end
- --
- function setLoginStep(human, id)
- human.guideLoginStep = nil
- local cf = GuideExcel.main_guide[id]
- if not cf then return end
- if #cf.loginList < 1 then return end
- human.guideLoginStep = {}
- for i, sid in ipairs(cf.loginList) do
- human.guideLoginStep[i] = sid
- end
- end
- function getLoginStep(human)
- if not human.guideLoginStep then
- return
- end
- return human.guideLoginStep[1]
- end
- function delLoginStep(human)
- if not human.guideLoginStep then return end
- for i = 1, #human.guideLoginStep do
- human.guideLoginStep[i] = human.guideLoginStep[i + 1]
- end
- if #human.guideLoginStep < 1 then
- human.guideLoginStep = nil
- end
- end
- -- 根据cmd获取id
- function getGuideIDByCmd(human, cmd)
- if not human.db.guide or
- not human.db.guide.cmd2id then
- return GUIDEID_FIRST
- end
- if not human.db.guide.cmd2id[cmd] then
- return GUIDEID_FIRST
- end
- return human.db.guide.cmd2id[cmd]
- end
- function isFinishGuideID(human, id)
- local cf = GuideExcel.main_guide[id]
- if not cf then return end
- local nowid = getGuideIDByCmd(human, cf.cmd)
- if nowid ~= id then
- return nowid > id
- end
- if getGuideID(human) == id then
- local state = getGuideState(human)
- return state == STATE_FINISH
- end
- return true
- end
- -- 获取当前类型 是否满足条件
- function getGuideSkip(human, skipType)
- local id = getGuideID(human)
- local state = getGuideState(human)
- if id and state == STATE_FINISH then
- return true
- end
- local cf = GuideExcel.main_guide[id]
- if not cf then return end
- if cf.skipType ~= skipType then return true end
- local isJump = nil
- if cf.skipType == SKIPTYPE_JUMP then
- isJump = true
- elseif cf.skipType == SKIPTYPE_JUMP_DRAW or
- cf.skipType == SKIPTYPE_JUMP_HERO or
- cf.skipType == SKIPTYPE_JUMP_SHOPBUY or
- cf.skipType == SKIPTYPE_JUMP_BATTLE or
- cf.skipType == SKIPTYPE_JUMP_JIEFENG_BAOJU or
- cf.skipType == SKIPTYPE_JUMP_BATTLE_GUAJI or
- cf.skipType == SKIPTYPE_JUMP_BATTLE_EXP or
- cf.skipType == SKIPTYPE_JUMP_BARTASK then
- if getDoSpecialGuide(human, cf.skipType) > 0 then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_NAME then
- if (human.db.changeNameCnt or 0) > 0 then
- isJump = true
- end
-
- elseif cf.skipType == SKIPTYPE_JUMP_HEROUP or
- cf.skipType == SKIPTYPE_JUMP_UPGRADE then
- if getDoSpecialGuide(human, cf.skipType) >= cf.skipArgs[1] then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_REWARD then
- if BattleLogic.isGetReward(human, cf.skipArgs[1] or 1) then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_OL_REWARD then
- if (human.db.onlineReward and human.db.onlineReward.id or 1) > 1 then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_LOGINSIGN then
- if not LoginSignLogic.isRed(human) or getDoSpecialGuide(human, cf.skipType) > 0 then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_SD then
- if (human.db.mopupDoCnt or 0) > 0 and getDoSpecialGuide(human, cf.skipType) > 0 then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_LEVEL_GIFT then
- if human.db.chongJi ~= nil then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_OPEN_SERVER_GIFT then
- local len = #OpenActExcel.openServerGift
- for i = 1,len do
- local state = OpenServerGiftLogic.getGiftState(human, i)
- if state ~= 1 and state ~= 0 then
- isJump = true
- break
- end
- end
- elseif cf.skipType == SKIPTYPE_JUMP_JIBAN_GROUP then
- for i = 1,CombatDefine.COMBAT_TYPE_MAX do
- local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,i)
- if combatHeroDB and combatHeroDB.jiban then
- isJump = true
- break
- end
- end
- end
- return isJump
- end
- -- 是否触发过该特殊指引
- function getDoSpecialGuide(human, id)
- if not human.db.guide or
- not human.db.guide.flags then
- return 0
- end
- return human.db.guide.flags[id] or 0
- end
- -- 设置已触发
- function setDoSpecialGuide(human, id)
- human.db.guide = human.db.guide or {}
- human.db.guide.flags = human.db.guide.flags or {}
- local cnt = human.db.guide.flags[id] or 0
- human.db.guide.flags[id] = cnt + 1
- end
- -- 刷新指引状态
- function refreshGuide(human, isLogin)
- local id = getGuideID(human)
- local state = getGuideState(human)
- if id and state ~= STATE_FINISH then
- local conf = GuideExcel.main_guide[id]
- if not conf then
- assert(nil, " GuideExcel conf not have id : ".. id)
- end
- if conf.cmd == GUIDECMD_LIST[1] and conf.skipType == SKIPTYPE_JUMP_FINISH and isLogin then
- -- 完成此任务
- setGuide(human, id, STATE_FINISH, conf.skipType)
-
- while true do
- local pid = getGuideIDByCmd(human, GUIDECMD_LIST[1])
- if pid == GUIDEID_FIRST then
- break
- end
- local nid = getNextGuideID(pid, GUIDECMD_LIST[1])
- local cf = GuideExcel.main_guide[nid]
- if nid and cf and cf.cmd == GUIDECMD_LIST[1] then
- setGuide(human, nid, STATE_FINISH, cf.skipType)
- else
- break
- end
- end
-
- end
- return
- end
- local doSkip = false
- local fid = nil
- for _, cmd in ipairs(GUIDECMD_LIST) do
- local cond, skip, nid = nil
- while true do
- local pid = getGuideIDByCmd(human, cmd)
- nid = getNextGuideID(pid, cmd)
- cond = checkCondition(human, nid)
- local cf = GuideExcel.main_guide[nid]
-
- if nid and cf and cf.cmd == "lv" then
- -- 不重登的情况下 必须达成等级需求才跳过 没有开启活动
- local isSkip = false
- if cf.args[2] == 1 and not isLogin and human.db.lv >= cf.args[1] and not cond then
- setGuide(human, nid, STATE_FINISH, cf.skipType)
- isSkip = true
- end
- -- 重登的情况下 直接跳过
- if isLogin and human.db.lv >= cf.args[1] then
- setGuide(human, nid, STATE_FINISH, cf.skipType)
- isSkip = true
- end
- if not isSkip then break end
- else
- break
- end
- end
- if nid and cond then
- fid = nid
- break
- end
- end
- if (not fid) or (fid == id) then return end
- setGuide(human, fid, STATE_DOING)
- return true
- end
- -- 指引跳过/还原处理
- function skipGuide(human)
- local id = getGuideID(human)
- local state = getGuideState(human)
- local nSubStep = getGuideStep(human)
- local nNextSubStep = nSubStep + 1
- print("[skipGuide] nSubStep = "..nSubStep)
- if id and state == STATE_FINISH then
- return
- end
- local cf = GuideExcel.main_guide[id]
- if not cf then return end
- local isJump = nil
- if cf.skipType == SKIPTYPE_JUMP or
- cf.skipType == SKIPTYPE_JUMP_BARTASK then
- isJump = true
- elseif cf.skipType == SKIPTYPE_JUMP_DRAW or
- cf.skipType == SKIPTYPE_JUMP_HERO or
- cf.skipType == SKIPTYPE_JUMP_SHOPBUY or
- cf.skipType == SKIPTYPE_JUMP_BATTLE or
- cf.skipType == SKIPTYPE_JUMP_JIEFENG_BAOJU or
- cf.skipType == SKIPTYPE_JUMP_BATTLE_GUAJI or
- cf.skipType == SKIPTYPE_JUMP_BATTLE_EXP then
- if getDoSpecialGuide(human, cf.skipType) > 0 then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_NAME then
- if human.db.changeNameCnt ~= nil then
- print("[skipGuide] changeNameCnt = "..human.db.changeNameCnt)
- isJump = true
- end
-
- elseif cf.skipType == SKIPTYPE_JUMP_HEROUP or
- cf.skipType == SKIPTYPE_JUMP_UPGRADE then
- if getDoSpecialGuide(human, cf.skipType) >= cf.skipArgs[1] then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_REWARD then
- if BattleLogic.isGetReward(human, cf.skipArgs[1] or 1) then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_OL_REWARD then
- if (human.db.onlineReward and human.db.onlineReward.id or 1) > 1 then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_LOGINSIGN then
- if not LoginSignLogic.isRed(human) or getDoSpecialGuide(human, cf.skipType) > 0 then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_SD then
- if (human.db.mopupDoCnt or 0) > 0 and getDoSpecialGuide(human, cf.skipType) > 0 then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_LEVEL_GIFT then
- if human.db.chongJi ~= nil then
- isJump = true
- end
- elseif cf.skipType == SKIPTYPE_JUMP_OPEN_SERVER_GIFT then
- local len = #OpenActExcel.openServerGift
- for i = 1,len do
- local state = OpenServerGiftLogic.getGiftState(human, i)
- if state ~= 1 and state ~= 0 then
- isJump = true
- break
- end
- end
- elseif cf.skipType == SKIPTYPE_JUMP_JIBAN_GROUP then
- for i = 1,CombatDefine.COMBAT_TYPE_MAX do
- local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,i)
- if combatHeroDB and combatHeroDB.jiban then
- isJump = true
- break
- end
- end
- end
- if isJump == true then
- -- 存在且进行中
- if id and STATE_DOING == state then
- print("[skipGuide] id = "..id)
- local tNoJumpInfo = GuideDefine.tGuideNoJumpInfo[id]
- if tNoJumpInfo and tNoJumpInfo[nNextSubStep] then
- return
- end
- end
- end
- if isJump then
- --跳过所有战斗
- for i = CombatDefine.COMBAT_TYPE1, CombatDefine.COMBAT_TYPE_MAX do
- CombatLogic.clientFinish(human, i, true)
- end
- return setGuide(human, id, STATE_FINISH, cf.skipType)
- end
- local nJump = isJump and 1 or 0
- print("[skipGuide] nJump = "..nJump)
- setGuideStep(human, nil)
- end
- -- 奖励判断操作
- local function GuideLogic_StepPrize(human, nNowStep, nNowSubStep)
- if not human or 0 >= nNowSubStep or 0 >= nNowStep then
- return
- end
- local tSubConfig = GuideExcel.sub_guide[nNowSubStep]
- if not tSubConfig then
- return
- end
- local szBehaviorName = tSubConfig.behavior[1]
- if not szBehaviorName then
- return
- end
- print("[GuideLogic_StepPrize] szBehaviorName = "..szBehaviorName.." nNowStep = "..nNowStep.." nNowSubStep = "..nNowSubStep)
- local tPrizeConfig = GuideDefine.tGuidePrizeBehavior[szBehaviorName]
- if not tPrizeConfig or not tPrizeConfig[nNowStep] or not tPrizeConfig[nNowStep][nNowSubStep] then
- return
- end
- local tPrize = tPrizeConfig[nNowStep][nNowSubStep]
- local tGoodsInfo = {}
- for k, v in pairs(tPrize) do
- table.insert(tGoodsInfo, {v[1],v[2]})
- -- 获取奖励写日志
- Log.write(Log.LOGID_OSS_GUIDE_SUB, "[GuideLogic_StepPrize] 玩家创角步骤获取到奖励 name = "
- ..human.db.name.." _id = "..human.db._id.." nGoodsID = "..v[1].." nGoodsNum = "..v[2].." nNowStep = "..nNowStep .. " nNowSubStep = "..nNowSubStep)
- end
- BagLogic.addItemList(human, tGoodsInfo, "guide")
- print("[GuideLogic_StepPrize] 玩家创角发送奖励 name = "..human.db.name)
- end
- ---------------------------- condition -----------------------------------
- GuideCondition = {}
- GuideCondition["lv"] = function(human, lv, checkAct)
- if not SceneHandler.canCharge(human) then
- return -- 如果不能充值,所有等级指引都不开
- end
- if checkAct and checkAct == 1 then
- if human.db.lv >= lv then
- for k, v in ipairs(OpenActExcel.openAct) do
- local flag = OpenAct.getOpenActTime(k)
- if flag == true then
- return true
- end
- end
- end
- else
- return human.db.lv >= lv
- end
- return false
- end
- -- 完成指定战役
- GuideCondition["battle"] = function(human, id)
- return (human.db.battleID or 1) > id
- end
- function checkCondition(human, id)
- local cf = GuideExcel.main_guide[id]
- if not cf then return end
- if cf.cmd == "" then return true end
- local func = GuideCondition[cf.cmd]
- if not func then return end
- return func(human, cf.args[1], cf.args[2])
- end
- ------------------------------ excel --------------------------------------
- -- 获取下一个指引id
- local GUIDEID_2_NEXTID = nil -- [cmd][preid] = nextid
- function getNextGuideID(id, cmd)
- if not GUIDEID_2_NEXTID then
- GUIDEID_2_NEXTID = {}
- local sids = {}
- for tid, cf in Util.pairsByKeys(GuideExcel.main_guide) do
- if #cf.guideList > 0 then
- local sid = sids[cf.cmd] or GUIDEID_FIRST
- GUIDEID_2_NEXTID[cf.cmd] = GUIDEID_2_NEXTID[cf.cmd] or {}
- GUIDEID_2_NEXTID[cf.cmd][sid] = tid
- sids[cf.cmd] = tid
- end
- end
- end
- if not GUIDEID_2_NEXTID[cmd] then
- return
- end
- return GUIDEID_2_NEXTID[cmd][id]
- end
- local SID_2_GUIDEID = nil
- local SID_2_GUIDESTEP = nil
- function getGuideIDBySid(sid)
- if not SID_2_GUIDEID then
- SID_2_GUIDEID = {}
- SID_2_GUIDESTEP = {}
- for id, cf in pairs(GuideExcel.main_guide) do
- for step, tsid in ipairs(cf.guideList) do
- SID_2_GUIDEID[tsid] = id
- SID_2_GUIDESTEP[tsid] = step
- end
- end
- end
- return SID_2_GUIDEID[sid], SID_2_GUIDESTEP[sid]
- end
- function getNextGuideIDByLv(lv)
- local minlv = nil
- local minid = nil
- for id, cf in pairs(GuideExcel.lv_guide) do
- if cf.cmd == "lv" and cf.dialog > 0 then
- local clv = cf.args[1]
- if clv > lv and (minlv == nil or clv < minlv) then
- minlv = clv
- minid = id
- end
- end
- end
- if not minid then return end
- return minid
- end
- local DIALOG_2_CONTENT = nil
- function getContentByDialog(dialog)
- if not dialog then return end
- if not DIALOG_2_CONTENT then
- DIALOG_2_CONTENT = {}
- for id, cf in pairs(GuideExcel.main_guide) do
- if cf.dialog > 0 then
- DIALOG_2_CONTENT[cf.dialog] = cf.content
- end
- end
- end
- return DIALOG_2_CONTENT[dialog]
- end
- local function getLvUpGetZuanshi(oldLv,newLv)
- local addZuanshi = 0
- for lv=1,#RoleExcel.exp do
- if lv > oldLv and lv <= newLv then
- addZuanshi = addZuanshi + RoleExcel.exp[lv].lvUpGetZuanshi
- end
- end
- return addZuanshi
- end
- ------------------------------- msg -------------------------------------
- function sendStep(human, sendNil)
- if not Config.HAS_GUIDE then return end -- 指引总开关
- local diffTime = os.time() - human.db.createTime
- if diffTime >= 7 * 86400 and human.db.lv >= 5 then
- return
- end
- if human.db.noguide and not sendNil then return end
- local id = (not sendNil) and getGuideID(human)
- local cf = id and GuideExcel.main_guide[id]
- local nextstep = getGuideStep(human) + 1
- local state = getGuideState(human)
- print("[sendStep] id = "..id.." nextstep = "..nextstep.." state = "..state)
-
- local msgRet = Msg.gc.GC_GUIDE_STEP
- msgRet.step[0] = 0
- if cf and state == STATE_DOING then
- local sid = getLoginStep(human) or cf.guideList[nextstep]
- local scf = sid and GuideExcel.sub_guide[sid]
- if scf then
- msgRet.step[0] = msgRet.step[0] + 1
- local net = msgRet.step[msgRet.step[0]]
- net.id = sid
- net.conditions = Json.Encode(scf.conditions)
- net.behavior = Json.Encode(scf.behavior)
- net.sound = scf.sound
- net.dialog = scf.dialog
- net.content = scf.content
- net.handid = scf.handid
- net.zhiyin = scf.zhiyin
- net.heroLhID = scf.herolhId
- net.skip = scf.skip
- if scf.behavior[1] == "openPanel" and scf.behavior[2] and
- scf.behavior[2][1] == PanelDefine.PANEL_ID_52 then
- local dialog = scf.behavior[2][2]
- net.content = getContentByDialog(dialog)
- end
- if scf.behavior[1] == "showAnima" and GUIDE_COMBAT_INFO.combat ~= nil then
- CombatLogic.sendCombatData(human, GUIDE_COMBAT_INFO.combat)
- end
- end
- end
- --Msg.trace(msgRet)
- Msg.send(msgRet, human.fd)
- end
- -- 能否下一步
- function canStepFinish(human, sid)
- local state = getGuideState(human)
- if state ~= STATE_DOING then return end
- if getLoginStep(human) == sid then -- 登录步骤
- delLoginStep(human)
- return true, getGuideID(human), 0
- end
- local id, step = getGuideIDBySid(sid)
- if not id then return end
- if getGuideID(human) ~= id then return end
- if sid >= 503 and sid <= 506 then
- local config = GuideExcel.main_guide[id]
- local oldStep = getGuideStep(human)
- local oldSid = config.guideList[oldStep]
- if oldSid < 502 or oldSid > 506 then
- return
- end
- -- if oldStep <
- else
- if getGuideStep(human) + 1 ~= step then return end
- end
-
- local cf = GuideExcel.main_guide[id]
- -- 升级次数
- if cf.skipType == SKIPTYPE_JUMP_HEROUP and cf.skipArgs[2] == sid then
- if getDoSpecialGuide(human, SKIPTYPE_JUMP_HEROUP) < cf.skipArgs[1] then
- return
- end
- end
- -- 进阶次数判定
- if cf.skipType == SKIPTYPE_JUMP_UPGRADE and cf.skipArgs[2] == sid then
- if getDoSpecialGuide(human, SKIPTYPE_JUMP_UPGRADE) < cf.skipArgs[1] then
- return
- end
- end
- return true, id, step
- end
- function stepFinish(human, sid, noSend)
- local isok, id, step = canStepFinish(human, sid)
- if isok then
- local cf = GuideExcel.main_guide[id]
- if step >= #cf.guideList then
- setGuide(human, id, STATE_FINISH)
- else
- setGuideStep(human, step, sid)
- end
- GuideLogic_StepPrize(human, id, sid)
- end
- refreshGuide(human)
- sendStep(human)
- end
- -- 登录回调
- function onLogin(human)
- skipGuide(human)
- refreshGuide(human, true)
- if getGuideState(human) == STATE_DOING then
- setLoginStep(human, getGuideID(human))
- sendStep(human)
- end
- sendLvGuide(human)
- end
- -- 升级回调
- function onLvUpCB(human, oldLv, newLv)
- local giveZuanshi = getLvUpGetZuanshi(oldLv,newLv)
- if giveZuanshi > 0 then
- ObjHuman.addZuanshi(human, giveZuanshi, "level_up")
- end
- local id = getNextGuideIDByLv(newLv)
- local cf = id and GuideExcel.lv_guide[id]
- local msgRet = Msg.gc.GC_LEVEL_UP
- local net = msgRet.data
- net.oldLv = oldLv
- net.newLv = newLv
- net.items[0] = 0
- if giveZuanshi > 0 then
- net.items[0] = net.items[0] + 1
- Grid.makeItem(net.items[net.items[0]], ItemDefine.ITEM_ZUANSHI_ID, giveZuanshi)
- end
- net.dialog = cf and cf.dialog or 0
- net.dialogName = cf and cf.dialogName or ""
- net.content = cf and cf.content or ""
- net.noticeLv = cf and cf.args[1] or 0
- net.panelId = cf and cf.panelId or 0
- Msg.send(msgRet, human.fd)
- end
- -- 等级指引
- local function makeLvGuideNet(net, id, human)
- local cf = GuideExcel.lv_guide[id]
- net.id = id
- net.noticeLv = cf and cf.args[1] or 0
- net.panelId = cf and cf.panelId or 0
- net.status = human.db.lvGuide and human.db.lvGuide[id] or 0
- local len = 0
- for k, v in ipairs(cf.guideList) do
- len = len + 1
- net.guideList[len] = v
- end
- net.guideList[0] = len
- end
- --推送等级指引
- function sendLvGuide(human)
- local msgRet = Msg.gc.GC_LEVEL_GUIDE
- local len = 0
- for k, v in ipairs(GuideExcel.lv_guide) do
- len = len + 1
- local net = msgRet.data[len]
- makeLvGuideNet(net, k, human)
- end
- msgRet.data[0] = len
- Msg.send(msgRet, human.fd)
- end
- --
- function stepLvFinish(human, id)
- local cf = GuideExcel.lv_guide[id]
- if not cf then
- if human.db.lvGuide and human.db.lvGuide[id] then
- human.db.lvGuide[id] = nil
- end
- return
- end
- human.db.lvGuide = human.db.lvGuide or {}
- human.db.lvGuide[id] = 1
- end
- --
- function stepLvInfo(human, id, guideId)
- if not Config.HAS_GUIDE then return end -- 指引总开关
- local diffTime = os.time() - human.db.createTime
- if diffTime >= 7 * 86400 and human.db.lv >= 5 then
- return
- end
-
- local cf = id and GuideExcel.lv_guide[id]
- if not cf then return end
- local msgRet = Msg.gc.GC_GUIDE_STEP
- msgRet.step[0] = 0
- local scf = GuideExcel.sub_guide[guideId]
- if scf then
- msgRet.step[0] = msgRet.step[0] + 1
- local net = msgRet.step[msgRet.step[0]]
- net.id = guideId
- net.conditions = Json.Encode(scf.conditions)
- net.behavior = Json.Encode(scf.behavior)
- net.sound = scf.sound
- net.dialog = scf.dialog
- net.content = scf.content
- net.handid = scf.handid
- net.zhiyin = scf.zhiyin
- net.heroLhID = scf.herolhId
- net.skip = scf.skip
-
- if scf.behavior[1] == "openPanel" and scf.behavior[2] and
- scf.behavior[2][1] == PanelDefine.PANEL_ID_52 then
- local dialog = scf.behavior[2][2]
- net.content = getContentByDialog(dialog)
- end
- end
-
- Msg.send(msgRet, human.fd)
- end
- -- 通用回调
- function onCallback(human)
- if not refreshGuide(human) then
- return
- end
- if getGuideState(human) ~= STATE_DOING then
- return
- end
- sendStep(human)
- return true
- end
- -- 临时 容错
- function checkAllFinish(human)
- if not Config.HAS_GUIDE then return 1 end
- -- local lastConfig = GuideExcel.main_guide[1200]
- -- local lastID = lastConfig.guideList[#lastConfig.guideList]
- -- local isFinish = isFinishGuideID(human, 1200)
- return isFinishGuideID(human, 1200) and 1 or 0
- end
|