From 4101d0f1e9acfd7ebf255367a03b9c0d99ba1964 Mon Sep 17 00:00:00 2001 From: Purple <87976511+purplebarber@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:02:48 +0800 Subject: [PATCH] Fix sell commands not working for generic unusuals Add findByPartialSku() for Inventory.ts which is called when an unusual object has no effect. Is called when searching for generic unusuals in other player's inventory. --- src/classes/Carts/UserCart.ts | 42 +++++++++++++++++++++++++++++++---- src/classes/Inventory.ts | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/classes/Carts/UserCart.ts b/src/classes/Carts/UserCart.ts index 1adadb43e..aba9f8722 100644 --- a/src/classes/Carts/UserCart.ts +++ b/src/classes/Carts/UserCart.ts @@ -514,15 +514,34 @@ export default class UserCart extends Cart { }; // Add their items - for (const sku in this.their) { + for (let sku in this.their) { if (!Object.prototype.hasOwnProperty.call(this.their, sku)) { continue; } - let alteredMessage: string; + let findByPartialSku = false; + let elevatedStrange = false; + const item_object = SKU.fromString(sku); + if (item_object.quality == 5 && !item_object.effect) { + log.debug('Generic Unusual in their cart, finding by partial sku'); + findByPartialSku = true; + if (item_object.quality2 == 11) { + elevatedStrange = true; + } + } + let theirAssetids: string[]; let amount = this.getTheirCount(sku); - const theirAssetids = theirInventory.findBySKU(sku, true); + if (findByPartialSku) { + theirAssetids = theirInventory.findByPartialSku(sku, true, elevatedStrange); + if (theirAssetids.length > 0) { + sku = theirInventory.findByAssetid(theirAssetids[0]); + } + } else { + theirAssetids = theirInventory.findBySKU(sku, true); + } + + let alteredMessage: string; const theirAssetidsCount = theirAssetids.length; if (amount > theirAssetidsCount) { @@ -745,8 +764,23 @@ export default class UserCart extends Cart { continue; } + const item_object = SKU.fromString(sku); + let findByPartialSku = false; + let elevatedStrange = false; + if (item_object.quality == 5 && !item_object.effect) { + findByPartialSku = true; + if (item_object.quality2 == 11) { + elevatedStrange = true; + } + } + + let assetids: string[]; const amount = this.their[sku]; - let assetids = theirInventory.findBySKU(sku, true); + if (findByPartialSku) { + assetids = theirInventory.findByPartialSku(sku, true, elevatedStrange); + } else { + assetids = theirInventory.findBySKU(sku, true); + } const addToDupeCheckList = this.bot.pricelist diff --git a/src/classes/Inventory.ts b/src/classes/Inventory.ts index 166bdfe03..5ccb62d10 100644 --- a/src/classes/Inventory.ts +++ b/src/classes/Inventory.ts @@ -6,6 +6,7 @@ import { HighValue } from './Options'; import Bot from './Bot'; import { noiseMakers, spellsData, killstreakersData, sheensData } from '../lib/data'; import Pricelist from './Pricelist'; +import log from '../lib/logger'; export default class Inventory { private readonly steamID: SteamID; @@ -195,6 +196,44 @@ export default class Inventory { return nonTradable.concat(tradable).slice(0); } + findByPartialSku(partialSku: string, tradableOnly = true, elevatedStrange = false): string[] { + const matchingSkus: string[] = []; + + if (elevatedStrange) { + partialSku = partialSku.replace(';strange', ''); + + for (const sku in this.tradable) { + if (sku.startsWith(partialSku) && sku.includes(';strange')) { + matchingSkus.push(...this.tradable[sku].map(item => item?.id)); + } + } + + if (!tradableOnly) { + for (const sku in this.nonTradable) { + if (sku.startsWith(partialSku) && sku.includes(';strange')) { + matchingSkus.push(...this.nonTradable[sku].map(item => item?.id)); + } + } + } + + } else { + for (const sku in this.tradable) { + if (sku.startsWith(partialSku)) { + matchingSkus.push(...this.tradable[sku].map(item => item?.id)); + } + } + + if (!tradableOnly) { + for (const sku in this.nonTradable) { + if (sku.startsWith(partialSku)) { + matchingSkus.push(...this.nonTradable[sku].map(item => item?.id)); + } + } + } + } + return matchingSkus.slice(0); + } + getAmount({ priceKey, includeNonNormalized,