TripleIncome.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. --三倍收益
  2. --剩余的3倍收益时间,单位秒
  3. local REMAIN_TIME_KEY = "T$_REMAIN_TRIPLE_INCOME_TIME";
  4. --3倍收益有效截至时间(这个时间有值,表示3倍收益生效),但是毫秒时间戳
  5. local EFFECT_TIMESTAMP_KEY = "T$_EFFECT_TRIPLE_INCOME_TIME"
  6. --3倍收益时间最新领取时间
  7. local RECEIVE_TIME_KEY = "T$_TRIPLE_INCOME_RECEIVE_TIME"
  8. -- 5006 globalID的值
  9. local RATE_CACHE = 0
  10. TripleIncome = {}
  11. function TripleIncome.getRateFromConfig()
  12. if RATE_CACHE > 0 then
  13. return RATE_CACHE
  14. end
  15. local value = ConfigDataManager.getTableValue("cfg_global", "value","id",5006)
  16. RATE_CACHE = tonumber(value)
  17. return RATE_CACHE
  18. end
  19. function TripleIncome.getReceiveTime(actor)
  20. local timestamp = getplaydef(actor, RECEIVE_TIME_KEY)
  21. if timestamp == nil then
  22. return 0
  23. end
  24. return tonumber(timestamp)
  25. end
  26. function TripleIncome.setReceiveTime(actor, timestampMills)
  27. setplaydef(actor, RECEIVE_TIME_KEY, timestampMills)
  28. end
  29. function TripleIncome.getRemainTime(actor)
  30. local timeSec = getplaydef(actor, REMAIN_TIME_KEY)
  31. if timeSec == nil then
  32. timeSec = 0
  33. end
  34. return tonumber(timeSec)
  35. end
  36. function TripleIncome.setRemainTime(actor, num)
  37. setplaydef(actor,REMAIN_TIME_KEY, num)
  38. end
  39. --增加3倍收益时间
  40. function TripleIncome.AddRemainTime(actor, addNumSec)
  41. local sMaxLimit = ConfigDataManager.getTableValue("cfg_global","value","id", 5001)
  42. local maxLimitSec = tonumber(sMaxLimit) * 3600
  43. local time = TripleIncome.getRemainTime(actor)
  44. local final_time = time + addNumSec
  45. if(maxLimitSec > 0 and final_time > maxLimitSec) then
  46. final_time = maxLimitSec
  47. end
  48. TripleIncome.setRemainTime(actor, final_time)
  49. gameDebug.print("-------增加三倍收益时间--------", "rid:" .. actor:toString(), addNumSec, time, final_time, debug.traceback())
  50. end
  51. --减少3倍收益时间
  52. function TripleIncome.subRemainTime(actor, subNumSec)
  53. local time = TripleIncome.getRemainTime(actor)
  54. time = time - subNumSec
  55. time = math.max(time, 0)
  56. TripleIncome.setRemainTime(actor, time)
  57. end
  58. function TripleIncome.getEffectTimestamp(actor)
  59. local timestampMills = getplaydef(actor, EFFECT_TIMESTAMP_KEY)
  60. if timestampMills == nil then
  61. return 0
  62. end
  63. return tonumber(timestampMills)
  64. end
  65. function TripleIncome.setEffectTimestamp(actor, timestampMills)
  66. setplaydef(actor, EFFECT_TIMESTAMP_KEY, tonumber(timestampMills))
  67. end
  68. --三倍收益是否生效
  69. function TripleIncome.IsEffect(actor)
  70. local timestampMills = TripleIncome.getEffectTimestamp(actor)
  71. local now = getbaseinfo("now")
  72. return timestampMills > now
  73. end
  74. function TripleIncome.GetRate(actor)
  75. local effect = TripleIncome.IsEffect(actor)
  76. if effect then
  77. local rate = TripleIncome.getRateFromConfig()
  78. return rate / 10000
  79. else
  80. return 1
  81. end
  82. end
  83. --领取时间
  84. function TripleIncome.ReceiveTime(actor, hour)
  85. hour = tonumber(hour)
  86. local receiveAll = hour == 0
  87. local remainSec = TripleIncome.getRemainTime(actor)
  88. local receiveSec = 0
  89. if receiveAll then
  90. receiveSec = remainSec
  91. else
  92. local sec = hour * 60 * 60
  93. if remainSec < sec then
  94. noticeTip.noticeinfo(actor, StringIdConst.TEXT384)
  95. return
  96. end
  97. receiveSec = sec
  98. end
  99. local effectTimestamp = TripleIncome.getEffectTimestamp(actor)
  100. local now = getbaseinfo("now")
  101. if effectTimestamp <= 0 or effectTimestamp < now then
  102. effectTimestamp = now
  103. end
  104. effectTimestamp = effectTimestamp + receiveSec * 1000
  105. TripleIncome.setReceiveTime(actor, now)
  106. TripleIncome.setEffectTimestamp(actor, effectTimestamp)
  107. TripleIncome.subRemainTime(actor, receiveSec)
  108. TripleIncome.PanelInfo(actor)
  109. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.OPEN_TRIPLE_INCOME)
  110. end
  111. --归还3倍奖励时间
  112. function TripleIncome.ReturnTime(actor)
  113. local effectTimestamp = TripleIncome.getEffectTimestamp(actor)
  114. local now = getbaseinfo("now")
  115. if effectTimestamp <= 0 or effectTimestamp <= now then
  116. return
  117. end
  118. local returnSec = (effectTimestamp - now)/1000
  119. TripleIncome.AddRemainTime(actor, returnSec)
  120. TripleIncome.setEffectTimestamp(actor,0)
  121. TripleIncome.PanelInfo(actor)
  122. end
  123. --返回给客户端的3倍收益信息
  124. function TripleIncome.PanelInfo(actor)
  125. local now = getbaseinfo("now")
  126. local effectTimestampMills = TripleIncome.getEffectTimestamp(actor)
  127. local remainSec = TripleIncome.getRemainTime(actor)
  128. local effectSec = 0
  129. if effectTimestampMills > now then
  130. effectSec = ( effectTimestampMills - now ) / 1000
  131. end
  132. local receiveTimestamp = TripleIncome.getReceiveTime(actor);
  133. local res = {
  134. remainSec = remainSec,
  135. effectSec = effectSec,
  136. receiveTimestamp = receiveTimestamp, --毫秒时间戳
  137. }
  138. sendluamsg(actor, LuaMessageIdToClient.TRIPLE_INCOME_INFO, res)
  139. end
  140. function TripleIncome.CheckInGoldMap(actor, mapId)
  141. local isGoldMap = ConfigDataManager.getTableValue("cfg_map_info", "goldmap", "id", mapId)
  142. if tonumber(isGoldMap) == 1 then
  143. -- 检查是否具有特权
  144. local isPrivilege = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.WILD_LINE)
  145. if isPrivilege then
  146. return nil
  147. end
  148. -- 检查是否具有VIP特权
  149. local is_vip, map_id_str = VipGiftPack.hasPrivilege(actor, VipPrivilege.Type.goldway)
  150. if is_vip then
  151. local map_ids = string.split(map_id_str, "#")
  152. if table.contains(map_ids, tostring(mapId)) then
  153. return nil
  154. end
  155. end
  156. -- 没有权限
  157. noticeTip.noticeinfo(actor, StringIdConst.TEXT478)
  158. return {result = true, reason = "无权限进入此地图"}
  159. end
  160. return nil
  161. end
  162. --====== gm测试 ================================
  163. function addtripleincomesec(actor, sec)
  164. sec = tonumber(sec)
  165. TripleIncome.AddRemainTime(actor,sec)
  166. local hour = sec / 3600
  167. jprint("增加三倍收益时间", sec, hour)
  168. TripleIncome.ReceiveTime(actor, hour)
  169. TripleIncome.PanelInfo(actor)
  170. end
  171. function tripleincomepanelinfo(actor)
  172. local remainTimeSec = TripleIncome.getRemainTime(actor)
  173. local effectTimestamp = TripleIncome.getEffectTimestamp(actor)
  174. jprint("三倍收益信息", remainTimeSec, effectTimestamp)
  175. TripleIncome.PanelInfo(actor)
  176. end