GuideLogic.lua 27 KB

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