Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to cancel trip and receive full refund #6259

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions data/osb.commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
"bankbg",
"lamp",
"cancel",
"cancel_and_refund",
"set_icon",
"set_name",
"level",
Expand Down
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ enum activity_type_enum {
MyNotes
Colosseum
CreateForestersRations
Refund
}

enum xp_gains_skill_enum {
Expand Down
1 change: 1 addition & 0 deletions src/lib/MUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ Charge your items using ${mentionCommand(globalClient, 'minion', 'charge')}.`
bpData.scales -= scales;
validateBlowpipeData(bpData);
updates.blowpipe = bpData;
realCost.add("Zulrah's scales", scales);
}

if (bankRemove.length > 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { hunterTask } from '../tasks/minions/HunterActivity/hunterActivity';
import { buryingTask } from '../tasks/minions/PrayerActivity/buryingActivity';
import { offeringTask } from '../tasks/minions/PrayerActivity/offeringActivity';
import { scatteringTask } from '../tasks/minions/PrayerActivity/scatteringActivity';
import { RefundTask } from '../tasks/minions/RefundActivity';
import { agilityTask } from '../tasks/minions/agilityActivity';
import { alchingTask } from '../tasks/minions/alchingActivity';
import { butlerTask } from '../tasks/minions/butlerActivity';
Expand Down Expand Up @@ -193,7 +194,8 @@ const tasks: MinionTask[] = [
camdozaalFishingTask,
myNotesTask,
colosseumTask,
CreateForestersRationsTask
CreateForestersRationsTask,
RefundTask
];

export async function processPendingActivities() {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/colosseum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ export async function colosseumCommand(user: MUser, channelID: string) {
}

const degradeResults = await degradeChargeBank(user, chargeBank);
messages.push(degradeResults);
messages.push(degradeResults.results);
}

await addSubTaskToActivityTask<ColoTaskOptions>({
Expand Down
10 changes: 7 additions & 3 deletions src/lib/degradeableItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,16 @@ export async function degradeChargeBank(user: MUser, chargeBank: ChargeBank) {
for (const [key, chargesToDegrade] of chargeBank.entries()) {
const { item } = degradeableItems.find(i => i.settingsKey === key)!;
const result = await degradeItem({ item, chargesToDegrade, user });
if (result.chargesToDegrade && result.chargesToDegrade !== chargesToDegrade) {
//if Ghommal's penny has procced
chargeBank.add(key, result.chargesToDegrade);
chargeBank.remove(key, chargesToDegrade);
}
results.push(result.userMessage);
}
if (user.hasEquipped("Ghommal's lucky penny")) results.push(" 5% reduced charges for Ghommal's lucky penny");

if (user.hasEquipped("Ghommal's lucky penny")) results.push("5% reduced charges for Ghommal's lucky penny");

return results.join(', ');
return { chargeBank, results: results.join(',') };
}

export async function refundChargeBank(user: MUser, chargeBank: ChargeBank): Promise<RefundResult[]> {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/musicCape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export const musicCapeRequirements = new Requirements()
activity_type_enum.ChampionsChallenge,
activity_type_enum.Nex,
activity_type_enum.Revenants, // This is now under monsterActivity
activity_type_enum.KourendFavour // Kourend favor activity was removed
activity_type_enum.KourendFavour, // Kourend favor activity was removed
activity_type_enum.Refund
];
const notDoneActivities = Object.values(activity_type_enum).filter(
type => !typesNotRequiredForMusicCape.includes(type) && !uniqueActivitiesDone.includes(type)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/randomEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const RandomEvents: RandomEvent[] = [

const cache = new LRUCache<string, number>({ max: 500 });

const doesntGetRandomEvent: activity_type_enum[] = [activity_type_enum.TombsOfAmascut];
const doesntGetRandomEvent: activity_type_enum[] = [activity_type_enum.TombsOfAmascut, activity_type_enum.Refund];

export async function triggerRandomEvent(user: MUser, type: activity_type_enum, duration: number, messages: string[]) {
if (doesntGetRandomEvent.includes(type)) return {};
Expand Down
18 changes: 15 additions & 3 deletions src/lib/structures/Bank.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { GeneralBank, type GeneralBankType } from '@oldschoolgg/toolkit/structures';
import { GeneralBank } from '@oldschoolgg/toolkit/structures';
import { Bank } from 'oldschooljs';

import type { DegradeableItem } from '../degradeableItems';
import { degradeableItems } from '../degradeableItems';
import type { ItemBank } from '../types';

export class ChargeBank extends GeneralBank<DegradeableItem['settingsKey']> {
constructor(initialBank?: GeneralBankType<DegradeableItem['settingsKey']>) {
super({ initialBank, allowedKeys: degradeableItems.map(i => i.settingsKey) });
constructor(charges?: ItemBank | ChargeBank) {
super({ allowedKeys: degradeableItems.map(i => i.settingsKey) });
if (charges) {
const entries = Object.entries(charges);
for (const [item, qty] of entries) {
const degItem = degradeableItems.find(a => a.settingsKey === item);
if (degItem) this.add(degItem.settingsKey, qty);
}
}
}

toString() {
Expand All @@ -17,6 +25,10 @@ export class ChargeBank extends GeneralBank<DegradeableItem['settingsKey']> {
)
.join(', ');
}

toJSON() {
return Object.fromEntries(this.entries());
}
}

export { XPBank } from './XPBank';
Expand Down
7 changes: 4 additions & 3 deletions src/lib/structures/UpdateBank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ export class UpdateBank {

// Charges
if (this.chargeBank.length() > 0) {
const degradeResults = await degradeChargeBank(user, this.chargeBank);
if (degradeResults) {
results.push(degradeResults);
const degradeResult = await degradeChargeBank(user, this.chargeBank);
if (degradeResult) {
this.chargeBank = degradeResult.chargeBank;
results.push(degradeResult.results);
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/lib/types/minions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { CropUpgradeType } from '@prisma/client';

import type { Bank } from 'oldschooljs';
import type { ItemBank } from '.';
import type { NMZStrategy, TwitcherGloves, UnderwaterAgilityThievingTrainingSkill } from '../constants';
import type { SlayerActivityConstants } from '../minions/data/combatConstants';
import type { IPatchData } from '../minions/farming/types';
import type { AttackStyles } from '../minions/functions';
import type { MinigameName } from '../settings/minigames';
import type { RaidLevel } from '../simulation/toa';
import type { ChargeBank } from '../structures/Bank';
import type { Peak } from '../tickers';
import type { BirdhouseData } from './../skilling/skills/hunter/defaultBirdHouseTrap';

Expand All @@ -16,6 +18,8 @@ export interface ActivityTaskOptions {
id: number;
finishDate: number;
channelID: string;
itemCost?: Bank;
chargeCost?: ChargeBank;
}

export interface ActivityTaskOptionsWithNoChanges extends ActivityTaskOptions {
Expand Down Expand Up @@ -568,6 +572,12 @@ export interface SpecificQuestOptions extends ActivityTaskOptions {
questID: number;
}

export interface RefundOptions extends ActivityTaskOptions {
type: 'Refund';
refundItems?: Bank;
refundCharges?: ChargeBank;
}

export type ActivityTaskData =
| MonsterActivityTaskOptions
| WoodcuttingActivityTaskOptions
Expand Down Expand Up @@ -634,4 +644,5 @@ export type ActivityTaskData =
| MinigameActivityTaskOptionsWithNoChanges
| CutLeapingFishActivityTaskOptions
| CreateForestersRationsActivityTaskOptions
| ColoTaskOptions;
| ColoTaskOptions
| RefundOptions;
10 changes: 10 additions & 0 deletions src/lib/util/globalInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const globalInteractionActions = [
'CHECK_PATCHES',
'AUTO_SLAY',
'CANCEL_TRIP',
'REFUND_TRIP',
'AUTO_FARM',
'AUTO_FARMING_CONTRACT',
'FARMING_CONTRACT_EASIER',
Expand Down Expand Up @@ -440,6 +441,15 @@ export async function interactionHook(interaction: Interaction) {
});
}

if (id === 'REFUND_TRIP') {
return runCommand({
commandName: 'minion',
args: { cancel_and_refund: {} },
bypassInhibitors: true,
...options
});
}

if (id === 'BUY_MINION') {
return runCommand({
commandName: 'minion',
Expand Down
3 changes: 3 additions & 0 deletions src/lib/util/minionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,5 +716,8 @@ export function minionStatus(user: MUser) {
case 'BlastFurnace': {
throw new Error('Removed');
}
case 'Refund': {
return `${name} is returning from their trip with supplies. The trip should take ${formatDuration(durationRemaining)}.`;
}
}
}
7 changes: 6 additions & 1 deletion src/lib/util/repeatStoredTrip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ const taskCanBeRepeated = (activity: Activity, user: MUser) => {
activity_type_enum.TokkulShop,
activity_type_enum.Birdhouse,
activity_type_enum.StrongholdOfSecurity,
activity_type_enum.CombatRing
activity_type_enum.CombatRing,
activity_type_enum.Refund
] as activity_type_enum[]
).includes(activity.type);
};
Expand Down Expand Up @@ -673,6 +674,10 @@ const tripHandlers = {
args: () => ({
name: 'colosseum'
})
},
[activity_type_enum.Refund]: {
commandName: 'm',
args: () => ({})
}
} as const;

Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export const buildCommand: OSBMahojiCommand = {
channelID: channelID.toString(),
quantity,
duration,
type: 'Construction'
type: 'Construction',
itemCost: cost
});

const xpHr = `${(((object.xp * quantity) / (duration / Time.Minute)) * 60).toLocaleString()} XP/Hr`;
Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/cook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export const cookCommand: OSBMahojiCommand = {
channelID: channelID.toString(),
quantity,
duration,
type: 'Cooking'
type: 'Cooking',
itemCost: totalCost
});

return `${user.minionName} is now cooking ${quantity}x ${cookable.name}, it'll take around ${formatDuration(
Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/craft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export const craftCommand: OSBMahojiCommand = {
channelID: channelID.toString(),
quantity,
duration,
type: 'Crafting'
type: 'Crafting',
itemCost: itemsNeeded
});

