@ianlucas/cs2-lib 7.25.0 → 7.26.0

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.
@@ -64,6 +64,8 @@ interface CS2Item {
64
64
  specialsImage?: string | undefined;
65
65
  statTrakless?: boolean | undefined;
66
66
  statTrakOnly?: boolean | undefined;
67
+ legacyStickerSlots?: number | undefined;
68
+ stickerSlots?: number | undefined;
67
69
  teams?: CS2ItemTeamValues | undefined;
68
70
  textureImage?: string | undefined;
69
71
  tint?: number | undefined;
@@ -70,6 +70,7 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
70
70
  index: number | undefined;
71
71
  keys: number[] | undefined;
72
72
  legacy: boolean | undefined;
73
+ legacyStickerSlots: number | undefined;
73
74
  model: string | undefined;
74
75
  modelBinary: string | undefined;
75
76
  name: string;
@@ -77,6 +78,7 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
77
78
  specialsImage: string | undefined;
78
79
  statTrakless: boolean | undefined;
79
80
  statTrakOnly: boolean | undefined;
81
+ stickerSlots: number | undefined;
80
82
  textureImage: string | undefined;
81
83
  tint: number | undefined;
82
84
  tournamentDesc: string | undefined;
@@ -162,6 +164,7 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
162
164
  getMaximumWear(): number;
163
165
  getMinimumSeed(): number;
164
166
  getMaximumSeed(): number;
167
+ getStickerSlotCount(): number;
165
168
  groupContents(): Record<string, CS2EconomyItem[]>;
166
169
  listContents(hideSpecials?: boolean): CS2EconomyItem[];
167
170
  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;use({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))}validateUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),i(e.rawContents?.includes(t)||e.rawSpecials?.includes(t))}},U=class{altName;base;baseId;category;collection;collectionDesc;collectionImage;collectionName;containerType;def;desc;free;id=null;image;index;keys;legacy;model;modelBinary;name=null;rarity=null;specialsImage;statTrakless;statTrakOnly;textureImage;tint;tournamentDesc;type=null;voFallback;voFemale;voPrefix;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}}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){if(i(this.image),this.hasWear()&&e!==void 0){let t=`${this.economy.baseUrl}${this.image}`;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`${this.economy.baseUrl}${this.image}`}getCollectionImage(){return`${this.economy.baseUrl}${this.collectionImage}`}getSpecialsImage(){return this.expectContainer(),i(this.rawSpecials),i(this.specialsImage),`${this.economy.baseUrl}${this.specialsImage}`}getTextureImage(){return`${this.economy.baseUrl}${o(this.textureImage)}`}getModelBinary(){let{modelBinary:e}=this.parent??this;return`${this.economy.baseUrl}${o(e)}`}getMinimumWear(){return this.wearMin??0}getMaximumWear(){return this.wearMax??1}getMinimumSeed(){return this.isKeychain(),1}getMaximumSeed(){return this.isKeychain()?g:v}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,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;use({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))}validateUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),i(e.rawContents?.includes(t)||e.rawSpecials?.includes(t))}},U=class{altName;base;baseId;category;collection;collectionDesc;collectionImage;collectionName;containerType;def;desc;free;id=null;image;index;keys;legacy;legacyStickerSlots;model;modelBinary;name=null;rarity=null;specialsImage;statTrakless;statTrakOnly;stickerSlots;textureImage;tint;tournamentDesc;type=null;voFallback;voFemale;voPrefix;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}}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){if(i(this.image),this.hasWear()&&e!==void 0){let t=`${this.economy.baseUrl}${this.image}`;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`${this.economy.baseUrl}${this.image}`}getCollectionImage(){return`${this.economy.baseUrl}${this.collectionImage}`}getSpecialsImage(){return this.expectContainer(),i(this.rawSpecials),i(this.specialsImage),`${this.economy.baseUrl}${this.specialsImage}`}getTextureImage(){return`${this.economy.baseUrl}${o(this.textureImage)}`}getModelBinary(){let{modelBinary:e}=this.parent??this;return`${this.economy.baseUrl}${o(e)}`}getMinimumWear(){return this.wearMin??0}getMaximumWear(){return this.wearMax??1}getMinimumSeed(){return this.isKeychain(),1}getMaximumSeed(){return this.isKeychain()?g:v}getStickerSlotCount(){return this.parent?.[this.legacy?`legacyStickerSlots`:`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 +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++}}var m=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.entries(e);t(r.length<=5),t(n===void 0||n.hasStickers());for(let[e,{id:n,wear:i,rotation:o,x:s,y:c,schema:l}]of r){let r=parseInt(e,10);t(r>=0&&r<5),this.economy.getById(n).expectSticker(),i!==void 0&&(t(Number.isFinite(i)),t(String(i).length<=String(a).length),t(i>=0&&i<=.9)),o!==void 0&&(t(Number.isInteger(o)),t(o>=0&&o<=359)),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<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}]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))}}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())}}}removeInvalidItemReferences(e){if(e.patches!==void 0)for(let[t,n]of Object.entries(e.patches))this.economy.items.has(n)||delete e.patches[t];if(e.stickers!==void 0)for(let[t,n]of Object.entries(e.stickers))this.economy.items.has(n.id)||delete e.stickers[t]}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.removeInvalidItemReferences(t);let n=parseInt(e,10);return[n,new h(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 h(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:{[n]:{id:r.id}}}),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.validateUnlockedItem(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){t(r>=0&&r<=4);let i=this.get(e),a=this.get(n);return t(i.hasStickers()),a.expectSticker(),i.stickers??=new Map,t(i.stickers.get(r)===void 0),i.stickers.set(r,{id:a.id}),i.updatedAt=f(),this.items.delete(n),this}scrapeItemSticker(e,i){let o=this.get(e);t(o.stickers!==void 0);let s=n(o.stickers.get(i)),c=r((s.wear??0)+a);return c>1?(o.stickers.delete(i),o.stickers.size===0&&(o.stickers=void 0),this):(s.wear=c,o.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)}},h=class e extends s{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=new Map(Object.entries(i).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),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.removeInvalidItemReferences(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){for(let t of e)Object.assign(this,t),this.assign(t)}allStickers(){let e=[];for(let t=0;t<5;t++){let n=this.stickers?.get(t);e.push([t,n])}return e}someStickers(){return this.allStickers().filter(e=>e[1]!==void 0)}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{m as CS2Inventory,h 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,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++}}var m=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.entries(e);t(r.length<=5),t(n===void 0||n.hasStickers());for(let[e,{id:i,wear:o,rotation:s,x:c,y:l,schema:u}]of r){let r=parseInt(e,10);t(r>=0&&r<5),this.economy.getById(i).expectSticker(),o!==void 0&&(t(Number.isFinite(o)),t(String(o).length<=String(a).length),t(o>=0&&o<=.9)),s!==void 0&&(t(Number.isInteger(s)),t(s>=0&&s<=359)),c!==void 0&&t(Number.isFinite(c)),l!==void 0&&t(Number.isFinite(l)),u!==void 0&&(t(Number.isInteger(u)),t(u>=0&&u<(n?.getStickerSlotCount()??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}]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))}}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())}}}removeInvalidItemReferences(e){if(e.patches!==void 0)for(let[t,n]of Object.entries(e.patches))this.economy.items.has(n)||delete e.patches[t];if(e.stickers!==void 0)for(let[t,n]of Object.entries(e.stickers))this.economy.items.has(n.id)||delete e.stickers[t]}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.removeInvalidItemReferences(t);let n=parseInt(e,10);return[n,new h(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 h(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:{[n]:{id:r.id}}}),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.validateUnlockedItem(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){t(r>=0&&r<=4);let i=this.get(e),a=this.get(n);return t(i.hasStickers()),a.expectSticker(),i.stickers??=new Map,t(i.stickers.get(r)===void 0),i.stickers.set(r,{id:a.id}),i.updatedAt=f(),this.items.delete(n),this}scrapeItemSticker(e,i){let o=this.get(e);t(o.stickers!==void 0);let s=n(o.stickers.get(i)),c=r((s.wear??0)+a);return c>1?(o.stickers.delete(i),o.stickers.size===0&&(o.stickers=void 0),this):(s.wear=c,o.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)}},h=class e extends s{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=new Map(Object.entries(i).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),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.removeInvalidItemReferences(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){for(let t of e)Object.assign(this,t),this.assign(t)}allStickers(){let e=[];for(let t=0;t<5;t++){let n=this.stickers?.get(t);e.push([t,n])}return e}someStickers(){return this.allStickers().filter(e=>e[1]!==void 0)}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{m as CS2Inventory,h as CS2InventoryItem,d as CS2_INVENTORY_EQUIPPABLE_ITEMS,u as CS2_INVENTORY_TIMESTAMP,l as CS2_INVENTORY_VERSION,p as getNextUid,f as getTimestamp};