Skip to content

Commit

Permalink
Add spirit flakes option to fish command (#5948)
Browse files Browse the repository at this point in the history
  • Loading branch information
minimicronano authored Aug 23, 2024
1 parent 44c0a40 commit 99fc046
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/lib/types/minions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export interface FishingActivityTaskOptions extends ActivityTaskOptions {
type: 'Fishing';
fishID: number;
quantity: number;
flakesQuantity?: number;
iQty?: number;
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/util/repeatStoredTrip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ const tripHandlers = {
},
[activity_type_enum.Fishing]: {
commandName: 'fish',
args: (data: FishingActivityTaskOptions) => ({ name: data.fishID, quantity: data.iQty })
args: (data: FishingActivityTaskOptions) => ({
name: data.fishID,
quantity: data.iQty,
flakes: data.flakesQuantity !== undefined
})
},
[activity_type_enum.FishingTrawler]: {
commandName: 'minigames',
Expand Down
42 changes: 34 additions & 8 deletions src/mahoji/commands/fish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ export const fishCommand: OSBMahojiCommand = {
description: 'The quantity you want to fish (optional).',
required: false,
min_value: 1
},
{
type: ApplicationCommandOptionType.Boolean,
name: 'flakes',
description: 'Use spirit flakes?',
required: false
}
],
run: async ({ options, userID, channelID }: CommandRunOptions<{ name: string; quantity?: number }>) => {
run: async ({
options,
userID,
channelID
}: CommandRunOptions<{ name: string; quantity?: number; flakes?: boolean }>) => {
const user = await mUserFetch(userID);
const fish = Fishing.Fishes.find(
fish =>
Expand Down Expand Up @@ -132,8 +142,22 @@ export const fishCommand: OSBMahojiCommand = {

const maxTripLength = calcMaxTripLength(user, 'Fishing');

let { quantity } = options;
if (!quantity) quantity = Math.floor(maxTripLength / scaledTimePerFish);
let { quantity, flakes } = options;
if (!quantity) {
quantity = Math.floor(maxTripLength / scaledTimePerFish);
}
let flakesQuantity: number | undefined;
const cost = new Bank();

if (flakes) {
if (!user.bank.has('Spirit flakes')) {
return 'You need to have at least one spirit flake!';
}

flakesQuantity = Math.min(user.bank.amount('Spirit flakes'), quantity);
boosts.push(`More fish from using ${flakesQuantity}x Spirit flakes`);
cost.add('Spirit flakes', flakesQuantity);
}

if (fish.bait) {
const baseCost = new Bank().add(fish.bait);
Expand All @@ -146,11 +170,12 @@ export const fishCommand: OSBMahojiCommand = {
quantity = maxCanDo;
}

const cost = new Bank();
cost.add(baseCost.multiply(quantity));
cost.add(fish.bait, quantity);
}

// Remove the bait from their bank.
await user.removeItemsFromBank(new Bank().add(fish.bait, quantity));
if (cost.length > 0) {
// Remove the bait and/or spirit flakes from their bank.
await user.removeItemsFromBank(cost);
}

let duration = quantity * scaledTimePerFish;
Expand All @@ -173,7 +198,8 @@ export const fishCommand: OSBMahojiCommand = {
quantity,
iQty: options.quantity ? options.quantity : undefined,
duration,
type: 'Fishing'
type: 'Fishing',
flakesQuantity
});

let response = `${user.minionName} is now fishing ${quantity}x ${fish.name}, it'll take around ${formatDuration(
Expand Down
6 changes: 6 additions & 0 deletions src/tasks/minions/fishingActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const fishingTask: MinionTask = {
}),
async run(data: FishingActivityTaskOptions) {
const { fishID, quantity, userID, channelID, duration } = data;
let { flakesQuantity } = data;
const user = await mUserFetch(userID);
const currentLevel = user.skillLevel(SkillsEnum.Fishing);
const { blessingEquipped, blessingChance } = radasBlessing(user);
Expand Down Expand Up @@ -160,6 +161,11 @@ export const fishingTask: MinionTask = {
} else {
lootQuantity += blessingEquipped && percentChance(blessingChance) ? 2 : 1;
}

if (flakesQuantity && flakesQuantity > 0) {
lootQuantity += percentChance(50) ? 1 : 0;
flakesQuantity--;
}
}

const loot = new Bank({
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/commands/fish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,41 @@ describe('Fish Command', () => {
**Boosts:** +9 trip minutes for having a Fish sack barrel.`
});
});

it('should handle using flakes without flakes in bank', () => {
testRunCmd({
cmd: fishCommand,
opts: { name: 'shrimps', flakes: true },
user: {
skills_fishing: 999_999
},
result: 'You need to have at least one spirit flake!'
});
});

it('should fish with flakes', () => {
testRunCmd({
cmd: fishCommand,
opts: { name: 'shrimps', flakes: true },
user: {
bank: new Bank({ 'Spirit flakes': 10000 })
},
result: `<:minion:778418736180494347> Your minion is now fishing 251x Shrimps, it'll take around 29 minutes, 58 seconds to finish.
**Boosts:** More fish from using 251x Spirit flakes.`
});
});

it('should still use flakes if bank contains fewer flakes than fish quantity', () => {
testRunCmd({
cmd: fishCommand,
opts: { name: 'shrimps', flakes: true },
user: {
bank: new Bank({ 'Spirit flakes': 100 })
},
result: `<:minion:778418736180494347> Your minion is now fishing 251x Shrimps, it'll take around 29 minutes, 58 seconds to finish.
**Boosts:** More fish from using 100x Spirit flakes.`
});
});
});

0 comments on commit 99fc046

Please sign in to comment.