return `${user.minionName} is now crafting ${quantity}${sets} ${
Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/fish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export const fishCommand: OSBMahojiCommand = {
iQty: options.quantity ? options.quantity : undefined,
duration,
type: 'Fishing',
flakesQuantity
flakesQuantity,
itemCost: cost
});

let response = `${user.minionName} is now fishing ${quantity}x ${fish.name}, it'll take around ${formatDuration(
Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/fletch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export const fletchCommand: OSBMahojiCommand = {
channelID: channelID.toString(),
quantity,
duration,
type: 'Fletching'
type: 'Fletching',
itemCost: itemsNeeded
});

return `${user.minionName} is now Fletching ${quantity}${sets} ${
Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/hunt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ export const huntCommand: OSBMahojiCommand = {
usingHuntPotion,
usingStaminaPotion,
wildyPeak,
type: 'Hunter'
type: 'Hunter',
itemCost: removeBank
});

let response = `${user.minionName} is now ${crystalImpling ? 'hunting' : `${creature.huntTechnique}`}${
Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/laps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ export const lapsCommand: OSBMahojiCommand = {
: {
itemID: alchResult.itemToAlch.id,
quantity: alchResult.maxCasts
}
},
itemCost: alchResult?.bankToRemove
});

return response;
Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export const lightCommand: OSBMahojiCommand = {
channelID: channelID.toString(),
quantity,
duration,
type: 'Firemaking'
type: 'Firemaking',
itemCost: cost
});

