GuideLogic.lua 32 KB

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