Skip to content

Commit

Permalink
🔀 Merge pull request #1683 from purplebarber/development
Browse files Browse the repository at this point in the history
fix sell commands not working for generic unusuals
  • Loading branch information
idinium96 authored Nov 2, 2023
2 parents 20da17e + 3552341 commit 13300a9
Show file tree
Hide file tree
Showing 2 changed files with 60 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, 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, elevatedStrange);
} else {
assetids = theirInventory.findBySKU(sku, true);
}

const addToDupeCheckList =
this.bot.pricelist
Expand Down
22 changes: 22 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';

Check warning on line 9 in src/classes/Inventory.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'log' is defined but never used

Check warning on line 9 in src/classes/Inventory.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'log' is defined but never used

export default class Inventory {
private readonly steamID: SteamID;
Expand Down Expand Up @@ -195,6 +196,27 @@ export default class Inventory {
return nonTradable.concat(tradable).slice(0);
}

findByPartialSku(partialSku: string, 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));
}
}
} else {
for (const sku in this.tradable) {
if (sku.startsWith(partialSku)) {
matchingSkus.push(...this.tradable[sku].map(item => item?.id));
}
}
}
return matchingSkus.slice(0);
}

getAmount({
priceKey,
includeNonNormalized,
Expand Down

0 comments on commit 13300a9

Please sign in to comment.