Skip to content

Commit

Permalink
Fix sell commands not working for generic unusuals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
purplebarber committed Oct 27, 2023
1 parent 60dec30 commit 4101d0f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/classes/Carts/UserCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions src/classes/Inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4101d0f

Please sign in to comment.