Skip to content

Commit 35d6a53

Browse files
committed
Add decay slash command and update ingame decay command
1 parent cb8b553 commit 35d6a53

File tree

8 files changed

+373
-64
lines changed

8 files changed

+373
-64
lines changed

docs/commands.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Slash Command | Description
1515
[**/cctv**](commands.md#cctv) | Posts CCTV codes for a monument.
1616
[**/craft**](commands.md#craft) | Display the cost to craft an item.
1717
[**/credentials**](commands.md#credentials) | Set/Clear the FCM Credentials for the user account.
18+
[**/decay**](commands.md#decay) | Display the decay time of an item.
1819
[**/help**](commands.md#help) | Display help message.
1920
[**/item**](commands.md#item) | Get the details of an item.
2021
[**/leader**](commands.md#leader) | Give or take the leadership from/to a team member.
@@ -129,6 +130,19 @@ Subcommand | Options | Description | Required
129130
![Discord Slash Command credentials Image](images/slash_commands/credentials.png)
130131

131132

133+
## **/decay**
134+
135+
> **Display the decay time of an item.**
136+
137+
Subcommand | Options | Description | Required
138+
---------- | ------- | ----------- | --------
139+
  | `name` | The name of the item. | `False`
140+
  | `id` | The id of the item. | `False`
141+
  | `hp` | THe current HP of the item. | `False`
142+
143+
![Discord Slash Command decay Image](images/slash_commands/decay.png)
144+
145+
132146
## **/help**
133147

134148
> Display help message.
@@ -343,7 +357,7 @@ In-Game Command | Description
343357
[**connection/connections**](commands.md#connectionconnections) | Get recent connection events.
344358
[**craft**](commands.md#craft-ingame) | Display the cost to craft an item.
345359
[**death/deaths**](commands.md#deathdeaths) | Get recent death events.
346-
[**decay**](commands.md#decay) | Get time before structure decay.
360+
[**decay**](commands.md#decay-ingame) | Display the decay time of an item.
347361
[**events**](commands.md#events) | Get recent events.
348362
[**heli**](commands.md#heli) | Get information about Patrol Helicopter (Location, time since last downed, time since last on map).
349363
[**large**](commands.md#large) | Get information about Large Oil Rig (Time till crate unlocks, time since last trigger).
@@ -436,12 +450,13 @@ In-Game Command | Description
436450
![In-Game Command death Image](images/ingame_commands/death_ingame.png)
437451

438452

439-
## **decay**
453+
## **decay ingame**
440454

441-
> **Get time before structure decay.**
455+
> **Display the decay time of an item.**
442456
<br>Command: `!decay`
443-
<br>Command: `!decay stone 100`
444-
<br>Command: `!decay armored 1000`
457+
<br>Command: `!decay Sheet Metal Door`
458+
<br>Command: `!decay Tug Boat 100`
459+
<br>Command: `!decay armored wall 450`
445460
446461
![In-Game Command decay Image](images/ingame_commands/decay_ingame.png)
447462

docs/full_list_features.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- **/cctv** - Get cctv camera codes for monuments.
88
- **/craft** - Display the cost to craft an item.
99
- **/credentials** - Setup FCM-Credentials.
10+
- **/decay** - Display the decay time of an item.
1011
- **/help** - Get help message.
1112
- **/item** - Get the details of an item.
1213
- **/leader** - Transfer leadership.
@@ -31,7 +32,7 @@
3132
- **connection/connections** - Display latest team connections.
3233
- **craft** - Display the cost to craft an item.
3334
- **death/deaths** - Display latest deaths.
34-
- **decay** - Get decay time of different wall-types.
35+
- **decay** - Display the decay time of an item.
3536
- **events** - Get recent events.
3637
- **heli** - Get information regarding Patrol Helicopter.
3738
- **large** - Get information regarding Large Oil Rig.
30.4 KB
Loading

docs/images/slash_commands/decay.png

12.3 KB
Loading

src/commands/decay.js

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
Copyright (C) 2023 Alexander Emanuelsson (alexemanuelol)
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
https://github.com/alexemanuelol/rustplusplus
18+
19+
*/
20+
21+
const Builder = require('@discordjs/builders');
22+
23+
const DiscordEmbeds = require('../discordTools/discordEmbeds.js');
24+
const Timer = require('../util/timer.js');
25+
26+
module.exports = {
27+
name: 'decay',
28+
29+
getData(client, guildId) {
30+
return new Builder.SlashCommandBuilder()
31+
.setName('decay')
32+
.setDescription(client.intlGet(guildId, 'commandsDecayDesc'))
33+
.addStringOption(option => option
34+
.setName('name')
35+
.setDescription(client.intlGet(guildId, 'theNameOfTheItem'))
36+
.setRequired(false))
37+
.addStringOption(option => option
38+
.setName('id')
39+
.setDescription(client.intlGet(guildId, 'theIdOfTheItem'))
40+
.setRequired(false))
41+
.addIntegerOption(option => option
42+
.setName('hp')
43+
.setDescription(client.intlGet(guildId, 'currentItemHp'))
44+
.setRequired(false));
45+
},
46+
47+
async execute(client, interaction) {
48+
const guildId = interaction.guildId;
49+
50+
const verifyId = Math.floor(100000 + Math.random() * 900000);
51+
client.logInteraction(interaction, verifyId, 'slashCommand');
52+
53+
if (!await client.validatePermissions(interaction)) return;
54+
await interaction.deferReply({ ephemeral: true });
55+
56+
const decayItemName = interaction.options.getString('name');
57+
const decayItemId = interaction.options.getString('id');
58+
const decayItemHp = interaction.options.getInteger('hp');
59+
60+
let itemId = null;
61+
let type = 'items';
62+
63+
if (decayItemName !== null) {
64+
let foundName = null;
65+
if (!foundName) {
66+
foundName = client.rustlabs.getClosestOtherNameByName(decayItemName);
67+
if (foundName) {
68+
if (client.rustlabs.decayData['other'].hasOwnProperty(foundName)) {
69+
type = 'other';
70+
}
71+
else {
72+
foundName = null;
73+
}
74+
}
75+
}
76+
77+
if (!foundName) {
78+
foundName = client.rustlabs.getClosestBuildingBlockNameByName(decayItemName);
79+
if (foundName) {
80+
if (client.rustlabs.decayData['buildingBlocks'].hasOwnProperty(foundName)) {
81+
type = 'buildingBlocks';
82+
}
83+
else {
84+
foundName = null;
85+
}
86+
}
87+
}
88+
89+
if (!foundName) {
90+
foundName = client.items.getClosestItemIdByName(decayItemName);
91+
if (foundName) {
92+
if (!client.rustlabs.decayData['items'].hasOwnProperty(foundName)) {
93+
foundName = null;
94+
}
95+
}
96+
}
97+
98+
if (!foundName) {
99+
const str = client.intlGet(guildId, 'noItemWithNameFound', {
100+
name: decayItemName
101+
});
102+
await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str));
103+
client.log(client.intlGet(guildId, 'warningCap'), str);
104+
return;
105+
}
106+
itemId = foundName;
107+
}
108+
else if (decayItemId !== null) {
109+
if (client.items.itemExist(decayItemId)) {
110+
itemId = decayItemId;
111+
}
112+
else {
113+
const str = client.intlGet(guildId, 'noItemWithIdFound', {
114+
id: decayItemId
115+
});
116+
await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str));
117+
client.log(client.intlGet(guildId, 'warningCap'), str);
118+
return;
119+
}
120+
}
121+
else if (decayItemName === null && decayItemId === null) {
122+
const str = client.intlGet(guildId, 'noNameIdGiven');
123+
await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str));
124+
client.log(client.intlGet(guildId, 'warningCap'), str);
125+
return;
126+
}
127+
128+
let itemName = null;
129+
let decayDetails = null;
130+
if (type === 'items') {
131+
itemName = client.items.getName(itemId);
132+
decayDetails = client.rustlabs.getDecayDetailsById(itemId);
133+
}
134+
else {
135+
itemName = itemId;
136+
decayDetails = client.rustlabs.getDecayDetailsByName(itemId);
137+
}
138+
139+
if (decayDetails === null) {
140+
const str = client.intlGet(guildId, 'couldNotFindDecayDetails', {
141+
name: itemName
142+
});
143+
await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str));
144+
client.log(client.intlGet(guildId, 'warningCap'), str);
145+
return;
146+
}
147+
148+
const details = decayDetails[3];
149+
150+
const hp = decayItemHp === null ? details.hp : decayItemHp;
151+
if (hp > details.hp) {
152+
const str = client.intlGet(guildId, 'hpExceedMax', {
153+
hp: hp,
154+
max: details.hp
155+
});
156+
await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str));
157+
client.log(client.intlGet(guildId, 'warningCap'), str);
158+
return;
159+
}
160+
161+
const decayMultiplier = hp / details.hp;
162+
163+
let decayString = `${itemName} (${hp}/${details.hp}) `;
164+
const decayStrings = [];
165+
if (details.decayString !== null) {
166+
let str = `${client.intlGet(guildId, 'decay')}: `;
167+
if (hp === details.hp) {
168+
decayStrings.push(`${str}${details.decayString}`);
169+
}
170+
else {
171+
const time = Timer.secondsToFullScale(Math.floor(details.decay * decayMultiplier));
172+
decayStrings.push(`${str}${time}`);
173+
}
174+
}
175+
176+
if (details.decayOutsideString !== null) {
177+
let str = `${client.intlGet(guildId, 'outside')}: `;
178+
if (hp === details.hp) {
179+
decayStrings.push(`${str}${details.decayOutsideString}`);
180+
}
181+
else {
182+
const time = Timer.secondsToFullScale(Math.floor(details.decayOutside * decayMultiplier));
183+
decayStrings.push(`${str}${time}`);
184+
}
185+
}
186+
187+
if (details.decayInsideString !== null) {
188+
let str = `${client.intlGet(guildId, 'inside')}: `;
189+
if (hp === details.hp) {
190+
decayStrings.push(`${str}${details.decayInsideString}`);
191+
}
192+
else {
193+
const time = Timer.secondsToFullScale(Math.floor(details.decayInside * decayMultiplier));
194+
decayStrings.push(`${str}${time}`);
195+
}
196+
}
197+
198+
if (details.decayUnderwaterString !== null) {
199+
let str = `${client.intlGet(guildId, 'underwater')}: `;
200+
if (hp === details.hp) {
201+
decayStrings.push(`${str}${details.decayUnderwaterString}`);
202+
}
203+
else {
204+
const time = Timer.secondsToFullScale(Math.floor(details.decayUnderwater * decayMultiplier));
205+
decayStrings.push(`${str}${time}`);
206+
}
207+
}
208+
decayString += `${decayStrings.join(', ')}.`;
209+
210+
client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, 'slashCommandValueChange', {
211+
id: `${verifyId}`,
212+
value: `${decayItemName} ${decayItemId} ${decayItemHp}`
213+
}));
214+
215+
await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(0, decayString));
216+
client.log(client.intlGet(null, 'infoCap'), decayString);
217+
},
218+
};

src/commands/upkeep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module.exports = {
101101
}
102102
else if (upkeepItemId !== null) {
103103
if (client.items.itemExist(upkeepItemId)) {
104-
itemId = itemItemId;
104+
itemId = upkeepItemId;
105105
}
106106
else {
107107
const str = client.intlGet(guildId, 'noItemWithIdFound', {

src/languages/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
"commandsCredentialsSetHosterDesc": "Set the hoster of FCM Credentials.",
192192
"commandsCredentialsSetHosterSteamIdDesc": "SteamId of the FCM Credentials hoster.",
193193
"commandsCredentialsShowDesc": "Show the currently registered FCM Credentials.",
194+
"commandsDecayDesc": "Display the decay time of an item.",
194195
"commandsDespawnDesc": "Display the despawn time of an item.",
195196
"commandsHelpCommandList": "Command List",
196197
"commandsHelpDesc": "Display help message.",
@@ -282,6 +283,7 @@
282283
"couldNotFindCategory": "Could not find category: {category}",
283284
"couldNotFindChannel": "Could not find channel: {channel}",
284285
"couldNotFindCraftDetails": "Could not find craft details for {name}.",
286+
"couldNotFindDecayDetails": "Could not find decay details for {name}.",
285287
"couldNotFindDespawnDetails": "Could not find despawn details for {name}.",
286288
"couldNotFindGuild": "Could not find guild: {guildId}",
287289
"couldNotFindLanguage": "Could not find language: {language}",
@@ -317,6 +319,7 @@
317319
"credentialsSetHosterSuccessfully": "FCM Credentials hoster was successfully set to steamId: {steamId}.",
318320
"currencySign": "Currency Sign",
319321
"currentCommandDelay": "Current Command Delay: {delay} seconds.",
322+
"currentItemHp": "The current HP of the item.",
320323
"currentPrefixPlaceholder": "Current Prefix: {prefix}",
321324
"customCommand": "Custom Command",
322325
"customTimerEditCargoShipEgressLabel": "Cargoship egress time (seconds):",
@@ -327,6 +330,7 @@
327330
"dayOfWipe": "Day {day}",
328331
"deathCap": "DEATH",
329332
"decay": "Decay",
333+
"decayTimeForItem": "Decay time for {item} is {time}.",
330334
"decayingCap": "DECAYING",
331335
"deleteUnreachableDevicesCap": "DELETE UNREACHABLE DEVICES",
332336
"despawnTime": "Despawn Time",
@@ -388,6 +392,7 @@
388392
"hideTrademark": "Hide trademark.",
389393
"hoster": "Hoster",
390394
"hp": "HP",
395+
"hpExceedMax": "Hp {hp} is exceeding max of {max}.",
391396
"hqmQuarry": "HQM Quarry",
392397
"ignoreSetAvatar": "Ignored setAvatar",
393398
"ignoreSetNickname": "Ignored setNickname",

0 commit comments

Comments
 (0)