Skip to content

Commit

Permalink
Correct ammo and charge messages for /k (#6187)
Browse files Browse the repository at this point in the history
  • Loading branch information
DayV-git authored Nov 21, 2024
1 parent 3a653da commit 81a873c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
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.map(i => i.userMessage).join(', '));
messages.push(degradeResults);
}

await addSubTaskToActivityTask<ColoTaskOptions>({
Expand Down
11 changes: 6 additions & 5 deletions src/lib/degradeableItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,8 @@ export async function degradeItem({
const chargesAfter = user.user[degItem.settingsKey];
assert(typeof chargesAfter === 'number' && chargesAfter > 0);
return {
userMessage: `Your ${item.name} degraded by ${chargesToDegrade} charges, and now has ${chargesAfter} remaining${
pennyReduction > 0 ? `. Your Ghommal's lucky penny saved ${pennyReduction} charges` : ''
}`
chargesToDegrade: chargesToDegrade,
userMessage: `Your ${item.name} degraded by ${chargesToDegrade} charges`
};
}

Expand Down Expand Up @@ -429,10 +428,12 @@ 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 });
results.push(result);
results.push(result.userMessage);
}

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

return results.join(', ');
}

export async function refundChargeBank(user: MUser, chargeBank: ChargeBank): Promise<RefundResult[]> {
Expand Down
13 changes: 7 additions & 6 deletions src/lib/structures/UpdateBank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ export class UpdateBank {

// Charges
if (this.chargeBank.length() > 0) {
const res = await degradeChargeBank(user, this.chargeBank).then(res =>
res.map(p => p.userMessage).join(', ')
);
if (res) {
results.push(res);
const degradeResults = await degradeChargeBank(user, this.chargeBank);
if (degradeResults) {
results.push(degradeResults);
}
}

// Loot/Cost
const totalCost = new Bank();
if (this.itemCostBank.length > 0) {
await user.specialRemoveItems(this.itemCostBank, { isInWilderness });
const { realCost } = await user.specialRemoveItems(this.itemCostBank, { isInWilderness });
totalCost.add(realCost);
}
let itemTransactionResult: Awaited<ReturnType<MUserClass['addItemsToBank']>> | null = null;
if (this.itemLootBank.length > 0) {
Expand Down Expand Up @@ -142,6 +142,7 @@ export class UpdateBank {
await user.sync();
return {
itemTransactionResult,
totalCost,
rawResults: results,
message: results.filter(r => typeof r === 'string').join(', ')
};
Expand Down
6 changes: 6 additions & 0 deletions src/mahoji/lib/abstracted_commands/minionKill/minionKill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export async function minionKillCommand(
return updateResult;
}

if (updateResult.message.length > 0) result.messages.push(updateResult.message);

if (updateResult.totalCost.length > 0) {
result.messages.push(`Removing items: ${updateResult.totalCost}`);
}

if (result.updateBank.itemCostBank.length > 0) {
await updateBankSetting('economyStats_PVMCost', result.updateBank.itemCostBank);
await trackLoot({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ export function newMinionKillCommand(args: MinionKillOptions) {
speedDurationResult.updateBank.itemCostBank.freeze();
speedDurationResult.updateBank.itemLootBank.freeze();

if (speedDurationResult.updateBank.itemCostBank.length > 0) {
speedDurationResult.messages.push(`Removing items: ${speedDurationResult.updateBank.itemCostBank}`);
}

const result = newMinionKillReturnSchema.parse({
duration,
quantity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export const mainBoostEffects: (Boost | Boost[])[] = [
const actualDegItem = degradeableItems.find(i => i.item.id === degItem.item.id);
if (!actualDegItem) throw new Error(`Missing actual degradeable item for ${rawItem.item.name}`);
charges.add(actualDegItem.settingsKey, chargesNeeded);
messages.push(`${rawItem.boostPercent}% for ${rawItem.item.name} (${chargesNeeded} charges)`);
messages.push(`${rawItem.boostPercent}% for ${rawItem.item.name}`);
}

return {
Expand Down

0 comments on commit 81a873c

Please sign in to comment.