GuideLogic.lua 30 KB

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