GuideLogic.lua 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. ---------------------------------------------------------------
  2. -- 指引
  3. -- db.guide.id 指引id
  4. -- db.guide.step 步骤
  5. -- db.guide.state 状态
  6. -- db.guide.cmd2id cmd->id
  7. -- db.guide.flags 特殊指引标记,是否完成
  8. ---------------------------------------------------------------
  9. local Config = require("Config")
  10. Json = Json or require("common.Json")
  11. local GuideExcel = require("excel.guide")
  12. local Util = require("common.Util")
  13. local Log = require("common.Log")
  14. local Msg = require("core.Msg")
  15. local ObjHuman = require("core.ObjHuman")
  16. local Grid = require("bag.Grid")
  17. local BagLogic = require("bag.BagLogic")
  18. local ItemDefine = require("bag.ItemDefine")
  19. local BattleLogic = require("battle.BattleLogic")
  20. local LoginSignLogic = require("loginSign.LoginSignLogic")
  21. local PanelDefine = require("broadcast.PanelDefine")
  22. local SceneHandler = require("scene.Handler")
  23. local RoleExcel = require("excel.role")
  24. local CombatLogic = require("combat.CombatLogic")
  25. local HeroGrid = require("hero.HeroGrid")
  26. local HeroLogic = require("hero.HeroLogic")
  27. local CombatDefine = require("combat.CombatDefine")
  28. local CombatPosLogic = require("combat.CombatPosLogic")
  29. local RoleDefine = require("role.RoleDefine")
  30. local CombatExcel = require("excel.combat")
  31. local OpenActExcel = require("excel.openAct")
  32. local OpenAct = require("present.OpenAct")
  33. local CommonDB = require("common.CommonDB")
  34. local OpenServerGiftLogic = require("present.OpenServerGiftLogic")
  35. local MaiDianDefine = require("MaiDian.MaiDianDefine")
  36. local MainDianLogic = require("MaiDian.MaiDianLogic")
  37. local WeiLen = 30
  38. local GUIDECMD_LIST = {"battle"}
  39. local GUIDEID_FIRST = 0
  40. -- 指引中断处理方式
  41. SKIPTYPE_RESET = 0 -- 该指引重新从第一步开始
  42. SKIPTYPE_JUMP = 1 -- 该指引直接跳过
  43. SKIPTYPE_JUMP_NAME = 2 -- 改名跳过该指引
  44. SKIPTYPE_JUMP_DRAW = 3 -- 期间进行过高级抽奖,直接跳过
  45. SKIPTYPE_JUMP_HERO = 4 -- 期间获得过英雄,直接跳过
  46. SKIPTYPE_JUMP_HEROUP = 5 -- 英雄升级指定次数
  47. SKIPTYPE_JUMP_BATTLE_REWARD = 7 -- 战役通关奖励
  48. SKIPTYPE_JUMP_SHOPBUY = 8 -- 商店购买
  49. SKIPTYPE_JUMP_OL_REWARD = 9 -- 在线奖励
  50. SKIPTYPE_JUMP_LOGINSIGN = 10 -- 签到
  51. SKIPTYPE_JUMP_BATTLE_SD = 11 -- 战役扫荡
  52. SKIPTYPE_JUMP_BATTLE = 12 -- 战役
  53. SKIPTYPE_JUMP_BATTLE_EXP = 13 -- 是否领取经验
  54. SKIPTYPE_JUMP_LEVEL_GIFT = 14 -- 领取等级礼包
  55. SKIPTYPE_JUMP_OPEN_SERVER_GIFT = 15 -- 领取开服有礼礼包
  56. SKIPTYPE_JUMP_UPGRADE = 16 -- 英雄指定进阶次数
  57. SKIPTYPE_JUMP_JIBAN_GROUP = 17 -- 添加过羁绊组合
  58. SKIPTYPE_JUMP_JIEFENG_BAOJU = 18 -- 解封过宝具奖励
  59. SKIPTYPE_JUMP_BATTLE_GUAJI = 19 -- 领取过挂机奖励
  60. SKIPTYPE_JUMP_BARTASK = 20 -- 悬赏
  61. SKIPTYPE_JUMP_FINISH = 21 -- 直接全部跳过
  62. -- 状态
  63. STATE_DOING = 1 -- 进行中
  64. STATE_FINISH = 2 -- 完成
  65. GUIDE_COMBAT_INFO = GUIDE_COMBAT_INFO or { db = {} }
  66. -- 开服第8天 除了取名的指引 其余一律跳过
  67. local function initGuideHeroList()
  68. local combatConf = CombatExcel.gm[888888]
  69. if not combatConf then return end
  70. GUIDE_COMBAT_INFO.attacker = {}
  71. GUIDE_COMBAT_INFO.defender = {}
  72. GUIDE_COMBAT_INFO.atkFormation = combatConf.atkF
  73. GUIDE_COMBAT_INFO.defFormation = combatConf.defF
  74. local atkConf = nil
  75. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  76. atkConf = nil
  77. for k, v in ipairs(combatConf.atk) do
  78. if i == v[2] then
  79. atkConf = v
  80. break
  81. end
  82. end
  83. if atkConf then
  84. GUIDE_COMBAT_INFO.attacker[i] = CombatLogic.createHeroObj(GUIDE_COMBAT_INFO, atkConf[1], atkConf[3], atkConf[4], i)
  85. end
  86. atkConf = nil
  87. for k, v in ipairs(combatConf.def) do
  88. if i == v[2] then
  89. atkConf = v
  90. break
  91. end
  92. end
  93. if atkConf then
  94. GUIDE_COMBAT_INFO.defender[i] = CombatLogic.createHeroObj(GUIDE_COMBAT_INFO, atkConf[1], atkConf[3], atkConf[4], i)
  95. end
  96. end
  97. GUIDE_COMBAT_INFO.init = 1
  98. end
  99. function initAfterHot()
  100. if GUIDE_COMBAT_INFO.combat ~= nil then
  101. return
  102. end
  103. GuideExcel = require("excel.guide")
  104. -- 初始化剧情动画
  105. initGuideHeroList()
  106. if not GUIDE_COMBAT_INFO.init then return end
  107. CombatLogic.combatGuide(GUIDE_COMBAT_INFO, GUIDE_COMBAT_INFO.atkFormation, GUIDE_COMBAT_INFO.attacker,
  108. GUIDE_COMBAT_INFO.defFormation, GUIDE_COMBAT_INFO.defender)
  109. end
  110. ------------------------------ data --------------------------------------
  111. -- 设置指引
  112. function setGuide(human, id, state, skipType)
  113. local cf = GuideExcel.main_guide[id]
  114. if not cf then return end
  115. human.db.guide = human.db.guide or {}
  116. local oldstate = human.db.guide.state
  117. local oldid = human.db.guide.id
  118. if (oldid == id) and (oldstate == state) then
  119. return -- 老的和新的一致
  120. end
  121. local guide = human.db.guide
  122. local oldcmdid = getGuideIDByCmd(human, cf.cmd)
  123. guide.id = id
  124. guide.state = state
  125. guide.step = 0
  126. guide.cmd2id = guide.cmd2id or {}
  127. guide.cmd2id[cf.cmd] = id
  128. guide.flags = nil
  129. if state == STATE_DOING then
  130. if oldcmdid < id then
  131. -- 触发指引给东西
  132. BagLogic.addItemList(human, cf.items, "guide")
  133. end
  134. end
  135. if state == STATE_FINISH then
  136. -- Log.write(Log.LOGID_OSS_GUIDE_MAIN, human.db._id, human.db.account, human.db.name, human.db.lv, human.db.ip,
  137. -- human.pf or "", human.appid, id, skipType or 0)
  138. Log.write(Log.LOGID_OSS_GUIDE_MAIN, human.db._id, human.db.newUniqueTag, human.db.name, human.db.lv, human.db.ip,
  139. human.pf or "", human.appid, id, skipType or 0)
  140. end
  141. end
  142. -- 获取id
  143. function getGuideID(human)
  144. if not human.db.guide then
  145. return
  146. end
  147. return human.db.guide.id
  148. end
  149. --
  150. function getGuideState(human)
  151. if not human.db.guide then
  152. return
  153. end
  154. return human.db.guide.state
  155. end
  156. function getGuideStep(human)
  157. if not human.db.guide then
  158. return 0
  159. end
  160. return human.db.guide.step or 0
  161. end
  162. function setGuideStep(human, step, sid)
  163. if not human.db.guide then
  164. return
  165. end
  166. human.db.guide.step = step
  167. if sid then
  168. --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)
  169. Log.write(Log.LOGID_OSS_GUIDE_SUB, human.db._id, human.db.newUniqueTag, human.db.name, human.db.lv, human.db.ip, human.pf or "", human.appid, sid)
  170. end
  171. end
  172. --
  173. function setLoginStep(human, id)
  174. human.guideLoginStep = nil
  175. local cf = GuideExcel.main_guide[id]
  176. if not cf then return end
  177. if #cf.loginList < 1 then return end
  178. human.guideLoginStep = {}
  179. for i, sid in ipairs(cf.loginList) do
  180. human.guideLoginStep[i] = sid
  181. end
  182. end
  183. function getLoginStep(human)
  184. if not human.guideLoginStep then
  185. return
  186. end
  187. return human.guideLoginStep[1]
  188. end
  189. function delLoginStep(human)
  190. if not human.guideLoginStep then return end
  191. for i = 1, #human.guideLoginStep do
  192. human.guideLoginStep[i] = human.guideLoginStep[i + 1]
  193. end
  194. if #human.guideLoginStep < 1 then
  195. human.guideLoginStep = nil
  196. end
  197. end
  198. -- 根据cmd获取id
  199. function getGuideIDByCmd(human, cmd)
  200. if not human.db.guide or
  201. not human.db.guide.cmd2id then
  202. return GUIDEID_FIRST
  203. end
  204. if not human.db.guide.cmd2id[cmd] then
  205. return GUIDEID_FIRST
  206. end
  207. return human.db.guide.cmd2id[cmd]
  208. end
  209. function isFinishGuideID(human, id)
  210. local cf = GuideExcel.main_guide[id]
  211. if not cf then return end
  212. local nowid = getGuideIDByCmd(human, cf.cmd)
  213. if nowid ~= id then
  214. return nowid > id
  215. end
  216. if getGuideID(human) == id then
  217. local state = getGuideState(human)
  218. return state == STATE_FINISH
  219. end
  220. return true
  221. end
  222. -- 获取当前类型 是否满足条件
  223. function getGuideSkip(human, skipType)
  224. local id = getGuideID(human)
  225. local state = getGuideState(human)
  226. if id and state == STATE_FINISH then
  227. return true
  228. end
  229. local cf = GuideExcel.main_guide[id]
  230. if not cf then return end
  231. if cf.skipType ~= skipType then return true end
  232. local isJump = nil
  233. if cf.skipType == SKIPTYPE_JUMP then
  234. isJump = true
  235. elseif cf.skipType == SKIPTYPE_JUMP_DRAW or
  236. cf.skipType == SKIPTYPE_JUMP_HERO or
  237. cf.skipType == SKIPTYPE_JUMP_SHOPBUY or
  238. cf.skipType == SKIPTYPE_JUMP_BATTLE or
  239. cf.skipType == SKIPTYPE_JUMP_JIEFENG_BAOJU or
  240. cf.skipType == SKIPTYPE_JUMP_BATTLE_GUAJI or
  241. cf.skipType == SKIPTYPE_JUMP_BATTLE_EXP or
  242. cf.skipType == SKIPTYPE_JUMP_BARTASK then
  243. if getDoSpecialGuide(human, cf.skipType) > 0 then
  244. isJump = true
  245. end
  246. elseif cf.skipType == SKIPTYPE_JUMP_NAME then
  247. if (human.db.changeNameCnt or 0) > 0 then
  248. isJump = true
  249. end
  250. elseif cf.skipType == SKIPTYPE_JUMP_HEROUP or
  251. cf.skipType == SKIPTYPE_JUMP_UPGRADE then
  252. if getDoSpecialGuide(human, cf.skipType) >= cf.skipArgs[1] then
  253. isJump = true
  254. end
  255. elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_REWARD then
  256. if BattleLogic.isGetReward(human, cf.skipArgs[1] or 1) then
  257. isJump = true
  258. end
  259. elseif cf.skipType == SKIPTYPE_JUMP_OL_REWARD then
  260. if (human.db.onlineReward and human.db.onlineReward.id or 1) > 1 then
  261. isJump = true
  262. end
  263. elseif cf.skipType == SKIPTYPE_JUMP_LOGINSIGN then
  264. if not LoginSignLogic.isRed(human) or getDoSpecialGuide(human, cf.skipType) > 0 then
  265. isJump = true
  266. end
  267. elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_SD then
  268. if (human.db.mopupDoCnt or 0) > 0 and getDoSpecialGuide(human, cf.skipType) > 0 then
  269. isJump = true
  270. end
  271. elseif cf.skipType == SKIPTYPE_JUMP_LEVEL_GIFT then
  272. if human.db.chongJi ~= nil then
  273. isJump = true
  274. end
  275. elseif cf.skipType == SKIPTYPE_JUMP_OPEN_SERVER_GIFT then
  276. local len = #OpenActExcel.openServerGift
  277. for i = 1,len do
  278. local state = OpenServerGiftLogic.getGiftState(human, i)
  279. if state ~= 1 and state ~= 0 then
  280. isJump = true
  281. break
  282. end
  283. end
  284. elseif cf.skipType == SKIPTYPE_JUMP_JIBAN_GROUP then
  285. for i = 1,CombatDefine.COMBAT_TYPE_MAX do
  286. local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,i)
  287. if combatHeroDB and combatHeroDB.jiban then
  288. isJump = true
  289. break
  290. end
  291. end
  292. end
  293. return isJump
  294. end
  295. -- 是否触发过该特殊指引
  296. function getDoSpecialGuide(human, id)
  297. if not human.db.guide or
  298. not human.db.guide.flags then
  299. return 0
  300. end
  301. return human.db.guide.flags[id] or 0
  302. end
  303. -- 设置已触发
  304. function setDoSpecialGuide(human, id)
  305. human.db.guide = human.db.guide or {}
  306. human.db.guide.flags = human.db.guide.flags or {}
  307. local cnt = human.db.guide.flags[id] or 0
  308. human.db.guide.flags[id] = cnt + 1
  309. end
  310. -- 刷新指引状态
  311. function refreshGuide(human, isLogin)
  312. local id = getGuideID(human)
  313. local state = getGuideState(human)
  314. if id and state ~= STATE_FINISH then
  315. local conf = GuideExcel.main_guide[id]
  316. if not conf then
  317. assert(nil, " GuideExcel conf not have id : ".. id)
  318. end
  319. if conf.cmd == GUIDECMD_LIST[1] and conf.skipType == SKIPTYPE_JUMP_FINISH and isLogin then
  320. -- 完成此任务
  321. setGuide(human, id, STATE_FINISH, conf.skipType)
  322. while true do
  323. local pid = getGuideIDByCmd(human, GUIDECMD_LIST[1])
  324. if pid == GUIDEID_FIRST then
  325. break
  326. end
  327. local nid = getNextGuideID(pid, GUIDECMD_LIST[1])
  328. local cf = GuideExcel.main_guide[nid]
  329. if nid and cf and cf.cmd == GUIDECMD_LIST[1] then
  330. setGuide(human, nid, STATE_FINISH, cf.skipType)
  331. else
  332. break
  333. end
  334. end
  335. end
  336. return
  337. end
  338. local doSkip = false
  339. local fid = nil
  340. for _, cmd in ipairs(GUIDECMD_LIST) do
  341. local cond, skip, nid = nil
  342. while true do
  343. local pid = getGuideIDByCmd(human, cmd)
  344. nid = getNextGuideID(pid, cmd)
  345. cond = checkCondition(human, nid)
  346. local cf = GuideExcel.main_guide[nid]
  347. if nid and cf and cf.cmd == "lv" then
  348. -- 不重登的情况下 必须达成等级需求才跳过 没有开启活动
  349. local isSkip = false
  350. if cf.args[2] == 1 and not isLogin and human.db.lv >= cf.args[1] and not cond then
  351. setGuide(human, nid, STATE_FINISH, cf.skipType)
  352. isSkip = true
  353. end
  354. -- 重登的情况下 直接跳过
  355. if isLogin and human.db.lv >= cf.args[1] then
  356. setGuide(human, nid, STATE_FINISH, cf.skipType)
  357. isSkip = true
  358. end
  359. if not isSkip then break end
  360. else
  361. break
  362. end
  363. end
  364. if nid and cond then
  365. fid = nid
  366. break
  367. end
  368. end
  369. if (not fid) or (fid == id) then return end
  370. setGuide(human, fid, STATE_DOING)
  371. return true
  372. end
  373. -- 指引跳过/还原处理
  374. function skipGuide(human)
  375. local id = getGuideID(human)
  376. local state = getGuideState(human)
  377. if id and state == STATE_FINISH then
  378. return
  379. end
  380. local cf = GuideExcel.main_guide[id]
  381. if not cf then return end
  382. local isJump = nil
  383. if cf.skipType == SKIPTYPE_JUMP or
  384. cf.skipType == SKIPTYPE_JUMP_BARTASK then
  385. isJump = true
  386. elseif cf.skipType == SKIPTYPE_JUMP_DRAW or
  387. cf.skipType == SKIPTYPE_JUMP_HERO or
  388. cf.skipType == SKIPTYPE_JUMP_SHOPBUY or
  389. cf.skipType == SKIPTYPE_JUMP_BATTLE or
  390. cf.skipType == SKIPTYPE_JUMP_JIEFENG_BAOJU or
  391. cf.skipType == SKIPTYPE_JUMP_BATTLE_GUAJI or
  392. cf.skipType == SKIPTYPE_JUMP_BATTLE_EXP then
  393. if getDoSpecialGuide(human, cf.skipType) > 0 then
  394. isJump = true
  395. end
  396. elseif cf.skipType == SKIPTYPE_JUMP_NAME then
  397. if human.db.changeNameCnt ~= nil then
  398. isJump = true
  399. end
  400. elseif cf.skipType == SKIPTYPE_JUMP_HEROUP or
  401. cf.skipType == SKIPTYPE_JUMP_UPGRADE then
  402. if getDoSpecialGuide(human, cf.skipType) >= cf.skipArgs[1] then
  403. isJump = true
  404. end
  405. elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_REWARD then
  406. if BattleLogic.isGetReward(human, cf.skipArgs[1] or 1) then
  407. isJump = true
  408. end
  409. elseif cf.skipType == SKIPTYPE_JUMP_OL_REWARD then
  410. if (human.db.onlineReward and human.db.onlineReward.id or 1) > 1 then
  411. isJump = true
  412. end
  413. elseif cf.skipType == SKIPTYPE_JUMP_LOGINSIGN then
  414. if not LoginSignLogic.isRed(human) or getDoSpecialGuide(human, cf.skipType) > 0 then
  415. isJump = true
  416. end
  417. elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_SD then
  418. if (human.db.mopupDoCnt or 0) > 0 and getDoSpecialGuide(human, cf.skipType) > 0 then
  419. isJump = true
  420. end
  421. elseif cf.skipType == SKIPTYPE_JUMP_LEVEL_GIFT then
  422. if human.db.chongJi ~= nil then
  423. isJump = true
  424. end
  425. elseif cf.skipType == SKIPTYPE_JUMP_OPEN_SERVER_GIFT then
  426. local len = #OpenActExcel.openServerGift
  427. for i = 1,len do
  428. local state = OpenServerGiftLogic.getGiftState(human, i)
  429. if state ~= 1 and state ~= 0 then
  430. isJump = true
  431. break
  432. end
  433. end
  434. elseif cf.skipType == SKIPTYPE_JUMP_JIBAN_GROUP then
  435. for i = 1,CombatDefine.COMBAT_TYPE_MAX do
  436. local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,i)
  437. if combatHeroDB and combatHeroDB.jiban then
  438. isJump = true
  439. break
  440. end
  441. end
  442. end
  443. if isJump then
  444. --跳过所有战斗
  445. for i = CombatDefine.COMBAT_TYPE1, CombatDefine.COMBAT_TYPE_MAX do
  446. CombatLogic.clientFinish(human, i, true)
  447. end
  448. return setGuide(human, id, STATE_FINISH, cf.skipType)
  449. end
  450. setGuideStep(human, nil)
  451. end
  452. ---------------------------- condition -----------------------------------
  453. GuideCondition = {}
  454. GuideCondition["lv"] = function(human, lv, checkAct)
  455. if not SceneHandler.canCharge(human) then
  456. return -- 如果不能充值,所有等级指引都不开
  457. end
  458. if checkAct and checkAct == 1 then
  459. if human.db.lv >= lv then
  460. for k, v in ipairs(OpenActExcel.openAct) do
  461. local flag = OpenAct.getOpenActTime(k)
  462. if flag == true then
  463. return true
  464. end
  465. end
  466. end
  467. else
  468. return human.db.lv >= lv
  469. end
  470. return false
  471. end
  472. -- 完成指定战役
  473. GuideCondition["battle"] = function(human, id)
  474. return (human.db.battleID or 1) > id
  475. end
  476. function checkCondition(human, id)
  477. local cf = GuideExcel.main_guide[id]
  478. if not cf then return end
  479. if cf.cmd == "" then return true end
  480. local func = GuideCondition[cf.cmd]
  481. if not func then return end
  482. return func(human, cf.args[1], cf.args[2])
  483. end
  484. ------------------------------ excel --------------------------------------
  485. -- 获取下一个指引id
  486. local GUIDEID_2_NEXTID = nil -- [cmd][preid] = nextid
  487. function getNextGuideID(id, cmd)
  488. if not GUIDEID_2_NEXTID then
  489. GUIDEID_2_NEXTID = {}
  490. local sids = {}
  491. for tid, cf in Util.pairsByKeys(GuideExcel.main_guide) do
  492. if #cf.guideList > 0 then
  493. local sid = sids[cf.cmd] or GUIDEID_FIRST
  494. GUIDEID_2_NEXTID[cf.cmd] = GUIDEID_2_NEXTID[cf.cmd] or {}
  495. GUIDEID_2_NEXTID[cf.cmd][sid] = tid
  496. sids[cf.cmd] = tid
  497. end
  498. end
  499. end
  500. if not GUIDEID_2_NEXTID[cmd] then
  501. return
  502. end
  503. return GUIDEID_2_NEXTID[cmd][id]
  504. end
  505. local SID_2_GUIDEID = nil
  506. local SID_2_GUIDESTEP = nil
  507. function getGuideIDBySid(sid)
  508. if not SID_2_GUIDEID then
  509. SID_2_GUIDEID = {}
  510. SID_2_GUIDESTEP = {}
  511. for id, cf in pairs(GuideExcel.main_guide) do
  512. for step, tsid in ipairs(cf.guideList) do
  513. SID_2_GUIDEID[tsid] = id
  514. SID_2_GUIDESTEP[tsid] = step
  515. end
  516. end
  517. end
  518. return SID_2_GUIDEID[sid], SID_2_GUIDESTEP[sid]
  519. end
  520. function getNextGuideIDByLv(lv)
  521. local minlv = nil
  522. local minid = nil
  523. for id, cf in pairs(GuideExcel.lv_guide) do
  524. if cf.cmd == "lv" and cf.dialog > 0 then
  525. local clv = cf.args[1]
  526. if clv > lv and (minlv == nil or clv < minlv) then
  527. minlv = clv
  528. minid = id
  529. end
  530. end
  531. end
  532. if not minid then return end
  533. return minid
  534. end
  535. local DIALOG_2_CONTENT = nil
  536. function getContentByDialog(dialog)
  537. if not dialog then return end
  538. if not DIALOG_2_CONTENT then
  539. DIALOG_2_CONTENT = {}
  540. for id, cf in pairs(GuideExcel.main_guide) do
  541. if cf.dialog > 0 then
  542. DIALOG_2_CONTENT[cf.dialog] = cf.content
  543. end
  544. end
  545. end
  546. return DIALOG_2_CONTENT[dialog]
  547. end
  548. local function getLvUpGetZuanshi(oldLv,newLv)
  549. local addZuanshi = 0
  550. for lv=1,#RoleExcel.exp do
  551. if lv > oldLv and lv <= newLv then
  552. addZuanshi = addZuanshi + RoleExcel.exp[lv].lvUpGetZuanshi
  553. end
  554. end
  555. return addZuanshi
  556. end
  557. ------------------------------- msg -------------------------------------
  558. function sendStep(human, sendNil)
  559. if not Config.HAS_GUIDE then return end -- 指引总开关
  560. local diffTime = os.time() - human.db.createTime
  561. if diffTime >= 7 * 86400 and human.db.lv >= 5 then
  562. return
  563. end
  564. if human.db.noguide and not sendNil then return end
  565. local id = (not sendNil) and getGuideID(human)
  566. local cf = id and GuideExcel.main_guide[id]
  567. local nextstep = getGuideStep(human) + 1
  568. local state = getGuideState(human)
  569. local msgRet = Msg.gc.GC_GUIDE_STEP
  570. msgRet.step[0] = 0
  571. if cf and state == STATE_DOING then
  572. local sid = getLoginStep(human) or cf.guideList[nextstep]
  573. local scf = sid and GuideExcel.sub_guide[sid]
  574. if scf then
  575. msgRet.step[0] = msgRet.step[0] + 1
  576. local net = msgRet.step[msgRet.step[0]]
  577. net.id = sid
  578. net.conditions = Json.Encode(scf.conditions)
  579. net.behavior = Json.Encode(scf.behavior)
  580. net.sound = scf.sound
  581. net.dialog = scf.dialog
  582. net.content = scf.content
  583. net.handid = scf.handid
  584. net.zhiyin = scf.zhiyin
  585. net.heroLhID = scf.herolhId
  586. net.skip = scf.skip
  587. if scf.behavior[1] == "openPanel" and scf.behavior[2] and
  588. scf.behavior[2][1] == PanelDefine.PANEL_ID_52 then
  589. local dialog = scf.behavior[2][2]
  590. net.content = getContentByDialog(dialog)
  591. end
  592. if scf.behavior[1] == "showAnima" and GUIDE_COMBAT_INFO.combat ~= nil then
  593. CombatLogic.sendCombatData(human, GUIDE_COMBAT_INFO.combat)
  594. end
  595. end
  596. end
  597. --Msg.trace(msgRet)
  598. Msg.send(msgRet, human.fd)
  599. end
  600. -- 能否下一步
  601. function canStepFinish(human, sid)
  602. local state = getGuideState(human)
  603. if state ~= STATE_DOING then return end
  604. if getLoginStep(human) == sid then -- 登录步骤
  605. delLoginStep(human)
  606. return true, getGuideID(human), 0
  607. end
  608. local id, step = getGuideIDBySid(sid)
  609. if not id then return end
  610. if getGuideID(human) ~= id then return end
  611. if sid >= 503 and sid <= 506 then
  612. local config = GuideExcel.main_guide[id]
  613. local oldStep = getGuideStep(human)
  614. local oldSid = config.guideList[oldStep]
  615. if oldSid < 502 or oldSid > 506 then
  616. return
  617. end
  618. -- if oldStep <
  619. else
  620. if getGuideStep(human) + 1 ~= step then return end
  621. end
  622. local cf = GuideExcel.main_guide[id]
  623. -- 升级次数
  624. if cf.skipType == SKIPTYPE_JUMP_HEROUP and cf.skipArgs[2] == sid then
  625. if getDoSpecialGuide(human, SKIPTYPE_JUMP_HEROUP) < cf.skipArgs[1] then
  626. return
  627. end
  628. end
  629. -- 进阶次数判定
  630. if cf.skipType == SKIPTYPE_JUMP_UPGRADE and cf.skipArgs[2] == sid then
  631. if getDoSpecialGuide(human, SKIPTYPE_JUMP_UPGRADE) < cf.skipArgs[1] then
  632. return
  633. end
  634. end
  635. return true, id, step
  636. end
  637. function stepFinish(human, sid, noSend)
  638. local isok, id, step = canStepFinish(human, sid)
  639. if isok then
  640. local cf = GuideExcel.main_guide[id]
  641. if step >= #cf.guideList then
  642. setGuide(human, id, STATE_FINISH)
  643. else
  644. setGuideStep(human, step, sid)
  645. MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_GUIDE, {nValue = sid})
  646. end
  647. end
  648. refreshGuide(human)
  649. sendStep(human)
  650. end
  651. -- 登录回调
  652. function onLogin(human)
  653. skipGuide(human)
  654. refreshGuide(human, true)
  655. if getGuideState(human) == STATE_DOING then
  656. setLoginStep(human, getGuideID(human))
  657. sendStep(human)
  658. end
  659. sendLvGuide(human)
  660. end
  661. -- 升级回调
  662. function onLvUpCB(human, oldLv, newLv)
  663. local giveZuanshi = getLvUpGetZuanshi(oldLv,newLv)
  664. if giveZuanshi > 0 then
  665. ObjHuman.addZuanshi(human, giveZuanshi, "level_up")
  666. end
  667. local id = getNextGuideIDByLv(newLv)
  668. local cf = id and GuideExcel.lv_guide[id]
  669. local msgRet = Msg.gc.GC_LEVEL_UP
  670. local net = msgRet.data
  671. net.oldLv = oldLv
  672. net.newLv = newLv
  673. net.items[0] = 0
  674. if giveZuanshi > 0 then
  675. net.items[0] = net.items[0] + 1
  676. Grid.makeItem(net.items[net.items[0]], ItemDefine.ITEM_ZUANSHI_ID, giveZuanshi)
  677. end
  678. net.dialog = cf and cf.dialog or 0
  679. net.dialogName = cf and cf.dialogName or ""
  680. net.content = cf and cf.content or ""
  681. net.noticeLv = cf and cf.args[1] or 0
  682. net.panelId = cf and cf.panelId or 0
  683. Msg.send(msgRet, human.fd)
  684. end
  685. -- 等级指引
  686. local function makeLvGuideNet(net, id, human)
  687. local cf = GuideExcel.lv_guide[id]
  688. net.id = id
  689. net.noticeLv = cf and cf.args[1] or 0
  690. net.panelId = cf and cf.panelId or 0
  691. net.status = human.db.lvGuide and human.db.lvGuide[id] or 0
  692. local len = 0
  693. for k, v in ipairs(cf.guideList) do
  694. len = len + 1
  695. net.guideList[len] = v
  696. end
  697. net.guideList[0] = len
  698. end
  699. --推送等级指引
  700. function sendLvGuide(human)
  701. local msgRet = Msg.gc.GC_LEVEL_GUIDE
  702. local len = 0
  703. for k, v in ipairs(GuideExcel.lv_guide) do
  704. len = len + 1
  705. local net = msgRet.data[len]
  706. makeLvGuideNet(net, k, human)
  707. end
  708. msgRet.data[0] = len
  709. Msg.send(msgRet, human.fd)
  710. end
  711. --
  712. function stepLvFinish(human, id)
  713. local cf = GuideExcel.lv_guide[id]
  714. if not cf then
  715. if human.db.lvGuide and human.db.lvGuide[id] then
  716. human.db.lvGuide[id] = nil
  717. end
  718. return
  719. end
  720. human.db.lvGuide = human.db.lvGuide or {}
  721. human.db.lvGuide[id] = 1
  722. end
  723. --
  724. function stepLvInfo(human, id, guideId)
  725. if not Config.HAS_GUIDE then return end -- 指引总开关
  726. local diffTime = os.time() - human.db.createTime
  727. if diffTime >= 7 * 86400 and human.db.lv >= 5 then
  728. return
  729. end
  730. local cf = id and GuideExcel.lv_guide[id]
  731. if not cf then return end
  732. local msgRet = Msg.gc.GC_GUIDE_STEP
  733. msgRet.step[0] = 0
  734. local scf = GuideExcel.sub_guide[guideId]
  735. if scf then
  736. msgRet.step[0] = msgRet.step[0] + 1
  737. local net = msgRet.step[msgRet.step[0]]
  738. net.id = guideId
  739. net.conditions = Json.Encode(scf.conditions)
  740. net.behavior = Json.Encode(scf.behavior)
  741. net.sound = scf.sound
  742. net.dialog = scf.dialog
  743. net.content = scf.content
  744. net.handid = scf.handid
  745. net.zhiyin = scf.zhiyin
  746. net.heroLhID = scf.herolhId
  747. net.skip = scf.skip
  748. if scf.behavior[1] == "openPanel" and scf.behavior[2] and
  749. scf.behavior[2][1] == PanelDefine.PANEL_ID_52 then
  750. local dialog = scf.behavior[2][2]
  751. net.content = getContentByDialog(dialog)
  752. end
  753. end
  754. Msg.send(msgRet, human.fd)
  755. end
  756. -- 通用回调
  757. function onCallback(human)
  758. if not refreshGuide(human) then
  759. return
  760. end
  761. if getGuideState(human) ~= STATE_DOING then
  762. return
  763. end
  764. sendStep(human)
  765. return true
  766. end
  767. -- 临时 容错
  768. function checkAllFinish(human)
  769. if not Config.HAS_GUIDE then return 1 end
  770. -- local lastConfig = GuideExcel.main_guide[1200]
  771. -- local lastID = lastConfig.guideList[#lastConfig.guideList]
  772. -- local isFinish = isFinishGuideID(human, 1200)
  773. return isFinishGuideID(human, 1200) and 1 or 0
  774. end