GuideLogic.lua 30 KB

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