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