Skip to content

Commit

Permalink
Merge branch 'bso' of github.com:gc/oldschoolbot-secret into bso
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Mar 5, 2024
2 parents 1fd207b + 4e487dd commit 0322854
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 13 deletions.
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ model Tame {
last_activity_date DateTime? @db.Timestamp(6)
levels_from_egg_feed Int?
custom_icon_id String? @db.VarChar(19)
tame_activity TameActivity[]
@@index([user_id])
Expand Down
Binary file added src/lib/resources/images/tames/1_replace_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/lib/resources/images/tames/1_replace_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/lib/resources/images/tames/1_replace_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/lib/resources/images/tames/1_replace_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/lib/resources/images/tames/1_replace_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/lib/resources/images/tames/2_replace_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/lib/resources/images/tames/2_replace_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/lib/resources/images/tames/3_replace_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
155 changes: 142 additions & 13 deletions src/mahoji/commands/tames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,57 @@ const tameForegrounds = [
}
];

const tameImageReplacementChoices = [
{
name: 'Elvarg',
species: TameSpeciesID.Igne,
image: readFileSync('./src/lib/resources/images/tames/1_replace_1.png')
},
{
name: 'King Black Dragon',
species: TameSpeciesID.Igne,
image: readFileSync('./src/lib/resources/images/tames/1_replace_2.png')
},
{
name: 'Lava Dragon',
species: TameSpeciesID.Igne,
image: readFileSync('./src/lib/resources/images/tames/1_replace_3.png')
},
{
name: 'Revenant Dragon',
species: TameSpeciesID.Igne,
image: readFileSync('./src/lib/resources/images/tames/1_replace_4.png')
},
{
name: 'Rune Dragon',
species: TameSpeciesID.Igne,
image: readFileSync('./src/lib/resources/images/tames/1_replace_5.png')
}
];

const tameImageReplacementEasterEggs = [
{
shouldActivate: (t: Tame) => t.nickname?.toLowerCase() === 'robochimp' && t.species_id === TameSpeciesID.Monkey,
image: readFileSync('./src/lib/resources/images/tames/2_replace_1.png')
},
{
shouldActivate: (t: Tame) => t.nickname?.toLowerCase() === 'magnaboy' && t.species_id === TameSpeciesID.Monkey,
image: readFileSync('./src/lib/resources/images/tames/2_replace_2.png')
},
{
shouldActivate: (t: Tame) =>
t.nickname !== null &&
['meneldor', 'gwaihir', 'landroval'].includes(t.nickname.toLowerCase()) &&
t.species_id === TameSpeciesID.Eagle,
image: readFileSync('./src/lib/resources/images/tames/3_replace_1.png')
},
...tameImageReplacementChoices.map(tameImage => ({

Check warning on line 260 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

'tameImage' is already declared in the upper scope on line 364 column 23

Check warning on line 260 in src/mahoji/commands/tames.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

'tameImage' is already declared in the upper scope on line 364 column 23
shouldActivate: (t: Tame, user: MUser) =>
t.custom_icon_id === tameImage.name && user.perkTier() >= PerkTier.Four,
image: tameImage.image
}))
];

// eslint-disable-next-line @typescript-eslint/init-declarations
let sprites: {
base: {
Expand Down Expand Up @@ -255,20 +306,26 @@ async function initSprites() {
return {
type: v,
growthStage: {
[tame_growth.baby]: await getClippedRegionImage(tameImage, (v - 1) * 96, 0, 96, 96),
[tame_growth.baby]: await getClippedRegionImage(
tameImage,
(v - 1) * tameImageSize,
0,
tameImageSize,
tameImageSize
),
[tame_growth.juvenile]: await getClippedRegionImage(
tameImage,
(v - 1) * 96,
96,
96,
96
(v - 1) * tameImageSize,
tameImageSize,
tameImageSize,
tameImageSize
),
[tame_growth.adult]: await getClippedRegionImage(
tameImage,
(v - 1) * 96,
96 * 2,
96,
96
(v - 1) * tameImageSize,
tameImageSize * 2,
tameImageSize,
tameImageSize
)
}
};
Expand Down Expand Up @@ -387,12 +444,16 @@ export async function tameImage(user: MUser): CommandResponse {
128
);

const tameX = (10 + 256) * x + (isTameActive ? 96 : 256 - 96) / 2;
const tameX = (10 + 256) * x + (isTameActive ? tameImageSize : 256 - tameImageSize) / 2;
const tameY = (10 + 128) * y + 10;

const tameImage = sprites
.tames!.find(t => t.id === species.id)!
.sprites.find(f => f.type === t.species_variant)!.growthStage[t.growth_stage];
const imageReplacement = tameImageReplacementEasterEggs.find(i => i.shouldActivate(t, user));

const tameImage = imageReplacement
? await loadImage(imageReplacement.image)
: sprites.tames!.find(t => t.id === species.id)!.sprites.find(f => f.type === t.species_variant)!
.growthStage[t.growth_stage];

// Draw tame
ctx.drawImage(tameImage, tameX, tameY, tameImageSize, tameImageSize);
const foreground = tameForegrounds.find(i => i.shouldActivate(t));
Expand Down Expand Up @@ -1666,6 +1727,9 @@ export type TamesCommandOptions = CommandRunOptions<{
clue?: {
clue: string;
};
set_custom_image?: {
image: string;
};
}>;
export const tamesCommand: OSBMahojiCommand = {
name: 'tames',
Expand Down Expand Up @@ -1917,6 +1981,27 @@ export const tamesCommand: OSBMahojiCommand = {
}
}
]
},
{
type: ApplicationCommandOptionType.Subcommand,
name: 'set_custom_image',
description: 'Set a custom image for your tame.',
options: [
{
type: ApplicationCommandOptionType.String,
name: 'image',
description: 'The image to pick.',
required: true,
autocomplete: async () => {
const options = tameImageReplacementChoices.map(t => ({
name: `${t.name} (${tameSpecies.find(s => s.id === t.species)!.name})`,
value: t.name
}));
options.unshift({ name: 'None', value: 'none' });
return options;
}
}
]
}
],
run: async ({ options, userID, channelID, interaction }: TamesCommandOptions) => {
Expand Down Expand Up @@ -1988,6 +2073,50 @@ export const tamesCommand: OSBMahojiCommand = {

return reply;
}
if (options.set_custom_image) {
if (user.perkTier() < PerkTier.Four) {
return 'You need to be a Tier 3 patron to set a custom image for your tame.';
}

// Handle resetting the custom image:
if (options.set_custom_image?.image.toLowerCase() === 'none') {
const { tame } = await getUsersTame(user);
if (tame === null) {
return "You don't have a tame selected, select the tame who's icon should be reset.";
}
await prisma.tame.update({
where: {
id: tame.id
},
data: {
custom_icon_id: null
}
});
return 'Successfully removed the custom tame icon!';
}

// Handle updating the image:
const replacement = tameImageReplacementChoices.find(i => i.name === options.set_custom_image?.image);
if (!replacement) {
return 'Invalid image.';
}
const { tame } = await getUsersTame(user);
if (tame === null) {
return "You don't have a tame selected, select the tame you want to give this icon.";
}
if (tame.species_id !== replacement.species) {
return `This image is for the ${tameSpecies.find(s => s.id === replacement.species)!.name} species.`;
}
await prisma.tame.update({
where: {
id: tame.id
},
data: {
custom_icon_id: replacement.name
}
});
return `You set the '${replacement.name}' custom image for your ${tameName(tame)}.`;
}
return 'Invalid command.';
}
};

0 comments on commit 0322854

Please sign in to comment.