@ianlucas/cs2-lib 8.4.0 → 8.5.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/economy-types.d.mts +1 -2
- package/dist/economy.d.mts +3 -5
- package/dist/economy.mjs +1 -1
- package/dist/inventory.d.mts +0 -56
- package/dist/items.mjs +1 -1
- package/package.json +2 -2
package/dist/economy-types.d.mts
CHANGED
|
@@ -45,6 +45,7 @@ interface CS2Item {
|
|
|
45
45
|
base?: boolean | undefined;
|
|
46
46
|
baseId?: number | undefined;
|
|
47
47
|
category?: string | undefined;
|
|
48
|
+
clothCollider?: boolean | undefined;
|
|
48
49
|
collection?: string | undefined;
|
|
49
50
|
collectionImage?: string | undefined;
|
|
50
51
|
containerType?: CS2ContainerType | undefined;
|
|
@@ -73,7 +74,6 @@ interface CS2Item {
|
|
|
73
74
|
legacyStickerOffsetXMin?: number | undefined;
|
|
74
75
|
legacyStickerOffsetYMax?: number | undefined;
|
|
75
76
|
legacyStickerOffsetYMin?: number | undefined;
|
|
76
|
-
/** Count of sticker schemas (StickerMarkup anchors) on the legacy mesh; see {@link CS2EconomyItem.getStickerSchemaCount}. */
|
|
77
77
|
legacyStickerSchemaCount?: number | undefined;
|
|
78
78
|
model?: string | undefined;
|
|
79
79
|
paintMaterial?: string | undefined;
|
|
@@ -88,7 +88,6 @@ interface CS2Item {
|
|
|
88
88
|
stickerOffsetXMin?: number | undefined;
|
|
89
89
|
stickerOffsetYMax?: number | undefined;
|
|
90
90
|
stickerOffsetYMin?: number | undefined;
|
|
91
|
-
/** Count of sticker schemas (StickerMarkup anchors) on the HD mesh; see {@link CS2EconomyItem.getStickerSchemaCount}. */
|
|
92
91
|
stickerSchemaCount?: number | undefined;
|
|
93
92
|
teams?: CS2ItemTeam | undefined;
|
|
94
93
|
tint?: number | undefined;
|
package/dist/economy.d.mts
CHANGED
|
@@ -51,6 +51,7 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
|
|
|
51
51
|
base: boolean | undefined;
|
|
52
52
|
baseId: number | undefined;
|
|
53
53
|
category: string | undefined;
|
|
54
|
+
clothCollider: boolean | undefined;
|
|
54
55
|
collection: string | undefined;
|
|
55
56
|
collectionDesc: string | undefined;
|
|
56
57
|
collectionImage: string | undefined;
|
|
@@ -175,15 +176,11 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
|
|
|
175
176
|
getPaintMaterial(): string;
|
|
176
177
|
getPlayerModel(): string;
|
|
177
178
|
getModelData(): string;
|
|
179
|
+
getClothCollider(): string | undefined;
|
|
178
180
|
getMinimumWear(): number;
|
|
179
181
|
getMaximumWear(): number;
|
|
180
182
|
getMinimumSeed(): number;
|
|
181
183
|
getMaximumSeed(): number;
|
|
182
|
-
/**
|
|
183
|
-
* Count of sticker schemas (StickerMarkup anchors) the model defines; valid `schema` is
|
|
184
|
-
* `[0, count)`. Independent of the 5-deep stack ({@link CS2_MAX_STICKERS}), so a model with
|
|
185
|
-
* fewer schemas than stickers shares anchors.
|
|
186
|
-
*/
|
|
187
184
|
getStickerSchemaCount(): number;
|
|
188
185
|
getMinimumStickerOffsetX(): number | undefined;
|
|
189
186
|
getMaximumStickerOffsetX(): number | undefined;
|
|
@@ -197,6 +194,7 @@ declare class CS2EconomyItem implements Interface<Omit<CS2Item, "contents" | "sp
|
|
|
197
194
|
getMaximumKeychainOffsetZ(): number | undefined;
|
|
198
195
|
groupContents(): Record<string, CS2EconomyItem[]>;
|
|
199
196
|
listContents(hideSpecials?: boolean): CS2EconomyItem[];
|
|
197
|
+
/** @see https://www.csgo.com.cn/news/gamebroad/20170911/206155.shtml */
|
|
200
198
|
unlockContainer(options?: {
|
|
201
199
|
computeOdds?: (rarities: (typeof CS2_RARITY_ORDER)[number][]) => number[] | undefined;
|
|
202
200
|
}): CS2UnlockedItem;
|
package/dist/economy.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{assert as i,compare as a,ensure as o,isFactorPrecise as s,safe as c,truncateToFactor as l}from"./utils.mjs";import{CS2_CONTAINER_ITEMS as u,CS2_DISPLAY_ITEMS as d,CS2_EQUIPMENT_ITEMS as f,CS2_GRAPHIC_ART_ITEMS as p,CS2_KEYCHAINABLE_ITEMS as m,CS2_MACHINEGUN_MODELS as h,CS2_MAX_FACTORY_NEW_WEAR as g,CS2_MAX_FIELD_TESTED_WEAR as _,CS2_MAX_KEYCHAIN_SEED as v,CS2_MAX_MINIMAL_WEAR_WEAR as y,CS2_MAX_SEED as b,CS2_MAX_WELL_WORN_WEAR as x,CS2_MIDTIER_CATEGORIES as S,CS2_MISC_CATEGORIES as C,CS2_NAMETAGGABLE_ITEMS as w,CS2_NAMETAG_RE as T,CS2_PAINTABLE_ITEMS as E,CS2_PATCHABLE_ITEMS as D,CS2_RIFLE_CATEGORIES as O,CS2_SEEDABLE_ITEMS as k,CS2_SNIPER_RIFLE_MODELS as A,CS2_STATTRAKABLE_ITEMS as j,CS2_STICKERABLE_ITEMS as M,CS2_TEAMS_BOTH as N,CS2_TEAMS_CT as P,CS2_TEAMS_T as F,CS2_WEAR_FACTOR as I}from"./economy-constants.mjs";import{CS2RarityColorName as L,CS2RarityColorOrder as R,CS2RaritySoundName as z,CS2_RARITY_ORDER as B,randomFloat as V,randomInt as H}from"./economy-container.mjs";function U(e){return function(t){return a(e.type,t.type)&&a(e.free,t.free)&&a(e.model,t.model)&&a(e.base,t.base)&&a(e.category,t.category)&&(e.team===void 0||t.teams===void 0||t.teams.includes(e.team))}}var W=class{baseUrl=`https://cdn.cstrike.app`;categories=new Set;items=new Map;itemsAsArray=[];stickers=new Set;load({assetsBaseUrl:e,items:t,language:n}){this.baseUrl=e??this.baseUrl,this.categories.clear(),this.items.clear(),this.stickers.clear(),this.itemsAsArray=[];for(let e of t){let t=new G(this,e,n===void 0?{name:String(e.id)}:o(n[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),n!==void 0&&this.categories.add(o(t.category))),this.itemsAsArray.push(t)}}getById(e){return o(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return o(this.itemsAsArray.find(U(e)))}filterItems(e){let t=this.itemsAsArray.filter(U(e));return i(t.length>0),t}validateWear(e,t){return e===void 0?!0:(i(s(e,I)),i(e>=0&&e<=1),t!==void 0&&(i(t.hasWear()),i(t.wearMin===void 0||e>=t.wearMin),i(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return c(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0?!0:(i(Number.isFinite(e)),i(Number.isInteger(e)),i(t===void 0||t.hasSeed()),i(e>=(t?.getMinimumSeed()??1)&&e<=(t?.getMaximumSeed()??1e3)),!0)}safeValidateSeed(e,t){return c(()=>this.validateSeed(e,t))}trimNameTag(e){let t=e?.trim();return t===``?void 0:t}validateNameTag(e,t){return e!==void 0&&(i(t===void 0||t.hasNameTag()),i(e[0]!==` `&&T.test(e))),!0}safeValidateNameTag(e,t){return c(()=>this.validateNameTag(e,t))}requireNameTag(e,t){return i(e===void 0||e.trim().length>0),this.validateNameTag(e,t)}safeRequireNameTag(e,t){return c(()=>this.requireNameTag(e,t))}validateStatTrak(e,t){return e===void 0?!0:(i(t===void 0||t.hasStatTrak()),i(Number.isInteger(e)),i(e>=0&&e<=999999),!0)}safeValidateStatTrak(e,t){return c(()=>this.validateStatTrak(e,t))}getWearFromValue(e){switch(!0){case e<=g:return r.FactoryNew;case e<=y:return r.MinimalWear;case e<=_:return r.FieldTested;case e<=x:return r.WellWorn;default:return r.BattleScarred}}getStickerCategories(){return Array.from(this.categories).sort()}getStickers(){return Array.from(this.stickers)}validateContainerAndKey(e,t){return e=this.get(e),e.expectContainer(),t=t===void 0?void 0:this.get(t),t===void 0?i(e.keys===void 0):(t.expectKey(),i(e.keys!==void 0),i(e.keys.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return c(()=>this.validateContainerAndKey(e,t))}expectUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),i(e.rawContents?.includes(t)||e.rawSpecials?.includes(t))}resolveUrl(e){return`${this.baseUrl}${e}`}},G=class{economy;item;language;altName;base;baseId;category;collection;collectionDesc;collectionImage;collectionName;containerType;def;desc;displaySeed;free;id=null;image;index;keychainOffsetXMax;keychainOffsetXMin;keychainOffsetYMax;keychainOffsetYMin;keychainOffsetZMax;keychainOffsetZMin;keys;legacy;legacyKeychainOffsetXMax;legacyKeychainOffsetXMin;legacyKeychainOffsetYMax;legacyKeychainOffsetYMin;legacyKeychainOffsetZMax;legacyKeychainOffsetZMin;legacyStickerOffsetXMax;legacyStickerOffsetXMin;legacyStickerOffsetYMax;legacyStickerOffsetYMin;legacyStickerSchemaCount;model;name=null;paintMaterial;playerModel;rarity=null;specialsImage;statTrakless;statTrakOnly;stickerId;stickerOffsetXMax;stickerOffsetXMin;stickerOffsetYMax;stickerOffsetYMin;stickerSchemaCount;tint;tournamentDesc;type=null;wearMax;wearMin;_contents;_specials;_teams;constructor(e,t,r){this.economy=e,this.item=t,this.language=r,Object.assign(this,t),Object.assign(this,r),i(typeof this.id==`number`),i(this.name),i(this.type),i(t.type===n.Stub||typeof this.rarity==`string`)}set contents(e){this._contents=e}get contents(){return this.expectContainer(),o(this._contents).map(e=>this.economy.get(e))}get parent(){return this.baseId===void 0?void 0:this.economy.items.has(this.baseId)?this.economy.get(this.baseId):void 0}get rawContents(){return this._contents}get rawSpecials(){return this._specials}set specials(e){this._specials=e}get specials(){return this.expectContainer(),this._specials?.map(e=>this.economy.get(e))}set teams(e){this._teams=e}get teams(){switch(this._teams){case t.Both:return N;case t.T:return F;case t.CT:return P;default:return}}get wrappedSticker(){return this.stickerId===void 0?void 0:this.economy.get(this.stickerId)}isC4(){return this.category===`c4`}isPistol(){return this.category===`secondary`}isSMG(){return this.category===`smg`}isRifle(){return this.category===`rifle`}isSniperRifle(){return this.model!==void 0&&A.includes(this.model)}isMachinegun(){return this.model!==void 0&&h.includes(this.model)}isHeavy(){return this.category===`heavy`}isEquipment(){return this.category===`equipment`}isInMidTiers(){return this.category!==void 0&&S.includes(this.category)}isInRifles(){return this.category!==void 0&&O.includes(this.category)}isInMisc(){return this.category!==void 0&&C.includes(this.category)}isAgent(){return this.type===n.Agent}isCollectible(){return this.type===n.Collectible}isContainer(){return this.type===n.Container}isKey(){return this.type===n.Key}isGloves(){return this.type===n.Gloves}isGraffiti(){return this.type===n.Graffiti}isMelee(){return this.type===n.Melee}isMusicKit(){return this.type===n.MusicKit}isPatch(){return this.type===n.Patch}isSticker(){return this.type===n.Sticker}isKeychain(){return this.type===n.Keychain}isStub(){return this.type===n.Stub}isTool(){return this.type===n.Tool}isWeapon(){return this.type===n.Weapon}isStorageUnit(){return this.isTool()&&this.def===1201}isNameTag(){return this.isTool()&&this.def===1200}isStatTrakSwapTool(){return this.isTool()&&this.def===1324}isContract(){return this.isTool()&&this.def===62}expectAgent(){return i(this.isAgent()),this}expectPatch(){return i(this.isPatch()),this}expectSticker(){return i(this.isSticker()),this}expectKeychain(){return i(this.isKeychain()),this}expectStorageUnit(){return i(this.isStorageUnit()),this}expectNameTag(){return i(this.isNameTag()),this}expectStatTrakSwapTool(){return i(this.isStatTrakSwapTool()),this}expectContainer(){return i(this.isContainer()),this}expectKey(){return i(this.isKey()),this}hasWear(){return E.includes(this.type)&&!this.free&&this.index!==0}hasSeed(){return k.includes(this.type)&&!this.free&&this.index!==0}hasStickers(){return M.includes(this.type)&&!this.isC4()}hasKeychains(){return m.includes(this.type)&&!this.isC4()}hasPatches(){return D.includes(this.type)}hasNameTag(){return w.includes(this.type)||this.isStorageUnit()}hasStatTrak(){return j.includes(this.type)&&!this.free}isWeaponCase(){return this.containerType===e.WeaponCase}isStickerCapsule(){return this.containerType===e.StickerCapsule}isGraffitiBox(){return this.containerType===e.GraffitiBox}isSouvenirCase(){return this.containerType===e.SouvenirCase}isInEquipments(){return f.includes(this.type)}isInGraphicArts(){return p.includes(this.type)}isInContainers(){return u.includes(this.type)}isInDisplay(){return d.includes(this.type)}isPaintable(){return E.includes(this.type)}getImage(e){i(this.image);let t=this.economy.resolveUrl(this.image);if(this.hasWear()&&e!==void 0)switch(!0){case e<1/3:return t.replace(`.webp`,`_light.webp`);case e<2/3:return t.replace(`.webp`,`_medium.webp`);default:return t.replace(`.webp`,`_heavy.webp`)}return t}getCollectionImage(){return this.economy.resolveUrl(this.collectionImage)}getSpecialsImage(){return this.expectContainer(),i(this.rawSpecials),i(this.specialsImage),this.economy.resolveUrl(this.specialsImage)}getPaintMaterial(){return this.economy.resolveUrl(this.paintMaterial??this.parent?.paintMaterial)}getPlayerModel(){let e=this.playerModel??this.parent?.playerModel;return this.economy.resolveUrl(e)}getModelData(){let e=this.playerModel??this.parent?.playerModel;return this.economy.resolveUrl(e?.replace(/\.glb$/,`.json`))}getMinimumWear(){return this.wearMin??0}getMaximumWear(){return this.wearMax??1}getMinimumSeed(){return this.isKeychain(),1}getMaximumSeed(){return this.isKeychain()?v:b}getStickerSchemaCount(){let e=this.parent??this;return(this.legacy?e.legacyStickerSchemaCount:void 0)??e.stickerSchemaCount??5}getMinimumStickerOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetXMin:void 0)??e.stickerOffsetXMin}getMaximumStickerOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetXMax:void 0)??e.stickerOffsetXMax}getMinimumStickerOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetYMin:void 0)??e.stickerOffsetYMin}getMaximumStickerOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetYMax:void 0)??e.stickerOffsetYMax}getMinimumKeychainOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetXMin:void 0)??e.keychainOffsetXMin}getMaximumKeychainOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetXMax:void 0)??e.keychainOffsetXMax}getMinimumKeychainOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetYMin:void 0)??e.keychainOffsetYMin}getMaximumKeychainOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetYMax:void 0)??e.keychainOffsetYMax}getMinimumKeychainOffsetZ(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetZMin:void 0)??e.keychainOffsetZMin}getMaximumKeychainOffsetZ(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetZMax:void 0)??e.keychainOffsetZMax}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=L[t.rarity];e[n]||(e[n]=[]),e[n].push(t)}if(t!==void 0)for(let n of t){let t=`special`;e[t]||(e[t]=[]),e[t].push(n)}return e}listContents(e=!1){let t=this.specials;return[...this.contents,...!e&&t!==void 0?t:[]].sort((e,t)=>(R[e.rarity]??0)-(R[t.rarity]??0))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=B.filter(e=>n.includes(e)),i=e?.computeOdds?.(r)??r.map((e,t)=>.8/5**t),a=i.reduce((e,t)=>e+t,0),s=r.map((e,t)=>[e,o(i[t])/a]),c=Math.random(),[u]=o(s[0]),d=0;for(let[e,t]of s)if(d+=t,c<=d){u=e;break}let f=o(t[u]),p=o(f[Math.floor(Math.random()*f.length)]),m=this.statTrakless!==!0,h=this.statTrakOnly===!0;return{attributes:{containerId:this.id,seed:p.hasSeed()?H(1,b):void 0,statTrak:m&&p.hasStatTrak()&&(h||Math.random()<=.1)?0:void 0,wear:p.hasWear()?l(V(p.wearMin??0,p.wearMax??1),I):void 0},id:p.id,rarity:z[p.rarity],special:u===`special`}}};const K=new W;export{K as CS2Economy,W as CS2EconomyInstance,G as CS2EconomyItem};
|
|
1
|
+
import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{assert as i,compare as a,ensure as o,isFactorPrecise as s,safe as c,truncateToFactor as l}from"./utils.mjs";import{CS2_CONTAINER_ITEMS as u,CS2_DISPLAY_ITEMS as d,CS2_EQUIPMENT_ITEMS as f,CS2_GRAPHIC_ART_ITEMS as p,CS2_KEYCHAINABLE_ITEMS as m,CS2_MACHINEGUN_MODELS as h,CS2_MAX_FACTORY_NEW_WEAR as g,CS2_MAX_FIELD_TESTED_WEAR as _,CS2_MAX_KEYCHAIN_SEED as v,CS2_MAX_MINIMAL_WEAR_WEAR as y,CS2_MAX_SEED as b,CS2_MAX_WELL_WORN_WEAR as x,CS2_MIDTIER_CATEGORIES as S,CS2_MISC_CATEGORIES as C,CS2_NAMETAGGABLE_ITEMS as w,CS2_NAMETAG_RE as T,CS2_PAINTABLE_ITEMS as E,CS2_PATCHABLE_ITEMS as D,CS2_RIFLE_CATEGORIES as O,CS2_SEEDABLE_ITEMS as k,CS2_SNIPER_RIFLE_MODELS as A,CS2_STATTRAKABLE_ITEMS as j,CS2_STICKERABLE_ITEMS as M,CS2_TEAMS_BOTH as N,CS2_TEAMS_CT as P,CS2_TEAMS_T as F,CS2_WEAR_FACTOR as I}from"./economy-constants.mjs";import{CS2RarityColorName as L,CS2RarityColorOrder as R,CS2RaritySoundName as z,CS2_RARITY_ORDER as B,randomFloat as V,randomInt as H}from"./economy-container.mjs";function U(e){return function(t){return a(e.type,t.type)&&a(e.free,t.free)&&a(e.model,t.model)&&a(e.base,t.base)&&a(e.category,t.category)&&(e.team===void 0||t.teams===void 0||t.teams.includes(e.team))}}var W=class{baseUrl=`https://cdn.cstrike.app`;categories=new Set;items=new Map;itemsAsArray=[];stickers=new Set;load({assetsBaseUrl:e,items:t,language:n}){this.baseUrl=e??this.baseUrl,this.categories.clear(),this.items.clear(),this.stickers.clear(),this.itemsAsArray=[];for(let e of t){let t=new G(this,e,n===void 0?{name:String(e.id)}:o(n[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),n!==void 0&&this.categories.add(o(t.category))),this.itemsAsArray.push(t)}}getById(e){return o(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return o(this.itemsAsArray.find(U(e)))}filterItems(e){let t=this.itemsAsArray.filter(U(e));return i(t.length>0),t}validateWear(e,t){return e===void 0?!0:(i(s(e,I)),i(e>=0&&e<=1),t!==void 0&&(i(t.hasWear()),i(t.wearMin===void 0||e>=t.wearMin),i(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return c(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0?!0:(i(Number.isFinite(e)),i(Number.isInteger(e)),i(t===void 0||t.hasSeed()),i(e>=(t?.getMinimumSeed()??1)&&e<=(t?.getMaximumSeed()??1e3)),!0)}safeValidateSeed(e,t){return c(()=>this.validateSeed(e,t))}trimNameTag(e){let t=e?.trim();return t===``?void 0:t}validateNameTag(e,t){return e!==void 0&&(i(t===void 0||t.hasNameTag()),i(e[0]!==` `&&T.test(e))),!0}safeValidateNameTag(e,t){return c(()=>this.validateNameTag(e,t))}requireNameTag(e,t){return i(e===void 0||e.trim().length>0),this.validateNameTag(e,t)}safeRequireNameTag(e,t){return c(()=>this.requireNameTag(e,t))}validateStatTrak(e,t){return e===void 0?!0:(i(t===void 0||t.hasStatTrak()),i(Number.isInteger(e)),i(e>=0&&e<=999999),!0)}safeValidateStatTrak(e,t){return c(()=>this.validateStatTrak(e,t))}getWearFromValue(e){switch(!0){case e<=g:return r.FactoryNew;case e<=y:return r.MinimalWear;case e<=_:return r.FieldTested;case e<=x:return r.WellWorn;default:return r.BattleScarred}}getStickerCategories(){return Array.from(this.categories).sort()}getStickers(){return Array.from(this.stickers)}validateContainerAndKey(e,t){return e=this.get(e),e.expectContainer(),t=t===void 0?void 0:this.get(t),t===void 0?i(e.keys===void 0):(t.expectKey(),i(e.keys!==void 0),i(e.keys.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return c(()=>this.validateContainerAndKey(e,t))}expectUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),i(e.rawContents?.includes(t)||e.rawSpecials?.includes(t))}resolveUrl(e){return`${this.baseUrl}${e}`}},G=class{economy;item;language;altName;base;baseId;category;clothCollider;collection;collectionDesc;collectionImage;collectionName;containerType;def;desc;displaySeed;free;id=null;image;index;keychainOffsetXMax;keychainOffsetXMin;keychainOffsetYMax;keychainOffsetYMin;keychainOffsetZMax;keychainOffsetZMin;keys;legacy;legacyKeychainOffsetXMax;legacyKeychainOffsetXMin;legacyKeychainOffsetYMax;legacyKeychainOffsetYMin;legacyKeychainOffsetZMax;legacyKeychainOffsetZMin;legacyStickerOffsetXMax;legacyStickerOffsetXMin;legacyStickerOffsetYMax;legacyStickerOffsetYMin;legacyStickerSchemaCount;model;name=null;paintMaterial;playerModel;rarity=null;specialsImage;statTrakless;statTrakOnly;stickerId;stickerOffsetXMax;stickerOffsetXMin;stickerOffsetYMax;stickerOffsetYMin;stickerSchemaCount;tint;tournamentDesc;type=null;wearMax;wearMin;_contents;_specials;_teams;constructor(e,t,r){this.economy=e,this.item=t,this.language=r,Object.assign(this,t),Object.assign(this,r),i(typeof this.id==`number`),i(this.name),i(this.type),i(t.type===n.Stub||typeof this.rarity==`string`)}set contents(e){this._contents=e}get contents(){return this.expectContainer(),o(this._contents).map(e=>this.economy.get(e))}get parent(){return this.baseId===void 0?void 0:this.economy.items.has(this.baseId)?this.economy.get(this.baseId):void 0}get rawContents(){return this._contents}get rawSpecials(){return this._specials}set specials(e){this._specials=e}get specials(){return this.expectContainer(),this._specials?.map(e=>this.economy.get(e))}set teams(e){this._teams=e}get teams(){switch(this._teams){case t.Both:return N;case t.T:return F;case t.CT:return P;default:return}}get wrappedSticker(){return this.stickerId===void 0?void 0:this.economy.get(this.stickerId)}isC4(){return this.category===`c4`}isPistol(){return this.category===`secondary`}isSMG(){return this.category===`smg`}isRifle(){return this.category===`rifle`}isSniperRifle(){return this.model!==void 0&&A.includes(this.model)}isMachinegun(){return this.model!==void 0&&h.includes(this.model)}isHeavy(){return this.category===`heavy`}isEquipment(){return this.category===`equipment`}isInMidTiers(){return this.category!==void 0&&S.includes(this.category)}isInRifles(){return this.category!==void 0&&O.includes(this.category)}isInMisc(){return this.category!==void 0&&C.includes(this.category)}isAgent(){return this.type===n.Agent}isCollectible(){return this.type===n.Collectible}isContainer(){return this.type===n.Container}isKey(){return this.type===n.Key}isGloves(){return this.type===n.Gloves}isGraffiti(){return this.type===n.Graffiti}isMelee(){return this.type===n.Melee}isMusicKit(){return this.type===n.MusicKit}isPatch(){return this.type===n.Patch}isSticker(){return this.type===n.Sticker}isKeychain(){return this.type===n.Keychain}isStub(){return this.type===n.Stub}isTool(){return this.type===n.Tool}isWeapon(){return this.type===n.Weapon}isStorageUnit(){return this.isTool()&&this.def===1201}isNameTag(){return this.isTool()&&this.def===1200}isStatTrakSwapTool(){return this.isTool()&&this.def===1324}isContract(){return this.isTool()&&this.def===62}expectAgent(){return i(this.isAgent()),this}expectPatch(){return i(this.isPatch()),this}expectSticker(){return i(this.isSticker()),this}expectKeychain(){return i(this.isKeychain()),this}expectStorageUnit(){return i(this.isStorageUnit()),this}expectNameTag(){return i(this.isNameTag()),this}expectStatTrakSwapTool(){return i(this.isStatTrakSwapTool()),this}expectContainer(){return i(this.isContainer()),this}expectKey(){return i(this.isKey()),this}hasWear(){return E.includes(this.type)&&!this.free&&this.index!==0}hasSeed(){return k.includes(this.type)&&!this.free&&this.index!==0}hasStickers(){return M.includes(this.type)&&!this.isC4()}hasKeychains(){return m.includes(this.type)&&!this.isC4()}hasPatches(){return D.includes(this.type)}hasNameTag(){return w.includes(this.type)||this.isStorageUnit()}hasStatTrak(){return j.includes(this.type)&&!this.free}isWeaponCase(){return this.containerType===e.WeaponCase}isStickerCapsule(){return this.containerType===e.StickerCapsule}isGraffitiBox(){return this.containerType===e.GraffitiBox}isSouvenirCase(){return this.containerType===e.SouvenirCase}isInEquipments(){return f.includes(this.type)}isInGraphicArts(){return p.includes(this.type)}isInContainers(){return u.includes(this.type)}isInDisplay(){return d.includes(this.type)}isPaintable(){return E.includes(this.type)}getImage(e){i(this.image);let t=this.economy.resolveUrl(this.image);if(this.hasWear()&&e!==void 0)switch(!0){case e<1/3:return t.replace(`.webp`,`_light.webp`);case e<2/3:return t.replace(`.webp`,`_medium.webp`);default:return t.replace(`.webp`,`_heavy.webp`)}return t}getCollectionImage(){return this.economy.resolveUrl(this.collectionImage)}getSpecialsImage(){return this.expectContainer(),i(this.rawSpecials),i(this.specialsImage),this.economy.resolveUrl(this.specialsImage)}getPaintMaterial(){return this.economy.resolveUrl(this.paintMaterial??this.parent?.paintMaterial)}getPlayerModel(){let e=this.playerModel??this.parent?.playerModel;return this.economy.resolveUrl(e)}getModelData(){let e=this.playerModel??this.parent?.playerModel;return this.economy.resolveUrl(e?.replace(/\.glb$/,`.json`))}getClothCollider(){if(!(this.clothCollider??this.parent?.clothCollider))return;let e=this.playerModel??this.parent?.playerModel;return this.economy.resolveUrl(e?.replace(/\.glb$/,`.collider.json`))}getMinimumWear(){return this.wearMin??0}getMaximumWear(){return this.wearMax??1}getMinimumSeed(){return this.isKeychain(),1}getMaximumSeed(){return this.isKeychain()?v:b}getStickerSchemaCount(){let e=this.parent??this;return(this.legacy?e.legacyStickerSchemaCount:void 0)??e.stickerSchemaCount??5}getMinimumStickerOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetXMin:void 0)??e.stickerOffsetXMin}getMaximumStickerOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetXMax:void 0)??e.stickerOffsetXMax}getMinimumStickerOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetYMin:void 0)??e.stickerOffsetYMin}getMaximumStickerOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyStickerOffsetYMax:void 0)??e.stickerOffsetYMax}getMinimumKeychainOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetXMin:void 0)??e.keychainOffsetXMin}getMaximumKeychainOffsetX(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetXMax:void 0)??e.keychainOffsetXMax}getMinimumKeychainOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetYMin:void 0)??e.keychainOffsetYMin}getMaximumKeychainOffsetY(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetYMax:void 0)??e.keychainOffsetYMax}getMinimumKeychainOffsetZ(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetZMin:void 0)??e.keychainOffsetZMin}getMaximumKeychainOffsetZ(){let e=this.parent??this;return(this.legacy?e.legacyKeychainOffsetZMax:void 0)??e.keychainOffsetZMax}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=L[t.rarity];e[n]||(e[n]=[]),e[n].push(t)}if(t!==void 0)for(let n of t){let t=`special`;e[t]||(e[t]=[]),e[t].push(n)}return e}listContents(e=!1){let t=this.specials;return[...this.contents,...!e&&t!==void 0?t:[]].sort((e,t)=>(R[e.rarity]??0)-(R[t.rarity]??0))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=B.filter(e=>n.includes(e)),i=e?.computeOdds?.(r)??r.map((e,t)=>.8/5**t),a=i.reduce((e,t)=>e+t,0),s=r.map((e,t)=>[e,o(i[t])/a]),c=Math.random(),[u]=o(s[0]),d=0;for(let[e,t]of s)if(d+=t,c<=d){u=e;break}let f=o(t[u]),p=o(f[Math.floor(Math.random()*f.length)]),m=this.statTrakless!==!0,h=this.statTrakOnly===!0;return{attributes:{containerId:this.id,seed:p.hasSeed()?H(1,b):void 0,statTrak:m&&p.hasStatTrak()&&(h||Math.random()<=.1)?0:void 0,wear:p.hasWear()?l(V(p.wearMin??0,p.wearMax??1),I):void 0},id:p.id,rarity:z[p.rarity],special:u===`special`}}};const K=new W;export{K as CS2Economy,W as CS2EconomyInstance,G as CS2EconomyItem};
|
package/dist/inventory.d.mts
CHANGED
|
@@ -20,17 +20,9 @@ interface CS2BaseInventoryItem {
|
|
|
20
20
|
patches?: Record<string, number>;
|
|
21
21
|
seed?: number;
|
|
22
22
|
statTrak?: number;
|
|
23
|
-
/**
|
|
24
|
-
* Stickers on the item — a stack of up to {@link CS2_MAX_STICKERS}. The record key is the
|
|
25
|
-
* **slot/index**: the 0-based stack (draw) position. Each sticker's **`schema`** is its physical
|
|
26
|
-
* anchor — an index into the model's `StickerMarkup`, valid in
|
|
27
|
-
* `[0, CS2EconomyItem.getStickerSchemaCount())`. The stack can outnumber a model's schemas, so
|
|
28
|
-
* stickers may share an anchor.
|
|
29
|
-
*/
|
|
30
23
|
stickers?: Record<string, {
|
|
31
24
|
id: number;
|
|
32
25
|
rotation?: number;
|
|
33
|
-
/** Physical anchor: a `StickerMarkup` index in `[0, CS2EconomyItem.getStickerSchemaCount())`. */
|
|
34
26
|
schema?: number;
|
|
35
27
|
wear?: number;
|
|
36
28
|
x?: number;
|
|
@@ -59,35 +51,10 @@ declare function getTimestamp(): number;
|
|
|
59
51
|
declare function getNextUid(map: Map<number, unknown>): number;
|
|
60
52
|
declare function stickerMapToArray(stickers: Map<number, RecordValue<CS2BaseInventoryItem["stickers"]>> | undefined): RecordValue<CS2BaseInventoryItem["stickers"]>[];
|
|
61
53
|
declare function toStickerMap(stickers: CS2BaseInventoryItem["stickers"]): Map<number, RecordValue<CS2BaseInventoryItem["stickers"]>> | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* Normalizes a stored sticker offset so healed data passes validation: drops non-finite values,
|
|
64
|
-
* truncates onto the {@link CS2_STICKER_OFFSET_FACTOR} grid, then clamps into the model's
|
|
65
|
-
* `[min, max]` (pass the item's `getMinimum/MaximumStickerOffsetX/Y()`; each bound skipped when undefined).
|
|
66
|
-
*/
|
|
67
54
|
declare function healStickerOffset(value: number | undefined, min: number | undefined, max: number | undefined): number | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* Normalizes a stored keychain offset so healed data passes validation: drops non-finite values,
|
|
70
|
-
* truncates onto the {@link CS2_KEYCHAIN_OFFSET_FACTOR} grid, then clamps into the model's
|
|
71
|
-
* `[min, max]` (pass the item's `getMinimum/MaximumKeychainOffsetX/Y/Z()`; each bound skipped when undefined).
|
|
72
|
-
*/
|
|
73
55
|
declare function healKeychainOffset(value: number | undefined, min: number | undefined, max: number | undefined): number | undefined;
|
|
74
|
-
/**
|
|
75
|
-
* True when `rotation` is a valid sticker rotation: on the {@link CS2_STICKER_ROTATION_STEP}
|
|
76
|
-
* half-degree grid (…, -0.5, 0, 0.5, 1, …) and within
|
|
77
|
-
* [{@link CS2_MIN_STICKER_ROTATION}, {@link CS2_MAX_STICKER_ROTATION}]. `undefined` (unset) is valid.
|
|
78
|
-
*/
|
|
79
56
|
declare function validateStickerRotation(rotation?: number): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Snaps a rotation in degrees to the nearest {@link CS2_STICKER_ROTATION_STEP} grid value
|
|
82
|
-
* (2.4 → 2.5, 2.7 → 2.5). Exact - half-degree values are binary-representable, so no float noise.
|
|
83
|
-
* Does NOT range-wrap; pair with {@link validateStickerRotation}.
|
|
84
|
-
*/
|
|
85
57
|
declare function snapStickerRotation(rotation: number): number;
|
|
86
|
-
/**
|
|
87
|
-
* The schema (StickerMarkup anchor) a freshly applied sticker should occupy: the first anchor in
|
|
88
|
-
* `[0, schemaCount)` no current sticker uses, falling back to `0` once every anchor is taken (so the
|
|
89
|
-
* stack can exceed the schema count). Pass the target's {@link CS2EconomyItem.getStickerSchemaCount}.
|
|
90
|
-
*/
|
|
91
58
|
declare function getNextStickerSchema(stickers: RecordValue<CS2BaseInventoryItem["stickers"]>[], schemaCount: number): number;
|
|
92
59
|
declare class CS2Inventory {
|
|
93
60
|
private economy;
|
|
@@ -100,9 +67,6 @@ declare class CS2Inventory {
|
|
|
100
67
|
private validateKeychains;
|
|
101
68
|
private validatePatches;
|
|
102
69
|
healBaseInventoryItem(item: CS2BaseInventoryItem): void;
|
|
103
|
-
/**
|
|
104
|
-
* @deprecated Use {@link healBaseInventoryItem} instead.
|
|
105
|
-
*/
|
|
106
70
|
removeInvalidItemReferences(item: CS2BaseInventoryItem): void;
|
|
107
71
|
validateBaseInventoryItem({ id, keychains, nameTag, patches, seed, statTrak, stickers, wear }: CS2BaseInventoryItem): void;
|
|
108
72
|
private toInventoryItems;
|
|
@@ -112,20 +76,7 @@ declare class CS2Inventory {
|
|
|
112
76
|
add(item: CS2BaseInventoryItem): this;
|
|
113
77
|
private addInventoryItem;
|
|
114
78
|
addWithNameTag(nameTagUid: number, id: number, nameTag: string): this;
|
|
115
|
-
/**
|
|
116
|
-
* Adds a new item `id` to the inventory with the sticker item `stickerUid` applied to its first
|
|
117
|
-
* slot, consuming the sticker. The optional `attributes` set that sticker's `schema` (its physical
|
|
118
|
-
* {@link CS2EconomyItem.getStickerSchemaCount} anchor), `x`/`y` offset, `rotation`, and `wear`. All
|
|
119
|
-
* are validated against the new item before anything mutates, so an invalid value throws without
|
|
120
|
-
* consuming the sticker.
|
|
121
|
-
*/
|
|
122
79
|
addWithSticker(stickerUid: number, id: number, attributes?: Omit<RecordValue<CS2BaseInventoryItem["stickers"]>, "id">): this;
|
|
123
|
-
/**
|
|
124
|
-
* Adds a new item `id` to the inventory with the keychain item `keychainUid` applied to its first
|
|
125
|
-
* slot, consuming the keychain. The optional `attributes` set that keychain's `seed` and its
|
|
126
|
-
* `x`/`y`/`z` position in markup space. All are validated against the new item before anything
|
|
127
|
-
* mutates, so an invalid value throws without consuming the keychain.
|
|
128
|
-
*/
|
|
129
80
|
addWithKeychain(keychainUid: number, id: number, attributes?: Omit<RecordValue<CS2BaseInventoryItem["keychains"]>, "id">): this;
|
|
130
81
|
edit(itemUid: number, properties: Partial<CS2BaseInventoryItem>): this;
|
|
131
82
|
equip(itemUid: number, team?: CS2Team): this;
|
|
@@ -141,13 +92,6 @@ declare class CS2Inventory {
|
|
|
141
92
|
getStorageUnitItems(storageUid: number): CS2InventoryItem[];
|
|
142
93
|
depositToStorageUnit(storageUid: number, depositUids: number[]): this;
|
|
143
94
|
retrieveFromStorageUnit(storageUid: number, retrieveUids: number[]): this;
|
|
144
|
-
/**
|
|
145
|
-
* Applies the sticker item `stickerUid` onto `targetUid`, appending it to the stack. The optional
|
|
146
|
-
* `attributes` set the new sticker's `schema` (its physical {@link CS2EconomyItem.getStickerSchemaCount}
|
|
147
|
-
* anchor — defaults to the next free anchor), `x`/`y` offset, `rotation`, and `wear`. All are
|
|
148
|
-
* validated against the target before anything mutates, so an invalid value throws without
|
|
149
|
-
* consuming the sticker.
|
|
150
|
-
*/
|
|
151
95
|
applyItemSticker(targetUid: number, stickerUid: number, attributes?: Omit<RecordValue<CS2BaseInventoryItem["stickers"]>, "id">): this;
|
|
152
96
|
removeItemSticker(targetUid: number, index: number): this;
|
|
153
97
|
moveItemSticker(targetUid: number, fromIndex: number, toIndex: number): this;
|