@takaro/modules 0.0.1
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.
- package/README.md +3 -0
- package/dist/BuiltinModule.d.ts +49 -0
- package/dist/BuiltinModule.js +194 -0
- package/dist/BuiltinModule.js.map +1 -0
- package/dist/dto/base.d.ts +6 -0
- package/dist/dto/base.js +28 -0
- package/dist/dto/base.js.map +1 -0
- package/dist/dto/discordEvents.d.ts +31 -0
- package/dist/dto/discordEvents.js +92 -0
- package/dist/dto/discordEvents.js.map +1 -0
- package/dist/dto/gameEvents.d.ts +84 -0
- package/dist/dto/gameEvents.js +190 -0
- package/dist/dto/gameEvents.js.map +1 -0
- package/dist/dto/index.d.ts +37 -0
- package/dist/dto/index.js +18 -0
- package/dist/dto/index.js.map +1 -0
- package/dist/dto/takaroEvents.d.ts +150 -0
- package/dist/dto/takaroEvents.js +422 -0
- package/dist/dto/takaroEvents.js.map +1 -0
- package/dist/main.d.ts +4 -0
- package/dist/main.js +31 -0
- package/dist/main.js.map +1 -0
- package/dist/modules/chatBridge/hooks/DiscordToGame.d.ts +1 -0
- package/dist/modules/chatBridge/hooks/DiscordToGame.js +18 -0
- package/dist/modules/chatBridge/hooks/DiscordToGame.js.map +1 -0
- package/dist/modules/chatBridge/hooks/GameToDiscord.d.ts +1 -0
- package/dist/modules/chatBridge/hooks/GameToDiscord.js +14 -0
- package/dist/modules/chatBridge/hooks/GameToDiscord.js.map +1 -0
- package/dist/modules/chatBridge/hooks/PlayerConnected.d.ts +1 -0
- package/dist/modules/chatBridge/hooks/PlayerConnected.js +9 -0
- package/dist/modules/chatBridge/hooks/PlayerConnected.js.map +1 -0
- package/dist/modules/chatBridge/hooks/PlayerDisconnected.d.ts +1 -0
- package/dist/modules/chatBridge/hooks/PlayerDisconnected.js +9 -0
- package/dist/modules/chatBridge/hooks/PlayerDisconnected.js.map +1 -0
- package/dist/modules/chatBridge/index.d.ts +4 -0
- package/dist/modules/chatBridge/index.js +54 -0
- package/dist/modules/chatBridge/index.js.map +1 -0
- package/dist/modules/economyUtils/commands/balance.d.ts +1 -0
- package/dist/modules/economyUtils/commands/balance.js +7 -0
- package/dist/modules/economyUtils/commands/balance.js.map +1 -0
- package/dist/modules/economyUtils/commands/confirmTransfer.d.ts +1 -0
- package/dist/modules/economyUtils/commands/confirmTransfer.js +38 -0
- package/dist/modules/economyUtils/commands/confirmTransfer.js.map +1 -0
- package/dist/modules/economyUtils/commands/grantCurrency.d.ts +1 -0
- package/dist/modules/economyUtils/commands/grantCurrency.js +31 -0
- package/dist/modules/economyUtils/commands/grantCurrency.js.map +1 -0
- package/dist/modules/economyUtils/commands/revokeCurrency.d.ts +1 -0
- package/dist/modules/economyUtils/commands/revokeCurrency.js +31 -0
- package/dist/modules/economyUtils/commands/revokeCurrency.js.map +1 -0
- package/dist/modules/economyUtils/commands/topCurrency.d.ts +1 -0
- package/dist/modules/economyUtils/commands/topCurrency.js +22 -0
- package/dist/modules/economyUtils/commands/topCurrency.js.map +1 -0
- package/dist/modules/economyUtils/commands/transfer.d.ts +1 -0
- package/dist/modules/economyUtils/commands/transfer.js +55 -0
- package/dist/modules/economyUtils/commands/transfer.js.map +1 -0
- package/dist/modules/economyUtils/index.d.ts +4 -0
- package/dist/modules/economyUtils/index.js +117 -0
- package/dist/modules/economyUtils/index.js.map +1 -0
- package/dist/modules/geoBlock/hooks/IPDetected.d.ts +1 -0
- package/dist/modules/geoBlock/hooks/IPDetected.js +50 -0
- package/dist/modules/geoBlock/hooks/IPDetected.js.map +1 -0
- package/dist/modules/geoBlock/index.d.ts +8 -0
- package/dist/modules/geoBlock/index.js +321 -0
- package/dist/modules/geoBlock/index.js.map +1 -0
- package/dist/modules/gimme/commands/gimme.d.ts +1 -0
- package/dist/modules/gimme/commands/gimme.js +23 -0
- package/dist/modules/gimme/commands/gimme.js.map +1 -0
- package/dist/modules/gimme/index.d.ts +4 -0
- package/dist/modules/gimme/index.js +43 -0
- package/dist/modules/gimme/index.js.map +1 -0
- package/dist/modules/highPingKicker/cronJobs/Ping check.d.ts +1 -0
- package/dist/modules/highPingKicker/cronJobs/Ping check.js +54 -0
- package/dist/modules/highPingKicker/cronJobs/Ping check.js.map +1 -0
- package/dist/modules/highPingKicker/index.d.ts +4 -0
- package/dist/modules/highPingKicker/index.js +34 -0
- package/dist/modules/highPingKicker/index.js.map +1 -0
- package/dist/modules/lottery/commands/buyTicket.d.ts +1 -0
- package/dist/modules/lottery/commands/buyTicket.js +54 -0
- package/dist/modules/lottery/commands/buyTicket.js.map +1 -0
- package/dist/modules/lottery/commands/nextDraw.d.ts +1 -0
- package/dist/modules/lottery/commands/nextDraw.js +34 -0
- package/dist/modules/lottery/commands/nextDraw.js.map +1 -0
- package/dist/modules/lottery/commands/viewTickets.d.ts +1 -0
- package/dist/modules/lottery/commands/viewTickets.js +23 -0
- package/dist/modules/lottery/commands/viewTickets.js.map +1 -0
- package/dist/modules/lottery/cronJobs/drawLottery.d.ts +1 -0
- package/dist/modules/lottery/cronJobs/drawLottery.js +96 -0
- package/dist/modules/lottery/cronJobs/drawLottery.js.map +1 -0
- package/dist/modules/lottery/index.d.ts +4 -0
- package/dist/modules/lottery/index.js +73 -0
- package/dist/modules/lottery/index.js.map +1 -0
- package/dist/modules/playerOnboarding/commands/starterkit.d.ts +1 -0
- package/dist/modules/playerOnboarding/commands/starterkit.js +34 -0
- package/dist/modules/playerOnboarding/commands/starterkit.js.map +1 -0
- package/dist/modules/playerOnboarding/hooks/playerConnected.d.ts +1 -0
- package/dist/modules/playerOnboarding/hooks/playerConnected.js +11 -0
- package/dist/modules/playerOnboarding/hooks/playerConnected.js.map +1 -0
- package/dist/modules/playerOnboarding/index.d.ts +4 -0
- package/dist/modules/playerOnboarding/index.js +51 -0
- package/dist/modules/playerOnboarding/index.js.map +1 -0
- package/dist/modules/serverMessages/cronJobs/Automated message.d.ts +1 -0
- package/dist/modules/serverMessages/cronJobs/Automated message.js +9 -0
- package/dist/modules/serverMessages/cronJobs/Automated message.js.map +1 -0
- package/dist/modules/serverMessages/index.d.ts +4 -0
- package/dist/modules/serverMessages/index.js +35 -0
- package/dist/modules/serverMessages/index.js.map +1 -0
- package/dist/modules/teleports/commands/deletetp.d.ts +1 -0
- package/dist/modules/teleports/commands/deletetp.js +20 -0
- package/dist/modules/teleports/commands/deletetp.js.map +1 -0
- package/dist/modules/teleports/commands/deletewaypoint.d.ts +1 -0
- package/dist/modules/teleports/commands/deletewaypoint.js +54 -0
- package/dist/modules/teleports/commands/deletewaypoint.js.map +1 -0
- package/dist/modules/teleports/commands/listwaypoints.d.ts +1 -0
- package/dist/modules/teleports/commands/listwaypoints.js +36 -0
- package/dist/modules/teleports/commands/listwaypoints.js.map +1 -0
- package/dist/modules/teleports/commands/setprivate.d.ts +1 -0
- package/dist/modules/teleports/commands/setprivate.js +31 -0
- package/dist/modules/teleports/commands/setprivate.js.map +1 -0
- package/dist/modules/teleports/commands/setpublic.d.ts +1 -0
- package/dist/modules/teleports/commands/setpublic.js +55 -0
- package/dist/modules/teleports/commands/setpublic.js.map +1 -0
- package/dist/modules/teleports/commands/settp.d.ts +1 -0
- package/dist/modules/teleports/commands/settp.js +42 -0
- package/dist/modules/teleports/commands/settp.js.map +1 -0
- package/dist/modules/teleports/commands/setwaypoint.d.ts +1 -0
- package/dist/modules/teleports/commands/setwaypoint.js +88 -0
- package/dist/modules/teleports/commands/setwaypoint.js.map +1 -0
- package/dist/modules/teleports/commands/teleport.d.ts +1 -0
- package/dist/modules/teleports/commands/teleport.js +74 -0
- package/dist/modules/teleports/commands/teleport.js.map +1 -0
- package/dist/modules/teleports/commands/teleportwaypoint.d.ts +1 -0
- package/dist/modules/teleports/commands/teleportwaypoint.js +50 -0
- package/dist/modules/teleports/commands/teleportwaypoint.js.map +1 -0
- package/dist/modules/teleports/commands/tplist.d.ts +1 -0
- package/dist/modules/teleports/commands/tplist.js +45 -0
- package/dist/modules/teleports/commands/tplist.js.map +1 -0
- package/dist/modules/teleports/functions/utils.d.ts +2 -0
- package/dist/modules/teleports/functions/utils.js +18 -0
- package/dist/modules/teleports/functions/utils.js.map +1 -0
- package/dist/modules/teleports/index.d.ts +4 -0
- package/dist/modules/teleports/index.js +184 -0
- package/dist/modules/teleports/index.js.map +1 -0
- package/dist/modules/utils/commands/help.d.ts +1 -0
- package/dist/modules/utils/commands/help.js +29 -0
- package/dist/modules/utils/commands/help.js.map +1 -0
- package/dist/modules/utils/commands/ping.d.ts +1 -0
- package/dist/modules/utils/commands/ping.js +6 -0
- package/dist/modules/utils/commands/ping.js.map +1 -0
- package/dist/modules/utils/index.d.ts +4 -0
- package/dist/modules/utils/index.js +35 -0
- package/dist/modules/utils/index.js.map +1 -0
- package/dist/modules.json +478 -0
- package/package.json +26 -0
- package/scripts/buildBuiltinJson.ts +14 -0
- package/src/BuiltinModule.ts +125 -0
- package/src/__tests__/aliases.integration.test.ts +54 -0
- package/src/__tests__/builtinmodule.unit.test.ts +13 -0
- package/src/__tests__/commandArgs.integration.test.ts +285 -0
- package/src/__tests__/economyUtils.integration.test.ts +488 -0
- package/src/__tests__/geoblock.integration.test.ts +380 -0
- package/src/__tests__/gimme.integration.test.ts +97 -0
- package/src/__tests__/help.integration.test.ts +133 -0
- package/src/__tests__/lottery.integration.test.ts +332 -0
- package/src/__tests__/modulePermission.integration.test.ts +192 -0
- package/src/__tests__/onboarding.integration.test.ts +123 -0
- package/src/__tests__/ping.integration.test.ts +36 -0
- package/src/__tests__/roleExpiry.integration.test.ts +74 -0
- package/src/__tests__/serverMessages.integration.test.ts +104 -0
- package/src/__tests__/systemConfigCost.integration.test.ts +196 -0
- package/src/__tests__/teleports/listtp.integration.test.ts +115 -0
- package/src/__tests__/teleports/publicteleports.integration.test.ts +350 -0
- package/src/__tests__/teleports/teleport.integration.test.ts +109 -0
- package/src/__tests__/teleports/tpManagement.integration.test.ts +175 -0
- package/src/__tests__/teleports/waypoints.integration.test.ts +613 -0
- package/src/dto/base.ts +13 -0
- package/src/dto/discordEvents.ts +69 -0
- package/src/dto/gameEvents.ts +154 -0
- package/src/dto/index.ts +25 -0
- package/src/dto/takaroEvents.ts +290 -0
- package/src/main.ts +36 -0
- package/src/modules/.eslintrc +5 -0
- package/src/modules/chatBridge/hooks/DiscordToGame.js +18 -0
- package/src/modules/chatBridge/hooks/GameToDiscord.js +18 -0
- package/src/modules/chatBridge/hooks/PlayerConnected.js +11 -0
- package/src/modules/chatBridge/hooks/PlayerDisconnected.js +11 -0
- package/src/modules/chatBridge/index.ts +59 -0
- package/src/modules/economyUtils/commands/balance.js +8 -0
- package/src/modules/economyUtils/commands/confirmTransfer.js +55 -0
- package/src/modules/economyUtils/commands/grantCurrency.js +38 -0
- package/src/modules/economyUtils/commands/revokeCurrency.js +38 -0
- package/src/modules/economyUtils/commands/topCurrency.js +29 -0
- package/src/modules/economyUtils/commands/transfer.js +73 -0
- package/src/modules/economyUtils/index.ts +125 -0
- package/src/modules/geoBlock/hooks/IPDetected.js +52 -0
- package/src/modules/geoBlock/index.ts +331 -0
- package/src/modules/gimme/commands/gimme.js +28 -0
- package/src/modules/gimme/index.ts +49 -0
- package/src/modules/highPingKicker/cronJobs/Ping check.js +66 -0
- package/src/modules/highPingKicker/index.ts +39 -0
- package/src/modules/lottery/commands/buyTicket.js +68 -0
- package/src/modules/lottery/commands/nextDraw.js +45 -0
- package/src/modules/lottery/commands/viewTickets.js +32 -0
- package/src/modules/lottery/cronJobs/drawLottery.js +124 -0
- package/src/modules/lottery/index.ts +80 -0
- package/src/modules/playerOnboarding/commands/starterkit.js +47 -0
- package/src/modules/playerOnboarding/hooks/playerConnected.js +14 -0
- package/src/modules/playerOnboarding/index.ts +58 -0
- package/src/modules/serverMessages/cronJobs/Automated message.js +12 -0
- package/src/modules/serverMessages/index.ts +40 -0
- package/src/modules/teleports/commands/deletetp.js +25 -0
- package/src/modules/teleports/commands/deletewaypoint.js +77 -0
- package/src/modules/teleports/commands/listwaypoints.js +55 -0
- package/src/modules/teleports/commands/setprivate.js +39 -0
- package/src/modules/teleports/commands/setpublic.js +71 -0
- package/src/modules/teleports/commands/settp.js +54 -0
- package/src/modules/teleports/commands/setwaypoint.js +112 -0
- package/src/modules/teleports/commands/teleport.js +93 -0
- package/src/modules/teleports/commands/teleportwaypoint.js +72 -0
- package/src/modules/teleports/commands/tplist.js +61 -0
- package/src/modules/teleports/functions/utils.js +20 -0
- package/src/modules/teleports/index.ts +193 -0
- package/src/modules/utils/commands/help.js +38 -0
- package/src/modules/utils/commands/ping.js +7 -0
- package/src/modules/utils/index.ts +40 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +9 -0
- package/typedoc.json +3 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { takaro, data } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
function getTotalPrize(tickets, ticketPrice, profitMargin) {
|
|
4
|
+
const amount = tickets.reduce((acc, ticket) => {
|
|
5
|
+
const ticketAmount = parseInt(JSON.parse(ticket.value).amount, 10);
|
|
6
|
+
|
|
7
|
+
return acc + ticketAmount;
|
|
8
|
+
}, 0);
|
|
9
|
+
|
|
10
|
+
const rawTotal = amount * ticketPrice;
|
|
11
|
+
const profit = rawTotal * profitMargin;
|
|
12
|
+
const totalPrize = rawTotal - profit;
|
|
13
|
+
|
|
14
|
+
return totalPrize;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function drawWinner(takaro, gameServerId, tickets) {
|
|
18
|
+
const randomIndex = Math.floor(Math.random() * tickets.length);
|
|
19
|
+
const winnerTicket = tickets[randomIndex];
|
|
20
|
+
|
|
21
|
+
const winner = (await takaro.player.playerControllerGetOne(winnerTicket.playerId)).data.data;
|
|
22
|
+
const pog = await takaro.playerOnGameserver.playerOnGameServerControllerSearch({
|
|
23
|
+
filters: {
|
|
24
|
+
gameServerId: [gameServerId],
|
|
25
|
+
playerId: [winner.id],
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
name: winner.name,
|
|
31
|
+
playerId: pog.data.data[0].playerId,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function refundPlayer(takaro, gameServerId, playerId, amount, currencyName) {
|
|
36
|
+
const pog = (
|
|
37
|
+
await takaro.playerOnGameserver.playerOnGameServerControllerSearch({
|
|
38
|
+
filters: {
|
|
39
|
+
gameServerId: [gameServerId],
|
|
40
|
+
playerId: [playerId],
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
).data.data[0];
|
|
44
|
+
|
|
45
|
+
await takaro.playerOnGameserver.playerOnGameServerControllerAddCurrency(gameServerId, pog.playerId, {
|
|
46
|
+
currency: amount,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
|
|
50
|
+
message: `You have been refunded ${amount} ${currencyName} because the lottery has been cancelled.`,
|
|
51
|
+
opts: {
|
|
52
|
+
recipient: {
|
|
53
|
+
gameId: pog.gameId,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function cleanUp(takaro, tickets) {
|
|
60
|
+
const deleteTasks = tickets.map((ticket) => takaro.variable.variableControllerDelete(ticket.id));
|
|
61
|
+
await Promise.allSettled(deleteTasks);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function main() {
|
|
65
|
+
const { gameServerId, module: mod } = data;
|
|
66
|
+
|
|
67
|
+
let tickets = [];
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', gameServerId)).data.data.value;
|
|
71
|
+
const ticketCost = mod.systemConfig.commands.buyTicket.cost;
|
|
72
|
+
|
|
73
|
+
tickets = (
|
|
74
|
+
await takaro.variable.variableControllerSearch({
|
|
75
|
+
filters: {
|
|
76
|
+
gameServerId: [gameServerId],
|
|
77
|
+
moduleId: [mod.moduleId],
|
|
78
|
+
key: ['lottery_tickets_bought'],
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
).data.data;
|
|
82
|
+
|
|
83
|
+
if (tickets.length === 0) {
|
|
84
|
+
await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
|
|
85
|
+
message: 'No one has bought any tickets. The lottery has been cancelled.',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (tickets.length === 1) {
|
|
92
|
+
await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
|
|
93
|
+
message: 'Only one person has bought a ticket. The lottery has been cancelled.',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const amount = parseInt(JSON.parse(tickets[0].value).amount, 10) * ticketCost;
|
|
97
|
+
|
|
98
|
+
await refundPlayer(takaro, gameServerId, tickets[0].playerId, amount, currencyName);
|
|
99
|
+
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const totalPrize = getTotalPrize(tickets, ticketCost, mod.userConfig.profitMargin);
|
|
104
|
+
const { name: winnerName, playerId } = await drawWinner(takaro, gameServerId, tickets);
|
|
105
|
+
|
|
106
|
+
await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
|
|
107
|
+
message: 'The lottery raffle is about to start!',
|
|
108
|
+
});
|
|
109
|
+
await takaro.gameserver.gameServerControllerSendMessage(gameServerId, { message: 'drumrolls please...' });
|
|
110
|
+
await takaro.gameserver.gameServerControllerSendMessage(gameServerId, { message: 'The winner is...' });
|
|
111
|
+
|
|
112
|
+
await takaro.playerOnGameserver.playerOnGameServerControllerAddCurrency(gameServerId, playerId, {
|
|
113
|
+
currency: totalPrize,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
|
|
117
|
+
message: `${winnerName}! Congratulations! You have won ${totalPrize} ${currencyName}!`,
|
|
118
|
+
});
|
|
119
|
+
} finally {
|
|
120
|
+
await cleanUp(takaro, tickets);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
await main();
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { BuiltinModule, ICommand, ICronJob, IPermission } from '../../BuiltinModule.js';
|
|
2
|
+
|
|
3
|
+
export class Lottery extends BuiltinModule<Lottery> {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(
|
|
6
|
+
'lottery',
|
|
7
|
+
'Players can buy tickets for a lottery, and the winner is chosen at random.',
|
|
8
|
+
JSON.stringify({
|
|
9
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
profitMargin: {
|
|
13
|
+
type: 'number',
|
|
14
|
+
maximum: 1,
|
|
15
|
+
minimum: 0,
|
|
16
|
+
description: 'The profit margin the server takes from the lottery.',
|
|
17
|
+
default: 0.1,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: [],
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
this.permissions = [
|
|
26
|
+
new IPermission({
|
|
27
|
+
permission: 'LOTTERY_BUY',
|
|
28
|
+
friendlyName: 'Buy Lottery Tickets',
|
|
29
|
+
canHaveCount: false,
|
|
30
|
+
description: 'Allows the player to buy lottery tickets.',
|
|
31
|
+
}),
|
|
32
|
+
new IPermission({
|
|
33
|
+
permission: 'LOTTERY_VIEW_TICKETS',
|
|
34
|
+
friendlyName: 'View Lottery Tickets',
|
|
35
|
+
description: 'Allows the player to view his lottery tickets.',
|
|
36
|
+
canHaveCount: false,
|
|
37
|
+
}),
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
this.cronJobs = [
|
|
41
|
+
new ICronJob({
|
|
42
|
+
name: 'drawLottery',
|
|
43
|
+
temporalValue: '0 0 * * *',
|
|
44
|
+
function: this.loadFn('cronJobs', 'drawLottery'),
|
|
45
|
+
}),
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
this.commands = [
|
|
49
|
+
new ICommand({
|
|
50
|
+
function: this.loadFn('commands', 'buyTicket'),
|
|
51
|
+
name: 'buyTicket',
|
|
52
|
+
trigger: 'buyTicket',
|
|
53
|
+
helpText: 'Buy a lottery ticket.',
|
|
54
|
+
arguments: [
|
|
55
|
+
{
|
|
56
|
+
name: 'amount',
|
|
57
|
+
type: 'number',
|
|
58
|
+
helpText: 'The amount of tickets to buy.',
|
|
59
|
+
position: 0,
|
|
60
|
+
defaultValue: null,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
}),
|
|
64
|
+
new ICommand({
|
|
65
|
+
function: this.loadFn('commands', 'viewTickets'),
|
|
66
|
+
name: 'viewTickets',
|
|
67
|
+
trigger: 'viewTickets',
|
|
68
|
+
helpText: 'View your lottery tickets.',
|
|
69
|
+
arguments: [],
|
|
70
|
+
}),
|
|
71
|
+
new ICommand({
|
|
72
|
+
function: this.loadFn('commands', 'nextDraw'),
|
|
73
|
+
name: 'nextDraw',
|
|
74
|
+
trigger: 'nextDraw',
|
|
75
|
+
helpText: 'View when the next draw is.',
|
|
76
|
+
arguments: [],
|
|
77
|
+
}),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { takaro, data, TakaroUserError } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
const VARIABLE_KEY = 't_starterkit_lock';
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const items = data.module.userConfig.starterKitItems;
|
|
7
|
+
|
|
8
|
+
if (!items || items.length === 0) {
|
|
9
|
+
throw new TakaroUserError(
|
|
10
|
+
'No starter kit items configured. Please ask your server administrator to configure this.'
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const starterKitLockRes = await takaro.variable.variableControllerSearch({
|
|
15
|
+
filters: {
|
|
16
|
+
key: [VARIABLE_KEY],
|
|
17
|
+
gameServerId: [data.gameServerId],
|
|
18
|
+
playerId: [data.player.id],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (starterKitLockRes.data.data.length > 0) {
|
|
23
|
+
throw new TakaroUserError('You already used starterkit on this server');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await data.player.pm('You are about to receive your starter kit...');
|
|
27
|
+
|
|
28
|
+
await Promise.all(
|
|
29
|
+
items.map(async (item) => {
|
|
30
|
+
return takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {
|
|
31
|
+
name: item,
|
|
32
|
+
amount: 1,
|
|
33
|
+
});
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
await takaro.variable.variableControllerCreate({
|
|
38
|
+
key: VARIABLE_KEY,
|
|
39
|
+
value: '1',
|
|
40
|
+
gameServerId: data.gameServerId,
|
|
41
|
+
playerId: data.player.id,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await data.player.pm(`Gave ${items.length} items, enjoy!`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await main();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { takaro, data } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const { player } = data;
|
|
5
|
+
|
|
6
|
+
const rawMessage = data.module.userConfig.message;
|
|
7
|
+
const message = rawMessage.replace('{player}', player.name);
|
|
8
|
+
|
|
9
|
+
await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
|
|
10
|
+
message,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
await main();
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BuiltinModule, ICommand, IHook } from '../../BuiltinModule.js';
|
|
2
|
+
import { HookEvents } from '../../dto/index.js';
|
|
3
|
+
export class PlayerOnboarding extends BuiltinModule<PlayerOnboarding> {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(
|
|
6
|
+
'playerOnboarding',
|
|
7
|
+
'Collection of functions that are executed when a player joins the server. Helps with onboarding new players, like sending a welcome message.',
|
|
8
|
+
JSON.stringify({
|
|
9
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
message: {
|
|
13
|
+
title: 'Message',
|
|
14
|
+
description: 'The message to send to the player when they join the server.',
|
|
15
|
+
type: 'string',
|
|
16
|
+
minLength: 1,
|
|
17
|
+
maxLength: 256,
|
|
18
|
+
default: 'Welcome {player} to the server!',
|
|
19
|
+
},
|
|
20
|
+
starterKitItems: {
|
|
21
|
+
type: 'array',
|
|
22
|
+
'x-component': 'item',
|
|
23
|
+
title: 'Starter kit items',
|
|
24
|
+
description:
|
|
25
|
+
'List of items a player will receive when they execute the starterkit command for the first time.',
|
|
26
|
+
uniqueItems: true,
|
|
27
|
+
items: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
required: [],
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
}),
|
|
35
|
+
JSON.stringify({
|
|
36
|
+
starterKitItems: { 'ui:widget': 'item' },
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
this.hooks = [
|
|
41
|
+
new IHook({
|
|
42
|
+
eventType: HookEvents.PLAYER_CONNECTED,
|
|
43
|
+
name: 'playerConnected',
|
|
44
|
+
function: this.loadFn('hooks', 'playerConnected'),
|
|
45
|
+
}),
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
this.commands = [
|
|
49
|
+
new ICommand({
|
|
50
|
+
name: 'starterkit',
|
|
51
|
+
function: this.loadFn('commands', 'starterkit'),
|
|
52
|
+
trigger: 'starterkit',
|
|
53
|
+
helpText: 'Get a starter kit, you can only execute this once on a server!',
|
|
54
|
+
arguments: [],
|
|
55
|
+
}),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { takaro, data } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const randomMessage =
|
|
5
|
+
data.module.userConfig.messages[Math.floor(Math.random() * data.module.userConfig.messages.length)];
|
|
6
|
+
|
|
7
|
+
await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
|
|
8
|
+
message: randomMessage,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
await main();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BuiltinModule, ICronJob } from '../../BuiltinModule.js';
|
|
2
|
+
|
|
3
|
+
export class ServerMessages extends BuiltinModule<ServerMessages> {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(
|
|
6
|
+
'serverMessages',
|
|
7
|
+
'Send automated, rotated, configurable messages to players on the server.',
|
|
8
|
+
JSON.stringify({
|
|
9
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
messages: {
|
|
13
|
+
type: 'array',
|
|
14
|
+
title: 'Messages',
|
|
15
|
+
description: 'List of messages that will be sent to players on the server.',
|
|
16
|
+
default: [
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
'This is an automated message, don\'t forget to read the server rules!',
|
|
19
|
+
],
|
|
20
|
+
items: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
minLength: 5,
|
|
23
|
+
maxLength: 1024,
|
|
24
|
+
},
|
|
25
|
+
minItems: 1,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
required: ['messages'],
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
this.cronJobs = [
|
|
33
|
+
new ICronJob({
|
|
34
|
+
name: 'Automated message',
|
|
35
|
+
temporalValue: '*/30 * * * *',
|
|
36
|
+
function: this.loadFn('cronJobs', 'Automated message'),
|
|
37
|
+
}),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { takaro, data, TakaroUserError } from '@takaro/helpers';
|
|
2
|
+
import { getVariableKey } from './utils.js';
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const { pog, gameServerId, arguments: args, module: mod } = data;
|
|
6
|
+
|
|
7
|
+
const existingVariable = await takaro.variable.variableControllerSearch({
|
|
8
|
+
filters: {
|
|
9
|
+
key: [getVariableKey(args.tp)],
|
|
10
|
+
gameServerId: [gameServerId],
|
|
11
|
+
playerId: [pog.playerId],
|
|
12
|
+
moduleId: [mod.moduleId],
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (existingVariable.data.data.length === 0) {
|
|
17
|
+
throw new TakaroUserError(`Teleport ${args.tp} does not exist.`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await takaro.variable.variableControllerDelete(existingVariable.data.data[0].id);
|
|
21
|
+
|
|
22
|
+
await data.player.pm(`Teleport ${args.tp} deleted.`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await main();
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
function getWaypointName(name) {
|
|
4
|
+
return `waypoint ${name}`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
const { pog, gameServerId, arguments: args } = data;
|
|
9
|
+
|
|
10
|
+
if (!checkPermission(pog, 'TELEPORTS_MANAGE_WAYPOINTS')) {
|
|
11
|
+
throw new TakaroUserError('You do not have permission to manage waypoints.');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function ensureWaypointsModule() {
|
|
15
|
+
let waypointsDefinition = (
|
|
16
|
+
await takaro.module.moduleControllerSearch({
|
|
17
|
+
filters: {
|
|
18
|
+
name: ['Waypoints'],
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
).data.data[0];
|
|
22
|
+
|
|
23
|
+
if (!waypointsDefinition) {
|
|
24
|
+
console.log('Waypoints module definition not found, creating it.');
|
|
25
|
+
waypointsDefinition = (
|
|
26
|
+
await takaro.module.moduleControllerCreate({
|
|
27
|
+
name: 'Waypoints',
|
|
28
|
+
description: 'Waypoints module for the teleport system.',
|
|
29
|
+
})
|
|
30
|
+
).data.data;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let waypointsInstallation = (
|
|
34
|
+
await takaro.gameserver.gameServerControllerGetInstalledModules(gameServerId)
|
|
35
|
+
).data.data.find((module) => module.name === 'Waypoints');
|
|
36
|
+
|
|
37
|
+
if (!waypointsInstallation) {
|
|
38
|
+
console.log('Waypoints module not found, installing it.');
|
|
39
|
+
waypointsInstallation = (
|
|
40
|
+
await takaro.gameserver.gameServerControllerInstallModule(gameServerId, waypointsDefinition.id)
|
|
41
|
+
).data.data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { waypointsInstallation, waypointsDefinition };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { waypointsInstallation } = await ensureWaypointsModule();
|
|
48
|
+
|
|
49
|
+
const variable = await takaro.variable.variableControllerSearch({
|
|
50
|
+
filters: {
|
|
51
|
+
key: [getWaypointName(args.waypoint)],
|
|
52
|
+
gameServerId: [gameServerId],
|
|
53
|
+
moduleId: [waypointsInstallation.moduleId],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (!variable.data.data.length) {
|
|
58
|
+
throw new TakaroUserError(`Waypoint ${args.waypoint} doesn't exist.`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await takaro.variable.variableControllerDelete(variable.data.data[0].id);
|
|
62
|
+
|
|
63
|
+
const teleportCommand = await takaro.command.commandControllerSearch({
|
|
64
|
+
filters: {
|
|
65
|
+
moduleId: [waypointsInstallation.moduleId],
|
|
66
|
+
name: [`waypoint ${args.waypoint} server ${gameServerId}`],
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (teleportCommand.data.data.length) {
|
|
71
|
+
await takaro.command.commandControllerRemove(teleportCommand.data.data[0].id);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
await pog.pm(`Waypoint ${args.waypoint} deleted.`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
await main();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { takaro, data, checkPermission } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const { pog, gameServerId } = data;
|
|
5
|
+
|
|
6
|
+
async function ensureWaypointsModule() {
|
|
7
|
+
let waypointsDefinition = (
|
|
8
|
+
await takaro.module.moduleControllerSearch({
|
|
9
|
+
filters: {
|
|
10
|
+
name: ['Waypoints'],
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
).data.data[0];
|
|
14
|
+
|
|
15
|
+
if (!waypointsDefinition) {
|
|
16
|
+
console.log('Waypoints module definition not found, creating it.');
|
|
17
|
+
waypointsDefinition = (
|
|
18
|
+
await takaro.module.moduleControllerCreate({
|
|
19
|
+
name: 'Waypoints',
|
|
20
|
+
description: 'Waypoints module for the teleport system.',
|
|
21
|
+
})
|
|
22
|
+
).data.data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let waypointsInstallation = (
|
|
26
|
+
await takaro.gameserver.gameServerControllerGetInstalledModules(gameServerId)
|
|
27
|
+
).data.data.find((module) => module.name === 'Waypoints');
|
|
28
|
+
|
|
29
|
+
if (!waypointsInstallation) {
|
|
30
|
+
console.log('Waypoints module not found, installing it.');
|
|
31
|
+
waypointsInstallation = (
|
|
32
|
+
await takaro.gameserver.gameServerControllerInstallModule(gameServerId, waypointsDefinition.id)
|
|
33
|
+
).data.data;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { waypointsInstallation, waypointsDefinition };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { waypointsDefinition } = await ensureWaypointsModule();
|
|
40
|
+
|
|
41
|
+
const allWaypoints = waypointsDefinition.commands;
|
|
42
|
+
|
|
43
|
+
const waypointsWithPermission = allWaypoints
|
|
44
|
+
.filter((waypoint) => checkPermission(pog, `WAYPOINTS_USE_${waypoint.trigger.toUpperCase()}_${gameServerId}`))
|
|
45
|
+
.sort((a, b) => a.trigger.localeCompare(b.trigger));
|
|
46
|
+
|
|
47
|
+
if (!waypointsWithPermission.length) {
|
|
48
|
+
await pog.pm('There are no waypoints available.');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await pog.pm(`Available waypoints: ${waypointsWithPermission.map((waypoint) => waypoint.trigger).join(', ')}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await main();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { takaro, data, TakaroUserError } from '@takaro/helpers';
|
|
2
|
+
import { getVariableKey } from './utils.js';
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const { pog, gameServerId, arguments: args, module: mod } = data;
|
|
6
|
+
|
|
7
|
+
const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data;
|
|
8
|
+
|
|
9
|
+
const teleportRes = await takaro.variable.variableControllerSearch({
|
|
10
|
+
filters: {
|
|
11
|
+
gameServerId: [gameServerId],
|
|
12
|
+
playerId: [pog.playerId],
|
|
13
|
+
key: [getVariableKey(args.tp)],
|
|
14
|
+
moduleId: [mod.moduleId],
|
|
15
|
+
},
|
|
16
|
+
sortBy: 'key',
|
|
17
|
+
sortDirection: 'asc',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const teleports = teleportRes.data.data;
|
|
21
|
+
|
|
22
|
+
if (teleports.length === 0) {
|
|
23
|
+
throw new TakaroUserError(`No teleport with name ${args.tp} found, use ${prefix}settp <name> to set one first.`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const teleportRecord = teleports[0];
|
|
27
|
+
const teleport = JSON.parse(teleportRecord.value);
|
|
28
|
+
|
|
29
|
+
await takaro.variable.variableControllerUpdate(teleportRecord.id, {
|
|
30
|
+
value: JSON.stringify({
|
|
31
|
+
...teleport,
|
|
32
|
+
public: false,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await data.player.pm(`Teleport ${args.tp} is now private.`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await main();
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';
|
|
2
|
+
import { getVariableKey } from './utils.js';
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const { pog, gameServerId, module: mod, arguments: args } = data;
|
|
6
|
+
|
|
7
|
+
const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data;
|
|
8
|
+
|
|
9
|
+
if (!mod.userConfig.allowPublicTeleports) {
|
|
10
|
+
throw new TakaroUserError('Public teleports are disabled.');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const hasPermission = checkPermission(pog, 'TELEPORTS_CREATE_PUBLIC');
|
|
14
|
+
|
|
15
|
+
if (!hasPermission) {
|
|
16
|
+
throw new TakaroUserError('You do not have permission to create public teleports.');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const existingTeleportsForPlayerRes = await takaro.variable.variableControllerSearch({
|
|
20
|
+
search: {
|
|
21
|
+
key: 'tp_',
|
|
22
|
+
},
|
|
23
|
+
filters: {
|
|
24
|
+
gameServerId: [gameServerId],
|
|
25
|
+
playerId: [pog.playerId],
|
|
26
|
+
moduleId: [mod.moduleId],
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const existingPublicTeleportsForPlayer = existingTeleportsForPlayerRes.data.data.filter((tp) => {
|
|
31
|
+
const teleport = JSON.parse(tp.value);
|
|
32
|
+
return teleport.public;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (existingPublicTeleportsForPlayer.length >= hasPermission.count) {
|
|
36
|
+
throw new TakaroUserError(
|
|
37
|
+
`You have reached the maximum number of public teleports for your role, maximum allowed is ${hasPermission.count}`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const teleportRes = await takaro.variable.variableControllerSearch({
|
|
42
|
+
filters: {
|
|
43
|
+
gameServerId: [gameServerId],
|
|
44
|
+
playerId: [pog.playerId],
|
|
45
|
+
moduleId: [mod.moduleId],
|
|
46
|
+
key: [getVariableKey(args.tp)],
|
|
47
|
+
},
|
|
48
|
+
sortBy: 'key',
|
|
49
|
+
sortDirection: 'asc',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const teleports = teleportRes.data.data;
|
|
53
|
+
|
|
54
|
+
if (teleports.length === 0) {
|
|
55
|
+
throw new TakaroUserError(`No teleport with name ${args.tp} found, use ${prefix}settp <name> to set one first.`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const teleportRecord = teleports[0];
|
|
59
|
+
const teleport = JSON.parse(teleportRecord.value);
|
|
60
|
+
|
|
61
|
+
await takaro.variable.variableControllerUpdate(teleportRecord.id, {
|
|
62
|
+
value: JSON.stringify({
|
|
63
|
+
...teleport,
|
|
64
|
+
public: true,
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await data.player.pm(`Teleport ${args.tp} is now public.`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await main();
|