GuideLogic.lua 32 KB

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