HeroGrowUp.lua 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  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. if exRewardNet.state ~= 1 and nowLv - maxLv > 0 and (nowLv - maxLv) % lvdefine.lastNeedLv == 0 then
  730. exRewardNet.state = 2
  731. end
  732. nextLv = maxLv + lvdefine.lastNeedLv
  733. while true do
  734. if nextLv > nowLv then
  735. break
  736. end
  737. local nextState = getGetExReward(human,nextLv)
  738. if not nextState or nextState == 1 then
  739. break
  740. end
  741. nextLv = nextLv + lvdefine.lastNeedLv
  742. end
  743. exRewardNet.exLv = nextLv
  744. exRewardNet.stateEx = getGetExReward(human,nextLv)
  745. local isBuy = isBuyKing(human)
  746. if isBuy ~= 1 then
  747. exRewardNet.stateEx = 0
  748. end
  749. if exRewardNet.stateEx ~= 1 and nowLv - maxLv > 0 and (nowLv - maxLv) % lvdefine.lastNeedLv == 0 then
  750. exRewardNet.stateEx = 2
  751. end
  752. for i = 1, exRewardNet.items[0] do
  753. local itemID = lvdefine.lastItems[i][1]
  754. local itemCnt = lvdefine.lastItems[i][2]
  755. Grid.makeItem(exRewardNet.items[i], itemID, itemCnt)
  756. end
  757. exRewardNet.itemsKing[0] = #lvdefine.lastItemsKing
  758. for i = 1, exRewardNet.itemsKing[0] do
  759. local itemID = lvdefine.lastItemsKing[i][1]
  760. local itemCnt = lvdefine.lastItemsKing[i][2]
  761. Grid.makeItem(exRewardNet.itemsKing[i], itemID, itemCnt)
  762. end
  763. --Msg.trace(msgRet)
  764. Msg.send(msgRet, human.fd)
  765. end
  766. -------------------------------------------- 回调 -------------------------------------------------------
  767. -- 升级回调
  768. function getLvReward(human, lv)
  769. local actStartTime,actEndTime, groupID = getActStartTime()
  770. if not groupID then
  771. return
  772. end
  773. local nowLv = getLv(human)
  774. if lv > nowLv then
  775. return
  776. end
  777. print("[getLvReward] 当前等级 nowLv = "..nowLv)
  778. -- local normalGet = getGetReward(human,lv)
  779. -- local exGet = getGetExReward(human,lv)
  780. local lvConfigs = getLvConfigs(groupID)
  781. if not lvConfigs then
  782. return
  783. end
  784. local lvdefine = lvConfigs[1]
  785. local list = {}
  786. local maxLv = #lvConfigs
  787. local isBuy = isBuyKing(human)
  788. for nLv = 1, nowLv, 1 do
  789. local normalGet = getGetReward(human, nLv)
  790. local exGet = getGetExReward(human, nLv)
  791. local cf = lvConfigs[nLv]
  792. local items = cf and cf.items
  793. local itemsKing = cf and cf.itemsKing
  794. if (not cf) and (nLv - maxLv) % lvdefine.lastNeedLv == 0 then
  795. items = lvdefine.lastItems
  796. itemsKing = lvdefine.lastItemsKing
  797. end
  798. if items and normalGet ~= 2 then
  799. for _, item in ipairs(items) do
  800. local itemID = item[1]
  801. local itemCnt = item[2]
  802. list[itemID] = (list[itemID] or 0) + itemCnt
  803. end
  804. setGetReward(human,nLv)
  805. end
  806. if itemsKing and isBuy == 1 and exGet ~= 2 then
  807. for _, item in ipairs(itemsKing) do
  808. local itemID = item[1]
  809. local itemCnt = item[2]
  810. list[itemID] = (list[itemID] or 0) + itemCnt
  811. end
  812. setGetExReward(human, nLv)
  813. end
  814. end
  815. if not next(list) then return end
  816. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  817. local msgRet = Msg.gc.GC_HERO_GROWUP_LVUP
  818. msgRet.lv = nowLv
  819. msgRet.items[0] = 0
  820. for itemID, itemCnt in pairs(list) do
  821. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  822. if msgRet.items[0] < #msgRet.items then
  823. msgRet.items[0] = msgRet.items[0] + 1
  824. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  825. end
  826. end
  827. BagLogic.sendItemGetList2(human, list)
  828. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  829. --Msg.trace(msgRet)
  830. Msg.send(msgRet, human.fd)
  831. end
  832. -- 购买王者礼包ii
  833. function buyKing(human)
  834. local actStartTime,actEndTime, groupID = getActStartTime()
  835. local lvConfigs = getLvConfigs(groupID)
  836. if not actStartTime then return end
  837. if not lvConfigs then
  838. return
  839. end
  840. local lvdefine = lvConfigs[1]
  841. checkDB(human, actStartTime,groupID)
  842. local isBuy = isBuyKing(human)
  843. if isBuy == 1 then return end
  844. setBuyKing(human, actStartTime)
  845. -- 计算可以给的东西
  846. -- local maxLv = #lvConfigs
  847. -- local nowLv = getLv(human)
  848. -- local list = {}
  849. -- for lv = 1, nowLv do
  850. -- local cf = lvConfigs[lv]
  851. -- local itemsKing = cf and cf.itemsKing
  852. -- if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv then
  853. -- itemsKing = lvdefine.lastItemsKing
  854. -- end
  855. -- if itemsKing then
  856. -- for _, item in ipairs(itemsKing) do
  857. -- local itemID = item[1]
  858. -- local itemCnt = item[2]
  859. -- list[itemID] = (list[itemID] or 0) + itemCnt
  860. -- end
  861. -- end
  862. -- end
  863. local list = {}
  864. local config = lvdefine.kingBuyItems
  865. if isBuy then
  866. config = lvdefine.kingBuyItems2
  867. end
  868. -- 购买王者后直接赠送的东西
  869. for _, item in ipairs(config) do
  870. local itemID = item[1]
  871. local itemCnt = item[2]
  872. list[itemID] = (list[itemID] or 0) + itemCnt
  873. end
  874. -- 给东西
  875. for itemID, itemCnt in pairs(list) do
  876. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  877. end
  878. BagLogic.sendItemGetList2(human, list)
  879. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  880. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_OK
  881. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  882. Msg.send(msgRet, human.fd)
  883. sendRewardQuery(human)
  884. end
  885. -- 子回调
  886. local function doCallback(human, actStartTime, mainType, taskType, maxValue, key, value)
  887. local oldValue = getValueByKey(human, mainType, taskType, key)
  888. if oldValue >= maxValue then
  889. return
  890. end
  891. local newValue = oldValue
  892. -- 任务类型11 指定英雄 竞技场胜利指定次数
  893. if taskType == TASKTYPE11 then
  894. local isFind = nil
  895. for _, obj in pairs(value.objList) do
  896. if obj.side == CombatDefine.ATTACK_SIDE and
  897. obj.id == key then
  898. isFind = true
  899. break
  900. end
  901. end
  902. if not isFind then return end
  903. newValue = oldValue + 1
  904. elseif taskType == TASKTYPE12 then
  905. if key ~= value then
  906. return
  907. end
  908. newValue = oldValue + 1
  909. elseif taskType == TASKTYPE14 then
  910. if value > key then
  911. return
  912. end
  913. newValue = oldValue + 1
  914. else
  915. newValue = math.min(oldValue + value, maxValue)
  916. end
  917. updateValue(human, actStartTime, mainType, taskType, key, newValue)
  918. return true
  919. end
  920. -- 任务回调
  921. function onCallback(human, taskType, value)
  922. local actStartTime,actEndTime,groupID = getActStartTime()
  923. if not actStartTime then return end
  924. local mainTypes = getMainTypesByTaskType(taskType)
  925. if not mainTypes then return end
  926. checkDB(human, actStartTime,groupID)
  927. local isChange = nil
  928. for mainType, mainValue in pairs(mainTypes) do
  929. local mainValueType = type(mainValue)
  930. if mainValueType == "number" then
  931. if doCallback(human, actStartTime, mainType, taskType, mainValue, nil, value) then
  932. isChange = true
  933. end
  934. elseif mainValueType == "table" then
  935. for key, maxValue in pairs(mainValue) do
  936. if doCallback(human, actStartTime, mainType, taskType, maxValue, key, value) then
  937. isChange = true
  938. end
  939. end
  940. end
  941. end
  942. if isChange then
  943. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  944. Msg.send(Msg.gc.GC_HERO_GROWUP_TASK_REFRESH, human.fd)
  945. end
  946. return isChange
  947. end
  948. -- 任务回调 uuid
  949. local FakeHuman = {}
  950. function onCallbackByUuid(uuid, taskType, value)
  951. local db, online = RoleDBLogic.getDb(uuid)
  952. if not db then return end
  953. FakeHuman.db = db
  954. if onCallback(FakeHuman, taskType, value) and not online then
  955. RoleDBLogic.saveRole(db)
  956. end
  957. end
  958. function buyJifen(human,itemID,cnt)
  959. local actStartTime,actEndTime,groupID = getActStartTime()
  960. if not actStartTime then return end
  961. local now = os.time()
  962. if actEndTime - now > 3*86400 then
  963. return
  964. end
  965. checkDB(human, actStartTime,groupID)
  966. local config = ItemExcel.commonBuy[itemID]
  967. if not config then
  968. return
  969. end
  970. local price = config.price[2]*cnt
  971. if not ObjHuman.checkRMB(human,price) then
  972. return
  973. end
  974. ObjHuman.decZuanshi(human, - price, "hero_growup")
  975. addJifen(human, 1000*cnt)
  976. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_JIFEN
  977. msgRet.lv = human.db.heroGrowUp.lv or 0
  978. msgRet.jifen = human.db.heroGrowUp.jifen or 0
  979. msgRet.maxJifen = AbsActExcel.heroGrowUpLv[1].needJifen
  980. Msg.send(msgRet,human.fd)
  981. end
  982. -- 活动循环,开启与结束
  983. function actLoop()
  984. local workManStartTime,workManEndTime,groupID = getActStartTime()
  985. local workMan = CommonDB.getWorkMan()
  986. -- 活动未开,且commonDB活动开,则关闭活动
  987. if not workManStartTime and workMan.state then
  988. CommonDB.setWorkManState()
  989. return
  990. end
  991. -- 活动开,且commonDB活动未开,则开启活动
  992. -- 活动id不符
  993. if (workManStartTime and not workMan.state) or groupID ~= workMan.groupID then
  994. CommonDB.setWorkManState(true)
  995. CommonDB.setWorkManGroup(groupID)
  996. CommonDB.setWorkManTs(workManStartTime)
  997. --重置任务
  998. TASKTYPE_2_MAINTYPES = {}
  999. MAINTYPE_2_IDLIST = {}
  1000. -- 设置新任务
  1001. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  1002. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  1003. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  1004. end
  1005. if not MAINTYPE_2_IDLIST[cf.mainType] then
  1006. MAINTYPE_2_IDLIST[cf.mainType] = {}
  1007. end
  1008. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  1009. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  1010. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  1011. local value = cf.taskArgs[1]
  1012. local key = cf.taskArgs[2]
  1013. if type(cf.taskArgs[2]) == "table" then
  1014. local lenth = #cf.taskArgs[2]
  1015. local randomPos = math.random(1,lenth)
  1016. key = cf.taskArgs[2][randomPos]
  1017. end
  1018. if key then
  1019. list[cf.mainType] = list[cf.mainType] or {}
  1020. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  1021. else
  1022. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  1023. end
  1024. end
  1025. GROUPID_2_LVCONFIGS = {}
  1026. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  1027. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  1028. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  1029. end
  1030. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  1031. end
  1032. return
  1033. end
  1034. end