@ianlucas/cs2-lib 9.7.0 → 9.8.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.
@@ -2,6 +2,7 @@ import { Interface } from "./utils.mjs";
2
2
  import { CS2RarityColor, CS2_RARITY_ORDER } from "./economy-container.mjs";
3
3
  import { CS2Bounds, CS2ContainerType, CS2Item, CS2ItemTeam, CS2ItemTranslation, CS2ItemTranslationMap, CS2ItemType, CS2ItemWear, CS2ModelAnimationSkeleton, CS2ModelAnimations, CS2StatTrakMode, CS2UnlockedItem } from "./economy-types.mjs";
4
4
  import { CS2Team } from "./teams.mjs";
5
+ import { CS2ItemAppearance, CS2ItemAppearanceOptions } from "./inventory-types.mjs";
5
6
  //#region src/economy.d.ts
6
7
  type CS2EconomyItemPredicate = Partial<CS2EconomyItem> & {
7
8
  usableByTeam?: CS2Team;
@@ -202,6 +203,7 @@ export declare class CS2EconomyItem implements Interface<CS2Item & CS2ItemTransl
202
203
  hasCharges(): boolean;
203
204
  hasDisplayCase(): boolean;
204
205
  getDisplayCase(): CS2EconomyItem;
206
+ getAppearance(_options?: CS2ItemAppearanceOptions): CS2ItemAppearance;
205
207
  getImageUrl(wear?: number): string;
206
208
  getCollectionImageUrl(): string;
207
209
  getSpecialsImageUrl(): string;
package/dist/economy.mjs CHANGED
@@ -1 +1 @@
1
- import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r,CS2StatTrakMode as i}from"./economy-types.mjs";import{assert as a,compare as o,ensure as s,isFactorPrecise as c,safe as l,truncateToFactor as u}from"./utils.mjs";import{CS2_CONTAINER_ITEMS as d,CS2_DISPLAY_ITEMS as f,CS2_EQUIPMENT_ITEMS as p,CS2_GRAPHIC_ART_ITEMS as m,CS2_KEYCHAINABLE_ITEMS as h,CS2_MACHINEGUN_MODEL_KEYS as g,CS2_MAX_CHARM_DETACHMENT_CHARGES as _,CS2_MAX_FACTORY_NEW_WEAR as v,CS2_MAX_FIELD_TESTED_WEAR as y,CS2_MAX_KEYCHAIN_SEED as b,CS2_MAX_MINIMAL_WEAR_WEAR as x,CS2_MAX_PET_SEED as S,CS2_MAX_SEED as C,CS2_MAX_WELL_WORN_WEAR as w,CS2_MIDTIER_LOADOUT_CATEGORIES as T,CS2_MISC_LOADOUT_CATEGORIES as E,CS2_NAMETAGGABLE_ITEMS as D,CS2_NAMETAG_RE as O,CS2_PAINTABLE_ITEMS as k,CS2_PATCHABLE_ITEMS as A,CS2_PET_BREED_UPGRADE_LEVELS as j,CS2_PET_CHICK_UPGRADE_LEVELS as M,CS2_PET_EGG_UPGRADE_LEVELS as N,CS2_PET_UPGRADE_LEVELS as P,CS2_RIFLE_LOADOUT_CATEGORIES as F,CS2_SEEDABLE_ITEMS as I,CS2_SNIPER_RIFLE_MODEL_KEYS as L,CS2_STATTRAKABLE_ITEMS as R,CS2_STICKERABLE_ITEMS as z,CS2_TEAMS_BOTH as B,CS2_TEAMS_CT as V,CS2_TEAMS_T as H,CS2_WEAR_FACTOR as U}from"./economy-constants.mjs";import{CS2RarityColorName as W,CS2RarityColorOrder as G,CS2RaritySoundName as K,CS2_RARITY_ORDER as q,randomFloat as J,randomInt as Y}from"./economy-container.mjs";function X(e){return function(t){return o(e.type,t.type)&&o(e.isDefault,t.isDefault)&&o(e.modelKey,t.modelKey)&&o(e.isBase,t.isBase)&&o(e.loadoutCategory,t.loadoutCategory)&&(e.usableByTeam===void 0||t.teams===void 0||t.teams.includes(e.usableByTeam))}}var Z=class{baseUrl=`https://cdn.cstrike.app`;categories=new Set;items=new Map;itemsAsArray=[];stickers=new Set;animations={};charmDetachment;stickerDisplayCases=new Map;load({animations:e,assetsBaseUrl:t,items:n,language:r}){this.animations=e??{},this.baseUrl=t??this.baseUrl,this.categories.clear(),this.items.clear(),this.stickers.clear(),this.itemsAsArray=[],this.charmDetachment=void 0,this.stickerDisplayCases.clear();for(let e of n){let t=new Q(this,e,r===void 0?{name:String(e.id)}:s(r[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),r!==void 0&&this.categories.add(s(t.categoryName))),t.isStickerDisplayCase()&&this.stickerDisplayCases.set(s(t.displayedStickerId),t),this.itemsAsArray.push(t)}}getById(e){return s(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return s(this.itemsAsArray.find(X(e)))}filterItems(e){let t=this.itemsAsArray.filter(X(e));return a(t.length>0),t}validateWear(e,t){return e===void 0||(a(c(e,U)),a(e>=0&&e<=1),t!==void 0&&(a(t.hasWear()),a(t.wearMin===void 0||e>=t.wearMin),a(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return l(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0||(a(Number.isFinite(e)),a(Number.isInteger(e)),a(t===void 0||t.hasSeed()),a(e>=(t?.getMinimumSeed()??1)&&e<=(t?.getMaximumSeed()??1e3)),!0)}safeValidateSeed(e,t){return l(()=>this.validateSeed(e,t))}validateStyle(e,t){return e===void 0||(a(Number.isInteger(e)),a(e>=1),a(t===void 0||t.hasStyle()&&e<=t.getStyleCount()),!0)}safeValidateStyle(e,t){return l(()=>this.validateStyle(e,t))}validateUpgradeLevel(e,t){return e===void 0||a((t?.getUpgradeLevels()??P).includes(e)),!0}safeValidateUpgradeLevel(e,t){return l(()=>this.validateUpgradeLevel(e,t))}trimNameTag(e){let t=e?.trim();return t===``?void 0:t}validateNameTag(e,t){return e!==void 0&&e!==``&&(a(t===void 0||t.hasNameTag()),a(O.test(e))),!0}safeValidateNameTag(e,t){return l(()=>this.validateNameTag(e,t))}requireNameTag(e,t){return a(e===void 0||e.length>0),this.validateNameTag(e,t)}safeRequireNameTag(e,t){return l(()=>this.requireNameTag(e,t))}validateCharges(e,t){return e===void 0||(a(t===void 0||t.hasCharges()),a(Number.isInteger(e)),a(e>=1&&e<=(t?.getMaximumCharges()??2**53-1)),!0)}safeValidateCharges(e,t){return l(()=>this.validateCharges(e,t))}validateStatTrak(e,t){return e===void 0||(a(t===void 0||t.hasStatTrak()),a(Number.isInteger(e)),a(e>=0&&e<=999999),!0)}safeValidateStatTrak(e,t){return l(()=>this.validateStatTrak(e,t))}validateContainerAndKey(e,t){return e=this.get(e),e.expectContainer(),t=t===void 0?void 0:this.get(t),t===void 0?a(e.keyIds===void 0):(t.expectKey(),a(e.keyIds!==void 0),a(e.keyIds.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return l(()=>this.validateContainerAndKey(e,t))}getWearFromValue(e){switch(!0){case e<=v:return r.FactoryNew;case e<=x:return r.MinimalWear;case e<=y:return r.FieldTested;case e<=w:return r.WellWorn;default:return r.BattleScarred}}getStickerCategories(){return Array.from(this.categories).sort()}getStickers(){return Array.from(this.stickers)}getCharmDetachment(){return this.charmDetachment??=s(this.itemsAsArray.find(e=>e.isCharmDetachment())),this.charmDetachment}getStickerDisplayCase(e){return s(this.stickerDisplayCases.get(this.get(e).expectSticker().id))}hasStickerDisplayCase(e){return this.stickerDisplayCases.has(this.get(e).expectSticker().id)}expectUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),a(e.contentIds?.includes(t)||e.specialIds?.includes(t))}resolveUrl(e){return`${this.baseUrl}${e}`}getAnimationUrl(e){let t=this.getAnimation(e);return t&&this.resolveUrl(t.path)}getAnimationSkeleton(e){return this.getAnimation(e)?.skeleton}getAnimationNames(e){return Object.entries(this.animations).filter(([,t])=>e===void 0||t.skeleton===e).map(([e])=>e)}getAnimation(e){return Object.hasOwn(this.animations,e)?this.animations[e]:void 0}},Q=class{economy;item;language;alternateName;categoryName;collectionDescription;collectionImagePath;collectionKey;collectionName;containerType;contentIds;definitionIndex;description;displayedStickerId;hasColliderData;id=null;imagePath;isBase;isDefault;isLegacyModel;keychainPositionXMax;keychainPositionXMin;keychainPositionYMax;keychainPositionYMin;keychainPositionZMax;keychainPositionZMin;keyIds;legacyKeychainPositionXMax;legacyKeychainPositionXMin;legacyKeychainPositionYMax;legacyKeychainPositionYMin;legacyKeychainPositionZMax;legacyKeychainPositionZMin;legacyStickerOffsetXMax;legacyStickerOffsetXMin;legacyStickerOffsetYMax;legacyStickerOffsetYMin;legacyStickerSchemaCount;loadoutCategory;materialPath;modelKey;modelPath;name=null;parentId;previewSeed;rarityColor=null;specialIds;specialsImagePath;statTrakMode;stickerOffsetXMax;stickerOffsetXMin;stickerOffsetYMax;stickerOffsetYMin;stickerSchemaCount;styleCount;team;tintIndex;tournamentDescription;type=null;variantIndex;wearMax;wearMin;constructor(e,t,r){this.economy=e,this.item=t,this.language=r,Object.assign(this,t),Object.assign(this,r),a(typeof this.id==`number`),a(this.name),a(this.type),a(t.type===n.Stub||typeof this.rarityColor==`string`)}get contents(){return this.expectContainer(),s(this.contentIds).map(e=>this.economy.get(e))}get displayedSticker(){return this.displayedStickerId===void 0?void 0:this.economy.get(this.displayedStickerId)}get parent(){return this.parentId===void 0?void 0:this.economy.items.has(this.parentId)?this.economy.get(this.parentId):void 0}get specials(){return this.expectContainer(),this.specialIds?.map(e=>this.economy.get(e))}get teams(){switch(this.team){case t.Both:return B;case t.T:return H;case t.CT:return V;default:return}}isC4(){return this.loadoutCategory===`c4`}isPistol(){return this.loadoutCategory===`secondary`}isSMG(){return this.loadoutCategory===`smg`}isRifle(){return this.loadoutCategory===`rifle`}isHeavy(){return this.loadoutCategory===`heavy`}isEquipment(){return this.loadoutCategory===`equipment`}isSniperRifle(){return this.modelKey!==void 0&&L.includes(this.modelKey)}isMachinegun(){return this.modelKey!==void 0&&g.includes(this.modelKey)}isInMidTiers(){return this.loadoutCategory!==void 0&&T.includes(this.loadoutCategory)}isInRifles(){return this.loadoutCategory!==void 0&&F.includes(this.loadoutCategory)}isInMisc(){return this.loadoutCategory!==void 0&&E.includes(this.loadoutCategory)}isInEquipments(){return p.includes(this.type)}isInGraphicArts(){return m.includes(this.type)}isInContainers(){return d.includes(this.type)}isInDisplay(){return f.includes(this.type)}isPaintable(){return k.includes(this.type)}isAgent(){return this.type===n.Agent}isCollectible(){return this.type===n.Collectible}isContainer(){return this.type===n.Container}isGloves(){return this.type===n.Gloves}isGraffiti(){return this.type===n.Graffiti}isKey(){return this.type===n.Key}isKeychain(){return this.type===n.Keychain}isMelee(){return this.type===n.Melee}isMusicKit(){return this.type===n.MusicKit}isPatch(){return this.type===n.Patch}isPet(){return this.type===n.Pet}isSticker(){return this.type===n.Sticker}isStub(){return this.type===n.Stub}isTool(){return this.type===n.Tool}isWeapon(){return this.type===n.Weapon}isStorageUnit(){return this.isTool()&&this.definitionIndex===1201}isNameTag(){return this.isTool()&&this.definitionIndex===1200}isStatTrakSwapTool(){return this.isTool()&&this.definitionIndex===1324}isChickenEgg(){return this.isTool()&&this.definitionIndex===4948}isChickenFeed(){return this.isTool()&&this.definitionIndex===4949}isPetEgg(){return this.isPet()&&this.variantIndex===1}isPetChick(){return this.isPet()&&this.variantIndex===2}isNameablePet(){return this.isPet()&&!this.isPetEgg()}isContract(){return this.isTool()&&this.definitionIndex===62}isCharmDetachment(){return this.isTool()&&this.definitionIndex===65}isCharmDetachmentPack(){return this.isTool()&&this.definitionIndex===4950}isStickerSlab(){return this.isTool()&&this.definitionIndex===1355}isStickerDisplayCase(){return this.isKeychain()&&this.displayedStickerId!==void 0}isWeaponCase(){return this.containerType===e.WeaponCase}isStickerCapsule(){return this.containerType===e.StickerCapsule}isGraffitiBox(){return this.containerType===e.GraffitiBox}isSouvenirCase(){return this.containerType===e.SouvenirCase}expectAgent(){return a(this.isAgent()),this}expectContainer(){return a(this.isContainer()),this}expectKey(){return a(this.isKey()),this}expectKeychain(){return a(this.isKeychain()),this}expectPatch(){return a(this.isPatch()),this}expectPet(){return a(this.isPet()),this}expectSticker(){return a(this.isSticker()),this}expectStorageUnit(){return a(this.isStorageUnit()),this}expectNameTag(){return a(this.isNameTag()),this}expectStatTrakSwapTool(){return a(this.isStatTrakSwapTool()),this}expectCharmDetachmentPack(){return a(this.isCharmDetachmentPack()),this}expectStickerSlab(){return a(this.isStickerSlab()),this}expectStickerDisplayCase(){return a(this.isStickerDisplayCase()),this}hasWear(){return k.includes(this.type)&&!this.isDefault&&this.variantIndex!==0}hasSeed(){return I.includes(this.type)&&!this.isDefault&&this.variantIndex!==0}hasStickers(){return z.includes(this.type)}hasKeychains(){return h.includes(this.type)}hasPatches(){return A.includes(this.type)&&!this.isDefault}hasNameTag(){return D.includes(this.type)||this.isStorageUnit()||this.isNameablePet()}hasStyle(){return this.isPet()&&this.getStyleCount()>0}hasUpgradeLevel(){return this.isPet()}hasStatTrak(){return R.includes(this.type)&&!this.isDefault}hasCharges(){return this.isGraffiti()||this.isCharmDetachment()}hasDisplayCase(){return this.economy.hasStickerDisplayCase(this)}getDisplayCase(){return this.economy.getStickerDisplayCase(this)}getImageUrl(e){a(this.imagePath);let t=this.economy.resolveUrl(this.imagePath);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}getCollectionImageUrl(){return this.economy.resolveUrl(this.collectionImagePath)}getSpecialsImageUrl(){return this.expectContainer(),a(this.specialIds),a(this.specialsImagePath),this.economy.resolveUrl(this.specialsImagePath)}getMaterialUrl(){return this.economy.resolveUrl(this.materialPath??this.parent?.materialPath)}getModelPath(){return this.modelPath??this.parent?.modelPath}getModelUrl(){return this.economy.resolveUrl(this.getModelPath())}getModelDataUrl(){return this.economy.resolveUrl(this.getModelPath()?.replace(/\.glb$/,`.json`))}getColliderDataUrl(){if(this.hasColliderData??this.parent?.hasColliderData)return this.economy.resolveUrl(this.getModelPath()?.replace(/\.glb$/,`.collider.json`))}getMinimumWear(){return this.wearMin??0}getMaximumWear(){return this.wearMax??1}getMinimumSeed(){return this.isKeychain()||this.isPet(),1}getMaximumSeed(){return this.isKeychain()?b:this.isPet()?S:C}getStyleCount(){return this.styleCount??0}getUpgradeLevels(){return this.isPet()?this.isPetEgg()?N:this.isPetChick()?M:j:[]}getDefaultUpgradeLevel(){return this.getUpgradeLevels().at(-1)}getPreviewSeed(){return this.previewSeed??5e4}getDefaultCharges(){return this.isGraffiti()?50:1}getMaximumCharges(){return this.isGraffiti()?50:_}getStickerSchemaCount(){let e=this.parent??this;return(this.isLegacyModel?e.legacyStickerSchemaCount:e.stickerSchemaCount)??5}getStickerOffsetBounds(){let e=this.parent??this,t=this.isLegacyModel;return{x:{min:t?e.legacyStickerOffsetXMin:e.stickerOffsetXMin,max:t?e.legacyStickerOffsetXMax:e.stickerOffsetXMax},y:{min:t?e.legacyStickerOffsetYMin:e.stickerOffsetYMin,max:t?e.legacyStickerOffsetYMax:e.stickerOffsetYMax}}}getKeychainPositionBounds(){let e=this.parent??this,t=this.isLegacyModel;return{x:{min:t?e.legacyKeychainPositionXMin:e.keychainPositionXMin,max:t?e.legacyKeychainPositionXMax:e.keychainPositionXMax},y:{min:t?e.legacyKeychainPositionYMin:e.keychainPositionYMin,max:t?e.legacyKeychainPositionYMax:e.keychainPositionYMax},z:{min:t?e.legacyKeychainPositionZMin:e.keychainPositionZMin,max:t?e.legacyKeychainPositionZMax:e.keychainPositionZMax}}}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=W[t.rarityColor];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)=>(G[e.rarityColor]??0)-(G[t.rarityColor]??0))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=q.filter(e=>n.includes(e)),a=e?.computeOdds?.(r)??r.map((e,t)=>.8/5**t),o=a.reduce((e,t)=>e+t,0),c=r.map((e,t)=>[e,s(a[t])/o]),l=Math.random(),[d]=s(c[0]),f=0;for(let[e,t]of c)if(f+=t,l<=f){d=e;break}let p=s(t[d]),m=s(p[Math.floor(Math.random()*p.length)]);return{attributes:{containerId:this.id,seed:m.hasSeed()?Y(1,C):void 0,statTrak:m.hasStatTrak()&&this.statTrakMode!==i.Excluded&&(this.statTrakMode===i.Guaranteed||Math.random()<=.1)?0:void 0,wear:m.hasWear()?u(J(m.wearMin??0,m.wearMax??1),U):void 0},id:m.id,rarity:K[m.rarityColor],special:d===`special`}}};const $=new Z;export{$ as CS2Economy,Z as CS2EconomyInstance,Q as CS2EconomyItem};
1
+ import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r,CS2StatTrakMode as i}from"./economy-types.mjs";import{assert as a,compare as o,ensure as s,isFactorPrecise as c,safe as l,truncateToFactor as u}from"./utils.mjs";import{CS2_CONTAINER_ITEMS as d,CS2_DISPLAY_ITEMS as f,CS2_EQUIPMENT_ITEMS as p,CS2_GRAPHIC_ART_ITEMS as m,CS2_KEYCHAINABLE_ITEMS as h,CS2_MACHINEGUN_MODEL_KEYS as g,CS2_MAX_CHARM_DETACHMENT_CHARGES as _,CS2_MAX_FACTORY_NEW_WEAR as v,CS2_MAX_FIELD_TESTED_WEAR as y,CS2_MAX_KEYCHAIN_SEED as b,CS2_MAX_MINIMAL_WEAR_WEAR as x,CS2_MAX_PET_SEED as S,CS2_MAX_SEED as C,CS2_MAX_WELL_WORN_WEAR as w,CS2_MIDTIER_LOADOUT_CATEGORIES as T,CS2_MISC_LOADOUT_CATEGORIES as E,CS2_NAMETAGGABLE_ITEMS as D,CS2_NAMETAG_RE as O,CS2_PAINTABLE_ITEMS as k,CS2_PATCHABLE_ITEMS as A,CS2_PET_BREED_UPGRADE_LEVELS as j,CS2_PET_CHICK_UPGRADE_LEVELS as M,CS2_PET_EGG_UPGRADE_LEVELS as N,CS2_PET_UPGRADE_LEVELS as P,CS2_RIFLE_LOADOUT_CATEGORIES as F,CS2_SEEDABLE_ITEMS as I,CS2_SNIPER_RIFLE_MODEL_KEYS as L,CS2_STATTRAKABLE_ITEMS as R,CS2_STICKERABLE_ITEMS as z,CS2_TEAMS_BOTH as B,CS2_TEAMS_CT as V,CS2_TEAMS_T as H,CS2_WEAR_FACTOR as U}from"./economy-constants.mjs";import{CS2RarityColorName as W,CS2RarityColorOrder as G,CS2RaritySoundName as K,CS2_RARITY_ORDER as q,randomFloat as J,randomInt as Y}from"./economy-container.mjs";function X(e){return function(t){return o(e.type,t.type)&&o(e.isDefault,t.isDefault)&&o(e.modelKey,t.modelKey)&&o(e.isBase,t.isBase)&&o(e.loadoutCategory,t.loadoutCategory)&&(e.usableByTeam===void 0||t.teams===void 0||t.teams.includes(e.usableByTeam))}}var Z=class{baseUrl=`https://cdn.cstrike.app`;categories=new Set;items=new Map;itemsAsArray=[];stickers=new Set;animations={};charmDetachment;stickerDisplayCases=new Map;load({animations:e,assetsBaseUrl:t,items:n,language:r}){this.animations=e??{},this.baseUrl=t??this.baseUrl,this.categories.clear(),this.items.clear(),this.stickers.clear(),this.itemsAsArray=[],this.charmDetachment=void 0,this.stickerDisplayCases.clear();for(let e of n){let t=new Q(this,e,r===void 0?{name:String(e.id)}:s(r[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),r!==void 0&&this.categories.add(s(t.categoryName))),t.isStickerDisplayCase()&&this.stickerDisplayCases.set(s(t.displayedStickerId),t),this.itemsAsArray.push(t)}}getById(e){return s(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return s(this.itemsAsArray.find(X(e)))}filterItems(e){let t=this.itemsAsArray.filter(X(e));return a(t.length>0),t}validateWear(e,t){return e===void 0||(a(c(e,U)),a(e>=0&&e<=1),t!==void 0&&(a(t.hasWear()),a(t.wearMin===void 0||e>=t.wearMin),a(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return l(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0||(a(Number.isFinite(e)),a(Number.isInteger(e)),a(t===void 0||t.hasSeed()),a(e>=(t?.getMinimumSeed()??1)&&e<=(t?.getMaximumSeed()??1e3)),!0)}safeValidateSeed(e,t){return l(()=>this.validateSeed(e,t))}validateStyle(e,t){return e===void 0||(a(Number.isInteger(e)),a(e>=1),a(t===void 0||t.hasStyle()&&e<=t.getStyleCount()),!0)}safeValidateStyle(e,t){return l(()=>this.validateStyle(e,t))}validateUpgradeLevel(e,t){return e===void 0||a((t?.getUpgradeLevels()??P).includes(e)),!0}safeValidateUpgradeLevel(e,t){return l(()=>this.validateUpgradeLevel(e,t))}trimNameTag(e){let t=e?.trim();return t===``?void 0:t}validateNameTag(e,t){return e!==void 0&&e!==``&&(a(t===void 0||t.hasNameTag()),a(O.test(e))),!0}safeValidateNameTag(e,t){return l(()=>this.validateNameTag(e,t))}requireNameTag(e,t){return a(e===void 0||e.length>0),this.validateNameTag(e,t)}safeRequireNameTag(e,t){return l(()=>this.requireNameTag(e,t))}validateCharges(e,t){return e===void 0||(a(t===void 0||t.hasCharges()),a(Number.isInteger(e)),a(e>=1&&e<=(t?.getMaximumCharges()??2**53-1)),!0)}safeValidateCharges(e,t){return l(()=>this.validateCharges(e,t))}validateStatTrak(e,t){return e===void 0||(a(t===void 0||t.hasStatTrak()),a(Number.isInteger(e)),a(e>=0&&e<=999999),!0)}safeValidateStatTrak(e,t){return l(()=>this.validateStatTrak(e,t))}validateContainerAndKey(e,t){return e=this.get(e),e.expectContainer(),t=t===void 0?void 0:this.get(t),t===void 0?a(e.keyIds===void 0):(t.expectKey(),a(e.keyIds!==void 0),a(e.keyIds.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return l(()=>this.validateContainerAndKey(e,t))}getWearFromValue(e){switch(!0){case e<=v:return r.FactoryNew;case e<=x:return r.MinimalWear;case e<=y:return r.FieldTested;case e<=w:return r.WellWorn;default:return r.BattleScarred}}getStickerCategories(){return Array.from(this.categories).sort()}getStickers(){return Array.from(this.stickers)}getCharmDetachment(){return this.charmDetachment??=s(this.itemsAsArray.find(e=>e.isCharmDetachment())),this.charmDetachment}getStickerDisplayCase(e){return s(this.stickerDisplayCases.get(this.get(e).expectSticker().id))}hasStickerDisplayCase(e){return this.stickerDisplayCases.has(this.get(e).expectSticker().id)}expectUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),a(e.contentIds?.includes(t)||e.specialIds?.includes(t))}resolveUrl(e){return`${this.baseUrl}${e}`}getAnimationUrl(e){let t=this.getAnimation(e);return t&&this.resolveUrl(t.path)}getAnimationSkeleton(e){return this.getAnimation(e)?.skeleton}getAnimationNames(e){return Object.entries(this.animations).filter(([,t])=>e===void 0||t.skeleton===e).map(([e])=>e)}getAnimation(e){return Object.hasOwn(this.animations,e)?this.animations[e]:void 0}},Q=class{economy;item;language;alternateName;categoryName;collectionDescription;collectionImagePath;collectionKey;collectionName;containerType;contentIds;definitionIndex;description;displayedStickerId;hasColliderData;id=null;imagePath;isBase;isDefault;isLegacyModel;keychainPositionXMax;keychainPositionXMin;keychainPositionYMax;keychainPositionYMin;keychainPositionZMax;keychainPositionZMin;keyIds;legacyKeychainPositionXMax;legacyKeychainPositionXMin;legacyKeychainPositionYMax;legacyKeychainPositionYMin;legacyKeychainPositionZMax;legacyKeychainPositionZMin;legacyStickerOffsetXMax;legacyStickerOffsetXMin;legacyStickerOffsetYMax;legacyStickerOffsetYMin;legacyStickerSchemaCount;loadoutCategory;materialPath;modelKey;modelPath;name=null;parentId;previewSeed;rarityColor=null;specialIds;specialsImagePath;statTrakMode;stickerOffsetXMax;stickerOffsetXMin;stickerOffsetYMax;stickerOffsetYMin;stickerSchemaCount;styleCount;team;tintIndex;tournamentDescription;type=null;variantIndex;wearMax;wearMin;constructor(e,t,r){this.economy=e,this.item=t,this.language=r,Object.assign(this,t),Object.assign(this,r),a(typeof this.id==`number`),a(this.name),a(this.type),a(t.type===n.Stub||typeof this.rarityColor==`string`)}get contents(){return this.expectContainer(),s(this.contentIds).map(e=>this.economy.get(e))}get displayedSticker(){return this.displayedStickerId===void 0?void 0:this.economy.get(this.displayedStickerId)}get parent(){return this.parentId===void 0?void 0:this.economy.items.has(this.parentId)?this.economy.get(this.parentId):void 0}get specials(){return this.expectContainer(),this.specialIds?.map(e=>this.economy.get(e))}get teams(){switch(this.team){case t.Both:return B;case t.T:return H;case t.CT:return V;default:return}}isC4(){return this.loadoutCategory===`c4`}isPistol(){return this.loadoutCategory===`secondary`}isSMG(){return this.loadoutCategory===`smg`}isRifle(){return this.loadoutCategory===`rifle`}isHeavy(){return this.loadoutCategory===`heavy`}isEquipment(){return this.loadoutCategory===`equipment`}isSniperRifle(){return this.modelKey!==void 0&&L.includes(this.modelKey)}isMachinegun(){return this.modelKey!==void 0&&g.includes(this.modelKey)}isInMidTiers(){return this.loadoutCategory!==void 0&&T.includes(this.loadoutCategory)}isInRifles(){return this.loadoutCategory!==void 0&&F.includes(this.loadoutCategory)}isInMisc(){return this.loadoutCategory!==void 0&&E.includes(this.loadoutCategory)}isInEquipments(){return p.includes(this.type)}isInGraphicArts(){return m.includes(this.type)}isInContainers(){return d.includes(this.type)}isInDisplay(){return f.includes(this.type)}isPaintable(){return k.includes(this.type)}isAgent(){return this.type===n.Agent}isCollectible(){return this.type===n.Collectible}isContainer(){return this.type===n.Container}isGloves(){return this.type===n.Gloves}isGraffiti(){return this.type===n.Graffiti}isKey(){return this.type===n.Key}isKeychain(){return this.type===n.Keychain}isMelee(){return this.type===n.Melee}isMusicKit(){return this.type===n.MusicKit}isPatch(){return this.type===n.Patch}isPet(){return this.type===n.Pet}isSticker(){return this.type===n.Sticker}isStub(){return this.type===n.Stub}isTool(){return this.type===n.Tool}isWeapon(){return this.type===n.Weapon}isStorageUnit(){return this.isTool()&&this.definitionIndex===1201}isNameTag(){return this.isTool()&&this.definitionIndex===1200}isStatTrakSwapTool(){return this.isTool()&&this.definitionIndex===1324}isChickenEgg(){return this.isTool()&&this.definitionIndex===4948}isChickenFeed(){return this.isTool()&&this.definitionIndex===4949}isPetEgg(){return this.isPet()&&this.variantIndex===1}isPetChick(){return this.isPet()&&this.variantIndex===2}isNameablePet(){return this.isPet()&&!this.isPetEgg()}isContract(){return this.isTool()&&this.definitionIndex===62}isCharmDetachment(){return this.isTool()&&this.definitionIndex===65}isCharmDetachmentPack(){return this.isTool()&&this.definitionIndex===4950}isStickerSlab(){return this.isTool()&&this.definitionIndex===1355}isStickerDisplayCase(){return this.isKeychain()&&this.displayedStickerId!==void 0}isWeaponCase(){return this.containerType===e.WeaponCase}isStickerCapsule(){return this.containerType===e.StickerCapsule}isGraffitiBox(){return this.containerType===e.GraffitiBox}isSouvenirCase(){return this.containerType===e.SouvenirCase}expectAgent(){return a(this.isAgent()),this}expectContainer(){return a(this.isContainer()),this}expectKey(){return a(this.isKey()),this}expectKeychain(){return a(this.isKeychain()),this}expectPatch(){return a(this.isPatch()),this}expectPet(){return a(this.isPet()),this}expectSticker(){return a(this.isSticker()),this}expectStorageUnit(){return a(this.isStorageUnit()),this}expectNameTag(){return a(this.isNameTag()),this}expectStatTrakSwapTool(){return a(this.isStatTrakSwapTool()),this}expectCharmDetachmentPack(){return a(this.isCharmDetachmentPack()),this}expectStickerSlab(){return a(this.isStickerSlab()),this}expectStickerDisplayCase(){return a(this.isStickerDisplayCase()),this}hasWear(){return k.includes(this.type)&&!this.isDefault&&this.variantIndex!==0}hasSeed(){return I.includes(this.type)&&!this.isDefault&&this.variantIndex!==0}hasStickers(){return z.includes(this.type)}hasKeychains(){return h.includes(this.type)}hasPatches(){return A.includes(this.type)&&!this.isDefault}hasNameTag(){return D.includes(this.type)||this.isStorageUnit()||this.isNameablePet()}hasStyle(){return this.isPet()&&this.getStyleCount()>0}hasUpgradeLevel(){return this.isPet()}hasStatTrak(){return R.includes(this.type)&&!this.isDefault}hasCharges(){return this.isGraffiti()||this.isCharmDetachment()}hasDisplayCase(){return this.economy.hasStickerDisplayCase(this)}getDisplayCase(){return this.economy.getStickerDisplayCase(this)}getAppearance(e){return{id:this.id}}getImageUrl(e){a(this.imagePath);let t=this.economy.resolveUrl(this.imagePath);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}getCollectionImageUrl(){return this.economy.resolveUrl(this.collectionImagePath)}getSpecialsImageUrl(){return this.expectContainer(),a(this.specialIds),a(this.specialsImagePath),this.economy.resolveUrl(this.specialsImagePath)}getMaterialUrl(){return this.economy.resolveUrl(this.materialPath??this.parent?.materialPath)}getModelPath(){return this.modelPath??this.parent?.modelPath}getModelUrl(){return this.economy.resolveUrl(this.getModelPath())}getModelDataUrl(){return this.economy.resolveUrl(this.getModelPath()?.replace(/\.glb$/,`.json`))}getColliderDataUrl(){if(this.hasColliderData??this.parent?.hasColliderData)return this.economy.resolveUrl(this.getModelPath()?.replace(/\.glb$/,`.collider.json`))}getMinimumWear(){return this.wearMin??0}getMaximumWear(){return this.wearMax??1}getMinimumSeed(){return this.isKeychain()||this.isPet(),1}getMaximumSeed(){return this.isKeychain()?b:this.isPet()?S:C}getStyleCount(){return this.styleCount??0}getUpgradeLevels(){return this.isPet()?this.isPetEgg()?N:this.isPetChick()?M:j:[]}getDefaultUpgradeLevel(){return this.getUpgradeLevels().at(-1)}getPreviewSeed(){return this.previewSeed??5e4}getDefaultCharges(){return this.isGraffiti()?50:1}getMaximumCharges(){return this.isGraffiti()?50:_}getStickerSchemaCount(){let e=this.parent??this;return(this.isLegacyModel?e.legacyStickerSchemaCount:e.stickerSchemaCount)??5}getStickerOffsetBounds(){let e=this.parent??this,t=this.isLegacyModel;return{x:{min:t?e.legacyStickerOffsetXMin:e.stickerOffsetXMin,max:t?e.legacyStickerOffsetXMax:e.stickerOffsetXMax},y:{min:t?e.legacyStickerOffsetYMin:e.stickerOffsetYMin,max:t?e.legacyStickerOffsetYMax:e.stickerOffsetYMax}}}getKeychainPositionBounds(){let e=this.parent??this,t=this.isLegacyModel;return{x:{min:t?e.legacyKeychainPositionXMin:e.keychainPositionXMin,max:t?e.legacyKeychainPositionXMax:e.keychainPositionXMax},y:{min:t?e.legacyKeychainPositionYMin:e.keychainPositionYMin,max:t?e.legacyKeychainPositionYMax:e.keychainPositionYMax},z:{min:t?e.legacyKeychainPositionZMin:e.keychainPositionZMin,max:t?e.legacyKeychainPositionZMax:e.keychainPositionZMax}}}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=W[t.rarityColor];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)=>(G[e.rarityColor]??0)-(G[t.rarityColor]??0))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=q.filter(e=>n.includes(e)),a=e?.computeOdds?.(r)??r.map((e,t)=>.8/5**t),o=a.reduce((e,t)=>e+t,0),c=r.map((e,t)=>[e,s(a[t])/o]),l=Math.random(),[d]=s(c[0]),f=0;for(let[e,t]of c)if(f+=t,l<=f){d=e;break}let p=s(t[d]),m=s(p[Math.floor(Math.random()*p.length)]);return{attributes:{containerId:this.id,seed:m.hasSeed()?Y(1,C):void 0,statTrak:m.hasStatTrak()&&this.statTrakMode!==i.Excluded&&(this.statTrakMode===i.Guaranteed||Math.random()<=.1)?0:void 0,wear:m.hasWear()?u(J(m.wearMin??0,m.wearMax??1),U):void 0},id:m.id,rarity:K[m.rarityColor],special:d===`special`}}};const $=new Z;export{$ as CS2Economy,Z as CS2EconomyInstance,Q as CS2EconomyItem};
package/dist/index.d.mts CHANGED
@@ -1,17 +1,17 @@
1
- import { EnumValues, Interface, MapValue, RecordValue, assert, clamp, compare, countDecimals, ensure, fail, float, isFactorPrecise, isNotUndefined, roundToFactor, safe, truncateToFactor } from "./utils.mjs";
1
+ import { EnumValues, Interface, MapValue, RecordValue, assert, clamp, compare, countDecimals, ensure, fail, float, isFactorPrecise, isNotUndefined, roundToFactor, safe, sortRecord, truncateToFactor, withoutUndefined } 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 { CS2Bounds, CS2ContainerType, CS2Item, CS2ItemTeam, CS2ItemTranslation, CS2ItemTranslationByLanguage, CS2ItemTranslationMap, CS2ItemType, CS2ItemWear, CS2ModelAnimation, CS2ModelAnimationSkeleton, CS2ModelAnimations, CS2ModelMaterials, CS2StatTrakMode, CS2UnlockedItem } from "./economy-types.mjs";
4
4
  import { CS2Team, toggleCS2Team } from "./teams.mjs";
5
5
  import { CS2_CHARM_DETACHMENT_PACK_CHARGES, CS2_CHARM_DETACHMENT_PACK_TOOL_DEFINITION_INDEX, CS2_CHARM_DETACHMENT_TOOL_DEFINITION_INDEX, CS2_CHICKEN_EGG_TOOL_DEFINITION_INDEX, CS2_CHICKEN_FEED_TOOL_DEFINITION_INDEX, CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEFINITION_INDEX, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_EQUIPMENT_ITEMS, CS2_FALLBACK_PREVIEW_SEED, CS2_GRAPHIC_ART_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_KEYCHAIN_POSITION_FACTOR, CS2_MACHINEGUN_MODEL_KEYS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_CHARM_DETACHMENT_CHARGES, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_GRAFFITI_CHARGES, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_PET_SEED, 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_LOADOUT_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_CHARGES, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_PET_SEED, CS2_MIN_PET_STYLE, CS2_MIN_SEED, CS2_MIN_STATTRAK, CS2_MIN_STICKER_ROTATION, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR, CS2_MIN_WELL_WORN_WEAR, CS2_MISC_LOADOUT_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEFINITION_INDEX, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_PET_BREED_UPGRADE_LEVELS, CS2_PET_CHICK_UPGRADE_LEVEL, CS2_PET_CHICK_UPGRADE_LEVELS, CS2_PET_CHICK_VARIANT_INDEX, CS2_PET_EGG_UPGRADE_LEVEL, CS2_PET_EGG_UPGRADE_LEVELS, CS2_PET_EGG_VARIANT_INDEX, CS2_PET_HEN_UPGRADE_LEVEL, CS2_PET_PULLET_UPGRADE_LEVEL, CS2_PET_UPGRADE_LEVELS, CS2_RIFLE_LOADOUT_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODEL_KEYS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_SWAP_TOOL_DEFINITION_INDEX, CS2_STICKERABLE_ITEMS, CS2_STICKER_OFFSET_FACTOR, CS2_STICKER_ROTATION_STEP, CS2_STICKER_SCRAPE_FACTOR, CS2_STICKER_SLAB_TOOL_DEFINITION_INDEX, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEFINITION_INDEX, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_WEAR_FACTOR } from "./economy-constants.mjs";
6
+ import { CS2BaseInventoryItem, CS2InventoryData, CS2InventoryOptions, CS2InventorySpec, CS2ItemAppearance, CS2ItemAppearanceOptions } from "./inventory-types.mjs";
6
7
  import { CS2Economy, CS2EconomyInstance, CS2EconomyItem } from "./economy.mjs";
7
- import { CS2BaseInventoryItem, CS2InventoryData, CS2InventoryOptions, CS2InventorySpec } from "./inventory-types.mjs";
8
8
  import { CS2InventoryDecodeError, CS2InventoryDecoded, CS2InventoryDrop, CS2InventoryDropReason, CS2InventoryError, CS2InventoryLoadChanges, CS2InventoryMigrationError, CS2InventoryVersionError, decodeInventoryData } from "./inventory-format.mjs";
9
9
  import { CS2InventoryMigration, CS2_INVENTORY_VERSION, CS2_MIN_INVENTORY_VERSION, migrations } from "./inventory-migrations/index.mjs";
10
- import { CS2InventoryRule, CS2InventoryRuleName, CS2InventoryStorageDrops, CS2_INVENTORY_RULES, assertAddable, assertInventoryItem, assertKeychains, assertPatches, assertStickers, checkAddable, checkAttachable, checkInventoryItem, checkKeychains, checkPatches, checkStickerSchema, checkStickers, checkStorage, getDropReason, getNextStickerSchema, isStorableInStorageUnit, reconcileInventoryItems, repairInventoryItem, snapStickerRotation, validateStickerRotation } from "./inventory-rules.mjs";
10
+ import { CS2InventoryRule, CS2InventoryRuleName, CS2InventoryStorageDrops, CS2_INVENTORY_RULES, assertAddable, assertInventoryItem, assertKeychains, assertPatches, assertStickers, checkAddable, checkAttachable, checkInventoryItem, checkKeychains, checkPatches, checkStickerSchema, checkStickers, checkStorage, getDropReason, getItemAppearance, getNextStickerSchema, isStorableInStorageUnit, reconcileInventoryItems, repairInventoryItem, snapStickerRotation, validateStickerRotation } from "./inventory-rules.mjs";
11
11
  import { CS2Inventory, CS2InventoryItem, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_TIMESTAMP, getNextUid, getTimestamp, stickerMapToArray, toStickerMap } from "./inventory.mjs";
12
12
  import { CS2_ITEMS } from "./items.mjs";
13
13
  import { CS2KeyValues } from "./keyvalues.mjs";
14
14
  import { CS2KeyValues3 } from "./keyvalues3.mjs";
15
15
  import { CS2Map, 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";
16
16
  import { CS2Veto, CS2VetoAction, CS2VetoEvent, CS2VetoMap, CS2VetoTeam, CS2VetoType } from "./veto.mjs";
17
- export { CS2BaseInventoryItem, CS2Bounds, CS2ContainerType, CS2Economy, CS2EconomyInstance, CS2EconomyItem, CS2Inventory, CS2InventoryData, CS2InventoryDecodeError, CS2InventoryDecoded, CS2InventoryDrop, CS2InventoryDropReason, CS2InventoryError, CS2InventoryItem, CS2InventoryLoadChanges, CS2InventoryMigration, CS2InventoryMigrationError, CS2InventoryOptions, CS2InventoryRule, CS2InventoryRuleName, CS2InventorySpec, CS2InventoryStorageDrops, CS2InventoryVersionError, CS2Item, CS2ItemTeam, CS2ItemTranslation, CS2ItemTranslationByLanguage, CS2ItemTranslationMap, CS2ItemType, CS2ItemWear, CS2KeyValues, CS2KeyValues3, CS2Map, CS2ModelAnimation, CS2ModelAnimationSkeleton, CS2ModelAnimations, CS2ModelMaterials, CS2Rarity, CS2RarityColor, CS2RarityColorName, CS2RarityColorOrder, CS2RarityKeys, CS2RaritySoundName, CS2StatTrakMode, CS2Team, CS2UnlockedItem, CS2Veto, CS2VetoAction, CS2VetoEvent, CS2VetoMap, CS2VetoTeam, CS2VetoType, CS2_ALL_MAPS, CS2_ANCIENT_MAP, CS2_ANUBIS_MAP, CS2_BASE_ODD, CS2_CACHE_MAP, CS2_CHARM_DETACHMENT_PACK_CHARGES, CS2_CHARM_DETACHMENT_PACK_TOOL_DEFINITION_INDEX, CS2_CHARM_DETACHMENT_TOOL_DEFINITION_INDEX, CS2_CHICKEN_EGG_TOOL_DEFINITION_INDEX, CS2_CHICKEN_FEED_TOOL_DEFINITION_INDEX, CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEFINITION_INDEX, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_DUST2_MAP, CS2_EQUIPMENT_ITEMS, CS2_FALLBACK_PREVIEW_SEED, CS2_GRAPHIC_ART_ITEMS, CS2_INFERNO_MAP, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_RULES, CS2_INVENTORY_TIMESTAMP, CS2_INVENTORY_VERSION, CS2_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_KEYCHAIN_POSITION_FACTOR, CS2_MACHINEGUN_MODEL_KEYS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_CHARM_DETACHMENT_CHARGES, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_GRAFFITI_CHARGES, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_PET_SEED, 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_LOADOUT_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_CHARGES, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_INVENTORY_VERSION, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_PET_SEED, CS2_MIN_PET_STYLE, 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_LOADOUT_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEFINITION_INDEX, CS2_NUKE_MAP, CS2_OVERPASS_MAP, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_PET_BREED_UPGRADE_LEVELS, CS2_PET_CHICK_UPGRADE_LEVEL, CS2_PET_CHICK_UPGRADE_LEVELS, CS2_PET_CHICK_VARIANT_INDEX, CS2_PET_EGG_UPGRADE_LEVEL, CS2_PET_EGG_UPGRADE_LEVELS, CS2_PET_EGG_VARIANT_INDEX, CS2_PET_HEN_UPGRADE_LEVEL, CS2_PET_PULLET_UPGRADE_LEVEL, CS2_PET_UPGRADE_LEVELS, CS2_RARITIES, CS2_RARITY_COLOR_DEFAULT, CS2_RARITY_ORDER, CS2_RIFLE_LOADOUT_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODEL_KEYS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_ODD, CS2_STATTRAK_SWAP_TOOL_DEFINITION_INDEX, CS2_STICKERABLE_ITEMS, CS2_STICKER_OFFSET_FACTOR, CS2_STICKER_ROTATION_STEP, CS2_STICKER_SCRAPE_FACTOR, CS2_STICKER_SLAB_TOOL_DEFINITION_INDEX, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEFINITION_INDEX, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_TRAIN_MAP, CS2_VERTIGO_MAP, CS2_WEAR_FACTOR, EnumValues, Interface, MapValue, RecordValue, assert, assertAddable, assertInventoryItem, assertKeychains, assertPatches, assertStickers, checkAddable, checkAttachable, checkInventoryItem, checkKeychains, checkPatches, checkStickerSchema, checkStickers, checkStorage, clamp, compare, countDecimals, decodeInventoryData, ensure, fail, float, getDropReason, getMapnameName, getNextStickerSchema, getNextUid, getTimestamp, isFactorPrecise, isNotUndefined, isStorableInStorageUnit, migrations, randomBoolean, randomFloat, randomInt, reconcileInventoryItems, repairInventoryItem, roundToFactor, safe, snapStickerRotation, stickerMapToArray, toStickerMap, toggleCS2Team, truncateToFactor, validateStickerRotation };
17
+ export { CS2BaseInventoryItem, CS2Bounds, CS2ContainerType, CS2Economy, CS2EconomyInstance, CS2EconomyItem, CS2Inventory, CS2InventoryData, CS2InventoryDecodeError, CS2InventoryDecoded, CS2InventoryDrop, CS2InventoryDropReason, CS2InventoryError, CS2InventoryItem, CS2InventoryLoadChanges, CS2InventoryMigration, CS2InventoryMigrationError, CS2InventoryOptions, CS2InventoryRule, CS2InventoryRuleName, CS2InventorySpec, CS2InventoryStorageDrops, CS2InventoryVersionError, CS2Item, CS2ItemAppearance, CS2ItemAppearanceOptions, CS2ItemTeam, CS2ItemTranslation, CS2ItemTranslationByLanguage, CS2ItemTranslationMap, CS2ItemType, CS2ItemWear, CS2KeyValues, CS2KeyValues3, CS2Map, CS2ModelAnimation, CS2ModelAnimationSkeleton, CS2ModelAnimations, CS2ModelMaterials, CS2Rarity, CS2RarityColor, CS2RarityColorName, CS2RarityColorOrder, CS2RarityKeys, CS2RaritySoundName, CS2StatTrakMode, CS2Team, CS2UnlockedItem, CS2Veto, CS2VetoAction, CS2VetoEvent, CS2VetoMap, CS2VetoTeam, CS2VetoType, CS2_ALL_MAPS, CS2_ANCIENT_MAP, CS2_ANUBIS_MAP, CS2_BASE_ODD, CS2_CACHE_MAP, CS2_CHARM_DETACHMENT_PACK_CHARGES, CS2_CHARM_DETACHMENT_PACK_TOOL_DEFINITION_INDEX, CS2_CHARM_DETACHMENT_TOOL_DEFINITION_INDEX, CS2_CHICKEN_EGG_TOOL_DEFINITION_INDEX, CS2_CHICKEN_FEED_TOOL_DEFINITION_INDEX, CS2_CONTAINER_ITEMS, CS2_CONTRACT_TOOL_DEFINITION_INDEX, CS2_DEFAULT_MAX_WEAR, CS2_DEFAULT_MIN_WEAR, CS2_DISPLAY_ITEMS, CS2_DUST2_MAP, CS2_EQUIPMENT_ITEMS, CS2_FALLBACK_PREVIEW_SEED, CS2_GRAPHIC_ART_ITEMS, CS2_INFERNO_MAP, CS2_INVENTORY_EQUIPPABLE_ITEMS, CS2_INVENTORY_RULES, CS2_INVENTORY_TIMESTAMP, CS2_INVENTORY_VERSION, CS2_ITEMS, CS2_KEYCHAINABLE_ITEMS, CS2_KEYCHAIN_POSITION_FACTOR, CS2_MACHINEGUN_MODEL_KEYS, CS2_MAX_BATTLE_SCARRED_WEAR, CS2_MAX_CHARM_DETACHMENT_CHARGES, CS2_MAX_FACTORY_NEW_WEAR, CS2_MAX_FIELD_TESTED_WEAR, CS2_MAX_GRAFFITI_CHARGES, CS2_MAX_KEYCHAINS, CS2_MAX_KEYCHAIN_SEED, CS2_MAX_MINIMAL_WEAR_WEAR, CS2_MAX_PATCHES, CS2_MAX_PET_SEED, 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_LOADOUT_CATEGORIES, CS2_MIN_BATTLE_SCARRED_WEAR, CS2_MIN_CHARGES, CS2_MIN_FACTORY_NEW_WEAR, CS2_MIN_FIELD_TESTED_WEAR, CS2_MIN_INVENTORY_VERSION, CS2_MIN_KEYCHAIN_SEED, CS2_MIN_MINIMAL_WEAR_WEAR, CS2_MIN_PET_SEED, CS2_MIN_PET_STYLE, 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_LOADOUT_CATEGORIES, CS2_NAMETAGGABLE_ITEMS, CS2_NAMETAG_RE, CS2_NAMETAG_TOOL_DEFINITION_INDEX, CS2_NUKE_MAP, CS2_OVERPASS_MAP, CS2_PAINTABLE_ITEMS, CS2_PATCHABLE_ITEMS, CS2_PET_BREED_UPGRADE_LEVELS, CS2_PET_CHICK_UPGRADE_LEVEL, CS2_PET_CHICK_UPGRADE_LEVELS, CS2_PET_CHICK_VARIANT_INDEX, CS2_PET_EGG_UPGRADE_LEVEL, CS2_PET_EGG_UPGRADE_LEVELS, CS2_PET_EGG_VARIANT_INDEX, CS2_PET_HEN_UPGRADE_LEVEL, CS2_PET_PULLET_UPGRADE_LEVEL, CS2_PET_UPGRADE_LEVELS, CS2_RARITIES, CS2_RARITY_COLOR_DEFAULT, CS2_RARITY_ORDER, CS2_RIFLE_LOADOUT_CATEGORIES, CS2_SEEDABLE_ITEMS, CS2_SNIPER_RIFLE_MODEL_KEYS, CS2_STATTRAKABLE_ITEMS, CS2_STATTRAK_ODD, CS2_STATTRAK_SWAP_TOOL_DEFINITION_INDEX, CS2_STICKERABLE_ITEMS, CS2_STICKER_OFFSET_FACTOR, CS2_STICKER_ROTATION_STEP, CS2_STICKER_SCRAPE_FACTOR, CS2_STICKER_SLAB_TOOL_DEFINITION_INDEX, CS2_STICKER_WEAR_FACTOR, CS2_STORAGE_UNIT_TOOL_DEFINITION_INDEX, CS2_TEAMS_BOTH, CS2_TEAMS_CT, CS2_TEAMS_T, CS2_TRAIN_MAP, CS2_VERTIGO_MAP, CS2_WEAR_FACTOR, EnumValues, Interface, MapValue, RecordValue, assert, assertAddable, assertInventoryItem, assertKeychains, assertPatches, assertStickers, checkAddable, checkAttachable, checkInventoryItem, checkKeychains, checkPatches, checkStickerSchema, checkStickers, checkStorage, clamp, compare, countDecimals, decodeInventoryData, ensure, fail, float, getDropReason, getItemAppearance, getMapnameName, getNextStickerSchema, getNextUid, getTimestamp, isFactorPrecise, isNotUndefined, isStorableInStorageUnit, migrations, randomBoolean, randomFloat, randomInt, reconcileInventoryItems, repairInventoryItem, roundToFactor, safe, snapStickerRotation, sortRecord, stickerMapToArray, toStickerMap, toggleCS2Team, truncateToFactor, validateStickerRotation, withoutUndefined };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r,CS2StatTrakMode as i}from"./economy-types.mjs";import{assert as a,clamp as o,compare as s,countDecimals as c,ensure as l,fail as u,float as d,isFactorPrecise as f,isNotUndefined as p,roundToFactor as m,safe as h,truncateToFactor as g}from"./utils.mjs";import{CS2Team as _,toggleCS2Team as v}from"./teams.mjs";import{CS2_CHARM_DETACHMENT_PACK_CHARGES as y,CS2_CHARM_DETACHMENT_PACK_TOOL_DEFINITION_INDEX as b,CS2_CHARM_DETACHMENT_TOOL_DEFINITION_INDEX as x,CS2_CHICKEN_EGG_TOOL_DEFINITION_INDEX as S,CS2_CHICKEN_FEED_TOOL_DEFINITION_INDEX as C,CS2_CONTAINER_ITEMS as w,CS2_CONTRACT_TOOL_DEFINITION_INDEX as T,CS2_DEFAULT_MAX_WEAR as E,CS2_DEFAULT_MIN_WEAR as D,CS2_DISPLAY_ITEMS as O,CS2_EQUIPMENT_ITEMS as k,CS2_FALLBACK_PREVIEW_SEED as A,CS2_GRAPHIC_ART_ITEMS as j,CS2_KEYCHAINABLE_ITEMS as M,CS2_KEYCHAIN_POSITION_FACTOR as N,CS2_MACHINEGUN_MODEL_KEYS as P,CS2_MAX_BATTLE_SCARRED_WEAR as F,CS2_MAX_CHARM_DETACHMENT_CHARGES as I,CS2_MAX_FACTORY_NEW_WEAR as L,CS2_MAX_FIELD_TESTED_WEAR as R,CS2_MAX_GRAFFITI_CHARGES as z,CS2_MAX_KEYCHAINS as B,CS2_MAX_KEYCHAIN_SEED as V,CS2_MAX_MINIMAL_WEAR_WEAR as H,CS2_MAX_PATCHES as U,CS2_MAX_PET_SEED as W,CS2_MAX_SEED as G,CS2_MAX_STATTRAK as K,CS2_MAX_STICKERS as q,CS2_MAX_STICKER_ROTATION as J,CS2_MAX_STICKER_WEAR as Y,CS2_MAX_WEAR as X,CS2_MAX_WELL_WORN_WEAR as Z,CS2_MIDTIER_LOADOUT_CATEGORIES as Q,CS2_MIN_BATTLE_SCARRED_WEAR as $,CS2_MIN_CHARGES as ee,CS2_MIN_FACTORY_NEW_WEAR as te,CS2_MIN_FIELD_TESTED_WEAR as ne,CS2_MIN_KEYCHAIN_SEED as re,CS2_MIN_MINIMAL_WEAR_WEAR as ie,CS2_MIN_PET_SEED as ae,CS2_MIN_PET_STYLE as oe,CS2_MIN_SEED as se,CS2_MIN_STATTRAK as ce,CS2_MIN_STICKER_ROTATION as le,CS2_MIN_STICKER_WEAR as ue,CS2_MIN_WEAR as de,CS2_MIN_WELL_WORN_WEAR as fe,CS2_MISC_LOADOUT_CATEGORIES as pe,CS2_NAMETAGGABLE_ITEMS as me,CS2_NAMETAG_RE as he,CS2_NAMETAG_TOOL_DEFINITION_INDEX as ge,CS2_PAINTABLE_ITEMS as _e,CS2_PATCHABLE_ITEMS as ve,CS2_PET_BREED_UPGRADE_LEVELS as ye,CS2_PET_CHICK_UPGRADE_LEVEL as be,CS2_PET_CHICK_UPGRADE_LEVELS as xe,CS2_PET_CHICK_VARIANT_INDEX as Se,CS2_PET_EGG_UPGRADE_LEVEL as Ce,CS2_PET_EGG_UPGRADE_LEVELS as we,CS2_PET_EGG_VARIANT_INDEX as Te,CS2_PET_HEN_UPGRADE_LEVEL as Ee,CS2_PET_PULLET_UPGRADE_LEVEL as De,CS2_PET_UPGRADE_LEVELS as Oe,CS2_RIFLE_LOADOUT_CATEGORIES as ke,CS2_SEEDABLE_ITEMS as Ae,CS2_SNIPER_RIFLE_MODEL_KEYS as je,CS2_STATTRAKABLE_ITEMS as Me,CS2_STATTRAK_SWAP_TOOL_DEFINITION_INDEX as Ne,CS2_STICKERABLE_ITEMS as Pe,CS2_STICKER_OFFSET_FACTOR as Fe,CS2_STICKER_ROTATION_STEP as Ie,CS2_STICKER_SCRAPE_FACTOR as Le,CS2_STICKER_SLAB_TOOL_DEFINITION_INDEX as Re,CS2_STICKER_WEAR_FACTOR as ze,CS2_STORAGE_UNIT_TOOL_DEFINITION_INDEX as Be,CS2_TEAMS_BOTH as Ve,CS2_TEAMS_CT as He,CS2_TEAMS_T as Ue,CS2_WEAR_FACTOR as We}from"./economy-constants.mjs";import{CS2Rarity as Ge,CS2RarityColor as Ke,CS2RarityColorName as qe,CS2RarityColorOrder as Je,CS2RaritySoundName as Ye,CS2_BASE_ODD as Xe,CS2_RARITIES as Ze,CS2_RARITY_COLOR_DEFAULT as Qe,CS2_RARITY_ORDER as $e,CS2_STATTRAK_ODD as et,randomBoolean as tt,randomFloat as nt,randomInt as rt}from"./economy-container.mjs";import{CS2Economy as it,CS2EconomyInstance as at,CS2EconomyItem as ot}from"./economy.mjs";import{CS2_INVENTORY_VERSION as st,CS2_MIN_INVENTORY_VERSION as ct,migrations as lt}from"./inventory-migrations/index.mjs";import{CS2InventoryDecodeError as ut,CS2InventoryError as dt,CS2InventoryMigrationError as ft,CS2InventoryVersionError as pt,decodeInventoryData as mt}from"./inventory-format.mjs";import{CS2Inventory as ht,CS2InventoryItem as gt,CS2_INVENTORY_EQUIPPABLE_ITEMS as _t,CS2_INVENTORY_TIMESTAMP as vt,getNextUid as yt,getTimestamp as bt,stickerMapToArray as xt,toStickerMap as St}from"./inventory.mjs";import{CS2_INVENTORY_RULES as Ct,assertAddable as wt,assertInventoryItem as Tt,assertKeychains as Et,assertPatches as Dt,assertStickers as Ot,checkAddable as kt,checkAttachable as At,checkInventoryItem as jt,checkKeychains as Mt,checkPatches as Nt,checkStickerSchema as Pt,checkStickers as Ft,checkStorage as It,getDropReason as Lt,getNextStickerSchema as Rt,isStorableInStorageUnit as zt,reconcileInventoryItems as Bt,repairInventoryItem as Vt,snapStickerRotation as Ht,validateStickerRotation as Ut}from"./inventory-rules.mjs";import{CS2_ITEMS as Wt}from"./items.mjs";import{CS2KeyValues as Gt}from"./keyvalues.mjs";import{CS2KeyValues3 as Kt}from"./keyvalues3.mjs";import{CS2_ALL_MAPS as qt,CS2_ANCIENT_MAP as Jt,CS2_ANUBIS_MAP as Yt,CS2_CACHE_MAP as Xt,CS2_DUST2_MAP as Zt,CS2_INFERNO_MAP as Qt,CS2_MIRAGE_MAP as $t,CS2_NUKE_MAP as en,CS2_OVERPASS_MAP as tn,CS2_TRAIN_MAP as nn,CS2_VERTIGO_MAP as rn,getMapnameName as an}from"./maps.mjs";import{CS2Veto as on,CS2VetoAction as sn,CS2VetoType as cn}from"./veto.mjs";export{e as CS2ContainerType,it as CS2Economy,at as CS2EconomyInstance,ot as CS2EconomyItem,ht as CS2Inventory,ut as CS2InventoryDecodeError,dt as CS2InventoryError,gt as CS2InventoryItem,ft as CS2InventoryMigrationError,pt as CS2InventoryVersionError,t as CS2ItemTeam,n as CS2ItemType,r as CS2ItemWear,Gt as CS2KeyValues,Kt as CS2KeyValues3,Ge as CS2Rarity,Ke as CS2RarityColor,qe as CS2RarityColorName,Je as CS2RarityColorOrder,Ye as CS2RaritySoundName,i as CS2StatTrakMode,_ as CS2Team,on as CS2Veto,sn as CS2VetoAction,cn as CS2VetoType,qt as CS2_ALL_MAPS,Jt as CS2_ANCIENT_MAP,Yt as CS2_ANUBIS_MAP,Xe as CS2_BASE_ODD,Xt as CS2_CACHE_MAP,y as CS2_CHARM_DETACHMENT_PACK_CHARGES,b as CS2_CHARM_DETACHMENT_PACK_TOOL_DEFINITION_INDEX,x as CS2_CHARM_DETACHMENT_TOOL_DEFINITION_INDEX,S as CS2_CHICKEN_EGG_TOOL_DEFINITION_INDEX,C as CS2_CHICKEN_FEED_TOOL_DEFINITION_INDEX,w as CS2_CONTAINER_ITEMS,T as CS2_CONTRACT_TOOL_DEFINITION_INDEX,E as CS2_DEFAULT_MAX_WEAR,D as CS2_DEFAULT_MIN_WEAR,O as CS2_DISPLAY_ITEMS,Zt as CS2_DUST2_MAP,k as CS2_EQUIPMENT_ITEMS,A as CS2_FALLBACK_PREVIEW_SEED,j as CS2_GRAPHIC_ART_ITEMS,Qt as CS2_INFERNO_MAP,_t as CS2_INVENTORY_EQUIPPABLE_ITEMS,Ct as CS2_INVENTORY_RULES,vt as CS2_INVENTORY_TIMESTAMP,st as CS2_INVENTORY_VERSION,Wt as CS2_ITEMS,M as CS2_KEYCHAINABLE_ITEMS,N as CS2_KEYCHAIN_POSITION_FACTOR,P as CS2_MACHINEGUN_MODEL_KEYS,F as CS2_MAX_BATTLE_SCARRED_WEAR,I as CS2_MAX_CHARM_DETACHMENT_CHARGES,L as CS2_MAX_FACTORY_NEW_WEAR,R as CS2_MAX_FIELD_TESTED_WEAR,z as CS2_MAX_GRAFFITI_CHARGES,B as CS2_MAX_KEYCHAINS,V as CS2_MAX_KEYCHAIN_SEED,H as CS2_MAX_MINIMAL_WEAR_WEAR,U as CS2_MAX_PATCHES,W as CS2_MAX_PET_SEED,G as CS2_MAX_SEED,K as CS2_MAX_STATTRAK,q as CS2_MAX_STICKERS,J as CS2_MAX_STICKER_ROTATION,Y as CS2_MAX_STICKER_WEAR,X as CS2_MAX_WEAR,Z as CS2_MAX_WELL_WORN_WEAR,Q as CS2_MIDTIER_LOADOUT_CATEGORIES,$ as CS2_MIN_BATTLE_SCARRED_WEAR,ee as CS2_MIN_CHARGES,te as CS2_MIN_FACTORY_NEW_WEAR,ne as CS2_MIN_FIELD_TESTED_WEAR,ct as CS2_MIN_INVENTORY_VERSION,re as CS2_MIN_KEYCHAIN_SEED,ie as CS2_MIN_MINIMAL_WEAR_WEAR,ae as CS2_MIN_PET_SEED,oe as CS2_MIN_PET_STYLE,se as CS2_MIN_SEED,ce as CS2_MIN_STATTRAK,le as CS2_MIN_STICKER_ROTATION,ue as CS2_MIN_STICKER_WEAR,de as CS2_MIN_WEAR,fe as CS2_MIN_WELL_WORN_WEAR,$t as CS2_MIRAGE_MAP,pe as CS2_MISC_LOADOUT_CATEGORIES,me as CS2_NAMETAGGABLE_ITEMS,he as CS2_NAMETAG_RE,ge as CS2_NAMETAG_TOOL_DEFINITION_INDEX,en as CS2_NUKE_MAP,tn as CS2_OVERPASS_MAP,_e as CS2_PAINTABLE_ITEMS,ve as CS2_PATCHABLE_ITEMS,ye as CS2_PET_BREED_UPGRADE_LEVELS,be as CS2_PET_CHICK_UPGRADE_LEVEL,xe as CS2_PET_CHICK_UPGRADE_LEVELS,Se as CS2_PET_CHICK_VARIANT_INDEX,Ce as CS2_PET_EGG_UPGRADE_LEVEL,we as CS2_PET_EGG_UPGRADE_LEVELS,Te as CS2_PET_EGG_VARIANT_INDEX,Ee as CS2_PET_HEN_UPGRADE_LEVEL,De as CS2_PET_PULLET_UPGRADE_LEVEL,Oe as CS2_PET_UPGRADE_LEVELS,Ze as CS2_RARITIES,Qe as CS2_RARITY_COLOR_DEFAULT,$e as CS2_RARITY_ORDER,ke as CS2_RIFLE_LOADOUT_CATEGORIES,Ae as CS2_SEEDABLE_ITEMS,je as CS2_SNIPER_RIFLE_MODEL_KEYS,Me as CS2_STATTRAKABLE_ITEMS,et as CS2_STATTRAK_ODD,Ne as CS2_STATTRAK_SWAP_TOOL_DEFINITION_INDEX,Pe as CS2_STICKERABLE_ITEMS,Fe as CS2_STICKER_OFFSET_FACTOR,Ie as CS2_STICKER_ROTATION_STEP,Le as CS2_STICKER_SCRAPE_FACTOR,Re as CS2_STICKER_SLAB_TOOL_DEFINITION_INDEX,ze as CS2_STICKER_WEAR_FACTOR,Be as CS2_STORAGE_UNIT_TOOL_DEFINITION_INDEX,Ve as CS2_TEAMS_BOTH,He as CS2_TEAMS_CT,Ue as CS2_TEAMS_T,nn as CS2_TRAIN_MAP,rn as CS2_VERTIGO_MAP,We as CS2_WEAR_FACTOR,a as assert,wt as assertAddable,Tt as assertInventoryItem,Et as assertKeychains,Dt as assertPatches,Ot as assertStickers,kt as checkAddable,At as checkAttachable,jt as checkInventoryItem,Mt as checkKeychains,Nt as checkPatches,Pt as checkStickerSchema,Ft as checkStickers,It as checkStorage,o as clamp,s as compare,c as countDecimals,mt as decodeInventoryData,l as ensure,u as fail,d as float,Lt as getDropReason,an as getMapnameName,Rt as getNextStickerSchema,yt as getNextUid,bt as getTimestamp,f as isFactorPrecise,p as isNotUndefined,zt as isStorableInStorageUnit,lt as migrations,tt as randomBoolean,nt as randomFloat,rt as randomInt,Bt as reconcileInventoryItems,Vt as repairInventoryItem,m as roundToFactor,h as safe,Ht as snapStickerRotation,xt as stickerMapToArray,St as toStickerMap,v as toggleCS2Team,g as truncateToFactor,Ut as validateStickerRotation};
1
+ import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r,CS2StatTrakMode as i}from"./economy-types.mjs";import{assert as a,clamp as o,compare as s,countDecimals as c,ensure as l,fail as u,float as d,isFactorPrecise as f,isNotUndefined as p,roundToFactor as m,safe as h,sortRecord as g,truncateToFactor as _,withoutUndefined as v}from"./utils.mjs";import{CS2Team as y,toggleCS2Team as b}from"./teams.mjs";import{CS2_CHARM_DETACHMENT_PACK_CHARGES as x,CS2_CHARM_DETACHMENT_PACK_TOOL_DEFINITION_INDEX as S,CS2_CHARM_DETACHMENT_TOOL_DEFINITION_INDEX as C,CS2_CHICKEN_EGG_TOOL_DEFINITION_INDEX as w,CS2_CHICKEN_FEED_TOOL_DEFINITION_INDEX as T,CS2_CONTAINER_ITEMS as E,CS2_CONTRACT_TOOL_DEFINITION_INDEX as D,CS2_DEFAULT_MAX_WEAR as O,CS2_DEFAULT_MIN_WEAR as k,CS2_DISPLAY_ITEMS as A,CS2_EQUIPMENT_ITEMS as j,CS2_FALLBACK_PREVIEW_SEED as M,CS2_GRAPHIC_ART_ITEMS as N,CS2_KEYCHAINABLE_ITEMS as P,CS2_KEYCHAIN_POSITION_FACTOR as F,CS2_MACHINEGUN_MODEL_KEYS as I,CS2_MAX_BATTLE_SCARRED_WEAR as L,CS2_MAX_CHARM_DETACHMENT_CHARGES as R,CS2_MAX_FACTORY_NEW_WEAR as z,CS2_MAX_FIELD_TESTED_WEAR as B,CS2_MAX_GRAFFITI_CHARGES as V,CS2_MAX_KEYCHAINS as H,CS2_MAX_KEYCHAIN_SEED as U,CS2_MAX_MINIMAL_WEAR_WEAR as W,CS2_MAX_PATCHES as G,CS2_MAX_PET_SEED as K,CS2_MAX_SEED as q,CS2_MAX_STATTRAK as J,CS2_MAX_STICKERS as Y,CS2_MAX_STICKER_ROTATION as X,CS2_MAX_STICKER_WEAR as Z,CS2_MAX_WEAR as Q,CS2_MAX_WELL_WORN_WEAR as $,CS2_MIDTIER_LOADOUT_CATEGORIES as ee,CS2_MIN_BATTLE_SCARRED_WEAR as te,CS2_MIN_CHARGES as ne,CS2_MIN_FACTORY_NEW_WEAR as re,CS2_MIN_FIELD_TESTED_WEAR as ie,CS2_MIN_KEYCHAIN_SEED as ae,CS2_MIN_MINIMAL_WEAR_WEAR as oe,CS2_MIN_PET_SEED as se,CS2_MIN_PET_STYLE as ce,CS2_MIN_SEED as le,CS2_MIN_STATTRAK as ue,CS2_MIN_STICKER_ROTATION as de,CS2_MIN_STICKER_WEAR as fe,CS2_MIN_WEAR as pe,CS2_MIN_WELL_WORN_WEAR as me,CS2_MISC_LOADOUT_CATEGORIES as he,CS2_NAMETAGGABLE_ITEMS as ge,CS2_NAMETAG_RE as _e,CS2_NAMETAG_TOOL_DEFINITION_INDEX as ve,CS2_PAINTABLE_ITEMS as ye,CS2_PATCHABLE_ITEMS as be,CS2_PET_BREED_UPGRADE_LEVELS as xe,CS2_PET_CHICK_UPGRADE_LEVEL as Se,CS2_PET_CHICK_UPGRADE_LEVELS as Ce,CS2_PET_CHICK_VARIANT_INDEX as we,CS2_PET_EGG_UPGRADE_LEVEL as Te,CS2_PET_EGG_UPGRADE_LEVELS as Ee,CS2_PET_EGG_VARIANT_INDEX as De,CS2_PET_HEN_UPGRADE_LEVEL as Oe,CS2_PET_PULLET_UPGRADE_LEVEL as ke,CS2_PET_UPGRADE_LEVELS as Ae,CS2_RIFLE_LOADOUT_CATEGORIES as je,CS2_SEEDABLE_ITEMS as Me,CS2_SNIPER_RIFLE_MODEL_KEYS as Ne,CS2_STATTRAKABLE_ITEMS as Pe,CS2_STATTRAK_SWAP_TOOL_DEFINITION_INDEX as Fe,CS2_STICKERABLE_ITEMS as Ie,CS2_STICKER_OFFSET_FACTOR as Le,CS2_STICKER_ROTATION_STEP as Re,CS2_STICKER_SCRAPE_FACTOR as ze,CS2_STICKER_SLAB_TOOL_DEFINITION_INDEX as Be,CS2_STICKER_WEAR_FACTOR as Ve,CS2_STORAGE_UNIT_TOOL_DEFINITION_INDEX as He,CS2_TEAMS_BOTH as Ue,CS2_TEAMS_CT as We,CS2_TEAMS_T as Ge,CS2_WEAR_FACTOR as Ke}from"./economy-constants.mjs";import{CS2Rarity as qe,CS2RarityColor as Je,CS2RarityColorName as Ye,CS2RarityColorOrder as Xe,CS2RaritySoundName as Ze,CS2_BASE_ODD as Qe,CS2_RARITIES as $e,CS2_RARITY_COLOR_DEFAULT as et,CS2_RARITY_ORDER as tt,CS2_STATTRAK_ODD as nt,randomBoolean as rt,randomFloat as it,randomInt as at}from"./economy-container.mjs";import{CS2Economy as ot,CS2EconomyInstance as st,CS2EconomyItem as ct}from"./economy.mjs";import{CS2_INVENTORY_VERSION as lt,CS2_MIN_INVENTORY_VERSION as ut,migrations as dt}from"./inventory-migrations/index.mjs";import{CS2InventoryDecodeError as ft,CS2InventoryError as pt,CS2InventoryMigrationError as mt,CS2InventoryVersionError as ht,decodeInventoryData as gt}from"./inventory-format.mjs";import{CS2Inventory as _t,CS2InventoryItem as vt,CS2_INVENTORY_EQUIPPABLE_ITEMS as yt,CS2_INVENTORY_TIMESTAMP as bt,getNextUid as xt,getTimestamp as St,stickerMapToArray as Ct,toStickerMap as wt}from"./inventory.mjs";import{CS2_INVENTORY_RULES as Tt,assertAddable as Et,assertInventoryItem as Dt,assertKeychains as Ot,assertPatches as kt,assertStickers as At,checkAddable as jt,checkAttachable as Mt,checkInventoryItem as Nt,checkKeychains as Pt,checkPatches as Ft,checkStickerSchema as It,checkStickers as Lt,checkStorage as Rt,getDropReason as zt,getItemAppearance as Bt,getNextStickerSchema as Vt,isStorableInStorageUnit as Ht,reconcileInventoryItems as Ut,repairInventoryItem as Wt,snapStickerRotation as Gt,validateStickerRotation as Kt}from"./inventory-rules.mjs";import{CS2_ITEMS as qt}from"./items.mjs";import{CS2KeyValues as Jt}from"./keyvalues.mjs";import{CS2KeyValues3 as Yt}from"./keyvalues3.mjs";import{CS2_ALL_MAPS as Xt,CS2_ANCIENT_MAP as Zt,CS2_ANUBIS_MAP as Qt,CS2_CACHE_MAP as $t,CS2_DUST2_MAP as en,CS2_INFERNO_MAP as tn,CS2_MIRAGE_MAP as nn,CS2_NUKE_MAP as rn,CS2_OVERPASS_MAP as an,CS2_TRAIN_MAP as on,CS2_VERTIGO_MAP as sn,getMapnameName as cn}from"./maps.mjs";import{CS2Veto as ln,CS2VetoAction as un,CS2VetoType as dn}from"./veto.mjs";export{e as CS2ContainerType,ot as CS2Economy,st as CS2EconomyInstance,ct as CS2EconomyItem,_t as CS2Inventory,ft as CS2InventoryDecodeError,pt as CS2InventoryError,vt as CS2InventoryItem,mt as CS2InventoryMigrationError,ht as CS2InventoryVersionError,t as CS2ItemTeam,n as CS2ItemType,r as CS2ItemWear,Jt as CS2KeyValues,Yt as CS2KeyValues3,qe as CS2Rarity,Je as CS2RarityColor,Ye as CS2RarityColorName,Xe as CS2RarityColorOrder,Ze as CS2RaritySoundName,i as CS2StatTrakMode,y as CS2Team,ln as CS2Veto,un as CS2VetoAction,dn as CS2VetoType,Xt as CS2_ALL_MAPS,Zt as CS2_ANCIENT_MAP,Qt as CS2_ANUBIS_MAP,Qe as CS2_BASE_ODD,$t as CS2_CACHE_MAP,x as CS2_CHARM_DETACHMENT_PACK_CHARGES,S as CS2_CHARM_DETACHMENT_PACK_TOOL_DEFINITION_INDEX,C as CS2_CHARM_DETACHMENT_TOOL_DEFINITION_INDEX,w as CS2_CHICKEN_EGG_TOOL_DEFINITION_INDEX,T as CS2_CHICKEN_FEED_TOOL_DEFINITION_INDEX,E as CS2_CONTAINER_ITEMS,D as CS2_CONTRACT_TOOL_DEFINITION_INDEX,O as CS2_DEFAULT_MAX_WEAR,k as CS2_DEFAULT_MIN_WEAR,A as CS2_DISPLAY_ITEMS,en as CS2_DUST2_MAP,j as CS2_EQUIPMENT_ITEMS,M as CS2_FALLBACK_PREVIEW_SEED,N as CS2_GRAPHIC_ART_ITEMS,tn as CS2_INFERNO_MAP,yt as CS2_INVENTORY_EQUIPPABLE_ITEMS,Tt as CS2_INVENTORY_RULES,bt as CS2_INVENTORY_TIMESTAMP,lt as CS2_INVENTORY_VERSION,qt as CS2_ITEMS,P as CS2_KEYCHAINABLE_ITEMS,F as CS2_KEYCHAIN_POSITION_FACTOR,I as CS2_MACHINEGUN_MODEL_KEYS,L as CS2_MAX_BATTLE_SCARRED_WEAR,R as CS2_MAX_CHARM_DETACHMENT_CHARGES,z as CS2_MAX_FACTORY_NEW_WEAR,B as CS2_MAX_FIELD_TESTED_WEAR,V as CS2_MAX_GRAFFITI_CHARGES,H as CS2_MAX_KEYCHAINS,U as CS2_MAX_KEYCHAIN_SEED,W as CS2_MAX_MINIMAL_WEAR_WEAR,G as CS2_MAX_PATCHES,K as CS2_MAX_PET_SEED,q as CS2_MAX_SEED,J as CS2_MAX_STATTRAK,Y as CS2_MAX_STICKERS,X as CS2_MAX_STICKER_ROTATION,Z as CS2_MAX_STICKER_WEAR,Q as CS2_MAX_WEAR,$ as CS2_MAX_WELL_WORN_WEAR,ee as CS2_MIDTIER_LOADOUT_CATEGORIES,te as CS2_MIN_BATTLE_SCARRED_WEAR,ne as CS2_MIN_CHARGES,re as CS2_MIN_FACTORY_NEW_WEAR,ie as CS2_MIN_FIELD_TESTED_WEAR,ut as CS2_MIN_INVENTORY_VERSION,ae as CS2_MIN_KEYCHAIN_SEED,oe as CS2_MIN_MINIMAL_WEAR_WEAR,se as CS2_MIN_PET_SEED,ce as CS2_MIN_PET_STYLE,le as CS2_MIN_SEED,ue as CS2_MIN_STATTRAK,de as CS2_MIN_STICKER_ROTATION,fe as CS2_MIN_STICKER_WEAR,pe as CS2_MIN_WEAR,me as CS2_MIN_WELL_WORN_WEAR,nn as CS2_MIRAGE_MAP,he as CS2_MISC_LOADOUT_CATEGORIES,ge as CS2_NAMETAGGABLE_ITEMS,_e as CS2_NAMETAG_RE,ve as CS2_NAMETAG_TOOL_DEFINITION_INDEX,rn as CS2_NUKE_MAP,an as CS2_OVERPASS_MAP,ye as CS2_PAINTABLE_ITEMS,be as CS2_PATCHABLE_ITEMS,xe as CS2_PET_BREED_UPGRADE_LEVELS,Se as CS2_PET_CHICK_UPGRADE_LEVEL,Ce as CS2_PET_CHICK_UPGRADE_LEVELS,we as CS2_PET_CHICK_VARIANT_INDEX,Te as CS2_PET_EGG_UPGRADE_LEVEL,Ee as CS2_PET_EGG_UPGRADE_LEVELS,De as CS2_PET_EGG_VARIANT_INDEX,Oe as CS2_PET_HEN_UPGRADE_LEVEL,ke as CS2_PET_PULLET_UPGRADE_LEVEL,Ae as CS2_PET_UPGRADE_LEVELS,$e as CS2_RARITIES,et as CS2_RARITY_COLOR_DEFAULT,tt as CS2_RARITY_ORDER,je as CS2_RIFLE_LOADOUT_CATEGORIES,Me as CS2_SEEDABLE_ITEMS,Ne as CS2_SNIPER_RIFLE_MODEL_KEYS,Pe as CS2_STATTRAKABLE_ITEMS,nt as CS2_STATTRAK_ODD,Fe as CS2_STATTRAK_SWAP_TOOL_DEFINITION_INDEX,Ie as CS2_STICKERABLE_ITEMS,Le as CS2_STICKER_OFFSET_FACTOR,Re as CS2_STICKER_ROTATION_STEP,ze as CS2_STICKER_SCRAPE_FACTOR,Be as CS2_STICKER_SLAB_TOOL_DEFINITION_INDEX,Ve as CS2_STICKER_WEAR_FACTOR,He as CS2_STORAGE_UNIT_TOOL_DEFINITION_INDEX,Ue as CS2_TEAMS_BOTH,We as CS2_TEAMS_CT,Ge as CS2_TEAMS_T,on as CS2_TRAIN_MAP,sn as CS2_VERTIGO_MAP,Ke as CS2_WEAR_FACTOR,a as assert,Et as assertAddable,Dt as assertInventoryItem,Ot as assertKeychains,kt as assertPatches,At as assertStickers,jt as checkAddable,Mt as checkAttachable,Nt as checkInventoryItem,Pt as checkKeychains,Ft as checkPatches,It as checkStickerSchema,Lt as checkStickers,Rt as checkStorage,o as clamp,s as compare,c as countDecimals,gt as decodeInventoryData,l as ensure,u as fail,d as float,zt as getDropReason,Bt as getItemAppearance,cn as getMapnameName,Vt as getNextStickerSchema,xt as getNextUid,St as getTimestamp,f as isFactorPrecise,p as isNotUndefined,Ht as isStorableInStorageUnit,dt as migrations,rt as randomBoolean,it as randomFloat,at as randomInt,Ut as reconcileInventoryItems,Wt as repairInventoryItem,m as roundToFactor,h as safe,Gt as snapStickerRotation,g as sortRecord,Ct as stickerMapToArray,wt as toStickerMap,b as toggleCS2Team,_ as truncateToFactor,Kt as validateStickerRotation,v as withoutUndefined};
@@ -1,5 +1,5 @@
1
- import { CS2EconomyInstance } from "./economy.mjs";
2
1
  import { CS2InventoryData } from "./inventory-types.mjs";
2
+ import { CS2EconomyInstance } from "./economy.mjs";
3
3
  //#region src/inventory-format.d.ts
4
4
  export declare class CS2InventoryError extends Error {}
5
5
  export declare class CS2InventoryDecodeError extends CS2InventoryError {}
@@ -1,6 +1,6 @@
1
1
  import { RecordValue } from "./utils.mjs";
2
+ import { CS2BaseInventoryItem, CS2InventoryOptions, CS2ItemAppearance, CS2ItemAppearanceOptions } from "./inventory-types.mjs";
2
3
  import { CS2EconomyInstance, CS2EconomyItem } from "./economy.mjs";
3
- import { CS2BaseInventoryItem, CS2InventoryOptions } from "./inventory-types.mjs";
4
4
  import { CS2InventoryDrop, CS2InventoryDropReason } from "./inventory-format.mjs";
5
5
  //#region src/inventory-rules.d.ts
6
6
  export interface CS2InventoryRule<T> {
@@ -33,4 +33,5 @@ export interface CS2InventoryStorageDrops {
33
33
  }
34
34
  export declare function repairInventoryItem(economy: CS2EconomyInstance, item: CS2BaseInventoryItem, storageDrops?: CS2InventoryStorageDrops): boolean;
35
35
  export declare function reconcileInventoryItems(economy: CS2EconomyInstance, items: Record<number, CS2BaseInventoryItem>, options: Readonly<CS2InventoryOptions>): CS2InventoryDrop[];
36
+ export declare function getItemAppearance(item: CS2BaseInventoryItem, { wearFractionDigits }?: CS2ItemAppearanceOptions): CS2ItemAppearance;
36
37
  //#endregion
@@ -1 +1 @@
1
- import{assert as e,clamp as t,ensure as n,isFactorPrecise as r,truncateToFactor as i}from"./utils.mjs";import{CS2_KEYCHAIN_POSITION_FACTOR as a,CS2_MAX_KEYCHAIN_SEED as o,CS2_MAX_STATTRAK as s,CS2_STICKER_OFFSET_FACTOR as c,CS2_STICKER_ROTATION_STEP as l,CS2_STICKER_WEAR_FACTOR as u}from"./economy-constants.mjs";import{CS2InventoryItem as d,getTimestamp as f}from"./inventory.mjs";function p(e,n){return{check(t,i){if(t===void 0)return!0;let{min:a,max:o}=n(i);return r(t,e)&&(a===void 0||t>=a)&&(o===void 0||t<=o)},repair(r,a){if(r===void 0||!Number.isFinite(r))return;let{min:o,max:s}=n(a),c=i(r,e);return t(c,o??c,s??c)}}}function m(e){return{check(t,n){if(t===void 0)return!0;let{min:r,max:i}=e(n);return Number.isInteger(t)&&t>=r&&t<=i},repair(n,r){if(n===void 0||!Number.isFinite(n))return;let{min:i,max:a}=e(r);return t(Math.trunc(n),i,a)}}}function h(e){return e===void 0||Number.isInteger(e/.5)&&e>=-180&&e<=180}function g(e){return Math.round(e/l)*l}const _={itemCharges:{check:(e,t)=>t.economy.safeValidateCharges(e,t),repair(e,n){return e!==void 0&&n.hasCharges()&&Number.isFinite(e)?t(Math.trunc(e),1,n.getMaximumCharges()):void 0}},itemSeed:{check:(e,t)=>t.economy.safeValidateSeed(e,t),repair(e,n){return e!==void 0&&n.hasSeed()&&Number.isFinite(e)?t(Math.trunc(e),n.getMinimumSeed(),n.getMaximumSeed()):void 0}},itemStatTrak:{check:(e,t)=>t.economy.safeValidateStatTrak(e,t),repair(e,n){return e!==void 0&&n.hasStatTrak()&&Number.isFinite(e)?t(Math.trunc(e),0,s):void 0}},itemStyle:{check:(e,t)=>t.economy.safeValidateStyle(e,t),repair:(e,t)=>t.economy.safeValidateStyle(e,t)?e:void 0},itemUpgradeLevel:{check:(e,t)=>t.economy.safeValidateUpgradeLevel(e,t),repair:(e,t)=>t.economy.safeValidateUpgradeLevel(e,t)?e:void 0},itemWear:{check:(e,t)=>t.economy.safeValidateWear(e,t),repair(e,n){if(e===void 0||!n.hasWear())return;let r=t(e,n.getMinimumWear(),n.getMaximumWear());return n.economy.safeValidateWear(r,n)?r:void 0}},keychainPositionX:p(a,e=>e.getKeychainPositionBounds().x),keychainPositionY:p(a,e=>e.getKeychainPositionBounds().y),keychainPositionZ:p(a,e=>e.getKeychainPositionBounds().z),keychainSeed:m(()=>({min:1,max:o})),stickerRotation:{check:e=>h(e),repair(e){if(e===void 0)return;let t=g(e);return h(t)?t:void 0}},stickerSchema:{check:(e,t)=>v(e,t.getStickerSchemaCount()),repair:(e,t)=>v(e,t.getStickerSchemaCount())?e:void 0},stickerWear:p(u,()=>({min:0,max:1})),stickerX:p(c,e=>e.getStickerOffsetBounds().x),stickerY:p(c,e=>e.getStickerOffsetBounds().y)};function v(e,t){return e===void 0||Number.isInteger(e)&&e>=0&&e<t}function y(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}function b(e){return!e.isGloves()||e.isDefault===!0||e.isBase!==!0}function x(t){e(b(t))}function S(e){return e.isDefault!==!0}function C(e,t,n){if(!e.items.has(t))return!1;let r=e.getById(t);return n(r)&&S(r)}function w(e,t,n){if(t===void 0)return!0;let r=Object.values(t);if(r.length>5||!n.hasStickers())return!1;for(let{id:t,wear:i,rotation:a,x:o,y:s,schema:c}of r){if(!e.items.has(t))return!1;let r=e.getById(t);if(!r.isSticker()||!S(r)||!_.stickerWear.check(i,n)||!_.stickerRotation.check(a,n)||!_.stickerX.check(o,n)||!_.stickerY.check(s,n)||!_.stickerSchema.check(c,n))return!1}return!0}function T(t,n,r){e(w(t,n,r))}function E(e,t,n){if(t===void 0)return!0;let r=Object.entries(t);if(r.length>1||!n.hasKeychains())return!1;for(let[t,{id:i,seed:a,x:o,y:s,z:c}]of r){let r=parseInt(t,10);if(r<0||r>0||!e.items.has(i))return!1;let l=e.getById(i);if(!l.isKeychain()||!S(l)||!_.keychainSeed.check(a,n)||!_.keychainPositionX.check(o,n)||!_.keychainPositionY.check(s,n)||!_.keychainPositionZ.check(c,n))return!1}return!0}function D(t,n,r){e(E(t,n,r))}function O(e,t,n){if(t===void 0)return!0;if(!n.hasPatches())return!1;for(let[n,r]of Object.entries(t)){let t=parseInt(n,10);if(t<0||t>2||!e.items.has(r))return!1;let i=e.getById(r);if(!i.isPatch()||!S(i))return!1}return!0}function k(t,n,r){e(O(t,n,r))}function A(e,t,n){if(t===void 0)return!0;if(!n.isStorageUnit())return!1;for(let n of Object.values(t))if(n.storage!==void 0||!e.items.has(n.id)||!j(n,e.getById(n.id))||!M(e,n))return!1;return!0}function j({charges:e},t){return!t.isStorageUnit()&&!t.isCharmDetachment()&&!t.isCharmDetachmentPack()&&!t.isPet()&&!t.isChickenEgg()&&!t.isChickenFeed()&&(!t.hasCharges()||e===void 0)}function M(e,{charges:t,id:n,keychains:r,nameTag:i,patches:a,seed:o,statTrak:s,stickers:c,storage:l,style:u,upgradeLevel:d,wear:f}){if(!e.items.has(n))return!1;let p=e.getById(n);return _.itemWear.check(f,p)&&_.itemCharges.check(t,p)&&_.itemSeed.check(o,p)&&_.itemStatTrak.check(s,p)&&_.itemStyle.check(u,p)&&_.itemUpgradeLevel.check(d,p)&&e.safeRequireNameTag(i,p)&&b(p)&&O(e,a,p)&&w(e,c,p)&&E(e,r,p)&&A(e,l,p)}function N(t,n){e(M(t,n))}function P(e,t){let n=Object.keys(e).map(e=>[e,parseInt(e,10)]).sort(([,e],[,t])=>e-t),r=0;for(let[i,a]of n)!Number.isInteger(a)||a<0||a>=t||r===t?delete e[i]:r++}function F(e){let t=[];for(let[n,r]of Object.keys(e).map(e=>[e,parseInt(e,10)]).sort(([,e],[,t])=>e-t))(!Number.isInteger(r)||r<0||r>=3)&&(t.push(e[n]),delete e[n]);for(let n of t){let t=Array.from({length:3},(e,t)=>t).find(t=>e[t]===void 0);if(t===void 0)break;e[t]=n}}function I(e,t){return e.items.has(t)?`unrepairable`:`unknown-item`}function L(e,t,n){if(!e.items.has(t.id))return!1;let r=e.getById(t.id);if(t.patches!==void 0){if(!r.hasPatches())t.patches=void 0;else{F(t.patches);for(let[n,r]of Object.entries(t.patches))C(e,r,e=>e.isPatch())||delete t.patches[n]}}if(t.stickers!==void 0){if(!r.hasStickers())t.stickers=void 0;else{let n=r.getStickerSchemaCount(),i=Object.keys(t.stickers).length>5;for(let[a,o]of Object.entries(t.stickers)){if(!C(e,o.id,e=>e.isSticker())){delete t.stickers[a],i=!0;continue}v(o.schema,n)||(i=!0),o.wear=_.stickerWear.repair(o.wear,r),o.rotation=_.stickerRotation.repair(o.rotation,r),o.x=_.stickerX.repair(o.x,r),o.y=_.stickerY.repair(o.y,r)}i&&(t.stickers=d.stickersFromArray(d.stickersToArray(t.stickers,n)))}}if(t.keychains!==void 0){if(!r.hasKeychains())t.keychains=void 0;else{P(t.keychains,1);for(let[n,i]of Object.entries(t.keychains)){if(!C(e,i.id,e=>e.isKeychain())){delete t.keychains[n];continue}i.seed=_.keychainSeed.repair(i.seed,r),i.x=_.keychainPositionX.repair(i.x,r),i.y=_.keychainPositionY.repair(i.y,r),i.z=_.keychainPositionZ.repair(i.z,r)}}}if(t.storage!==void 0){if(!r.isStorageUnit())t.storage=void 0;else{for(let[r,i]of Object.entries(t.storage)){let a=parseInt(r,10);if(i.storage=void 0,e.items.has(i.id)&&!j(i,e.getById(i.id))){n?.dropped.push({uid:a,id:i.id,reason:`policy`,storageUid:n.storageUid}),delete t.storage[a];continue}L(e,i)||(n?.dropped.push({uid:a,id:i.id,reason:I(e,i.id),storageUid:n.storageUid}),delete t.storage[a])}Object.keys(t.storage).length===0&&(t.storage=void 0)}}return t.nameTag=e.trimNameTag(t.nameTag),e.safeRequireNameTag(t.nameTag,r)||(t.nameTag=void 0),t.seed=_.itemSeed.repair(t.seed,r),t.statTrak=_.itemStatTrak.repair(t.statTrak,r),t.style=_.itemStyle.repair(t.style,r),t.upgradeLevel=_.itemUpgradeLevel.repair(t.upgradeLevel,r),t.charges=_.itemCharges.repair(t.charges,r),t.charges===void 0&&r.isGraffiti()&&(t.equipped===!0||t.equippedCT===!0||t.equippedT===!0)&&(t.charges=r.getDefaultCharges()),t.wear=_.itemWear.repair(t.wear,r),M(e,t)}function R(e,t){return e.items.has(t.id)&&e.getById(t.id).isDefault===!0&&t.nameTag===void 0&&t.charges===void 0&&Object.keys(t.stickers??{}).length===0&&Object.keys(t.keychains??{}).length===0&&Object.keys(t.patches??{}).length===0}function z(e,t,r,i){let a=Object.keys(e).map(e=>parseInt(e,10)).sort((e,t)=>e-t);for(let o of a.slice(t)){let t={uid:o,id:n(e[o]).id,reason:`policy`};i!==void 0&&(t.storageUid=i),r.push(t),delete e[o]}}function B(e,t,r){let i=[];for(let[n,r]of Object.entries(t)){if(r.storage===void 0)continue;let t=parseInt(n,10);for(let[n,a]of Object.entries(r.storage))if(e.items.has(a.id)&&!j(a,e.getById(a.id))){let e=parseInt(n,10);i.push({uid:e,id:a.id,reason:`policy`,storageUid:t}),delete r.storage[e]}Object.keys(r.storage).length===0&&(r.storage=void 0)}let a=Object.entries(t).map(([e,t])=>[parseInt(e,10),t]).filter(([,{id:t}])=>e.items.has(t)&&e.getById(t).isCharmDetachment()).sort(([e],[t])=>e-t);if(a.length>1){let[r,i]=n(a[0]),o=e.getById(i.id),s=0;for(let[e,n]of a)s+=n.charges??o.getDefaultCharges(),e!==r&&delete t[e];i.charges=Math.min(s,o.getMaximumCharges()),i.updatedAt=f()}if(r.dropEmptyDefaultItems===!0){for(let[n,r]of Object.entries(t))if(R(e,r)){let e=parseInt(n,10);i.push({uid:e,id:r.id,reason:`policy`}),delete t[e]}}for(let[e,n]of Object.entries(t))n.storage!==void 0&&Object.keys(n.storage).length>r.storageUnitMaxItems&&z(n.storage,r.storageUnitMaxItems,i,parseInt(e,10));return Object.keys(t).length>r.maxItems&&z(t,r.maxItems,i),i}export{_ as CS2_INVENTORY_RULES,x as assertAddable,N as assertInventoryItem,D as assertKeychains,k as assertPatches,T as assertStickers,b as checkAddable,S as checkAttachable,M as checkInventoryItem,E as checkKeychains,O as checkPatches,v as checkStickerSchema,w as checkStickers,A as checkStorage,I as getDropReason,y as getNextStickerSchema,j as isStorableInStorageUnit,B as reconcileInventoryItems,L as repairInventoryItem,g as snapStickerRotation,h as validateStickerRotation};
1
+ import{assert as e,clamp as t,ensure as n,float as r,isFactorPrecise as i,sortRecord as a,truncateToFactor as o,withoutUndefined as s}from"./utils.mjs";import{CS2_KEYCHAIN_POSITION_FACTOR as c,CS2_MAX_KEYCHAIN_SEED as l,CS2_MAX_STATTRAK as u,CS2_STICKER_OFFSET_FACTOR as d,CS2_STICKER_ROTATION_STEP as f,CS2_STICKER_WEAR_FACTOR as p}from"./economy-constants.mjs";import{CS2InventoryItem as m,getTimestamp as h}from"./inventory.mjs";function g(e,n){return{check(t,r){if(t===void 0)return!0;let{min:a,max:o}=n(r);return i(t,e)&&(a===void 0||t>=a)&&(o===void 0||t<=o)},repair(r,i){if(r===void 0||!Number.isFinite(r))return;let{min:a,max:s}=n(i),c=o(r,e);return t(c,a??c,s??c)}}}function _(e){return{check(t,n){if(t===void 0)return!0;let{min:r,max:i}=e(n);return Number.isInteger(t)&&t>=r&&t<=i},repair(n,r){if(n===void 0||!Number.isFinite(n))return;let{min:i,max:a}=e(r);return t(Math.trunc(n),i,a)}}}function v(e){return e===void 0||Number.isInteger(e/.5)&&e>=-180&&e<=180}function y(e){return Math.round(e/f)*f}const b={itemCharges:{check:(e,t)=>t.economy.safeValidateCharges(e,t),repair(e,n){return e!==void 0&&n.hasCharges()&&Number.isFinite(e)?t(Math.trunc(e),1,n.getMaximumCharges()):void 0}},itemSeed:{check:(e,t)=>t.economy.safeValidateSeed(e,t),repair(e,n){return e!==void 0&&n.hasSeed()&&Number.isFinite(e)?t(Math.trunc(e),n.getMinimumSeed(),n.getMaximumSeed()):void 0}},itemStatTrak:{check:(e,t)=>t.economy.safeValidateStatTrak(e,t),repair(e,n){return e!==void 0&&n.hasStatTrak()&&Number.isFinite(e)?t(Math.trunc(e),0,u):void 0}},itemStyle:{check:(e,t)=>t.economy.safeValidateStyle(e,t),repair:(e,t)=>t.economy.safeValidateStyle(e,t)?e:void 0},itemUpgradeLevel:{check:(e,t)=>t.economy.safeValidateUpgradeLevel(e,t),repair:(e,t)=>t.economy.safeValidateUpgradeLevel(e,t)?e:void 0},itemWear:{check:(e,t)=>t.economy.safeValidateWear(e,t),repair(e,n){if(e===void 0||!n.hasWear())return;let r=t(e,n.getMinimumWear(),n.getMaximumWear());return n.economy.safeValidateWear(r,n)?r:void 0}},keychainPositionX:g(c,e=>e.getKeychainPositionBounds().x),keychainPositionY:g(c,e=>e.getKeychainPositionBounds().y),keychainPositionZ:g(c,e=>e.getKeychainPositionBounds().z),keychainSeed:_(()=>({min:1,max:l})),stickerRotation:{check:e=>v(e),repair(e){if(e===void 0)return;let t=y(e);return v(t)?t:void 0}},stickerSchema:{check:(e,t)=>x(e,t.getStickerSchemaCount()),repair:(e,t)=>x(e,t.getStickerSchemaCount())?e:void 0},stickerWear:g(p,()=>({min:0,max:1})),stickerX:g(d,e=>e.getStickerOffsetBounds().x),stickerY:g(d,e=>e.getStickerOffsetBounds().y)};function x(e,t){return e===void 0||Number.isInteger(e)&&e>=0&&e<t}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}function C(e){return!e.isGloves()||e.isDefault===!0||e.isBase!==!0}function w(t){e(C(t))}function T(e){return e.isDefault!==!0}function E(e,t,n){if(!e.items.has(t))return!1;let r=e.getById(t);return n(r)&&T(r)}function D(e,t,n){if(t===void 0)return!0;let r=Object.values(t);if(r.length>5||!n.hasStickers())return!1;for(let{id:t,wear:i,rotation:a,x:o,y:s,schema:c}of r){if(!e.items.has(t))return!1;let r=e.getById(t);if(!r.isSticker()||!T(r)||!b.stickerWear.check(i,n)||!b.stickerRotation.check(a,n)||!b.stickerX.check(o,n)||!b.stickerY.check(s,n)||!b.stickerSchema.check(c,n))return!1}return!0}function O(t,n,r){e(D(t,n,r))}function k(e,t,n){if(t===void 0)return!0;let r=Object.entries(t);if(r.length>1||!n.hasKeychains())return!1;for(let[t,{id:i,seed:a,x:o,y:s,z:c}]of r){let r=parseInt(t,10);if(r<0||r>0||!e.items.has(i))return!1;let l=e.getById(i);if(!l.isKeychain()||!T(l)||!b.keychainSeed.check(a,n)||!b.keychainPositionX.check(o,n)||!b.keychainPositionY.check(s,n)||!b.keychainPositionZ.check(c,n))return!1}return!0}function A(t,n,r){e(k(t,n,r))}function j(e,t,n){if(t===void 0)return!0;if(!n.hasPatches())return!1;for(let[n,r]of Object.entries(t)){let t=parseInt(n,10);if(t<0||t>2||!e.items.has(r))return!1;let i=e.getById(r);if(!i.isPatch()||!T(i))return!1}return!0}function M(t,n,r){e(j(t,n,r))}function N(e,t,n){if(t===void 0)return!0;if(!n.isStorageUnit())return!1;for(let n of Object.values(t))if(n.storage!==void 0||!e.items.has(n.id)||!P(n,e.getById(n.id))||!F(e,n))return!1;return!0}function P({charges:e},t){return!t.isStorageUnit()&&!t.isCharmDetachment()&&!t.isCharmDetachmentPack()&&!t.isPet()&&!t.isChickenEgg()&&!t.isChickenFeed()&&(!t.hasCharges()||e===void 0)}function F(e,{charges:t,id:n,keychains:r,nameTag:i,patches:a,seed:o,statTrak:s,stickers:c,storage:l,style:u,upgradeLevel:d,wear:f}){if(!e.items.has(n))return!1;let p=e.getById(n);return b.itemWear.check(f,p)&&b.itemCharges.check(t,p)&&b.itemSeed.check(o,p)&&b.itemStatTrak.check(s,p)&&b.itemStyle.check(u,p)&&b.itemUpgradeLevel.check(d,p)&&e.safeRequireNameTag(i,p)&&C(p)&&j(e,a,p)&&D(e,c,p)&&k(e,r,p)&&N(e,l,p)}function I(t,n){e(F(t,n))}function L(e,t){let n=Object.keys(e).map(e=>[e,parseInt(e,10)]).sort(([,e],[,t])=>e-t),r=0;for(let[i,a]of n)!Number.isInteger(a)||a<0||a>=t||r===t?delete e[i]:r++}function R(e){let t=[];for(let[n,r]of Object.keys(e).map(e=>[e,parseInt(e,10)]).sort(([,e],[,t])=>e-t))(!Number.isInteger(r)||r<0||r>=3)&&(t.push(e[n]),delete e[n]);for(let n of t){let t=Array.from({length:3},(e,t)=>t).find(t=>e[t]===void 0);if(t===void 0)break;e[t]=n}}function z(e,t){return e.items.has(t)?`unrepairable`:`unknown-item`}function B(e,t,n){if(!e.items.has(t.id))return!1;let r=e.getById(t.id);if(t.patches!==void 0){if(!r.hasPatches())t.patches=void 0;else{R(t.patches);for(let[n,r]of Object.entries(t.patches))E(e,r,e=>e.isPatch())||delete t.patches[n]}}if(t.stickers!==void 0){if(!r.hasStickers())t.stickers=void 0;else{let n=r.getStickerSchemaCount(),i=Object.keys(t.stickers).length>5;for(let[a,o]of Object.entries(t.stickers)){if(!E(e,o.id,e=>e.isSticker())){delete t.stickers[a],i=!0;continue}x(o.schema,n)||(i=!0),o.wear=b.stickerWear.repair(o.wear,r),o.rotation=b.stickerRotation.repair(o.rotation,r),o.x=b.stickerX.repair(o.x,r),o.y=b.stickerY.repair(o.y,r)}i&&(t.stickers=m.stickersFromArray(m.stickersToArray(t.stickers,n)))}}if(t.keychains!==void 0){if(!r.hasKeychains())t.keychains=void 0;else{L(t.keychains,1);for(let[n,i]of Object.entries(t.keychains)){if(!E(e,i.id,e=>e.isKeychain())){delete t.keychains[n];continue}i.seed=b.keychainSeed.repair(i.seed,r),i.x=b.keychainPositionX.repair(i.x,r),i.y=b.keychainPositionY.repair(i.y,r),i.z=b.keychainPositionZ.repair(i.z,r)}}}if(t.storage!==void 0){if(!r.isStorageUnit())t.storage=void 0;else{for(let[r,i]of Object.entries(t.storage)){let a=parseInt(r,10);if(i.storage=void 0,e.items.has(i.id)&&!P(i,e.getById(i.id))){n?.dropped.push({uid:a,id:i.id,reason:`policy`,storageUid:n.storageUid}),delete t.storage[a];continue}B(e,i)||(n?.dropped.push({uid:a,id:i.id,reason:z(e,i.id),storageUid:n.storageUid}),delete t.storage[a])}Object.keys(t.storage).length===0&&(t.storage=void 0)}}return t.nameTag=e.trimNameTag(t.nameTag),e.safeRequireNameTag(t.nameTag,r)||(t.nameTag=void 0),t.seed=b.itemSeed.repair(t.seed,r),t.statTrak=b.itemStatTrak.repair(t.statTrak,r),t.style=b.itemStyle.repair(t.style,r),t.upgradeLevel=b.itemUpgradeLevel.repair(t.upgradeLevel,r),t.charges=b.itemCharges.repair(t.charges,r),t.charges===void 0&&r.isGraffiti()&&(t.equipped===!0||t.equippedCT===!0||t.equippedT===!0)&&(t.charges=r.getDefaultCharges()),t.wear=b.itemWear.repair(t.wear,r),F(e,t)}function V(e,t){return e.items.has(t.id)&&e.getById(t.id).isDefault===!0&&t.nameTag===void 0&&t.charges===void 0&&Object.keys(t.stickers??{}).length===0&&Object.keys(t.keychains??{}).length===0&&Object.keys(t.patches??{}).length===0}function H(e,t,r,i){let a=Object.keys(e).map(e=>parseInt(e,10)).sort((e,t)=>e-t);for(let o of a.slice(t)){let t={uid:o,id:n(e[o]).id,reason:`policy`};i!==void 0&&(t.storageUid=i),r.push(t),delete e[o]}}function U(e,t,r){let i=[];for(let[n,r]of Object.entries(t)){if(r.storage===void 0)continue;let t=parseInt(n,10);for(let[n,a]of Object.entries(r.storage))if(e.items.has(a.id)&&!P(a,e.getById(a.id))){let e=parseInt(n,10);i.push({uid:e,id:a.id,reason:`policy`,storageUid:t}),delete r.storage[e]}Object.keys(r.storage).length===0&&(r.storage=void 0)}let a=Object.entries(t).map(([e,t])=>[parseInt(e,10),t]).filter(([,{id:t}])=>e.items.has(t)&&e.getById(t).isCharmDetachment()).sort(([e],[t])=>e-t);if(a.length>1){let[r,i]=n(a[0]),o=e.getById(i.id),s=0;for(let[e,n]of a)s+=n.charges??o.getDefaultCharges(),e!==r&&delete t[e];i.charges=Math.min(s,o.getMaximumCharges()),i.updatedAt=h()}if(r.dropEmptyDefaultItems===!0){for(let[n,r]of Object.entries(t))if(V(e,r)){let e=parseInt(n,10);i.push({uid:e,id:r.id,reason:`policy`}),delete t[e]}}for(let[e,n]of Object.entries(t))n.storage!==void 0&&Object.keys(n.storage).length>r.storageUnitMaxItems&&H(n.storage,r.storageUnitMaxItems,i,parseInt(e,10));return Object.keys(t).length>r.maxItems&&H(t,r.maxItems,i),i}function W(e,{wearFractionDigits:t}={}){return s({id:e.id,keychains:a(e.keychains,({id:e,seed:t,x:n,y:r,z:i})=>s({id:e,seed:t,x:n,y:r,z:i})),nameTag:e.nameTag,patches:a(e.patches,e=>e),seed:e.seed,statTrak:e.statTrak,stickers:a(e.stickers,({id:e,rotation:t,schema:n,wear:r,x:i,y:a})=>s({id:e,rotation:t,schema:n,wear:r,x:i,y:a})),style:e.style,upgradeLevel:e.upgradeLevel,wear:e.wear!==void 0&&t!==void 0?r(e.wear,t):e.wear})}export{b as CS2_INVENTORY_RULES,w as assertAddable,I as assertInventoryItem,A as assertKeychains,M as assertPatches,O as assertStickers,C as checkAddable,T as checkAttachable,F as checkInventoryItem,k as checkKeychains,j as checkPatches,x as checkStickerSchema,D as checkStickers,N as checkStorage,z as getDropReason,W as getItemAppearance,S as getNextStickerSchema,P as isStorableInStorageUnit,U as reconcileInventoryItems,B as repairInventoryItem,y as snapStickerRotation,v as validateStickerRotation};
@@ -32,6 +32,10 @@ export interface CS2BaseInventoryItem {
32
32
  upgradeLevel?: number;
33
33
  wear?: number;
34
34
  }
35
+ export type CS2ItemAppearance = Pick<CS2BaseInventoryItem, "id" | "keychains" | "nameTag" | "patches" | "seed" | "statTrak" | "stickers" | "style" | "upgradeLevel" | "wear">;
36
+ export interface CS2ItemAppearanceOptions {
37
+ wearFractionDigits?: number;
38
+ }
35
39
  export interface CS2InventoryData {
36
40
  items: Record<number, CS2BaseInventoryItem>;
37
41
  version: number;
@@ -1,8 +1,8 @@
1
1
  import { Interface, MapValue, RecordValue } from "./utils.mjs";
2
2
  import { CS2ItemType, CS2UnlockedItem } from "./economy-types.mjs";
3
3
  import { CS2Team } from "./teams.mjs";
4
+ import { CS2BaseInventoryItem, CS2InventoryData, CS2InventoryOptions, CS2InventorySpec, CS2ItemAppearance, CS2ItemAppearanceOptions } from "./inventory-types.mjs";
4
5
  import { CS2EconomyItem } from "./economy.mjs";
5
- import { CS2BaseInventoryItem, CS2InventoryData, CS2InventoryOptions, CS2InventorySpec } from "./inventory-types.mjs";
6
6
  import { CS2InventoryLoadChanges } from "./inventory-format.mjs";
7
7
  //#region src/inventory.d.ts
8
8
  export declare const CS2_INVENTORY_TIMESTAMP = 1707696138408;
@@ -116,5 +116,6 @@ export declare class CS2InventoryItem extends CS2EconomyItem implements Interfac
116
116
  somePatches(): [number, number][];
117
117
  edit(...sources: Partial<CS2BaseInventoryItem>[]): void;
118
118
  asBase(): CS2BaseInventoryItem;
119
+ override getAppearance(options?: CS2ItemAppearanceOptions): CS2ItemAppearance;
119
120
  }
120
121
  //#endregion
@@ -1 +1 @@
1
- import{CS2ItemType as e}from"./economy-types.mjs";import{assert as t,ensure as n,roundToFactor as r}from"./utils.mjs";import{CS2Team as i}from"./teams.mjs";import{CS2_STICKER_SCRAPE_FACTOR as a,CS2_STICKER_WEAR_FACTOR as o}from"./economy-constants.mjs";import{CS2Economy as s,CS2EconomyItem as c}from"./economy.mjs";import{CS2_INVENTORY_VERSION as l}from"./inventory-migrations/index.mjs";import{decodeInventoryData as u}from"./inventory-format.mjs";import{assertInventoryItem as d,assertKeychains as f,assertStickers as p,checkStickerSchema as m,getDropReason as h,getNextStickerSchema as g,isStorableInStorageUnit as _,reconcileInventoryItems as v,repairInventoryItem as y}from"./inventory-rules.mjs";const b=1707696138408,x=[e.Agent,e.Collectible,e.Gloves,e.Graffiti,e.Melee,e.MusicKit,e.Pet,e.Weapon];function S(){return Math.ceil((Date.now()-b)/1e3)}function C(e){let t=0;for(;;){if(!e.has(t))return t;t++}}function w(e){return D.stickersToArray(e===void 0?void 0:Object.fromEntries(e))}function T(e){return e===void 0?void 0:new Map(Object.entries(e).map(([e,t])=>[parseInt(e,10),t]))}var E=class e{economy;items;loadChanges;options;static load(t,r={}){let i=r.economy??s,{data:a,migratedFrom:o}=u(t,i),c=new e({...r,data:a,economy:i});return n(c.loadChanges).migratedFrom=o,c}constructor({economy:e,data:t,dropEmptyDefaultItems:n,maxItems:r,storageUnitMaxItems:i}={}){this.economy=e??s,this.options={dropEmptyDefaultItems:n??!1,maxItems:r??256,storageUnitMaxItems:i??32};let a={migratedFrom:void 0,dropped:[],repairedUids:[]};this.items=t===void 0?new Map:this.toInventoryItems(structuredClone(t.items),a),this.loadChanges=t===void 0?void 0:a}toInventoryItems(e,t){let n=new Map(Object.entries(e).map(([e,t])=>[parseInt(e,10),JSON.stringify(t)]));for(let[n,r]of Object.entries(e)){let i=parseInt(n,10);y(this.economy,r,{dropped:t.dropped,storageUid:i})||(t.dropped.push({uid:i,id:r.id,reason:h(this.economy,r.id)}),delete e[i])}return t.dropped.push(...v(this.economy,e,this.options)),new Map(Object.entries(e).map(([e,r])=>{let i=parseInt(e,10);return JSON.stringify(r)!==n.get(i)&&t.repairedUids.push(i),[i,new D(this,i,r,this.economy.getById(r.id))]}))}toBaseInventoryItems(e){return Object.fromEntries(Array.from(e).map(([e,t])=>[e,t.asBase()]))}isFull(){return this.items.size>=this.options.maxItems}isStorageUnitFull(e){return this.get(e).storage?.size===this.options.storageUnitMaxItems}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}get(e){return n(this.items.get(e))}getAll(){return Array.from(this.items.values())}getAllAsBase(){return Object.values(this.toBaseInventoryItems(this.items))}getStorageUnitSize(e){return this.get(e).storage?.size??0}getStorageUnitItems(e){return Array.from(this.get(e).storage?.values()??[])}getCharmDetachmentCharges(){let e=this.findChargeableUid(this.economy.getCharmDetachment().id);return e===void 0?0:this.get(e).getCharges()}getData(){return{items:this.toBaseInventoryItems(this.items),version:l}}findChargeableUid(e){let t;for(let[n,r]of this.items)r.id===e&&(t===void 0||n<t)&&(t=n);return t}addCharges(e,n){t(e.hasCharges());let r=e.getMaximumCharges(),i=this.findChargeableUid(e.id);if(i!==void 0){let t=this.get(i);return t.charges=Math.min((t.charges??e.getDefaultCharges())+n,r),t.updatedAt=S(),this}t(!this.isFull());let a=C(this.items);return this.items.set(a,new D(this,a,{id:e.id,charges:Math.min(n,r),updatedAt:S()},e)),this}add(e){let n=this.economy.getById(e.id);if(t(!n.isStub()),t(e.charges===void 0),n.isCharmDetachment())return this.addCharges(n,1);t(!this.isFull());let r=C(this.items);return this.items.set(r,new D(this,r,Object.assign(e,{equipped:void 0,equippedCT:void 0,equippedT:void 0,updatedAt:S()}),n)),this}addInventoryItem(e){t(!this.isFull());let n=C(this.items);return e.equipped=void 0,e.equippedCT=void 0,e.equippedT=void 0,e.uid=n,e.updatedAt=S(),this.items.set(n,e),this}addWithNameTag(e,n,r){this.get(e).expectNameTag();let i=this.economy.getById(n);t(!i.isStorageUnit()),t(!i.isPet());let a=this.economy.trimNameTag(r);return t(a!==void 0),this.economy.requireNameTag(a,i),this.items.delete(e),this.add({id:n,nameTag:a}),this}addWithSticker(e,t,n={}){let r=this.get(e).expectSticker(),{schema:i,x:a,y:o,rotation:s,wear:c}=n,l={0:{id:r.id,schema:i,x:a,y:o,rotation:s,wear:c}};return p(this.economy,l,this.economy.getById(t)),this.items.delete(e),this.add({id:t,stickers:l}),this}addWithKeychain(e,t,n={}){let r=this.get(e).expectKeychain(),{x:i,y:a,z:o}=n,s={0:{id:r.id,seed:r.seed,x:i,y:a,z:o}};return f(this.economy,s,this.economy.getById(t)),this.items.delete(e),this.add({id:t,keychains:s}),this}dropIfEmptyDefaultItem(e){this.options.dropEmptyDefaultItems===!0&&e.isDefault===!0&&e.nameTag===void 0&&e.charges===void 0&&(e.stickers?.size??0)===0&&(e.keychains?.size??0)===0&&(e.patches?.size??0)===0&&this.items.delete(e.uid)}edit(e,n){let r=this.get(e);return t(n.id===void 0||n.id===r.id),t(n.charges===void 0||n.charges===r.charges),r.edit(n,{updatedAt:S()}),this.dropIfEmptyDefaultItem(r),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(x.includes(r.type)),t(!r.isSealed()),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||void 0,a.equippedCT=n===i.CT||a.equippedCT,a.equippedT=n===i.T||a.equippedT):a.type===r.type&&(!r.isWeapon()||a.modelKey===r.modelKey)&&(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:S()}),this}unsealItem(e){let n=this.get(e);return t(n.isSealed()),n.charges=n.getDefaultCharges(),n.updatedAt=S(),this}unpackItem(e){return this.get(e).expectCharmDetachmentPack(),this.items.delete(e),this.addCharges(this.economy.getCharmDetachment(),3)}consumeItemCharges(e,n=1){let r=this.get(e);t(r.hasCharges()),t(!r.isSealed()),t(Number.isInteger(n)&&n>0);let i=r.getCharges()-n;return t(i>=0),i===0?(this.items.delete(e),this):(r.charges=i,r.updatedAt=S(),this)}renameItem(e,n,r){let i=this.economy.trimNameTag(r);this.get(e).expectNameTag();let a=this.get(n);return t(!a.isStorageUnit()),t(!a.isPet()),t(r===void 0||i!==void 0),this.economy.requireNameTag(i,a),a.nameTag=i,a.updatedAt=S(),this.items.delete(e),this.dropIfEmptyDefaultItem(a),this}clearNameTag(e){let n=this.get(e);return t(!n.isStorageUnit()),t(!n.isPet()),t(n.nameTag!==void 0),n.nameTag=void 0,n.updatedAt=S(),this.dropIfEmptyDefaultItem(n),this}renameStorageUnit(e,n){let r=this.economy.trimNameTag(n),i=this.get(e);return i.expectStorageUnit(),t(r!==void 0),this.economy.requireNameTag(r),i.nameTag=r,i.updatedAt=S(),this}renamePet(e,n){let r=this.economy.trimNameTag(n),i=this.get(e);return i.expectPet(),t(r!==void 0),this.economy.requireNameTag(r,i),i.nameTag=r,i.updatedAt=S(),this}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){let n=this.get(e);t(n.isStorableInStorageUnit())}let i=r.storage??new Map;for(let e of n){let t=C(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=S(),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=S(),this}applyItemSticker(e,n,r={}){let i=this.get(e),a=this.get(n).expectSticker();t(i.hasStickers());let o=w(i.stickers);t(o.length<5);let{schema:s,x:c,y:l,rotation:u,wear:d}=r;o.push({id:a.id,schema:s??g(o,i.getStickerSchemaCount()),x:c,y:l,rotation:u,wear:d});let f=D.stickersFromArray(o);return p(this.economy,f,i),i.stickers=T(f),i.updatedAt=S(),this.items.delete(n),this}removeItemSticker(e,n){let r=this.get(e),i=w(r.stickers);return t(i[n]!==void 0),i.splice(n,1),r.stickers=T(D.stickersFromArray(i)),r.updatedAt=S(),this.dropIfEmptyDefaultItem(r),this}moveItemSticker(e,r,i){let a=this.get(e),o=w(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=T(D.stickersFromArray(o)),a.updatedAt=S(),this}editItemSticker(e,n,r){let i=this.get(e),a=w(i.stickers);t(a[n]!==void 0),a[n]={...a[n],...r};let o=D.stickersFromArray(a);return p(this.economy,o,i),i.stickers=T(o),i.updatedAt=S(),this}scrapeItemSticker(e,i,s){let c=this.get(e),l=w(c.stickers),u=n(l[i]),d=u.wear??0,f;return s===void 0?f=r(d+a,o):(t(Number.isFinite(s)),t(s>d&&s<=1),f=r(s,o)),(s===void 0?f>1:f>=1)?l.splice(i,1):l[i]={...u,wear:f},c.stickers=T(D.stickersFromArray(l)),c.updatedAt=S(),this.dropIfEmptyDefaultItem(c),this}applyItemKeychain(e,n,r={}){let i=this.get(e),a=this.get(n).expectKeychain();t(i.hasKeychains()),t(i.getKeychainsCount()<1);let o=0;for(;i.keychains?.has(o);)o++;let{x:s,y:c,z:l}=r,u={id:a.id,seed:a.seed,x:s,y:c,z:l},d={...Object.fromEntries(i.keychains??[]),[o]:u};return f(this.economy,d,i),(i.keychains??=new Map).set(o,u),i.updatedAt=S(),this.items.delete(n),this}removeItemKeychain(e,r){let i=this.get(e),a=n(i.keychains),o=n(a.get(r)),s=n(this.findChargeableUid(this.economy.getCharmDetachment().id));return t(!this.isFull()||this.get(s).getCharges()===1),this.consumeItemCharges(s),a.delete(r),a.size===0&&(i.keychains=void 0),i.updatedAt=S(),this.add({id:o.id,seed:o.seed}),this.dropIfEmptyDefaultItem(i),this}editItemKeychain(e,t,r){let i=this.get(e),a=n(i.keychains),o={...n(a.get(t)),...r},s={...Object.fromEntries(a),[t]:o};return f(this.economy,s,i),a.set(t,o),i.updatedAt=S(),this}sealStickerSlab(e,t){this.get(e).expectStickerSlab();let n=this.get(t).expectSticker().getDisplayCase();return this.items.delete(e),this.items.delete(t),this.add({id:n.id}),this}unsealStickerSlab(e){let t=this.get(e).expectStickerDisplayCase(),r=n(t.displayedStickerId);return this.items.delete(e),this.add({id:r}),this}applyItemPatch(e,n,r){t(r>=0&&r<=2);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=S(),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=S(),this.dropIfEmptyDefaultItem(r),this}incrementItemStatTrak(e){let n=this.get(e);return t(n.statTrak!==void 0),n.statTrak<999999&&(n.statTrak++,n.updatedAt=S()),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.definitionIndex===a.definitionIndex);let o=i.statTrak;return i.statTrak=a.statTrak,i.updatedAt=S(),a.statTrak=o,a.updatedAt=S(),this.items.delete(e),this}remove(e){return this.items.delete(e),this}removeAll(){return this.items.clear(),this}setAll(e){return this.items=e,this}size(){return this.items.size}stringify(){return JSON.stringify(this.getData())}move(t={}){return new e({...this.options,economy:this.economy,...t}).setAll(this.items)}},D=class e extends c{inventory;uid;charges;containerId;equipped;equippedCT;equippedT;keychains;nameTag;patches;seed;statTrak;stickers;storage;style;updatedAt;upgradeLevel;wear;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&&!m(n,t)&&(n=g(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}]))}assign({keychains:t,patches:n,stickers:r,storage:i}){n!==void 0&&(this.patches=new Map(Object.entries(n).map(([e,t])=>[parseInt(e,10),t]))),r!==void 0&&(this.stickers=T(e.stickersFromArray(e.stickersToArray(r,this.getStickerSchemaCount())))),t!==void 0&&(this.keychains=new Map(Object.entries(t).map(([e,t])=>[parseInt(e,10),t]))),i!==void 0&&(this.storage=new Map(Object.entries(i).map(([t,n])=>{let r=parseInt(t,10);return[r,new e(this.inventory,r,n,this.economy.getById(n.id))]})))}constructor(e,t,n,{economy:r,item:i,language:a}){super(r,i,a),this.inventory=e,this.uid=t,d(this.economy,n),Object.assign(this,n),this.assign(n)}isSealed(){return this.hasCharges()&&this.charges===void 0}isStorableInStorageUnit(){return _(this,this)}getStickersCount(){return this.stickers?.size??0}getStickerWear(e){return this.stickers?.get(e)?.wear??0}getKeychainsCount(){return this.keychains?.size??0}getKeychainSeed(e){return this.keychains?.get(e)?.seed??1}getPatchesCount(){return this.patches?.size??0}getCharges(){return this.charges??0}getWear(){return this.wear??this.wearMin??0}getUpgradeLevel(){return this.upgradeLevel??this.getDefaultUpgradeLevel()}getImageUrl(e){return super.getImageUrl(e??this.getWear())}allStickers(){return w(this.stickers).map((e,t)=>[t,e])}allKeychains(){let e=[];for(let t=0;t<1;t++){let n=this.keychains?.get(t);e.push([t,n])}return e}allPatches(){let e=[];for(let t=0;t<3;t++){let n=this.patches?.get(t);e.push([t,n])}return e}someStickers(){return this.allStickers()}someKeychains(){return this.allKeychains().filter(e=>e[1]!==void 0)}somePatches(){return this.allPatches().filter(e=>e[1]!==void 0)}edit(...e){let t=this.asBase();for(let n of e)Object.assign(t,n);d(this.economy,t);for(let t of e)Object.assign(this,t),this.assign(t)}asBase(){return{charges:this.charges,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()])),style:this.style,updatedAt:this.updatedAt,upgradeLevel:this.upgradeLevel,wear:this.wear}}};export{E as CS2Inventory,D as CS2InventoryItem,x as CS2_INVENTORY_EQUIPPABLE_ITEMS,b as CS2_INVENTORY_TIMESTAMP,C as getNextUid,S as getTimestamp,w as stickerMapToArray,T as toStickerMap};
1
+ import{CS2ItemType as e}from"./economy-types.mjs";import{assert as t,ensure as n,roundToFactor as r}from"./utils.mjs";import{CS2Team as i}from"./teams.mjs";import{CS2_STICKER_SCRAPE_FACTOR as a,CS2_STICKER_WEAR_FACTOR as o}from"./economy-constants.mjs";import{CS2Economy as s,CS2EconomyItem as c}from"./economy.mjs";import{CS2_INVENTORY_VERSION as l}from"./inventory-migrations/index.mjs";import{decodeInventoryData as u}from"./inventory-format.mjs";import{assertInventoryItem as d,assertKeychains as f,assertStickers as p,checkStickerSchema as m,getDropReason as h,getItemAppearance as g,getNextStickerSchema as _,isStorableInStorageUnit as v,reconcileInventoryItems as y,repairInventoryItem as b}from"./inventory-rules.mjs";const x=1707696138408,S=[e.Agent,e.Collectible,e.Gloves,e.Graffiti,e.Melee,e.MusicKit,e.Pet,e.Weapon];function C(){return Math.ceil((Date.now()-x)/1e3)}function w(e){let t=0;for(;;){if(!e.has(t))return t;t++}}function T(e){return O.stickersToArray(e===void 0?void 0:Object.fromEntries(e))}function E(e){return e===void 0?void 0:new Map(Object.entries(e).map(([e,t])=>[parseInt(e,10),t]))}var D=class e{economy;items;loadChanges;options;static load(t,r={}){let i=r.economy??s,{data:a,migratedFrom:o}=u(t,i),c=new e({...r,data:a,economy:i});return n(c.loadChanges).migratedFrom=o,c}constructor({economy:e,data:t,dropEmptyDefaultItems:n,maxItems:r,storageUnitMaxItems:i}={}){this.economy=e??s,this.options={dropEmptyDefaultItems:n??!1,maxItems:r??256,storageUnitMaxItems:i??32};let a={migratedFrom:void 0,dropped:[],repairedUids:[]};this.items=t===void 0?new Map:this.toInventoryItems(structuredClone(t.items),a),this.loadChanges=t===void 0?void 0:a}toInventoryItems(e,t){let n=new Map(Object.entries(e).map(([e,t])=>[parseInt(e,10),JSON.stringify(t)]));for(let[n,r]of Object.entries(e)){let i=parseInt(n,10);b(this.economy,r,{dropped:t.dropped,storageUid:i})||(t.dropped.push({uid:i,id:r.id,reason:h(this.economy,r.id)}),delete e[i])}return t.dropped.push(...y(this.economy,e,this.options)),new Map(Object.entries(e).map(([e,r])=>{let i=parseInt(e,10);return JSON.stringify(r)!==n.get(i)&&t.repairedUids.push(i),[i,new O(this,i,r,this.economy.getById(r.id))]}))}toBaseInventoryItems(e){return Object.fromEntries(Array.from(e).map(([e,t])=>[e,t.asBase()]))}isFull(){return this.items.size>=this.options.maxItems}isStorageUnitFull(e){return this.get(e).storage?.size===this.options.storageUnitMaxItems}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}get(e){return n(this.items.get(e))}getAll(){return Array.from(this.items.values())}getAllAsBase(){return Object.values(this.toBaseInventoryItems(this.items))}getStorageUnitSize(e){return this.get(e).storage?.size??0}getStorageUnitItems(e){return Array.from(this.get(e).storage?.values()??[])}getCharmDetachmentCharges(){let e=this.findChargeableUid(this.economy.getCharmDetachment().id);return e===void 0?0:this.get(e).getCharges()}getData(){return{items:this.toBaseInventoryItems(this.items),version:l}}findChargeableUid(e){let t;for(let[n,r]of this.items)r.id===e&&(t===void 0||n<t)&&(t=n);return t}addCharges(e,n){t(e.hasCharges());let r=e.getMaximumCharges(),i=this.findChargeableUid(e.id);if(i!==void 0){let t=this.get(i);return t.charges=Math.min((t.charges??e.getDefaultCharges())+n,r),t.updatedAt=C(),this}t(!this.isFull());let a=w(this.items);return this.items.set(a,new O(this,a,{id:e.id,charges:Math.min(n,r),updatedAt:C()},e)),this}add(e){let n=this.economy.getById(e.id);if(t(!n.isStub()),t(e.charges===void 0),n.isCharmDetachment())return this.addCharges(n,1);t(!this.isFull());let r=w(this.items);return this.items.set(r,new O(this,r,Object.assign(e,{equipped:void 0,equippedCT:void 0,equippedT:void 0,updatedAt:C()}),n)),this}addInventoryItem(e){t(!this.isFull());let n=w(this.items);return e.equipped=void 0,e.equippedCT=void 0,e.equippedT=void 0,e.uid=n,e.updatedAt=C(),this.items.set(n,e),this}addWithNameTag(e,n,r){this.get(e).expectNameTag();let i=this.economy.getById(n);t(!i.isStorageUnit()),t(!i.isPet());let a=this.economy.trimNameTag(r);return t(a!==void 0),this.economy.requireNameTag(a,i),this.items.delete(e),this.add({id:n,nameTag:a}),this}addWithSticker(e,t,n={}){let r=this.get(e).expectSticker(),{schema:i,x:a,y:o,rotation:s,wear:c}=n,l={0:{id:r.id,schema:i,x:a,y:o,rotation:s,wear:c}};return p(this.economy,l,this.economy.getById(t)),this.items.delete(e),this.add({id:t,stickers:l}),this}addWithKeychain(e,t,n={}){let r=this.get(e).expectKeychain(),{x:i,y:a,z:o}=n,s={0:{id:r.id,seed:r.seed,x:i,y:a,z:o}};return f(this.economy,s,this.economy.getById(t)),this.items.delete(e),this.add({id:t,keychains:s}),this}dropIfEmptyDefaultItem(e){this.options.dropEmptyDefaultItems===!0&&e.isDefault===!0&&e.nameTag===void 0&&e.charges===void 0&&(e.stickers?.size??0)===0&&(e.keychains?.size??0)===0&&(e.patches?.size??0)===0&&this.items.delete(e.uid)}edit(e,n){let r=this.get(e);return t(n.id===void 0||n.id===r.id),t(n.charges===void 0||n.charges===r.charges),r.edit(n,{updatedAt:C()}),this.dropIfEmptyDefaultItem(r),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(S.includes(r.type)),t(!r.isSealed()),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||void 0,a.equippedCT=n===i.CT||a.equippedCT,a.equippedT=n===i.T||a.equippedT):a.type===r.type&&(!r.isWeapon()||a.modelKey===r.modelKey)&&(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:C()}),this}unsealItem(e){let n=this.get(e);return t(n.isSealed()),n.charges=n.getDefaultCharges(),n.updatedAt=C(),this}unpackItem(e){return this.get(e).expectCharmDetachmentPack(),this.items.delete(e),this.addCharges(this.economy.getCharmDetachment(),3)}consumeItemCharges(e,n=1){let r=this.get(e);t(r.hasCharges()),t(!r.isSealed()),t(Number.isInteger(n)&&n>0);let i=r.getCharges()-n;return t(i>=0),i===0?(this.items.delete(e),this):(r.charges=i,r.updatedAt=C(),this)}renameItem(e,n,r){let i=this.economy.trimNameTag(r);this.get(e).expectNameTag();let a=this.get(n);return t(!a.isStorageUnit()),t(!a.isPet()),t(r===void 0||i!==void 0),this.economy.requireNameTag(i,a),a.nameTag=i,a.updatedAt=C(),this.items.delete(e),this.dropIfEmptyDefaultItem(a),this}clearNameTag(e){let n=this.get(e);return t(!n.isStorageUnit()),t(!n.isPet()),t(n.nameTag!==void 0),n.nameTag=void 0,n.updatedAt=C(),this.dropIfEmptyDefaultItem(n),this}renameStorageUnit(e,n){let r=this.economy.trimNameTag(n),i=this.get(e);return i.expectStorageUnit(),t(r!==void 0),this.economy.requireNameTag(r),i.nameTag=r,i.updatedAt=C(),this}renamePet(e,n){let r=this.economy.trimNameTag(n),i=this.get(e);return i.expectPet(),t(r!==void 0),this.economy.requireNameTag(r,i),i.nameTag=r,i.updatedAt=C(),this}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){let n=this.get(e);t(n.isStorableInStorageUnit())}let i=r.storage??new Map;for(let e of n){let t=w(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=C(),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=C(),this}applyItemSticker(e,n,r={}){let i=this.get(e),a=this.get(n).expectSticker();t(i.hasStickers());let o=T(i.stickers);t(o.length<5);let{schema:s,x:c,y:l,rotation:u,wear:d}=r;o.push({id:a.id,schema:s??_(o,i.getStickerSchemaCount()),x:c,y:l,rotation:u,wear:d});let f=O.stickersFromArray(o);return p(this.economy,f,i),i.stickers=E(f),i.updatedAt=C(),this.items.delete(n),this}removeItemSticker(e,n){let r=this.get(e),i=T(r.stickers);return t(i[n]!==void 0),i.splice(n,1),r.stickers=E(O.stickersFromArray(i)),r.updatedAt=C(),this.dropIfEmptyDefaultItem(r),this}moveItemSticker(e,r,i){let a=this.get(e),o=T(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=E(O.stickersFromArray(o)),a.updatedAt=C(),this}editItemSticker(e,n,r){let i=this.get(e),a=T(i.stickers);t(a[n]!==void 0),a[n]={...a[n],...r};let o=O.stickersFromArray(a);return p(this.economy,o,i),i.stickers=E(o),i.updatedAt=C(),this}scrapeItemSticker(e,i,s){let c=this.get(e),l=T(c.stickers),u=n(l[i]),d=u.wear??0,f;return s===void 0?f=r(d+a,o):(t(Number.isFinite(s)),t(s>d&&s<=1),f=r(s,o)),(s===void 0?f>1:f>=1)?l.splice(i,1):l[i]={...u,wear:f},c.stickers=E(O.stickersFromArray(l)),c.updatedAt=C(),this.dropIfEmptyDefaultItem(c),this}applyItemKeychain(e,n,r={}){let i=this.get(e),a=this.get(n).expectKeychain();t(i.hasKeychains()),t(i.getKeychainsCount()<1);let o=0;for(;i.keychains?.has(o);)o++;let{x:s,y:c,z:l}=r,u={id:a.id,seed:a.seed,x:s,y:c,z:l},d={...Object.fromEntries(i.keychains??[]),[o]:u};return f(this.economy,d,i),(i.keychains??=new Map).set(o,u),i.updatedAt=C(),this.items.delete(n),this}removeItemKeychain(e,r){let i=this.get(e),a=n(i.keychains),o=n(a.get(r)),s=n(this.findChargeableUid(this.economy.getCharmDetachment().id));return t(!this.isFull()||this.get(s).getCharges()===1),this.consumeItemCharges(s),a.delete(r),a.size===0&&(i.keychains=void 0),i.updatedAt=C(),this.add({id:o.id,seed:o.seed}),this.dropIfEmptyDefaultItem(i),this}editItemKeychain(e,t,r){let i=this.get(e),a=n(i.keychains),o={...n(a.get(t)),...r},s={...Object.fromEntries(a),[t]:o};return f(this.economy,s,i),a.set(t,o),i.updatedAt=C(),this}sealStickerSlab(e,t){this.get(e).expectStickerSlab();let n=this.get(t).expectSticker().getDisplayCase();return this.items.delete(e),this.items.delete(t),this.add({id:n.id}),this}unsealStickerSlab(e){let t=this.get(e).expectStickerDisplayCase(),r=n(t.displayedStickerId);return this.items.delete(e),this.add({id:r}),this}applyItemPatch(e,n,r){t(r>=0&&r<=2);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=C(),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=C(),this.dropIfEmptyDefaultItem(r),this}incrementItemStatTrak(e){let n=this.get(e);return t(n.statTrak!==void 0),n.statTrak<999999&&(n.statTrak++,n.updatedAt=C()),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.definitionIndex===a.definitionIndex);let o=i.statTrak;return i.statTrak=a.statTrak,i.updatedAt=C(),a.statTrak=o,a.updatedAt=C(),this.items.delete(e),this}remove(e){return this.items.delete(e),this}removeAll(){return this.items.clear(),this}setAll(e){return this.items=e,this}size(){return this.items.size}stringify(){return JSON.stringify(this.getData())}move(t={}){return new e({...this.options,economy:this.economy,...t}).setAll(this.items)}},O=class e extends c{inventory;uid;charges;containerId;equipped;equippedCT;equippedT;keychains;nameTag;patches;seed;statTrak;stickers;storage;style;updatedAt;upgradeLevel;wear;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&&!m(n,t)&&(n=_(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}]))}assign({keychains:t,patches:n,stickers:r,storage:i}){n!==void 0&&(this.patches=new Map(Object.entries(n).map(([e,t])=>[parseInt(e,10),t]))),r!==void 0&&(this.stickers=E(e.stickersFromArray(e.stickersToArray(r,this.getStickerSchemaCount())))),t!==void 0&&(this.keychains=new Map(Object.entries(t).map(([e,t])=>[parseInt(e,10),t]))),i!==void 0&&(this.storage=new Map(Object.entries(i).map(([t,n])=>{let r=parseInt(t,10);return[r,new e(this.inventory,r,n,this.economy.getById(n.id))]})))}constructor(e,t,n,{economy:r,item:i,language:a}){super(r,i,a),this.inventory=e,this.uid=t,d(this.economy,n),Object.assign(this,n),this.assign(n)}isSealed(){return this.hasCharges()&&this.charges===void 0}isStorableInStorageUnit(){return v(this,this)}getStickersCount(){return this.stickers?.size??0}getStickerWear(e){return this.stickers?.get(e)?.wear??0}getKeychainsCount(){return this.keychains?.size??0}getKeychainSeed(e){return this.keychains?.get(e)?.seed??1}getPatchesCount(){return this.patches?.size??0}getCharges(){return this.charges??0}getWear(){return this.wear??this.wearMin??0}getUpgradeLevel(){return this.upgradeLevel??this.getDefaultUpgradeLevel()}getImageUrl(e){return super.getImageUrl(e??this.getWear())}allStickers(){return T(this.stickers).map((e,t)=>[t,e])}allKeychains(){let e=[];for(let t=0;t<1;t++){let n=this.keychains?.get(t);e.push([t,n])}return e}allPatches(){let e=[];for(let t=0;t<3;t++){let n=this.patches?.get(t);e.push([t,n])}return e}someStickers(){return this.allStickers()}someKeychains(){return this.allKeychains().filter(e=>e[1]!==void 0)}somePatches(){return this.allPatches().filter(e=>e[1]!==void 0)}edit(...e){let t=this.asBase();for(let n of e)Object.assign(t,n);d(this.economy,t);for(let t of e)Object.assign(this,t),this.assign(t)}asBase(){return{charges:this.charges,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()])),style:this.style,updatedAt:this.updatedAt,upgradeLevel:this.upgradeLevel,wear:this.wear}}getAppearance(e){return g(this.asBase(),e)}};export{D as CS2Inventory,O as CS2InventoryItem,S as CS2_INVENTORY_EQUIPPABLE_ITEMS,x as CS2_INVENTORY_TIMESTAMP,w as getNextUid,C as getTimestamp,T as stickerMapToArray,E as toStickerMap};