GuideLogic.lua 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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. end
  139. end
  140. -- 获取id
  141. function getGuideID(human)
  142. if not human.db.guide then
  143. return
  144. end
  145. return human.db.guide.id
  146. end
  147. --
  148. function getGuideState(human)
  149. if not human.db.guide then
  150. return
  151. end
  152. return human.db.guide.state
  153. end
  154. function getGuideStep(human)
  155. if not human.db.guide then
  156. return 0
  157. end
  158. return human.db.guide.step or 0
  159. end
  160. function setGuideStep(human, step, sid)
  161. if not human.db.guide then
  162. return
  163. end
  164. human.db.guide.step = step
  165. if sid then
  166. 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)
  167. end
  168. end
  169. --
  170. function setLoginStep(human, id)
  171. human.guideLoginStep = nil
  172. local cf = GuideExcel.main_guide[id]
  173. if not cf then return end
  174. if #cf.loginList < 1 then return end
  175. human.guideLoginStep = {}
  176. for i, sid in ipairs(cf.loginList) do
  177. human.guideLoginStep[i] = sid
  178. end
  179. end
  180. function getLoginStep(human)
  181. if not human.guideLoginStep then
  182. return
  183. end
  184. return human.guideLoginStep[1]
  185. end
  186. function delLoginStep(human)
  187. if not human.guideLoginStep then return end
  188. for i = 1, #human.guideLoginStep do
  189. human.guideLoginStep[i] = human.guideLoginStep[i + 1]
  190. end
  191. if #human.guideLoginStep < 1 then
  192. human.guideLoginStep = nil
  193. end
  194. end
  195. -- 根据cmd获取id
  196. function getGuideIDByCmd(human, cmd)
  197. if not human.db.guide or
  198. not human.db.guide.cmd2id then
  199. return GUIDEID_FIRST
  200. end
  201. if not human.db.guide.cmd2id[cmd] then
  202. return GUIDEID_FIRST
  203. end
  204. return human.db.guide.cmd2id[cmd]
  205. end
  206. function isFinishGuideID(human, id)
  207. local cf = GuideExcel.main_guide[id]
  208. if not cf then return end
  209. local nowid = getGuideIDByCmd(human, cf.cmd)
  210. if nowid ~= id then
  211. return nowid > id
  212. end
  213. if getGuideID(human) == id then
  214. local state = getGuideState(human)
  215. return state == STATE_FINISH
  216. end
  217. return true
  218. end
  219. -- 获取当前类型 是否满足条件
  220. function getGuideSkip(human, skipType)
  221. local id = getGuideID(human)
  222. local state = getGuideState(human)
  223. if id and state == STATE_FINISH then
  224. return true
  225. end
  226. local cf = GuideExcel.main_guide[id]
  227. if not cf then return end
  228. if cf.skipType ~= skipType then return true end
  229. local isJump = nil
  230. if cf.skipType == SKIPTYPE_JUMP then
  231. isJump = true
  232. elseif cf.skipType == SKIPTYPE_JUMP_DRAW or
  233. cf.skipType == SKIPTYPE_JUMP_HERO or
  234. cf.skipType == SKIPTYPE_JUMP_SHOPBUY or
  235. cf.skipType == SKIPTYPE_JUMP_BATTLE or
  236. cf.skipType == SKIPTYPE_JUMP_JIEFENG_BAOJU or
  237. cf.skipType == SKIPTYPE_JUMP_BATTLE_GUAJI or
  238. cf.skipType == SKIPTYPE_JUMP_BATTLE_EXP or
  239. cf.skipType == SKIPTYPE_JUMP_BARTASK then
  240. if getDoSpecialGuide(human, cf.skipType) > 0 then
  241. isJump = true
  242. end
  243. elseif cf.skipType == SKIPTYPE_JUMP_NAME then
  244. if (human.db.changeNameCnt or 0) > 0 then
  245. isJump = true
  246. end
  247. elseif cf.skipType == SKIPTYPE_JUMP_HEROUP or
  248. cf.skipType == SKIPTYPE_JUMP_UPGRADE then
  249. if getDoSpecialGuide(human, cf.skipType) >= cf.skipArgs[1] then
  250. isJump = true
  251. end
  252. elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_REWARD then
  253. if BattleLogic.isGetReward(human, cf.skipArgs[1] or 1) then
  254. isJump = true
  255. end
  256. elseif cf.skipType == SKIPTYPE_JUMP_OL_REWARD then
  257. if (human.db.onlineReward and human.db.onlineReward.id or 1) > 1 then
  258. isJump = true
  259. end
  260. elseif cf.skipType == SKIPTYPE_JUMP_LOGINSIGN then
  261. if not LoginSignLogic.isRed(human) or getDoSpecialGuide(human, cf.skipType) > 0 then
  262. isJump = true
  263. end
  264. elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_SD then
  265. if (human.db.mopupDoCnt or 0) > 0 and getDoSpecialGuide(human, cf.skipType) > 0 then
  266. isJump = true
  267. end
  268. elseif cf.skipType == SKIPTYPE_JUMP_LEVEL_GIFT then
  269. if human.db.chongJi ~= nil then
  270. isJump = true
  271. end
  272. elseif cf.skipType == SKIPTYPE_JUMP_OPEN_SERVER_GIFT then
  273. local len = #OpenActExcel.openServerGift
  274. for i = 1,len do
  275. local state = OpenServerGiftLogic.getGiftState(human, i)
  276. if state ~= 1 and state ~= 0 then
  277. isJump = true
  278. break
  279. end
  280. end
  281. elseif cf.skipType == SKIPTYPE_JUMP_JIBAN_GROUP then
  282. for i = 1,CombatDefine.COMBAT_TYPE_MAX do
  283. local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,i)
  284. if combatHeroDB and combatHeroDB.jiban then
  285. isJump = true
  286. break
  287. end
  288. end
  289. end
  290. return isJump
  291. end
  292. -- 是否触发过该特殊指引
  293. function getDoSpecialGuide(human, id)
  294. if not human.db.guide or
  295. not human.db.guide.flags then
  296. return 0
  297. end
  298. return human.db.guide.flags[id] or 0
  299. end
  300. -- 设置已触发
  301. function setDoSpecialGuide(human, id)
  302. human.db.guide = human.db.guide or {}
  303. human.db.guide.flags = human.db.guide.flags or {}
  304. local cnt = human.db.guide.flags[id] or 0
  305. human.db.guide.flags[id] = cnt + 1
  306. end
  307. -- 刷新指引状态
  308. function refreshGuide(human, isLogin)
  309. local id = getGuideID(human)
  310. local state = getGuideState(human)
  311. if id and state ~= STATE_FINISH then
  312. local conf = GuideExcel.main_guide[id]
  313. if not conf then
  314. assert(nil, " GuideExcel conf not have id : ".. id)
  315. end
  316. if conf.cmd == GUIDECMD_LIST[1] and conf.skipType == SKIPTYPE_JUMP_FINISH and isLogin then
  317. -- 完成此任务
  318. setGuide(human, id, STATE_FINISH, conf.skipType)
  319. while true do
  320. local pid = getGuideIDByCmd(human, GUIDECMD_LIST[1])
  321. if pid == GUIDEID_FIRST then
  322. break
  323. end
  324. local nid = getNextGuideID(pid, GUIDECMD_LIST[1])
  325. local cf = GuideExcel.main_guide[nid]
  326. if nid and cf and cf.cmd == GUIDECMD_LIST[1] then
  327. setGuide(human, nid, STATE_FINISH, cf.skipType)
  328. else
  329. break
  330. end
  331. end
  332. end
  333. return
  334. end
  335. local doSkip = false
  336. local fid = nil
  337. for _, cmd in ipairs(GUIDECMD_LIST) do
  338. local cond, skip, nid = nil
  339. while true do
  340. local pid = getGuideIDByCmd(human, cmd)
  341. nid = getNextGuideID(pid, cmd)
  342. cond = checkCondition(human, nid)
  343. local cf = GuideExcel.main_guide[nid]
  344. if nid and cf and cf.cmd == "lv" then
  345. -- 不重登的情况下 必须达成等级需求才跳过 没有开启活动
  346. local isSkip = false
  347. if cf.args[2] == 1 and not isLogin and human.db.lv >= cf.args[1] and not cond then
  348. setGuide(human, nid, STATE_FINISH, cf.skipType)
  349. isSkip = true
  350. end
  351. -- 重登的情况下 直接跳过
  352. if isLogin and human.db.lv >= cf.args[1] then
  353. setGuide(human, nid, STATE_FINISH, cf.skipType)
  354. isSkip = true
  355. end
  356. if not isSkip then break end
  357. else
  358. break
  359. end
  360. end
  361. if nid and cond then
  362. fid = nid
  363. break
  364. end
  365. end
  366. if (not fid) or (fid == id) then return end
  367. setGuide(human, fid, STATE_DOING)
  368. return true
  369. end
  370. -- 指引跳过/还原处理
  371. function skipGuide(human)
  372. local id = getGuideID(human)
  373. local state = getGuideState(human)
  374. if id and state == STATE_FINISH then
  375. return
  376. end
  377. local cf = GuideExcel.main_guide[id]
  378. if not cf then return end
  379. local isJump = nil
  380. if cf.skipType == SKIPTYPE_JUMP or
  381. cf.skipType == SKIPTYPE_JUMP_BARTASK then
  382. isJump = true
  383. elseif cf.skipType == SKIPTYPE_JUMP_DRAW or
  384. cf.skipType == SKIPTYPE_JUMP_HERO or
  385. cf.skipType == SKIPTYPE_JUMP_SHOPBUY or
  386. cf.skipType == SKIPTYPE_JUMP_BATTLE or
  387. cf.skipType == SKIPTYPE_JUMP_JIEFENG_BAOJU or
  388. cf.skipType == SKIPTYPE_JUMP_BATTLE_GUAJI or
  389. cf.skipType == SKIPTYPE_JUMP_BATTLE_EXP then
  390. if getDoSpecialGuide(human, cf.skipType) > 0 then
  391. isJump = true
  392. end
  393. elseif cf.skipType == SKIPTYPE_JUMP_NAME then
  394. if human.db.changeNameCnt ~= nil then
  395. isJump = true
  396. end
  397. elseif cf.skipType == SKIPTYPE_JUMP_HEROUP or
  398. cf.skipType == SKIPTYPE_JUMP_UPGRADE then
  399. if getDoSpecialGuide(human, cf.skipType) >= cf.skipArgs[1] then
  400. isJump = true
  401. end
  402. elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_REWARD then
  403. if BattleLogic.isGetReward(human, cf.skipArgs[1] or 1) then
  404. isJump = true
  405. end
  406. elseif cf.skipType == SKIPTYPE_JUMP_OL_REWARD then
  407. if (human.db.onlineReward and human.db.onlineReward.id or 1) > 1 then
  408. isJump = true
  409. end
  410. elseif cf.skipType == SKIPTYPE_JUMP_LOGINSIGN then
  411. if not LoginSignLogic.isRed(human) or getDoSpecialGuide(human, cf.skipType) > 0 then
  412. isJump = true
  413. end
  414. elseif cf.skipType == SKIPTYPE_JUMP_BATTLE_SD then
  415. if (human.db.mopupDoCnt or 0) > 0 and getDoSpecialGuide(human, cf.skipType) > 0 then
  416. isJump = true
  417. end
  418. elseif cf.skipType == SKIPTYPE_JUMP_LEVEL_GIFT then
  419. if human.db.chongJi ~= nil then
  420. isJump = true
  421. end
  422. elseif cf.skipType == SKIPTYPE_JUMP_OPEN_SERVER_GIFT then
  423. local len = #OpenActExcel.openServerGift
  424. for i = 1,len do
  425. local state = OpenServerGiftLogic.getGiftState(human, i)
  426. if state ~= 1 and state ~= 0 then
  427. isJump = true
  428. break
  429. end
  430. end
  431. elseif cf.skipType == SKIPTYPE_JUMP_JIBAN_GROUP then
  432. for i = 1,CombatDefine.COMBAT_TYPE_MAX do
  433. local combatHeroDB = CombatPosLogic.getCombatHeroDB(human,i)
  434. if combatHeroDB and combatHeroDB.jiban then
  435. isJump = true
  436. break
  437. end
  438. end
  439. end
  440. if isJump then
  441. --跳过所有战斗
  442. for i = CombatDefine.COMBAT_TYPE1, CombatDefine.COMBAT_TYPE_MAX do
  443. CombatLogic.clientFinish(human, i, true)
  444. end
  445. return setGuide(human, id, STATE_FINISH, cf.skipType)
  446. end
  447. setGuideStep(human, nil)
  448. end
  449. ---------------------------- condition -----------------------------------
  450. GuideCondition = {}
  451. GuideCondition["lv"] = function(human, lv, checkAct)
  452. if not SceneHandler.canCharge(human) then
  453. return -- 如果不能充值,所有等级指引都不开
  454. end
  455. if checkAct and checkAct == 1 then
  456. if human.db.lv >= lv then
  457. for k, v in ipairs(OpenActExcel.openAct) do
  458. local flag = OpenAct.getOpenActTime(k)
  459. if flag == true then
  460. return true
  461. end
  462. end
  463. end
  464. else
  465. return human.db.lv >= lv
  466. end
  467. return false
  468. end
  469. -- 完成指定战役
  470. GuideCondition["battle"] = function(human, id)
  471. return (human.db.battleID or 1) > id
  472. end
  473. function checkCondition(human, id)
  474. local cf = GuideExcel.main_guide[id]
  475. if not cf then return end
  476. if cf.cmd == "" then return true end
  477. local func = GuideCondition[cf.cmd]
  478. if not func then return end
  479. return func(human, cf.args[1], cf.args[2])
  480. end
  481. ------------------------------ excel --------------------------------------
  482. -- 获取下一个指引id
  483. local GUIDEID_2_NEXTID = nil -- [cmd][preid] = nextid
  484. function getNextGuideID(id, cmd)
  485. if not GUIDEID_2_NEXTID then
  486. GUIDEID_2_NEXTID = {}
  487. local sids = {}
  488. for tid, cf in Util.pairsByKeys(GuideExcel.main_guide) do
  489. if #cf.guideList > 0 then
  490. local sid = sids[cf.cmd] or GUIDEID_FIRST
  491. GUIDEID_2_NEXTID[cf.cmd] = GUIDEID_2_NEXTID[cf.cmd] or {}
  492. GUIDEID_2_NEXTID[cf.cmd][sid] = tid
  493. sids[cf.cmd] = tid
  494. end
  495. end
  496. end
  497. if not GUIDEID_2_NEXTID[cmd] then
  498. return
  499. end
  500. return GUIDEID_2_NEXTID[cmd][id]
  501. end
  502. local SID_2_GUIDEID = nil
  503. local SID_2_GUIDESTEP = nil
  504. function getGuideIDBySid(sid)
  505. if not SID_2_GUIDEID then
  506. SID_2_GUIDEID = {}
  507. SID_2_GUIDESTEP = {}
  508. for id, cf in pairs(GuideExcel.main_guide) do
  509. for step, tsid in ipairs(cf.guideList) do
  510. SID_2_GUIDEID[tsid] = id
  511. SID_2_GUIDESTEP[tsid] = step
  512. end
  513. end
  514. end
  515. return SID_2_GUIDEID[sid], SID_2_GUIDESTEP[sid]
  516. end
  517. function getNextGuideIDByLv(lv)
  518. local minlv = nil
  519. local minid = nil
  520. for id, cf in pairs(GuideExcel.lv_guide) do
  521. if cf.cmd == "lv" and cf.dialog > 0 then
  522. local clv = cf.args[1]
  523. if clv > lv and (minlv == nil or clv < minlv) then
  524. minlv = clv
  525. minid = id
  526. end
  527. end
  528. end
  529. if not minid then return end
  530. return minid
  531. end
  532. local DIALOG_2_CONTENT = nil
  533. function getContentByDialog(dialog)
  534. if not dialog then return end
  535. if not DIALOG_2_CONTENT then
  536. DIALOG_2_CONTENT = {}
  537. for id, cf in pairs(GuideExcel.main_guide) do
  538. if cf.dialog > 0 then
  539. DIALOG_2_CONTENT[cf.dialog] = cf.content
  540. end
  541. end
  542. end
  543. return DIALOG_2_CONTENT[dialog]
  544. end
  545. local function getLvUpGetZuanshi(oldLv,newLv)
  546. local addZuanshi = 0
  547. for lv=1,#RoleExcel.exp do
  548. if lv > oldLv and lv <= newLv then
  549. addZuanshi = addZuanshi + RoleExcel.exp[lv].lvUpGetZuanshi
  550. end
  551. end
  552. return addZuanshi
  553. end
  554. ------------------------------- msg -------------------------------------
  555. function sendStep(human, sendNil)
  556. if not Config.HAS_GUIDE then return end -- 指引总开关
  557. local diffTime = os.time() - human.db.createTime
  558. if diffTime >= 7 * 86400 and human.db.lv >= 5 then
  559. return
  560. end
  561. if human.db.noguide and not sendNil then return end
  562. local id = (not sendNil) and getGuideID(human)
  563. local cf = id and GuideExcel.main_guide[id]
  564. local nextstep = getGuideStep(human) + 1
  565. local state = getGuideState(human)
  566. local msgRet = Msg.gc.GC_GUIDE_STEP
  567. msgRet.step[0] = 0
  568. if cf and state == STATE_DOING then
  569. local sid = getLoginStep(human) or cf.guideList[nextstep]
  570. local scf = sid and GuideExcel.sub_guide[sid]
  571. if scf then
  572. msgRet.step[0] = msgRet.step[0] + 1
  573. local net = msgRet.step[msgRet.step[0]]
  574. net.id = sid
  575. net.conditions = Json.Encode(scf.conditions)
  576. net.behavior = Json.Encode(scf.behavior)
  577. net.sound = scf.sound
  578. net.dialog = scf.dialog
  579. net.content = scf.content
  580. net.handid = scf.handid
  581. net.zhiyin = scf.zhiyin
  582. net.heroLhID = scf.herolhId
  583. net.skip = scf.skip
  584. if scf.behavior[1] == "openPanel" and scf.behavior[2] and
  585. scf.behavior[2][1] == PanelDefine.PANEL_ID_52 then
  586. local dialog = scf.behavior[2][2]
  587. net.content = getContentByDialog(dialog)
  588. end
  589. if scf.behavior[1] == "showAnima" and GUIDE_COMBAT_INFO.combat ~= nil then
  590. CombatLogic.sendCombatData(human, GUIDE_COMBAT_INFO.combat)
  591. end
  592. end
  593. end
  594. --Msg.trace(msgRet)
  595. Msg.send(msgRet, human.fd)
  596. end
  597. -- 能否下一步
  598. function canStepFinish(human, sid)
  599. local state = getGuideState(human)
  600. if state ~= STATE_DOING then return end
  601. if getLoginStep(human) == sid then -- 登录步骤
  602. delLoginStep(human)
  603. return true, getGuideID(human), 0
  604. end
  605. local id, step = getGuideIDBySid(sid)
  606. if not id then return end
  607. if getGuideID(human) ~= id then return end
  608. if sid >= 503 and sid <= 506 then
  609. local config = GuideExcel.main_guide[id]
  610. local oldStep = getGuideStep(human)
  611. local oldSid = config.guideList[oldStep]
  612. if oldSid < 502 or oldSid > 506 then
  613. return
  614. end
  615. -- if oldStep <
  616. else
  617. if getGuideStep(human) + 1 ~= step then return end
  618. end
  619. local cf = GuideExcel.main_guide[id]
  620. -- 升级次数
  621. if cf.skipType == SKIPTYPE_JUMP_HEROUP and cf.skipArgs[2] == sid then
  622. if getDoSpecialGuide(human, SKIPTYPE_JUMP_HEROUP) < cf.skipArgs[1] then
  623. return
  624. end
  625. end
  626. -- 进阶次数判定
  627. if cf.skipType == SKIPTYPE_JUMP_UPGRADE and cf.skipArgs[2] == sid then
  628. if getDoSpecialGuide(human, SKIPTYPE_JUMP_UPGRADE) < cf.skipArgs[1] then
  629. return
  630. end
  631. end
  632. return true, id, step
  633. end
  634. function stepFinish(human, sid, noSend)
  635. local isok, id, step = canStepFinish(human, sid)
  636. if isok then
  637. local cf = GuideExcel.main_guide[id]
  638. if step >= #cf.guideList then
  639. setGuide(human, id, STATE_FINISH)
  640. else
  641. setGuideStep(human, step, sid)
  642. MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_GUIDE, {nValue = sid})
  643. end
  644. end
  645. refreshGuide(human)
  646. sendStep(human)
  647. end
  648. -- 登录回调
  649. function onLogin(human)
  650. skipGuide(human)
  651. refreshGuide(human, true)
  652. if getGuideState(human) == STATE_DOING then
  653. setLoginStep(human, getGuideID(human))
  654. sendStep(human)
  655. end
  656. sendLvGuide(human)
  657. end
  658. -- 升级回调
  659. function onLvUpCB(human, oldLv, newLv)
  660. local giveZuanshi = getLvUpGetZuanshi(oldLv,newLv)
  661. if giveZuanshi > 0 then
  662. ObjHuman.addZuanshi(human, giveZuanshi, "level_up")
  663. end
  664. local id = getNextGuideIDByLv(newLv)
  665. local cf = id and GuideExcel.lv_guide[id]
  666. local msgRet = Msg.gc.GC_LEVEL_UP
  667. local net = msgRet.data
  668. net.oldLv = oldLv
  669. net.newLv = newLv
  670. net.items[0] = 0
  671. if giveZuanshi > 0 then
  672. net.items[0] = net.items[0] + 1
  673. Grid.makeItem(net.items[net.items[0]], ItemDefine.ITEM_ZUANSHI_ID, giveZuanshi)
  674. end
  675. net.dialog = cf and cf.dialog or 0
  676. net.dialogName = cf and cf.dialogName or ""
  677. net.content = cf and cf.content or ""
  678. net.noticeLv = cf and cf.args[1] or 0
  679. net.panelId = cf and cf.panelId or 0
  680. Msg.send(msgRet, human.fd)
  681. end
  682. -- 等级指引
  683. local function makeLvGuideNet(net, id, human)
  684. local cf = GuideExcel.lv_guide[id]
  685. net.id = id
  686. net.noticeLv = cf and cf.args[1] or 0
  687. net.panelId = cf and cf.panelId or 0
  688. net.status = human.db.lvGuide and human.db.lvGuide[id] or 0
  689. local len = 0
  690. for k, v in ipairs(cf.guideList) do
  691. len = len + 1
  692. net.guideList[len] = v
  693. end
  694. net.guideList[0] = len
  695. end
  696. --推送等级指引
  697. function sendLvGuide(human)
  698. local msgRet = Msg.gc.GC_LEVEL_GUIDE
  699. local len = 0
  700. for k, v in ipairs(GuideExcel.lv_guide) do
  701. len = len + 1
  702. local net = msgRet.data[len]
  703. makeLvGuideNet(net, k, human)
  704. end
  705. msgRet.data[0] = len
  706. Msg.send(msgRet, human.fd)
  707. end
  708. --
  709. function stepLvFinish(human, id)
  710. local cf = GuideExcel.lv_guide[id]
  711. if not cf then
  712. if human.db.lvGuide and human.db.lvGuide[id] then
  713. human.db.lvGuide[id] = nil
  714. end
  715. return
  716. end
  717. human.db.lvGuide = human.db.lvGuide or {}
  718. human.db.lvGuide[id] = 1
  719. end
  720. --
  721. function stepLvInfo(human, id, guideId)
  722. if not Config.HAS_GUIDE then return end -- 指引总开关
  723. local diffTime = os.time() - human.db.createTime
  724. if diffTime >= 7 * 86400 and human.db.lv >= 5 then
  725. return
  726. end
  727. local cf = id and GuideExcel.lv_guide[id]
  728. if not cf then return end
  729. local msgRet = Msg.gc.GC_GUIDE_STEP
  730. msgRet.step[0] = 0
  731. local scf = GuideExcel.sub_guide[guideId]
  732. if scf then
  733. msgRet.step[0] = msgRet.step[0] + 1
  734. local net = msgRet.step[msgRet.step[0]]
  735. net.id = guideId
  736. net.conditions = Json.Encode(scf.conditions)
  737. net.behavior = Json.Encode(scf.behavior)
  738. net.sound = scf.sound
  739. net.dialog = scf.dialog
  740. net.content = scf.content
  741. net.handid = scf.handid
  742. net.zhiyin = scf.zhiyin
  743. net.heroLhID = scf.herolhId
  744. net.skip = scf.skip
  745. if scf.behavior[1] == "openPanel" and scf.behavior[2] and
  746. scf.behavior[2][1] == PanelDefine.PANEL_ID_52 then
  747. local dialog = scf.behavior[2][2]
  748. net.content = getContentByDialog(dialog)
  749. end
  750. end
  751. Msg.send(msgRet, human.fd)
  752. end
  753. -- 通用回调
  754. function onCallback(human)
  755. if not refreshGuide(human) then
  756. return
  757. end
  758. if getGuideState(human) ~= STATE_DOING then
  759. return
  760. end
  761. sendStep(human)
  762. return true
  763. end
  764. -- 临时 容错
  765. function checkAllFinish(human)
  766. if not Config.HAS_GUIDE then return 1 end
  767. -- local lastConfig = GuideExcel.main_guide[1200]
  768. -- local lastID = lastConfig.guideList[#lastConfig.guideList]
  769. -- local isFinish = isFinishGuideID(human, 1200)
  770. return isFinishGuideID(human, 1200) and 1 or 0
  771. end