@ianlucas/cs2-lib 5.0.0-rc.15 → 5.0.0-rc.16

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.
@@ -25,6 +25,7 @@ export declare const CS2_MAX_PATCHES = 5;
25
25
  export declare const CS2_STICKER_WEAR_FACTOR = 0.1;
26
26
  export declare const CS2_WEAR_FACTOR = 0.000001;
27
27
  export declare const CS2_NAMETAG_RE: RegExp;
28
+ export declare const CS2_CONTRACT_TOOL_DEF = 62;
28
29
  export declare const CS2_NAMETAG_TOOL_DEF = 1200;
29
30
  export declare const CS2_STATTRAK_SWAP_TOOL_DEF = 1324;
30
31
  export declare const CS2_STORAGE_UNIT_TOOL_DEF = 1201;
@@ -33,7 +34,15 @@ export declare const CS2_SEEDABLE_ITEMS: CS2ItemTypeValues[];
33
34
  export declare const CS2_STATTRAKABLE_ITEMS: CS2ItemTypeValues[];
34
35
  export declare const CS2_STICKERABLE_ITEMS: CS2ItemTypeValues[];
35
36
  export declare const CS2_WEARABLE_ITEMS: CS2ItemTypeValues[];
36
- export declare const CS2_CONTAINER_OR_TOOL_ITEM: CS2ItemTypeValues[];
37
+ export declare const CS2_EQUIPMENT_ITEMS: CS2ItemTypeValues[];
38
+ export declare const CS2_GRAPHIC_ART_ITEMS: CS2ItemTypeValues[];
39
+ export declare const CS2_CONTAINER_ITEMS: CS2ItemTypeValues[];
40
+ export declare const CS2_DISPLAY_ITEMS: CS2ItemTypeValues[];
41
+ export declare const CS2_MIDTIER_CATEGORIES: string[];
42
+ export declare const CS2_RIFLE_CATEGORIES: string[];
43
+ export declare const CS2_MISC_CATEGORIES: string[];
44
+ export declare const CS2_SNIPER_RIFLE_MODELS: string[];
45
+ export declare const CS2_MACHINEGUN_MODELS: string[];
37
46
  export declare const CS2_TEAMS_BOTH: CS2TeamValues[];
38
47
  export declare const CS2_TEAMS_CT: CS2TeamValues[];
39
48
  export declare const CS2_TEAMS_T: CS2TeamValues[];
@@ -29,6 +29,7 @@ export const CS2_MAX_PATCHES = 5;
29
29
  export const CS2_STICKER_WEAR_FACTOR = 0.1;
30
30
  export const CS2_WEAR_FACTOR = 0.000001;