return `${user.minionName} is now lighting ${quantity}x ${log.name}, it'll take around ${formatDuration(
Expand Down
10 changes: 9 additions & 1 deletion src/mahoji/commands/minion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ export const minionCommand: OSBMahojiCommand = {
name: 'cancel',
description: 'Cancel your current trip.'
},
{
type: ApplicationCommandOptionType.Subcommand,
name: 'cancel_and_refund',
description: 'Cancel your current trip, and bring back supplies.'
},
{
type: ApplicationCommandOptionType.Subcommand,
name: 'set_icon',
Expand Down Expand Up @@ -432,6 +437,7 @@ export const minionCommand: OSBMahojiCommand = {
cracker?: { user: MahojiUserOption };
lamp?: { item: string; quantity?: number; skill: string };
cancel?: {};
cancel_and_refund?: {};
set_icon?: { icon: string };
set_name?: { name: string };
level?: { skill: string };
Expand Down Expand Up @@ -481,7 +487,9 @@ export const minionCommand: OSBMahojiCommand = {
return lampCommand(user, options.lamp.item, options.lamp.skill, options.lamp.quantity);
}

if (options.cancel) return cancelTaskCommand(user, interaction);
if (options.cancel) return cancelTaskCommand(user, channelID, interaction);

if (options.cancel_and_refund) return cancelTaskCommand(user, channelID, interaction, true);

if (options.set_icon) {
if (perkTier < PerkTier.Four) return patronMsg(PerkTier.Four);
Expand Down
3 changes: 2 additions & 1 deletion src/mahoji/commands/mix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export const mixCommand: OSBMahojiCommand = {
wesley: Boolean(wesley),
quantity,
duration: quantity * timeToMixSingleItem,
type: 'Herblore'
type: 'Herblore',
itemCost: finalCost
});

return `${user.minionName} ${cost} making ${quantity}x ${
Expand Down
10 changes: 5 additions & 5 deletions src/mahoji/commands/offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,18 @@ export const offerCommand: OSBMahojiCommand = {
)}.`;
}

await user.removeItemsFromBank(new Bank().add(bone.inputId, quantity));
const cost = new Bank().add(bone.inputId, quantity);
await user.removeItemsFromBank(cost);

await addSubTaskToActivityTask<OfferingActivityTaskOptions>({
boneID: bone.inputId,
userID: user.id,
channelID: channelID.toString(),
quantity,
duration,
type: 'Offering'
type: 'Offering',
itemCost: cost
});
return `${user.minionName} is now offering ${quantity}x ${
bone.name
} at the Chaos altar, it'll take around ${formatDuration(duration)} to finish.`;
return `${user.minionName} is now offering ${quantity}x ${bone.name} at the Chaos altar, it'll take around ${formatDuration(duration)} to finish.`;
}
};
3 changes: 2 additions & 1 deletion src/mahoji/commands/runecraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ export const runecraftCommand: OSBMahojiCommand = {
daeyaltEssence: daeyalt_essence,
duration,
imbueCasts,
type: 'Runecraft'
type: 'Runecraft',
itemCost: totalCost
});

let response = `${user.minionName} is now turning ${quantity}x`;
Expand Down
Loading
Loading