@takaro/modules 0.0.14 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/dist/BuiltinModule.d.ts +13 -8
  2. package/dist/BuiltinModule.d.ts.map +1 -0
  3. package/dist/BuiltinModule.js +48 -31
  4. package/dist/BuiltinModule.js.map +1 -1
  5. package/dist/dto/base.d.ts +1 -0
  6. package/dist/dto/base.d.ts.map +1 -0
  7. package/dist/dto/discordEvents.d.ts +1 -0
  8. package/dist/dto/discordEvents.d.ts.map +1 -0
  9. package/dist/dto/gameEvents.d.ts +1 -0
  10. package/dist/dto/gameEvents.d.ts.map +1 -0
  11. package/dist/dto/index.d.ts +4 -0
  12. package/dist/dto/index.d.ts.map +1 -0
  13. package/dist/dto/takaroEvents.d.ts +16 -0
  14. package/dist/dto/takaroEvents.d.ts.map +1 -0
  15. package/dist/dto/takaroEvents.js +36 -0
  16. package/dist/dto/takaroEvents.js.map +1 -1
  17. package/dist/main.d.ts +4 -3
  18. package/dist/main.d.ts.map +1 -0
  19. package/dist/main.js +3 -1
  20. package/dist/main.js.map +1 -1
  21. package/dist/modules/chatBridge/hooks/DiscordToGame.d.ts +1 -0
  22. package/dist/modules/chatBridge/hooks/DiscordToGame.d.ts.map +1 -0
  23. package/dist/modules/chatBridge/hooks/GameToDiscord.d.ts +1 -0
  24. package/dist/modules/chatBridge/hooks/GameToDiscord.d.ts.map +1 -0
  25. package/dist/modules/chatBridge/hooks/PlayerConnected.d.ts +1 -0
  26. package/dist/modules/chatBridge/hooks/PlayerConnected.d.ts.map +1 -0
  27. package/dist/modules/chatBridge/hooks/PlayerDisconnected.d.ts +1 -0
  28. package/dist/modules/chatBridge/hooks/PlayerDisconnected.d.ts.map +1 -0
  29. package/dist/modules/chatBridge/index.d.ts +3 -2
  30. package/dist/modules/chatBridge/index.d.ts.map +1 -0
  31. package/dist/modules/chatBridge/index.js +55 -47
  32. package/dist/modules/chatBridge/index.js.map +1 -1
  33. package/dist/modules/dailyRewards/commands/daily.d.ts +2 -0
  34. package/dist/modules/dailyRewards/commands/daily.d.ts.map +1 -0
  35. package/dist/modules/dailyRewards/commands/daily.js +106 -0
  36. package/dist/modules/dailyRewards/commands/daily.js.map +1 -0
  37. package/dist/modules/dailyRewards/commands/streak.d.ts +2 -0
  38. package/dist/modules/dailyRewards/commands/streak.d.ts.map +1 -0
  39. package/dist/modules/dailyRewards/commands/streak.js +34 -0
  40. package/dist/modules/dailyRewards/commands/streak.js.map +1 -0
  41. package/dist/modules/dailyRewards/commands/topstreak.d.ts +2 -0
  42. package/dist/modules/dailyRewards/commands/topstreak.d.ts.map +1 -0
  43. package/dist/modules/dailyRewards/commands/topstreak.js +44 -0
  44. package/dist/modules/dailyRewards/commands/topstreak.js.map +1 -0
  45. package/dist/modules/dailyRewards/functions/utils.d.ts +6 -0
  46. package/dist/modules/dailyRewards/functions/utils.d.ts.map +1 -0
  47. package/dist/modules/dailyRewards/functions/utils.js +32 -0
  48. package/dist/modules/dailyRewards/functions/utils.js.map +1 -0
  49. package/dist/modules/dailyRewards/hooks/dailyLoginCheck.d.ts +2 -0
  50. package/dist/modules/dailyRewards/hooks/dailyLoginCheck.d.ts.map +1 -0
  51. package/dist/modules/dailyRewards/hooks/dailyLoginCheck.js +19 -0
  52. package/dist/modules/dailyRewards/hooks/dailyLoginCheck.js.map +1 -0
  53. package/dist/modules/dailyRewards/index.d.ts +5 -0
  54. package/dist/modules/dailyRewards/index.d.ts.map +1 -0
  55. package/dist/modules/dailyRewards/index.js +125 -0
  56. package/dist/modules/dailyRewards/index.js.map +1 -0
  57. package/dist/modules/economyUtils/commands/balance.d.ts +1 -0
  58. package/dist/modules/economyUtils/commands/balance.d.ts.map +1 -0
  59. package/dist/modules/economyUtils/commands/claim.d.ts +1 -0
  60. package/dist/modules/economyUtils/commands/claim.d.ts.map +1 -0
  61. package/dist/modules/economyUtils/commands/confirmTransfer.d.ts +1 -0
  62. package/dist/modules/economyUtils/commands/confirmTransfer.d.ts.map +1 -0
  63. package/dist/modules/economyUtils/commands/grantCurrency.d.ts +1 -0
  64. package/dist/modules/economyUtils/commands/grantCurrency.d.ts.map +1 -0
  65. package/dist/modules/economyUtils/commands/revokeCurrency.d.ts +1 -0
  66. package/dist/modules/economyUtils/commands/revokeCurrency.d.ts.map +1 -0
  67. package/dist/modules/economyUtils/commands/shop.d.ts +1 -0
  68. package/dist/modules/economyUtils/commands/shop.d.ts.map +1 -0
  69. package/dist/modules/economyUtils/commands/topCurrency.d.ts +1 -0
  70. package/dist/modules/economyUtils/commands/topCurrency.d.ts.map +1 -0
  71. package/dist/modules/economyUtils/commands/transfer.d.ts +1 -0
  72. package/dist/modules/economyUtils/commands/transfer.d.ts.map +1 -0
  73. package/dist/modules/economyUtils/cronJobs/zombieKillReward.d.ts +1 -0
  74. package/dist/modules/economyUtils/cronJobs/zombieKillReward.d.ts.map +1 -0
  75. package/dist/modules/economyUtils/index.d.ts +3 -2
  76. package/dist/modules/economyUtils/index.d.ts.map +1 -0
  77. package/dist/modules/economyUtils/index.js +178 -170
  78. package/dist/modules/economyUtils/index.js.map +1 -1
  79. package/dist/modules/geoBlock/hooks/IPDetected.d.ts +1 -0
  80. package/dist/modules/geoBlock/hooks/IPDetected.d.ts.map +1 -0
  81. package/dist/modules/geoBlock/hooks/IPDetected.js +4 -2
  82. package/dist/modules/geoBlock/hooks/IPDetected.js.map +1 -1
  83. package/dist/modules/geoBlock/index.d.ts +3 -2
  84. package/dist/modules/geoBlock/index.d.ts.map +1 -0
  85. package/dist/modules/geoBlock/index.js +71 -63
  86. package/dist/modules/geoBlock/index.js.map +1 -1
  87. package/dist/modules/gimme/commands/gimme.d.ts +1 -0
  88. package/dist/modules/gimme/commands/gimme.d.ts.map +1 -0
  89. package/dist/modules/gimme/commands/gimme.js +17 -6
  90. package/dist/modules/gimme/commands/gimme.js.map +1 -1
  91. package/dist/modules/gimme/index.d.ts +3 -2
  92. package/dist/modules/gimme/index.d.ts.map +1 -0
  93. package/dist/modules/gimme/index.js +64 -34
  94. package/dist/modules/gimme/index.js.map +1 -1
  95. package/dist/modules/highPingKicker/cronJobs/Ping check.d.ts +1 -0
  96. package/dist/modules/highPingKicker/cronJobs/Ping check.d.ts.map +1 -0
  97. package/dist/modules/highPingKicker/index.d.ts +3 -2
  98. package/dist/modules/highPingKicker/index.d.ts.map +1 -0
  99. package/dist/modules/highPingKicker/index.js +36 -28
  100. package/dist/modules/highPingKicker/index.js.map +1 -1
  101. package/dist/modules/lottery/commands/buyTicket.d.ts +1 -0
  102. package/dist/modules/lottery/commands/buyTicket.d.ts.map +1 -0
  103. package/dist/modules/lottery/commands/nextDraw.d.ts +1 -0
  104. package/dist/modules/lottery/commands/nextDraw.d.ts.map +1 -0
  105. package/dist/modules/lottery/commands/viewTickets.d.ts +1 -0
  106. package/dist/modules/lottery/commands/viewTickets.d.ts.map +1 -0
  107. package/dist/modules/lottery/cronJobs/drawLottery.d.ts +1 -0
  108. package/dist/modules/lottery/cronJobs/drawLottery.d.ts.map +1 -0
  109. package/dist/modules/lottery/index.d.ts +3 -2
  110. package/dist/modules/lottery/index.d.ts.map +1 -0
  111. package/dist/modules/lottery/index.js +73 -65
  112. package/dist/modules/lottery/index.js.map +1 -1
  113. package/dist/modules/playerOnboarding/commands/starterkit.d.ts +1 -0
  114. package/dist/modules/playerOnboarding/commands/starterkit.d.ts.map +1 -0
  115. package/dist/modules/playerOnboarding/commands/starterkit.js +16 -3
  116. package/dist/modules/playerOnboarding/commands/starterkit.js.map +1 -1
  117. package/dist/modules/playerOnboarding/hooks/playerConnected.d.ts +1 -0
  118. package/dist/modules/playerOnboarding/hooks/playerConnected.d.ts.map +1 -0
  119. package/dist/modules/playerOnboarding/index.d.ts +3 -2
  120. package/dist/modules/playerOnboarding/index.d.ts.map +1 -0
  121. package/dist/modules/playerOnboarding/index.js +73 -43
  122. package/dist/modules/playerOnboarding/index.js.map +1 -1
  123. package/dist/modules/serverMessages/cronJobs/Automated message.d.ts +1 -0
  124. package/dist/modules/serverMessages/cronJobs/Automated message.d.ts.map +1 -0
  125. package/dist/modules/serverMessages/index.d.ts +3 -2
  126. package/dist/modules/serverMessages/index.d.ts.map +1 -0
  127. package/dist/modules/serverMessages/index.js +36 -28
  128. package/dist/modules/serverMessages/index.js.map +1 -1
  129. package/dist/modules/teleports/commands/deletetp.d.ts +1 -0
  130. package/dist/modules/teleports/commands/deletetp.d.ts.map +1 -0
  131. package/dist/modules/teleports/commands/deletewaypoint.d.ts +1 -0
  132. package/dist/modules/teleports/commands/deletewaypoint.d.ts.map +1 -0
  133. package/dist/modules/teleports/commands/deletewaypoint.js +4 -35
  134. package/dist/modules/teleports/commands/deletewaypoint.js.map +1 -1
  135. package/dist/modules/teleports/commands/listwaypoints.d.ts +1 -0
  136. package/dist/modules/teleports/commands/listwaypoints.d.ts.map +1 -0
  137. package/dist/modules/teleports/commands/listwaypoints.js +3 -22
  138. package/dist/modules/teleports/commands/listwaypoints.js.map +1 -1
  139. package/dist/modules/teleports/commands/setprivate.d.ts +1 -0
  140. package/dist/modules/teleports/commands/setprivate.d.ts.map +1 -0
  141. package/dist/modules/teleports/commands/setpublic.d.ts +1 -0
  142. package/dist/modules/teleports/commands/setpublic.d.ts.map +1 -0
  143. package/dist/modules/teleports/commands/settp.d.ts +1 -0
  144. package/dist/modules/teleports/commands/settp.d.ts.map +1 -0
  145. package/dist/modules/teleports/commands/setwaypoint.d.ts +1 -0
  146. package/dist/modules/teleports/commands/setwaypoint.d.ts.map +1 -0
  147. package/dist/modules/teleports/commands/setwaypoint.js +5 -63
  148. package/dist/modules/teleports/commands/setwaypoint.js.map +1 -1
  149. package/dist/modules/teleports/commands/teleport.d.ts +1 -0
  150. package/dist/modules/teleports/commands/teleport.d.ts.map +1 -0
  151. package/dist/modules/teleports/commands/teleportwaypoint.d.ts +1 -0
  152. package/dist/modules/teleports/commands/teleportwaypoint.d.ts.map +1 -0
  153. package/dist/modules/teleports/commands/teleportwaypoint.js +7 -23
  154. package/dist/modules/teleports/commands/teleportwaypoint.js.map +1 -1
  155. package/dist/modules/teleports/commands/tplist.d.ts +1 -0
  156. package/dist/modules/teleports/commands/tplist.d.ts.map +1 -0
  157. package/dist/modules/teleports/cronJobs/Waypoint reconciler.d.ts +2 -0
  158. package/dist/modules/teleports/cronJobs/Waypoint reconciler.d.ts.map +1 -0
  159. package/dist/modules/teleports/cronJobs/Waypoint reconciler.js +6 -0
  160. package/dist/modules/teleports/cronJobs/Waypoint reconciler.js.map +1 -0
  161. package/dist/modules/teleports/functions/utils.d.ts +12 -0
  162. package/dist/modules/teleports/functions/utils.d.ts.map +1 -0
  163. package/dist/modules/teleports/functions/utils.js +117 -0
  164. package/dist/modules/teleports/functions/utils.js.map +1 -1
  165. package/dist/modules/teleports/index.d.ts +3 -2
  166. package/dist/modules/teleports/index.d.ts.map +1 -0
  167. package/dist/modules/teleports/index.js +188 -172
  168. package/dist/modules/teleports/index.js.map +1 -1
  169. package/dist/modules/timedShutdown/cronJobs/Shutdown.d.ts +1 -0
  170. package/dist/modules/timedShutdown/cronJobs/Shutdown.d.ts.map +1 -0
  171. package/dist/modules/timedShutdown/cronJobs/warning.d.ts +1 -0
  172. package/dist/modules/timedShutdown/cronJobs/warning.d.ts.map +1 -0
  173. package/dist/modules/timedShutdown/index.d.ts +3 -2
  174. package/dist/modules/timedShutdown/index.d.ts.map +1 -0
  175. package/dist/modules/timedShutdown/index.js +35 -27
  176. package/dist/modules/timedShutdown/index.js.map +1 -1
  177. package/dist/modules/utils/commands/help.d.ts +1 -0
  178. package/dist/modules/utils/commands/help.d.ts.map +1 -0
  179. package/dist/modules/utils/commands/help.js +10 -9
  180. package/dist/modules/utils/commands/help.js.map +1 -1
  181. package/dist/modules/utils/commands/ping.d.ts +1 -0
  182. package/dist/modules/utils/commands/ping.d.ts.map +1 -0
  183. package/dist/modules/utils/index.d.ts +3 -2
  184. package/dist/modules/utils/index.d.ts.map +1 -0
  185. package/dist/modules/utils/index.js +36 -28
  186. package/dist/modules/utils/index.js.map +1 -1
  187. package/dist/modules.json +601 -506
  188. package/package.json +2 -5
  189. package/scripts/buildBuiltinJson.ts +50 -2
  190. package/src/BuiltinModule.ts +25 -17
  191. package/src/__tests__/aliases.integration.test.ts +23 -26
  192. package/src/__tests__/bugRepros.integration.test.ts +261 -10
  193. package/src/__tests__/builtinmodule.unit.test.ts +3 -1
  194. package/src/__tests__/commandArgs.integration.test.ts +13 -6
  195. package/src/__tests__/economy/claim.integration.test.ts +1 -0
  196. package/src/__tests__/economy/economyUtils.integration.test.ts +43 -46
  197. package/src/__tests__/economy/shop.integration.test.ts +28 -4
  198. package/src/__tests__/economy/zombieKillReward.integration.test.ts +28 -31
  199. package/src/__tests__/geoblock.integration.test.ts +76 -91
  200. package/src/__tests__/gimme.integration.test.ts +25 -22
  201. package/src/__tests__/help.integration.test.ts +21 -20
  202. package/src/__tests__/lottery.integration.test.ts +15 -11
  203. package/src/__tests__/modulePermission.integration.test.ts +17 -13
  204. package/src/__tests__/onboarding.integration.test.ts +43 -43
  205. package/src/__tests__/ping.integration.test.ts +5 -4
  206. package/src/__tests__/roleExpiry.integration.test.ts +5 -4
  207. package/src/__tests__/serverMessages.integration.test.ts +24 -27
  208. package/src/__tests__/systemConfigCooldown.integration.test.ts +5 -1
  209. package/src/__tests__/systemConfigCost.integration.test.ts +16 -17
  210. package/src/__tests__/teleports/listtp.integration.test.ts +20 -21
  211. package/src/__tests__/teleports/publicteleports.integration.test.ts +58 -70
  212. package/src/__tests__/teleports/teleport.integration.test.ts +16 -17
  213. package/src/__tests__/teleports/tpManagement.integration.test.ts +21 -20
  214. package/src/__tests__/teleports/waypoints.integration.test.ts +52 -6
  215. package/src/dto/takaroEvents.ts +21 -0
  216. package/src/main.ts +14 -4
  217. package/src/modules/chatBridge/index.ts +54 -51
  218. package/src/modules/dailyRewards/commands/daily.js +118 -0
  219. package/src/modules/dailyRewards/commands/streak.js +42 -0
  220. package/src/modules/dailyRewards/commands/topstreak.js +54 -0
  221. package/src/modules/dailyRewards/functions/utils.js +36 -0
  222. package/src/modules/dailyRewards/hooks/dailyLoginCheck.js +24 -0
  223. package/src/modules/dailyRewards/index.ts +136 -0
  224. package/src/modules/economyUtils/index.ts +182 -179
  225. package/src/modules/geoBlock/hooks/IPDetected.js +4 -2
  226. package/src/modules/geoBlock/index.ts +72 -70
  227. package/src/modules/gimme/commands/gimme.js +16 -6
  228. package/src/modules/gimme/index.ts +62 -37
  229. package/src/modules/highPingKicker/index.ts +35 -32
  230. package/src/modules/lottery/index.ts +73 -71
  231. package/src/modules/playerOnboarding/commands/starterkit.js +19 -5
  232. package/src/modules/playerOnboarding/index.ts +72 -47
  233. package/src/modules/serverMessages/index.ts +36 -32
  234. package/src/modules/teleports/commands/deletewaypoint.js +4 -53
  235. package/src/modules/teleports/commands/listwaypoints.js +3 -35
  236. package/src/modules/teleports/commands/setwaypoint.js +5 -83
  237. package/src/modules/teleports/commands/teleportwaypoint.js +9 -36
  238. package/src/modules/teleports/cronJobs/Waypoint reconciler.js +7 -0
  239. package/src/modules/teleports/functions/utils.js +150 -0
  240. package/src/modules/teleports/index.ts +196 -180
  241. package/src/modules/timedShutdown/index.ts +35 -30
  242. package/src/modules/utils/commands/help.js +14 -14
  243. package/src/modules/utils/index.ts +36 -32
  244. package/tsconfig.json +1 -1