31
31
  export const CS2_NAMETAG_RE = /^[A-Za-z0-9`!@#$%^&*-+=(){}\[\]\/\|\\,.?:;'_\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\s]{0,20}$/u;
32
+ export const CS2_CONTRACT_TOOL_DEF = 62;
32
33
  export const CS2_NAMETAG_TOOL_DEF = 1200;
33
34
  export const CS2_STATTRAK_SWAP_TOOL_DEF = 1324;
34
35
  export const CS2_STORAGE_UNIT_TOOL_DEF = 1201;
@@ -37,7 +38,15 @@ export const CS2_SEEDABLE_ITEMS = [CS2ItemType.Weapon, CS2ItemType.Melee, CS2Ite
37
38
  export const CS2_STATTRAKABLE_ITEMS = [CS2ItemType.Melee, CS2ItemType.Weapon, CS2ItemType.MusicKit];
38
39
  export const CS2_STICKERABLE_ITEMS = [CS2ItemType.Weapon];
39
40
  export const CS2_WEARABLE_ITEMS = [CS2ItemType.Gloves, CS2ItemType.Melee, CS2ItemType.Weapon];
40
- export const CS2_CONTAINER_OR_TOOL_ITEM = [CS2ItemType.Container, CS2ItemType.Tool];
41
+ export const CS2_EQUIPMENT_ITEMS = [CS2ItemType.Weapon, CS2ItemType.Agent, CS2ItemType.Gloves, CS2ItemType.Melee, CS2ItemType.MusicKit];
42
+ export const CS2_GRAPHIC_ART_ITEMS = [CS2ItemType.Patch, CS2ItemType.Sticker, CS2ItemType.Graffiti];
43
+ export const CS2_CONTAINER_ITEMS = [CS2ItemType.Container, CS2ItemType.Tool];
44
+ export const CS2_DISPLAY_ITEMS = [CS2ItemType.Collectible, CS2ItemType.MusicKit];
45
+ export const CS2_MIDTIER_CATEGORIES = ["heavy", "smg"];
46
+ export const CS2_RIFLE_CATEGORIES = ["rifle"];
47
+ export const CS2_MISC_CATEGORIES = ["c4", "equipment"];
48
+ export const CS2_SNIPER_RIFLE_MODELS = ["awp", "g3sg1", "scar20", "ssg08"];
49
+ export const CS2_MACHINEGUN_MODELS = ["m249", "negev"];
41
50
  export const CS2_TEAMS_BOTH = [CS2Team.T, CS2Team.CT];
42
51
  export const CS2_TEAMS_CT = [CS2Team.CT];
43
52
  export const CS2_TEAMS_T = [CS2Team.T];
package/dist/economy.d.ts CHANGED
@@ -89,19 +89,34 @@ export declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents
89
89
  get specials(): CS2EconomyItem[] | undefined;
90
90
  set teams(value: CS2ItemTeamValues);
91
91
  get teams(): CS2TeamValues[] | undefined;
92
- isStub(): boolean;
93
92
  isC4(): boolean;
93
+ isPistol(): boolean;
94
+ isSMG(): boolean;
95
+ isRifle(): boolean;
96
+ isSniperRifle(): boolean;
97
+ isMachinegun(): boolean;
98
+ isHeavy(): boolean;
99
+ isEquipment(): boolean;
100
+ isInMidTiers(): boolean;
101
+ isInRifles(): boolean;
102
+ isInMisc(): boolean;
94
103
  isAgent(): boolean;
95
- isSticker(): boolean;
96
- isPatch(): boolean;
104
+ isCollectible(): boolean;
105
+ isContainer(): boolean;
106
+ isContainerKey(): boolean;
97
107
  isGloves(): boolean;
108
+ isGraffiti(): boolean;
109
+ isMelee(): boolean;
110
+ isMusicKit(): boolean;
111
+ isPatch(): boolean;
112
+ isSticker(): boolean;
113
+ isStub(): boolean;
114
+ isTool(): boolean;
115
+ isWeapon(): boolean;
98
116
  isStorageUnit(): boolean;
99
117
  isNameTag(): boolean;
100
118
  isStatTrakSwapTool(): boolean;
101
- isContainer(): boolean;
102
- isContainerKey(): boolean;
103
- isContainerOrTool(): boolean;
104
- isTool(): boolean;
119
+ isContract(): boolean;
105
120
  expectAgent(): this;
106
121
  expectPatch(): this;
107
122
  expectSticker(): this;
@@ -119,6 +134,11 @@ export declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents
119
134
  isStickerCapsule(): boolean;
120
135
  isGraffitiBox(): boolean;
121
136
  isSouvenirCase(): boolean;
137
+ isInEquipments(): boolean;
138
+ isInGraphicArts(): boolean;
139
+ isInContainers(): boolean;
140
+ isInDisplay(): boolean;
141
+ isHoldable(): boolean;
122
142
  groupContents(): Record<string, CS2EconomyItem[]>;
123
143
  listContents(hideSpecials?: boolean): CS2EconomyItem[];
124
144
  unlockContainer(): CS2UnlockedItem;
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_OR_TOOL_ITEM, 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_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_WEAR, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_SEEDABLE_ITEMS, 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_WEARABLE_ITEMS, CS2_WEAR_FACTOR } from "./economy-constants.js";
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, CS2_WEARABLE_ITEMS, 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";
@@ -273,32 +273,44 @@ export class CS2EconomyItem {
273
273
  return undefined;
274
274
  }
275
275
  }
276
- isStub() {
277
- return this.type === CS2ItemType.Stub;
278
- }
279
276
  isC4() {
280
277
  return this.category === "c4";
281
278
  }
282
- isAgent() {
283
- return this.type === CS2ItemType.Agent;
279
+ isPistol() {
280
+ return this.category === "secondary";
284
281
  }
285
- isSticker() {
286
- return this.type === CS2ItemType.Sticker;
282
+ isSMG() {
283
+ return this.category === "smg";
287
284
  }
288
- isPatch() {
289
- return this.type === CS2ItemType.Patch;
285
+ isRifle() {
286
+ return this.category === "rifle";
290
287
  }
291
- isGloves() {
292
- return this.type === CS2ItemType.Gloves;
288
+ isSniperRifle() {
289
+ return CS2_SNIPER_RIFLE_MODELS.includes(ensure(this.model));
293
290
  }
294
- isStorageUnit() {
295
- return this.type === CS2ItemType.Tool && this.def === CS2_STORAGE_UNIT_TOOL_DEF;
291
+ isMachinegun() {
292
+ return CS2_MACHINEGUN_MODELS.includes(ensure(this.model));
296
293
  }
297
- isNameTag() {
298
- return this.type === CS2ItemType.Tool && this.def === CS2_NAMETAG_TOOL_DEF;
294
+ isHeavy() {
295
+ return this.category === "heavy";
299
296
  }
300
- isStatTrakSwapTool() {
301
- return this.type === CS2ItemType.Tool && this.def === CS2_STATTRAK_SWAP_TOOL_DEF;
297
+ isEquipment() {
298
+ return this.category === "equipment";
299
+ }
300
+ isInMidTiers() {
301
+ return CS2_MIDTIER_CATEGORIES.includes(ensure(this.category));
302
+ }
303
+ isInRifles() {
304
+ return CS2_RIFLE_CATEGORIES.includes(ensure(this.category));
305
+ }
306
+ isInMisc() {
307
+ return CS2_MISC_CATEGORIES.includes(ensure(this.category));
308
+ }
309
+ isAgent() {
310
+ return this.type === CS2ItemType.Agent;
311
+ }
312
+ isCollectible() {
313
+ return this.type === CS2ItemType.Collectible;
302
314
  }
303
315
  isContainer() {
304
316
  return this.type === CS2ItemType.Container;
@@ -306,12 +318,45 @@ export class CS2EconomyItem {
306
318
  isContainerKey() {
307
319
  return this.type === CS2ItemType.ContainerKey;
308
320
  }
309
- isContainerOrTool() {
310
- return CS2_CONTAINER_OR_TOOL_ITEM.includes(this.type);
321
+ isGloves() {
322
+ return this.type === CS2ItemType.Gloves;
323
+ }
324
+ isGraffiti() {
325
+ return this.type === CS2ItemType.Graffiti;
326
+ }
327
+ isMelee() {
328
+ return this.type === CS2ItemType.Melee;
329
+ }
330
+ isMusicKit() {
331
+ return this.type === CS2ItemType.MusicKit;
332
+ }
333
+ isPatch() {
334
+ return this.type === CS2ItemType.Patch;
335
+ }
336
+ isSticker() {
337
+ return this.type === CS2ItemType.Sticker;
338
+ }
339
+ isStub() {
340
+ return this.type === CS2ItemType.Stub;
311
341
  }
312
342
  isTool() {
313
343
  return this.type === CS2ItemType.Tool;
314
344
  }
345
+ isWeapon() {
346
+ return this.type === CS2ItemType.Weapon;
347
+ }
348
+ isStorageUnit() {
349
+ return this.isTool() && this.def === CS2_STORAGE_UNIT_TOOL_DEF;
350
+ }
351
+ isNameTag() {
352
+ return this.isTool() && this.def === CS2_NAMETAG_TOOL_DEF;
353
+ }
354
+ isStatTrakSwapTool() {
355
+ return this.isTool() && this.def === CS2_STATTRAK_SWAP_TOOL_DEF;
356
+ }
357
+ isContract() {
358
+ return this.isTool() && this.def === CS2_CONTRACT_TOOL_DEF;
359
+ }
315
360
  expectAgent() {
316
361
  assert(this.isAgent());
317
362
  return this;
@@ -371,6 +416,21 @@ export class CS2EconomyItem {
371
416
  isSouvenirCase() {
372
417
  return this.containerType === CS2ContainerType.SouvenirCase;
373
418
  }
419
+ isInEquipments() {
420
+ return CS2_EQUIPMENT_ITEMS.includes(this.type);
421
+ }
422
+ isInGraphicArts() {
423
+ return CS2_GRAPHIC_ART_ITEMS.includes(this.type);
424
+ }
425
+ isInContainers() {
426
+ return CS2_CONTAINER_ITEMS.includes(this.type);
427
+ }
428
+ isInDisplay() {
429
+ return CS2_DISPLAY_ITEMS.includes(this.type);
430
+ }
431
+ isHoldable() {
432
+ return CS2_WEARABLE_ITEMS.includes(this.type);
433
+ }
374
434
  groupContents() {
375
435
  const items = {};
376
436
  const specials = this.specials;
package/dist/inventory.js CHANGED
@@ -162,8 +162,7 @@ export class CS2Inventory {
162
162
  otherItem.equippedT = team === CS2Team.T ? true : otherItem.equippedT;
163
163
  }
164
164
  else {
165
- if (otherItem.type === item.type &&
166
- (item.type !== CS2ItemType.Weapon || otherItem.model === item.model)) {
165
+ if (otherItem.type === item.type && (!item.isWeapon() || otherItem.model === item.model)) {
167
166
  otherItem.equipped = team === undefined ? undefined : otherItem.equipped;
168
167
  otherItem.equippedCT = team === CS2Team.CT ? undefined : otherItem.equippedCT;
169
168
  otherItem.equippedT = team === CS2Team.T ? undefined : otherItem.equippedT;
@@ -343,7 +342,7 @@ export class CS2Inventory {
343
342
  const toItem = this.get(toUid);
344
343
  assert(fromItem.statTrak !== undefined && toItem.statTrak !== undefined);
345
344
  assert(fromItem.type === toItem.type);
346
- assert(fromItem.type === CS2ItemType.MusicKit || fromItem.def === toItem.def);
345
+ assert(fromItem.isMusicKit() || fromItem.def === toItem.def);
347
346
  const fromStattrak = fromItem.statTrak;
348
347
  fromItem.statTrak = toItem.statTrak;
349
348
  fromItem.updatedAt = getTimestamp();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ianlucas/cs2-lib",
3
- "version": "5.0.0-rc.15",
3
+ "version": "5.0.0-rc.16",
4
4
  "description": "A TypeScript library for manipulating Counter-Strike 2 data",
5
5
  "license": "MIT",
6
6
  "author": "Ian Lucas",