Skip to content

Commit f9e9a5f

Browse files
committed
Fix a basic functionality for recycle stuff again
1 parent 0d2a720 commit f9e9a5f

File tree

6 files changed

+76
-52
lines changed

6 files changed

+76
-52
lines changed

src/commands/recycle.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ module.exports = {
4141
.addIntegerOption(option => option
4242
.setName('quantity')
4343
.setDescription(client.intlGet(guildId, 'commandsRecycleQuantityDesc'))
44-
.setRequired(false));
44+
.setRequired(false))
45+
.addStringOption(option => option
46+
.setName('recycler-type')
47+
.setDescription(client.intlGet(guildId, 'commandsRecycleRecyclerTypeDesc'))
48+
.setRequired(false)
49+
.addChoices(
50+
{ name: client.intlGet(guildId, 'recycler'), value: 'recycler' },
51+
{ name: client.intlGet(guildId, 'shredder'), value: 'shredder' },
52+
{ name: client.intlGet(guildId, 'safe-zone-recycler'), value: 'safe-zone-recycler' }));
4553
},
4654

4755
async execute(client, interaction) {
@@ -56,6 +64,7 @@ module.exports = {
5664
const recycleItemName = interaction.options.getString('name');
5765
const recycleItemId = interaction.options.getString('id');
5866
const recycleItemQuantity = interaction.options.getInteger('quantity');
67+
const recycleItemRecyclerType = interaction.options.getString('recycler-type');
5968

6069
let itemId = null;
6170
if (recycleItemName !== null) {
@@ -104,13 +113,14 @@ module.exports = {
104113
}
105114

106115
const quantity = recycleItemQuantity === null ? 1 : recycleItemQuantity;
116+
const recyclerType = recycleItemRecyclerType === null ? 'recycler' : recycleItemRecyclerType;
107117

108118
client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, 'slashCommandValueChange', {
109119
id: `${verifyId}`,
110-
value: `${recycleItemName} ${recycleItemId} ${recycleItemQuantity}`
120+
value: `${recycleItemName} ${recycleItemId} ${recycleItemQuantity} ${recycleItemRecyclerType}`
111121
}));
112122

113-
await DiscordMessages.sendRecycleMessage(interaction, recycleDetails, quantity);
123+
await DiscordMessages.sendRecycleMessage(interaction, recycleDetails, quantity, recyclerType);
114124
client.log(client.intlGet(null, 'infoCap'), client.intlGet(guildId, 'commandsRecycleDesc'));
115125
},
116126
};

src/discordTools/discordEmbeds.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ module.exports = {
434434
const grid = entity.location !== null ? ` (${entity.location})` : '';
435435

436436
let itemName = '', itemQuantity = '';
437-
for (const item of items) {
437+
for (const item of items['recycler']) {
438438
itemName += `\`${Client.client.items.getName(item.itemId)}\`\n`;
439439
itemQuantity += `\`${item.quantity}\`\n`;
440440
}
@@ -1141,21 +1141,22 @@ module.exports = {
11411141
});
11421142
},
11431143