@@ -0,0 +1,118 @@
1
+ import { takaro, data, TakaroUserError, checkPermission } from '@takaro/helpers';
2
+ import { DAILY_KEY, STREAK_KEY, getMultiplier } from './utils.js';
3
+
4
+ async function main() {
5
+ const { pog, gameServerId, module: mod } = data;
6
+
7
+ if (!checkPermission(pog, 'DAILY_CLAIM')) {
8
+ throw new TakaroUserError('You do not have permission to claim daily rewards.');
9
+ }
10
+
11
+ // Get last claim time
12
+ const lastClaimRes = await takaro.variable.variableControllerSearch({
13
+ filters: {
14
+ key: [DAILY_KEY],
15
+ gameServerId: [gameServerId],
16
+ playerId: [pog.playerId],
17
+ moduleId: [mod.moduleId],
18
+ },
19
+ });
20
+
21
+ const now = new Date();
22
+ let streak = 1;
23
+
24
+ if (lastClaimRes.data.data.length > 0) {
25
+ const lastClaim = new Date(JSON.parse(lastClaimRes.data.data[0].value));
26
+ const hoursSinceLastClaim = (now - lastClaim) / (1000 * 60 * 60);
27
+
28
+ // Check if 24 hours have passed
29
+ if (hoursSinceLastClaim < 24) {
30
+ const nextClaimTime = new Date(lastClaim.getTime() + 24 * 60 * 60 * 1000);
31
+ throw new TakaroUserError(`You can claim your next reward at ${nextClaimTime.toLocaleString()}`);
32
+ }
33
+
34
+ // Get current streak
35
+ const streakRes = await takaro.variable.variableControllerSearch({
36
+ filters: {
37
+ key: [STREAK_KEY],
38
+ gameServerId: [gameServerId],
39
+ playerId: [pog.playerId],
40
+ moduleId: [mod.moduleId],
41
+ },
42
+ });
43
+
44
+ if (streakRes.data.data.length > 0) {
45
+ // If claimed within 48 hours, increment streak
46
+ if (hoursSinceLastClaim < 48) {
47
+ streak = Math.min(JSON.parse(streakRes.data.data[0].value) + 1, mod.userConfig.maxStreak);
48
+ await takaro.variable.variableControllerUpdate(streakRes.data.data[0].id, {
49
+ value: JSON.stringify(streak),
50
+ });
51
+ } else {
52
+ // Reset streak if more than 48 hours
53
+ await takaro.variable.variableControllerUpdate(streakRes.data.data[0].id, {
54
+ value: JSON.stringify(1),
55
+ });
56
+ }
57
+ } else {
58
+ // Create new streak record
59
+ await takaro.variable.variableControllerCreate({
60
+ key: STREAK_KEY,
61
+ value: JSON.stringify(1),
62
+ gameServerId,
63
+ playerId: pog.playerId,
64
+ moduleId: mod.moduleId,
65
+ });
66
+ }
67
+
68
+ // Update last claim time
69
+ await takaro.variable.variableControllerUpdate(lastClaimRes.data.data[0].id, {
70
+ value: JSON.stringify(now),
71
+ });
72
+ } else {
73
+ // First time claim
74
+ await takaro.variable.variableControllerCreate({
75
+ key: DAILY_KEY,
76
+ value: JSON.stringify(now),
77
+ gameServerId,
78
+ playerId: pog.playerId,
79
+ moduleId: mod.moduleId,
80
+ });
81
+ await takaro.variable.variableControllerCreate({
82
+ key: STREAK_KEY,
83
+ value: JSON.stringify(1),
84
+ gameServerId,
85
+ playerId: pog.playerId,
86
+ moduleId: mod.moduleId,
87
+ });
88
+ }
89
+
90
+ const multiplier = await getMultiplier(pog);
91
+ const baseReward = mod.userConfig.baseReward * streak * multiplier;
92
+ let bonusReward = 0;
93
+ let milestoneMessage = '';
94
+
95
+ // Check for milestones
96
+ for (const milestone of mod.userConfig.milestoneRewards) {
97
+ if (streak === milestone.days) {
98
+ bonusReward = milestone.reward;
99
+ milestoneMessage = `\n${milestone.message}`;
100
+ break;
101
+ }
102
+ }
103
+
104
+ // Award total rewards
105
+ const totalReward = baseReward + bonusReward;
106
+ await takaro.playerOnGameserver.playerOnGameServerControllerAddCurrency(gameServerId, pog.playerId, {
107
+ currency: totalReward,
108
+ });
109
+
110
+ const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', gameServerId)).data.data.value;
111
+ await pog.pm(
112
+ `Daily reward claimed! You received ${totalReward} ${currencyName}\n` +
113
+ `Current streak: ${streak} days${multiplier > 1 ? ` (${multiplier}x bonus!)` : ''}` +
114
+ milestoneMessage,
115
+ );
116
+ }
117
+
118
+ await main();
@@ -0,0 +1,42 @@
1
+ import { data, takaro } from '@takaro/helpers';
2
+ import { getPlayerStreak, getLastClaim, getMultiplier } from './utils.js';
3
+
4
+ async function main() {
5
+ const { pog, gameServerId, module: mod } = data;
6
+
7
+ const streak = await getPlayerStreak(gameServerId, pog.playerId, mod.moduleId);
8
+ const lastClaim = await getLastClaim(gameServerId, pog.playerId, mod.moduleId);
9
+ const multiplier = await getMultiplier(pog);
10
+ const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value;
11
+
12
+ if (!streak || !lastClaim) {
13
+ await pog.pm(`You haven't claimed any daily rewards yet! Use ${prefix}daily to get started.`);
14
+ return;
15
+ }
16
+
17
+ const nextClaimTime = new Date(lastClaim.getTime() + 24 * 60 * 60 * 1000);
18
+ const now = new Date();
19
+ const canClaim = now >= nextClaimTime;
20
+
21
+ // Find next milestone
22
+ let nextMilestone = null;
23
+ for (const milestone of mod.userConfig.milestoneRewards) {
24
+ if (milestone.days > streak) {
25
+ nextMilestone = milestone;
26
+ break;
27
+ }
28
+ }
29
+
30
+ let message = `Current streak: ${streak} days${multiplier > 1 ? ` (${multiplier}x donor bonus!)` : ''}\n`;
31
+ message += canClaim
32
+ ? `Your daily reward is available! Use ${prefix}daily to claim it!\n`
33
+ : `Next reward available at: ${nextClaimTime.toLocaleString()}\n`;
34
+
35
+ if (nextMilestone) {
36
+ message += `\n🎯 Next milestone: ${nextMilestone.days} days (${nextMilestone.days - streak} days to go!)`;
37
+ }
38
+
39
+ await pog.pm(message);
40
+ }
41
+
42
+ await main();
@@ -0,0 +1,54 @@
1
+ import { takaro, data } from '@takaro/helpers';
2
+ import { STREAK_KEY } from './utils.js';
3
+
4
+ async function main() {
5
+ const { pog, gameServerId, module: mod, arguments: args } = data;
6
+
7
+ // Limit count to reasonable number
8
+ const count = Math.min(Math.max(1, args.count), 50);
9
+
10
+ // Get all streaks
11
+ const streaksRes = await takaro.variable.variableControllerSearch({
12
+ filters: {
13
+ key: [STREAK_KEY],
14
+ gameServerId: [gameServerId],
15
+ moduleId: [mod.moduleId],
16
+ },
17
+ limit: 1000, // Get all possible streaks
18
+ });
19
+
20
+ if (streaksRes.data.data.length === 0) {
21
+ await pog.pm('No players have started their daily streak yet!');
22
+ return;
23
+ }
24
+
25
+ // Sort by streak value
26
+ const sortedStreaks = streaksRes.data.data
27
+ .map((record) => ({
28
+ playerId: record.playerId,
29
+ streak: JSON.parse(record.value),
30
+ }))
31
+ .sort((a, b) => b.streak - a.streak)
32
+ .slice(0, count);
33
+
34
+ // Get player names
35
+ const playerDetails = await Promise.all(
36
+ sortedStreaks.map(async (record) => {
37
+ const player = (await takaro.player.playerControllerGetOne(record.playerId)).data.data;
38
+ return {
39
+ name: player.name,
40
+ streak: record.streak,
41
+ };
42
+ }),
43
+ );
44
+
45
+ // Build message
46
+ let message = `Top ${count} Daily Streaks:\n\n`;
47
+ playerDetails.forEach((player, index) => {
48
+ message += `${index + 1}. ${player.name}: ${player.streak} days\n`;
49
+ });
50
+
51
+ await pog.pm(message);
52
+ }
53
+
54
+ await main();
@@ -0,0 +1,36 @@
1
+ import { takaro, checkPermission } from '@takaro/helpers';
2
+
3
+ export const DAILY_KEY = 'daily_timestamp';
4
+ export const STREAK_KEY = 'daily_streak';
5
+
6
+ export async function getMultiplier(pog) {
7
+ const perm = checkPermission(pog, 'DAILY_REWARD_MULTIPLIER');
8
+ if (perm) return perm.count;
9
+ return 1;
10
+ }
11
+
12
+ export async function getPlayerStreak(gameServerId, playerId, moduleId) {
13
+ const streakRes = await takaro.variable.variableControllerSearch({
14
+ filters: {
15
+ key: [STREAK_KEY],
16
+ gameServerId: [gameServerId],
17
+ playerId: [playerId],
18
+ moduleId: [moduleId],
19
+ },
20
+ });
21
+
22
+ return streakRes.data.data.length ? parseInt(JSON.parse(streakRes.data.data[0].value)) : 0;
23
+ }
24
+
25
+ export async function getLastClaim(gameServerId, playerId, moduleId) {
26
+ const lastClaimRes = await takaro.variable.variableControllerSearch({
27
+ filters: {
28
+ key: [DAILY_KEY],
29
+ gameServerId: [gameServerId],
30
+ playerId: [playerId],
31
+ moduleId: [moduleId],
32
+ },
33
+ });
34
+
35
+ return lastClaimRes.data.data.length ? new Date(JSON.parse(lastClaimRes.data.data[0].value)) : null;
36
+ }
@@ -0,0 +1,24 @@
1
+ import { data, takaro } from '@takaro/helpers';
2
+ import { getLastClaim } from './utils.js';
3
+
4
+ async function main() {
5
+ const { pog, gameServerId, module: mod } = data;
6
+ const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value;
7
+
8
+ const lastClaim = await getLastClaim(gameServerId, pog.playerId, mod.moduleId);
9
+
10
+ // First time player
11
+ if (!lastClaim) {
12
+ await pog.pm(`Welcome! Use ${prefix}daily to claim your first daily reward and start your streak!`);
13
+ return;
14
+ }
15
+
16
+ const now = new Date();
17
+ const nextClaimTime = new Date(lastClaim.getTime() + 24 * 60 * 60 * 1000);
18
+
19
+ if (now >= nextClaimTime) {
20
+ await pog.pm(`Your daily reward is ready! Use ${prefix}daily to claim it!`);
21
+ }
22
+ }
23
+
24
+ await main();
@@ -0,0 +1,136 @@
1
+ /* eslint-disable quotes */
2
+ import {
3
+ ModuleTransferDTO,
4
+ ICommand,
5
+ IFunction,
6
+ IHook,
7
+ IPermission,
8
+ ModuleTransferVersionDTO,
9
+ } from '../../BuiltinModule.js';
10
+
11
+ export class DailyRewards extends ModuleTransferDTO<DailyRewards> {
12
+ constructor() {
13
+ super();
14
+ this.name = 'dailyRewards';
15
+ this.versions = [
16
+ new ModuleTransferVersionDTO({
17
+ description: 'Provides daily login rewards with streak tracking',
18
+ tag: '0.0.1',
19
+ configSchema: JSON.stringify({
20
+ $schema: 'http://json-schema.org/draft-07/schema#',
21
+ type: 'object',
22
+ properties: {
23
+ baseReward: {
24
+ type: 'number',
25
+ title: 'Base Reward',
26
+ description: 'Base amount of currency given for daily rewards. This is multiplied by streak level.',
27
+ default: 100,
28
+ minimum: 1,
29
+ },
30
+ maxStreak: {
31
+ type: 'number',
32
+ title: 'Maximum Streak',
33
+ description: 'Maximum streak level a player can reach',
34
+ default: 365,
35
+ minimum: 1,
36
+ },
37
+ milestoneRewards: {
38
+ type: 'array',
39
+ title: 'Milestone Rewards',
40
+ description: 'Additional rewards for reaching certain streak milestones',
41
+ items: {
42
+ type: 'object',
43
+ properties: {
44
+ days: {
45
+ type: 'number',
46
+ description: 'Days needed to reach milestone',
47
+ minimum: 1,
48
+ },
49
+ reward: {
50
+ type: 'number',
51
+ description: 'Bonus reward amount',
52
+ },
53
+ message: {
54
+ type: 'string',
55
+ description: 'Message to show when milestone is reached',
56
+ },
57
+ },
58
+ },
59
+ default: [
60
+ { days: 7, reward: 1000, message: 'You did it! 7 days in a row!' },
61
+ { days: 30, reward: 5000, message: "A whole month! You're on fire!" },
62
+ { days: 90, reward: 20000, message: "90 days! You're unstoppable!" },
63
+ { days: 180, reward: 50000, message: "Half a year! You're a legend!" },
64
+ { days: 365, reward: 150000, message: "365 days! You're a true champion!" },
65
+ ],
66
+ },
67
+ },
68
+ required: ['baseReward', 'maxStreak', 'milestoneRewards'],
69
+ additionalProperties: false,
70
+ }),
71
+ functions: [
72
+ new IFunction({
73
+ name: 'utils',
74
+ function: this.loadFn('functions', 'utils'),
75
+ }),
76
+ ],
77
+
78
+ permissions: [
79
+ new IPermission({
80
+ permission: 'DAILY_CLAIM',
81
+ friendlyName: 'Claim Daily Rewards',
82
+ description: 'Allows the player to claim daily rewards',
83
+ canHaveCount: false,
84
+ }),
85
+ new IPermission({
86
+ permission: 'DAILY_REWARD_MULTIPLIER',
87
+ friendlyName: 'Multiplier',
88
+ description:
89
+ 'Control the multiplier per role. This is useful to give your donors a little extra. Count is an integer multiplier.',
90
+ canHaveCount: true,
91
+ }),
92
+ ],
93
+
94
+ commands: [
95
+ new ICommand({
96
+ function: this.loadFn('commands', 'daily'),
97
+ name: 'daily',
98
+ trigger: 'daily',
99
+ helpText: 'Claim your daily reward',
100
+ arguments: [],
101
+ }),
102
+ new ICommand({
103
+ function: this.loadFn('commands', 'streak'),
104
+ name: 'streak',
105
+ trigger: 'streak',
106
+ helpText: 'Check your current daily reward streak and next claim time',
107
+ arguments: [],
108
+ }),
109
+ new ICommand({
110
+ function: this.loadFn('commands', 'topstreak'),
111
+ name: 'topstreak',
112
+ trigger: 'topstreak',
113
+ helpText: 'Shows the players with highest daily reward streaks',
114
+ arguments: [
115
+ {
116
+ name: 'count',
117
+ type: 'number',
118
+ defaultValue: '5',
119
+ helpText: 'Number of players to show (max 25)',
120
+ position: 0,
121
+ },
122
+ ],
123
+ }),
124
+ ],
125
+
126
+ hooks: [
127
+ new IHook({
128
+ eventType: 'player-connected',
129
+ name: 'dailyLoginCheck',
130
+ function: this.loadFn('hooks', 'dailyLoginCheck'),
131
+ }),
132
+ ],
133
+ }),
134
+ ];
135
+ }
136
+ }