Skip to content

Commit

Permalink
Merge pull request #294 from the-hideout/game-modes
Browse files Browse the repository at this point in the history
Support multiple game modes
  • Loading branch information
Razzmatazzz authored Jul 19, 2024
2 parents c5d8f8c + 0369a60 commit 6829f27
Show file tree
Hide file tree
Showing 25 changed files with 1,205 additions and 799 deletions.
32 changes: 20 additions & 12 deletions commands/barter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const defaultFunction = {
),
async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);
const commandT = getFixedT(lang, 'command');
const searchString = interaction.options.getString('name');

if (!searchString) {
Expand All @@ -33,12 +34,14 @@ const defaultFunction = {
});
}

const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});

const matchedBarters = [];

const [items, barters, traders] = await Promise.all([
gameData.items.getAll(locale),
gameData.barters.getAll(),
gameData.traders.getAll(locale)
gameData.items.getAll({lang, gameMode}),
gameData.barters.getAll({gameMode}),
gameData.traders.getAll({lang, gameMode})
]);
const searchedItems = items.filter(item => item.name.toLowerCase().includes(searchString.toLowerCase()));

Expand All @@ -54,17 +57,20 @@ const defaultFunction = {
}

if (matchedBarters.length === 0) {
const embed = new EmbedBuilder();
embed.setDescription(t(`Found no results for "{{searchString}}"`, {
searchString: searchString
}));
embed.setFooter({text: gameModeLabel});
return interaction.editReply({
content: t(`Found no results for "{{searchString}}"`, {
searchString: searchString
}),
embeds: [embed],
ephemeral: true,
});
}

let embeds = [];

const prog = await progress.getSafeProgress(interaction.user.id);
const prog = await progress.getProgressOrDefault(interaction.user.id);

for (let i = 0; i < matchedBarters.length; i = i + 1) {
const barter = barters.find(b => b.id === matchedBarters[i]);
Expand Down Expand Up @@ -135,10 +141,10 @@ const defaultFunction = {
}

totalCost += itemCost * req.count;
embed.addFields({name: reqName, value: itemCost.toLocaleString(locale) + "₽ x " + req.count, inline: true});
embed.addFields({name: reqName, value: itemCost.toLocaleString(lang) + "₽ x " + req.count, inline: true});
}

embed.addFields({name: t('Total'), value: totalCost.toLocaleString(locale) + "₽", inline: false});
embed.addFields({name: t('Total'), value: totalCost.toLocaleString(lang) + "₽", inline: false});

embeds.push(embed);

Expand All @@ -162,14 +168,16 @@ const defaultFunction = {
const bitemname = `[${rewardItem.name}](${rewardItem.link}) (${trader.name} LL${barter.level})`;

if (bitemname.length + 2 + otheritems.length > 2048) {
ending.setFooter({text: `${matchedBarters.length-i} ${t('additional results not shown.')}`,});
ending.setFooter({text: `${matchedBarters.length-i} ${t('additional results not shown.')} | ${gameModeLabel}`,});
break;
}
otheritems += bitemname + "\n";
}
ending.setDescription(otheritems);

embeds.push(ending);
} else {
embeds[embeds.length-1].setFooter({text: gameModeLabel});
}

return interaction.editReply({ embeds: embeds });
Expand Down
12 changes: 6 additions & 6 deletions commands/boss.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);

// Get the boss name from the command interaction
const bossName = interaction.options.getString('boss');

const bosses = await gameData.bosses.getAll(locale);
const bosses = await gameData.bosses.getAll({lang});

// Fetch all current map/boss data
const maps = await gameData.maps.getAll(locale);
const maps = await gameData.maps.getAll({lang, gameMode});

// Fetch all items
const items = await gameData.items.getAll(locale);
const items = await gameData.items.getAll({lang, gameMode});

const tiers = await getTiers();
const tiers = await getTiers(gameMode);

// Construct the embed
const embed = new EmbedBuilder();
Expand Down
34 changes: 22 additions & 12 deletions commands/craft.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);
const searchString = interaction.options.getString('name');

if (!searchString) {
Expand All @@ -34,12 +34,15 @@ const defaultFunction = {
});
}

