@ianlucas/cs2-lib 8.0.0-rc.4 → 8.0.0-rc.6
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.mts +3 -1
- package/dist/economy-constants.mjs +1 -1
- package/dist/economy-types.d.mts +12 -2
- package/dist/economy.d.mts +20 -3
- package/dist/economy.mjs +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/inventory.d.mts +24 -4
- package/dist/inventory.mjs +1 -1
- package/dist/items.mjs +1 -1
- package/dist/utils.d.mts +6 -1
- package/dist/utils.mjs +1 -1
- package/package.json +2 -2
|
@@ -30,6 +30,8 @@ declare const CS2_MAX_STICKERS = 5;
|
|
|
30
30
|
declare const CS2_MAX_PATCHES = 5;
|
|
31
31
|
declare const CS2_MAX_KEYCHAINS = 1;
|
|
32
32
|
declare const CS2_STICKER_WEAR_FACTOR = .01;
|
|
33
|
+
declare const CS2_STICKER_SCRAPE_FACTOR = .1;
|
|
34
|
+
declare const CS2_STICKER_OFFSET_FACTOR = 1e-4;
|
|
33
35
|
declare const CS2_WEAR_FACTOR = 1e-6;
|
|
34
36
|
declare const CS2_NAMETAG_RE: RegExp;
|
|
35
37
|
declare const CS2_CONTRACT_TOOL_DEF = 62;
|
|
@@ -56,4 +58,4 @@ declare const CS2_TEAMS_BOTH: CS2Team[];
|
|
|
56
58
|
declare const CS2_TEAMS_CT: CS2Team[];
|
|
57
59
|
declare const CS2_TEAMS_T: CS2Team[];
|
|
58
60
|
//#endregion
|
|
59
|
-
export { CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEF, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_EQUIPMENT_ITEMS, CS2_GRAPHIC_ART_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_MACHINEGUN_MODELS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_SEED, CS2_MAX_STATTRAK, CS2_MAX_STICKERS, CS2_MAX_STICKER_ROTATION, CS2_MAX_STICKER_WEAR, CS2_MAX_WEAR, CS2_MAX_WELL_WORN_WEAR, CS2_MIDTIER_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_STICKER_ROTATION, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR, CS2_MIN_WELL_WORN_WEAR, CS2_MISC_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_RIFLE_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODELS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_SWAP_TOOL_DEF, CS2_STICKERABLE_ITEMS, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEF, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_WEAR_FACTOR };
|
|
61
|
+
export { CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEF, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_EQUIPMENT_ITEMS, CS2_GRAPHIC_ART_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_MACHINEGUN_MODELS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_SEED, CS2_MAX_STATTRAK, CS2_MAX_STICKERS, CS2_MAX_STICKER_ROTATION, CS2_MAX_STICKER_WEAR, CS2_MAX_WEAR, CS2_MAX_WELL_WORN_WEAR, CS2_MIDTIER_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_STICKER_ROTATION, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR, CS2_MIN_WELL_WORN_WEAR, CS2_MISC_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_RIFLE_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODELS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_SWAP_TOOL_DEF, CS2_STICKERABLE_ITEMS, CS2_STICKER_OFFSET_FACTOR, CS2_STICKER_SCRAPE_FACTOR, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEF, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_WEAR_FACTOR };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CS2ItemType as e}from"./economy-types.mjs";import{CS2Team as t}from"./teams.mjs";const n=0,r=999999,i=0,a=1,o=.06,s=.8,c=0,l=.07,u=.070001,d=.15,f=.150001,p=.37,m=.370001,h=.44,g=.440001,_=1,v=1,y=1e3,b=0,x=1,S=-180,C=180,w=1,T=1e5,E=5,D=5,O=1,k=.01,A=1e-6,
|
|
1
|
+
import{CS2ItemType as e}from"./economy-types.mjs";import{CS2Team as t}from"./teams.mjs";const n=0,r=999999,i=0,a=1,o=.06,s=.8,c=0,l=.07,u=.070001,d=.15,f=.150001,p=.37,m=.370001,h=.44,g=.440001,_=1,v=1,y=1e3,b=0,x=1,S=-180,C=180,w=1,T=1e5,E=5,D=5,O=1,k=.01,A=.1,j=1e-4,M=1e-6,N=/^[A-Za-z0-9`!@#$%^&*-+=(){}\[\]\/\|\\,.?:;'_\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\s]{0,20}$/u,P=62,F=1200,I=1324,L=1201,R=[e.Container,e.Tool],z=[e.Collectible,e.MusicKit],B=[e.Weapon,e.Agent,e.Gloves,e.Melee,e.MusicKit],V=[e.Patch,e.Sticker,e.Graffiti,e.Keychain],H=[e.Melee,e.Weapon],U=[e.Gloves,e.Melee,e.Weapon],W=[e.Agent],G=[e.Weapon,e.Melee,e.Gloves,e.Keychain],K=[e.Melee,e.Weapon,e.MusicKit],q=[e.Weapon],J=[e.Weapon],Y=[`heavy`,`smg`],X=[`rifle`],Z=[`c4`,`equipment`],Q=[`awp`,`g3sg1`,`scar20`,`ssg08`],$=[`m249`,`negev`],ee=[t.T,t.CT],te=[t.CT],ne=[t.T];export{R as CS2_CONTAINER_ITEMS,P as CS2_CONTRACT_TOOL_DEF,s as CS2_DEFAULT_MAX_WEAR,o as CS2_DEFAULT_MIN_WEAR,z as CS2_DISPLAY_ITEMS,B as CS2_EQUIPMENT_ITEMS,V as CS2_GRAPHIC_ART_ITEMS,J as CS2_KEYCHAINABLE_ITEMS,$ as CS2_MACHINEGUN_MODELS,_ as CS2_MAX_BATTLE_SCARRED_WEAR,l as CS2_MAX_FACTORY_NEW_WEAR,p as CS2_MAX_FIELD_TESTED_WEAR,O as CS2_MAX_KEYCHAINS,T as CS2_MAX_KEYCHAIN_SEED,d as CS2_MAX_MINIMAL_WEAR_WEAR,D as CS2_MAX_PATCHES,y as CS2_MAX_SEED,r as CS2_MAX_STATTRAK,E as CS2_MAX_STICKERS,C as CS2_MAX_STICKER_ROTATION,x as CS2_MAX_STICKER_WEAR,a as CS2_MAX_WEAR,h as CS2_MAX_WELL_WORN_WEAR,Y as CS2_MIDTIER_CATEGORIES,g as CS2_MIN_BATTLE_SCARRED_WEAR,c as CS2_MIN_FACTORY_NEW_WEAR,f as CS2_MIN_FIELD_TESTED_WEAR,w as CS2_MIN_KEYCHAIN_SEED,u as CS2_MIN_MINIMAL_WEAR_WEAR,v as CS2_MIN_SEED,n as CS2_MIN_STATTRAK,S as CS2_MIN_STICKER_ROTATION,b as CS2_MIN_STICKER_WEAR,i as CS2_MIN_WEAR,m as CS2_MIN_WELL_WORN_WEAR,Z as CS2_MISC_CATEGORIES,H as CS2_NAMETAGGABLE_ITEMS,N as CS2_NAMETAG_RE,F as CS2_NAMETAG_TOOL_DEF,U as CS2_PAINTABLE_ITEMS,W as CS2_PATCHABLE_ITEMS,X as CS2_RIFLE_CATEGORIES,G as CS2_SEEDABLE_ITEMS,Q as CS2_SNIPER_RIFLE_MODELS,K as CS2_STATTRAKABLE_ITEMS,I as CS2_STATTRAK_SWAP_TOOL_DEF,q as CS2_STICKERABLE_ITEMS,j as CS2_STICKER_OFFSET_FACTOR,A as CS2_STICKER_SCRAPE_FACTOR,k as CS2_STICKER_WEAR_FACTOR,L as CS2_STORAGE_UNIT_TOOL_DEF,ee as CS2_TEAMS_BOTH,te as CS2_TEAMS_CT,ne as CS2_TEAMS_T,M as CS2_WEAR_FACTOR};
|
package/dist/economy-types.d.mts
CHANGED
|
@@ -57,7 +57,12 @@ interface CS2Item {
|
|
|
57
57
|
index?: number | undefined;
|
|
58
58
|
keys?: number[] | undefined;
|
|
59
59
|
legacy?: boolean | undefined;
|
|
60
|
-
|
|
60
|
+
legacyStickerOffsetXMax?: number | undefined;
|
|
61
|
+
legacyStickerOffsetXMin?: number | undefined;
|
|
62
|
+
legacyStickerOffsetYMax?: number | undefined;
|
|
63
|
+
legacyStickerOffsetYMin?: number | undefined;
|
|
64
|
+
/** Count of sticker schemas (StickerMarkup anchors) on the legacy mesh; see {@link CS2EconomyItem.getStickerSchemaCount}. */
|
|
65
|
+
legacyStickerSchemaCount?: number | undefined;
|
|
61
66
|
model?: string | undefined;
|
|
62
67
|
paintMaterial?: string | undefined;
|
|
63
68
|
playerModel?: string | undefined;
|
|
@@ -67,7 +72,12 @@ interface CS2Item {
|
|
|
67
72
|
statTrakless?: boolean | undefined;
|
|
68
73
|
statTrakOnly?: boolean | undefined;
|
|
69
74
|
stickerId?: number | undefined;
|
|
70
|
-
|
|
75
|
+
stickerOffsetXMax?: number | undefined;
|
|
76
|
+
stickerOffsetXMin?: number | undefined;
|
|
77
|
+
stickerOffsetYMax?: number | undefined;
|
|
78
|
+
stickerOffsetYMin?: number | undefined;
|
|
79
|
+
/** Count of sticker schemas (StickerMarkup anchors) on the HD mesh; see {@link CS2EconomyItem.getStickerSchemaCount}. */
|
|
80
|
+
stickerSchemaCount?: number | undefined;
|
|
71
81
|
teams?: CS2ItemTeam | undefined;
|
|
72
82
|
tint?: number | undefined;
|
|
73
83
|
type: CS2ItemType;
|
package/dist/economy.d.mts
CHANGED
|
@@ -71,7 +71,11 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
|
|
|
71
71
|
index: number | undefined;
|
|
72
72
|
keys: number[] | undefined;
|
|
73
73
|
legacy: boolean | undefined;
|
|
74
|
-
|
|
74
|
+
legacyStickerOffsetXMax: number | undefined;
|
|
75
|
+
legacyStickerOffsetXMin: number | undefined;
|
|
76
|
+
legacyStickerOffsetYMax: number | undefined;
|
|
77
|
+
legacyStickerOffsetYMin: number | undefined;
|
|
78
|
+
legacyStickerSchemaCount: number | undefined;
|
|
75
79
|
model: string | undefined;
|
|
76
80
|
name: string;
|
|
77
81
|
paintMaterial: string | undefined;
|
|
@@ -81,7 +85,11 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
|
|
|
81
85
|
statTrakless: boolean | undefined;
|
|
82
86
|
statTrakOnly: boolean | undefined;
|
|
83
87
|
stickerId: number | undefined;
|
|
84
|
-
|
|
88
|
+
stickerOffsetXMax: number | undefined;
|
|
89
|
+
stickerOffsetXMin: number | undefined;
|
|
90
|
+
stickerOffsetYMax: number | undefined;
|
|
91
|
+
stickerOffsetYMin: number | undefined;
|
|
92
|
+
stickerSchemaCount: number | undefined;
|
|
85
93
|
tint: number | undefined;
|
|
86
94
|
tournamentDesc: string | undefined;
|
|
87
95
|
type: CS2ItemType;
|
|
@@ -165,7 +173,16 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
|
|
|
165
173
|
getMaximumWear(): number;
|
|
166
174
|
getMinimumSeed(): number;
|
|
167
175
|
getMaximumSeed(): number;
|
|
168
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Count of sticker schemas (StickerMarkup anchors) the model defines; valid `schema` is
|
|
178
|
+
* `[0, count)`. Independent of the 5-deep stack ({@link CS2_MAX_STICKERS}), so a model with
|
|
179
|
+
* fewer schemas than stickers shares anchors.
|
|
180
|
+
*/
|
|
181
|
+
getStickerSchemaCount(): number;
|
|
182
|
+
getMinimumStickerOffsetX(): number | undefined;
|
|
183
|
+
getMaximumStickerOffsetX(): number | undefined;
|
|
184
|
+
getMinimumStickerOffsetY(): number | undefined;
|
|
185
|
+
getMaximumStickerOffsetY(): number | undefined;
|
|
169
186
|
groupContents(): Record<string, CS2EconomyItem[]>;
|
|
170
187
|
listContents(hideSpecials?: boolean): CS2EconomyItem[];
|
|
171
188
|
unlockContainer(options?: {
|
package/dist/economy.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{assert as i,compare as a,ensure as o,safe as s}from"./utils.mjs";import{CS2_CONTAINER_ITEMS as c,CS2_DISPLAY_ITEMS as l,CS2_EQUIPMENT_ITEMS as u,CS2_GRAPHIC_ART_ITEMS as d,CS2_KEYCHAINABLE_ITEMS as f,CS2_MACHINEGUN_MODELS as p,CS2_MAX_FACTORY_NEW_WEAR as m,CS2_MAX_FIELD_TESTED_WEAR as h,CS2_MAX_KEYCHAIN_SEED as g,CS2_MAX_MINIMAL_WEAR_WEAR as _,CS2_MAX_SEED as v,CS2_MAX_WELL_WORN_WEAR as y,CS2_MIDTIER_CATEGORIES as b,CS2_MISC_CATEGORIES as x,CS2_NAMETAGGABLE_ITEMS as S,CS2_NAMETAG_RE as C,CS2_PAINTABLE_ITEMS as w,CS2_PATCHABLE_ITEMS as T,CS2_RIFLE_CATEGORIES as E,CS2_SEEDABLE_ITEMS as D,CS2_SNIPER_RIFLE_MODELS as O,CS2_STATTRAKABLE_ITEMS as k,CS2_STICKERABLE_ITEMS as A,CS2_TEAMS_BOTH as j,CS2_TEAMS_CT as M,CS2_TEAMS_T as N,CS2_WEAR_FACTOR as P}from"./economy-constants.mjs";import{CS2RarityColorName as F,CS2RarityColorOrder as I,CS2RaritySoundName as L,CS2_RARITY_ORDER as R,randomFloat as z,randomInt as B}from"./economy-container.mjs";function V(e){return function(t){return a(e.type,t.type)&&a(e.free,t.free)&&a(e.model,t.model)&&a(e.base,t.base)&&a(e.category,t.category)&&(e.team===void 0||t.teams===void 0||t.teams.includes(e.team))}}var H=class{baseUrl=`https://cdn.cstrike.app`;categories=new Set;items=new Map;itemsAsArray=[];stickers=new Set;load({assetsBaseUrl:e,items:t,language:n}){this.baseUrl=e??this.baseUrl,this.categories.clear(),this.items.clear(),this.stickers.clear(),this.itemsAsArray=[];for(let e of t){let t=new U(this,e,o(n[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),this.categories.add(o(t.category))),this.itemsAsArray.push(t)}}getById(e){return o(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return o(this.itemsAsArray.find(V(e)))}filterItems(e){let t=this.itemsAsArray.filter(V(e));return i(t.length>0),t}validateWear(e,t){return e===void 0?!0:(i(Number.isFinite(e)),i(String(e).length<=String(P).length),i(e>=0&&e<=1),t!==void 0&&(i(t.hasWear()),i(t.wearMin===void 0||e>=t.wearMin),i(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return s(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0?!0:(i(Number.isFinite(e)),i(Number.isInteger(e)),i(t===void 0||t.hasSeed()),i(e>=(t?.getMinimumSeed()??1)&&e<=(t?.getMaximumSeed()??1e3)),!0)}safeValidateSeed(e,t){return s(()=>this.validateSeed(e,t))}trimNameTag(e){let t=e?.trim();return t===``?void 0:t}validateNameTag(e,t){return e!==void 0&&(i(t===void 0||t.hasNameTag()),i(e[0]!==` `&&C.test(e))),!0}safeValidateNameTag(e,t){return s(()=>this.validateNameTag(e,t))}requireNameTag(e,t){return i(e===void 0||e.trim().length>0),this.validateNameTag(e,t)}safeRequireNameTag(e,t){return s(()=>this.requireNameTag(e,t))}validateStatTrak(e,t){return e===void 0?!0:(i(t===void 0||t.hasStatTrak()),i(Number.isInteger(e)),i(e>=0&&e<=999999),!0)}safeValidateStatTrak(e,t){return s(()=>this.validateStatTrak(e,t))}getWearFromValue(e){switch(!0){case e<=m:return r.FactoryNew;case e<=_:return r.MinimalWear;case e<=h:return r.FieldTested;case e<=y:return r.WellWorn;default:return r.BattleScarred}}getStickerCategories(){return Array.from(this.categories).sort()}getStickers(){return Array.from(this.stickers)}validateContainerAndKey(e,t){return e=this.get(e),e.expectContainer(),t=t===void 0?void 0:this.get(t),t===void 0?i(e.keys===void 0):(t.expectKey(),i(e.keys!==void 0),i(e.keys.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return s(()=>this.validateContainerAndKey(e,t))}expectUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),i(e.rawContents?.includes(t)||e.rawSpecials?.includes(t))}resolveUrl(e){return`${this.baseUrl}${e}`}},U=class{economy;item;language;altName;base;baseId;category;collection;collectionDesc;collectionImage;collectionName;containerType;def;desc;free;id=null;image;index;keys;legacy;legacyStickerSlots;model;name=null;paintMaterial;playerModel;rarity=null;specialsImage;statTrakless;statTrakOnly;stickerId;stickerSlots;tint;tournamentDesc;type=null;wearMax;wearMin;_contents;_specials;_teams;constructor(e,t,r){this.economy=e,this.item=t,this.language=r,Object.assign(this,t),Object.assign(this,r),i(typeof this.id==`number`),i(this.name),i(this.type),i(t.type===n.Stub||typeof this.rarity==`string`)}set contents(e){this._contents=e}get contents(){return this.expectContainer(),o(this._contents).map(e=>this.economy.get(e))}get parent(){return this.baseId===void 0?void 0:this.economy.items.has(this.baseId)?this.economy.get(this.baseId):void 0}get rawContents(){return this._contents}get rawSpecials(){return this._specials}set specials(e){this._specials=e}get specials(){return this.expectContainer(),this._specials?.map(e=>this.economy.get(e))}set teams(e){this._teams=e}get teams(){switch(this._teams){case t.Both:return j;case t.T:return N;case t.CT:return M;default:return}}get wrappedSticker(){return this.stickerId===void 0?void 0:this.economy.get(this.stickerId)}isC4(){return this.category===`c4`}isPistol(){return this.category===`secondary`}isSMG(){return this.category===`smg`}isRifle(){return this.category===`rifle`}isSniperRifle(){return this.model!==void 0&&O.includes(this.model)}isMachinegun(){return this.model!==void 0&&p.includes(this.model)}isHeavy(){return this.category===`heavy`}isEquipment(){return this.category===`equipment`}isInMidTiers(){return this.category!==void 0&&b.includes(this.category)}isInRifles(){return this.category!==void 0&&E.includes(this.category)}isInMisc(){return this.category!==void 0&&x.includes(this.category)}isAgent(){return this.type===n.Agent}isCollectible(){return this.type===n.Collectible}isContainer(){return this.type===n.Container}isKey(){return this.type===n.Key}isGloves(){return this.type===n.Gloves}isGraffiti(){return this.type===n.Graffiti}isMelee(){return this.type===n.Melee}isMusicKit(){return this.type===n.MusicKit}isPatch(){return this.type===n.Patch}isSticker(){return this.type===n.Sticker}isKeychain(){return this.type===n.Keychain}isStub(){return this.type===n.Stub}isTool(){return this.type===n.Tool}isWeapon(){return this.type===n.Weapon}isStorageUnit(){return this.isTool()&&this.def===1201}isNameTag(){return this.isTool()&&this.def===1200}isStatTrakSwapTool(){return this.isTool()&&this.def===1324}isContract(){return this.isTool()&&this.def===62}expectAgent(){return i(this.isAgent()),this}expectPatch(){return i(this.isPatch()),this}expectSticker(){return i(this.isSticker()),this}expectKeychain(){return i(this.isKeychain()),this}expectStorageUnit(){return i(this.isStorageUnit()),this}expectNameTag(){return i(this.isNameTag()),this}expectStatTrakSwapTool(){return i(this.isStatTrakSwapTool()),this}expectContainer(){return i(this.isContainer()),this}expectKey(){return i(this.isKey()),this}hasWear(){return w.includes(this.type)&&!this.free&&this.index!==0}hasSeed(){return D.includes(this.type)&&!this.free&&this.index!==0}hasStickers(){return A.includes(this.type)&&!this.isC4()}hasKeychains(){return f.includes(this.type)&&!this.isC4()}hasPatches(){return T.includes(this.type)}hasNameTag(){return S.includes(this.type)||this.isStorageUnit()}hasStatTrak(){return k.includes(this.type)&&!this.free}isWeaponCase(){return this.containerType===e.WeaponCase}isStickerCapsule(){return this.containerType===e.StickerCapsule}isGraffitiBox(){return this.containerType===e.GraffitiBox}isSouvenirCase(){return this.containerType===e.SouvenirCase}isInEquipments(){return u.includes(this.type)}isInGraphicArts(){return d.includes(this.type)}isInContainers(){return c.includes(this.type)}isInDisplay(){return l.includes(this.type)}isPaintable(){return w.includes(this.type)}getImage(e){i(this.image);let t=this.economy.resolveUrl(this.image);if(this.hasWear()&&e!==void 0)switch(!0){case e<1/3:return t.replace(`.webp`,`_light.webp`);case e<2/3:return t.replace(`.webp`,`_medium.webp`);default:return t.replace(`.webp`,`_heavy.webp`)}return t}getCollectionImage(){return this.economy.resolveUrl(this.collectionImage)}getSpecialsImage(){return this.expectContainer(),i(this.rawSpecials),i(this.specialsImage),this.economy.resolveUrl(this.specialsImage)}getPaintMaterial(){return this.economy.resolveUrl(this.paintMaterial)}getPlayerModel(){let{playerModel:e}=this.parent??this;return this.economy.resolveUrl(e)}getModelData(){let{playerModel:e}=this.parent??this;return this.economy.resolveUrl(e?.replace(/\.glb$/,`.json`))}getMinimumWear(){return this.wearMin??0}getMaximumWear(){return this.wearMax??1}getMinimumSeed(){return this.isKeychain(),1}getMaximumSeed(){return this.isKeychain()?g:v}getMaximumStickers(){let e=this.parent??this;return(this.legacy?e.legacyStickerSlots:void 0)??e.stickerSlots??5}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=F[t.rarity];e[n]||(e[n]=[]),e[n].push(t)}if(t!==void 0)for(let n of t){let t=`special`;e[t]||(e[t]=[]),e[t].push(n)}return e}listContents(e=!1){let t=this.specials;return[...this.contents,...!e&&t!==void 0?t:[]].sort((e,t)=>(I[e.rarity]??0)-(I[t.rarity]??0))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=R.filter(e=>n.includes(e)),i=e?.computeOdds?.(r)??r.map((e,t)=>.8/5**t),a=i.reduce((e,t)=>e+t,0),s=r.map((e,t)=>[e,o(i[t])/a]),c=Math.random(),[l]=o(s[0]),u=0;for(let[e,t]of s)if(u+=t,c<=u){l=e;break}let d=o(t[l]),f=o(d[Math.floor(Math.random()*d.length)]),p=this.statTrakless!==!0,m=this.statTrakOnly===!0;return{attributes:{containerId:this.id,seed:f.hasSeed()?B(1,v):void 0,statTrak:p&&f.hasStatTrak()&&(m||Math.random()<=.1)?0:void 0,wear:f.hasWear()?Number(z(f.wearMin??0,f.wearMax??1).toString().substring(0,P.toString().length)):void 0},id:f.id,rarity:L[f.rarity],special:l===`special`}}};const W=new H;export{W as CS2Economy,H as CS2EconomyInstance,U as CS2EconomyItem};
|
|
1
|
+
import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{assert as i,compare as a,ensure as o,isFactorPrecise as s,safe as c,truncateToFactor as l}from"./utils.mjs";import{CS2_CONTAINER_ITEMS as u,CS2_DISPLAY_ITEMS as d,CS2_EQUIPMENT_ITEMS as f,CS2_GRAPHIC_ART_ITEMS as p,CS2_KEYCHAINABLE_ITEMS as m,CS2_MACHINEGUN_MODELS as h,CS2_MAX_FACTORY_NEW_WEAR as g,CS2_MAX_FIELD_TESTED_WEAR as _,CS2_MAX_KEYCHAIN_SEED as v,CS2_MAX_MINIMAL_WEAR_WEAR as y,CS2_MAX_SEED as b,CS2_MAX_WELL_WORN_WEAR as x,CS2_MIDTIER_CATEGORIES as S,CS2_MISC_CATEGORIES as C,CS2_NAMETAGGABLE_ITEMS as w,CS2_NAMETAG_RE as T,CS2_PAINTABLE_ITEMS as E,CS2_PATCHABLE_ITEMS as D,CS2_RIFLE_CATEGORIES as O,CS2_SEEDABLE_ITEMS as k,CS2_SNIPER_RIFLE_MODELS as A,CS2_STATTRAKABLE_ITEMS as j,CS2_STICKERABLE_ITEMS as M,CS2_TEAMS_BOTH as N,CS2_TEAMS_CT as P,CS2_TEAMS_T as F,CS2_WEAR_FACTOR as I}from"./economy-constants.mjs";import{CS2RarityColorName as L,CS2RarityColorOrder as R,CS2RaritySoundName as z,CS2_RARITY_ORDER as B,randomFloat as V,randomInt as H}from"./economy-container.mjs";function U(e){return function(t){return a(e.type,t.type)&&a(e.free,t.free)&&a(e.model,t.model)&&a(e.base,t.base)&&a(e.category,t.category)&&(e.team===void 0||t.teams===void 0||t.teams.includes(e.team))}}var W=class{baseUrl=`https://cdn.cstrike.app`;categories=new Set;items=new Map;itemsAsArray=[];stickers=new Set;load({assetsBaseUrl:e,items:t,language:n}){this.baseUrl=e??this.baseUrl,this.categories.clear(),this.items.clear(),this.stickers.clear(),this.itemsAsArray=[];for(let e of t){let t=new G(this,e,o(n[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),this.categories.add(o(t.category))),this.itemsAsArray.push(t)}}getById(e){return o(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return o(this.itemsAsArray.find(U(e)))}filterItems(e){let t=this.itemsAsArray.filter(U(e));return i(t.length>0),t}validateWear(e,t){return e===void 0?!0:(i(s(e,I)),i(e>=0&&e<=1),t!==void 0&&(i(t.hasWear()),i(t.wearMin===void 0||e>=t.wearMin),i(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return c(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0?!0:(i(Number.isFinite(e)),i(Number.isInteger(e)),i(t===void 0||t.hasSeed()),i(e>=(t?.getMinimumSeed()??1)&&e<=(t?.getMaximumSeed()??1e3)),!0)}safeValidateSeed(e,t){return c(()=>this.validateSeed(e,t))}trimNameTag(e){let t=e?.trim();return t===``?void 0:t}validateNameTag(e,t){return e!==void 0&&(i(t===void 0||t.hasNameTag()),i(e[0]!==` `&&T.test(e))),!0}safeValidateNameTag(e,t){return c(()=>this.validateNameTag(e,t))}requireNameTag(e,t){return i(e===void 0||e.trim().length>0),this.validateNameTag(e,t)}safeRequireNameTag(e,t){return c(()=>this.requireNameTag(e,t))}validateStatTrak(e,t){return e===void 0?!0:(i(t===void 0||t.hasStatTrak()),i(Number.isInteger(e)),i(e>=0&&e<=999999),!0)}safeValidateStatTrak(e,t){return c(()=>this.validateStatTrak(e,t))}getWearFromValue(e){switch(!0){case e<=g:return r.FactoryNew;case e<=y:return r.MinimalWear;case e<=_:return r.FieldTested;case e<=x:return r.WellWorn;default:return r.BattleScarred}}getStickerCategories(){return Array.from(this.categories).sort()}getStickers(){return Array.from(this.stickers)}validateContainerAndKey(e,t){return e=this.get(e),e.expectContainer(),t=t===void 0?void 0:this.get(t),t===void 0?i(e.keys===void 0):(t.expectKey(),i(e.keys!==void 0),i(e.keys.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return c(()=>this.validateContainerAndKey(e,t))}expectUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),i(e.rawContents?.includes(t)||e.rawSpecials?.includes(t))}resolveUrl(e){return`${this.baseUrl}${e}`}},G=class{economy;item;language;altName;base;baseId;category;collection;collectionDesc;collectionImage;collectionName;containerType;def;desc;free;id=null;image;index;keys;legacy;legacyStickerOffsetXMax;legacyStickerOffsetXMin;legacyStickerOffsetYMax;legacyStickerOffsetYMin;legacyStickerSchemaCount;model;name=null;paintMaterial;playerModel;rarity=null;specialsImage;statTrakless;statTrakOnly;stickerId;stickerOffsetXMax;stickerOffsetXMin;stickerOffsetYMax;stickerOffsetYMin;stickerSchemaCount;tint;tournamentDesc;type=null;wearMax;wearMin;_contents;_specials;_teams;constructor(e,t,r){this.economy=e,this.item=t,this.language=r,Object.assign(this,t),Object.assign(this,r),i(typeof this.id==`number`),i(this.name),i(this.type),i(t.type===n.Stub||typeof this.rarity==`string`)}set contents(e){this._contents=e}get contents(){return this.expectContainer(),o(this._contents).map(e=>this.economy.get(e))}get parent(){return this.baseId===void 0?void 0:this.economy.items.has(this.baseId)?this.economy.get(this.baseId):void 0}get rawContents(){return this._contents}get rawSpecials(){return this._specials}set specials(e){this._specials=e}get specials(){return this.expectContainer(),this._specials?.map(e=>this.economy.get(e))}set teams(e){this._teams=e}get teams(){switch(this._teams){case t.Both:return N;case t.T:return F;case t.CT:return P;default:return}}get wrappedSticker(){return this.stickerId===void 0?void 0:this.economy.get(this.stickerId)}isC4(){return this.category===`c4`}isPistol(){return this.category===`secondary`}isSMG(){return this.category===`smg`}isRifle(){return this.category===`rifle`}isSniperRifle(){return this.model!==void 0&&A.includes(this.model)}isMachinegun(){return this.model!==void 0&&h.includes(this.model)}isHeavy(){return this.category===`heavy`}isEquipment(){return this.category===`equipment`}isInMidTiers(){return this.category!==void 0&&S.includes(this.category)}isInRifles(){return this.category!==void 0&&O.includes(this.category)}isInMisc(){return this.category!==void 0&&C.includes(this.category)}isAgent(){return this.type===n.Agent}isCollectible(){return this.type===n.Collectible}isContainer(){return this.type===n.Container}isKey(){return this.type===n.Key}isGloves(){return this.type===n.Gloves}isGraffiti(){return this.type===n.Graffiti}isMelee(){return this.type===n.Melee}isMusicKit(){return this.type===n.MusicKit}isPatch(){return this.type===n.Patch}isSticker(){return this.type===n.Sticker}isKeychain(){return this.type===n.Keychain}isStub(){return this.type===n.Stub}isTool(){return this.type===n.Tool}isWeapon(){return this.type===n.Weapon}isStorageUnit(){return this.isTool()&&this.def===1201}isNameTag(){return this.isTool()&&this.def===1200}isStatTrakSwapTool(){return this.isTool()&&this.def===1324}isContract(){return this.isTool()&&this.def===62}expectAgent(){return i(this.isAgent()),this}expectPatch(){return i(this.isPatch()),this}expectSticker(){return i(this.isSticker()),this}expectKeychain(){return i(this.isKeychain()),this}expectStorageUnit(){return i(this.isStorageUnit()),this}expectNameTag(){return i(this.isNameTag()),this}expectStatTrakSwapTool(){return i(this.isStatTrakSwapTool()),this}expectContainer(){return i(this.isContainer()),this}expectKey(){return i(this.isKey()),this}hasWear(){return E.includes(this.type)&&!this.free&&this.index!==0}hasSeed(){return k.includes(this.type)&&!this.free&&this.index!==0}hasStickers(){return M.includes(this.type)&&!this.isC4()}hasKeychains(){return m.includes(this.type)&&!this.isC4()}hasPatches(){return D.includes(this.type)}hasNameTag(){return w.includes(this.type)||this.isStorageUnit()}hasStatTrak(){return j.includes(this.type)&&!this.free}isWeaponCase(){return this.containerType===e.WeaponCase}isStickerCapsule(){return this.containerType===e.StickerCapsule}isGraffitiBox(){return this.containerType===e.GraffitiBox}isSouvenirCase(){return this.containerType===e.SouvenirCase}isInEquipments(){return f.includes(this.type)}isInGraphicArts(){return p.includes(this.type)}isInContainers(){return u.includes(this.type)}isInDisplay(){return d.includes(this.type)}isPaintable(){return E.includes(this.type)}getImage(e){i(this.image);let t=this.economy.resolveUrl(this.image);if(this.hasWear()&&e!==void 0)switch(!0){case e<1/3:return t.replace(`.webp`,`_light.webp`);case e<2/3:return t.replace(`.webp`,`_medium.webp`);default:return t.replace(`.webp`,`_heavy.webp`)}return t}getCollectionImage(){return this.economy.resolveUrl(this.collectionImage)}getSpecialsImage(){return this.expectContainer(),i(this.rawSpecials),i(this.specialsImage),this.economy.resolveUrl(this.specialsImage)}getPaintMaterial(){return this.economy.resolveUrl(this.paintMaterial)}getPlayerModel(){let{playerModel:e}=this.parent??this;return this.economy.resolveUrl(e)}getModelData(){let{playerModel:e}=this.parent??this;return this.economy.resolveUrl(e?.replace(/\.glb$/,`.json`))}getMinimumWear(){return this.wearMin??0}getMaximumWear(){return this.wearMax??1}getMinimumSeed(){return this.isKeychain(),1}getMaximumSeed(){return this.isKeychain()?v:b}getStickerSchemaCount(){let e=this.parent??this;return(this.legacy?e.legacyStickerSchemaCount:void 0)??e.stickerSchemaCount??5}getMinimumStickerOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetXMin:void 0)??e.stickerOffsetXMin}getMaximumStickerOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetXMax:void 0)??e.stickerOffsetXMax}getMinimumStickerOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetYMin:void 0)??e.stickerOffsetYMin}getMaximumStickerOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetYMax:void 0)??e.stickerOffsetYMax}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=L[t.rarity];e[n]||(e[n]=[]),e[n].push(t)}if(t!==void 0)for(let n of t){let t=`special`;e[t]||(e[t]=[]),e[t].push(n)}return e}listContents(e=!1){let t=this.specials;return[...this.contents,...!e&&t!==void 0?t:[]].sort((e,t)=>(R[e.rarity]??0)-(R[t.rarity]??0))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=B.filter(e=>n.includes(e)),i=e?.computeOdds?.(r)??r.map((e,t)=>.8/5**t),a=i.reduce((e,t)=>e+t,0),s=r.map((e,t)=>[e,o(i[t])/a]),c=Math.random(),[u]=o(s[0]),d=0;for(let[e,t]of s)if(d+=t,c<=d){u=e;break}let f=o(t[u]),p=o(f[Math.floor(Math.random()*f.length)]),m=this.statTrakless!==!0,h=this.statTrakOnly===!0;return{attributes:{containerId:this.id,seed:p.hasSeed()?H(1,b):void 0,statTrak:m&&p.hasStatTrak()&&(h||Math.random()<=.1)?0:void 0,wear:p.hasWear()?l(V(p.wearMin??0,p.wearMax??1),I):void 0},id:p.id,rarity:z[p.rarity],special:u===`special`}}};const K=new W;export{K as CS2Economy,W as CS2EconomyInstance,G as CS2EconomyItem};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { EnumValues, Interface, MapValue, RecordValue, assert, compare, ensure, fail, float, isNotUndefined, safe } from "./utils.mjs";
|
|
1
|
+
import { EnumValues, Interface, MapValue, RecordValue, assert, clamp, compare, countDecimals, ensure, fail, float, isFactorPrecise, isNotUndefined, roundToFactor, safe, truncateToFactor } from "./utils.mjs";
|
|
2
2
|
import { CS2Rarity, CS2RarityColor, CS2RarityColorName, CS2RarityColorOrder, CS2RarityKeys, CS2RaritySoundName, CS2_BASE_ODD, CS2_RARITIES, CS2_RARITY_COLOR_DEFAULT, CS2_RARITY_ORDER, CS2_STATTRAK_ODD, randomBoolean, randomFloat, randomInt } from "./economy-container.mjs";
|
|
3
3
|
import { CS2ContainerType, CS2Item, CS2ItemTeam, CS2ItemTranslation, CS2ItemTranslationByLanguage, CS2ItemTranslationMap, CS2ItemType, CS2ItemWear, CS2UnlockedItem } from "./economy-types.mjs";
|
|
4
4
|
import { CS2Team, toggleCS2Team } from "./teams.mjs";
|
|
5
|
-
import { CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEF, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_EQUIPMENT_ITEMS, CS2_GRAPHIC_ART_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_MACHINEGUN_MODELS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_SEED, CS2_MAX_STATTRAK, CS2_MAX_STICKERS, CS2_MAX_STICKER_ROTATION, CS2_MAX_STICKER_WEAR, CS2_MAX_WEAR, CS2_MAX_WELL_WORN_WEAR, CS2_MIDTIER_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_STICKER_ROTATION, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR, CS2_MIN_WELL_WORN_WEAR, CS2_MISC_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_RIFLE_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODELS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_SWAP_TOOL_DEF, CS2_STICKERABLE_ITEMS, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEF, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_WEAR_FACTOR } from "./economy-constants.mjs";
|
|
5
|
+
import { CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEF, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_EQUIPMENT_ITEMS, CS2_GRAPHIC_ART_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_MACHINEGUN_MODELS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_SEED, CS2_MAX_STATTRAK, CS2_MAX_STICKERS, CS2_MAX_STICKER_ROTATION, CS2_MAX_STICKER_WEAR, CS2_MAX_WEAR, CS2_MAX_WELL_WORN_WEAR, CS2_MIDTIER_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_STICKER_ROTATION, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR, CS2_MIN_WELL_WORN_WEAR, CS2_MISC_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_RIFLE_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODELS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_SWAP_TOOL_DEF, CS2_STICKERABLE_ITEMS, CS2_STICKER_OFFSET_FACTOR, CS2_STICKER_SCRAPE_FACTOR, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEF, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_WEAR_FACTOR } from "./economy-constants.mjs";
|
|
6
6
|
import { CS2Economy, CS2EconomyInstance, CS2EconomyItem } from "./economy.mjs";
|
|
7
|
-
import { CS2BaseInventoryItem, CS2Inventory, CS2InventoryData, CS2InventoryItem, CS2InventoryOptions, CS2InventorySpec, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_TIMESTAMP, CS2_INVENTORY_VERSION, getNextUid, getTimestamp } from "./inventory.mjs";
|
|
7
|
+
import { CS2BaseInventoryItem, CS2Inventory, CS2InventoryData, CS2InventoryItem, CS2InventoryOptions, CS2InventorySpec, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_TIMESTAMP, CS2_INVENTORY_VERSION, getNextStickerSchema, getNextUid, getTimestamp, healStickerOffset, stickerMapToArray, toStickerMap } from "./inventory.mjs";
|
|
8
8
|
import { CS2_ITEMS } from "./items.mjs";
|
|
9
9
|
import { CS2KeyValues } from "./keyvalues.mjs";
|
|
10
10
|
import { CS2KeyValues3 } from "./keyvalues3.mjs";
|
|
11
11
|
import { CS2Map, CS2_ACTIVE_MAP_POOL, CS2_ALL_MAPS, CS2_ANCIENT_MAP, CS2_ANUBIS_MAP, CS2_CACHE_MAP, CS2_DUST2_MAP, CS2_INFERNO_MAP, CS2_MIRAGE_MAP, CS2_NUKE_MAP, CS2_OVERPASS_MAP, CS2_TRAIN_MAP, CS2_VERTIGO_MAP, getMapnameName } from "./maps.mjs";
|
|
12
12
|
import { CS2Veto, CS2VetoAction, CS2VetoMap, CS2VetoType } from "./veto.mjs";
|
|
13
|
-
export { CS2BaseInventoryItem, CS2ContainerType, CS2Economy, CS2EconomyInstance, CS2EconomyItem, CS2Inventory, CS2InventoryData, CS2InventoryItem, CS2InventoryOptions, CS2InventorySpec, CS2Item, CS2ItemTeam, CS2ItemTranslation, CS2ItemTranslationByLanguage, CS2ItemTranslationMap, CS2ItemType, CS2ItemWear, CS2KeyValues, CS2KeyValues3, CS2Map, CS2Rarity, CS2RarityColor, CS2RarityColorName, CS2RarityColorOrder, CS2RarityKeys, CS2RaritySoundName, CS2Team, CS2UnlockedItem, CS2Veto, CS2VetoAction, CS2VetoMap, CS2VetoType, CS2_ACTIVE_MAP_POOL, CS2_ALL_MAPS, CS2_ANCIENT_MAP, CS2_ANUBIS_MAP, CS2_BASE_ODD, CS2_CACHE_MAP, CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEF, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_DUST2_MAP, CS2_EQUIPMENT_ITEMS, CS2_GRAPHIC_ART_ITEMS, CS2_INFERNO_MAP, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_TIMESTAMP, CS2_INVENTORY_VERSION, CS2_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_MACHINEGUN_MODELS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_SEED, CS2_MAX_STATTRAK, CS2_MAX_STICKERS, CS2_MAX_STICKER_ROTATION, CS2_MAX_STICKER_WEAR, CS2_MAX_WEAR, CS2_MAX_WELL_WORN_WEAR, CS2_MIDTIER_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_STICKER_ROTATION, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR, CS2_MIN_WELL_WORN_WEAR, CS2_MIRAGE_MAP, CS2_MISC_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_NUKE_MAP, CS2_OVERPASS_MAP, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_RARITIES, CS2_RARITY_COLOR_DEFAULT, CS2_RARITY_ORDER, CS2_RIFLE_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODELS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_ODD, CS2_STATTRAK_SWAP_TOOL_DEF, CS2_STICKERABLE_ITEMS, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEF, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_TRAIN_MAP, CS2_VERTIGO_MAP, CS2_WEAR_FACTOR, EnumValues, Interface, MapValue, RecordValue, assert, compare, ensure, fail, float, getMapnameName, getNextUid, getTimestamp, isNotUndefined, randomBoolean, randomFloat, randomInt, safe, toggleCS2Team };
|
|
13
|
+
export { CS2BaseInventoryItem, CS2ContainerType, CS2Economy, CS2EconomyInstance, CS2EconomyItem, CS2Inventory, CS2InventoryData, CS2InventoryItem, CS2InventoryOptions, CS2InventorySpec, CS2Item, CS2ItemTeam, CS2ItemTranslation, CS2ItemTranslationByLanguage, CS2ItemTranslationMap, CS2ItemType, CS2ItemWear, CS2KeyValues, CS2KeyValues3, CS2Map, CS2Rarity, CS2RarityColor, CS2RarityColorName, CS2RarityColorOrder, CS2RarityKeys, CS2RaritySoundName, CS2Team, CS2UnlockedItem, CS2Veto, CS2VetoAction, CS2VetoMap, CS2VetoType, CS2_ACTIVE_MAP_POOL, CS2_ALL_MAPS, CS2_ANCIENT_MAP, CS2_ANUBIS_MAP, CS2_BASE_ODD, CS2_CACHE_MAP, CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEF, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_DUST2_MAP, CS2_EQUIPMENT_ITEMS, CS2_GRAPHIC_ART_ITEMS, CS2_INFERNO_MAP, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_TIMESTAMP, CS2_INVENTORY_VERSION, CS2_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_MACHINEGUN_MODELS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_SEED, CS2_MAX_STATTRAK, CS2_MAX_STICKERS, CS2_MAX_STICKER_ROTATION, CS2_MAX_STICKER_WEAR, CS2_MAX_WEAR, CS2_MAX_WELL_WORN_WEAR, CS2_MIDTIER_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_STICKER_ROTATION, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR, CS2_MIN_WELL_WORN_WEAR, CS2_MIRAGE_MAP, CS2_MISC_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEF, CS2_NUKE_MAP, CS2_OVERPASS_MAP, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_RARITIES, CS2_RARITY_COLOR_DEFAULT, CS2_RARITY_ORDER, CS2_RIFLE_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODELS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_ODD, CS2_STATTRAK_SWAP_TOOL_DEF, CS2_STICKERABLE_ITEMS, CS2_STICKER_OFFSET_FACTOR, CS2_STICKER_SCRAPE_FACTOR, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEF, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_TRAIN_MAP, CS2_VERTIGO_MAP, CS2_WEAR_FACTOR, EnumValues, Interface, MapValue, RecordValue, assert, clamp, compare, countDecimals, ensure, fail, float, getMapnameName, getNextStickerSchema, getNextUid, getTimestamp, healStickerOffset, isFactorPrecise, isNotUndefined, randomBoolean, randomFloat, randomInt, roundToFactor, safe, stickerMapToArray, toStickerMap, toggleCS2Team, truncateToFactor };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{assert as i,
|
|
1
|
+
import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{assert as i,clamp as a,compare as o,countDecimals as s,ensure as c,fail as l,float as u,isFactorPrecise as d,isNotUndefined as f,roundToFactor as p,safe as m,truncateToFactor as h}from"./utils.mjs";import{CS2Team as g,toggleCS2Team as _}from"./teams.mjs";import{CS2_CONTAINER_ITEMS as v,CS2_CONTRACT_TOOL_DEF as y,CS2_DEFAULT_MAX_WEAR as b,CS2_DEFAULT_MIN_WEAR as x,CS2_DISPLAY_ITEMS as S,CS2_EQUIPMENT_ITEMS as C,CS2_GRAPHIC_ART_ITEMS as w,CS2_KEYCHAINABLE_ITEMS as T,CS2_MACHINEGUN_MODELS as E,CS2_MAX_BATTLE_SCARRED_WEAR as D,CS2_MAX_FACTORY_NEW_WEAR as O,CS2_MAX_FIELD_TESTED_WEAR as k,CS2_MAX_KEYCHAINS as A,CS2_MAX_KEYCHAIN_SEED as j,CS2_MAX_MINIMAL_WEAR_WEAR as M,CS2_MAX_PATCHES as N,CS2_MAX_SEED as P,CS2_MAX_STATTRAK as F,CS2_MAX_STICKERS as I,CS2_MAX_STICKER_ROTATION as L,CS2_MAX_STICKER_WEAR as R,CS2_MAX_WEAR as z,CS2_MAX_WELL_WORN_WEAR as B,CS2_MIDTIER_CATEGORIES as V,CS2_MIN_BATTLE_SCARRED_WEAR as H,CS2_MIN_FACTORY_NEW_WEAR as U,CS2_MIN_FIELD_TESTED_WEAR as W,CS2_MIN_KEYCHAIN_SEED as G,CS2_MIN_MINIMAL_WEAR_WEAR as K,CS2_MIN_SEED as q,CS2_MIN_STATTRAK as J,CS2_MIN_STICKER_ROTATION as Y,CS2_MIN_STICKER_WEAR as X,CS2_MIN_WEAR as Z,CS2_MIN_WELL_WORN_WEAR as Q,CS2_MISC_CATEGORIES as $,CS2_NAMETAGGABLE_ITEMS as ee,CS2_NAMETAG_RE as te,CS2_NAMETAG_TOOL_DEF as ne,CS2_PAINTABLE_ITEMS as re,CS2_PATCHABLE_ITEMS as ie,CS2_RIFLE_CATEGORIES as ae,CS2_SEEDABLE_ITEMS as oe,CS2_SNIPER_RIFLE_MODELS as se,CS2_STATTRAKABLE_ITEMS as ce,CS2_STATTRAK_SWAP_TOOL_DEF as le,CS2_STICKERABLE_ITEMS as ue,CS2_STICKER_OFFSET_FACTOR as de,CS2_STICKER_SCRAPE_FACTOR as fe,CS2_STICKER_WEAR_FACTOR as pe,CS2_STORAGE_UNIT_TOOL_DEF as me,CS2_TEAMS_BOTH as he,CS2_TEAMS_CT as ge,CS2_TEAMS_T as _e,CS2_WEAR_FACTOR as ve}from"./economy-constants.mjs";import{CS2Rarity as ye,CS2RarityColor as be,CS2RarityColorName as xe,CS2RarityColorOrder as Se,CS2RaritySoundName as Ce,CS2_BASE_ODD as we,CS2_RARITIES as Te,CS2_RARITY_COLOR_DEFAULT as Ee,CS2_RARITY_ORDER as De,CS2_STATTRAK_ODD as Oe,randomBoolean as ke,randomFloat as Ae,randomInt as je}from"./economy-container.mjs";import{CS2Economy as Me,CS2EconomyInstance as Ne,CS2EconomyItem as Pe}from"./economy.mjs";import{CS2Inventory as Fe,CS2InventoryItem as Ie,CS2_INVENTORY_EQUIPPABLE_ITEMS as Le,CS2_INVENTORY_TIMESTAMP as Re,CS2_INVENTORY_VERSION as ze,getNextStickerSchema as Be,getNextUid as Ve,getTimestamp as He,healStickerOffset as Ue,stickerMapToArray as We,toStickerMap as Ge}from"./inventory.mjs";import{CS2_ITEMS as Ke}from"./items.mjs";import{CS2KeyValues as qe}from"./keyvalues.mjs";import{CS2KeyValues3 as Je}from"./keyvalues3.mjs";import{CS2_ACTIVE_MAP_POOL as Ye,CS2_ALL_MAPS as Xe,CS2_ANCIENT_MAP as Ze,CS2_ANUBIS_MAP as Qe,CS2_CACHE_MAP as $e,CS2_DUST2_MAP as et,CS2_INFERNO_MAP as tt,CS2_MIRAGE_MAP as nt,CS2_NUKE_MAP as rt,CS2_OVERPASS_MAP as it,CS2_TRAIN_MAP as at,CS2_VERTIGO_MAP as ot,getMapnameName as st}from"./maps.mjs";import{CS2Veto as ct,CS2VetoAction as lt,CS2VetoType as ut}from"./veto.mjs";export{e as CS2ContainerType,Me as CS2Economy,Ne as CS2EconomyInstance,Pe as CS2EconomyItem,Fe as CS2Inventory,Ie as CS2InventoryItem,t as CS2ItemTeam,n as CS2ItemType,r as CS2ItemWear,qe as CS2KeyValues,Je as CS2KeyValues3,ye as CS2Rarity,be as CS2RarityColor,xe as CS2RarityColorName,Se as CS2RarityColorOrder,Ce as CS2RaritySoundName,g as CS2Team,ct as CS2Veto,lt as CS2VetoAction,ut as CS2VetoType,Ye as CS2_ACTIVE_MAP_POOL,Xe as CS2_ALL_MAPS,Ze as CS2_ANCIENT_MAP,Qe as CS2_ANUBIS_MAP,we as CS2_BASE_ODD,$e as CS2_CACHE_MAP,v as CS2_CONTAINER_ITEMS,y as CS2_CONTRACT_TOOL_DEF,b as CS2_DEFAULT_MAX_WEAR,x as CS2_DEFAULT_MIN_WEAR,S as CS2_DISPLAY_ITEMS,et as CS2_DUST2_MAP,C as CS2_EQUIPMENT_ITEMS,w as CS2_GRAPHIC_ART_ITEMS,tt as CS2_INFERNO_MAP,Le as CS2_INVENTORY_EQUIPPABLE_ITEMS,Re as CS2_INVENTORY_TIMESTAMP,ze as CS2_INVENTORY_VERSION,Ke as CS2_ITEMS,T as CS2_KEYCHAINABLE_ITEMS,E as CS2_MACHINEGUN_MODELS,D as CS2_MAX_BATTLE_SCARRED_WEAR,O as CS2_MAX_FACTORY_NEW_WEAR,k as CS2_MAX_FIELD_TESTED_WEAR,A as CS2_MAX_KEYCHAINS,j as CS2_MAX_KEYCHAIN_SEED,M as CS2_MAX_MINIMAL_WEAR_WEAR,N as CS2_MAX_PATCHES,P as CS2_MAX_SEED,F as CS2_MAX_STATTRAK,I as CS2_MAX_STICKERS,L as CS2_MAX_STICKER_ROTATION,R as CS2_MAX_STICKER_WEAR,z as CS2_MAX_WEAR,B as CS2_MAX_WELL_WORN_WEAR,V as CS2_MIDTIER_CATEGORIES,H as CS2_MIN_BATTLE_SCARRED_WEAR,U as CS2_MIN_FACTORY_NEW_WEAR,W as CS2_MIN_FIELD_TESTED_WEAR,G as CS2_MIN_KEYCHAIN_SEED,K as CS2_MIN_MINIMAL_WEAR_WEAR,q as CS2_MIN_SEED,J as CS2_MIN_STATTRAK,Y as CS2_MIN_STICKER_ROTATION,X as CS2_MIN_STICKER_WEAR,Z as CS2_MIN_WEAR,Q as CS2_MIN_WELL_WORN_WEAR,nt as CS2_MIRAGE_MAP,$ as CS2_MISC_CATEGORIES,ee as CS2_NAMETAGGABLE_ITEMS,te as CS2_NAMETAG_RE,ne as CS2_NAMETAG_TOOL_DEF,rt as CS2_NUKE_MAP,it as CS2_OVERPASS_MAP,re as CS2_PAINTABLE_ITEMS,ie as CS2_PATCHABLE_ITEMS,Te as CS2_RARITIES,Ee as CS2_RARITY_COLOR_DEFAULT,De as CS2_RARITY_ORDER,ae as CS2_RIFLE_CATEGORIES,oe as CS2_SEEDABLE_ITEMS,se as CS2_SNIPER_RIFLE_MODELS,ce as CS2_STATTRAKABLE_ITEMS,Oe as CS2_STATTRAK_ODD,le as CS2_STATTRAK_SWAP_TOOL_DEF,ue as CS2_STICKERABLE_ITEMS,de as CS2_STICKER_OFFSET_FACTOR,fe as CS2_STICKER_SCRAPE_FACTOR,pe as CS2_STICKER_WEAR_FACTOR,me as CS2_STORAGE_UNIT_TOOL_DEF,he as CS2_TEAMS_BOTH,ge as CS2_TEAMS_CT,_e as CS2_TEAMS_T,at as CS2_TRAIN_MAP,ot as CS2_VERTIGO_MAP,ve as CS2_WEAR_FACTOR,i as assert,a as clamp,o as compare,s as countDecimals,c as ensure,l as fail,u as float,st as getMapnameName,Be as getNextStickerSchema,Ve as getNextUid,He as getTimestamp,Ue as healStickerOffset,d as isFactorPrecise,f as isNotUndefined,ke as randomBoolean,Ae as randomFloat,je as randomInt,p as roundToFactor,m as safe,We as stickerMapToArray,Ge as toStickerMap,_ as toggleCS2Team,h as truncateToFactor};
|
package/dist/inventory.d.mts
CHANGED
|
@@ -21,9 +21,16 @@ interface CS2BaseInventoryItem {
|
|
|
21
21
|
patches?: Record<string, number>;
|
|
22
22
|
seed?: number;
|
|
23
23
|
statTrak?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Stickers on the item — a stack of up to {@link CS2_MAX_STICKERS}. The record key is the
|
|
26
|
+
* **slot/index**: the 0-based stack (draw) position. Each sticker's **`schema`** is its physical
|
|
27
|
+
* anchor — an index into the model's `StickerMarkup`, valid in
|
|
28
|
+
* `[0, CS2EconomyItem.getStickerSchemaCount())`. The stack can outnumber a model's schemas, so
|
|
29
|
+
* stickers may share an anchor.
|
|
30
|
+
*/
|
|
24
31
|
stickers?: Record<string, {
|
|
25
32
|
id: number;
|
|
26
|
-
rotation?: number;
|
|
33
|
+
rotation?: number; /** Physical anchor: a `StickerMarkup` index in `[0, CS2EconomyItem.getStickerSchemaCount())`. */
|
|
27
34
|
schema?: number;
|
|
28
35
|
wear?: number;
|
|
29
36
|
x?: number;
|
|
@@ -50,6 +57,20 @@ declare const CS2_INVENTORY_TIMESTAMP = 1707696138408;
|
|
|
50
57
|
declare const CS2_INVENTORY_EQUIPPABLE_ITEMS: CS2ItemType[];
|
|
51
58
|
declare function getTimestamp(): number;
|
|
52
59
|
declare function getNextUid(map: Map<number, unknown>): number;
|
|
60
|
+
declare function stickerMapToArray(stickers: Map<number, RecordValue<CS2BaseInventoryItem["stickers"]>> | undefined): RecordValue<CS2BaseInventoryItem["stickers"]>[];
|
|
61
|
+
declare function toStickerMap(stickers: CS2BaseInventoryItem["stickers"]): Map<number, RecordValue<CS2BaseInventoryItem["stickers"]>> | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Normalizes a stored sticker offset so healed data passes validation: drops non-finite values,
|
|
64
|
+
* truncates onto the {@link CS2_STICKER_OFFSET_FACTOR} grid, then clamps into the model's
|
|
65
|
+
* `[min, max]` (pass the item's `getMinimum/MaximumStickerOffsetX/Y()`; each bound skipped when undefined).
|
|
66
|
+
*/
|
|
67
|
+
declare function healStickerOffset(value: number | undefined, min: number | undefined, max: number | undefined): number | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* The schema (StickerMarkup anchor) a freshly applied sticker should occupy: the first anchor in
|
|
70
|
+
* `[0, schemaCount)` no current sticker uses, falling back to `0` once every anchor is taken (so the
|
|
71
|
+
* stack can exceed the schema count). Pass the target's {@link CS2EconomyItem.getStickerSchemaCount}.
|
|
72
|
+
*/
|
|
73
|
+
declare function getNextStickerSchema(stickers: RecordValue<CS2BaseInventoryItem["stickers"]>[], schemaCount: number): number;
|
|
53
74
|
declare class CS2Inventory {
|
|
54
75
|
private economy;
|
|
55
76
|
private items;
|
|
@@ -144,9 +165,8 @@ declare class CS2InventoryItem extends CS2EconomyItem implements Interface<Omit<
|
|
|
144
165
|
language
|
|
145
166
|
}: CS2EconomyItem);
|
|
146
167
|
edit(...sources: Partial<CS2BaseInventoryItem>[]): void;
|
|
147
|
-
static stickersToArray(stickers: CS2BaseInventoryItem["stickers"]): RecordValue<CS2BaseInventoryItem["stickers"]>[];
|
|
168
|
+
static stickersToArray(stickers: CS2BaseInventoryItem["stickers"], schemaCount?: number): RecordValue<CS2BaseInventoryItem["stickers"]>[];
|
|
148
169
|
static stickersFromArray(stickers: RecordValue<CS2BaseInventoryItem["stickers"]>[]): CS2BaseInventoryItem["stickers"];
|
|
149
|
-
static getNextStickerSchema(stickers: RecordValue<CS2BaseInventoryItem["stickers"]>[], maxStickers: number): number;
|
|
150
170
|
allStickers(): [number, MapValue<CS2InventoryItem["stickers"]>][];
|
|
151
171
|
someStickers(): [number, MapValue<CS2InventoryItem["stickers"]>][];
|
|
152
172
|
getStickersCount(): number;
|
|
@@ -163,4 +183,4 @@ declare class CS2InventoryItem extends CS2EconomyItem implements Interface<Omit<
|
|
|
163
183
|
asBase(): CS2BaseInventoryItem;
|
|
164
184
|
}
|
|
165
185
|
//#endregion
|
|
166
|
-
export { CS2BaseInventoryItem, CS2Inventory, CS2InventoryData, CS2InventoryItem, CS2InventoryOptions, CS2InventorySpec, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_TIMESTAMP, CS2_INVENTORY_VERSION, getNextUid, getTimestamp };
|
|
186
|
+
export { CS2BaseInventoryItem, CS2Inventory, CS2InventoryData, CS2InventoryItem, CS2InventoryOptions, CS2InventorySpec, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_TIMESTAMP, CS2_INVENTORY_VERSION, getNextStickerSchema, getNextUid, getTimestamp, healStickerOffset, stickerMapToArray, toStickerMap };
|
package/dist/inventory.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CS2ItemType as e}from"./economy-types.mjs";import{assert as t,ensure as n,float as r}from"./utils.mjs";import{CS2Team as i}from"./teams.mjs";import{CS2_STICKER_WEAR_FACTOR as a}from"./economy-constants.mjs";import{CS2Economy as o,CS2EconomyItem as s}from"./economy.mjs";import{resolveInventoryData as c}from"./inventory-upgrader.mjs";const l=1,u=1707696138408,d=[e.Agent,e.Collectible,e.Gloves,e.Graffiti,e.Melee,e.MusicKit,e.Weapon];function f(){return Math.ceil((Date.now()-u)/1e3)}function p(e){let t=0;for(;;){if(!e.has(t))return t;t++}}function m(e){return _.stickersToArray(e===void 0?void 0:Object.fromEntries(e))}function h(e){return e===void 0?void 0:new Map(Object.entries(e).map(([e,t])=>[parseInt(e,10),t]))}var g=class e{economy;items;options;static parse(e,t){return c(e??void 0,t)}constructor({economy:e,data:t,maxItems:n,storageUnitMaxItems:r}={}){this.economy=e??o,this.items=t===void 0?new Map:this.toInventoryItems(t.items),this.options={maxItems:n??256,storageUnitMaxItems:r??32}}validateAddable(e){e.isGloves()&&t(e.free||!e.base)}validateStickers(e,n){if(e===void 0)return;let r=Object.values(e);t(r.length<=5),t(n===void 0||n.hasStickers());for(let{id:e,wear:i,rotation:o,x:s,y:c,schema:l}of r)this.economy.getById(e).expectSticker(),i!==void 0&&(t(Number.isFinite(i)),t(String(i).length<=String(a).length),t(i>=0&&i<=1)),o!==void 0&&(t(Number.isInteger(o)),t(o>=-180&&o<=180)),s!==void 0&&t(Number.isFinite(s)),c!==void 0&&t(Number.isFinite(c)),l!==void 0&&(t(Number.isInteger(l)),t(l>=0&&l<(n?.getMaximumStickers()??5)))}validateKeychains(e,n){if(e===void 0)return;let r=Object.entries(e);t(r.length<=1),t(n===void 0||n.hasKeychains());for(let[e,{id:n,seed:i,x:a,y:o,z:s}]of r){let r=parseInt(e,10);t(r>=0&&r<=0),this.economy.getById(n).expectKeychain(),i!==void 0&&(t(Number.isFinite(i)),t(Number.isInteger(i)),t(i>=1&&i<=1e5)),a!==void 0&&t(Number.isFinite(a)),o!==void 0&&t(Number.isFinite(o)),s!==void 0&&t(Number.isFinite(s))}}validatePatches(e,n){if(e!==void 0){t(n===void 0||n.isAgent());for(let[n,r]of Object.entries(e)){let e=parseInt(n,10);t(e>=0&&e<=4),t(r===void 0||this.economy.getById(r).isPatch())}}}healBaseInventoryItem(e){if(!this.economy.items.has(e.id))return;let t=this.economy.getById(e.id);if(e.patches!==void 0)if(!t.hasPatches())e.patches=void 0;else for(let[t,n]of Object.entries(e.patches))this.economy.items.has(n)||delete e.patches[t];if(e.stickers!==void 0)if(!t.hasStickers())e.stickers=void 0;else{for(let[t,n]of Object.entries(e.stickers)){if(!this.economy.items.has(n.id)){delete e.stickers[t];continue}n.rotation!==void 0&&(Number.isInteger(n.rotation)&&n.rotation>180&&(n.rotation-=360),(!Number.isInteger(n.rotation)||n.rotation<-180||n.rotation>180)&&(n.rotation=void 0))}e.stickers=_.stickersFromArray(_.stickersToArray(e.stickers))}if(e.keychains!==void 0)if(!t.hasKeychains())e.keychains=void 0;else for(let[t,n]of Object.entries(e.keychains))this.economy.items.has(n.id)||delete e.keychains[t];if(e.wear!==void 0)if(!t.hasWear())e.wear=void 0;else{let n=t.getMinimumWear(),r=t.getMaximumWear();e.wear<n?e.wear=n:e.wear>r&&(e.wear=r),this.economy.safeValidateWear(e.wear,t)||(e.wear=void 0)}}removeInvalidItemReferences(e){this.healBaseInventoryItem(e)}validateBaseInventoryItem({id:e,keychains:t,nameTag:n,patches:r,seed:i,statTrak:a,stickers:o,wear:s}){let c=this.economy.getById(e);this.economy.validateWear(s,c),this.economy.validateSeed(i,c),this.economy.validateNameTag(n,c),this.economy.validateStatTrak(a,c),this.validateAddable(c),this.validatePatches(r,c),this.validateStickers(o,c),this.validateKeychains(t,c)}toInventoryItems(e){return new Map(Object.entries(e).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>{this.healBaseInventoryItem(t);let n=parseInt(e,10);return[n,new _(this,n,t,this.economy.getById(t.id))]}))}toBaseInventoryItems(e){return Object.fromEntries(Array.from(e).map(([e,t])=>[e,t.asBase()]))}stringify(){return JSON.stringify(this.getData())}isFull(){return this.items.size>=this.options.maxItems}add(e){t(!this.isFull());let n=p(this.items),r=this.economy.getById(e.id);return t(!r.isStub()),this.items.set(n,new _(this,n,Object.assign(e,{equipped:void 0,equippedCT:void 0,equippedT:void 0,updatedAt:f()}),r)),this}addInventoryItem(e){t(!this.isFull());let n=p(this.items);return e.equipped=void 0,e.equippedCT=void 0,e.equippedT=void 0,e.uid=n,e.updatedAt=f(),this.items.set(n,e),this}addWithNameTag(e,t,n){return this.get(e).expectNameTag(),this.economy.requireNameTag(n),this.items.delete(e),this.add({id:t,nameTag:n}),this}addWithSticker(e,t,n){let r=this.get(e).expectSticker();return this.items.delete(e),this.add({id:t,stickers:{0:{id:r.id,schema:n}}}),this}edit(e,n){let r=this.get(e);return t(n.id===void 0||n.id===r.id),r.edit(n,{updatedAt:f()}),this}equip(e,n){let r=this.get(e);t(r.equipped===void 0),t(n!==i.CT||r.equippedCT===void 0),t(n!==i.T||r.equippedT===void 0),t(d.includes(r.type)),t(n===void 0||r.teams?.includes(n)),t(n!==void 0||r.teams===void 0);for(let[t,a]of this.items)e===t?(a.equipped=n===void 0?!0:void 0,a.equippedCT=n===i.CT?!0:a.equippedCT,a.equippedT=n===i.T?!0:a.equippedT):a.type===r.type&&(!r.isWeapon()||a.model===r.model)&&(a.equipped=n===void 0?void 0:a.equipped,a.equippedCT=n===i.CT?void 0:a.equippedCT,a.equippedT=n===i.T?void 0:a.equippedT);return this}unequip(e,t){let n=this.get(e);return n.equipped=t===void 0?void 0:n.equipped,n.equippedCT=t===i.CT?void 0:n.equippedCT,n.equippedT=t===i.T?void 0:n.equippedT,this}unlockContainer(e,t,n){let r=this.get(t);this.economy.expectUnlockedItem(r,e);let i=n===void 0?void 0:this.get(n);return this.economy.validateContainerAndKey(r,i),this.items.delete(t),n!==void 0&&this.items.delete(n),this.add({...e.attributes,id:e.id,updatedAt:f()}),this}renameItem(e,t,n){n=this.economy.trimNameTag(n),this.get(e).expectNameTag();let r=this.get(t);return this.economy.validateNameTag(n,r),r.nameTag=n,r.updatedAt=f(),this.items.delete(e),this}renameStorageUnit(e,t){let n=this.economy.trimNameTag(t),r=this.get(e);return r.expectStorageUnit(),this.economy.requireNameTag(n),r.nameTag=n,r.updatedAt=f(),this}isStorageUnitFull(e){return this.get(e).storage?.size===this.options.storageUnitMaxItems}getStorageUnitSize(e){return this.get(e).storage?.size??0}isStorageUnitFilled(e){return this.getStorageUnitSize(e)>0}canDepositToStorageUnit(e,t=1){return this.get(e).nameTag!==void 0&&this.getStorageUnitSize(e)+t<=this.options.storageUnitMaxItems}canRetrieveFromStorageUnit(e,t=1){return this.getStorageUnitSize(e)-t>=0&&this.size()+t<=this.options.maxItems}getStorageUnitItems(e){return Array.from(this.get(e).storage?.values()??[])}depositToStorageUnit(e,n){let r=this.get(e);r.expectStorageUnit(),t(n.length>0),t(this.canDepositToStorageUnit(e,n.length));for(let e of n)t(!this.get(e).isStorageUnit());let i=r.storage??new Map;for(let e of n){let t=p(i);i.set(t,Object.assign(this.get(e),{equipped:void 0,equippedCT:void 0,equippedT:void 0,uid:t})),this.items.delete(e)}return r.storage=i,r.updatedAt=f(),this}retrieveFromStorageUnit(e,r){let i=this.get(e);i.expectStorageUnit();let a=i.storage;t(a!==void 0),t(r.length>0),t(this.canRetrieveFromStorageUnit(e,r.length));for(let e of r)t(a.has(e));for(let e of r){let t=n(a.get(e));this.addInventoryItem(t),a.delete(e)}return i.storage=a.size>0?a:void 0,i.updatedAt=f(),this}applyItemSticker(e,n,r){let i=this.get(e),a=this.get(n).expectSticker();t(i.hasStickers());let o=m(i.stickers);t(o.length<5),o.push({id:a.id,schema:r??_.getNextStickerSchema(o,i.getMaximumStickers())});let s=_.stickersFromArray(o);return this.validateStickers(s,i),i.stickers=h(s),i.updatedAt=f(),this.items.delete(n),this}removeItemSticker(e,n){let r=this.get(e),i=m(r.stickers);return t(i[n]!==void 0),i.splice(n,1),r.stickers=h(_.stickersFromArray(i)),r.updatedAt=f(),this}moveItemSticker(e,r,i){let a=this.get(e),o=m(a.stickers),s=n(o[r]);return t(Number.isInteger(i)&&i>=0&&i<o.length),o.splice(r,1),o.splice(i,0,s),a.stickers=h(_.stickersFromArray(o)),a.updatedAt=f(),this}editItemSticker(e,n,r){let i=this.get(e),a=m(i.stickers);t(a[n]!==void 0),a[n]={...a[n],...r};let o=_.stickersFromArray(a);return this.validateStickers(o,i),i.stickers=h(o),i.updatedAt=f(),this}scrapeItemSticker(e,i,o){let s=this.get(e),c=m(s.stickers),l=n(c[i]),u=l.wear??0,d;return o===void 0?d=r(u+a):(t(Number.isFinite(o)),t(o>u&&o<=1),d=r(o)),d>=1?c.splice(i,1):c[i]={...l,wear:d},s.stickers=h(_.stickersFromArray(c)),s.updatedAt=f(),this}applyItemPatch(e,n,r){t(r>=0&&r<=4);let i=this.get(e).expectAgent(),a=this.get(n).expectPatch();return i.patches??=new Map,t(i.patches.get(r)===void 0),i.patches.set(r,a.id),i.updatedAt=f(),this.items.delete(n),this}removeItemPatch(e,n){let r=this.get(e);return t(r.patches!==void 0),t(r.patches.get(n)!==void 0),r.patches.delete(n),r.patches.size===0&&(r.patches=void 0),r.updatedAt=f(),this}incrementItemStatTrak(e){let n=this.get(e);return t(n.statTrak!==void 0),n.statTrak<999999&&(n.statTrak++,n.updatedAt=f()),this}swapItemsStatTrak(e,n,r){t(n!==r),this.get(e).expectStatTrakSwapTool();let i=this.get(n),a=this.get(r);t(i.statTrak!==void 0&&a.statTrak!==void 0),t(i.type===a.type),t(i.isMusicKit()||i.def===a.def);let o=i.statTrak;return i.statTrak=a.statTrak,i.updatedAt=f(),a.statTrak=o,a.updatedAt=f(),this.items.delete(e),this}remove(e){return this.items.delete(e),this}removeAll(){return this.items.clear(),this}get(e){return n(this.items.get(e))}getAll(){return Array.from(this.items.values())}getAllAsBase(){return Object.values(this.toBaseInventoryItems(this.items))}setAll(e){return this.items=e,this}getData(){return{items:this.toBaseInventoryItems(this.items),version:1}}size(){return this.items.size}move(t={}){return new e({...this.options,economy:this.economy,...t}).setAll(this.items)}},_=class e extends s{inventory;uid;containerId;equipped;equippedCT;equippedT;keychains;nameTag;patches;seed;statTrak;stickers;storage;updatedAt;wear;assign({keychains:n,patches:r,stickers:i,storage:a}){r!==void 0&&(this.patches=new Map(Object.entries(r).filter(([,e])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),i!==void 0&&(this.stickers=h(e.stickersFromArray(e.stickersToArray(i).filter(({id:e})=>this.economy.items.has(e))))),n!==void 0&&(this.keychains=new Map(Object.entries(n).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),a!==void 0&&(t(this.isStorageUnit()),this.storage=new Map(Object.entries(a).filter(([,{id:e}])=>this.economy.items.has(e)).map(([n,r])=>{this.inventory.healBaseInventoryItem(r);let i=this.economy.getById(r.id);t(r.storage===void 0);let a=parseInt(n,10);return[a,new e(this.inventory,a,r,i)]})))}constructor(e,t,n,{economy:r,item:i,language:a}){super(r,i,a),this.inventory=e,this.uid=t,e.validateBaseInventoryItem(n),Object.assign(this,n),this.assign(n)}edit(...e){let t=this.asBase();for(let n of e)Object.assign(t,n);this.inventory.validateBaseInventoryItem(t);for(let t of e)Object.assign(this,t),this.assign(t)}static stickersToArray(e){return e===void 0?[]:Object.entries(e).map(([e,t])=>[parseInt(e,10),t]).sort(([e],[t])=>e-t).slice(0,5).map(([e,t])=>({...t,schema:t.schema??e}))}static stickersFromArray(e){if(e.length!==0)return Object.fromEntries(e.slice(0,5).map((e,t)=>[t,{id:e.id,schema:e.schema??t,wear:e.wear||void 0,rotation:e.rotation||void 0,x:e.x||void 0,y:e.y||void 0}]))}static getNextStickerSchema(e,t){let n=new Set(e.map(({schema:e})=>e));for(let e=0;e<t;e++)if(!n.has(e))return e;return 0}allStickers(){return m(this.stickers).map((e,t)=>[t,e])}someStickers(){return this.allStickers()}getStickersCount(){return this.stickers?.size??0}allKeychains(){let e=[];for(let t=0;t<1;t++){let n=this.keychains?.get(t);e.push([t,n])}return e}someKeychains(){return this.allKeychains().filter(e=>e[1]!==void 0)}getKeychainsCount(){return this.keychains?.size??0}allPatches(){let e=[];for(let t=0;t<5;t++){let n=this.patches?.get(t);e.push([t,n])}return e}somePatches(){return this.allPatches().filter(e=>e[1]!==void 0)}getPatchesCount(){return this.patches?.size??0}getWear(){return this.wear??this.wearMin??0}getStickerWear(e){return this.stickers?.get(e)?.wear??0}getKeychainSeed(e){return this.keychains?.get(e)?.seed??1}getImage(e){return super.getImage(e??this.getWear())}asBase(){return{containerId:this.containerId,equipped:this.equipped,equippedCT:this.equippedCT,equippedT:this.equippedT,id:this.id,keychains:this.keychains===void 0?void 0:Object.fromEntries(this.keychains),nameTag:this.nameTag,patches:this.patches===void 0?void 0:Object.fromEntries(this.patches),seed:this.seed,statTrak:this.statTrak,stickers:this.stickers===void 0?void 0:Object.fromEntries(this.stickers),storage:this.storage===void 0?void 0:Object.fromEntries(Array.from(this.storage).map(([e,t])=>[e,t.asBase()])),updatedAt:this.updatedAt,wear:this.wear}}};export{g as CS2Inventory,_ as CS2InventoryItem,d as CS2_INVENTORY_EQUIPPABLE_ITEMS,u as CS2_INVENTORY_TIMESTAMP,l as CS2_INVENTORY_VERSION,p as getNextUid,f as getTimestamp};
|
|
1
|
+
import{CS2ItemType as e}from"./economy-types.mjs";import{assert as t,clamp as n,ensure as r,isFactorPrecise as i,roundToFactor as a,truncateToFactor as o}from"./utils.mjs";import{CS2Team as s}from"./teams.mjs";import{CS2_STICKER_OFFSET_FACTOR as c,CS2_STICKER_SCRAPE_FACTOR as l,CS2_STICKER_WEAR_FACTOR as u}from"./economy-constants.mjs";import{CS2Economy as d,CS2EconomyItem as f}from"./economy.mjs";import{resolveInventoryData as p}from"./inventory-upgrader.mjs";const m=1,h=1707696138408,g=[e.Agent,e.Collectible,e.Gloves,e.Graffiti,e.Melee,e.MusicKit,e.Weapon];function _(){return Math.ceil((Date.now()-h)/1e3)}function v(e){let t=0;for(;;){if(!e.has(t))return t;t++}}function y(e){return w.stickersToArray(e===void 0?void 0:Object.fromEntries(e))}function b(e){return e===void 0?void 0:new Map(Object.entries(e).map(([e,t])=>[parseInt(e,10),t]))}function x(e,t,n){if(!(e===void 0||!Number.isFinite(e)))return e=o(e,c),t!==void 0&&e<t?t:n!==void 0&&e>n?n:e}function S(e,t){let n=new Set(e.map(({schema:e})=>e));for(let e=0;e<t;e++)if(!n.has(e))return e;return 0}var C=class e{economy;items;options;static parse(e,t){return p(e??void 0,t)}constructor({economy:e,data:t,maxItems:n,storageUnitMaxItems:r}={}){this.economy=e??d,this.items=t===void 0?new Map:this.toInventoryItems(t.items),this.options={maxItems:n??256,storageUnitMaxItems:r??32}}validateAddable(e){e.isGloves()&&t(e.free||!e.base)}validateStickers(e,n){if(e===void 0)return;let r=Object.values(e);t(r.length<=5),t(n===void 0||n.hasStickers());for(let{id:e,wear:a,rotation:o,x:s,y:l,schema:d}of r){if(this.economy.getById(e).expectSticker(),a!==void 0&&(t(i(a,u)),t(a>=0&&a<=1)),o!==void 0&&(t(Number.isInteger(o)),t(o>=-180&&o<=180)),s!==void 0&&(t(i(s,c)),n!==void 0)){let e=n.getMinimumStickerOffsetX(),r=n.getMaximumStickerOffsetX();t(e===void 0||s>=e),t(r===void 0||s<=r)}if(l!==void 0&&(t(i(l,c)),n!==void 0)){let e=n.getMinimumStickerOffsetY(),r=n.getMaximumStickerOffsetY();t(e===void 0||l>=e),t(r===void 0||l<=r)}d!==void 0&&(t(Number.isInteger(d)),t(d>=0&&d<(n?.getStickerSchemaCount()??5)))}}validateKeychains(e,n){if(e===void 0)return;let r=Object.entries(e);t(r.length<=1),t(n===void 0||n.hasKeychains());for(let[e,{id:n,seed:i,x:a,y:o,z:s}]of r){let r=parseInt(e,10);t(r>=0&&r<=0),this.economy.getById(n).expectKeychain(),i!==void 0&&(t(Number.isFinite(i)),t(Number.isInteger(i)),t(i>=1&&i<=1e5)),a!==void 0&&t(Number.isFinite(a)),o!==void 0&&t(Number.isFinite(o)),s!==void 0&&t(Number.isFinite(s))}}validatePatches(e,n){if(e!==void 0){t(n===void 0||n.isAgent());for(let[n,r]of Object.entries(e)){let e=parseInt(n,10);t(e>=0&&e<=4),t(r===void 0||this.economy.getById(r).isPatch())}}}healBaseInventoryItem(e){if(!this.economy.items.has(e.id))return;let t=this.economy.getById(e.id);if(e.patches!==void 0)if(!t.hasPatches())e.patches=void 0;else for(let[t,n]of Object.entries(e.patches))this.economy.items.has(n)||delete e.patches[t];if(e.stickers!==void 0)if(!t.hasStickers())e.stickers=void 0;else{for(let[n,r]of Object.entries(e.stickers)){if(!this.economy.items.has(r.id)){delete e.stickers[n];continue}r.rotation!==void 0&&(Number.isInteger(r.rotation)&&r.rotation>180&&(r.rotation-=360),(!Number.isInteger(r.rotation)||r.rotation<-180||r.rotation>180)&&(r.rotation=void 0)),r.x=x(r.x,t.getMinimumStickerOffsetX(),t.getMaximumStickerOffsetX()),r.y=x(r.y,t.getMinimumStickerOffsetY(),t.getMaximumStickerOffsetY())}e.stickers=w.stickersFromArray(w.stickersToArray(e.stickers,t.getStickerSchemaCount()))}if(e.keychains!==void 0)if(!t.hasKeychains())e.keychains=void 0;else for(let[t,n]of Object.entries(e.keychains))this.economy.items.has(n.id)||delete e.keychains[t];e.wear!==void 0&&(t.hasWear()?(e.wear=n(e.wear,t.getMinimumWear(),t.getMaximumWear()),this.economy.safeValidateWear(e.wear,t)||(e.wear=void 0)):e.wear=void 0)}removeInvalidItemReferences(e){this.healBaseInventoryItem(e)}validateBaseInventoryItem({id:e,keychains:t,nameTag:n,patches:r,seed:i,statTrak:a,stickers:o,wear:s}){let c=this.economy.getById(e);this.economy.validateWear(s,c),this.economy.validateSeed(i,c),this.economy.validateNameTag(n,c),this.economy.validateStatTrak(a,c),this.validateAddable(c),this.validatePatches(r,c),this.validateStickers(o,c),this.validateKeychains(t,c)}toInventoryItems(e){return new Map(Object.entries(e).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>{this.healBaseInventoryItem(t);let n=parseInt(e,10);return[n,new w(this,n,t,this.economy.getById(t.id))]}))}toBaseInventoryItems(e){return Object.fromEntries(Array.from(e).map(([e,t])=>[e,t.asBase()]))}stringify(){return JSON.stringify(this.getData())}isFull(){return this.items.size>=this.options.maxItems}add(e){t(!this.isFull());let n=v(this.items),r=this.economy.getById(e.id);return t(!r.isStub()),this.items.set(n,new w(this,n,Object.assign(e,{equipped:void 0,equippedCT:void 0,equippedT:void 0,updatedAt:_()}),r)),this}addInventoryItem(e){t(!this.isFull());let n=v(this.items);return e.equipped=void 0,e.equippedCT=void 0,e.equippedT=void 0,e.uid=n,e.updatedAt=_(),this.items.set(n,e),this}addWithNameTag(e,t,n){return this.get(e).expectNameTag(),this.economy.requireNameTag(n),this.items.delete(e),this.add({id:t,nameTag:n}),this}addWithSticker(e,t,n){let r=this.get(e).expectSticker();return this.items.delete(e),this.add({id:t,stickers:{0:{id:r.id,schema:n}}}),this}edit(e,n){let r=this.get(e);return t(n.id===void 0||n.id===r.id),r.edit(n,{updatedAt:_()}),this}equip(e,n){let r=this.get(e);t(r.equipped===void 0),t(n!==s.CT||r.equippedCT===void 0),t(n!==s.T||r.equippedT===void 0),t(g.includes(r.type)),t(n===void 0||r.teams?.includes(n)),t(n!==void 0||r.teams===void 0);for(let[t,i]of this.items)e===t?(i.equipped=n===void 0?!0:void 0,i.equippedCT=n===s.CT?!0:i.equippedCT,i.equippedT=n===s.T?!0:i.equippedT):i.type===r.type&&(!r.isWeapon()||i.model===r.model)&&(i.equipped=n===void 0?void 0:i.equipped,i.equippedCT=n===s.CT?void 0:i.equippedCT,i.equippedT=n===s.T?void 0:i.equippedT);return this}unequip(e,t){let n=this.get(e);return n.equipped=t===void 0?void 0:n.equipped,n.equippedCT=t===s.CT?void 0:n.equippedCT,n.equippedT=t===s.T?void 0:n.equippedT,this}unlockContainer(e,t,n){let r=this.get(t);this.economy.expectUnlockedItem(r,e);let i=n===void 0?void 0:this.get(n);return this.economy.validateContainerAndKey(r,i),this.items.delete(t),n!==void 0&&this.items.delete(n),this.add({...e.attributes,id:e.id,updatedAt:_()}),this}renameItem(e,t,n){n=this.economy.trimNameTag(n),this.get(e).expectNameTag();let r=this.get(t);return this.economy.validateNameTag(n,r),r.nameTag=n,r.updatedAt=_(),this.items.delete(e),this}renameStorageUnit(e,t){let n=this.economy.trimNameTag(t),r=this.get(e);return r.expectStorageUnit(),this.economy.requireNameTag(n),r.nameTag=n,r.updatedAt=_(),this}isStorageUnitFull(e){return this.get(e).storage?.size===this.options.storageUnitMaxItems}getStorageUnitSize(e){return this.get(e).storage?.size??0}isStorageUnitFilled(e){return this.getStorageUnitSize(e)>0}canDepositToStorageUnit(e,t=1){return this.get(e).nameTag!==void 0&&this.getStorageUnitSize(e)+t<=this.options.storageUnitMaxItems}canRetrieveFromStorageUnit(e,t=1){return this.getStorageUnitSize(e)-t>=0&&this.size()+t<=this.options.maxItems}getStorageUnitItems(e){return Array.from(this.get(e).storage?.values()??[])}depositToStorageUnit(e,n){let r=this.get(e);r.expectStorageUnit(),t(n.length>0),t(this.canDepositToStorageUnit(e,n.length));for(let e of n)t(!this.get(e).isStorageUnit());let i=r.storage??new Map;for(let e of n){let t=v(i);i.set(t,Object.assign(this.get(e),{equipped:void 0,equippedCT:void 0,equippedT:void 0,uid:t})),this.items.delete(e)}return r.storage=i,r.updatedAt=_(),this}retrieveFromStorageUnit(e,n){let i=this.get(e);i.expectStorageUnit();let a=i.storage;t(a!==void 0),t(n.length>0),t(this.canRetrieveFromStorageUnit(e,n.length));for(let e of n)t(a.has(e));for(let e of n){let t=r(a.get(e));this.addInventoryItem(t),a.delete(e)}return i.storage=a.size>0?a:void 0,i.updatedAt=_(),this}applyItemSticker(e,n,r){let i=this.get(e),a=this.get(n).expectSticker();t(i.hasStickers());let o=y(i.stickers);t(o.length<5),o.push({id:a.id,schema:r??S(o,i.getStickerSchemaCount())});let s=w.stickersFromArray(o);return this.validateStickers(s,i),i.stickers=b(s),i.updatedAt=_(),this.items.delete(n),this}removeItemSticker(e,n){let r=this.get(e),i=y(r.stickers);return t(i[n]!==void 0),i.splice(n,1),r.stickers=b(w.stickersFromArray(i)),r.updatedAt=_(),this}moveItemSticker(e,n,i){let a=this.get(e),o=y(a.stickers),s=r(o[n]);return t(Number.isInteger(i)&&i>=0&&i<o.length),o.splice(n,1),o.splice(i,0,s),a.stickers=b(w.stickersFromArray(o)),a.updatedAt=_(),this}editItemSticker(e,n,r){let i=this.get(e),a=y(i.stickers);t(a[n]!==void 0),a[n]={...a[n],...r};let o=w.stickersFromArray(a);return this.validateStickers(o,i),i.stickers=b(o),i.updatedAt=_(),this}scrapeItemSticker(e,n,i){let o=this.get(e),s=y(o.stickers),c=r(s[n]),d=c.wear??0,f;return i===void 0?f=a(d+l,u):(t(Number.isFinite(i)),t(i>d&&i<=1),f=a(i,u)),(i===void 0?f>1:f>=1)?s.splice(n,1):s[n]={...c,wear:f},o.stickers=b(w.stickersFromArray(s)),o.updatedAt=_(),this}applyItemPatch(e,n,r){t(r>=0&&r<=4);let i=this.get(e).expectAgent(),a=this.get(n).expectPatch();return i.patches??=new Map,t(i.patches.get(r)===void 0),i.patches.set(r,a.id),i.updatedAt=_(),this.items.delete(n),this}removeItemPatch(e,n){let r=this.get(e);return t(r.patches!==void 0),t(r.patches.get(n)!==void 0),r.patches.delete(n),r.patches.size===0&&(r.patches=void 0),r.updatedAt=_(),this}incrementItemStatTrak(e){let n=this.get(e);return t(n.statTrak!==void 0),n.statTrak<999999&&(n.statTrak++,n.updatedAt=_()),this}swapItemsStatTrak(e,n,r){t(n!==r),this.get(e).expectStatTrakSwapTool();let i=this.get(n),a=this.get(r);t(i.statTrak!==void 0&&a.statTrak!==void 0),t(i.type===a.type),t(i.isMusicKit()||i.def===a.def);let o=i.statTrak;return i.statTrak=a.statTrak,i.updatedAt=_(),a.statTrak=o,a.updatedAt=_(),this.items.delete(e),this}remove(e){return this.items.delete(e),this}removeAll(){return this.items.clear(),this}get(e){return r(this.items.get(e))}getAll(){return Array.from(this.items.values())}getAllAsBase(){return Object.values(this.toBaseInventoryItems(this.items))}setAll(e){return this.items=e,this}getData(){return{items:this.toBaseInventoryItems(this.items),version:1}}size(){return this.items.size}move(t={}){return new e({...this.options,economy:this.economy,...t}).setAll(this.items)}},w=class e extends f{inventory;uid;containerId;equipped;equippedCT;equippedT;keychains;nameTag;patches;seed;statTrak;stickers;storage;updatedAt;wear;assign({keychains:n,patches:r,stickers:i,storage:a}){r!==void 0&&(this.patches=new Map(Object.entries(r).filter(([,e])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),i!==void 0&&(this.stickers=b(e.stickersFromArray(e.stickersToArray(i,this.getStickerSchemaCount()).filter(({id:e})=>this.economy.items.has(e))))),n!==void 0&&(this.keychains=new Map(Object.entries(n).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),a!==void 0&&(t(this.isStorageUnit()),this.storage=new Map(Object.entries(a).filter(([,{id:e}])=>this.economy.items.has(e)).map(([n,r])=>{this.inventory.healBaseInventoryItem(r);let i=this.economy.getById(r.id);t(r.storage===void 0);let a=parseInt(n,10);return[a,new e(this.inventory,a,r,i)]})))}constructor(e,t,n,{economy:r,item:i,language:a}){super(r,i,a),this.inventory=e,this.uid=t,e.validateBaseInventoryItem(n),Object.assign(this,n),this.assign(n)}edit(...e){let t=this.asBase();for(let n of e)Object.assign(t,n);this.inventory.validateBaseInventoryItem(t);for(let t of e)Object.assign(this,t),this.assign(t)}static stickersToArray(e,t){if(e===void 0)return[];let n=Object.entries(e).map(([e,t])=>[parseInt(e,10),t]).sort(([e],[t])=>e-t).slice(0,5),r=[];for(let[e,i]of n){let n=i.schema??e;t!==void 0&&(!Number.isInteger(n)||n<0||n>=t)&&(n=S(r,t)),r.push({...i,schema:n})}return r}static stickersFromArray(e){if(e.length!==0)return Object.fromEntries(e.slice(0,5).map((e,t)=>[t,{id:e.id,schema:e.schema??t,wear:e.wear||void 0,rotation:e.rotation||void 0,x:e.x||void 0,y:e.y||void 0}]))}allStickers(){return y(this.stickers).map((e,t)=>[t,e])}someStickers(){return this.allStickers()}getStickersCount(){return this.stickers?.size??0}allKeychains(){let e=[];for(let t=0;t<1;t++){let n=this.keychains?.get(t);e.push([t,n])}return e}someKeychains(){return this.allKeychains().filter(e=>e[1]!==void 0)}getKeychainsCount(){return this.keychains?.size??0}allPatches(){let e=[];for(let t=0;t<5;t++){let n=this.patches?.get(t);e.push([t,n])}return e}somePatches(){return this.allPatches().filter(e=>e[1]!==void 0)}getPatchesCount(){return this.patches?.size??0}getWear(){return this.wear??this.wearMin??0}getStickerWear(e){return this.stickers?.get(e)?.wear??0}getKeychainSeed(e){return this.keychains?.get(e)?.seed??1}getImage(e){return super.getImage(e??this.getWear())}asBase(){return{containerId:this.containerId,equipped:this.equipped,equippedCT:this.equippedCT,equippedT:this.equippedT,id:this.id,keychains:this.keychains===void 0?void 0:Object.fromEntries(this.keychains),nameTag:this.nameTag,patches:this.patches===void 0?void 0:Object.fromEntries(this.patches),seed:this.seed,statTrak:this.statTrak,stickers:this.stickers===void 0?void 0:Object.fromEntries(this.stickers),storage:this.storage===void 0?void 0:Object.fromEntries(Array.from(this.storage).map(([e,t])=>[e,t.asBase()])),updatedAt:this.updatedAt,wear:this.wear}}};export{C as CS2Inventory,w as CS2InventoryItem,g as CS2_INVENTORY_EQUIPPABLE_ITEMS,h as CS2_INVENTORY_TIMESTAMP,m as CS2_INVENTORY_VERSION,S as getNextStickerSchema,v as getNextUid,_ as getTimestamp,x as healStickerOffset,y as stickerMapToArray,b as toStickerMap};
|