1144-
getRecycleEmbed: function (guildId, recycleDetails, quantity) {
1145-
const title = quantity === 1 ? `${recycleDetails[1].name}` : `${recycleDetails[1].name} x${quantity}`;
1144+
getRecycleEmbed: function (guildId, recycleDetails, quantity, recyclerType) {
1145+
let title = quantity === 1 ? `${recycleDetails[1].name}` : `${recycleDetails[1].name} x${quantity}`;
1146+
title += ` (${Client.client.intlGet(guildId, recyclerType)})`;
11461147

11471148
const recycleData = Client.client.rustlabs.getRecycleDataFromArray([
11481149
{ itemId: recycleDetails[0], quantity: quantity, itemIsBlueprint: false }
11491150
]);
11501151

11511152
let items0 = '', quantities0 = '';
1152-
for (const item of recycleDetails[2]) {
1153+
for (const item of recycleDetails[2][recyclerType]['yield']) {
11531154
items0 += `${Client.client.items.getName(item.id)}\n`;
11541155
quantities0 += (item.probability !== 1) ? `${parseInt(item.probability * 100)}%\n` : `${item.quantity}\n`;
11551156
}
11561157

11571158
let items1 = '', quantities1 = '';
1158-
for (const item of recycleData) {
1159+
for (const item of recycleData[recyclerType]) {
11591160
items1 += `${Client.client.items.getName(item.itemId)}\n`;
11601161
quantities1 += `${item.quantity}\n`;
11611162
}
@@ -1335,7 +1336,7 @@ module.exports = {
13351336

13361337
const recycleDetails = type === 'items' ? Client.client.rustlabs.getRecycleDetailsById(itemId) : null;
13371338
if (recycleDetails !== null) {
1338-
const details = recycleDetails[2];
1339+
const details = recycleDetails[2]['recycler']['yield'];
13391340

13401341
let recycleString = '';
13411342
for (const recycleItem of details) {

src/discordTools/discordMessages.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,9 @@ module.exports = {
569569
await Client.client.interactionEditReply(interaction, content);
570570
},
571571

572-
sendRecycleMessage: async function (interaction, recycleDetails, quantity) {
572+
sendRecycleMessage: async function (interaction, recycleDetails, quantity, recyclerType) {
573573
const content = {
574-
embeds: [DiscordEmbeds.getRecycleEmbed(interaction.guildId, recycleDetails, quantity)],
574+
embeds: [DiscordEmbeds.getRecycleEmbed(interaction.guildId, recycleDetails, quantity, recyclerType)],
575575
ephemeral: true
576576
}
577577

src/languages/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
"commandsPlayersStatusDesc": "Search for players that are online/offline/any.",
223223
"commandsRecycleDesc": "Display the output of recycling an item.",
224224
"commandsRecycleQuantityDesc": "The quantity of items to recycle.",
225+
"commandsRecycleRecyclerTypeDesc": "The recycler type (recycler, shredder, safe-zone-recycler).",
225226
"commandsResearchDesc": "Display the cost to research an item.",
226227
"commandsResetAlarmsDesc": "Reset alarms channel.",
227228
"commandsResetDesc": "Reset Discord channels.",
@@ -581,6 +582,7 @@
581582
"reconnectingToServer": "RECONNECTING TO SERVER...",
582583
"recycle": "Recycle",
583584
"recycleCap": "RECYCLE",
585+
"recycler": "Recycler",
584586
"remain": "left",
585587
"removePlayerCap": "REMOVE PLAYER",
586588
"removeSwitchCap": "REMOVE SWITCH",
@@ -597,6 +599,7 @@
597599
"roleSet": "rustplusplus role has been set to {name}.",
598600
"rustMonument": "Rust Monument",
599601
"rustplusOperational": "RUSTPLUS OPERATIONAL.",
602+
"safe-zone-recycler": "Safe Zone Recycler",
600603
"samsite": "SAM site",
601604
"satelliteDish": "Satellite Dish",
602605
"scrap": "Scrap",
@@ -633,6 +636,7 @@
633636
"shouldSmartSwitchNotifyInGameWhenChangedFromDiscord": "Should Smart Switches and Smart Switch Groups notify In-Game when they are changed from discord?",
634637
"showingBlacklist": "Showing the blacklist.",
635638
"showingSubscriptionList": "Showing the subscription list.",
639+
"shredder": "Shredder",
636640
"sirenLight": "Siren Light",
637641
"six": "Six",
638642
"slash": "Slash",

src/structures/RustLabs.js

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ class RustLabs {
342342
/**
343343
* Get recycle data from an array of items.
344344
* @param {array} items The array of items (every item include itemId, quantity, itemIsBlueprint).
345-
* @return {array} An array of the output of recycling the items (every item include itemId, quantity,
346-
* itemIsBlueprint).
345+
* @return {Object} An object with recycler, shredder and safe-zone-recycler recycle data where
346+
* the all recycled items have (itemId, quantity, itemIsBlueprint).
347347
*/
348348
getRecycleDataFromArray(items) {
349349
/* Remove element duplicates */
@@ -360,54 +360,63 @@ class RustLabs {
360360
}
361361
items = mergedItems.slice();
362362

363-
let recycleData = items.slice();
364-
while (true) {
365-
let noMoreIterations = true;
363+
const recycleData = new Object();
364+
recycleData['recycler'] = [];
365+
recycleData['shredder'] = [];
366+
recycleData['safe-zone-recycler'] = [];
366367

367-
const expandedItems = [];
368-
for (const item of recycleData) {
369-
if (!this.hasRecycleDetails(item.itemId)) {
370-
expandedItems.push(item);
371-
continue;
372-
}
368+
for (const recyclerType in recycleData) {
369+
let recycledItems = items.slice();
370+
while (true) {
371+
let noMoreIterations = true;
373372

374-
/* Can the item be recycled further? */
375-
if (this.recycleData[item.itemId].length > 0 && !item.itemIsBlueprint &&
376-
!IGNORED_RECYCLE_ITEMS.includes(item.itemId)) {
377-
noMoreIterations = false;
378-
for (const recycleItem of this.recycleData[item.itemId]) {
379-
for (let i = 0; i < item.quantity; i++) {
380-
if (recycleItem.probability < 1 && Math.random() * 1 > recycleItem.probability) continue;
381-
382-
const found = expandedItems.find(e => e.itemId === recycleItem.id);
383-
if (found === undefined) {
384-
expandedItems.push({
385-
itemId: recycleItem.id,
386-
quantity: recycleItem.quantity,
387-
itemIsBlueprint: false
388-
});
389-
}
390-
else {
391-
found.quantity += recycleItem.quantity;
373+
const expandedItems = [];
374+
for (const item of recycledItems) {
375+
if (!this.hasRecycleDetails(item.itemId)) {
376+
expandedItems.push(item);
377+
continue;
378+
}
379+
380+
/* Can the item be recycled further? */
381+
if (this.recycleData[item.itemId][recyclerType]['yield'].length > 0 && !item.itemIsBlueprint &&
382+
!IGNORED_RECYCLE_ITEMS.includes(item.itemId)) {
383+
noMoreIterations = false;
384+
for (const recycleItem of this.recycleData[item.itemId][recyclerType]['yield']) {
385+
for (let i = 0; i < item.quantity; i++) {
386+
if (recycleItem.probability < 1 && Math.random() * 1 > recycleItem.probability) continue;
387+
388+
const found = expandedItems.find(e => e.itemId === recycleItem.id);
389+
if (found === undefined) {
390+
expandedItems.push({
391+
itemId: recycleItem.id,
392+
quantity: recycleItem.quantity,
393+
itemIsBlueprint: false
394+
});
395+
}
396+
else {
397+
found.quantity += recycleItem.quantity;
398+
}
392399
}
393400
}
394401
}
395-
}
396-
else {
397-
const found = expandedItems.find(e => e.itemId === item.itemId &&
398-
e.itemIsBlueprint === item.itemIsBlueprint);
399-
if (found === undefined) {
400-
expandedItems.push(item);
401-
}
402402
else {
403-
found.quantity += item.quantity;
403+
const found = expandedItems.find(e => e.itemId === item.itemId &&
404+
e.itemIsBlueprint === item.itemIsBlueprint);
405+
if (found === undefined) {
406+
expandedItems.push(item);
407+
}
408+
else {
409+
found.quantity += item.quantity;
410+
}
404411
}
405412
}
406-
}
407413

408-
recycleData = expandedItems.slice();
414+
recycledItems = expandedItems.slice();
415+
416+
if (noMoreIterations) break;
417+
}
409418

410-
if (noMoreIterations) break;
419+
recycleData[recyclerType] = recycledItems;
411420
}
412421

413422
return recycleData;

src/structures/RustPlus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ class RustPlus extends RustPlusLib {
21942194
]);
21952195

21962196
let str = `${itemName}: `;
2197-
for (const item of recycleData) {
2197+
for (const item of recycleData['recycler']) {
21982198
str += `${Client.client.items.getName(item.itemId)} x${item.quantity}, `;
21992199
}
22002200
str = str.slice(0, -2);

0 commit comments

Comments
 (0)