HeroGrowUp.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. ---------------------------------------------------------------
  2. -- 英雄崛起(其实28天为一期的任务活动)
  3. -- 与创角时间相关
  4. -- tip 32
  5. -- db.heroGrowUp.groupID 活动组id
  6. -- db.heroGrowUp.time 活动开始的时间戳
  7. -- db.heroGrowUp.lv 等级
  8. -- db.heroGrowUp.lvGet 等级领取
  9. -- db.heroGrowUp.lvExGet 等级额外领取
  10. -- db.heroGrowUp.jifen 当前积分
  11. -- db.heroGrowUp.isBuy 是否购买
  12. -- db.heroGrowUp.task[mainType] = taskList
  13. -- taskList.time 刷新时间
  14. -- taskList.records 任务进度 [id] = value
  15. -- taskList.gets 领取记录 [id] = true
  16. ---------------------------------------------------------------
  17. local PresentExcel = require("excel.present")
  18. local OpenActExcel = require("excel.openAct")
  19. local Util = require("common.Util")
  20. local Lang = require("common.Lang")
  21. local Msg = require("core.Msg")
  22. local Broadcast = require("broadcast.Broadcast")
  23. local Grid = require("bag.Grid")
  24. local BagLogic = require("bag.BagLogic")
  25. local CombatDefine = require("combat.CombatDefine")
  26. local BuyLogic = require("topup.BuyLogic")
  27. local HeroDefine = require("hero.HeroDefine")
  28. local RoleDBLogic = require("role.RoleDBLogic")
  29. local YunYingLogic = require("yunying.YunYingLogic")
  30. local SceneHandler = require("scene.Handler")
  31. local CommonDB = require("common.CommonDB")
  32. local ItemExcel = require("excel.item")
  33. local ObjHuman = require("core.ObjHuman")
  34. local Config = require("Config")
  35. local AbsActExcel = require("excel.absAct")
  36. local AbsActLogic = require("absAct.AbsActLogic")
  37. DAY_TIME_SEC = 1 * 86400
  38. WEEK_TIME_SEC = 7 * 86400
  39. ACT_TIME_SEC1 = 28 * 86400
  40. ACT_TIME_SEC2 = 14 * 86400
  41. local SERVER_TIME_ZONE = 8 -- 服务器所在区服时区 北京东八区
  42. -- 任务分类
  43. MAINTYPE_DAY = 1 -- 每日
  44. MAINTYPE_WEEK = 2 -- 每周
  45. MAINTYPE_MONTH = 3 -- 每期
  46. MAINTYPE_CNT = 3
  47. -- 任务状态
  48. TASK_STATE_NONE = 0 -- 不可领
  49. TASK_STATE_CAN = 1 -- 可领
  50. TASK_STATE_HAD = 2 -- 已领
  51. -- 任务类型
  52. TASKTYPE1 = 1 -- o登录游戏
  53. TASKTYPE2 = 2 -- o天命召唤
  54. TASKTYPE3 = 3 -- o占卜合成
  55. TASKTYPE4 = 4 -- o消耗x金币
  56. TASKTYPE5 = 5 -- o消耗x钻石
  57. TASKTYPE6 = 6 -- o战报点赞X次
  58. TASKTYPE7 = 7 -- o皇冠联赛战场胜利X次
  59. TASKTYPE8 = 8 -- o合成X次任意符文
  60. TASKTYPE9 = 9 -- o冰龙巢穴
  61. TASKTYPE10 = 10 -- o随机商店购买道具
  62. TASKTYPE11 = 11 -- o上阵指定英雄XX,皇冠联赛战场获得X场胜利
  63. TASKTYPE12 = 12 -- o获取X个Y星英雄
  64. TASKTYPE13 = 13 -- o挑战战神殿
  65. TASKTYPE14 = 14 -- o王者争霸32强
  66. TASKTYPE15 = 15 -- o完成X次悬赏任务
  67. TASKTYPE16 = 16 -- o圣树试炼胜利X次
  68. TASKTYPE17 = 17 -- o接取X次红色悬赏任务
  69. TASKTYPE18 = 18 -- o消耗X英雄经验
  70. TASKTYPE19 = 19 -- o洗练X次任意装备
  71. TASKTYPE20 = 20 -- o遗迹探宝,击败x个守卫
  72. TASKTYPE21 = 21 -- o分解装备
  73. DG_ABS_ACT_ID = 8001
  74. HGU_AFTER_START = true
  75. function initAfterStart()
  76. HGU_AFTER_START = false
  77. end
  78. function initAfterHot()
  79. if HGU_AFTER_START then
  80. return
  81. end
  82. local workManStartTime,workManEndTime,groupID = getActStartTime()
  83. -- 活动未开
  84. if not workManStartTime then
  85. return
  86. end
  87. --重置任务
  88. TASKTYPE_2_MAINTYPES = {}
  89. MAINTYPE_2_IDLIST = {}
  90. -- 设置新任务
  91. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  92. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  93. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  94. end
  95. if not MAINTYPE_2_IDLIST[cf.mainType] then
  96. MAINTYPE_2_IDLIST[cf.mainType] = {}
  97. end
  98. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  99. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  100. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  101. local value = cf.taskArgs[1]
  102. local key = cf.taskArgs[2]
  103. if type(cf.taskArgs[2]) == "table" then
  104. local lenth = #cf.taskArgs[2]
  105. local randomPos = math.random(1,lenth)
  106. key = cf.taskArgs[2][randomPos]
  107. end
  108. if key then
  109. list[cf.mainType] = list[cf.mainType] or {}
  110. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  111. else
  112. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  113. end
  114. end
  115. GROUPID_2_LVCONFIGS = {}
  116. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  117. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  118. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  119. end
  120. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  121. end
  122. end
  123. -- 本期活动开始时间 --@warning actID不存在
  124. function getActStartTime()
  125. --local id = AbsActLogic.getIDByActID(human, DG_ABS_ACT_ID)
  126. --[[if absActConfig.actId and absActConfig.actId ~= 0 then
  127. return absActConfig.startDate,absActConfig.endDate,absActConfig.actId
  128. end]]
  129. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  130. assert(#absActConfig.turns ~= 0,"invalid config error")
  131. local actStartDate = absActConfig.startDate
  132. actStartDate.hour = actStartDate.hour or 0
  133. actStartDate.min = actStartDate.min or 0
  134. actStartDate.sec = actStartDate.sec or 0
  135. local actEndDate = absActConfig.endDate
  136. actEndDate.hour = actEndDate.hour or 0
  137. actEndDate.min = actEndDate.min or 0
  138. actEndDate.sec = actEndDate.sec or 0
  139. return os.time(actStartDate),os.time(actEndDate),absActConfig.turns[1] -- @error 目前默认第一期
  140. end
  141. local function transBeiJingTime(d)
  142. return os.time(d) - SERVER_TIME_ZONE * 3600
  143. end
  144. -- 活动剩余时间
  145. local function getActLeftTime(dateCfg)
  146. --local finishTime = transBeiJingTime(dateCfg)
  147. local now = os.time()
  148. return now > dateCfg and dateCfg - now or 0
  149. end
  150. -- 任务周期
  151. function getTaskTime(mainType)
  152. if mainType == MAINTYPE_DAY then
  153. return DAY_TIME_SEC
  154. elseif mainType == MAINTYPE_WEEK then
  155. return WEEK_TIME_SEC
  156. elseif mainType == MAINTYPE_MONTH then
  157. return ACT_TIME_SEC1
  158. end
  159. end
  160. -- 本期任务开始时间
  161. function getTaskStartTime(actStartTime, mainType)
  162. local time = getTaskTime(mainType)
  163. if not time then return end
  164. local sec = os.time() - actStartTime
  165. local cnt = math.floor(sec / time)
  166. return actStartTime + cnt * time
  167. end
  168. -- 获取任务剩余时间
  169. function getTaskLeftTime(actStartDate, mainType)
  170. local time = getTaskTime(mainType)
  171. if not time then return end
  172. --local actLeftTime = getActLeftTime(actStartTime)
  173. --return actLeftTime % time
  174. local now = os.time()
  175. if now < actStartDate then
  176. return 0
  177. end
  178. return (now - actStartDate) % time
  179. end
  180. -- 是否开放
  181. function isOpen(human)
  182. local openDay = CommonDB.getServerOpenDay()
  183. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  184. if openDay and openDay < absActConfig.openDay then
  185. return
  186. end
  187. if not getActStartTime(human) then
  188. return
  189. end
  190. return true
  191. end
  192. -- 是否红点
  193. function isRed(human)
  194. return isTaskRed(human) or isRewardRed(human)
  195. end
  196. -- 积分任务是否有红点
  197. function isTaskRed(human)
  198. for mainType = 1, MAINTYPE_CNT do
  199. if isTaskRedByType(human, mainType) then
  200. return true
  201. end
  202. end
  203. end
  204. -- 有奖励可领取
  205. function isRewardRed(human)
  206. local heroGrowUpDB = human.db.heroGrowUp
  207. if not heroGrowUpDB then
  208. return
  209. end
  210. local actStartTime,actEndTime,groupID = getActStartTime()
  211. local lvConfigs = getLvConfigs(groupID)
  212. if not actStartTime then return end
  213. if not lvConfigs then
  214. return
  215. end
  216. local maxLv = #lvConfigs
  217. for i = 1,heroGrowUpDB.lv do
  218. if i <= maxLv then
  219. if getGetReward(human,i) == 1 or not getGetExReward(human,i) == 1 then
  220. return true
  221. end
  222. else
  223. local lvDefine = lvConfigs[1]
  224. local flag = (i - maxLv) % lvDefine.lastNeedLv
  225. if flag == 0 then
  226. if getGetReward(human,i) == 1 or getGetExReward(human,i) == 1 then
  227. return true
  228. end
  229. end
  230. end
  231. end
  232. return
  233. end
  234. -- 根据分类判断是否有红点
  235. function isTaskRedByType(human, mainType)
  236. local list = getTaskIDList(mainType)
  237. local listLen = list and #list or 0
  238. for i = 1, listLen do
  239. local id = list[i]
  240. local cf = AbsActExcel.heroGrowUpTask[id]
  241. if getTaskState(human, id, cf) == TASK_STATE_CAN then
  242. return true
  243. end
  244. end
  245. end
  246. -- 根据类型获取任务id
  247. function getTaskIDList(mainType)
  248. return MAINTYPE_2_IDLIST and MAINTYPE_2_IDLIST[mainType]
  249. end
  250. -- 根据任务类型获取影响的分类
  251. -- [taskType] = {[mainType1] = maxValue, [mainType2][key] = maxValue2}
  252. function getMainTypesByTaskType(taskType)
  253. return TASKTYPE_2_MAINTYPES and TASKTYPE_2_MAINTYPES[taskType]
  254. end
  255. -- 最多x期
  256. local MAX_GROUPID = nil
  257. function getMaxGroupID()
  258. if not MAX_GROUPID then
  259. MAX_GROUPID = 0
  260. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  261. if cf.groupID > MAX_GROUPID then
  262. MAX_GROUPID = cf.groupID
  263. end
  264. end
  265. end
  266. return MAX_GROUPID
  267. end
  268. -- 根据第x期获取配置
  269. function getLvConfigs(groupID)
  270. return (groupID and GROUPID_2_LVCONFIGS) and GROUPID_2_LVCONFIGS[groupID]
  271. end
  272. -------------------------------------------- db -------------------------------------------------------
  273. -- 初始DB
  274. function initDB(human, actStartTime)
  275. local _,_,groupID = getActStartTime()
  276. local lvConfigs = getLvConfigs(groupID)
  277. if not lvConfigs then
  278. return
  279. end
  280. local heroGrowUpDB = {}
  281. heroGrowUpDB.time = actStartTime
  282. heroGrowUpDB.groupID = groupID
  283. heroGrowUpDB.lv = 0
  284. heroGrowUpDB.lvGet = {}
  285. heroGrowUpDB.lvExGet = {}
  286. heroGrowUpDB.jifen = 0
  287. heroGrowUpDB.isBuy = nil
  288. heroGrowUpDB.task = {}
  289. human.db.heroGrowUp = heroGrowUpDB
  290. end
  291. -- 初始任务DB
  292. function initTaskDB(human, actStartTime, mainType)
  293. local heroGrowUpDB = human.db.heroGrowUp
  294. local taskStartTime = getTaskStartTime(actStartTime, mainType)
  295. local taskList = {}
  296. taskList.time = taskStartTime
  297. taskList.records = {}
  298. taskList.gets = {}
  299. heroGrowUpDB.task[mainType] = taskList
  300. end
  301. -- 检查DB是否需要重置
  302. function checkDB(human, actStartTime,groupID)
  303. local heroGrowUpDB = human.db.heroGrowUp
  304. if not heroGrowUpDB then
  305. return
  306. end
  307. -- 新一期活动
  308. if heroGrowUpDB.groupID ~= groupID then
  309. heroGrowUpDB.groupID = groupID
  310. heroGrowUpDB.time = actStartTime
  311. heroGrowUpDB.lv = 0
  312. heroGrowUpDB.lvGet = {}
  313. heroGrowUpDB.lvExGet = {}
  314. heroGrowUpDB.jifen = 0
  315. heroGrowUpDB.isBuy = heroGrowUpDB.isBuy and 0 or nil
  316. heroGrowUpDB.task = {}
  317. return
  318. end
  319. -- 任务记录重置
  320. for mainType, taskList in pairs(heroGrowUpDB.task) do
  321. local taskStartTime = getTaskStartTime(actStartTime, mainType)
  322. if taskList.time ~= taskStartTime then
  323. heroGrowUpDB.task[mainType] = nil
  324. end
  325. end
  326. end
  327. -- 获取等级
  328. function getLv(human)
  329. local heroGrowUpDB = human.db.heroGrowUp
  330. if not heroGrowUpDB then
  331. return 0
  332. end
  333. return heroGrowUpDB.lv or 0
  334. end
  335. -- 获取当前积分
  336. function getJifen(human)
  337. local heroGrowUpDB = human.db.heroGrowUp
  338. if not heroGrowUpDB then
  339. return 0
  340. end
  341. return heroGrowUpDB.jifen or 0
  342. end
  343. -- 增加积分
  344. function addJifen(human, value)
  345. local actStartTime,actEndTime,groupID = getActStartTime()
  346. local lvConfigs = getLvConfigs(groupID)
  347. if not actStartTime then return end
  348. if not lvConfigs then
  349. return
  350. end
  351. local lvdefine = lvConfigs[1]
  352. checkDB(human, actStartTime,groupID)
  353. if not human.db.heroGrowUp then
  354. initDB(human, actStartTime)
  355. end
  356. local heroGrowUpDB = human.db.heroGrowUp
  357. heroGrowUpDB.jifen = (heroGrowUpDB.jifen or 0) + value
  358. local addLv = math.floor(heroGrowUpDB.jifen / lvdefine.needJifen)
  359. local oldLv = heroGrowUpDB.lv or 0
  360. local newLv = oldLv + addLv
  361. heroGrowUpDB.jifen = heroGrowUpDB.jifen - addLv * lvdefine.needJifen
  362. heroGrowUpDB.lv = newLv
  363. if oldLv ~= newLv then
  364. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  365. end
  366. end
  367. -- 是否购买王者礼包
  368. function isBuyKing(human)
  369. local heroGrowUpDB = human.db.heroGrowUp
  370. if not heroGrowUpDB then
  371. return
  372. end
  373. return heroGrowUpDB.isBuy
  374. end
  375. -- 设置购买
  376. function setBuyKing(human, actStartTime)
  377. if not human.db.heroGrowUp then
  378. initDB(human, actStartTime)
  379. end
  380. local heroGrowUpDB = human.db.heroGrowUp
  381. heroGrowUpDB.isBuy = 1
  382. end
  383. -- 设置领奖
  384. function setGetReward(human,lv)
  385. if not human.db.heroGrowUp then
  386. initDB(human, actStartTime)
  387. end
  388. local heroGrowUpDB = human.db.heroGrowUp
  389. heroGrowUpDB.lvGet = heroGrowUpDB.lvGet or {}
  390. heroGrowUpDB.lvGet[lv] = 2
  391. end
  392. function getGetReward(human,lv)
  393. local heroGrowUpDB = human.db.heroGrowUp
  394. if not heroGrowUpDB then
  395. return 0
  396. end
  397. if lv > heroGrowUpDB.lv then
  398. return 0
  399. end
  400. if not heroGrowUpDB.lvGet or not heroGrowUpDB.lvGet[lv] then
  401. return 1
  402. else
  403. return heroGrowUpDB.lvGet[lv]
  404. end
  405. end
  406. function getGetExReward(human,lv)
  407. local heroGrowUpDB = human.db.heroGrowUp
  408. if not heroGrowUpDB then
  409. return 0
  410. end
  411. if lv > heroGrowUpDB.lv then
  412. return 0
  413. end
  414. if not heroGrowUpDB.lvExGet or not heroGrowUpDB.lvExGet[lv] then
  415. return 1
  416. else
  417. return heroGrowUpDB.lvExGet[lv]
  418. end
  419. end
  420. -- 设置领奖
  421. function setGetExReward(human,lv)
  422. if not human.db.heroGrowUp then
  423. initDB(human, actStartTime)
  424. end
  425. local heroGrowUpDB = human.db.heroGrowUp
  426. heroGrowUpDB.lvExGet = heroGrowUpDB.lvExGet or {}
  427. heroGrowUpDB.lvExGet[lv] = 2
  428. end
  429. -- 是否领取
  430. function isGetTask(human, id, cf)
  431. local heroGrowUpDB = human.db.heroGrowUp
  432. if not heroGrowUpDB then
  433. return
  434. end
  435. local taskList = heroGrowUpDB.task[cf.mainType]
  436. if not taskList then return end
  437. if taskList.gets[id] then
  438. return true
  439. end
  440. end
  441. -- 设置已领取
  442. function setGetTask(human, actStartTime, id, cf)
  443. if not human.db.heroGrowUp then
  444. initDB(human, actStartTime)
  445. end
  446. local heroGrowUpDB = human.db.heroGrowUp
  447. if not heroGrowUpDB.task[cf.mainType] then
  448. initTaskDB(human, actStartTime, cf.mainType)
  449. end
  450. heroGrowUpDB.task[cf.mainType].gets[id] = 1
  451. end
  452. local function getValueByKey(human, mainType, taskType, key)
  453. if taskType == TASKTYPE1 then
  454. return 1
  455. end
  456. local heroGrowUpDB = human.db.heroGrowUp
  457. local taskList = heroGrowUpDB and heroGrowUpDB.task[mainType]
  458. if not taskList then
  459. return 0
  460. end
  461. local record = taskList.records[taskType]
  462. if not key then
  463. return record or 0
  464. end
  465. return record and record[key] or 0
  466. end
  467. -- 当前进度
  468. function getValue(human, cf)
  469. local key = cf.taskArgs[2]
  470. if type(key) == "table" then
  471. local list = getMainTypesByTaskType(cf.taskType)
  472. for k,v in pairs(list[cf.mainType]) do
  473. key = k
  474. break
  475. end
  476. end
  477. return getValueByKey(human, cf.mainType, cf.taskType, key)
  478. end
  479. -- 更新进度
  480. function updateValue(human, actStartTime, mainType, taskType, key, value)
  481. if not human.db.heroGrowUp then
  482. initDB(human, actStartTime)
  483. end
  484. local heroGrowUpDB = human.db.heroGrowUp
  485. if not heroGrowUpDB.task[mainType] then
  486. initTaskDB(human, actStartTime, mainType)
  487. end
  488. local taskList = heroGrowUpDB.task[mainType]
  489. if key then
  490. taskList.records[taskType] = taskList.records[taskType] or {}
  491. taskList.records[taskType][key] = value
  492. else
  493. taskList.records[taskType] = value
  494. end
  495. end
  496. -- 最大进度
  497. function getMaxValue(cf)
  498. return cf.taskArgs[1]
  499. end
  500. -- 获取任务状态
  501. function getTaskState(human, id, cf)
  502. if isGetTask(human, id, cf) then
  503. return TASK_STATE_HAD
  504. end
  505. local value = getValue(human, cf)
  506. local maxValue = getMaxValue(cf)
  507. if value >= maxValue then
  508. return TASK_STATE_CAN
  509. end
  510. return TASK_STATE_NONE
  511. end
  512. -- 获取任务名字
  513. function getTaskName(cf)
  514. if cf.taskType == TASKTYPE11 then
  515. local list = TASKTYPE_2_MAINTYPES[TASKTYPE11][cf.mainType]
  516. local heroID = cf.taskArgs[2]
  517. for k,v in pairs(list) do
  518. heroID = k
  519. break
  520. end
  521. local heroConfig = HeroDefine.getConfig(heroID)
  522. return Util.format(cf.name, heroConfig.name)
  523. end
  524. return cf.name
  525. end
  526. -- 获取任务描述
  527. function getTaskDesc(cf)
  528. if cf.taskType == TASKTYPE18 or
  529. cf.taskType == TASKTYPE4 or
  530. cf.taskType == TASKTYPE12 then
  531. return Util.format(cf.desc, cf.taskArgs[1], cf.taskArgs[2])
  532. elseif cf.taskType == TASKTYPE14 then
  533. return Util.format(cf.desc, cf.taskArgs[2])
  534. end
  535. return Util.format(cf.desc, cf.taskArgs[1])
  536. end
  537. -------------------------------------------- msg -------------------------------------------------------
  538. -- 封装基础信息
  539. function fontBaseNet(net, human, actEndTime, lvdefine)
  540. net.leftTime = getActLeftTime(actEndTime)
  541. net.lv = getLv(human)
  542. net.jifen = getJifen(human)
  543. net.maxJifen = lvdefine.needJifen
  544. local isBuy = isBuyKing(human)
  545. net.isBuyKing = isBuy == 1 and 1 or 0
  546. net.hasTaskRed = isRed(human) and 1 or 0
  547. end
  548. -- 封装任务信息
  549. local function fontTaskNet(id, human)
  550. local cf = AbsActExcel.heroGrowUpTask[id]
  551. local ret = {}
  552. ret.id = id
  553. ret.taskName = getTaskName(cf)
  554. ret.taskDesc = getTaskDesc(cf)
  555. ret.maxValue = getMaxValue(cf)
  556. ret.nowValue = math.min(getValue(human, cf), ret.maxValue)
  557. ret.item = ret.item or {}
  558. Grid.makeItem(ret.item, cf.items[1][1], cf.items[1][2])
  559. ret.panelID = cf.panelID
  560. ret.state = getTaskState(human, id, cf)
  561. return ret
  562. end
  563. -- 积分任务界面
  564. function sendTaskQuery(human, mainType)
  565. local actStartTime,actEndTime, groupID = getActStartTime()
  566. local lvConfigs = getLvConfigs(groupID)
  567. if not actStartTime then
  568. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  569. end
  570. if not lvConfigs then
  571. return
  572. end
  573. local leftTime = getTaskLeftTime(actStartTime, mainType)
  574. if not leftTime then return end
  575. local lvdefine = lvConfigs[1]
  576. checkDB(human, actStartTime,groupID)
  577. local list = getTaskIDList(mainType)
  578. local msgRet = Msg.gc.GC_HERO_GROWUP_TASK_QUERY
  579. msgRet.endTime = actEndTime
  580. msgRet.startTime = actStartTime
  581. msgRet.leftTime = actEndTime - os.time()
  582. fontBaseNet(msgRet.data, human, actEndTime, lvdefine)
  583. msgRet.data.hasTaskRed = isTaskRed(human) and 1 or 0
  584. msgRet.mainType = mainType
  585. msgRet.taskLeftTime = leftTime
  586. msgRet.taskList = msgRet.taskList or {}
  587. msgRet.taskList[0] = list and #list or 0
  588. for i = 1, msgRet.taskList[0] do
  589. local id = list[i]
  590. msgRet.taskList[i] = fontTaskNet(id, human)
  591. end
  592. msgRet.taskReds[0] = MAINTYPE_CNT
  593. for i = 1, msgRet.taskReds[0] do
  594. msgRet.taskReds[i] = isTaskRedByType(human, i) and 1 or 0
  595. end
  596. --Msg.trace(msgRet)
  597. table.print_lua_table(msgRet)
  598. Msg.send(msgRet, human.fd)
  599. end
  600. -- 领取任务奖励
  601. function getTaskItems(human, id)
  602. local actStartTime,actEndTime,groupID = getActStartTime()
  603. if not actStartTime then
  604. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  605. end
  606. local cf = AbsActExcel.heroGrowUpTask[id]
  607. if not cf then return end
  608. local nType = cf.mainType
  609. checkDB(human, actStartTime,groupID)
  610. -- local state = getTaskState(human, id, cf)
  611. -- if state == TASK_STATE_NONE then
  612. -- return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  613. -- end
  614. -- if state == TASK_STATE_HAD then
  615. -- return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  616. -- end
  617. local tItem = {}
  618. for nID, v in pairs(AbsActExcel.heroGrowUpTask) do
  619. if v.mainType == nType then
  620. local state = getTaskState(human, nID, v)
  621. if state == TASK_STATE_CAN then
  622. setGetTask(human, actStartTime, nID, v)
  623. for _, item in ipairs(v.items) do
  624. local nGoodsID, nGoodsNum = item[1], item[2]
  625. if not tItem[nGoodsID] then
  626. tItem[nGoodsID] = 0
  627. end
  628. tItem[nGoodsID] = tItem[nGoodsID] + nGoodsNum
  629. end
  630. end
  631. end
  632. end
  633. if nil ~= _G.next(tItem) then
  634. BagLogic.addItemList(human, tItem, "hero_growup_task")
  635. -- BagLogic.sendItemGetList(human, tItem)
  636. end
  637. sendTaskQuery(human, cf.mainType)
  638. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  639. end
  640. -- 查看王者礼包信息
  641. function sendKingQuery(human)
  642. if not SceneHandler.canCharge(human) then
  643. return
  644. end
  645. local actStartTime,actEndTime, groupID = getActStartTime()
  646. local lvConfigs = getLvConfigs(groupID)
  647. if not actStartTime then
  648. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  649. end
  650. if not lvConfigs then
  651. return
  652. end
  653. local lvdefine = lvConfigs[1].kingBuyItems
  654. checkDB(human, actStartTime,groupID)
  655. local isBuy = isBuyKing(human)
  656. if isBuy then
  657. lvdefine = lvConfigs[1].kingBuyItems2
  658. end
  659. local msgRet = Msg.gc.GC_HERO_GROWUP_KING_QUERY
  660. msgRet.items[0] = math.min(#lvdefine, #msgRet.items)
  661. for i = 1, msgRet.items[0] do
  662. local itemID = lvdefine[i][1]
  663. local itemCnt = lvdefine[i][2]
  664. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  665. end
  666. BuyLogic.fontBuyItem(human, msgRet.buyItem, lvConfigs[1].buyID)
  667. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  668. --Msg.trace(msgRet)
  669. Msg.send(msgRet, human.fd)
  670. end
  671. -- 奖励界面查看
  672. function sendRewardQuery(human)
  673. local actStartTime,actEndTime, groupID = getActStartTime()
  674. local lvConfigs = getLvConfigs(groupID)
  675. if not actStartTime or not lvConfigs then
  676. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  677. end
  678. local lvdefine = lvConfigs[1]
  679. checkDB(human, actStartTime,groupID)
  680. local msgRet = Msg.gc.GC_HERO_GROWUP_REWARD_QUERY
  681. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  682. msgRet.data.hasTaskRed = isRewardRed(human) and 1 or 0
  683. msgRet.rewardList[0] = #lvConfigs
  684. local nowLv = getLv(human)
  685. for lv = 1, msgRet.rewardList[0] do
  686. local net = msgRet.rewardList[lv]
  687. local cf = lvConfigs[lv]
  688. net.lv = lv
  689. net.items[0] = #cf.items
  690. net.state = 0
  691. net.stateEx = 0
  692. for i = 1, net.items[0] do
  693. local itemID = cf.items[i][1]
  694. local itemCnt = cf.items[i][2]
  695. Grid.makeItem(net.items[i], itemID, itemCnt)
  696. end
  697. if lv <= nowLv then
  698. net.state = getGetReward(human,lv)
  699. end
  700. net.itemsKing[0] = #cf.itemsKing
  701. for i = 1, net.itemsKing[0] do
  702. local itemID = cf.itemsKing[i][1]
  703. local itemCnt = cf.itemsKing[i][2]
  704. Grid.makeItem(net.itemsKing[i], itemID, itemCnt)
  705. end
  706. if lv <= nowLv then
  707. net.stateEx = getGetExReward(human,lv)
  708. end
  709. end
  710. local maxLv = #lvConfigs
  711. local exRewardNet = msgRet.exReward
  712. local nextLv = maxLv + lvdefine.lastNeedLv
  713. exRewardNet.needLv = lvdefine.lastNeedLv
  714. exRewardNet.items[0] = #lvdefine.lastItems
  715. exRewardNet.state = 0
  716. exRewardNet.stateEx = 0
  717. while true do
  718. if nextLv > nowLv then
  719. break
  720. end
  721. local nextState = getGetReward(human,nextLv)
  722. if not nextState or nextState == 1 then
  723. break
  724. end
  725. nextLv = nextLv + lvdefine.lastNeedLv
  726. end
  727. exRewardNet.lv = nextLv
  728. exRewardNet.state = getGetReward(human,nextLv)
  729. nextLv = maxLv + lvdefine.lastNeedLv
  730. while true do
  731. if nextLv > nowLv then
  732. break
  733. end
  734. local nextState = getGetExReward(human,nextLv)
  735. if not nextState or nextState == 1 then
  736. break
  737. end
  738. nextLv = nextLv + lvdefine.lastNeedLv
  739. end
  740. exRewardNet.exLv = nextLv
  741. exRewardNet.stateEx = getGetExReward(human,nextLv)
  742. local isBuy = isBuyKing(human)
  743. if isBuy ~= 1 then
  744. exRewardNet.stateEx = 0
  745. end
  746. for i = 1, exRewardNet.items[0] do
  747. local itemID = lvdefine.lastItems[i][1]
  748. local itemCnt = lvdefine.lastItems[i][2]
  749. Grid.makeItem(exRewardNet.items[i], itemID, itemCnt)
  750. end
  751. exRewardNet.itemsKing[0] = #lvdefine.lastItemsKing
  752. for i = 1, exRewardNet.itemsKing[0] do
  753. local itemID = lvdefine.lastItemsKing[i][1]
  754. local itemCnt = lvdefine.lastItemsKing[i][2]
  755. Grid.makeItem(exRewardNet.itemsKing[i], itemID, itemCnt)
  756. end
  757. --Msg.trace(msgRet)
  758. Msg.send(msgRet, human.fd)
  759. end
  760. -------------------------------------------- 回调 -------------------------------------------------------
  761. -- 升级回调
  762. function getLvReward(human, lv)
  763. local actStartTime,actEndTime, groupID = getActStartTime()
  764. if not groupID then
  765. return
  766. end
  767. local nowLv = getLv(human)
  768. if lv > nowLv then
  769. return
  770. end
  771. local normalGet = getGetReward(human,lv)
  772. local exGet = getGetExReward(human,lv)
  773. local lvConfigs = getLvConfigs(groupID)
  774. if not lvConfigs then
  775. return
  776. end
  777. local lvdefine = lvConfigs[1]
  778. local list = {}
  779. local maxLv = #lvConfigs
  780. local isBuy = isBuyKing(human)
  781. local cf = lvConfigs[lv]
  782. local items = cf and cf.items
  783. local itemsKing = cf and cf.itemsKing
  784. if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv == 0 then
  785. items = lvdefine.lastItems
  786. itemsKing = lvdefine.lastItemsKing
  787. end
  788. if items and normalGet ~= 2 then
  789. for _, item in ipairs(items) do
  790. local itemID = item[1]
  791. local itemCnt = item[2]
  792. list[itemID] = (list[itemID] or 0) + itemCnt
  793. end
  794. end
  795. if itemsKing and isBuy == 1 and exGet ~= 2 then
  796. for _, item in ipairs(itemsKing) do
  797. local itemID = item[1]
  798. local itemCnt = item[2]
  799. list[itemID] = (list[itemID] or 0) + itemCnt
  800. end
  801. end
  802. if not next(list) then return end
  803. setGetReward(human,lv)
  804. if isBuy == 1 then
  805. setGetExReward(human,lv)
  806. end
  807. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  808. local msgRet = Msg.gc.GC_HERO_GROWUP_LVUP
  809. msgRet.lv = nowLv
  810. msgRet.items[0] = 0
  811. for itemID, itemCnt in pairs(list) do
  812. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  813. if msgRet.items[0] < #msgRet.items then
  814. msgRet.items[0] = msgRet.items[0] + 1
  815. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  816. end
  817. end
  818. BagLogic.sendItemGetList2(human, list)
  819. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  820. --Msg.trace(msgRet)
  821. Msg.send(msgRet, human.fd)
  822. end
  823. -- 购买王者礼包ii
  824. function buyKing(human)
  825. local actStartTime,actEndTime, groupID = getActStartTime()
  826. local lvConfigs = getLvConfigs(groupID)
  827. if not actStartTime then return end
  828. if not lvConfigs then
  829. return
  830. end
  831. local lvdefine = lvConfigs[1]
  832. checkDB(human, actStartTime,groupID)
  833. local isBuy = isBuyKing(human)
  834. if isBuy == 1 then return end
  835. setBuyKing(human, actStartTime)
  836. -- 计算可以给的东西
  837. -- local maxLv = #lvConfigs
  838. -- local nowLv = getLv(human)
  839. -- local list = {}
  840. -- for lv = 1, nowLv do
  841. -- local cf = lvConfigs[lv]
  842. -- local itemsKing = cf and cf.itemsKing
  843. -- if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv then
  844. -- itemsKing = lvdefine.lastItemsKing
  845. -- end
  846. -- if itemsKing then
  847. -- for _, item in ipairs(itemsKing) do
  848. -- local itemID = item[1]
  849. -- local itemCnt = item[2]
  850. -- list[itemID] = (list[itemID] or 0) + itemCnt
  851. -- end
  852. -- end
  853. -- end
  854. local list = {}
  855. local config = lvdefine.kingBuyItems
  856. if isBuy then
  857. config = lvdefine.kingBuyItems2
  858. end
  859. -- 购买王者后直接赠送的东西
  860. for _, item in ipairs(config) do
  861. local itemID = item[1]
  862. local itemCnt = item[2]
  863. list[itemID] = (list[itemID] or 0) + itemCnt
  864. end
  865. -- 给东西
  866. for itemID, itemCnt in pairs(list) do
  867. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  868. end
  869. BagLogic.sendItemGetList2(human, list)
  870. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  871. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_OK
  872. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  873. Msg.send(msgRet, human.fd)
  874. sendRewardQuery(human)
  875. end
  876. -- 子回调
  877. local function doCallback(human, actStartTime, mainType, taskType, maxValue, key, value)
  878. local oldValue = getValueByKey(human, mainType, taskType, key)
  879. if oldValue >= maxValue then
  880. return
  881. end
  882. local newValue = oldValue
  883. -- 任务类型11 指定英雄 竞技场胜利指定次数
  884. if taskType == TASKTYPE11 then
  885. local isFind = nil
  886. for _, obj in pairs(value.objList) do
  887. if obj.side == CombatDefine.ATTACK_SIDE and
  888. obj.id == key then
  889. isFind = true
  890. break
  891. end
  892. end
  893. if not isFind then return end
  894. newValue = oldValue + 1
  895. elseif taskType == TASKTYPE12 then
  896. if key ~= value then
  897. return
  898. end
  899. newValue = oldValue + 1
  900. elseif taskType == TASKTYPE14 then
  901. if value > key then
  902. return
  903. end
  904. newValue = oldValue + 1
  905. else
  906. newValue = math.min(oldValue + value, maxValue)
  907. end
  908. updateValue(human, actStartTime, mainType, taskType, key, newValue)
  909. return true
  910. end
  911. -- 任务回调
  912. function onCallback(human, taskType, value)
  913. local actStartTime,actEndTime,groupID = getActStartTime()
  914. if not actStartTime then return end
  915. local mainTypes = getMainTypesByTaskType(taskType)
  916. if not mainTypes then return end
  917. checkDB(human, actStartTime,groupID)
  918. local isChange = nil
  919. for mainType, mainValue in pairs(mainTypes) do
  920. local mainValueType = type(mainValue)
  921. if mainValueType == "number" then
  922. if doCallback(human, actStartTime, mainType, taskType, mainValue, nil, value) then
  923. isChange = true
  924. end
  925. elseif mainValueType == "table" then
  926. for key, maxValue in pairs(mainValue) do
  927. if doCallback(human, actStartTime, mainType, taskType, maxValue, key, value) then
  928. isChange = true
  929. end
  930. end
  931. end
  932. end
  933. if isChange then
  934. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  935. Msg.send(Msg.gc.GC_HERO_GROWUP_TASK_REFRESH, human.fd)
  936. end
  937. return isChange
  938. end
  939. -- 任务回调 uuid
  940. local FakeHuman = {}
  941. function onCallbackByUuid(uuid, taskType, value)
  942. local db, online = RoleDBLogic.getDb(uuid)
  943. if not db then return end
  944. FakeHuman.db = db
  945. if onCallback(FakeHuman, taskType, value) and not online then
  946. RoleDBLogic.saveRole(db)
  947. end
  948. end
  949. function buyJifen(human,itemID,cnt)
  950. local actStartTime,actEndTime,groupID = getActStartTime()
  951. if not actStartTime then return end
  952. local now = os.time()
  953. if actEndTime - now > 3*86400 then
  954. return
  955. end
  956. checkDB(human, actStartTime,groupID)
  957. local config = ItemExcel.commonBuy[itemID]
  958. if not config then
  959. return
  960. end
  961. local price = config.price[2]*cnt
  962. if not ObjHuman.checkRMB(human,price) then
  963. return
  964. end
  965. ObjHuman.decZuanshi(human, - price, "hero_growup")
  966. addJifen(human, 1000*cnt)
  967. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_JIFEN
  968. msgRet.lv = human.db.heroGrowUp.lv or 0
  969. msgRet.jifen = human.db.heroGrowUp.jifen or 0
  970. msgRet.maxJifen = AbsActExcel.heroGrowUpLv[1].needJifen
  971. Msg.send(msgRet,human.fd)
  972. end
  973. -- 活动循环,开启与结束
  974. function actLoop()
  975. local workManStartTime,workManEndTime,groupID = getActStartTime()
  976. local workMan = CommonDB.getWorkMan()
  977. -- 活动未开,且commonDB活动开,则关闭活动
  978. if not workManStartTime and workMan.state then
  979. CommonDB.setWorkManState()
  980. return
  981. end
  982. -- 活动开,且commonDB活动未开,则开启活动
  983. -- 活动id不符
  984. if (workManStartTime and not workMan.state) or groupID ~= workMan.groupID then
  985. CommonDB.setWorkManState(true)
  986. CommonDB.setWorkManGroup(groupID)
  987. CommonDB.setWorkManTs(workManStartTime)
  988. --重置任务
  989. TASKTYPE_2_MAINTYPES = {}
  990. MAINTYPE_2_IDLIST = {}
  991. -- 设置新任务
  992. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  993. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  994. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  995. end
  996. if not MAINTYPE_2_IDLIST[cf.mainType] then
  997. MAINTYPE_2_IDLIST[cf.mainType] = {}
  998. end
  999. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  1000. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  1001. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  1002. local value = cf.taskArgs[1]
  1003. local key = cf.taskArgs[2]
  1004. if type(cf.taskArgs[2]) == "table" then
  1005. local lenth = #cf.taskArgs[2]
  1006. local randomPos = math.random(1,lenth)
  1007. key = cf.taskArgs[2][randomPos]
  1008. end
  1009. if key then
  1010. list[cf.mainType] = list[cf.mainType] or {}
  1011. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  1012. else
  1013. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  1014. end
  1015. end
  1016. GROUPID_2_LVCONFIGS = {}
  1017. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  1018. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  1019. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  1020. end
  1021. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  1022. end
  1023. return
  1024. end
  1025. end