@ianlucas/cs2-lib 5.0.0-rc.21 → 5.0.0-rc.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/economy-constants.d.ts +1 -1
- package/dist/economy-constants.js +1 -1
- package/dist/economy.d.ts +1 -1
- package/dist/economy.js +9 -5
- package/dist/inventory.d.ts +1 -0
- package/dist/inventory.js +20 -6
- package/package.json +1 -1
|
@@ -33,7 +33,7 @@ export declare const CS2_NAMETAGGABLE_ITEMS: CS2ItemTypeValues[];
|
|
|
33
33
|
export declare const CS2_SEEDABLE_ITEMS: CS2ItemTypeValues[];
|
|
34
34
|
export declare const CS2_STATTRAKABLE_ITEMS: CS2ItemTypeValues[];
|
|
35
35
|
export declare const CS2_STICKERABLE_ITEMS: CS2ItemTypeValues[];
|
|
36
|
-
export declare const
|
|
36
|
+
export declare const CS2_PAINTABLE_ITEMS: CS2ItemTypeValues[];
|
|
37
37
|
export declare const CS2_EQUIPMENT_ITEMS: CS2ItemTypeValues[];
|
|
38
38
|
export declare const CS2_GRAPHIC_ART_ITEMS: CS2ItemTypeValues[];
|
|
39
39
|
export declare const CS2_CONTAINER_ITEMS: CS2ItemTypeValues[];
|
|
@@ -37,7 +37,7 @@ export const CS2_NAMETAGGABLE_ITEMS = [CS2ItemType.Melee, CS2ItemType.Weapon];
|
|
|
37
37
|
export const CS2_SEEDABLE_ITEMS = [CS2ItemType.Weapon, CS2ItemType.Melee, CS2ItemType.Gloves];
|
|
38
38
|
export const CS2_STATTRAKABLE_ITEMS = [CS2ItemType.Melee, CS2ItemType.Weapon, CS2ItemType.MusicKit];
|
|
39
39
|
export const CS2_STICKERABLE_ITEMS = [CS2ItemType.Weapon];
|
|
40
|
-
export const
|
|
40
|
+
export const CS2_PAINTABLE_ITEMS = [CS2ItemType.Gloves, CS2ItemType.Melee, CS2ItemType.Weapon];
|
|
41
41
|
export const CS2_EQUIPMENT_ITEMS = [CS2ItemType.Weapon, CS2ItemType.Agent, CS2ItemType.Gloves, CS2ItemType.Melee, CS2ItemType.MusicKit];
|
|
42
42
|
export const CS2_GRAPHIC_ART_ITEMS = [CS2ItemType.Patch, CS2ItemType.Sticker, CS2ItemType.Graffiti];
|
|
43
43
|
export const CS2_CONTAINER_ITEMS = [CS2ItemType.Container, CS2ItemType.Tool];
|
package/dist/economy.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ export declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents
|
|
|
138
138
|
isInGraphicArts(): boolean;
|
|
139
139
|
isInContainers(): boolean;
|
|
140
140
|
isInDisplay(): boolean;
|
|
141
|
-
|
|
141
|
+
isPaintable(): boolean;
|
|
142
142
|
getMinimumWear(): number;
|
|
143
143
|
getMaximumWear(): number;
|
|
144
144
|
groupContents(): Record<string, CS2EconomyItem[]>;
|
package/dist/economy.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Ian Lucas. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import { CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEF, CS2_DISPLAY_ITEMS, CS2_EQUIPMENT_ITEMS, CS2_GRAPHIC_ART_ITEMS, CS2_MACHINEGUN_MODELS, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_SEED, CS2_MAX_STATTRAK, CS2_MAX_WEAR, CS2_MAX_WELL_WORN_WEAR, CS2_MIDTIER_CATEGORIES, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_WEAR, CS2_MISC_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_RIFLE_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODELS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_SWAP_TOOL_DEF, CS2_STICKERABLE_ITEMS, CS2_STORAGE_UNIT_TOOL_DEF, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T,
|
|
5
|
+
import { CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEF, CS2_DISPLAY_ITEMS, CS2_EQUIPMENT_ITEMS, CS2_GRAPHIC_ART_ITEMS, CS2_MACHINEGUN_MODELS, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_SEED, CS2_MAX_STATTRAK, CS2_MAX_WEAR, CS2_MAX_WELL_WORN_WEAR, CS2_MIDTIER_CATEGORIES, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_WEAR, CS2_MISC_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_PAINTABLE_ITEMS, CS2_RIFLE_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODELS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_SWAP_TOOL_DEF, CS2_STICKERABLE_ITEMS, CS2_STORAGE_UNIT_TOOL_DEF, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_WEAR_FACTOR } from "./economy-constants.js";
|
|
6
6
|
import { CS2RarityColorName, CS2RarityColorOrder, CS2RaritySoundName, CS2_BASE_ODD, CS2_RARITY_COLOR_DEFAULT, CS2_RARITY_ORDER, CS2_STATTRAK_ODD, randomFloat, randomInt } from "./economy-container.js";
|
|
7
7
|
import { CS2ContainerType, CS2ItemTeam, CS2ItemType, CS2ItemWear } from "./economy-types.js";
|
|
8
8
|
import { assert, compare, ensure, safe } from "./utils.js";
|
|
@@ -243,7 +243,11 @@ export class CS2EconomyItem {
|
|
|
243
243
|
return ensure(this._contents).map((id) => this.economy.get(id));
|
|
244
244
|
}
|
|
245
245
|
get parent() {
|
|
246
|
-
return this.baseId !== undefined
|
|
246
|
+
return this.baseId !== undefined
|
|
247
|
+
? this.economy.items.has(this.baseId)
|
|
248
|
+
? this.economy.get(this.baseId)
|
|
249
|
+
: undefined
|
|
250
|
+
: undefined;
|
|
247
251
|
}
|
|
248
252
|
get rawContents() {
|
|
249
253
|
return this._contents;
|
|
@@ -390,7 +394,7 @@ export class CS2EconomyItem {
|
|
|
390
394
|
return this;
|
|
391
395
|
}
|
|
392
396
|
hasWear() {
|
|
393
|
-
return
|
|
397
|
+
return CS2_PAINTABLE_ITEMS.includes(this.type) && !this.free && this.index !== 0;
|
|
394
398
|
}
|
|
395
399
|
hasSeed() {
|
|
396
400
|
return CS2_SEEDABLE_ITEMS.includes(this.type) && !this.free && this.index !== 0;
|
|
@@ -428,8 +432,8 @@ export class CS2EconomyItem {
|
|
|
428
432
|
isInDisplay() {
|
|
429
433
|
return CS2_DISPLAY_ITEMS.includes(this.type);
|
|
430
434
|
}
|
|
431
|
-
|
|
432
|
-
return
|
|
435
|
+
isPaintable() {
|
|
436
|
+
return CS2_PAINTABLE_ITEMS.includes(this.type);
|
|
433
437
|
}
|
|
434
438
|
getMinimumWear() {
|
|
435
439
|
return this.wearMin ?? CS2_MIN_WEAR;
|
package/dist/inventory.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export declare class CS2Inventory {
|
|
|
45
45
|
readonly options: Readonly<CS2InventoryOptions>;
|
|
46
46
|
static parse(stringValue: string | undefined | null, economy?: CS2EconomyInstance): CS2InventoryData | undefined;
|
|
47
47
|
constructor({ economy, data, maxItems, storageUnitMaxItems }?: Partial<CS2InventorySpec>);
|
|
48
|
+
private validateAddable;
|
|
48
49
|
private validateStickers;
|
|
49
50
|
private validatePatches;
|
|
50
51
|
validateBaseInventoryItem({ id, nameTag, patches, seed, statTrak, stickers, wear }: CS2BaseInventoryItem): void;
|
package/dist/inventory.js
CHANGED
|
@@ -39,6 +39,11 @@ export class CS2Inventory {
|
|
|
39
39
|
storageUnitMaxItems: storageUnitMaxItems ?? 32
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
+
validateAddable(item) {
|
|
43
|
+
if (item.isGloves()) {
|
|
44
|
+
assert(item.free || !item.base);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
42
47
|
validateStickers(stickers, item) {
|
|
43
48
|
if (stickers === undefined) {
|
|
44
49
|
return;
|
|
@@ -74,11 +79,14 @@ export class CS2Inventory {
|
|
|
74
79
|
this.economy.validateSeed(seed, item);
|
|
75
80
|
this.economy.validateNametag(nameTag, item);
|
|
76
81
|
this.economy.validateStatTrak(statTrak, item);
|
|
82
|
+
this.validateAddable(item);
|
|
77
83
|
this.validatePatches(patches, item);
|
|
78
84
|
this.validateStickers(stickers, item);
|
|
79
85
|
}
|
|
80
86
|
toInventoryItems(items) {
|
|
81
|
-
return new Map(Object.entries(items)
|
|
87
|
+
return new Map(Object.entries(items)
|
|
88
|
+
.filter(([, { id }]) => this.economy.items.has(id))
|
|
89
|
+
.map(([key, value]) => {
|
|
82
90
|
const uid = parseInt(key, 10);
|
|
83
91
|
return [uid, new CS2InventoryItem(this, uid, value, this.economy.getById(value.id))];
|
|
84
92
|
}));
|
|
@@ -393,18 +401,24 @@ export class CS2InventoryItem extends CS2EconomyItem {
|
|
|
393
401
|
wear;
|
|
394
402
|
assign({ patches, stickers, storage }) {
|
|
395
403
|
if (patches !== undefined) {
|
|
396
|
-
this.patches = new Map(Object.entries(patches)
|
|
404
|
+
this.patches = new Map(Object.entries(patches)
|
|
405
|
+
.filter(([, patchId]) => this.economy.items.has(patchId))
|
|
406
|
+
.map(([slot, patchId]) => [parseInt(slot, 10), patchId]));
|
|
397
407
|
}
|
|
398
408
|
if (stickers !== undefined) {
|
|
399
|
-
this.stickers = new Map(Object.entries(stickers)
|
|
409
|
+
this.stickers = new Map(Object.entries(stickers)
|
|
410
|
+
.filter(([, sticker]) => this.economy.items.has(sticker.id))
|
|
411
|
+
.map(([slot, sticker]) => [parseInt(slot, 10), sticker]));
|
|
400
412
|
}
|
|
401
413
|
if (storage !== undefined) {
|
|
402
414
|
assert(this.isStorageUnit());
|
|
403
|
-
this.storage = new Map(Object.entries(storage)
|
|
404
|
-
|
|
415
|
+
this.storage = new Map(Object.entries(storage)
|
|
416
|
+
.filter(([, { id }]) => this.economy.items.has(id))
|
|
417
|
+
.map(([key, value]) => {
|
|
418
|
+
const economyItem = this.economy.getById(value.id);
|
|
405
419
|
assert(value.storage === undefined);
|
|
406
420
|
const uid = parseInt(key, 10);
|
|
407
|
-
return [uid, new CS2InventoryItem(this.inventory, uid, value,
|
|
421
|
+
return [uid, new CS2InventoryItem(this.inventory, uid, value, economyItem)];
|
|
408
422
|
}));
|
|
409
423
|
}
|
|
410
424
|
}
|