GuideLogic.lua 29 KB

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