GuideLogic.lua 27 KB

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