const commandT = getFixedT(lang, 'command');
const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});

const matchedCrafts = [];

const [items, crafts, stations] = await Promise.all([
gameData.items.getAll(locale),
gameData.crafts.getAll(),
gameData.hideout.getAll(locale),
gameData.items.getAll({lang, gameMode}),
gameData.crafts.getAll({gameMode}),
gameData.hideout.getAll({lang, gameMode}),
]);

const searchedItems = items.filter(item => item.name.toLowerCase().includes(searchString.toLowerCase()));
Expand All @@ -56,15 +59,20 @@ const defaultFunction = {
}

if (matchedCrafts.length === 0) {
const embed = new EmbedBuilder();
embed.setDescription(t(`Found no results for "{{searchString}}"`, {
searchString: searchString
}));
embed.setFooter({text: gameModeLabel});
return interaction.editReply({
content: t('Found no results for "{{searchString}}"', {searchString: searchString}),
embeds: [embed],
ephemeral: true,
});
}

let embeds = [];

const prog = await progress.getSafeProgress(interaction.user.id);
const prog = await progress.getProgressOrDefault(interaction.user.id);

for (let i = 0; i < matchedCrafts.length; i = i + 1) {
const craft = crafts.find(c => c.id === matchedCrafts[i]);
Expand Down Expand Up @@ -128,7 +136,7 @@ const defaultFunction = {
}
if (isTool) {
toolCost += itemCost * req.count;
toolsEmbed.addFields({name: reqItem.name, value: itemCost.toLocaleString(locale) + "₽ x " + req.count, inline: true});
toolsEmbed.addFields({name: reqItem.name, value: itemCost.toLocaleString(lang) + "₽ x " + req.count, inline: true});
if(!toolsEmbed.thumbnail) {
toolsEmbed.setThumbnail(reqItem.iconLink);
}
Expand All @@ -143,13 +151,13 @@ const defaultFunction = {
}
totalCost += itemCost * quantity;
//totalCost += req.item.avg24hPrice * req.count;
embed.addFields({name: reqItem.name, value: itemCost.toLocaleString(locale) + '₽ x ' + quantity, inline: true});
embed.addFields({name: reqItem.name, value: itemCost.toLocaleString(lang) + '₽ x ' + quantity, inline: true});
}
embed.addFields({name: t('Total'), value: totalCost.toLocaleString(locale) + '₽', inline: false});
embed.addFields({name: t('Total'), value: totalCost.toLocaleString(lang) + '₽', inline: false});

embeds.push(embed);
if (toolsEmbed.data.fields?.length > 0) {
toolsEmbed.addFields({name: t('Total'), value: toolCost.toLocaleString(locale) + '₽', inline: false});
toolsEmbed.addFields({name: t('Total'), value: toolCost.toLocaleString(lang) + '₽', inline: false});
embeds.push(toolsEmbed);
}

Expand All @@ -173,7 +181,7 @@ const defaultFunction = {
const bitemname = `[${rewardItem.name}](${rewardItem.link}) (${station.name} level ${craft.level})`;

if (bitemname.length + 4 + otheritems.length > 2048) {
ending.setFooter({text: `${matchedCrafts.length-i} ${t('additional results not shown.')}`,});
ending.setFooter({text: `${matchedCrafts.length-i} ${t('additional results not shown.')} | ${gameModeLabel}`,});

break;
}
Expand All @@ -182,6 +190,8 @@ const defaultFunction = {
ending.setDescription(otheritems);

embeds.push(ending);
} else {
embeds[embeds.length-1].setFooter({text: gameModeLabel});
}

return interaction.editReply({ embeds: embeds });
Expand Down
34 changes: 34 additions & 0 deletions commands/gamemode.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';

import { getFixedT, getCommandLocalizations, comT } from '../modules/translations.mjs';
import progress from '../modules/progress-shard.mjs';
import gameData from '../modules/game-data.mjs';

const defaultFunction = {
data: new SlashCommandBuilder()
.setName('gamemode')
.setDescription('Set the game mode (regular, PVE) for bot responses')
.setNameLocalizations(getCommandLocalizations('gamemode'))
.setDescriptionLocalizations(getCommandLocalizations('gamemode_desc'))
.addStringOption(option => option
.setName('gamemode')
.setDescription('Game mode to use')
.setNameLocalizations(getCommandLocalizations('gamemode'))
.setDescriptionLocalizations(getCommandLocalizations('gamemode_option_desc'))
.setRequired(true)
.setChoices(...gameData.gameModes.choices())
),
async execute(interaction) {
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const gameMode = interaction.options.getString('gamemode');
progress.setGameMode(interaction.user.id, gameMode);
const gameModeT = comT(`game_mode_${gameMode}`, {lng: locale});
return interaction.reply({
content: `✅ ${t('Game mode set to {{gameMode}}.', {gameMode: gameModeT})}`,
ephemeral: true
});
},
};

export default defaultFunction;
42 changes: 35 additions & 7 deletions commands/goons.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import got from 'got';
import moment from 'moment/min/moment-with-locales.js';

import gameData from '../modules/game-data.mjs';
import { getFixedT, getCommandLocalizations } from '../modules/translations.mjs';
Expand All @@ -22,20 +23,46 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply({ephemeral: true});
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);
const commandT = getFixedT(lang, 'command');
const mapId = interaction.options.getString('map');

if (!mapId) {
const locationEmbed = new EmbedBuilder();
locationEmbed.setTitle('Coming soon(?)');
locationEmbed.setDescription('Once we start getting a sufficient number of reports, we will be able to provide location');
const [maps, bosses, reports] = await Promise.all([
gameData.maps.getAll({lang, gameMode}),
gameData.bosses.getAll({lang, gameMode}),
gameData.goonReports.get({gameMode})
]);
const reportsEmbed = new EmbedBuilder();
const goons = bosses.find(b => b.normalizedName === 'death-knight');
if (goons) {
reportsEmbed.setThumbnail(goons.imagePortraitLink);
}
const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});
let embedTitle = t('No Recent Goons Reports');
let embedDescription = t('When users submit reports, they will appear here');
if (reports.length > 1) {
embedTitle = t('Latest Goon Reports');
embedDescription = `${reports.map(report => {
const map = maps.find(m => m.id === report.map.id);
if (!map) {
return false;
}
const reportDate = new Date(parseInt(report.timestamp));
moment.locale(lang);
return `${map.name}: ${moment(reportDate).fromNow()}`;
}).filter(Boolean).join('\n')}`;
}
reportsEmbed.setTitle(embedTitle);
reportsEmbed.setDescription(embedDescription);
reportsEmbed.setFooter({ text: gameModeLabel});
return interaction.editReply({
embeds: [locationEmbed],
embeds: [reportsEmbed],
});
}

