@takaro/modules 0.0.13 → 0.0.14
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/dist/modules/economyUtils/commands/shop.js +6 -6
- package/dist/modules/economyUtils/commands/shop.js.map +1 -1
- package/dist/modules/economyUtils/cronJobs/zombieKillReward.d.ts +1 -0
- package/dist/modules/economyUtils/cronJobs/zombieKillReward.js +66 -0
- package/dist/modules/economyUtils/cronJobs/zombieKillReward.js.map +1 -0
- package/dist/modules/economyUtils/index.js +21 -2
- package/dist/modules/economyUtils/index.js.map +1 -1
- package/dist/modules/gimme/commands/gimme.js +1 -1
- package/dist/modules/gimme/commands/gimme.js.map +1 -1
- package/dist/modules.json +17 -5
- package/package.json +1 -1
- package/src/__tests__/economy/zombieKillReward.integration.test.ts +296 -0
- package/src/modules/economyUtils/commands/shop.js +6 -6
- package/src/modules/economyUtils/cronJobs/zombieKillReward.js +82 -0
- package/src/modules/economyUtils/index.ts +23 -2
- package/src/modules/gimme/commands/gimme.js +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { takaro, data, TakaroUserError } from '@takaro/helpers';
|
|
2
2
|
async function main() {
|
|
3
|
-
const { arguments: args, player, gameServerId
|
|
3
|
+
const { arguments: args, player, gameServerId } = data;
|
|
4
4
|
const { page, item, action } = args;
|
|
5
5
|
const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value;
|
|
6
6
|
// If command is called without any arguments
|
|
@@ -29,12 +29,14 @@ async function main() {
|
|
|
29
29
|
}
|
|
30
30
|
const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', data.gameServerId)).data.data;
|
|
31
31
|
if (!item) {
|
|
32
|
-
// List the shop items
|
|
32
|
+
// List the shop items with index
|
|
33
|
+
let index = 1;
|
|
33
34
|
for (const listing of shopItems.data.data) {
|
|
34
35
|
const items = listing.items.slice(0, 3).map((item) => {
|
|
35
36
|
return `${item.amount}x ${item.item.name}`;
|
|
36
37
|
});
|
|
37
|
-
await player.pm(
|
|
38
|
+
await player.pm(`${index} - ${listing.name} - ${listing.price} ${currencyName.value}. ${items.join(', ')}`);
|
|
39
|
+
index++;
|
|
38
40
|
}
|
|
39
41
|
return;
|
|
40
42
|
}
|
|
@@ -52,12 +54,10 @@ async function main() {
|
|
|
52
54
|
return;
|
|
53
55
|
}
|
|
54
56
|
if (action === 'buy') {
|
|
55
|
-
if (!user)
|
|
56
|
-
throw new TakaroUserError('You must link your account to Takaro to use this command.');
|
|
57
57
|
const orderRes = await takaro.shopOrder.shopOrderControllerCreate({
|
|
58
58
|
amount: 1,
|
|
59
59
|
listingId: selectedItem.id,
|
|
60
|
-
|
|
60
|
+
playerId: player.id,
|
|
61
61
|
});
|
|
62
62
|
await player.pm(`You have purchased ${selectedItem.name} for ${selectedItem.price} ${currencyName.value}.`);
|
|
63
63
|
await takaro.shopOrder.shopOrderControllerClaim(orderRes.data.data.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shop.js","sourceRoot":"","sources":["../../../../src/modules/economyUtils/commands/shop.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"shop.js","sourceRoot":"","sources":["../../../../src/modules/economyUtils/commands/shop.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IACvD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACpC,MAAM,MAAM,GA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AAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/D,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CACnG,KAAK,EACL,GAAG,CACJ,CAAC;YAEF,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,WAAW,EAAE,CAAC,CAAC;QACrF,CAAC,CAAC,CACH,CAAC;QACF,OAAO;IACT,CAAC;IAED,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,yBAAyB,CAAC;YAChE,MAAM,EAAE,CAAC;YACT,SAAS,EAAE,YAAY,CAAC,EAAE;YAC1B,QAAQ,EAAE,MAAM,CAAC,EAAE;SACpB,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,EAAE,CAAC,sBAAsB,YAAY,CAAC,IAAI,QAAQ,YAAY,CAAC,KAAK,IAAI,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC;QAC5G,MAAM,MAAM,CAAC,SAAS,CAAC,wBAAwB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvE,OAAO;IACT,CAAC;IAED,MAAM,IAAI,eAAe,CAAC,0CAA0C,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { data, takaro, checkPermission } from '@takaro/helpers';
|
|
2
|
+
const VARIABLE_KEY = 'lastZombieKillReward';
|
|
3
|
+
async function main() {
|
|
4
|
+
const { gameServerId, module: mod } = data;
|
|
5
|
+
const lastRunRes = (await takaro.variable.variableControllerSearch({
|
|
6
|
+
filters: {
|
|
7
|
+
key: [VARIABLE_KEY],
|
|
8
|
+
gameServerId: [gameServerId],
|
|
9
|
+
moduleId: [mod.moduleId],
|
|
10
|
+
},
|
|
11
|
+
})).data.data;
|
|
12
|
+
// We last ran the rewards script at this time
|
|
13
|
+
// If this is the first time we run it, just get the last 5 minutes
|
|
14
|
+
const lastRun = lastRunRes.length ? new Date(JSON.parse(lastRunRes[0].value)) : new Date(Date.now() - 5 * 60 * 1000);
|
|
15
|
+
// Fetch all the kill events since the last time we gave out rewards
|
|
16
|
+
const killEvents = (await takaro.event.eventControllerSearch({
|
|
17
|
+
filters: { eventName: ['entity-killed'], gameserverId: [gameServerId] },
|
|
18
|
+
greaterThan: { createdAt: lastRun.toISOString() },
|
|
19
|
+
limit: 1000,
|
|
20
|
+
})).data.data;
|
|
21
|
+
console.log(`Found ${killEvents.length} kill events since ${lastRun.toISOString()}`);
|
|
22
|
+
// Group the events by player
|
|
23
|
+
const playerKills = {};
|
|
24
|
+
for (const killEvent of killEvents) {
|
|
25
|
+
if (!playerKills[killEvent.playerId]) {
|
|
26
|
+
playerKills[killEvent.playerId] = [];
|
|
27
|
+
}
|
|
28
|
+
playerKills[killEvent.playerId].push(killEvent);
|
|
29
|
+
}
|
|
30
|
+
// Give each player their reward
|
|
31
|
+
// We use Promise.allSettled to run this concurrently
|
|
32
|
+
const results = await Promise.allSettled(Object.entries(playerKills).map(async ([playerId, kills]) => {
|
|
33
|
+
const pog = (await takaro.playerOnGameserver.playerOnGameServerControllerGetOne(gameServerId, playerId)).data
|
|
34
|
+
.data;
|
|
35
|
+
const hasPermission = checkPermission(pog, 'ZOMBIE_KILL_REWARD_OVERRIDE');
|
|
36
|
+
const defaultReward = mod.userConfig.zombieKillReward;
|
|
37
|
+
const reward = hasPermission && hasPermission.count != null ? hasPermission.count : defaultReward;
|
|
38
|
+
const totalReward = reward * kills.length;
|
|
39
|
+
return takaro.playerOnGameserver.playerOnGameServerControllerAddCurrency(gameServerId, playerId, {
|
|
40
|
+
currency: totalReward,
|
|
41
|
+
});
|
|
42
|
+
}));
|
|
43
|
+
// Log any errors
|
|
44
|
+
for (const result of results) {
|
|
45
|
+
if (result.status === 'rejected') {
|
|
46
|
+
console.error(result.reason);
|
|
47
|
+
throw new Error(`Failed to give rewards: ${result.reason}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Update the last run time
|
|
51
|
+
if (lastRunRes.length) {
|
|
52
|
+
await takaro.variable.variableControllerUpdate(lastRunRes[0].id, {
|
|
53
|
+
value: JSON.stringify(new Date()),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
await takaro.variable.variableControllerCreate({
|
|
58
|
+
key: VARIABLE_KEY,
|
|
59
|
+
value: JSON.stringify(new Date()),
|
|
60
|
+
moduleId: mod.moduleId,
|
|
61
|
+
gameServerId,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
await main();
|
|
66
|
+
//# sourceMappingURL=zombieKillReward.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zombieKillReward.js","sourceRoot":"","sources":["../../../../src/modules/economyUtils/cronJobs/zombieKillReward.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAE5C,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE3C,MAAM,UAAU,GAAG,CACjB,MAAM,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAAC;QAC7C,OAAO,EAAE;YACP,GAAG,EAAE,CAAC,YAAY,CAAC;YACnB,YAAY,EAAE,CAAC,YAAY,CAAC;YAC5B,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ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MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAAC;YAC7C,GAAG,EAAE,YAAY;YACjB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC;YACjC,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,YAAY;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,MAAM,IAAI,EAAE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuiltinModule, ICommand, IPermission } from '../../BuiltinModule.js';
|
|
1
|
+
import { BuiltinModule, ICommand, ICronJob, IPermission } from '../../BuiltinModule.js';
|
|
2
2
|
export class EconomyUtils extends BuiltinModule {
|
|
3
3
|
constructor() {
|
|
4
4
|
super('economyUtils', 'A set of commands to allow players to manage their currency.', JSON.stringify({
|
|
@@ -11,6 +11,12 @@ export class EconomyUtils extends BuiltinModule {
|
|
|
11
11
|
description: 'When a player transfers money, they must confirm the transfer when the amount is equal or above this value. Set to 0 to disable.',
|
|
12
12
|
default: 0,
|
|
13
13
|
},
|
|
14
|
+
zombieKillReward: {
|
|
15
|
+
title: 'Zombie kill reward',
|
|
16
|
+
type: 'number',
|
|
17
|
+
description: 'The default amount of currency a player receives for killing a zombie. This can be overridden by roles.',
|
|
18
|
+
default: 1,
|
|
19
|
+
},
|
|
14
20
|
},
|
|
15
21
|
required: [],
|
|
16
22
|
additionalProperties: false,
|
|
@@ -22,6 +28,19 @@ export class EconomyUtils extends BuiltinModule {
|
|
|
22
28
|
description: 'Allows players to manage currency of other players. This includes granting and revoking currency.',
|
|
23
29
|
canHaveCount: false,
|
|
24
30
|
}),
|
|
31
|
+
new IPermission({
|
|
32
|
+
permission: 'ZOMBIE_KILL_REWARD_OVERRIDE',
|
|
33
|
+
friendlyName: 'Zombie kill reward override',
|
|
34
|
+
description: 'Allows a role to override the amount of currency a player receives for killing a entity.',
|
|
35
|
+
canHaveCount: true,
|
|
36
|
+
}),
|
|
37
|
+
];
|
|
38
|
+
this.cronJobs = [
|
|
39
|
+
new ICronJob({
|
|
40
|
+
function: this.loadFn('cronJobs', 'zombieKillReward'),
|
|
41
|
+
name: 'zombieKillReward',
|
|
42
|
+
temporalValue: '*/5 * * * *',
|
|
43
|
+
}),
|
|
25
44
|
];
|
|
26
45
|
this.commands = [
|
|
27
46
|
new ICommand({
|
|
@@ -64,7 +83,7 @@ export class EconomyUtils extends BuiltinModule {
|
|
|
64
83
|
function: this.loadFn('commands', 'revokeCurrency'),
|
|
65
84
|
name: 'revokeCurrency',
|
|
66
85
|
trigger: 'revokecurrency',
|
|
67
|
-
helpText: '
|
|
86
|
+
helpText: 'Revokes money from a player. The money disappears.',
|
|
68
87
|
arguments: [
|
|
69
88
|
{
|
|
70
89
|
name: 'receiver',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/economyUtils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/economyUtils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAExF,MAAM,OAAO,YAAa,SAAQ,aAA2B;IAC3D;QACE,KAAK,CACH,cAAc,EACd,8DAA8D,EAC9D,IAAI,CAAC,SAAS,CAAC;YACb,OAAO,EAAE,yCAAyC;YAClD,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,aAAa,EAAE;oBACb,KAAK,EAAE,gBAAgB;oBACvB,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,kIAAkI;oBACpI,OAAO,EAAE,CAAC;iBACX;gBACD,gBAAgB,EAAE;oBAChB,KAAK,EAAE,oBAAoB;oBAC3B,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,yGAAyG;o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;wBACtF,QAAQ,EAAE,CAAC;wBACX,YAAY,EAAE,MAAM;qBACrB;iBACF;aACF,CAAC;SACH,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gimme.js","sourceRoot":"","sources":["../../../../src/modules/gimme/commands/gimme.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE,KAAK,UAAU,IAAI;IACjB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC;IAEjD,IAAI,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,eAAe,CACvB,iGAAiG,CAClG,CAAC;IACJ,CAAC;IAED,oFAAoF;IACpF,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACjF,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,CAAC;IAEzD,IAAI,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,MAAM,CAAC,UAAU,CAAC,4BAA4B,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;YACtF,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"gimme.js","sourceRoot":"","sources":["../../../../src/modules/gimme/commands/gimme.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,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Error } from '@takaro/helpers';\nasync function main() {\n const items = data.module.userConfig.items;\n const commands = data.module.userConfig.commands;\n if (items.length + commands.length === 0) {\n throw new TakaroUserError('No items or commands configured, please ask your server administrator to configure this module.');\n }\n // pick a random item between 0 and the length of both the items and commands arrays\n const randomIndex = Math.floor(Math.random() * (items.length + commands.length));\n const randomOption = items.concat(commands)[randomIndex];\n if (randomIndex < items.length) {\n await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {\n name: randomOption,\n amount: 1,\n quality: 0,\n });\n await data.player.pm(`You received ${randomOption}!`);\n }\n else {\n await takaro.gameserver.gameServerControllerExecuteCommand(data.gameServerId, { command: randomOption });\n }\n}\nawait main();\n//# sourceMappingURL=gimme.js.map",
|
|
275
|
+
"function": "import { takaro, data, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n const items = data.module.userConfig.items;\n const commands = data.module.userConfig.commands;\n if (items.length + commands.length === 0) {\n throw new TakaroUserError('No items or commands configured, please ask your server administrator to configure this module.');\n }\n // pick a random item between 0 and the length of both the items and commands arrays\n const randomIndex = Math.floor(Math.random() * (items.length + commands.length));\n const randomOption = items.concat(commands)[randomIndex];\n if (randomIndex < items.length) {\n await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {\n name: randomOption,\n amount: 1,\n quality: '0',\n });\n await data.player.pm(`You received ${randomOption}!`);\n }\n else {\n await takaro.gameserver.gameServerControllerExecuteCommand(data.gameServerId, { command: randomOption });\n }\n}\nawait main();\n//# sourceMappingURL=gimme.js.map",
|
|
276
276
|
"name": "gimme",
|
|
277
277
|
"trigger": "gimme",
|
|
278
278
|
"helpText": "Randomly selects item from a list of items and entities.",
|
|
@@ -347,7 +347,7 @@
|
|
|
347
347
|
"function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n const { pog: revoker, arguments: args, gameServerId } = data;\n // args.receiver has an argument type of \"player\". Arguments of this type are automatically resolved to the player's id.\n // If the player doesn't exist or multiple players with the same name where found, it will have thrown an error before this command is executed.\n const receiver = args.receiver;\n if (!checkPermission(revoker, 'ECONOMY_UTILS_MANAGE_CURRENCY')) {\n throw new TakaroUserError('You do not have permission to use revoke currency command.');\n }\n const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', gameServerId)).data.data.value;\n const revokerName = (await takaro.player.playerControllerGetOne(revoker.playerId)).data.data.name;\n const receiverName = (await takaro.player.playerControllerGetOne(receiver.playerId)).data.data.name;\n await takaro.playerOnGameserver.playerOnGameServerControllerDeductCurrency(receiver.gameServerId, receiver.playerId, {\n currency: args.amount,\n });\n const messageToReceiver = takaro.gameserver.gameServerControllerSendMessage(gameServerId, {\n message: `${args.amount} ${currencyName} were revoked by ${revokerName}`,\n opts: {\n recipient: {\n gameId: receiver.gameId,\n },\n },\n });\n await Promise.all([\n revoker.pm(`You successfully revoked ${args.amount} ${currencyName} of ${receiverName}'s balance`),\n messageToReceiver,\n ]);\n return;\n}\nawait main();\n//# sourceMappingURL=revokeCurrency.js.map",
|
|
348
348
|
"name": "revokeCurrency",
|
|
349
349
|
"trigger": "revokecurrency",
|
|
350
|
-
"helpText": "
|
|
350
|
+
"helpText": "Revokes money from a player. The money disappears.",
|
|
351
351
|
"arguments": [
|
|
352
352
|
{
|
|
353
353
|
"name": "receiver",
|
|
@@ -410,7 +410,7 @@
|
|
|
410
410
|
]
|
|
411
411
|
},
|
|
412
412
|
{
|
|
413
|
-
"function": "import { takaro, data, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n const { arguments: args, player, gameServerId
|
|
413
|
+
"function": "import { takaro, data, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n const { arguments: args, player, gameServerId } = data;\n const { page, item, action } = args;\n const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value;\n // If command is called without any arguments\n const messageWithoutPrefix = data.chatMessage.msg.slice(prefix.length).trim();\n if (!messageWithoutPrefix.includes(' ')) {\n await player.pm('This command allows you to browse the shop and view available items.');\n await player.pm(`Usage: ${prefix}shop [page] [item] [action]`);\n await player.pm(`${prefix}shop 2 - View the second page of shop items`);\n await player.pm(`${prefix}shop 1 3 - View details about the third item on the first page`);\n await player.pm(`${prefix}shop 1 3 buy - Purchase the third item on the first page`);\n return;\n }\n const shopItems = await takaro.shopListing.shopListingControllerSearch({\n limit: 5,\n page: page - 1,\n sortBy: 'name',\n sortDirection: 'asc',\n filters: {\n gameServerId: [gameServerId],\n draft: false,\n },\n });\n if (shopItems.data.data.length === 0) {\n await player.pm('No items found.');\n return;\n }\n const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', data.gameServerId)).data.data;\n if (!item) {\n // List the shop items with index\n let index = 1;\n for (const listing of shopItems.data.data) {\n const items = listing.items.slice(0, 3).map((item) => {\n return `${item.amount}x ${item.item.name}`;\n });\n await player.pm(`${index} - ${listing.name} - ${listing.price} ${currencyName.value}. ${items.join(', ')}`);\n index++;\n }\n return;\n }\n const selectedItem = shopItems.data.data[item - 1];\n if (!selectedItem)\n throw new TakaroUserError(`Item not found. Please select an item from the list, valid options are 1-${shopItems.data.data.length}.`);\n if (action === 'none') {\n // Display more info about the item\n await player.pm(`Listing ${selectedItem.name} - ${selectedItem.price} ${currencyName.value}`);\n await Promise.all(selectedItem.items.map((item) => {\n const quality = item.quality ? `Quality: ${item.quality}` : '';\n const description = (item.item.description ? `Description: ${item.item.description}` : '').replaceAll('\\\\n', ' ');\n return player.pm(`- ${item.amount}x ${item.item.name}. ${quality} ${description}`);\n }));\n return;\n }\n if (action === 'buy') {\n const orderRes = await takaro.shopOrder.shopOrderControllerCreate({\n amount: 1,\n listingId: selectedItem.id,\n playerId: player.id,\n });\n await player.pm(`You have purchased ${selectedItem.name} for ${selectedItem.price} ${currencyName.value}.`);\n await takaro.shopOrder.shopOrderControllerClaim(orderRes.data.data.id);\n return;\n }\n throw new TakaroUserError('Invalid action. Valid actions are \"buy\".');\n}\nawait main();\n//# sourceMappingURL=shop.js.map",
|
|
414
414
|
"name": "shop",
|
|
415
415
|
"trigger": "shop",
|
|
416
416
|
"helpText": "Browse the shop and view available items.",
|
|
@@ -440,7 +440,13 @@
|
|
|
440
440
|
}
|
|
441
441
|
],
|
|
442
442
|
"hooks": [],
|
|
443
|
-
"cronJobs": [
|
|
443
|
+
"cronJobs": [
|
|
444
|
+
{
|
|
445
|
+
"function": "import { data, takaro, checkPermission } from '@takaro/helpers';\nconst VARIABLE_KEY = 'lastZombieKillReward';\nasync function main() {\n const { gameServerId, module: mod } = data;\n const lastRunRes = (await takaro.variable.variableControllerSearch({\n filters: {\n key: [VARIABLE_KEY],\n gameServerId: [gameServerId],\n moduleId: [mod.moduleId],\n },\n })).data.data;\n // We last ran the rewards script at this time\n // If this is the first time we run it, just get the last 5 minutes\n const lastRun = lastRunRes.length ? new Date(JSON.parse(lastRunRes[0].value)) : new Date(Date.now() - 5 * 60 * 1000);\n // Fetch all the kill events since the last time we gave out rewards\n const killEvents = (await takaro.event.eventControllerSearch({\n filters: { eventName: ['entity-killed'], gameserverId: [gameServerId] },\n greaterThan: { createdAt: lastRun.toISOString() },\n limit: 1000,\n })).data.data;\n console.log(`Found ${killEvents.length} kill events since ${lastRun.toISOString()}`);\n // Group the events by player\n const playerKills = {};\n for (const killEvent of killEvents) {\n if (!playerKills[killEvent.playerId]) {\n playerKills[killEvent.playerId] = [];\n }\n playerKills[killEvent.playerId].push(killEvent);\n }\n // Give each player their reward\n // We use Promise.allSettled to run this concurrently\n const results = await Promise.allSettled(Object.entries(playerKills).map(async ([playerId, kills]) => {\n const pog = (await takaro.playerOnGameserver.playerOnGameServerControllerGetOne(gameServerId, playerId)).data\n .data;\n const hasPermission = checkPermission(pog, 'ZOMBIE_KILL_REWARD_OVERRIDE');\n const defaultReward = mod.userConfig.zombieKillReward;\n const reward = hasPermission && hasPermission.count != null ? hasPermission.count : defaultReward;\n const totalReward = reward * kills.length;\n return takaro.playerOnGameserver.playerOnGameServerControllerAddCurrency(gameServerId, playerId, {\n currency: totalReward,\n });\n }));\n // Log any errors\n for (const result of results) {\n if (result.status === 'rejected') {\n console.error(result.reason);\n throw new Error(`Failed to give rewards: ${result.reason}`);\n }\n }\n // Update the last run time\n if (lastRunRes.length) {\n await takaro.variable.variableControllerUpdate(lastRunRes[0].id, {\n value: JSON.stringify(new Date()),\n });\n }\n else {\n await takaro.variable.variableControllerCreate({\n key: VARIABLE_KEY,\n value: JSON.stringify(new Date()),\n moduleId: mod.moduleId,\n gameServerId,\n });\n }\n}\nawait main();\n//# sourceMappingURL=zombieKillReward.js.map",
|
|
446
|
+
"name": "zombieKillReward",
|
|
447
|
+
"temporalValue": "*/5 * * * *"
|
|
448
|
+
}
|
|
449
|
+
],
|
|
444
450
|
"functions": [],
|
|
445
451
|
"permissions": [
|
|
446
452
|
{
|
|
@@ -448,11 +454,17 @@
|
|
|
448
454
|
"friendlyName": "Manage currency",
|
|
449
455
|
"description": "Allows players to manage currency of other players. This includes granting and revoking currency.",
|
|
450
456
|
"canHaveCount": false
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
"permission": "ZOMBIE_KILL_REWARD_OVERRIDE",
|
|
460
|
+
"friendlyName": "Zombie kill reward override",
|
|
461
|
+
"description": "Allows a role to override the amount of currency a player receives for killing a entity.",
|
|
462
|
+
"canHaveCount": true
|
|
451
463
|
}
|
|
452
464
|
],
|
|
453
465
|
"name": "economyUtils",
|
|
454
466
|
"description": "A set of commands to allow players to manage their currency.",
|
|
455
|
-
"configSchema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"properties\":{\"pendingAmount\":{\"title\":\"Pending amount\",\"type\":\"number\",\"description\":\"When a player transfers money, they must confirm the transfer when the amount is equal or above this value. Set to 0 to disable.\",\"default\":0}},\"required\":[],\"additionalProperties\":false}",
|
|
467
|
+
"configSchema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"properties\":{\"pendingAmount\":{\"title\":\"Pending amount\",\"type\":\"number\",\"description\":\"When a player transfers money, they must confirm the transfer when the amount is equal or above this value. Set to 0 to disable.\",\"default\":0},\"zombieKillReward\":{\"title\":\"Zombie kill reward\",\"type\":\"number\",\"description\":\"The default amount of currency a player receives for killing a zombie. This can be overridden by roles.\",\"default\":1}},\"required\":[],\"additionalProperties\":false}",
|
|
456
468
|
"uiSchema": "{}"
|
|
457
469
|
},
|
|
458
470
|
{
|
package/package.json
CHANGED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { EventsAwaiter, expect, IntegrationTest, IShopSetup, shopSetup } from '@takaro/test';
|
|
2
|
+
import { HookEvents } from '../../dto/index.js';
|
|
3
|
+
import { Client, PlayerOutputDTO } from '@takaro/apiclient';
|
|
4
|
+
|
|
5
|
+
const group = 'EconomyUtils:ZombieKillReward';
|
|
6
|
+
|
|
7
|
+
async function triggerKills(client: Client, player: PlayerOutputDTO, gameServerId: string, count: number) {
|
|
8
|
+
const events = (await new EventsAwaiter().connect(client)).waitForEvents(HookEvents.ENTITY_KILLED, count);
|
|
9
|
+
|
|
10
|
+
if (!player.playerOnGameServers) throw new Error('Player has no pogs');
|
|
11
|
+
const pog = player.playerOnGameServers.find((pog) => pog.gameServerId === gameServerId);
|
|
12
|
+
if (!pog) throw new Error('Player not found on game server');
|
|
13
|
+
|
|
14
|
+
await Promise.all(
|
|
15
|
+
Array.from({ length: count }, () => {
|
|
16
|
+
return client.gameserver.gameServerControllerExecuteCommand(gameServerId, {
|
|
17
|
+
command: `triggerKill ${pog.gameId}`,
|
|
18
|
+
});
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
await events;
|
|
23
|
+
return events;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const tests = [
|
|
27
|
+
new IntegrationTest<IShopSetup>({
|
|
28
|
+
group,
|
|
29
|
+
snapshot: false,
|
|
30
|
+
setup: shopSetup,
|
|
31
|
+
name: 'Simple happy path, killing one zombie gives one currency',
|
|
32
|
+
test: async function () {
|
|
33
|
+
const pogBefore = (
|
|
34
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
35
|
+
this.setupData.gameserver.id,
|
|
36
|
+
this.setupData.players[0].id,
|
|
37
|
+
)
|
|
38
|
+
).data.data;
|
|
39
|
+
|
|
40
|
+
(
|
|
41
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
42
|
+
this.setupData.gameserver.id,
|
|
43
|
+
this.setupData.economyUtilsModule.id,
|
|
44
|
+
)
|
|
45
|
+
).data.data;
|
|
46
|
+
const zombieKillCronjob = this.setupData.economyUtilsModule.cronJobs.find(
|
|
47
|
+
(cronjob) => cronjob.name === 'zombieKillReward',
|
|
48
|
+
);
|
|
49
|
+
if (!zombieKillCronjob) throw new Error('Cronjob not found');
|
|
50
|
+
await triggerKills(this.client, this.setupData.players[0], this.setupData.gameserver.id, 1);
|
|
51
|
+
await this.client.cronjob.cronJobControllerTrigger({
|
|
52
|
+
gameServerId: this.setupData.gameserver.id,
|
|
53
|
+
moduleId: this.setupData.economyUtilsModule.id,
|
|
54
|
+
cronjobId: zombieKillCronjob.id,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.CRONJOB_EXECUTED, 1);
|
|
58
|
+
await events;
|
|
59
|
+
|
|
60
|
+
const pogAfter = (
|
|
61
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
62
|
+
this.setupData.gameserver.id,
|
|
63
|
+
this.setupData.players[0].id,
|
|
64
|
+
)
|
|
65
|
+
).data.data;
|
|
66
|
+
expect(pogAfter.currency).to.equal(pogBefore.currency + 1);
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
/**
|
|
70
|
+
* First kill 3 zombies, then trigger the cronjob
|
|
71
|
+
* Check if the player has 3 currency
|
|
72
|
+
* Then kill 4 zombies
|
|
73
|
+
* Check if the player has 7 currency
|
|
74
|
+
*/
|
|
75
|
+
new IntegrationTest<IShopSetup>({
|
|
76
|
+
group,
|
|
77
|
+
snapshot: false,
|
|
78
|
+
setup: shopSetup,
|
|
79
|
+
name: 'Killing multiple zombies',
|
|
80
|
+
test: async function () {
|
|
81
|
+
const pogBefore = (
|
|
82
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
83
|
+
this.setupData.gameserver.id,
|
|
84
|
+
this.setupData.players[0].id,
|
|
85
|
+
)
|
|
86
|
+
).data.data;
|
|
87
|
+
|
|
88
|
+
(
|
|
89
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
90
|
+
this.setupData.gameserver.id,
|
|
91
|
+
this.setupData.economyUtilsModule.id,
|
|
92
|
+
)
|
|
93
|
+
).data.data;
|
|
94
|
+
const zombieKillCronjob = this.setupData.economyUtilsModule.cronJobs.find(
|
|
95
|
+
(cronjob) => cronjob.name === 'zombieKillReward',
|
|
96
|
+
);
|
|
97
|
+
if (!zombieKillCronjob) throw new Error('Cronjob not found');
|
|
98
|
+
await triggerKills(this.client, this.setupData.players[0], this.setupData.gameserver.id, 3);
|
|
99
|
+
await this.client.cronjob.cronJobControllerTrigger({
|
|
100
|
+
gameServerId: this.setupData.gameserver.id,
|
|
101
|
+
moduleId: this.setupData.economyUtilsModule.id,
|
|
102
|
+
cronjobId: zombieKillCronjob.id,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.CRONJOB_EXECUTED, 1);
|
|
106
|
+
await events;
|
|
107
|
+
|
|
108
|
+
let pogAfter = (
|
|
109
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
110
|
+
this.setupData.gameserver.id,
|
|
111
|
+
this.setupData.players[0].id,
|
|
112
|
+
)
|
|
113
|
+
).data.data;
|
|
114
|
+
expect(pogAfter.currency).to.equal(pogBefore.currency + 3);
|
|
115
|
+
|
|
116
|
+
await triggerKills(this.client, this.setupData.players[0], this.setupData.gameserver.id, 4);
|
|
117
|
+
await this.client.cronjob.cronJobControllerTrigger({
|
|
118
|
+
gameServerId: this.setupData.gameserver.id,
|
|
119
|
+
moduleId: this.setupData.economyUtilsModule.id,
|
|
120
|
+
cronjobId: zombieKillCronjob.id,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const events2 = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.CRONJOB_EXECUTED, 1);
|
|
124
|
+
await events2;
|
|
125
|
+
|
|
126
|
+
pogAfter = (
|
|
127
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
128
|
+
this.setupData.gameserver.id,
|
|
129
|
+
this.setupData.players[0].id,
|
|
130
|
+
)
|
|
131
|
+
).data.data;
|
|
132
|
+
expect(pogAfter.currency).to.equal(pogBefore.currency + 7);
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
new IntegrationTest<IShopSetup>({
|
|
136
|
+
group,
|
|
137
|
+
snapshot: false,
|
|
138
|
+
setup: shopSetup,
|
|
139
|
+
name: 'Different players killing zombies assigns the right amount to the right players',
|
|
140
|
+
test: async function () {
|
|
141
|
+
const pogBefore1 = (
|
|
142
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
143
|
+
this.setupData.gameserver.id,
|
|
144
|
+
this.setupData.players[0].id,
|
|
145
|
+
)
|
|
146
|
+
).data.data;
|
|
147
|
+
const pogBefore2 = (
|
|
148
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
149
|
+
this.setupData.gameserver.id,
|
|
150
|
+
this.setupData.players[1].id,
|
|
151
|
+
)
|
|
152
|
+
).data.data;
|
|
153
|
+
|
|
154
|
+
(
|
|
155
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
156
|
+
this.setupData.gameserver.id,
|
|
157
|
+
this.setupData.economyUtilsModule.id,
|
|
158
|
+
)
|
|
159
|
+
).data.data;
|
|
160
|
+
const zombieKillCronjob = this.setupData.economyUtilsModule.cronJobs.find(
|
|
161
|
+
(cronjob) => cronjob.name === 'zombieKillReward',
|
|
162
|
+
);
|
|
163
|
+
if (!zombieKillCronjob) throw new Error('Cronjob not found');
|
|
164
|
+
await triggerKills(this.client, this.setupData.players[0], this.setupData.gameserver.id, 3);
|
|
165
|
+
await triggerKills(this.client, this.setupData.players[1], this.setupData.gameserver.id, 4);
|
|
166
|
+
await this.client.cronjob.cronJobControllerTrigger({
|
|
167
|
+
gameServerId: this.setupData.gameserver.id,
|
|
168
|
+
moduleId: this.setupData.economyUtilsModule.id,
|
|
169
|
+
cronjobId: zombieKillCronjob.id,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.CRONJOB_EXECUTED, 1);
|
|
173
|
+
await events;
|
|
174
|
+
|
|
175
|
+
const pogAfter1 = (
|
|
176
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
177
|
+
this.setupData.gameserver.id,
|
|
178
|
+
this.setupData.players[0].id,
|
|
179
|
+
)
|
|
180
|
+
).data.data;
|
|
181
|
+
const pogAfter2 = (
|
|
182
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
183
|
+
this.setupData.gameserver.id,
|
|
184
|
+
this.setupData.players[1].id,
|
|
185
|
+
)
|
|
186
|
+
).data.data;
|
|
187
|
+
expect(pogAfter1.currency).to.equal(pogBefore1.currency + 3);
|
|
188
|
+
expect(pogAfter2.currency).to.equal(pogBefore2.currency + 4);
|
|
189
|
+
},
|
|
190
|
+
}),
|
|
191
|
+
new IntegrationTest<IShopSetup>({
|
|
192
|
+
group,
|
|
193
|
+
snapshot: false,
|
|
194
|
+
setup: shopSetup,
|
|
195
|
+
name: 'Can configure a custom amount of currency per kill',
|
|
196
|
+
test: async function () {
|
|
197
|
+
const pogBefore = (
|
|
198
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
199
|
+
this.setupData.gameserver.id,
|
|
200
|
+
this.setupData.players[0].id,
|
|
201
|
+
)
|
|
202
|
+
).data.data;
|
|
203
|
+
(
|
|
204
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
205
|
+
this.setupData.gameserver.id,
|
|
206
|
+
this.setupData.economyUtilsModule.id,
|
|
207
|
+
{
|
|
208
|
+
userConfig: JSON.stringify({ zombieKillReward: 5 }),
|
|
209
|
+
},
|
|
210
|
+
)
|
|
211
|
+
).data.data;
|
|
212
|
+
const zombieKillCronjob = this.setupData.economyUtilsModule.cronJobs.find(
|
|
213
|
+
(cronjob) => cronjob.name === 'zombieKillReward',
|
|
214
|
+
);
|
|
215
|
+
if (!zombieKillCronjob) throw new Error('Cronjob not found');
|
|
216
|
+
await triggerKills(this.client, this.setupData.players[0], this.setupData.gameserver.id, 1);
|
|
217
|
+
await this.client.cronjob.cronJobControllerTrigger({
|
|
218
|
+
gameServerId: this.setupData.gameserver.id,
|
|
219
|
+
moduleId: this.setupData.economyUtilsModule.id,
|
|
220
|
+
cronjobId: zombieKillCronjob.id,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.CRONJOB_EXECUTED, 1);
|
|
224
|
+
await events;
|
|
225
|
+
|
|
226
|
+
const pogAfter = (
|
|
227
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
228
|
+
this.setupData.gameserver.id,
|
|
229
|
+
this.setupData.players[0].id,
|
|
230
|
+
)
|
|
231
|
+
).data.data;
|
|
232
|
+
expect(pogAfter.currency).to.equal(pogBefore.currency + 5);
|
|
233
|
+
},
|
|
234
|
+
}),
|
|
235
|
+
new IntegrationTest<IShopSetup>({
|
|
236
|
+
group,
|
|
237
|
+
snapshot: false,
|
|
238
|
+
setup: shopSetup,
|
|
239
|
+
name: 'Can override amount earned per role',
|
|
240
|
+
test: async function () {
|
|
241
|
+
const zombieKillEarnerPermission = await this.client.permissionCodesToInputs(['ZOMBIE_KILL_REWARD_OVERRIDE']);
|
|
242
|
+
await this.client.role.roleControllerUpdate(this.setupData.role.id, {
|
|
243
|
+
permissions: [
|
|
244
|
+
{
|
|
245
|
+
permissionId: zombieKillEarnerPermission[0].permissionId,
|
|
246
|
+
count: 3,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const pogBefore = (
|
|
252
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
253
|
+
this.setupData.gameserver.id,
|
|
254
|
+
this.setupData.players[0].id,
|
|
255
|
+
)
|
|
256
|
+
).data.data;
|
|
257
|
+
(
|
|
258
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
259
|
+
this.setupData.gameserver.id,
|
|
260
|
+
this.setupData.economyUtilsModule.id,
|
|
261
|
+
{
|
|
262
|
+
userConfig: JSON.stringify({ zombieKillReward: 5 }),
|
|
263
|
+
},
|
|
264
|
+
)
|
|
265
|
+
).data.data;
|
|
266
|
+
|
|
267
|
+
const zombieKillCronjob = this.setupData.economyUtilsModule.cronJobs.find(
|
|
268
|
+
(cronjob) => cronjob.name === 'zombieKillReward',
|
|
269
|
+
);
|
|
270
|
+
if (!zombieKillCronjob) throw new Error('Cronjob not found');
|
|
271
|
+
await triggerKills(this.client, this.setupData.players[0], this.setupData.gameserver.id, 1);
|
|
272
|
+
await this.client.cronjob.cronJobControllerTrigger({
|
|
273
|
+
gameServerId: this.setupData.gameserver.id,
|
|
274
|
+
moduleId: this.setupData.economyUtilsModule.id,
|
|
275
|
+
cronjobId: zombieKillCronjob.id,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const events = (await new EventsAwaiter().connect(this.client)).waitForEvents(HookEvents.CRONJOB_EXECUTED, 1);
|
|
279
|
+
await events;
|
|
280
|
+
|
|
281
|
+
const pogAfter = (
|
|
282
|
+
await this.client.playerOnGameserver.playerOnGameServerControllerGetOne(
|
|
283
|
+
this.setupData.gameserver.id,
|
|
284
|
+
this.setupData.players[0].id,
|
|
285
|
+
)
|
|
286
|
+
).data.data;
|
|
287
|
+
expect(pogAfter.currency).to.equal(pogBefore.currency + 3);
|
|
288
|
+
},
|
|
289
|
+
}),
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
describe(group, function () {
|
|
293
|
+
tests.forEach((test) => {
|
|
294
|
+
test.run();
|
|
295
|
+
});
|
|
296
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { takaro, data, TakaroUserError } from '@takaro/helpers';
|
|
2
2
|
|
|
3
3
|
async function main() {
|
|
4
|
-
const { arguments: args, player, gameServerId
|
|
4
|
+
const { arguments: args, player, gameServerId } = data;
|
|
5
5
|
const { page, item, action } = args;
|
|
6
6
|
const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value;
|
|
7
7
|
|
|
@@ -35,12 +35,14 @@ async function main() {
|
|
|
35
35
|
const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', data.gameServerId)).data.data;
|
|
36
36
|
|
|
37
37
|
if (!item) {
|
|
38
|
-
// List the shop items
|
|
38
|
+
// List the shop items with index
|
|
39
|
+
let index = 1;
|
|
39
40
|
for (const listing of shopItems.data.data) {
|
|
40
41
|
const items = listing.items.slice(0, 3).map((item) => {
|
|
41
42
|
return `${item.amount}x ${item.item.name}`;
|
|
42
43
|
});
|
|
43
|
-
await player.pm(
|
|
44
|
+
await player.pm(`${index} - ${listing.name} - ${listing.price} ${currencyName.value}. ${items.join(', ')}`);
|
|
45
|
+
index++;
|
|
44
46
|
}
|
|
45
47
|
return;
|
|
46
48
|
}
|
|
@@ -69,12 +71,10 @@ async function main() {
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
if (action === 'buy') {
|
|
72
|
-
if (!user) throw new TakaroUserError('You must link your account to Takaro to use this command.');
|
|
73
|
-
|
|
74
74
|
const orderRes = await takaro.shopOrder.shopOrderControllerCreate({
|
|
75
75
|
amount: 1,
|
|
76
76
|
listingId: selectedItem.id,
|
|
77
|
-
|
|
77
|
+
playerId: player.id,
|
|
78
78
|
});
|
|
79
79
|
await player.pm(`You have purchased ${selectedItem.name} for ${selectedItem.price} ${currencyName.value}.`);
|
|
80
80
|
await takaro.shopOrder.shopOrderControllerClaim(orderRes.data.data.id);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { data, takaro, checkPermission } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
const VARIABLE_KEY = 'lastZombieKillReward';
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const { gameServerId, module: mod } = data;
|
|
7
|
+
|
|
8
|
+
const lastRunRes = (
|
|
9
|
+
await takaro.variable.variableControllerSearch({
|
|
10
|
+
filters: {
|
|
11
|
+
key: [VARIABLE_KEY],
|
|
12
|
+
gameServerId: [gameServerId],
|
|
13
|
+
moduleId: [mod.moduleId],
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
).data.data;
|
|
17
|
+
|
|
18
|
+
// We last ran the rewards script at this time
|
|
19
|
+
// If this is the first time we run it, just get the last 5 minutes
|
|
20
|
+
const lastRun = lastRunRes.length ? new Date(JSON.parse(lastRunRes[0].value)) : new Date(Date.now() - 5 * 60 * 1000);
|
|
21
|
+
|
|
22
|
+
// Fetch all the kill events since the last time we gave out rewards
|
|
23
|
+
const killEvents = (
|
|
24
|
+
await takaro.event.eventControllerSearch({
|
|
25
|
+
filters: { eventName: ['entity-killed'], gameserverId: [gameServerId] },
|
|
26
|
+
greaterThan: { createdAt: lastRun.toISOString() },
|
|
27
|
+
limit: 1000,
|
|
28
|
+
})
|
|
29
|
+
).data.data;
|
|
30
|
+
|
|
31
|
+
console.log(`Found ${killEvents.length} kill events since ${lastRun.toISOString()}`);
|
|
32
|
+
|
|
33
|
+
// Group the events by player
|
|
34
|
+
const playerKills = {};
|
|
35
|
+
for (const killEvent of killEvents) {
|
|
36
|
+
if (!playerKills[killEvent.playerId]) {
|
|
37
|
+
playerKills[killEvent.playerId] = [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
playerKills[killEvent.playerId].push(killEvent);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Give each player their reward
|
|
44
|
+
// We use Promise.allSettled to run this concurrently
|
|
45
|
+
const results = await Promise.allSettled(
|
|
46
|
+
Object.entries(playerKills).map(async ([playerId, kills]) => {
|
|
47
|
+
const pog = (await takaro.playerOnGameserver.playerOnGameServerControllerGetOne(gameServerId, playerId)).data
|
|
48
|
+
.data;
|
|
49
|
+
const hasPermission = checkPermission(pog, 'ZOMBIE_KILL_REWARD_OVERRIDE');
|
|
50
|
+
const defaultReward = mod.userConfig.zombieKillReward;
|
|
51
|
+
const reward = hasPermission && hasPermission.count != null ? hasPermission.count : defaultReward;
|
|
52
|
+
const totalReward = reward * kills.length;
|
|
53
|
+
return takaro.playerOnGameserver.playerOnGameServerControllerAddCurrency(gameServerId, playerId, {
|
|
54
|
+
currency: totalReward,
|
|
55
|
+
});
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// Log any errors
|
|
60
|
+
for (const result of results) {
|
|
61
|
+
if (result.status === 'rejected') {
|
|
62
|
+
console.error(result.reason);
|
|
63
|
+
throw new Error(`Failed to give rewards: ${result.reason}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Update the last run time
|
|
68
|
+
if (lastRunRes.length) {
|
|
69
|
+
await takaro.variable.variableControllerUpdate(lastRunRes[0].id, {
|
|
70
|
+
value: JSON.stringify(new Date()),
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
await takaro.variable.variableControllerCreate({
|
|
74
|
+
key: VARIABLE_KEY,
|
|
75
|
+
value: JSON.stringify(new Date()),
|
|
76
|
+
moduleId: mod.moduleId,
|
|
77
|
+
gameServerId,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await main();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuiltinModule, ICommand, IPermission } from '../../BuiltinModule.js';
|
|
1
|
+
import { BuiltinModule, ICommand, ICronJob, IPermission } from '../../BuiltinModule.js';
|
|
2
2
|
|
|
3
3
|
export class EconomyUtils extends BuiltinModule<EconomyUtils> {
|
|
4
4
|
constructor() {
|
|
@@ -16,6 +16,13 @@ export class EconomyUtils extends BuiltinModule<EconomyUtils> {
|
|
|
16
16
|
'When a player transfers money, they must confirm the transfer when the amount is equal or above this value. Set to 0 to disable.',
|
|
17
17
|
default: 0,
|
|
18
18
|
},
|
|
19
|
+
zombieKillReward: {
|
|
20
|
+
title: 'Zombie kill reward',
|
|
21
|
+
type: 'number',
|
|
22
|
+
description:
|
|
23
|
+
'The default amount of currency a player receives for killing a zombie. This can be overridden by roles.',
|
|
24
|
+
default: 1,
|
|
25
|
+
},
|
|
19
26
|
},
|
|
20
27
|
required: [],
|
|
21
28
|
additionalProperties: false,
|
|
@@ -30,6 +37,20 @@ export class EconomyUtils extends BuiltinModule<EconomyUtils> {
|
|
|
30
37
|
'Allows players to manage currency of other players. This includes granting and revoking currency.',
|
|
31
38
|
canHaveCount: false,
|
|
32
39
|
}),
|
|
40
|
+
new IPermission({
|
|
41
|
+
permission: 'ZOMBIE_KILL_REWARD_OVERRIDE',
|
|
42
|
+
friendlyName: 'Zombie kill reward override',
|
|
43
|
+
description: 'Allows a role to override the amount of currency a player receives for killing a entity.',
|
|
44
|
+
canHaveCount: true,
|
|
45
|
+
}),
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
this.cronJobs = [
|
|
49
|
+
new ICronJob({
|
|
50
|
+
function: this.loadFn('cronJobs', 'zombieKillReward'),
|
|
51
|
+
name: 'zombieKillReward',
|
|
52
|
+
temporalValue: '*/5 * * * *',
|
|
53
|
+
}),
|
|
33
54
|
];
|
|
34
55
|
|
|
35
56
|
this.commands = [
|
|
@@ -73,7 +94,7 @@ export class EconomyUtils extends BuiltinModule<EconomyUtils> {
|
|
|
73
94
|
function: this.loadFn('commands', 'revokeCurrency'),
|
|
74
95
|
name: 'revokeCurrency',
|
|
75
96
|
trigger: 'revokecurrency',
|
|
76
|
-
helpText: '
|
|
97
|
+
helpText: 'Revokes money from a player. The money disappears.',
|
|
77
98
|
arguments: [
|
|
78
99
|
{
|
|
79
100
|
name: 'receiver',
|
|
@@ -18,7 +18,7 @@ async function main() {
|
|
|
18
18
|
await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {
|
|
19
19
|
name: randomOption,
|
|
20
20
|
amount: 1,
|
|
21
|
-
quality: 0,
|
|
21
|
+
quality: '0',
|
|
22
22
|
});
|
|
23
23
|
await data.player.pm(`You received ${randomOption}!`);
|
|
24
24
|
} else {
|