MonsterHunt.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. MonsterHunt = {}
  2. local this = {}
  3. local VAR = {
  4. --积分存储
  5. MONSTER_HUNT_INTEGRAL = "R$_MONSTER_HUNT_INTEGRAL",
  6. --时间记录
  7. MONSTER_HUNT_TIME_INFO = "R$_MONSTER_HUNT_TIME_INFO",
  8. --重置状态
  9. MONSTER_HUNT_STATE = "R$_MONSTER_HUNT_STATE",
  10. --通知刷新次数
  11. MONSTER_HUNT_NOTICE_COUNT = "G$MONSTER_HUNT_NOTICE_COUNT",
  12. }
  13. local GLOBAL_ID = {
  14. INTEGRAL_2_MEDAL = 27001,
  15. TIME = 27002,
  16. GET_EXTRA_HIGH_LIMIT = 27005,
  17. SEASON_SETTLE = 27006,
  18. }
  19. --猎魔勋章的道具ID
  20. local MEDAL_ITEM_ID = 10230001
  21. local STATE_OK = 0
  22. local STATE_DENY = 1
  23. function this.getTimeInfo(actor)
  24. actor = this.getActor(actor)
  25. local timeInfo = getsysvar(actor,VAR.MONSTER_HUNT_TIME_INFO)
  26. if timeInfo == nil then
  27. return {
  28. settleTime = nil,
  29. resetTime = nil
  30. }
  31. else
  32. return timeInfo
  33. end
  34. end
  35. function this.setTimeInfo(timeInfo)
  36. setsysvar(VAR.MONSTER_HUNT_TIME_INFO, timeInfo)
  37. end
  38. function this.getState(actor)
  39. actor = this.getActor(actor)
  40. local state = getsysvar(actor,VAR.MONSTER_HUNT_STATE)
  41. return state or 0
  42. end
  43. function this.getNoticeCount()
  44. return getsysvar(VAR.MONSTER_HUNT_NOTICE_COUNT) or 0
  45. end
  46. function this.setNoticeCount(count)
  47. setsysvar(VAR.MONSTER_HUNT_NOTICE_COUNT, count)
  48. end
  49. function this.setState(state)
  50. setsysvar(VAR.MONSTER_HUNT_STATE, state)
  51. end
  52. function this.addIntegral(actor, integral)
  53. callonserial(actor, "monsterhurt_add_integral", integral)
  54. end
  55. function this.clearAllMedal()
  56. local roles = getallrolesummaryinfos()
  57. if roles then
  58. for _, role in ipairs(roles) do
  59. local actor = role["actor"]
  60. local count = getbagitemcountbyid(actor, MEDAL_ITEM_ID) or 0
  61. if count > 0 then
  62. removeitemfrombag(actor, MEDAL_ITEM_ID, count)
  63. end
  64. end
  65. end
  66. end
  67. function monsterhurt_clear_all_data()
  68. this.setTimeInfo(nil)
  69. this.setState(STATE_OK)
  70. this.setNoticeCount(0)
  71. this.setIntegralInfo(nil, nil)
  72. this.clearAllMedal()
  73. end
  74. function monsterhurt_add_integral(actor, integral)
  75. local allIntegralInfo = getsysvar(actor,VAR.MONSTER_HUNT_INTEGRAL)
  76. if allIntegralInfo == nil then
  77. allIntegralInfo = {}
  78. end
  79. local rid = tonumber(actor:toString())
  80. local actorInfo = allIntegralInfo[rid]
  81. if actorInfo == nil then
  82. actorInfo = {}
  83. allIntegralInfo[rid] = actorInfo
  84. end
  85. local oldIntegral = actorInfo["integral"] or 0
  86. oldIntegral = oldIntegral + tonumber(integral)
  87. actorInfo["integral"] = oldIntegral
  88. actorInfo["time"] = getbaseinfo("now")
  89. --保存
  90. setsysvar(actor,VAR.MONSTER_HUNT_INTEGRAL, allIntegralInfo)
  91. this.loginfo("击杀怪物获得积分", actor, integral, oldIntegral)
  92. end
  93. function this.getIntegralInfo(actor)
  94. actor = this.getActor(actor)
  95. local allIntegralInfo = getsysvar(actor,VAR.MONSTER_HUNT_INTEGRAL)
  96. if allIntegralInfo == nil then
  97. allIntegralInfo = {}
  98. end
  99. return allIntegralInfo
  100. end
  101. function this.setIntegralInfo(actor,intervalInfo)
  102. actor = this.getActor(actor)
  103. setsysvar(actor, VAR.MONSTER_HUNT_INTEGRAL, intervalInfo)
  104. end
  105. function this.clearIntegralInfo()
  106. callonserial("monsterhurt_clear_integral_info")
  107. end
  108. function monsterhurt_clear_integral_info()
  109. setsysvar(VAR.MONSTER_HUNT_INTEGRAL, nil)
  110. end
  111. function this.getActor(actor)
  112. if actor == nil then
  113. return getactor(0,0)
  114. else
  115. return actor
  116. end
  117. end
  118. function this.monsterDie(ownerId, monsterCfgId)
  119. -- 不在赛季时间内不生效
  120. if not this.isSeasonTime() then
  121. return
  122. end
  123. local monsterHuntID = ConfigDataManager.getTableValue("cfg_monster", "monsterhunt", "id", monsterCfgId)
  124. if string.isNullOrEmpty(monsterHuntID) then
  125. return
  126. end
  127. local config = ConfigDataManager.getById("cfg_monsterHunt", tonumber(monsterHuntID))
  128. if config == nil then
  129. return
  130. end
  131. if ownerId == nil or tonumber(ownerId) <= 0 then
  132. this.logerror("怪物击杀者为空", ownerId, monsterCfgId)
  133. return
  134. end
  135. local actor = getactor(tonumber(ownerId))
  136. local state = this.getState(actor)
  137. if state == STATE_DENY then
  138. this.loginfo("重置之前不积累积分")
  139. return
  140. end
  141. local strLevel = config["level"]
  142. local strNum = config["number"]
  143. local selfLevel = getbaseinfo(actor, "level")
  144. local levelPair = string.split(strLevel, "|")
  145. local index = 0
  146. for i, levelStr in pairs(levelPair) do
  147. local lowHigh = string.split(levelStr, "#")
  148. local low = tonumber(lowHigh[1])
  149. local high = tonumber(lowHigh[2])
  150. if low <= selfLevel and selfLevel <= high then
  151. index = i
  152. break
  153. end
  154. end
  155. if index == 0 then
  156. return
  157. end
  158. local strNums = string.split(strNum, "#")
  159. local strNum = strNums[index]
  160. if strNum == nil then
  161. return
  162. end
  163. local num = tonumber(strNum)
  164. --增加积分
  165. this.addIntegral(actor, num)
  166. end
  167. function this.isSeasonTime()
  168. local value = ConfigDataManager.getTableValue("cfg_global","value", "id", GLOBAL_ID.SEASON_SETTLE)
  169. if string.isNullOrEmpty(value) then
  170. return true
  171. end
  172. local seasons = string.split(value, "|")
  173. for _, seasonInfo in ipairs(seasons) do
  174. local beginTime = string.split(string.split(seasonInfo, "&")[2], "#")
  175. local endTime = string.split(string.split(seasonInfo, "&")[3], "#")
  176. local beginSec = this.convertToTimestamp(tonumber(beginTime[1]), tonumber(beginTime[2]), tonumber(beginTime[3]), tonumber(beginTime[4]))
  177. local endSec = this.convertToTimestamp(tonumber(endTime[1]), tonumber(endTime[2]), tonumber(endTime[3]), tonumber(endTime[4]))
  178. local nowSec = getbaseinfo("nowsec")
  179. if nowSec >= beginSec and nowSec <= endSec then
  180. return true
  181. end
  182. end
  183. return false
  184. end
  185. function this.convertToTimestamp(year, month, day, hour)
  186. return os.time({
  187. year = year,
  188. month = month,
  189. day = day,
  190. hour = hour or 0,
  191. min = 0,
  192. sec = 0
  193. })
  194. end
  195. --获得积分和勋章的转换比
  196. function this.medalScaleByIntegral(integral)
  197. local globalCfg = ConfigDataManager.getTableValue("cfg_global", "value", "id", GLOBAL_ID.INTEGRAL_2_MEDAL)
  198. if globalCfg == nil then
  199. return 0
  200. end
  201. local items = string.split(globalCfg, "|")
  202. local prevKv;
  203. local prevK = 0
  204. local prevV = 0
  205. local currK = 0
  206. local currV = 0
  207. for _, curr in pairs(items) do
  208. local currKv = string.split(curr, "#")
  209. if prevKv ~= nil then
  210. prevK = tonumber(prevKv[1])
  211. prevV = tonumber(prevKv[2])
  212. currK = tonumber(currKv[1])
  213. currV = tonumber(currKv[2])
  214. if integral >= prevK and integral <= currK then
  215. return prevV
  216. end
  217. end
  218. prevKv = currKv
  219. end
  220. return currV
  221. end
  222. function this.getTimeConfig()
  223. local timeCfg = ConfigDataManager.getTableValue("cfg_global", "value", "id", GLOBAL_ID.TIME)
  224. if string.isNullOrEmpty(timeCfg) then
  225. return nil
  226. end
  227. local items = string.split(timeCfg, "#")
  228. if table.isNullOrEmpty(items) then
  229. return nil
  230. end
  231. return tonumber(items[1]), tonumber(items[2])
  232. end
  233. function this.checkTimeInMinuteHeart(hour, settleHour, settleTime)
  234. if tonumber(hour) ~= tonumber(settleHour) then
  235. --不在刷新的时间点
  236. return false
  237. end
  238. if settleTime ~= nil and settleTime > 0 then
  239. local now = getbaseinfo("now")
  240. local diff = datediff(tonumber(settleTime), now, "day")
  241. if diff == 0 then
  242. --刷新过了
  243. return false
  244. end
  245. end
  246. return true
  247. end
  248. function this.getRankList(integralInfo)
  249. local medalTotal = 0
  250. local integralTotal = 0
  251. local rankList = {}
  252. local index = 0
  253. for id, roleIntegralInfo in pairs(integralInfo) do
  254. local integral = roleIntegralInfo["integral"] or 0
  255. local time = roleIntegralInfo["time"] or 0
  256. if integral > 0 then
  257. integralTotal = integralTotal + integral
  258. table.insert(rankList, { rid = id, integral = integral, time=time })
  259. end
  260. end
  261. --计算勋章总数
  262. local medalScale = this.medalScaleByIntegral(integralTotal) or 0
  263. medalTotal = math.floor(integralTotal * medalScale / 10000)
  264. --计算排名
  265. table.sort(rankList, function(a, b)
  266. if a.integral == b.integral then
  267. return a.time < b.time
  268. else
  269. return a.integral > b.integral
  270. end
  271. end)
  272. for _, rankItem in pairs(rankList) do
  273. index = index + 1
  274. rankItem["rank"] = index
  275. end
  276. local rewardPercentTotal = this.getSumRewardPercentByRankList(rankList)
  277. for _, rankItem in pairs(rankList) do
  278. local rankNum = rankItem.rank
  279. local percent, _ = this.getRewardPercentByRank(rankNum)
  280. local scale = percent / rewardPercentTotal
  281. local medalCount = math.floor( medalTotal * scale )
  282. rankItem["medalCount"] = medalCount
  283. --this.loginfo("id", rankItem.rid, "排名", rankNum, "瓜分比例", scale, "瓜分比率", percent, "总比率", rewardPercentTotal,"积分",rankItem.integral, "瓜分勋章数量", medalCount, "总勋章数量", medalTotal)
  284. end
  285. return rankList, medalTotal,integralTotal
  286. end
  287. function this.getSumRewardPercentByRankList(rankList)
  288. local total = 0
  289. for _, rankItem in pairs(rankList) do
  290. local rankNum = rankItem.rank
  291. local percent, _ = this.getRewardPercentByRank(rankNum)
  292. total = total + percent
  293. end
  294. return total
  295. end
  296. --是否能获得额外的积分
  297. function this.isGetExtra(selfIntegral)
  298. local highLimit = ConfigDataManager.getTableValue("cfg_global", "value", "id", GLOBAL_ID.GET_EXTRA_HIGH_LIMIT)
  299. if string.isNullOrEmpty(highLimit) then
  300. return false
  301. end
  302. return selfIntegral >= tonumber(highLimit)
  303. end
  304. --结算
  305. function this.Settle(hour, settleHour)
  306. if this.getState() == STATE_DENY then
  307. this.loginfo("未重置状态下不能结算")
  308. return
  309. end
  310. local timeInfo = this.getTimeInfo()
  311. local settleTime = timeInfo.settleTime
  312. local ok = this.checkTimeInMinuteHeart(hour, settleHour, settleTime)
  313. this.loginfo("是否可以结算", ok, timeInfo)
  314. if not ok then
  315. return
  316. end
  317. --先把状态改掉
  318. this.setState(STATE_DENY)
  319. --执行结算
  320. local integralInfo = this.getIntegralInfo(nil)
  321. local rankList, medalTotal,integralTotal = this.getRankList(integralInfo)
  322. this.loginfo("结算数据", medalTotal, rankList)
  323. if medalTotal == 0 then
  324. this.loginfo("可分配的勋章数量为0", medalTotal, rankList)
  325. return
  326. end
  327. local rankMap = {}
  328. for rankNum, rankItem in pairs(rankList) do
  329. local item = rankMap[rankNum]
  330. if item == nil then
  331. item = {}
  332. rankMap[rankNum] = item
  333. end
  334. table.insert(item, rankItem)
  335. end
  336. this.loginfo("rankMap", rankMap)
  337. for rankNum, idList in pairs(rankMap) do
  338. local percent, item, extraMedalCount = this.getRewardPercentByRank(rankNum)
  339. if percent >= 0 then
  340. for _, rankItem in pairs(idList) do
  341. local rid = rankItem.rid
  342. local integral = rankItem.integral
  343. local medalCount = rankItem.medalCount
  344. local rewardMap = {}
  345. if not string.isNullOrEmpty(extraMedalCount) and this.isGetExtra(integral) then
  346. medalCount = medalCount + tonumber(extraMedalCount)
  347. end
  348. rewardMap[MEDAL_ITEM_ID] = medalCount
  349. if not string.isNullOrEmpty(item) then
  350. local itemMap = string.toIntIntMap(item, "#", "|")
  351. if itemMap ~= nil then
  352. table.mergeTable(rewardMap, itemMap)
  353. else
  354. error("奖励配置格式格式错误", item)
  355. end
  356. end
  357. this.sendRewardToMail(getactor(rid),rid,rankItem.time,medalTotal,integralTotal , rankNum, integral, medalCount, rewardMap)
  358. end
  359. end
  360. end
  361. --设置结算时间
  362. local timeInfo = this.getTimeInfo()
  363. timeInfo.settleTime = getbaseinfo("now")
  364. this.setTimeInfo(timeInfo)
  365. end
  366. --重置
  367. function this.Reset(hour, resetHour)
  368. local timeInfo = this.getTimeInfo()
  369. local resetTime = timeInfo.resetTime
  370. local ok = this.checkTimeInMinuteHeart(hour, resetHour, resetTime)
  371. this.loginfo("是否可以重置", ok, timeInfo)
  372. if not ok then
  373. return
  374. end
  375. this.clearIntegralInfo()
  376. local timeInfo = this.getTimeInfo()
  377. timeInfo.resetTime = getbaseinfo("now")
  378. this.setTimeInfo(timeInfo)
  379. this.setState(STATE_OK)
  380. this.loginfo("重置完成,打印相关数据", this.getTimeInfo(), this.getIntegralInfo(nil), this.getState())
  381. end
  382. function this.sendRewardToMail(actor,rid,time,medalTotal, integralTotal, rank, integral, medalCount, rewardMap)
  383. local config = ConfigDataManager.getById("cfg_mail", MailConfig.MONSTER_HUNT_INTEGRAL)
  384. if config == nil then
  385. this.logerror(actor, "奖励邮件配置不存在", MailConfig.MONSTER_HUNT_INTEGRAL)
  386. this.loginfo("奖励入包", actor, rank, integral, medalCount, rewardMap)
  387. additemmaptobag(actor, rewardMap, 0, 9999, "猎魔积分")
  388. else
  389. -- local title = config["title"]
  390. -- local content = config["content"]
  391. -- content = string.format(content, integralTotal, medalTotal, rank, medalCount)
  392. -- sendmail(actor, title, content, rewardMap)
  393. sendconfigmailbyrid(actor, rid, MailConfig.MONSTER_HUNT_INTEGRAL, rewardMap,
  394. integralTotal .. "#" .. medalTotal .. "#" .. rank .. "#" .. medalCount)
  395. this.loginfo("发送奖励邮件", actor, rewardMap)
  396. end
  397. --记录日志
  398. gameDebug.debug(this.saveLog,actor,time,integral, medalCount, rank)
  399. end
  400. function this.saveLog(actor,time,integral,medalCount,rank)
  401. local roleName = getbaseinfo(actor, "rolename")
  402. local level = getbaseinfo(actor, "level")
  403. local lastLoginTime = getbaseinfo(actor, "logintime")
  404. local loginLong = getbaseinfo(actor, "loginlong") / 60
  405. local rechargeTotal = RechargeRecord.getTotalCount(actor)
  406. local lastGetIntegralTime = os.date('%Y-%m-%d %H:%M:%S', math.floor(time / 1000))
  407. logBody = {}
  408. logBody["角色名字"] = roleName
  409. logBody["等级"] = level
  410. logBody["最后登录时间"] = lastLoginTime
  411. logBody["登录时长"] = loginLong
  412. logBody["充值金额"] = rechargeTotal
  413. logBody["最后获得积分时间"] = lastGetIntegralTime
  414. logBody["杀怪积分"] = integral
  415. logBody["勋章数量"] = medalCount
  416. logBody["排名"] = rank
  417. local logContent = ""
  418. for k, v in pairs(logBody) do
  419. logContent = logContent .. k .. "=" .. v .. ","
  420. end
  421. logContent = string.sub(logContent,1, string.len(logContent) - 1)
  422. logop(actor, LogOpType.MONSTER_HUNT, logContent)
  423. end
  424. function this.getRewardPercentByRank(rank)
  425. local configList = ConfigDataManager.getTable("cfg_monsterHuntReward")
  426. local selfScale = 0
  427. local otherReward = nil
  428. local extraMedalCount = nil
  429. for _, config in pairs(configList) do
  430. local ranks = string.split(config.rank, "#")
  431. local rewardScale = tonumber(config.reward)
  432. local lowRank = tonumber(ranks[1])
  433. local highRank = tonumber(ranks[2])
  434. if lowRank <= rank and rank <= highRank then
  435. selfScale = rewardScale
  436. otherReward = config.item
  437. extraMedalCount = config.extra
  438. end
  439. end
  440. --this.loginfo("根据排名获得奖励比率", rank, selfScale, otherReward, extraMedalCount)
  441. return selfScale, otherReward,extraMedalCount
  442. end
  443. function this.checkSettleAndReset()
  444. local serverType = getbaseinfo("servertype")
  445. if serverType == 2 then
  446. --跨服不用结算
  447. return
  448. end
  449. local settleHour, resetHour = this.getTimeConfig()
  450. this.loginfo("检查结算和重置", settleHour, resetHour)
  451. if settleHour == nil or resetHour == nil then
  452. return
  453. end
  454. local hour = getbaseinfo("hour")
  455. this.Settle(hour, settleHour)
  456. this.Reset(hour, resetHour)
  457. end
  458. function this.buildOneRole(id)
  459. local actor = getactor(id)
  460. local role = {}
  461. role["career"] = getbaseinfo(actor, "getbasecareer")
  462. role["name"] = getbaseinfo(actor, "rolename")
  463. local serverId = getbaseinfo(actor, "originalserverid")
  464. role["serverid"] = serverId
  465. role["online"] = getbaseinfo(actor, "onlinestate")
  466. return role
  467. end
  468. function this.rankList(actor)
  469. local integralInfo = this.getIntegralInfo(actor)
  470. local rankList,medalTotal,integralTotal = this.getRankList(integralInfo)
  471. local resRankList = {}
  472. for _, rankItem in pairs(rankList) do
  473. local newItem = {
  474. rid = rankItem.rid,
  475. integral = rankItem.integral,
  476. medal= rankItem.medalCount,
  477. rank = rankItem.rank,
  478. roleInfo = this.buildOneRole(rankItem.rid)
  479. }
  480. table.insert(resRankList, newItem)
  481. end
  482. this.loginfo(actor, "总勋章数量", tostring(medalTotal),"总积分数量",integralTotal,"榜列表", resRankList)
  483. sendluamsg(actor, LuaMessageIdToClient.RES_MONSTER_HUNT_RANK, resRankList)
  484. end
  485. function this.notice()
  486. local serverType = getbaseinfo("servertype")
  487. if serverType == 2 then
  488. --跨服不用结算
  489. return
  490. end
  491. local count = this.getNoticeCount()
  492. count = count + 1
  493. this.setNoticeCount(count)
  494. if count % 5 == 0 then
  495. --每5分中发送通知
  496. this.sendNotice()
  497. end
  498. end
  499. function this.getNameByIndex(rankList, index)
  500. if table.isNullOrEmpty(rankList) then
  501. return ""
  502. end
  503. if #rankList >= index then
  504. local item = rankList[index]
  505. local rid = item.rid
  506. local actor = getactor(rid)
  507. local name = getbaseinfo(actor, "rolename")
  508. return name
  509. end
  510. return ""
  511. end
  512. function this.sendNotice()
  513. local integralInfo = this.getIntegralInfo(nil)
  514. local rankList = this.getRankList(integralInfo)
  515. local first = this.getNameByIndex(rankList, 1)
  516. local second = this.getNameByIndex(rankList, 2)
  517. local third = this.getNameByIndex(rankList, 3)
  518. local allplayer = getallplayer()
  519. for _, id in pairs(allplayer) do
  520. local actor = getactor(id)
  521. noticeTip.noticeinfo(actor, StringIdConst.TEXT27001, first, second, third)
  522. end
  523. end
  524. function this.info(actor)
  525. if not this.isSeasonTime() then
  526. sendluamsg(actor, LuaMessageIdToClient.RES_MONSTER_HUNT_INFO, {settleSec = 0, resetSec= 0})
  527. return
  528. end
  529. local settleHour, resetHour = this.getTimeConfig()
  530. local res
  531. if settleHour == nil or resetHour == nil then
  532. res = {
  533. settleSec= 0,
  534. resetSec= 0
  535. }
  536. else
  537. local timeInfo = this.getTimeInfo(actor)
  538. local settleSec = this.getTargetDateTimeSec(settleHour, timeInfo.settleTime)
  539. local resetSec = this.getTargetDateTimeSec(resetHour, timeInfo.resetTime)
  540. res = {
  541. settleSec= settleSec,
  542. resetSec= resetSec
  543. }
  544. end
  545. this.loginfo("信息", res)
  546. sendluamsg(actor, LuaMessageIdToClient.RES_MONSTER_HUNT_INFO, res)
  547. end
  548. --今天是否刷过了
  549. function this.todayIsRefresh(prevRefreshTimeMills)
  550. if prevRefreshTimeMills == nil or prevRefreshTimeMills <= 0 then
  551. return false
  552. end
  553. --this.loginfo("prevRefreshTimeMills", prevRefreshTimeMills, type(prevRefreshTimeMills))
  554. local now = getbaseinfo("now")
  555. local diffDays = datediff(now, prevRefreshTimeMills, "day")
  556. return diffDays == 0
  557. end
  558. function this.getTargetDateTimeSec(hour, prevRefreshTimeMills)
  559. local dateTimeFormat = "%s-%s-%s %s:%s:%s"
  560. local now = getbaseinfo("now")
  561. local target
  562. local todayIsRefresh = this.todayIsRefresh(prevRefreshTimeMills)
  563. if todayIsRefresh then
  564. --加一天
  565. target = dateadd(now, 1)
  566. else
  567. local y = year(now)
  568. local m = month(now)
  569. local d = day(now)
  570. local dateTimeString = string.format(dateTimeFormat, y, m, d, hour, 0, 0)
  571. local t = timestamp(dateTimeString)
  572. if t > now then
  573. this.loginfo("刷新间隔计算1", todayIsRefresh, dateTimeString, t, now )
  574. --今天刷
  575. --return datediff(t,now, "second")
  576. return math.round(t / 1000)
  577. else
  578. --明天刷
  579. target = dateadd(now, 1)
  580. end
  581. end
  582. local y = year(target)
  583. local m = month(target)
  584. local d = day(target)
  585. local dateTimeString = string.format(dateTimeFormat, y, m, d, hour, 0, 0)
  586. local t = timestamp(dateTimeString)
  587. this.loginfo("刷新间隔计算2", todayIsRefresh, dateTimeString, t, now )
  588. --return datediff(t,now, "second")
  589. return math.round(t / 1000)
  590. end
  591. function this.loginfo(...)
  592. info("[猎魔勋章]", ...)
  593. end
  594. function this.logerror(...)
  595. error("[猎魔勋章]", ...)
  596. end
  597. function MonsterHunt.GetMonsterHuntIntegralKey()
  598. return VAR.MONSTER_HUNT_INTEGRAL;
  599. end
  600. function MonsterHunt.CombineMonsterHuntIntegral(varData)
  601. if table.isNullOrEmpty(varData) then
  602. return
  603. end
  604. this.loginfo("猎魔积分合服数据", varData)
  605. local currIntegralInfo = this.getIntegralInfo(nil)
  606. for sid, integralInfo in pairs(varData) do
  607. table.merge(currIntegralInfo, integralInfo)
  608. end
  609. this.setIntegralInfo(nil, currIntegralInfo)
  610. end
  611. --怪物死亡触发
  612. function MonsterHunt.MonsterDie(ownerId, monsterCfgId)
  613. gameDebug.debug(this.monsterDie, ownerId, monsterCfgId)
  614. end
  615. --结算
  616. function MonsterHunt.CheckSettleAndReset()
  617. gameDebug.debug(this.checkSettleAndReset)
  618. end
  619. function MonsterHunt.Notice()
  620. gameDebug.debug(this.notice)
  621. end
  622. function MonsterHunt.RankList(actor)
  623. gameDebug.debug(this.rankList, actor)
  624. end
  625. --@lua monsterhuntinfo
  626. function MonsterHunt.Info(actor)
  627. gameDebug.debug(this.info, actor)
  628. end
  629. --- func desc 检查赛季是否结束
  630. function MonsterHunt.checkSeason()
  631. local value = ConfigDataManager.getTableValue("cfg_global","value", "id", GLOBAL_ID.SEASON_SETTLE)
  632. if string.isNullOrEmpty(value) then
  633. return
  634. end
  635. local seasons = string.split(value, "|")
  636. for _, seasonInfo in ipairs(seasons) do
  637. local timeInfo = string.split(string.split(seasonInfo, "&")[3], "#")
  638. local year = tonumber(timeInfo[1])
  639. local month = tonumber(timeInfo[2])
  640. local day = tonumber(timeInfo[3])
  641. local hour = tonumber(timeInfo[4])
  642. local nowSec = getbaseinfo("nowsec")
  643. local date = TimeUtil.timeToDate(nowSec)
  644. if date.year == year and date.month == month and date.day == day and date.hour == hour and date.min == 0 then
  645. info("猎魔赛季结算, 重置所有数据, year-",year,"month-",month,"day-",day,"hour-",hour)
  646. callonserial("monsterhurt_clear_all_data")
  647. -- this.resetAllData()
  648. break
  649. end
  650. end
  651. end
  652. --打印排行榜列表
  653. --@lua monsterhuntranklist
  654. function monsterhuntranklist(actor)
  655. this.rankList(actor)
  656. end
  657. --@lua monsterhuntchecksettleandreset
  658. function monsterhuntchecksettleandreset()
  659. this.checkSettleAndReset()
  660. end
  661. --@lua monsterhuntsendnotice
  662. function monsterhuntsendnotice()
  663. this.sendNotice()
  664. end
  665. -- @lua monsterhuntinfo
  666. function monsterhuntinfo(actor)
  667. this.info(actor)
  668. end
  669. -- @createMonster 80006
  670. -- @lua monstercleartimeinfo
  671. function monstercleartimeinfo(actor)
  672. this.setTimeInfo(nil)
  673. this.setState(nil)
  674. end
  675. --- func desc
  676. ---@param actor any
  677. function clall(actor)
  678. callonserial("monsterhurt_clear_all_data")
  679. end
  680. --- func desc
  681. ---@param actor any
  682. function allhunt(actor)
  683. local timeInfo = getsysvar(actor,VAR.MONSTER_HUNT_TIME_INFO)
  684. local state = getsysvar(actor,VAR.MONSTER_HUNT_STATE)
  685. local count = getsysvar(VAR.MONSTER_HUNT_NOTICE_COUNT) or 0
  686. local allIntegralInfo = getsysvar(actor,VAR.MONSTER_HUNT_INTEGRAL)
  687. lg("时间信息:",timeInfo,"状态:",state,"通知次数:",count,"积分信息:",allIntegralInfo)
  688. end