const mapData = await gameData.maps.getAll(locale);
const mapData = await gameData.maps.getAll(lang);
const selectedMap = mapData.find(m => m.id === mapId);

const confirm = new ButtonBuilder()
Expand Down Expand Up @@ -77,6 +104,7 @@ const defaultFunction = {
map: selectedMap.nameId,
timestamp: new Date().getTime(),
accountId: parseInt(interaction.user.id.slice(-10)),
gameMode: gameMode,
},
}).json();

Expand Down
14 changes: 9 additions & 5 deletions commands/map.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);
const commandT = getFixedT(lang, 'command');
const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});
const mapId = interaction.options.getString('map');

const [mapData, itemData] = await Promise.all([
gameData.maps.getAll(locale),
gameData.items.getAll(locale),
gameData.maps.getAll({lang, gameMode}),
gameData.items.getAll({lang, gameMode}),
]);
const embed = new EmbedBuilder();

Expand Down Expand Up @@ -113,7 +115,9 @@ const defaultFunction = {

// If the map was made by a contributor, give them credit
if (selectedMapData.source) {
embed.setFooter({ text: t('Map made by {{author}}', {author: selectedMapData.source})});
embed.setFooter({ text: `${t('Map made by {{author}}', {author: selectedMapData.source})} | ${gameModeLabel}`});
} else {
embed.setFooter({ text: gameModeLabel});
}

return interaction.editReply({
Expand Down
Loading

0 comments on commit 6829f27

Please sign in to comment.