From 87108b9398d92ae48dbc9d6ada0dfb0dfab00345 Mon Sep 17 00:00:00 2001 From: nwjgit Date: Tue, 10 Oct 2023 23:39:29 -0500 Subject: [PATCH 1/3] return correct uncharged item when charges run out --- src/lib/degradeableItems.ts | 78 ++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/src/lib/degradeableItems.ts b/src/lib/degradeableItems.ts index 9ae8ba1571..21d88e9b91 100644 --- a/src/lib/degradeableItems.ts +++ b/src/lib/degradeableItems.ts @@ -22,7 +22,7 @@ interface DegradeableItem { | 'blood_essence_charges' | 'trident_charges' | 'scythe_of_vitur_charges'; - itemsToRefundOnBreak: Bank; + run: (user: MUser) => Bank; setup: GearSetupType; aliases: string[]; chargeInput: { @@ -58,7 +58,9 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Abyssal tentacle'), settingsKey: 'tentacle_charges', - itemsToRefundOnBreak: new Bank().add('Kraken tentacle'), + run: () => { + return new Bank().add('Kraken tentacle'); + }, setup: 'melee', aliases: ['tentacle', 'tent'], chargeInput: { @@ -70,7 +72,15 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Sanguinesti staff'), settingsKey: 'sang_charges', - itemsToRefundOnBreak: new Bank().add('Sanguinesti staff (uncharged)'), + run: (user: MUser) => { + let unchargedItem: string = ''; + if (user.hasEquipped('Holy sanguinesti staff')) { + unchargedItem = 'Holy sanguinesti staff (uncharged)'; + } else { + unchargedItem = 'Sanguinesti staff (uncharged)'; + } + return new Bank().add(unchargedItem); + }, setup: 'mage', aliases: ['sang', 'sang staff', 'sanguinesti staff', 'sanguinesti'], chargeInput: { @@ -84,7 +94,9 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Celestial ring'), settingsKey: 'celestial_ring_charges', - itemsToRefundOnBreak: new Bank().add('Celestial ring (uncharged)'), + run: () => { + return new Bank().add('Celestial ring (uncharged)'); + }, setup: 'skilling', aliases: ['celestial ring'], chargeInput: { @@ -98,7 +110,9 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Ash sanctifier'), settingsKey: 'ash_sanctifier_charges', - itemsToRefundOnBreak: new Bank().add('Ash sanctifier'), + run: () => { + return new Bank().add('Ash sanctifier'); + }, setup: 'skilling', aliases: ['ash sanctifier'], chargeInput: { @@ -111,7 +125,9 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Serpentine helm'), settingsKey: 'serp_helm_charges', - itemsToRefundOnBreak: new Bank().add('Serpentine helm (uncharged)'), + run: () => { + return new Bank().add('Serpentine helm (uncharged)'); + }, setup: 'melee', aliases: ['serp', 'serp helm', 'serpentine helm'], chargeInput: { @@ -125,7 +141,9 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Amulet of blood fury'), settingsKey: 'blood_fury_charges', - itemsToRefundOnBreak: new Bank().add('Amulet of fury'), + run: () => { + return new Bank().add('Amulet of fury'); + }, setup: 'melee', aliases: ['blood fury', 'amulet of blood fury'], chargeInput: { @@ -139,7 +157,9 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem("Tumeken's shadow"), settingsKey: 'tum_shadow_charges', - itemsToRefundOnBreak: new Bank().add("Tumeken's shadow (uncharged)"), + run: () => { + return new Bank().add("Tumeken's shadow (uncharged)"); + }, setup: 'mage', aliases: ['ts', 'tum shadow', 'tumekens shadow'], chargeInput: { @@ -153,7 +173,9 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Blood essence (active)'), settingsKey: 'blood_essence_charges', - itemsToRefundOnBreak: new Bank(), + run: () => { + return new Bank(); + }, setup: 'skilling', aliases: ['blood essence'], chargeInput: { @@ -165,7 +187,15 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Trident of the swamp'), settingsKey: 'trident_charges', - itemsToRefundOnBreak: new Bank().add('Uncharged toxic trident'), + run: (user: MUser) => { + let unchargedItem: string = ''; + if (user.hasEquipped('Trident of the swamp')) { + unchargedItem = 'Uncharged toxic trident'; + } else { + unchargedItem = 'Uncharged trident'; + } + return new Bank().add(unchargedItem); + }, setup: 'mage', aliases: ['trident', 'trident of the swamp'], chargeInput: { @@ -179,7 +209,17 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Scythe of vitur'), settingsKey: 'scythe_of_vitur_charges', - itemsToRefundOnBreak: new Bank().add('Scythe of vitur (uncharged)'), + run: (user: MUser) => { + let unchargedItem: string = ''; + if (user.hasEquipped('Holy Scythe of vitur')) { + unchargedItem = 'Holy scythe of vitur (uncharged)'; + } else if (user.hasEquipped('Sanguine Scythe of vitur')) { + unchargedItem = 'Sanguine scythe of vitur (uncharged)'; + } else { + unchargedItem = 'Scythe of vitur (uncharged)'; + } + return new Bank().add(unchargedItem); + }, setup: 'melee', aliases: ['scythe of vitur'], chargeInput: { @@ -285,22 +325,22 @@ export async function degradeItem({ updateBankSetting('degraded_items_cost', itemsDeleted); if (hasEquipped) { - // If its equipped, unequip and delete it. + // If its equipped, give user new item, unequip old item and delete it. const gear = { ...user.gear[degItem.setup].raw() }; + if (degItem.run !== undefined) { + const bankValue = degItem.run(user); + await user.addItemsToBank({ items: bankValue, collectionLog: false }); + } gear[item.equipment!.slot] = null; await user.update({ [`gear_${degItem.setup}`]: gear }); - if (degItem.itemsToRefundOnBreak) { - await user.addItemsToBank({ items: degItem.itemsToRefundOnBreak, collectionLog: false }); - } } else if (hasInBank) { // If its in bank, just remove 1 from bank. - let itemsToAdd = undefined; - if (degItem.itemsToRefundOnBreak) { - itemsToAdd = degItem.itemsToRefundOnBreak; + if (degItem.run !== undefined) { + const itemsToAdd = degItem.run(user); // Call the function to get the actual Bank value + await user.transactItems({ itemsToRemove: new Bank().add(item.id, 1), itemsToAdd }); } - await user.transactItems({ itemsToRemove: new Bank().add(item.id, 1), itemsToAdd }); } else { // If its not in bank OR equipped, something weird has gone on. throw new Error( From afac7927f01f296f8523db44bc3e600a1e7a09ff Mon Sep 17 00:00:00 2001 From: nwjgit Date: Wed, 11 Oct 2023 13:55:45 -0500 Subject: [PATCH 2/3] address problems and redo how bot finds variants --- src/lib/degradeableItems.ts | 129 +++++++++++++++++------------------- 1 file changed, 62 insertions(+), 67 deletions(-) diff --git a/src/lib/degradeableItems.ts b/src/lib/degradeableItems.ts index 21d88e9b91..28e2e2a274 100644 --- a/src/lib/degradeableItems.ts +++ b/src/lib/degradeableItems.ts @@ -22,7 +22,12 @@ interface DegradeableItem { | 'blood_essence_charges' | 'trident_charges' | 'scythe_of_vitur_charges'; - run: (user: MUser) => Bank; + itemsToRefundOnBreak: Bank; + refundVariants: { + variant: Item; + refund: Bank; + }[]; + setup: GearSetupType; aliases: string[]; chargeInput: { @@ -58,13 +63,12 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Abyssal tentacle'), settingsKey: 'tentacle_charges', - run: () => { - return new Bank().add('Kraken tentacle'); - }, + itemsToRefundOnBreak: new Bank().add('Kraken tentacle').freeze(), + refundVariants: [], setup: 'melee', aliases: ['tentacle', 'tent'], chargeInput: { - cost: new Bank().add('Abyssal whip'), + cost: new Bank().add('Abyssal whip').freeze(), charges: 10_000 }, emoji: '<:Abyssal_tentacle:1068551359755989033>' @@ -72,19 +76,17 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Sanguinesti staff'), settingsKey: 'sang_charges', - run: (user: MUser) => { - let unchargedItem: string = ''; - if (user.hasEquipped('Holy sanguinesti staff')) { - unchargedItem = 'Holy sanguinesti staff (uncharged)'; - } else { - unchargedItem = 'Sanguinesti staff (uncharged)'; + itemsToRefundOnBreak: new Bank().add('Sanguinesti staff (uncharged)').freeze(), + refundVariants: [ + { + variant: getOSItem('Holy sanguinesti staff'), + refund: new Bank().add('Holy sanguinesti staff (uncharged)').freeze() } - return new Bank().add(unchargedItem); - }, + ], setup: 'mage', aliases: ['sang', 'sang staff', 'sanguinesti staff', 'sanguinesti'], chargeInput: { - cost: new Bank().add('Blood rune', 3), + cost: new Bank().add('Blood rune', 3).freeze(), charges: 1 }, unchargedItem: getOSItem('Sanguinesti staff (uncharged)'), @@ -94,13 +96,12 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Celestial ring'), settingsKey: 'celestial_ring_charges', - run: () => { - return new Bank().add('Celestial ring (uncharged)'); - }, + itemsToRefundOnBreak: new Bank().add('Celestial ring (uncharged)').freeze(), + refundVariants: [], setup: 'skilling', aliases: ['celestial ring'], chargeInput: { - cost: new Bank().add('Stardust', 10), + cost: new Bank().add('Stardust', 10).freeze(), charges: 10 }, unchargedItem: getOSItem('Celestial ring (uncharged)'), @@ -110,13 +111,12 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Ash sanctifier'), settingsKey: 'ash_sanctifier_charges', - run: () => { - return new Bank().add('Ash sanctifier'); - }, + itemsToRefundOnBreak: new Bank().add('Ash sanctifier').freeze(), + refundVariants: [], setup: 'skilling', aliases: ['ash sanctifier'], chargeInput: { - cost: new Bank().add('Death rune', 1), + cost: new Bank().add('Death rune', 1).freeze(), charges: 10 }, unchargedItem: getOSItem('Ash sanctifier'), @@ -125,13 +125,12 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Serpentine helm'), settingsKey: 'serp_helm_charges', - run: () => { - return new Bank().add('Serpentine helm (uncharged)'); - }, + itemsToRefundOnBreak: new Bank().add('Serpentine helm (uncharged)').freeze(), + refundVariants: [], setup: 'melee', aliases: ['serp', 'serp helm', 'serpentine helm'], chargeInput: { - cost: new Bank().add("Zulrah's scales"), + cost: new Bank().add("Zulrah's scales").freeze(), charges: 1 }, unchargedItem: getOSItem('Serpentine helm (uncharged)'), @@ -141,13 +140,12 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Amulet of blood fury'), settingsKey: 'blood_fury_charges', - run: () => { - return new Bank().add('Amulet of fury'); - }, + itemsToRefundOnBreak: new Bank().add('Amulet of fury').freeze(), + refundVariants: [], setup: 'melee', aliases: ['blood fury', 'amulet of blood fury'], chargeInput: { - cost: new Bank().add('Blood shard'), + cost: new Bank().add('Blood shard').freeze(), charges: 10_000 }, unchargedItem: getOSItem('Amulet of fury'), @@ -157,13 +155,12 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem("Tumeken's shadow"), settingsKey: 'tum_shadow_charges', - run: () => { - return new Bank().add("Tumeken's shadow (uncharged)"); - }, + itemsToRefundOnBreak: new Bank().add("Tumeken's shadow (uncharged)").freeze(), + refundVariants: [], setup: 'mage', aliases: ['ts', 'tum shadow', 'tumekens shadow'], chargeInput: { - cost: new Bank().add('Soul rune', 2).add('Chaos rune', 5), + cost: new Bank().add('Soul rune', 2).add('Chaos rune', 5).freeze(), charges: 1 }, unchargedItem: getOSItem("Tumeken's shadow (uncharged)"), @@ -173,13 +170,12 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Blood essence (active)'), settingsKey: 'blood_essence_charges', - run: () => { - return new Bank(); - }, + itemsToRefundOnBreak: new Bank().freeze(), + refundVariants: [], setup: 'skilling', aliases: ['blood essence'], chargeInput: { - cost: new Bank().add('Blood essence'), + cost: new Bank().add('Blood essence').freeze(), charges: 1000 }, emoji: '' @@ -187,19 +183,12 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Trident of the swamp'), settingsKey: 'trident_charges', - run: (user: MUser) => { - let unchargedItem: string = ''; - if (user.hasEquipped('Trident of the swamp')) { - unchargedItem = 'Uncharged toxic trident'; - } else { - unchargedItem = 'Uncharged trident'; - } - return new Bank().add(unchargedItem); - }, + itemsToRefundOnBreak: new Bank().add('Uncharged toxic trident').freeze(), + refundVariants: [], setup: 'mage', aliases: ['trident', 'trident of the swamp'], chargeInput: { - cost: new Bank().add('Death rune').add('Chaos rune').add('Fire rune', 5).add("Zulrah's scales"), + cost: new Bank().add('Death rune').add('Chaos rune').add('Fire rune', 5).add("Zulrah's scales").freeze(), charges: 1 }, unchargedItem: getOSItem('Uncharged toxic trident'), @@ -209,21 +198,21 @@ export const degradeableItems: DegradeableItem[] = [ { item: getOSItem('Scythe of vitur'), settingsKey: 'scythe_of_vitur_charges', - run: (user: MUser) => { - let unchargedItem: string = ''; - if (user.hasEquipped('Holy Scythe of vitur')) { - unchargedItem = 'Holy scythe of vitur (uncharged)'; - } else if (user.hasEquipped('Sanguine Scythe of vitur')) { - unchargedItem = 'Sanguine scythe of vitur (uncharged)'; - } else { - unchargedItem = 'Scythe of vitur (uncharged)'; + itemsToRefundOnBreak: new Bank().add('Scythe of vitur (uncharged)').freeze(), + refundVariants: [ + { + variant: getOSItem('Holy scythe of vitur'), + refund: new Bank().add('Holy scythe of vitur (uncharged)').freeze() + }, + { + variant: getOSItem('Sanguine scythe of vitur'), + refund: new Bank().add('Sanguine scythe of vitur (uncharged)').freeze() } - return new Bank().add(unchargedItem); - }, + ], setup: 'melee', aliases: ['scythe of vitur'], chargeInput: { - cost: new Bank().add('Blood rune', 300).add('Vial of blood'), + cost: new Bank().add('Blood rune', 300).add('Vial of blood').freeze(), charges: 100 }, unchargedItem: getOSItem('Scythe of vitur (uncharged)'), @@ -325,22 +314,28 @@ export async function degradeItem({ updateBankSetting('degraded_items_cost', itemsDeleted); if (hasEquipped) { - // If its equipped, give user new item, unequip old item and delete it. - const gear = { ...user.gear[degItem.setup].raw() }; - if (degItem.run !== undefined) { - const bankValue = degItem.run(user); - await user.addItemsToBank({ items: bankValue, collectionLog: false }); + // Get the users equipped item. + let refundItems = degItem.itemsToRefundOnBreak; + for (const variant of degItem.refundVariants) { + if (user.gear[degItem.setup].hasEquipped(variant.variant.id, false, false)) { + refundItems = variant.refund; + } } + // Unequip and delete the users item. + const gear = { ...user.gear[degItem.setup].raw() }; gear[item.equipment!.slot] = null; await user.update({ [`gear_${degItem.setup}`]: gear }); + // Give the user the uncharged version of their charged item. + await user.addItemsToBank({ items: refundItems, collectionLog: false }); } else if (hasInBank) { // If its in bank, just remove 1 from bank. - if (degItem.run !== undefined) { - const itemsToAdd = degItem.run(user); // Call the function to get the actual Bank value - await user.transactItems({ itemsToRemove: new Bank().add(item.id, 1), itemsToAdd }); + let itemsToAdd = undefined; + if (degItem.itemsToRefundOnBreak) { + itemsToAdd = degItem.itemsToRefundOnBreak; } + await user.transactItems({ itemsToRemove: new Bank().add(item.id, 1), itemsToAdd }); } else { // If its not in bank OR equipped, something weird has gone on. throw new Error( From c5cabd1fbbd36344b0a2519ffc2813ec10fa22f9 Mon Sep 17 00:00:00 2001 From: nwjgit Date: Wed, 11 Oct 2023 13:56:59 -0500 Subject: [PATCH 3/3] minor space adjustment --- src/lib/degradeableItems.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/degradeableItems.ts b/src/lib/degradeableItems.ts index 28e2e2a274..c97b4944c2 100644 --- a/src/lib/degradeableItems.ts +++ b/src/lib/degradeableItems.ts @@ -27,7 +27,6 @@ interface DegradeableItem { variant: Item; refund: Bank; }[]; - setup: GearSetupType; aliases: string[]; chargeInput: {