HeroGrowUp.lua 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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. checkDB(human, actStartTime,groupID)
  609. local state = getTaskState(human, id, cf)
  610. if state == TASK_STATE_NONE then
  611. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  612. end
  613. if state == TASK_STATE_HAD then
  614. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  615. end
  616. setGetTask(human, actStartTime, id, cf)
  617. for _, item in ipairs(cf.items) do
  618. local itemID = item[1]
  619. local itemCnt = item[2]
  620. BagLogic.addItem(human, itemID, itemCnt, "hero_growup_task")
  621. end
  622. BagLogic.sendItemGetList1(human, cf.items)
  623. sendTaskQuery(human, cf.mainType)
  624. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  625. end
  626. -- 查看王者礼包信息
  627. function sendKingQuery(human)
  628. if not SceneHandler.canCharge(human) then
  629. return
  630. end
  631. local actStartTime,actEndTime, groupID = getActStartTime()
  632. local lvConfigs = getLvConfigs(groupID)
  633. if not actStartTime then
  634. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  635. end
  636. if not lvConfigs then
  637. return
  638. end
  639. local lvdefine = lvConfigs[1].kingBuyItems
  640. checkDB(human, actStartTime,groupID)
  641. local isBuy = isBuyKing(human)
  642. if isBuy then
  643. lvdefine = lvConfigs[1].kingBuyItems2
  644. end
  645. local msgRet = Msg.gc.GC_HERO_GROWUP_KING_QUERY
  646. msgRet.items[0] = math.min(#lvdefine, #msgRet.items)
  647. for i = 1, msgRet.items[0] do
  648. local itemID = lvdefine[i][1]
  649. local itemCnt = lvdefine[i][2]
  650. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  651. end
  652. BuyLogic.fontBuyItem(human, msgRet.buyItem, lvConfigs[1].buyID)
  653. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  654. --Msg.trace(msgRet)
  655. Msg.send(msgRet, human.fd)
  656. end
  657. -- 奖励界面查看
  658. function sendRewardQuery(human)
  659. local actStartTime,actEndTime, groupID = getActStartTime()
  660. local lvConfigs = getLvConfigs(groupID)
  661. if not actStartTime or not lvConfigs then
  662. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  663. end
  664. local lvdefine = lvConfigs[1]
  665. checkDB(human, actStartTime,groupID)
  666. local msgRet = Msg.gc.GC_HERO_GROWUP_REWARD_QUERY
  667. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  668. msgRet.data.hasTaskRed = isRewardRed(human) and 1 or 0
  669. msgRet.rewardList[0] = #lvConfigs
  670. local nowLv = getLv(human)
  671. for lv = 1, msgRet.rewardList[0] do
  672. local net = msgRet.rewardList[lv]
  673. local cf = lvConfigs[lv]
  674. net.lv = lv
  675. net.items[0] = #cf.items
  676. net.state = 0
  677. net.stateEx = 0
  678. for i = 1, net.items[0] do
  679. local itemID = cf.items[i][1]
  680. local itemCnt = cf.items[i][2]
  681. Grid.makeItem(net.items[i], itemID, itemCnt)
  682. end
  683. if lv <= nowLv then
  684. net.state = getGetReward(human,lv)
  685. end
  686. net.itemsKing[0] = #cf.itemsKing
  687. for i = 1, net.itemsKing[0] do
  688. local itemID = cf.itemsKing[i][1]
  689. local itemCnt = cf.itemsKing[i][2]
  690. Grid.makeItem(net.itemsKing[i], itemID, itemCnt)
  691. end
  692. if lv <= nowLv then
  693. net.stateEx = getGetExReward(human,lv)
  694. end
  695. end
  696. local maxLv = #lvConfigs
  697. local exRewardNet = msgRet.exReward
  698. local nextLv = maxLv + lvdefine.lastNeedLv
  699. exRewardNet.needLv = lvdefine.lastNeedLv
  700. exRewardNet.items[0] = #lvdefine.lastItems
  701. exRewardNet.state = 0
  702. exRewardNet.stateEx = 0
  703. while true do
  704. if nextLv > nowLv then
  705. break
  706. end
  707. local nextState = getGetReward(human,nextLv)
  708. if not nextState or nextState == 1 then
  709. break
  710. end
  711. nextLv = nextLv + lvdefine.lastNeedLv
  712. end
  713. exRewardNet.lv = nextLv
  714. exRewardNet.state = getGetReward(human,nextLv)
  715. nextLv = maxLv + lvdefine.lastNeedLv
  716. while true do
  717. if nextLv > nowLv then
  718. break
  719. end
  720. local nextState = getGetExReward(human,nextLv)
  721. if not nextState or nextState == 1 then
  722. break
  723. end
  724. nextLv = nextLv + lvdefine.lastNeedLv
  725. end
  726. exRewardNet.exLv = nextLv
  727. exRewardNet.stateEx = getGetExReward(human,nextLv)
  728. local isBuy = isBuyKing(human)
  729. if isBuy ~= 1 then
  730. exRewardNet.stateEx = 0
  731. end
  732. for i = 1, exRewardNet.items[0] do
  733. local itemID = lvdefine.lastItems[i][1]
  734. local itemCnt = lvdefine.lastItems[i][2]
  735. Grid.makeItem(exRewardNet.items[i], itemID, itemCnt)
  736. end
  737. exRewardNet.itemsKing[0] = #lvdefine.lastItemsKing
  738. for i = 1, exRewardNet.itemsKing[0] do
  739. local itemID = lvdefine.lastItemsKing[i][1]
  740. local itemCnt = lvdefine.lastItemsKing[i][2]
  741. Grid.makeItem(exRewardNet.itemsKing[i], itemID, itemCnt)
  742. end
  743. --Msg.trace(msgRet)
  744. Msg.send(msgRet, human.fd)
  745. end
  746. -------------------------------------------- 回调 -------------------------------------------------------
  747. -- 升级回调
  748. function getLvReward(human, lv)
  749. local actStartTime,actEndTime, groupID = getActStartTime()
  750. if not groupID then
  751. return
  752. end
  753. local nowLv = getLv(human)
  754. if lv > nowLv then
  755. return
  756. end
  757. local normalGet = getGetReward(human,lv)
  758. local exGet = getGetExReward(human,lv)
  759. local lvConfigs = getLvConfigs(groupID)
  760. if not lvConfigs then
  761. return
  762. end
  763. local lvdefine = lvConfigs[1]
  764. local list = {}
  765. local maxLv = #lvConfigs
  766. local isBuy = isBuyKing(human)
  767. local cf = lvConfigs[lv]
  768. local items = cf and cf.items
  769. local itemsKing = cf and cf.itemsKing
  770. if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv == 0 then
  771. items = lvdefine.lastItems
  772. itemsKing = lvdefine.lastItemsKing
  773. end
  774. if items and normalGet ~= 2 then
  775. for _, item in ipairs(items) do
  776. local itemID = item[1]
  777. local itemCnt = item[2]
  778. list[itemID] = (list[itemID] or 0) + itemCnt
  779. end
  780. end
  781. if itemsKing and isBuy == 1 and exGet ~= 2 then
  782. for _, item in ipairs(itemsKing) do
  783. local itemID = item[1]
  784. local itemCnt = item[2]
  785. list[itemID] = (list[itemID] or 0) + itemCnt
  786. end
  787. end
  788. if not next(list) then return end
  789. setGetReward(human,lv)
  790. if isBuy == 1 then
  791. setGetExReward(human,lv)
  792. end
  793. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  794. local msgRet = Msg.gc.GC_HERO_GROWUP_LVUP
  795. msgRet.lv = nowLv
  796. msgRet.items[0] = 0
  797. for itemID, itemCnt in pairs(list) do
  798. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  799. if msgRet.items[0] < #msgRet.items then
  800. msgRet.items[0] = msgRet.items[0] + 1
  801. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  802. end
  803. end
  804. BagLogic.sendItemGetList2(human, list)
  805. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  806. --Msg.trace(msgRet)
  807. Msg.send(msgRet, human.fd)
  808. end
  809. -- 购买王者礼包ii
  810. function buyKing(human)
  811. local actStartTime,actEndTime, groupID = getActStartTime()
  812. local lvConfigs = getLvConfigs(groupID)
  813. if not actStartTime then return end
  814. if not lvConfigs then
  815. return
  816. end
  817. local lvdefine = lvConfigs[1]
  818. checkDB(human, actStartTime,groupID)
  819. local isBuy = isBuyKing(human)
  820. if isBuy == 1 then return end
  821. setBuyKing(human, actStartTime)
  822. -- 计算可以给的东西
  823. -- local maxLv = #lvConfigs
  824. -- local nowLv = getLv(human)
  825. -- local list = {}
  826. -- for lv = 1, nowLv do
  827. -- local cf = lvConfigs[lv]
  828. -- local itemsKing = cf and cf.itemsKing
  829. -- if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv then
  830. -- itemsKing = lvdefine.lastItemsKing
  831. -- end
  832. -- if itemsKing then
  833. -- for _, item in ipairs(itemsKing) do
  834. -- local itemID = item[1]
  835. -- local itemCnt = item[2]
  836. -- list[itemID] = (list[itemID] or 0) + itemCnt
  837. -- end
  838. -- end
  839. -- end
  840. local list = {}
  841. local config = lvdefine.kingBuyItems
  842. if isBuy then
  843. config = lvdefine.kingBuyItems2
  844. end
  845. -- 购买王者后直接赠送的东西
  846. for _, item in ipairs(config) do
  847. local itemID = item[1]
  848. local itemCnt = item[2]
  849. list[itemID] = (list[itemID] or 0) + itemCnt
  850. end
  851. -- 给东西
  852. for itemID, itemCnt in pairs(list) do
  853. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  854. end
  855. BagLogic.sendItemGetList2(human, list)
  856. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  857. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_OK
  858. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  859. Msg.send(msgRet, human.fd)
  860. sendRewardQuery(human)
  861. end
  862. -- 子回调
  863. local function doCallback(human, actStartTime, mainType, taskType, maxValue, key, value)
  864. local oldValue = getValueByKey(human, mainType, taskType, key)
  865. if oldValue >= maxValue then
  866. return
  867. end
  868. local newValue = oldValue
  869. -- 任务类型11 指定英雄 竞技场胜利指定次数
  870. if taskType == TASKTYPE11 then
  871. local isFind = nil
  872. for _, obj in pairs(value.objList) do
  873. if obj.side == CombatDefine.ATTACK_SIDE and
  874. obj.id == key then
  875. isFind = true
  876. break
  877. end
  878. end
  879. if not isFind then return end
  880. newValue = oldValue + 1
  881. elseif taskType == TASKTYPE12 then
  882. if key ~= value then
  883. return
  884. end
  885. newValue = oldValue + 1
  886. elseif taskType == TASKTYPE14 then
  887. if value > key then
  888. return
  889. end
  890. newValue = oldValue + 1
  891. else
  892. newValue = math.min(oldValue + value, maxValue)
  893. end
  894. updateValue(human, actStartTime, mainType, taskType, key, newValue)
  895. return true
  896. end
  897. -- 任务回调
  898. function onCallback(human, taskType, value)
  899. local actStartTime,actEndTime,groupID = getActStartTime()
  900. if not actStartTime then return end
  901. local mainTypes = getMainTypesByTaskType(taskType)
  902. if not mainTypes then return end
  903. checkDB(human, actStartTime,groupID)
  904. local isChange = nil
  905. for mainType, mainValue in pairs(mainTypes) do
  906. local mainValueType = type(mainValue)
  907. if mainValueType == "number" then
  908. if doCallback(human, actStartTime, mainType, taskType, mainValue, nil, value) then
  909. isChange = true
  910. end
  911. elseif mainValueType == "table" then
  912. for key, maxValue in pairs(mainValue) do
  913. if doCallback(human, actStartTime, mainType, taskType, maxValue, key, value) then
  914. isChange = true
  915. end
  916. end
  917. end
  918. end
  919. if isChange then
  920. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  921. Msg.send(Msg.gc.GC_HERO_GROWUP_TASK_REFRESH, human.fd)
  922. end
  923. return isChange
  924. end
  925. -- 任务回调 uuid
  926. local FakeHuman = {}
  927. function onCallbackByUuid(uuid, taskType, value)
  928. local db, online = RoleDBLogic.getDb(uuid)
  929. if not db then return end
  930. FakeHuman.db = db
  931. if onCallback(FakeHuman, taskType, value) and not online then
  932. RoleDBLogic.saveRole(db)
  933. end
  934. end
  935. function buyJifen(human,itemID,cnt)
  936. local actStartTime,actEndTime,groupID = getActStartTime()
  937. if not actStartTime then return end
  938. local now = os.time()
  939. if actEndTime - now > 3*86400 then
  940. return
  941. end
  942. checkDB(human, actStartTime,groupID)
  943. local config = ItemExcel.commonBuy[itemID]
  944. if not config then
  945. return
  946. end
  947. local price = config.price[2]*cnt
  948. if not ObjHuman.checkRMB(human,price) then
  949. return
  950. end
  951. ObjHuman.decZuanshi(human, - price, "hero_growup")
  952. addJifen(human, 1000*cnt)
  953. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_JIFEN
  954. msgRet.lv = human.db.heroGrowUp.lv or 0
  955. msgRet.jifen = human.db.heroGrowUp.jifen or 0
  956. msgRet.maxJifen = AbsActExcel.heroGrowUpLv[1].needJifen
  957. Msg.send(msgRet,human.fd)
  958. end
  959. -- 活动循环,开启与结束
  960. function actLoop()
  961. local workManStartTime,workManEndTime,groupID = getActStartTime()
  962. local workMan = CommonDB.getWorkMan()
  963. -- 活动未开,且commonDB活动开,则关闭活动
  964. if not workManStartTime and workMan.state then
  965. CommonDB.setWorkManState()
  966. return
  967. end
  968. -- 活动开,且commonDB活动未开,则开启活动
  969. -- 活动id不符
  970. if (workManStartTime and not workMan.state) or groupID ~= workMan.groupID then
  971. CommonDB.setWorkManState(true)
  972. CommonDB.setWorkManGroup(groupID)
  973. CommonDB.setWorkManTs(workManStartTime)
  974. --重置任务
  975. TASKTYPE_2_MAINTYPES = {}
  976. MAINTYPE_2_IDLIST = {}
  977. -- 设置新任务
  978. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  979. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  980. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  981. end
  982. if not MAINTYPE_2_IDLIST[cf.mainType] then
  983. MAINTYPE_2_IDLIST[cf.mainType] = {}
  984. end
  985. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  986. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  987. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  988. local value = cf.taskArgs[1]
  989. local key = cf.taskArgs[2]
  990. if type(cf.taskArgs[2]) == "table" then
  991. local lenth = #cf.taskArgs[2]
  992. local randomPos = math.random(1,lenth)
  993. key = cf.taskArgs[2][randomPos]
  994. end
  995. if key then
  996. list[cf.mainType] = list[cf.mainType] or {}
  997. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  998. else
  999. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  1000. end
  1001. end
  1002. GROUPID_2_LVCONFIGS = {}
  1003. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  1004. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  1005. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  1006. end
  1007. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  1008. end
  1009. return
  1010. end
  1011. end