MonsterHunt.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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, 0, 9999, "猎魔勋章")
  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 =
  177. this.convertToTimestamp(
  178. tonumber(beginTime[1]),
  179. tonumber(beginTime[2]),
  180. tonumber(beginTime[3]),
  181. tonumber(beginTime[4])
  182. )
  183. local endSec =
  184. this.convertToTimestamp(
  185. tonumber(endTime[1]),
  186. tonumber(endTime[2]),
  187. tonumber(endTime[3]),
  188. tonumber(endTime[4])
  189. )
  190. local nowSec = getbaseinfo("nowsec")
  191. if nowSec >= beginSec and nowSec <= endSec then
  192. return true
  193. end
  194. end
  195. return false
  196. end
  197. function this.convertToTimestamp(year, month, day, hour)
  198. return os.time(
  199. {
  200. year = year,
  201. month = month,
  202. day = day,
  203. hour = hour or 0,
  204. min = 0,
  205. sec = 0
  206. }
  207. )
  208. end
  209. --获得积分和勋章的转换比
  210. function this.medalScaleByIntegral(integral)
  211. local globalCfg = ConfigDataManager.getTableValue("cfg_global", "value", "id", GLOBAL_ID.INTEGRAL_2_MEDAL)
  212. if globalCfg == nil then
  213. return 0
  214. end
  215. local items = string.split(globalCfg, "|")
  216. local prevKv
  217. local prevK = 0
  218. local prevV = 0
  219. local currK = 0
  220. local currV = 0
  221. for _, curr in pairs(items) do
  222. local currKv = string.split(curr, "#")
  223. if prevKv ~= nil then
  224. prevK = tonumber(prevKv[1])
  225. prevV = tonumber(prevKv[2])
  226. currK = tonumber(currKv[1])
  227. currV = tonumber(currKv[2])
  228. if integral >= prevK and integral <= currK then
  229. return prevV
  230. end
  231. end
  232. prevKv = currKv
  233. end
  234. return currV
  235. end
  236. function this.getTimeConfig()
  237. local timeCfg = ConfigDataManager.getTableValue("cfg_global", "value", "id", GLOBAL_ID.TIME)
  238. if string.isNullOrEmpty(timeCfg) then
  239. return nil
  240. end
  241. local items = string.split(timeCfg, "#")
  242. if table.isNullOrEmpty(items) then
  243. return nil
  244. end
  245. return tonumber(items[1]), tonumber(items[2])
  246. end
  247. function this.checkTimeInMinuteHeart(hour, settleHour, settleTime)
  248. if tonumber(hour) ~= tonumber(settleHour) then
  249. --不在刷新的时间点
  250. return false
  251. end
  252. if settleTime ~= nil and settleTime > 0 then
  253. local now = getbaseinfo("now")
  254. local diff = datediff(tonumber(settleTime), now, "day")
  255. if diff == 0 then
  256. --刷新过了
  257. return false
  258. end
  259. end
  260. return true
  261. end
  262. function this.getRankList(integralInfo)
  263. local medalTotal = 0
  264. local integralTotal = 0
  265. local rankList = {}
  266. local index = 0
  267. for id, roleIntegralInfo in pairs(integralInfo) do
  268. local integral = roleIntegralInfo["integral"] or 0
  269. local time = roleIntegralInfo["time"] or 0
  270. if integral > 0 then
  271. integralTotal = integralTotal + integral
  272. table.insert(rankList, {rid = id, integral = integral, time = time})
  273. end
  274. end
  275. --计算勋章总数
  276. local medalScale = this.medalScaleByIntegral(integralTotal) or 0
  277. medalTotal = math.floor(integralTotal * medalScale / 10000)
  278. --计算排名
  279. table.sort(
  280. rankList,
  281. function(a, b)
  282. if a.integral == b.integral then
  283. return a.time < b.time
  284. else
  285. return a.integral > b.integral
  286. end
  287. end
  288. )
  289. for _, rankItem in pairs(rankList) do
  290. index = index + 1
  291. rankItem["rank"] = index
  292. end
  293. local rewardPercentTotal = this.getSumRewardPercentByRankList(rankList)
  294. for _, rankItem in pairs(rankList) do
  295. local rankNum = rankItem.rank
  296. local percent, _ = this.getRewardPercentByRank(rankNum)
  297. local scale = percent / rewardPercentTotal
  298. local medalCount = math.floor(medalTotal * scale)
  299. rankItem["medalCount"] = medalCount
  300. --this.loginfo("id", rankItem.rid, "排名", rankNum, "瓜分比例", scale, "瓜分比率", percent, "总比率", rewardPercentTotal,"积分",rankItem.integral, "瓜分勋章数量", medalCount, "总勋章数量", medalTotal)
  301. end
  302. return rankList, medalTotal, integralTotal
  303. end
  304. function this.getSumRewardPercentByRankList(rankList)
  305. local total = 0
  306. for _, rankItem in pairs(rankList) do
  307. local rankNum = rankItem.rank
  308. local percent, _ = this.getRewardPercentByRank(rankNum)
  309. total = total + percent
  310. end
  311. return total
  312. end
  313. --是否能获得额外的积分
  314. function this.isGetExtra(selfIntegral)
  315. local highLimit = ConfigDataManager.getTableValue("cfg_global", "value", "id", GLOBAL_ID.GET_EXTRA_HIGH_LIMIT)
  316. if string.isNullOrEmpty(highLimit) then
  317. return false
  318. end
  319. return selfIntegral >= tonumber(highLimit)
  320. end
  321. --结算
  322. function this.Settle(hour, settleHour)
  323. if this.getState() == STATE_DENY then
  324. this.loginfo("未重置状态下不能结算")
  325. return
  326. end
  327. local timeInfo = this.getTimeInfo()
  328. local settleTime = timeInfo.settleTime
  329. local ok = this.checkTimeInMinuteHeart(hour, settleHour, settleTime)
  330. this.loginfo("是否可以结算", ok, timeInfo)
  331. if not ok then
  332. return
  333. end
  334. --先把状态改掉
  335. this.setState(STATE_DENY)
  336. --执行结算
  337. local integralInfo = this.getIntegralInfo(nil)
  338. local rankList, medalTotal, integralTotal = this.getRankList(integralInfo)
  339. this.loginfo("结算数据", medalTotal, rankList)
  340. if medalTotal == 0 then
  341. this.loginfo("可分配的勋章数量为0", medalTotal, rankList)
  342. return
  343. end
  344. local rankMap = {}
  345. for rankNum, rankItem in pairs(rankList) do
  346. local item = rankMap[rankNum]
  347. if item == nil then
  348. item = {}
  349. rankMap[rankNum] = item
  350. end
  351. table.insert(item, rankItem)
  352. end
  353. this.loginfo("rankMap", rankMap)
  354. for rankNum, idList in pairs(rankMap) do
  355. local percent, item, extraMedalCount = this.getRewardPercentByRank(rankNum)
  356. if percent >= 0 then
  357. for _, rankItem in pairs(idList) do
  358. local rid = rankItem.rid
  359. local integral = rankItem.integral
  360. local medalCount = rankItem.medalCount
  361. local rewardMap = {}
  362. if not string.isNullOrEmpty(extraMedalCount) and this.isGetExtra(integral) then
  363. medalCount = medalCount + tonumber(extraMedalCount)
  364. end
  365. rewardMap[MEDAL_ITEM_ID] = medalCount
  366. if not string.isNullOrEmpty(item) then
  367. local itemMap = string.toIntIntMap(item, "#", "|")
  368. if itemMap ~= nil then
  369. table.mergeTable(rewardMap, itemMap)
  370. else
  371. error("奖励配置格式格式错误", item)
  372. end
  373. end
  374. this.sendRewardToMail(
  375. getactor(rid),
  376. rid,
  377. rankItem.time,
  378. medalTotal,
  379. integralTotal,
  380. rankNum,
  381. integral,
  382. medalCount,
  383. rewardMap
  384. )
  385. end
  386. end
  387. end
  388. --设置结算时间
  389. local timeInfo = this.getTimeInfo()
  390. timeInfo.settleTime = getbaseinfo("now")
  391. this.setTimeInfo(timeInfo)
  392. end
  393. --重置
  394. function this.Reset(hour, resetHour)
  395. local timeInfo = this.getTimeInfo()
  396. local resetTime = timeInfo.resetTime
  397. local ok = this.checkTimeInMinuteHeart(hour, resetHour, resetTime)
  398. this.loginfo("是否可以重置", ok, timeInfo)
  399. if not ok then
  400. return
  401. end
  402. this.clearIntegralInfo()
  403. local timeInfo = this.getTimeInfo()
  404. timeInfo.resetTime = getbaseinfo("now")
  405. this.setTimeInfo(timeInfo)
  406. this.setState(STATE_OK)
  407. this.loginfo("重置完成,打印相关数据", this.getTimeInfo(), this.getIntegralInfo(nil), this.getState())
  408. end
  409. function this.sendRewardToMail(actor, rid, time, medalTotal, integralTotal, rank, integral, medalCount, rewardMap)
  410. local config = ConfigDataManager.getById("cfg_mail", MailConfig.MONSTER_HUNT_INTEGRAL)
  411. if config == nil then
  412. this.logerror(actor, "奖励邮件配置不存在", MailConfig.MONSTER_HUNT_INTEGRAL)
  413. this.loginfo("奖励入包", actor, rank, integral, medalCount, rewardMap)
  414. Bag.addItemMapToBag(actor, rewardMap, 0, 9999, "猎魔积分")
  415. else
  416. -- local title = config["title"]
  417. -- local content = config["content"]
  418. -- content = string.format(content, integralTotal, medalTotal, rank, medalCount)
  419. -- sendmail(actor, title, content, rewardMap)
  420. sendconfigmailbyrid(
  421. actor,
  422. rid,
  423. MailConfig.MONSTER_HUNT_INTEGRAL,
  424. rewardMap,
  425. integralTotal .. "#" .. medalTotal .. "#" .. rank .. "#" .. medalCount
  426. )
  427. this.loginfo("发送奖励邮件", actor, rewardMap)
  428. end
  429. --记录日志
  430. gameDebug.debug(this.saveLog, actor, time, integral, medalCount, rank)
  431. end
  432. function this.saveLog(actor, time, integral, medalCount, rank)
  433. local roleName = getbaseinfo(actor, "rolename")
  434. local level = getbaseinfo(actor, "level")
  435. local lastLoginTime = getbaseinfo(actor, "logintime")
  436. local loginLong = getbaseinfo(actor, "loginlong") / 60
  437. local rechargeTotal = RechargeRecord.getTotalCount(actor)
  438. local lastGetIntegralTime = os.date("%Y-%m-%d %H:%M:%S", math.floor(time / 1000))
  439. logBody = {}
  440. logBody["角色名字"] = roleName
  441. logBody["等级"] = level
  442. logBody["最后登录时间"] = lastLoginTime
  443. logBody["登录时长"] = loginLong
  444. logBody["充值金额"] = rechargeTotal
  445. logBody["最后获得积分时间"] = lastGetIntegralTime
  446. logBody["杀怪积分"] = integral
  447. logBody["勋章数量"] = medalCount
  448. logBody["排名"] = rank
  449. local logContent = ""
  450. for k, v in pairs(logBody) do
  451. logContent = logContent .. k .. "=" .. v .. ","
  452. end
  453. logContent = string.sub(logContent, 1, string.len(logContent) - 1)
  454. logop(actor, LogOpType.MONSTER_HUNT, logContent)
  455. end
  456. function this.getRewardPercentByRank(rank)
  457. local configList = ConfigDataManager.getTable("cfg_monsterHuntReward")
  458. local selfScale = 0
  459. local otherReward = nil
  460. local extraMedalCount = nil
  461. for _, config in pairs(configList) do
  462. local ranks = string.split(config.rank, "#")
  463. local rewardScale = tonumber(config.reward)
  464. local lowRank = tonumber(ranks[1])
  465. local highRank = tonumber(ranks[2])
  466. if lowRank <= rank and rank <= highRank then
  467. selfScale = rewardScale
  468. otherReward = config.item
  469. extraMedalCount = config.extra
  470. end
  471. end
  472. --this.loginfo("根据排名获得奖励比率", rank, selfScale, otherReward, extraMedalCount)
  473. return selfScale, otherReward, extraMedalCount
  474. end
  475. function this.checkSettleAndReset()
  476. local serverType = getbaseinfo("servertype")
  477. if serverType == 2 then
  478. --跨服不用结算
  479. return
  480. end
  481. local settleHour, resetHour = this.getTimeConfig()
  482. this.loginfo("检查结算和重置", settleHour, resetHour)
  483. if settleHour == nil or resetHour == nil then
  484. return
  485. end
  486. local hour = getbaseinfo("hour")
  487. this.Settle(hour, settleHour)
  488. this.Reset(hour, resetHour)
  489. end
  490. function this.buildOneRole(id)
  491. local actor = getactor(id)
  492. local role = {}
  493. role["career"] = getbaseinfo(actor, "getbasecareer")
  494. role["name"] = getbaseinfo(actor, "rolename")
  495. local serverId = getbaseinfo(actor, "originalserverid")
  496. role["serverid"] = serverId
  497. role["online"] = getbaseinfo(actor, "onlinestate")
  498. return role
  499. end
  500. function this.rankList(actor)
  501. local integralInfo = this.getIntegralInfo(actor)
  502. local rankList, medalTotal, integralTotal = this.getRankList(integralInfo)
  503. local resRankList = {}
  504. for _, rankItem in pairs(rankList) do
  505. local newItem = {
  506. rid = rankItem.rid,
  507. integral = rankItem.integral,
  508. medal = rankItem.medalCount,
  509. rank = rankItem.rank,
  510. roleInfo = this.buildOneRole(rankItem.rid)
  511. }
  512. table.insert(resRankList, newItem)
  513. end
  514. this.loginfo(actor, "总勋章数量", tostring(medalTotal), "总积分数量", integralTotal, "榜列表", resRankList)
  515. sendluamsg(actor, LuaMessageIdToClient.RES_MONSTER_HUNT_RANK, resRankList)
  516. end
  517. function this.notice()
  518. local serverType = getbaseinfo("servertype")
  519. if serverType == 2 then
  520. --跨服不用结算
  521. return
  522. end
  523. local count = this.getNoticeCount()
  524. count = count + 1
  525. this.setNoticeCount(count)
  526. if count % 5 == 0 then
  527. --每5分中发送通知
  528. this.sendNotice()
  529. end
  530. end
  531. function this.getNameByIndex(rankList, index)
  532. if table.isNullOrEmpty(rankList) then
  533. return ""
  534. end
  535. if #rankList >= index then
  536. local item = rankList[index]
  537. local rid = item.rid
  538. local actor = getactor(rid)
  539. local name = getbaseinfo(actor, "rolename")
  540. return name
  541. end
  542. return ""
  543. end
  544. function this.sendNotice()
  545. local integralInfo = this.getIntegralInfo(nil)
  546. local rankList = this.getRankList(integralInfo)
  547. local first = this.getNameByIndex(rankList, 1)
  548. local second = this.getNameByIndex(rankList, 2)
  549. local third = this.getNameByIndex(rankList, 3)
  550. local allplayer = getallplayer()
  551. for _, id in pairs(allplayer) do
  552. local actor = getactor(id)
  553. -- noticeTip.noticeinfo(actor, StringIdConst.TEXT27001, first, second, third)
  554. end
  555. end
  556. function this.info(actor)
  557. if not this.isSeasonTime() then
  558. sendluamsg(actor, LuaMessageIdToClient.RES_MONSTER_HUNT_INFO, {settleSec = 0, resetSec = 0})
  559. return
  560. end
  561. local settleHour, resetHour = this.getTimeConfig()
  562. local res
  563. if settleHour == nil or resetHour == nil then
  564. res = {
  565. settleSec = 0,
  566. resetSec = 0
  567. }
  568. else
  569. local timeInfo = this.getTimeInfo(actor)
  570. local settleSec = this.getTargetDateTimeSec(settleHour, timeInfo.settleTime)
  571. local resetSec = this.getTargetDateTimeSec(resetHour, timeInfo.resetTime)
  572. res = {
  573. settleSec = settleSec,
  574. resetSec = resetSec
  575. }
  576. end
  577. this.loginfo("信息", res)
  578. sendluamsg(actor, LuaMessageIdToClient.RES_MONSTER_HUNT_INFO, res)
  579. end
  580. --今天是否刷过了
  581. function this.todayIsRefresh(prevRefreshTimeMills)
  582. if prevRefreshTimeMills == nil or prevRefreshTimeMills <= 0 then
  583. return false
  584. end
  585. --this.loginfo("prevRefreshTimeMills", prevRefreshTimeMills, type(prevRefreshTimeMills))
  586. local now = getbaseinfo("now")
  587. local diffDays = datediff(now, prevRefreshTimeMills, "day")
  588. return diffDays == 0
  589. end
  590. function this.getTargetDateTimeSec(hour, prevRefreshTimeMills)
  591. local dateTimeFormat = "%s-%s-%s %s:%s:%s"
  592. local now = getbaseinfo("now")
  593. local target
  594. local todayIsRefresh = this.todayIsRefresh(prevRefreshTimeMills)
  595. if todayIsRefresh then
  596. --加一天
  597. target = dateadd(now, 1)
  598. else
  599. local y = year(now)
  600. local m = month(now)
  601. local d = day(now)
  602. local dateTimeString = string.format(dateTimeFormat, y, m, d, hour, 0, 0)
  603. local t = timestamp(dateTimeString)
  604. if t > now then
  605. this.loginfo("刷新间隔计算1", todayIsRefresh, dateTimeString, t, now)
  606. --今天刷
  607. --return datediff(t,now, "second")
  608. return math.round(t / 1000)
  609. else
  610. --明天刷
  611. target = dateadd(now, 1)
  612. end
  613. end
  614. local y = year(target)
  615. local m = month(target)
  616. local d = day(target)
  617. local dateTimeString = string.format(dateTimeFormat, y, m, d, hour, 0, 0)
  618. local t = timestamp(dateTimeString)
  619. this.loginfo("刷新间隔计算2", todayIsRefresh, dateTimeString, t, now)
  620. --return datediff(t,now, "second")
  621. return math.round(t / 1000)
  622. end
  623. function this.loginfo(...)
  624. info("[猎魔勋章]", ...)
  625. end
  626. function this.logerror(...)
  627. error("[猎魔勋章]", ...)
  628. end
  629. function MonsterHunt.GetMonsterHuntIntegralKey()
  630. return VAR.MONSTER_HUNT_INTEGRAL
  631. end
  632. function MonsterHunt.CombineMonsterHuntIntegral(varData)
  633. if table.isNullOrEmpty(varData) then
  634. return
  635. end
  636. this.loginfo("猎魔积分合服数据", varData)
  637. local currIntegralInfo = this.getIntegralInfo(nil)
  638. for sid, integralInfo in pairs(varData) do
  639. table.merge(currIntegralInfo, integralInfo)
  640. end
  641. this.setIntegralInfo(nil, currIntegralInfo)
  642. end
  643. --怪物死亡触发
  644. function MonsterHunt.MonsterDie(ownerId, monsterCfgId)
  645. gameDebug.debug(this.monsterDie, ownerId, monsterCfgId)
  646. end
  647. --结算
  648. function MonsterHunt.CheckSettleAndReset()
  649. gameDebug.debug(this.checkSettleAndReset)
  650. end
  651. function MonsterHunt.Notice()
  652. gameDebug.debug(this.notice)
  653. end
  654. function MonsterHunt.RankList(actor)
  655. gameDebug.debug(this.rankList, actor)
  656. end
  657. --@lua monsterhuntinfo
  658. function MonsterHunt.Info(actor)
  659. gameDebug.debug(this.info, actor)
  660. end
  661. --- func desc 检查赛季是否结束
  662. function MonsterHunt.checkSeason()
  663. local value = ConfigDataManager.getTableValue("cfg_global", "value", "id", GLOBAL_ID.SEASON_SETTLE)
  664. if string.isNullOrEmpty(value) then
  665. return
  666. end
  667. local seasons = string.split(value, "|")
  668. for _, seasonInfo in ipairs(seasons) do
  669. local timeInfo = string.split(string.split(seasonInfo, "&")[3], "#")
  670. local year = tonumber(timeInfo[1])
  671. local month = tonumber(timeInfo[2])
  672. local day = tonumber(timeInfo[3])
  673. local hour = tonumber(timeInfo[4])
  674. local nowSec = getbaseinfo("nowsec")
  675. local date = TimeUtil.timeToDate(nowSec)
  676. if date.year == year and date.month == month and date.day == day and date.hour == hour and date.min == 0 then
  677. -- info("猎魔赛季结算, 重置所有数据, year-",year,"month-",month,"day-",day,"hour-",hour)
  678. callonserial("monsterhurt_clear_all_data")
  679. -- this.resetAllData()
  680. break
  681. end
  682. end
  683. end
  684. --打印排行榜列表
  685. --@lua monsterhuntranklist
  686. function monsterhuntranklist(actor)
  687. this.rankList(actor)
  688. end
  689. --@lua monsterhuntchecksettleandreset
  690. function monsterhuntchecksettleandreset()
  691. this.checkSettleAndReset()
  692. end
  693. --@lua monsterhuntsendnotice
  694. function monsterhuntsendnotice()
  695. this.sendNotice()
  696. end
  697. -- @lua monsterhuntinfo
  698. function monsterhuntinfo(actor)
  699. this.info(actor)
  700. end
  701. -- @createMonster 80006
  702. -- @lua monstercleartimeinfo
  703. function monstercleartimeinfo(actor)
  704. this.setTimeInfo(nil)
  705. this.setState(nil)
  706. end
  707. --- func desc
  708. ---@param actor any
  709. function clall(actor)
  710. callonserial("monsterhurt_clear_all_data")
  711. end
  712. --- func desc
  713. ---@param actor any
  714. function allhunt(actor)
  715. local timeInfo = getsysvar(actor, VAR.MONSTER_HUNT_TIME_INFO)
  716. local state = getsysvar(actor, VAR.MONSTER_HUNT_STATE)
  717. local count = getsysvar(VAR.MONSTER_HUNT_NOTICE_COUNT) or 0
  718. local allIntegralInfo = getsysvar(actor, VAR.MONSTER_HUNT_INTEGRAL)
  719. lg("时间信息:", timeInfo, "状态:", state, "通知次数:", count, "积分信息:", allIntegralInfo)
  720. end