@ianlucas/cs2-lib 5.0.0-rc.17 → 5.0.0-rc.18
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.d.ts +9 -7
- package/dist/economy.js +24 -18
- package/dist/inventory.d.ts +5 -3
- package/dist/inventory.js +22 -16
- package/package.json +1 -1
package/dist/economy.d.ts
CHANGED
|
@@ -22,13 +22,13 @@ export declare class CS2EconomyInstance {
|
|
|
22
22
|
safeValidateWear(wear?: number, item?: CS2EconomyItem): boolean;
|
|
23
23
|
validateSeed(seed?: number, item?: CS2EconomyItem): boolean;
|
|
24
24
|
safeValidateSeed(seed?: number, item?: CS2EconomyItem): boolean;
|
|
25
|
-
trimNametag(
|
|
26
|
-
validateNametag(
|
|
27
|
-
safeValidateNametag(
|
|
28
|
-
requireNametag(
|
|
29
|
-
safeRequireNametag(
|
|
30
|
-
validateStatTrak(
|
|
31
|
-
safeValidateStatTrak(
|
|
25
|
+
trimNametag(nameTag?: string): string | undefined;
|
|
26
|
+
validateNametag(nameTag?: string, item?: CS2EconomyItem): boolean;
|
|
27
|
+
safeValidateNametag(nameTag?: string, item?: CS2EconomyItem): boolean;
|
|
28
|
+
requireNametag(nameTag?: string, item?: CS2EconomyItem): boolean;
|
|
29
|
+
safeRequireNametag(nameTag?: string, item?: CS2EconomyItem): boolean;
|
|
30
|
+
validateStatTrak(statTrak?: number, item?: CS2EconomyItem): boolean;
|
|
31
|
+
safeValidateStatTrak(statTrak?: number, item?: CS2EconomyItem): boolean;
|
|
32
32
|
getWearFromValue(value: number): CS2ItemWearValues;
|
|
33
33
|
getStickerCategories(): string[];
|
|
34
34
|
getStickers(): CS2EconomyItem[];
|
|
@@ -139,6 +139,8 @@ export declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents
|
|
|
139
139
|
isInContainers(): boolean;
|
|
140
140
|
isInDisplay(): boolean;
|
|
141
141
|
isHoldable(): boolean;
|
|
142
|
+
getMinimumWear(): number;
|
|
143
|
+
getMaximumWear(): number;
|
|
142
144
|
groupContents(): Record<string, CS2EconomyItem[]>;
|
|
143
145
|
listContents(hideSpecials?: boolean): CS2EconomyItem[];
|
|
144
146
|
unlockContainer(): CS2UnlockedItem;
|
package/dist/economy.js
CHANGED
|
@@ -80,38 +80,38 @@ export class CS2EconomyInstance {
|
|
|
80
80
|
safeValidateSeed(seed, item) {
|
|
81
81
|
return safe(() => this.validateSeed(seed, item));
|
|
82
82
|
}
|
|
83
|
-
trimNametag(
|
|
84
|
-
const trimmed =
|
|
83
|
+
trimNametag(nameTag) {
|
|
84
|
+
const trimmed = nameTag?.trim();
|
|
85
85
|
return trimmed === "" ? undefined : trimmed;
|
|
86
86
|
}
|
|
87
|
-
validateNametag(
|
|
88
|
-
if (
|
|
87
|
+
validateNametag(nameTag, item) {
|
|
88
|
+
if (nameTag !== undefined) {
|
|
89
89
|
assert(item === undefined || item.hasNametag());
|
|
90
|
-
assert(
|
|
90
|
+
assert(nameTag[0] !== " " && CS2_NAMETAG_RE.test(nameTag));
|
|
91
91
|
}
|
|
92
92
|
return true;
|
|
93
93
|
}
|
|
94
|
-
safeValidateNametag(
|
|
95
|
-
return safe(() => this.validateNametag(
|
|
94
|
+
safeValidateNametag(nameTag, item) {
|
|
95
|
+
return safe(() => this.validateNametag(nameTag, item));
|
|
96
96
|
}
|
|
97
|
-
requireNametag(
|
|
98
|
-
assert(
|
|
99
|
-
return this.validateNametag(
|
|
97
|
+
requireNametag(nameTag, item) {
|
|
98
|
+
assert(nameTag === undefined || nameTag.trim().length > 0);
|
|
99
|
+
return this.validateNametag(nameTag, item);
|
|
100
100
|
}
|
|
101
|
-
safeRequireNametag(
|
|
102
|
-
return safe(() => this.requireNametag(
|
|
101
|
+
safeRequireNametag(nameTag, item) {
|
|
102
|
+
return safe(() => this.requireNametag(nameTag, item));
|
|
103
103
|
}
|
|
104
|
-
validateStatTrak(
|
|
105
|
-
if (
|
|
104
|
+
validateStatTrak(statTrak, item) {
|
|
105
|
+
if (statTrak === undefined) {
|
|
106
106
|
return true;
|
|
107
107
|
}
|
|
108
108
|
assert(item === undefined || item.hasStatTrak());
|
|
109
|
-
assert(Number.isInteger(
|
|
110
|
-
assert(
|
|
109
|
+
assert(Number.isInteger(statTrak));
|
|
110
|
+
assert(statTrak >= CS2_MIN_STATTRAK && statTrak <= CS2_MAX_STATTRAK);
|
|
111
111
|
return true;
|
|
112
112
|
}
|
|
113
|
-
safeValidateStatTrak(
|
|
114
|
-
return safe(() => this.validateStatTrak(
|
|
113
|
+
safeValidateStatTrak(statTrak, item) {
|
|
114
|
+
return safe(() => this.validateStatTrak(statTrak, item));
|
|
115
115
|
}
|
|
116
116
|
getWearFromValue(value) {
|
|
117
117
|
switch (true) {
|
|
@@ -431,6 +431,12 @@ export class CS2EconomyItem {
|
|
|
431
431
|
isHoldable() {
|
|
432
432
|
return CS2_WEARABLE_ITEMS.includes(this.type);
|
|
433
433
|
}
|
|
434
|
+
getMinimumWear() {
|
|
435
|
+
return this.wearMin ?? CS2_MIN_WEAR;
|
|
436
|
+
}
|
|
437
|
+
getMaximumWear() {
|
|
438
|
+
return this.wearMax ?? CS2_MAX_WEAR;
|
|
439
|
+
}
|
|
434
440
|
groupContents() {
|
|
435
441
|
const items = {};
|
|
436
442
|
const specials = this.specials;
|
package/dist/inventory.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare class CS2Inventory {
|
|
|
56
56
|
add(item: CS2BaseInventoryItem): this;
|
|
57
57
|
private addInventoryItem;
|
|
58
58
|
addWithNametag(nameTagUid: number, id: number, nameTag: string): this;
|
|
59
|
-
addWithSticker(stickerUid: number, id: number,
|
|
59
|
+
addWithSticker(stickerUid: number, id: number, slot: number): this;
|
|
60
60
|
edit(itemUid: number, properties: Partial<CS2BaseInventoryItem>): this;
|
|
61
61
|
equip(itemUid: number, team?: CS2TeamValues): this;
|
|
62
62
|
unequip(uid: number, team?: CS2TeamValues): this;
|
|
@@ -71,8 +71,8 @@ export declare class CS2Inventory {
|
|
|
71
71
|
getStorageUnitItems(storageUid: number): CS2InventoryItem[];
|
|
72
72
|
depositToStorageUnit(storageUid: number, depositUids: number[]): this;
|
|
73
73
|
retrieveFromStorageUnit(storageUid: number, retrieveUids: number[]): this;
|
|
74
|
-
applyItemSticker(targetUid: number, stickerUid: number,
|
|
75
|
-
scrapeItemSticker(targetUid: number,
|
|
74
|
+
applyItemSticker(targetUid: number, stickerUid: number, slot: number): this;
|
|
75
|
+
scrapeItemSticker(targetUid: number, slot: number): this;
|
|
76
76
|
applyItemPatch(targetUid: number, patchUid: number, patchIndex: number): this;
|
|
77
77
|
removeItemPatch(targetUid: number, patchIndex: number): this;
|
|
78
78
|
incrementItemStatTrak(targetUid: number): this;
|
|
@@ -114,5 +114,7 @@ export declare class CS2InventoryItem extends CS2EconomyItem implements Interfac
|
|
|
114
114
|
allPatches(): [number, number | undefined][];
|
|
115
115
|
somePatches(): [number, number][];
|
|
116
116
|
getStickersCount(): number;
|
|
117
|
+
getWear(): number;
|
|
118
|
+
getStickerWear(slot: number): number;
|
|
117
119
|
asBase(): CS2BaseInventoryItem;
|
|
118
120
|
}
|
package/dist/inventory.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_MAX_PATCHES, CS2_MAX_STATTRAK, CS2_MAX_STICKERS, CS2_MAX_STICKER_WEAR, CS2_MAX_WEAR, CS2_MIN_STICKER_WEAR, CS2_STICKER_WEAR_FACTOR } from "./economy-constants.js";
|
|
5
|
+
import { CS2_MAX_PATCHES, CS2_MAX_STATTRAK, CS2_MAX_STICKERS, CS2_MAX_STICKER_WEAR, CS2_MAX_WEAR, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR, CS2_STICKER_WEAR_FACTOR } from "./economy-constants.js";
|
|
6
6
|
import { CS2ItemType } from "./economy-types.js";
|
|
7
7
|
import { CS2Economy, CS2EconomyItem } from "./economy.js";
|
|
8
8
|
import { resolveInventoryData } from "./inventory-upgrader.js";
|
|
@@ -132,12 +132,12 @@ export class CS2Inventory {
|
|
|
132
132
|
this.add({ id, nameTag });
|
|
133
133
|
return this;
|
|
134
134
|
}
|
|
135
|
-
addWithSticker(stickerUid, id,
|
|
135
|
+
addWithSticker(stickerUid, id, slot) {
|
|
136
136
|
const sticker = this.get(stickerUid).expectSticker();
|
|
137
137
|
this.items.delete(stickerUid);
|
|
138
138
|
this.add({
|
|
139
139
|
id,
|
|
140
|
-
stickers: { [
|
|
140
|
+
stickers: { [slot]: { id: sticker.id } }
|
|
141
141
|
});
|
|
142
142
|
return this;
|
|
143
143
|
}
|
|
@@ -274,27 +274,27 @@ export class CS2Inventory {
|
|
|
274
274
|
item.updatedAt = getTimestamp();
|
|
275
275
|
return this;
|
|
276
276
|
}
|
|
277
|
-
applyItemSticker(targetUid, stickerUid,
|
|
278
|
-
assert(
|
|
277
|
+
applyItemSticker(targetUid, stickerUid, slot) {
|
|
278
|
+
assert(slot >= 0 && slot <= CS2_MAX_STICKERS - 1);
|
|
279
279
|
const target = this.get(targetUid);
|
|
280
280
|
const sticker = this.get(stickerUid);
|
|
281
281
|
assert(target.hasStickers());
|
|
282
282
|
sticker.expectSticker();
|
|
283
283
|
target.stickers ??= new Map();
|
|
284
|
-
assert(target.stickers.get(
|
|
285
|
-
target.stickers.set(
|
|
284
|
+
assert(target.stickers.get(slot) === undefined);
|
|
285
|
+
target.stickers.set(slot, { id: sticker.id });
|
|
286
286
|
target.updatedAt = getTimestamp();
|
|
287
287
|
this.items.delete(stickerUid);
|
|
288
288
|
return this;
|
|
289
289
|
}
|
|
290
|
-
scrapeItemSticker(targetUid,
|
|
290
|
+
scrapeItemSticker(targetUid, slot) {
|
|
291
291
|
const target = this.get(targetUid);
|
|
292
292
|
assert(target.stickers !== undefined);
|
|
293
|
-
const sticker = ensure(target.stickers.get(
|
|
293
|
+
const sticker = ensure(target.stickers.get(slot));
|
|
294
294
|
const wear = sticker.wear ?? 0;
|
|
295
295
|
const nextWear = float(wear + CS2_STICKER_WEAR_FACTOR);
|
|
296
296
|
if (nextWear > CS2_MAX_WEAR) {
|
|
297
|
-
target.stickers.delete(
|
|
297
|
+
target.stickers.delete(slot);
|
|
298
298
|
if (target.stickers.size === 0) {
|
|
299
299
|
target.stickers = undefined;
|
|
300
300
|
}
|
|
@@ -399,18 +399,18 @@ export class CS2InventoryItem extends CS2EconomyItem {
|
|
|
399
399
|
wear;
|
|
400
400
|
assign({ patches, stickers, storage }) {
|
|
401
401
|
if (patches !== undefined) {
|
|
402
|
-
this.patches = new Map(Object.entries(patches).map(([key,
|
|
402
|
+
this.patches = new Map(Object.entries(patches).map(([key, value]) => [parseInt(key, 10), value]));
|
|
403
403
|
}
|
|
404
404
|
if (stickers !== undefined) {
|
|
405
|
-
this.stickers = new Map(Object.entries(stickers).map(([key,
|
|
405
|
+
this.stickers = new Map(Object.entries(stickers).map(([key, value]) => [parseInt(key, 10), value]));
|
|
406
406
|
}
|
|
407
407
|
if (storage !== undefined) {
|
|
408
408
|
assert(this.isStorageUnit());
|
|
409
|
-
this.storage = new Map(Object.entries(storage).map(([key,
|
|
410
|
-
const storedEconomyItem = this.economy.getById(
|
|
411
|
-
assert(
|
|
409
|
+
this.storage = new Map(Object.entries(storage).map(([key, value]) => {
|
|
410
|
+
const storedEconomyItem = this.economy.getById(value.id);
|
|
411
|
+
assert(value.storage === undefined);
|
|
412
412
|
const uid = parseInt(key, 10);
|
|
413
|
-
return [uid, new CS2InventoryItem(this.inventory, uid,
|
|
413
|
+
return [uid, new CS2InventoryItem(this.inventory, uid, value, storedEconomyItem)];
|
|
414
414
|
}));
|
|
415
415
|
}
|
|
416
416
|
}
|
|
@@ -453,6 +453,12 @@ export class CS2InventoryItem extends CS2EconomyItem {
|
|
|
453
453
|
getStickersCount() {
|
|
454
454
|
return this.stickers?.size ?? 0;
|
|
455
455
|
}
|
|
456
|
+
getWear() {
|
|
457
|
+
return this.wear ?? this.wearMin ?? CS2_MIN_WEAR;
|
|
458
|
+
}
|
|
459
|
+
getStickerWear(slot) {
|
|
460
|
+
return this.stickers?.get(slot)?.wear ?? 0;
|
|
461
|
+
}
|
|
456
462
|
asBase() {
|
|
457
463
|
return {
|
|
458
464
|
containerId: this.containerId,
|