@ianlucas/cs2-lib 9.7.0-rc.1 → 9.7.0-rc.2

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.
@@ -1,6 +1,6 @@
1
1
  import { Interface } from "./utils.mjs";
2
2
  import { CS2RarityColor, CS2_RARITY_ORDER } from "./economy-container.mjs";
3
- import { CS2Bounds, CS2ContainerType, CS2Item, CS2ItemTeam, CS2ItemTranslation, CS2ItemTranslationMap, CS2ItemType, CS2ItemWear, CS2ModelAnimations, CS2StatTrakMode, CS2UnlockedItem } from "./economy-types.mjs";
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
5
  //#region src/economy.d.ts
6
6
  type CS2EconomyItemPredicate = Partial<CS2EconomyItem> & {
@@ -52,13 +52,10 @@ export declare class CS2EconomyInstance {
52
52
  hasStickerDisplayCase(sticker: number | CS2EconomyItem): boolean;
53
53
  expectUnlockedItem(item: number | CS2EconomyItem, { id }: ReturnType<InstanceType<typeof CS2EconomyItem>["unlockContainer"]>): void;
54
54
  resolveUrl(path?: string): string;
55
- /**
56
- * The URL of a published animation clip, by name (`chicken/world/chick_idle01`), or undefined
57
- * when no clip has that name. The clips are the `animations` given to `load`, which is
58
- * `CS2_MODEL_ANIMATIONS` from `@ianlucas/cs2-lib/model-animations`; none are known until then.
59
- * A clip is three.js `AnimationClip` JSON, and its entry names the skeleton it fits.
60
- */
61
55
  getAnimationUrl(name: string): string | undefined;
56
+ getAnimationSkeleton(name: string): CS2ModelAnimationSkeleton | undefined;
57
+ getAnimationNames(skeleton?: CS2ModelAnimationSkeleton): string[];
58
+ private getAnimation;
62
59
  }
63
60
  export declare class CS2EconomyItem implements Interface<CS2Item & CS2ItemTranslation & {
64
61
  contents: CS2EconomyItem[] | undefined;
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){return Object.hasOwn(this.animations,e)?this.resolveUrl(this.animations[e].path):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)}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/package.json CHANGED
@@ -79,5 +79,5 @@
79
79
  "engines": {
80
80
  "node": ">=20"
81
81
  },
82
- "version": "9.7.0-rc.1"
82
+ "version": "9.7.0-rc.2"
83
83
  }