@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,488 @@
|
|
|
1
|
+
import { IntegrationTest, expect } from '@takaro/test';
|
|
2
|
+
import { IModuleTestsSetupData, modulesTestSetup, chatMessageSorter } from '@takaro/test';
|
|
3
|
+
import { GameEvents } from '../dto/index.js';
|
|
4
|
+
|
|
5
|
+
const group = 'Economy utils suite';
|
|
6
|
+
|
|
7
|
+
const customSetup = async function (this: IntegrationTest<IModuleTestsSetupData>): Promise<IModuleTestsSetupData> {
|
|
8
|
+
const setupData = await modulesTestSetup.bind(this)();
|
|
9
|
+
|
|
10
|
+
await this.client.settings.settingsControllerSet('economyEnabled', {
|
|
11
|
+
value: 'true',
|
|
12
|
+
gameServerId: setupData.gameserver.id,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
await this.client.settings.settingsControllerSet('economyEnabled', {
|
|
16
|
+
value: 'true',
|
|
17
|
+
});
|
|
18
|
+
await this.client.settings.settingsControllerSet('currencyName', {
|
|
19
|
+
gameServerId: setupData.gameserver.id,
|
|
20
|
+
value: 'test coin',
|
|
21
|
+
});
|
|
22
|
+
return setupData;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const tests = [
|
|
26
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
27
|
+
group,
|
|
28
|
+
snapshot: false,
|
|
29
|
+
setup: customSetup,
|
|
30
|
+
name: 'Can get balance',
|
|
31
|
+
test: async function () {
|
|
32
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
33
|
+
this.setupData.gameserver.id,
|
|
34
|
+
this.setupData.economyUtilsModule.id
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
38
|
+
|
|
39
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
40
|
+
msg: '/balance',
|
|
41
|
+
playerId: this.setupData.players[0].id,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const playerOnGameServer = (
|
|
45
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerSearch({
|
|
46
|
+
filters: { playerId: [this.setupData.players[0].id], gameServerId: [this.setupData.gameserver.id] },
|
|
47
|
+
})
|
|
48
|
+
).data.data;
|
|
49
|
+
if (playerOnGameServer.length === 0) throw new Error('player not found');
|
|
50
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerSetCurrency(
|
|
51
|
+
playerOnGameServer[0].gameServerId,
|
|
52
|
+
playerOnGameServer[0].playerId,
|
|
53
|
+
{
|
|
54
|
+
currency: 1000,
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// trigger balance command
|
|
59
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
60
|
+
msg: '/balance',
|
|
61
|
+
playerId: this.setupData.players[0].id,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect((await events).length).to.be.eq(2);
|
|
65
|
+
expect((await events)[0].data.msg).to.be.eq('balance: 0 test coin');
|
|
66
|
+
expect((await events)[1].data.msg).to.be.eq('balance: 1000 test coin');
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
70
|
+
group,
|
|
71
|
+
snapshot: false,
|
|
72
|
+
setup: customSetup,
|
|
73
|
+
name: 'Can show list of top (max 10) players with highest balance',
|
|
74
|
+
test: async function () {
|
|
75
|
+
// install module
|
|
76
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
77
|
+
this.setupData.gameserver.id,
|
|
78
|
+
this.setupData.economyUtilsModule.id
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const giveCurrencies = this.setupData.players.map(async (player, index) => {
|
|
82
|
+
const playerOnGameServer = (
|
|
83
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerSearch({
|
|
84
|
+
filters: { playerId: [player.id], gameServerId: [this.setupData.gameserver.id] },
|
|
85
|
+
})
|
|
86
|
+
).data.data;
|
|
87
|
+
if (playerOnGameServer.length === 0) throw new Error('player not found');
|
|
88
|
+
return this.client.playerOnGameserver.playerOnGameServerControllerSetCurrency(
|
|
89
|
+
playerOnGameServer[0].gameServerId,
|
|
90
|
+
playerOnGameServer[0].playerId,
|
|
91
|
+
{
|
|
92
|
+
currency: 1000 * index,
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
await Promise.all(giveCurrencies);
|
|
97
|
+
|
|
98
|
+
// title message (1) + balance of player messages (5)
|
|
99
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 6);
|
|
100
|
+
|
|
101
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
102
|
+
msg: '/topcurrency',
|
|
103
|
+
playerId: this.setupData.players[0].id,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const messages = (await events).map((e) => e.data.msg as string);
|
|
107
|
+
expect((await events).length).to.be.eq(6);
|
|
108
|
+
for (const message of messages) {
|
|
109
|
+
expect(message).to.match(
|
|
110
|
+
/(Richest players\:|1\. .+ - 4000 test coin|2\. .+ - 3000 test coin|3\. .+ - 2000 test coin|4\. .+ - 1000 test coin|5\. .+ - 0 test coin)/
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
116
|
+
group,
|
|
117
|
+
snapshot: false,
|
|
118
|
+
setup: customSetup,
|
|
119
|
+
name: 'Can transfer money to another player',
|
|
120
|
+
test: async function () {
|
|
121
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
122
|
+
this.setupData.gameserver.id,
|
|
123
|
+
this.setupData.economyUtilsModule.id
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const transferAmount = 500;
|
|
127
|
+
|
|
128
|
+
const sender = this.setupData.players[0];
|
|
129
|
+
const senderPog = sender.playerOnGameServers?.find((pog) => pog.gameServerId === this.setupData.gameserver.id);
|
|
130
|
+
if (!senderPog) throw new Error('Sender playerOnGameServer does not exist');
|
|
131
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerSetCurrency(
|
|
132
|
+
senderPog.gameServerId,
|
|
133
|
+
senderPog.playerId,
|
|
134
|
+
{
|
|
135
|
+
currency: transferAmount,
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const receiver = this.setupData.players[1];
|
|
140
|
+
const receiverPog = receiver.playerOnGameServers?.find(
|
|
141
|
+
(pog) => pog.gameServerId === this.setupData.gameserver.id
|
|
142
|
+
);
|
|
143
|
+
if (!receiverPog) throw new Error('Receiver playerOnGameServer does not exist');
|
|
144
|
+
expect(receiverPog.currency).to.be.eq(0);
|
|
145
|
+
|
|
146
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
147
|
+
|
|
148
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
149
|
+
msg: `/transfer ${receiver.name} ${transferAmount}`,
|
|
150
|
+
playerId: sender.id,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const messages = (await events).sort(chatMessageSorter).map((e) => e.data.msg as string);
|
|
154
|
+
expect((await events).length).to.be.eq(2);
|
|
155
|
+
|
|
156
|
+
// check if balances are correct
|
|
157
|
+
const updatedSender = await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
158
|
+
senderPog.gameServerId,
|
|
159
|
+
senderPog.playerId
|
|
160
|
+
);
|
|
161
|
+
expect(updatedSender.data.data.currency).to.be.eq(0);
|
|
162
|
+
|
|
163
|
+
const updatedReceiver = await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
164
|
+
receiverPog.gameServerId,
|
|
165
|
+
receiverPog.playerId
|
|
166
|
+
);
|
|
167
|
+
expect(updatedReceiver.data.data.currency).to.be.eq(transferAmount);
|
|
168
|
+
|
|
169
|
+
expect(messages[0]).to.be.eq(`You received ${transferAmount} test coin from ${sender.name}`);
|
|
170
|
+
expect(messages[1]).to.be.eq(`You successfully transferred ${transferAmount} test coin to ${receiver.name}`);
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
174
|
+
group,
|
|
175
|
+
snapshot: false,
|
|
176
|
+
setup: customSetup,
|
|
177
|
+
name: 'Should return friendly user error when not enough currency',
|
|
178
|
+
test: async function () {
|
|
179
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
180
|
+
this.setupData.gameserver.id,
|
|
181
|
+
this.setupData.economyUtilsModule.id
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const sender = this.setupData.players[0];
|
|
185
|
+
const receiver = this.setupData.players[1];
|
|
186
|
+
const transferAmount = 500;
|
|
187
|
+
|
|
188
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
189
|
+
|
|
190
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
191
|
+
msg: `/transfer ${receiver.name} ${transferAmount}`,
|
|
192
|
+
playerId: sender.id,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const messages = (await events).sort(chatMessageSorter).map((e) => e.data.msg as string);
|
|
196
|
+
expect((await events).length).to.be.eq(1);
|
|
197
|
+
expect(messages[0]).to.be.eq(
|
|
198
|
+
`Failed to transfer ${transferAmount} test coin to ${receiver.name}. Are you sure you have enough balance?`
|
|
199
|
+
);
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
203
|
+
group,
|
|
204
|
+
snapshot: false,
|
|
205
|
+
setup: customSetup,
|
|
206
|
+
name: 'Should require confirmation when transfer amount is above pendingAmount',
|
|
207
|
+
test: async function () {
|
|
208
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
209
|
+
this.setupData.gameserver.id,
|
|
210
|
+
this.setupData.economyUtilsModule.id,
|
|
211
|
+
{
|
|
212
|
+
userConfig: JSON.stringify({
|
|
213
|
+
pendingAmount: 100,
|
|
214
|
+
}),
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const transferAmount = 500;
|
|
219
|
+
const prefix = (
|
|
220
|
+
await this.client.settings.settingsControllerGetOne('commandPrefix', this.setupData.gameserver.id)
|
|
221
|
+
).data.data.value;
|
|
222
|
+
|
|
223
|
+
const sender = this.setupData.players[0];
|
|
224
|
+
const senderPog = sender.playerOnGameServers?.find((pog) => pog.gameServerId === this.setupData.gameserver.id);
|
|
225
|
+
if (!senderPog) throw new Error('Sender playerOnGameServer does not exist');
|
|
226
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerSetCurrency(
|
|
227
|
+
senderPog.gameServerId,
|
|
228
|
+
senderPog.playerId,
|
|
229
|
+
{
|
|
230
|
+
currency: transferAmount,
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const receiver = this.setupData.players[1];
|
|
235
|
+
const receiverPog = receiver.playerOnGameServers?.find(
|
|
236
|
+
(pog) => pog.gameServerId === this.setupData.gameserver.id
|
|
237
|
+
);
|
|
238
|
+
if (!receiverPog) throw new Error('Receiver playerOnGameServer does not exist');
|
|
239
|
+
expect(receiverPog.currency).to.be.eq(0);
|
|
240
|
+
|
|
241
|
+
let events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
242
|
+
|
|
243
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
244
|
+
msg: `/transfer ${receiver.name} ${transferAmount}`,
|
|
245
|
+
playerId: sender.id,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
let messages = (await events).sort(chatMessageSorter).map((e) => e.data.msg as string);
|
|
249
|
+
|
|
250
|
+
// check if balances have not changed yet
|
|
251
|
+
expect(
|
|
252
|
+
(
|
|
253
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
254
|
+
senderPog.gameServerId,
|
|
255
|
+
senderPog.playerId
|
|
256
|
+
)
|
|
257
|
+
).data.data.currency
|
|
258
|
+
).to.be.eq(transferAmount);
|
|
259
|
+
expect(
|
|
260
|
+
(
|
|
261
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
262
|
+
receiverPog.gameServerId,
|
|
263
|
+
receiverPog.playerId
|
|
264
|
+
)
|
|
265
|
+
).data.data.currency
|
|
266
|
+
).to.be.eq(0);
|
|
267
|
+
expect(messages.length).to.be.eq(1);
|
|
268
|
+
expect(messages[0]).to.be.eq(
|
|
269
|
+
`You are about to send ${transferAmount} test coin to ${receiver.name}. (Please confirm by typing ${prefix}confirmtransfer)`
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
// =================================================
|
|
273
|
+
// transfer confirmed
|
|
274
|
+
// =================================================
|
|
275
|
+
events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
276
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
277
|
+
msg: `${prefix}confirmtransfer`,
|
|
278
|
+
playerId: sender.id,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
messages = (await events).sort(chatMessageSorter).map((e) => e.data.msg as string);
|
|
282
|
+
expect((await events).length).to.be.eq(2);
|
|
283
|
+
expect(
|
|
284
|
+
(
|
|
285
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
286
|
+
senderPog.gameServerId,
|
|
287
|
+
senderPog.playerId
|
|
288
|
+
)
|
|
289
|
+
).data.data.currency
|
|
290
|
+
).to.be.eq(0);
|
|
291
|
+
expect(
|
|
292
|
+
(
|
|
293
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
294
|
+
receiverPog.gameServerId,
|
|
295
|
+
receiverPog.playerId
|
|
296
|
+
)
|
|
297
|
+
).data.data.currency
|
|
298
|
+
).to.be.eq(transferAmount);
|
|
299
|
+
|
|
300
|
+
expect(messages[0]).to.be.eq(`You received ${transferAmount} test coin from ${sender.name}`);
|
|
301
|
+
expect(messages[1]).to.be.eq(`You successfully transferred ${transferAmount} test coin to ${receiver.name}`);
|
|
302
|
+
},
|
|
303
|
+
}),
|
|
304
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
305
|
+
group,
|
|
306
|
+
snapshot: false,
|
|
307
|
+
setup: customSetup,
|
|
308
|
+
name: 'Should return no pending transfers when there are none',
|
|
309
|
+
test: async function () {
|
|
310
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
311
|
+
this.setupData.gameserver.id,
|
|
312
|
+
this.setupData.economyUtilsModule.id,
|
|
313
|
+
{
|
|
314
|
+
userConfig: JSON.stringify({
|
|
315
|
+
pendingAmount: 100,
|
|
316
|
+
}),
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
320
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
321
|
+
msg: '/confirmtransfer',
|
|
322
|
+
playerId: this.setupData.players[0].id,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const messages = (await events).sort(chatMessageSorter).map((e) => e.data.msg as string);
|
|
326
|
+
expect(messages[0]).to.be.eq('You have no pending transfer.');
|
|
327
|
+
},
|
|
328
|
+
}),
|
|
329
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
330
|
+
group,
|
|
331
|
+
snapshot: false,
|
|
332
|
+
setup: customSetup,
|
|
333
|
+
name: 'Can grant currency to a player',
|
|
334
|
+
test: async function () {
|
|
335
|
+
const granter = this.setupData.players[0];
|
|
336
|
+
const receiver = this.setupData.players[1];
|
|
337
|
+
const grantAmount = 500;
|
|
338
|
+
|
|
339
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
340
|
+
this.setupData.gameserver.id,
|
|
341
|
+
this.setupData.economyUtilsModule.id
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
// Change permissions of role to only have manageCurrency permission
|
|
345
|
+
const manageCurrencyPermission = await this.client.permissionCodesToInputs(['ECONOMY_UTILS_MANAGE_CURRENCY']);
|
|
346
|
+
await this.client.role.roleControllerUpdate(this.setupData.role.id, {
|
|
347
|
+
permissions: [
|
|
348
|
+
{
|
|
349
|
+
permissionId: manageCurrencyPermission[0].permissionId,
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const receiverPog = receiver.playerOnGameServers?.find(
|
|
355
|
+
(pog) => pog.gameServerId === this.setupData.gameserver.id
|
|
356
|
+
);
|
|
357
|
+
if (!receiverPog) throw new Error('Receiver playerOnGameServer does not exist');
|
|
358
|
+
expect(receiverPog.currency).to.be.eq(0);
|
|
359
|
+
|
|
360
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
361
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
362
|
+
msg: `/grantcurrency ${receiver.name} ${grantAmount}`,
|
|
363
|
+
playerId: granter.id,
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const messages = (await events).sort(chatMessageSorter).map((e) => e.data.msg as string);
|
|
367
|
+
expect(
|
|
368
|
+
(
|
|
369
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
370
|
+
receiverPog.gameServerId,
|
|
371
|
+
receiverPog.playerId
|
|
372
|
+
)
|
|
373
|
+
).data.data.currency
|
|
374
|
+
).to.be.eq(grantAmount);
|
|
375
|
+
expect(messages[0]).to.be.eq(`Granted ${grantAmount} test coin by ${granter.name}`);
|
|
376
|
+
expect(messages[1]).to.be.eq(`You successfully granted ${grantAmount} test coin to ${receiver.name}`);
|
|
377
|
+
},
|
|
378
|
+
}),
|
|
379
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
380
|
+
group,
|
|
381
|
+
snapshot: false,
|
|
382
|
+
setup: customSetup,
|
|
383
|
+
name: 'Can revoke currency from a player',
|
|
384
|
+
test: async function () {
|
|
385
|
+
const revoker = this.setupData.players[0];
|
|
386
|
+
const receiver = this.setupData.players[1];
|
|
387
|
+
const revokeAmount = 500;
|
|
388
|
+
|
|
389
|
+
// make sure receiver has enough currency
|
|
390
|
+
const receiverPog = receiver.playerOnGameServers?.find(
|
|
391
|
+
(pog) => pog.gameServerId === this.setupData.gameserver.id
|
|
392
|
+
);
|
|
393
|
+
if (!receiverPog) throw new Error('Receiver playerOnGameServer does not exist');
|
|
394
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerSetCurrency(
|
|
395
|
+
receiverPog.gameServerId,
|
|
396
|
+
receiverPog.playerId,
|
|
397
|
+
{
|
|
398
|
+
currency: revokeAmount,
|
|
399
|
+
}
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
403
|
+
this.setupData.gameserver.id,
|
|
404
|
+
this.setupData.economyUtilsModule.id
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
// Change permissions of role to only have manageCurrency permission
|
|
408
|
+
const manageCurrencyPermission = await this.client.permissionCodesToInputs(['ECONOMY_UTILS_MANAGE_CURRENCY']);
|
|
409
|
+
await this.client.role.roleControllerUpdate(this.setupData.role.id, {
|
|
410
|
+
permissions: [
|
|
411
|
+
{
|
|
412
|
+
permissionId: manageCurrencyPermission[0].permissionId,
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// currency before revoke
|
|
418
|
+
expect(
|
|
419
|
+
receiver.playerOnGameServers?.find((pog) => pog.gameServerId === this.setupData.gameserver.id)?.currency
|
|
420
|
+
).to.be.eq(0);
|
|
421
|
+
|
|
422
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
423
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
424
|
+
msg: `/revokecurrency ${receiver.name} ${revokeAmount}`,
|
|
425
|
+
playerId: revoker.id,
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
const messages = (await events).sort(chatMessageSorter).map((e) => e.data.msg as string);
|
|
429
|
+
expect(
|
|
430
|
+
(
|
|
431
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
432
|
+
receiverPog.gameServerId,
|
|
433
|
+
receiverPog.playerId
|
|
434
|
+
)
|
|
435
|
+
).data.data.currency
|
|
436
|
+
).to.be.eq(0);
|
|
437
|
+
expect(messages[0]).to.be.eq(`${revokeAmount} test coin were revoked by ${revoker.name}`);
|
|
438
|
+
expect(messages[1]).to.be.eq(`You successfully revoked ${revokeAmount} test coin of ${receiver.name}'s balance`);
|
|
439
|
+
},
|
|
440
|
+
}),
|
|
441
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
442
|
+
group,
|
|
443
|
+
snapshot: false,
|
|
444
|
+
setup: customSetup,
|
|
445
|
+
name: 'Cannot use commands that require manageCurrency permission without it',
|
|
446
|
+
test: async function () {
|
|
447
|
+
const sender = this.setupData.players[0];
|
|
448
|
+
const receiver = this.setupData.players[1];
|
|
449
|
+
const amount = 500;
|
|
450
|
+
|
|
451
|
+
// by default all users get root permission => remove all permissions
|
|
452
|
+
await this.client.role.roleControllerUpdate(this.setupData.role.id, {
|
|
453
|
+
permissions: [],
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
457
|
+
this.setupData.gameserver.id,
|
|
458
|
+
this.setupData.economyUtilsModule.id
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
// currency before revoke
|
|
462
|
+
expect(
|
|
463
|
+
receiver.playerOnGameServers?.find((pog) => pog.gameServerId === this.setupData.gameserver.id)?.currency
|
|
464
|
+
).to.be.eq(0);
|
|
465
|
+
|
|
466
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
467
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
468
|
+
msg: `/grantcurrency ${receiver.name} ${amount}`,
|
|
469
|
+
playerId: sender.id,
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
473
|
+
msg: `/revokecurrency ${receiver.name} ${amount}`,
|
|
474
|
+
playerId: sender.id,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
const messages = (await events).sort(chatMessageSorter).map((e) => e.data.msg as string);
|
|
478
|
+
expect(messages[0]).to.be.eq('You do not have permission to use grant currency command.');
|
|
479
|
+
expect(messages[1]).to.be.eq('You do not have permission to use revoke currency command.');
|
|
480
|
+
},
|
|
481
|
+
}),
|
|
482
|
+
];
|
|
483
|
+
|
|
484
|
+
describe(group, function () {
|
|
485
|
+
tests.forEach((test) => {
|
|
486
|
+
test.run();
|
|
487
|
+
});
|
|
488
|
+
});
|