@ianlucas/cs2-lib 7.16.0 → 7.18.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.
- package/dist/economy.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/inventory.mjs +1 -1
- package/dist/items.mjs +1 -1
- package/dist/translations/brazilian.mjs +5 -1
- package/dist/translations/bulgarian.mjs +777 -9
- package/dist/translations/czech.mjs +5 -1
- package/dist/translations/danish.mjs +5 -1
- package/dist/translations/dutch.mjs +5 -1
- package/dist/translations/english.mjs +5 -1
- package/dist/translations/finnish.mjs +5 -1
- package/dist/translations/french.mjs +5 -1
- package/dist/translations/german.mjs +31 -27
- package/dist/translations/greek.mjs +5 -1
- package/dist/translations/hungarian.mjs +5 -1
- package/dist/translations/indonesian.mjs +5 -1
- package/dist/translations/italian.mjs +5 -1
- package/dist/translations/japanese.mjs +6 -2
- package/dist/translations/koreana.mjs +7 -3
- package/dist/translations/latam.mjs +5 -1
- package/dist/translations/norwegian.mjs +5 -1
- package/dist/translations/polish.mjs +23 -19
- package/dist/translations/portuguese.mjs +5 -1
- package/dist/translations/romanian.mjs +6 -2
- package/dist/translations/russian.mjs +5 -1
- package/dist/translations/schinese.mjs +7 -3
- package/dist/translations/spanish.mjs +5 -1
- package/dist/translations/swedish.mjs +17 -13
- package/dist/translations/tchinese.mjs +5 -1
- package/dist/translations/thai.mjs +5 -1
- package/dist/translations/turkish.mjs +5 -1
- package/dist/translations/ukrainian.mjs +5 -1
- package/dist/translations/vietnamese.mjs +5 -1
- package/dist/veto.mjs +1 -1
- package/package.json +10 -10
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{
|
|
1
|
+
import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{assert as i,compare as a,ensure as o,safe as s}from"./utils.mjs";import{CS2_CONTAINER_ITEMS as c,CS2_CONTRACT_TOOL_DEF as l,CS2_DISPLAY_ITEMS as u,CS2_EQUIPMENT_ITEMS as d,CS2_GRAPHIC_ART_ITEMS as f,CS2_KEYCHAINABLE_ITEMS as p,CS2_MACHINEGUN_MODELS as m,CS2_MAX_FACTORY_NEW_WEAR as ee,CS2_MAX_FIELD_TESTED_WEAR as h,CS2_MAX_KEYCHAIN_SEED as g,CS2_MAX_MINIMAL_WEAR_WEAR as _,CS2_MAX_SEED as v,CS2_MAX_STATTRAK as te,CS2_MAX_WEAR as y,CS2_MAX_WELL_WORN_WEAR as b,CS2_MIDTIER_CATEGORIES as x,CS2_MIN_KEYCHAIN_SEED as S,CS2_MIN_SEED as C,CS2_MIN_STATTRAK as ne,CS2_MIN_WEAR as w,CS2_MISC_CATEGORIES as T,CS2_NAMETAGGABLE_ITEMS as E,CS2_NAMETAG_RE as D,CS2_NAMETAG_TOOL_DEF as O,CS2_PAINTABLE_ITEMS as k,CS2_PATCHABLE_ITEMS as A,CS2_RIFLE_CATEGORIES as j,CS2_SEEDABLE_ITEMS as M,CS2_SNIPER_RIFLE_MODELS as N,CS2_STATTRAKABLE_ITEMS as P,CS2_STATTRAK_SWAP_TOOL_DEF as F,CS2_STICKERABLE_ITEMS as I,CS2_STORAGE_UNIT_TOOL_DEF as L,CS2_TEAMS_BOTH as R,CS2_TEAMS_CT as z,CS2_TEAMS_T as B,CS2_WEAR_FACTOR as V}from"./economy-constants.mjs";import{CS2RarityColorName as H,CS2RarityColorOrder as U,CS2RaritySoundName as W,CS2_BASE_ODD as G,CS2_RARITY_COLOR_DEFAULT as K,CS2_RARITY_ORDER as q,CS2_STATTRAK_ODD as J,randomFloat as Y,randomInt as X}from"./economy-container.mjs";function Z(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 Q=class{baseUrl=`https://cdn.cstrike.app`;categories=new Set;items=new Map;itemsAsArray=[];stickers=new Set;use({assetsBaseUrl:e,items:t,language:n}){this.baseUrl=e??this.baseUrl,this.categories.clear(),this.items.clear(),this.stickers.clear(),this.itemsAsArray=[];for(let e of t){let t=new $(this,e,o(n[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),this.categories.add(o(t.category))),this.itemsAsArray.push(t)}}getById(e){return o(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return o(this.itemsAsArray.find(Z(e)))}filterItems(e){let t=this.itemsAsArray.filter(Z(e));return i(t.length>0),t}validateWear(e,t){return e===void 0?!0:(i(Number.isFinite(e)),i(String(e).length<=String(V).length),i(e>=w&&e<=y),t!==void 0&&(i(t.hasWear()),i(t.wearMin===void 0||e>=t.wearMin),i(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return s(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0?!0:(i(Number.isFinite(e)),i(Number.isInteger(e)),i(t===void 0||t.hasSeed()),i(e>=(t?.getMinimumSeed()??C)&&e<=(t?.getMaximumSeed()??v)),!0)}safeValidateSeed(e,t){return s(()=>this.validateSeed(e,t))}trimNametag(e){let t=e?.trim();return t===``?void 0:t}validateNametag(e,t){return e!==void 0&&(i(t===void 0||t.hasNametag()),i(e[0]!==` `&&D.test(e))),!0}safeValidateNametag(e,t){return s(()=>this.validateNametag(e,t))}requireNametag(e,t){return i(e===void 0||e.trim().length>0),this.validateNametag(e,t)}safeRequireNametag(e,t){return s(()=>this.requireNametag(e,t))}validateStatTrak(e,t){return e===void 0?!0:(i(t===void 0||t.hasStatTrak()),i(Number.isInteger(e)),i(e>=ne&&e<=te),!0)}safeValidateStatTrak(e,t){return s(()=>this.validateStatTrak(e,t))}getWearFromValue(e){switch(!0){case e<=ee:return r.FactoryNew;case e<=_:return r.MinimalWear;case e<=h:return r.FieldTested;case e<=b:return r.WellWorn;default:return r.BattleScarred}}getStickerCategories(){return Array.from(this.categories).sort()}getStickers(){return Array.from(this.stickers)}validateContainerAndKey(e,t){return e=this.get(e),e.expectContainer(),t=t===void 0?void 0:this.get(t),t===void 0?i(e.keys===void 0):(t.expectKey(),i(e.keys!==void 0),i(e.keys.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return s(()=>this.validateContainerAndKey(e,t))}validateUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),i(e.rawContents?.includes(t)||e.rawSpecials?.includes(t))}},$=class{altName;base;baseId;category;collection;collectionDesc;collectionImage;collectionName;containerType;def;desc;free;id=null;image;index;keys;legacy;model;modelBinary;name=null;rarity=null;specialsImage;statTrakless;statTrakOnly;textureImage;tint;tournamentDesc;type=null;voFallback;voFemale;voPrefix;wearMax;wearMin;_contents;_specials;_teams;constructor(e,t,r){this.economy=e,this.item=t,this.language=r,Object.assign(this,t),Object.assign(this,r),i(typeof this.id==`number`),i(this.name),i(this.type),i(t.type===n.Stub||typeof this.rarity==`string`)}set contents(e){this._contents=e}get contents(){return this.expectContainer(),o(this._contents).map(e=>this.economy.get(e))}get parent(){return this.baseId===void 0?void 0:this.economy.items.has(this.baseId)?this.economy.get(this.baseId):void 0}get rawContents(){return this._contents}get rawSpecials(){return this._specials}set specials(e){this._specials=e}get specials(){return this.expectContainer(),this._specials?.map(e=>this.economy.get(e))}set teams(e){this._teams=e}get teams(){switch(this._teams){case t.Both:return R;case t.T:return B;case t.CT:return z;default:return}}isC4(){return this.category===`c4`}isPistol(){return this.category===`secondary`}isSMG(){return this.category===`smg`}isRifle(){return this.category===`rifle`}isSniperRifle(){return this.model!==void 0&&N.includes(this.model)}isMachinegun(){return this.model!==void 0&&m.includes(this.model)}isHeavy(){return this.category===`heavy`}isEquipment(){return this.category===`equipment`}isInMidTiers(){return this.category!==void 0&&x.includes(this.category)}isInRifles(){return this.category!==void 0&&j.includes(this.category)}isInMisc(){return this.category!==void 0&&T.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===L}isNameTag(){return this.isTool()&&this.def===O}isStatTrakSwapTool(){return this.isTool()&&this.def===F}isContract(){return this.isTool()&&this.def===l}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 k.includes(this.type)&&!this.free&&this.index!==0}hasSeed(){return M.includes(this.type)&&!this.free&&this.index!==0}hasStickers(){return I.includes(this.type)&&!this.isC4()}hasKeychains(){return p.includes(this.type)&&!this.isC4()}hasPatches(){return A.includes(this.type)}hasNametag(){return E.includes(this.type)||this.isStorageUnit()}hasStatTrak(){return P.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 d.includes(this.type)}isInGraphicArts(){return f.includes(this.type)}isInContainers(){return c.includes(this.type)}isInDisplay(){return u.includes(this.type)}isPaintable(){return k.includes(this.type)}getImage(e){if(i(this.image),this.hasWear()&&e!==void 0){let t=`${this.economy.baseUrl}${this.image}`;switch(!0){case e<1/3:return t.replace(`.webp`,`_light.webp`);case e<2/3:return t.replace(`.webp`,`_medium.webp`);default:return t.replace(`.webp`,`_heavy.webp`)}}return`${this.economy.baseUrl}${this.image}`}getCollectionImage(){return`${this.economy.baseUrl}${this.collectionImage}`}getSpecialsImage(){return this.expectContainer(),i(this.rawSpecials),i(this.specialsImage),`${this.economy.baseUrl}${this.specialsImage}`}getTextureImage(){return`${this.economy.baseUrl}${o(this.textureImage)}`}getModelBinary(){let{modelBinary:e}=this.parent??this;return`${this.economy.baseUrl}${o(e)}`}getMinimumWear(){return this.wearMin??w}getMaximumWear(){return this.wearMax??y}getMinimumSeed(){return this.isKeychain()?S:C}getMaximumSeed(){return this.isKeychain()?g:v}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=H[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)=>(U[e.rarity]??K)-(U[t.rarity]??K))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=q.filter(e=>n.includes(e)),i=e?.computeOdds?.(r)??r.map((e,t)=>G/5**t),a=i.reduce((e,t)=>e+t,0),s=r.map((e,t)=>[e,o(i[t])/a]),c=Math.random(),[l]=o(s[0]),u=0;for(let[e,t]of s)if(u+=t,c<=u){l=e;break}let d=o(t[l]),f=o(d[Math.floor(Math.random()*d.length)]),p=this.statTrakless!==!0,m=this.statTrakOnly===!0;return{attributes:{containerId:this.id,seed:f.hasSeed()?X(C,v):void 0,statTrak:p&&f.hasStatTrak()&&(m||Math.random()<=J)?0:void 0,wear:f.hasWear()?Number(Y(f.wearMin??w,f.wearMax??y).toString().substring(0,V.toString().length)):void 0},id:f.id,rarity:W[f.rarity],special:l===`special`}}};const re=new Q;export{re as CS2Economy,Q as CS2EconomyInstance,$ as CS2EconomyItem};
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{
|
|
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,fail as s,float as c,isNotUndefined as l,safe as u}from"./utils.mjs";import{CS2Team as d,toggleCS2Team as f}from"./teams.mjs";import{CS2_CONTAINER_ITEMS as p,CS2_CONTRACT_TOOL_DEF as m,CS2_DEFAULT_MAX_WEAR as h,CS2_DEFAULT_MIN_WEAR as g,CS2_DISPLAY_ITEMS as _,CS2_EQUIPMENT_ITEMS as v,CS2_GRAPHIC_ART_ITEMS as y,CS2_KEYCHAINABLE_ITEMS as b,CS2_MACHINEGUN_MODELS as x,CS2_MAX_BATTLE_SCARRED_WEAR as S,CS2_MAX_FACTORY_NEW_WEAR as C,CS2_MAX_FIELD_TESTED_WEAR as w,CS2_MAX_KEYCHAINS as T,CS2_MAX_KEYCHAIN_SEED as E,CS2_MAX_MINIMAL_WEAR_WEAR as D,CS2_MAX_PATCHES as O,CS2_MAX_SEED as k,CS2_MAX_STATTRAK as A,CS2_MAX_STICKERS as j,CS2_MAX_STICKER_ROTATION as M,CS2_MAX_STICKER_WEAR as N,CS2_MAX_WEAR as P,CS2_MAX_WELL_WORN_WEAR as F,CS2_MIDTIER_CATEGORIES as I,CS2_MIN_BATTLE_SCARRED_WEAR as L,CS2_MIN_FACTORY_NEW_WEAR as R,CS2_MIN_FIELD_TESTED_WEAR as z,CS2_MIN_KEYCHAIN_SEED as B,CS2_MIN_MINIMAL_WEAR_WEAR as V,CS2_MIN_SEED as H,CS2_MIN_STATTRAK as U,CS2_MIN_STICKER_ROTATION as W,CS2_MIN_STICKER_WEAR as G,CS2_MIN_WEAR as K,CS2_MIN_WELL_WORN_WEAR as q,CS2_MISC_CATEGORIES as J,CS2_NAMETAGGABLE_ITEMS as Y,CS2_NAMETAG_RE as X,CS2_NAMETAG_TOOL_DEF as Z,CS2_PAINTABLE_ITEMS as Q,CS2_PATCHABLE_ITEMS as $,CS2_RIFLE_CATEGORIES as ee,CS2_SEEDABLE_ITEMS as te,CS2_SNIPER_RIFLE_MODELS as ne,CS2_STATTRAKABLE_ITEMS as re,CS2_STATTRAK_SWAP_TOOL_DEF as ie,CS2_STICKERABLE_ITEMS as ae,CS2_STICKER_WEAR_FACTOR as oe,CS2_STORAGE_UNIT_TOOL_DEF as se,CS2_TEAMS_BOTH as ce,CS2_TEAMS_CT as le,CS2_TEAMS_T as ue,CS2_WEAR_FACTOR as de}from"./economy-constants.mjs";import{CS2Rarity as fe,CS2RarityColor as pe,CS2RarityColorName as me,CS2RarityColorOrder as he,CS2RaritySoundName as ge,CS2_BASE_ODD as _e,CS2_RARITIES as ve,CS2_RARITY_COLOR_DEFAULT as ye,CS2_RARITY_ORDER as be,CS2_STATTRAK_ODD as xe,randomBoolean as Se,randomFloat as Ce,randomInt as we}from"./economy-container.mjs";import{CS2Economy as Te,CS2EconomyInstance as Ee,CS2EconomyItem as De}from"./economy.mjs";import{CS2Inventory as Oe,CS2InventoryItem as ke,CS2_INVENTORY_EQUIPPABLE_ITEMS as Ae,CS2_INVENTORY_TIMESTAMP as je,CS2_INVENTORY_VERSION as Me,getNextUid as Ne,getTimestamp as Pe}from"./inventory.mjs";import{CS2_ITEMS as Fe}from"./items.mjs";import{CS2KeyValues as Ie}from"./keyvalues.mjs";import{CS2KeyValues3 as Le}from"./keyvalues3.mjs";import{CS2_ACTIVE_MAP_POOL as Re,CS2_ALL_MAPS as ze,CS2_ANCIENT_MAP as Be,CS2_ANUBIS_MAP as Ve,CS2_DUST2_MAP as He,CS2_INFERNO_MAP as Ue,CS2_MIRAGE_MAP as We,CS2_NUKE_MAP as Ge,CS2_OVERPASS_MAP as Ke,CS2_TRAIN_MAP as qe,CS2_VERTIGO_MAP as Je,getMapnameName as Ye}from"./maps.mjs";import{CS2_STICKER_MARKUP as Xe}from"./sticker-markup.mjs";import{CS2Veto as Ze,CS2VetoAction as Qe,CS2VetoType as $e}from"./veto.mjs";export{e as CS2ContainerType,Te as CS2Economy,Ee as CS2EconomyInstance,De as CS2EconomyItem,Oe as CS2Inventory,ke as CS2InventoryItem,t as CS2ItemTeam,n as CS2ItemType,r as CS2ItemWear,Ie as CS2KeyValues,Le as CS2KeyValues3,fe as CS2Rarity,pe as CS2RarityColor,me as CS2RarityColorName,he as CS2RarityColorOrder,ge as CS2RaritySoundName,d as CS2Team,Ze as CS2Veto,Qe as CS2VetoAction,$e as CS2VetoType,Re as CS2_ACTIVE_MAP_POOL,ze as CS2_ALL_MAPS,Be as CS2_ANCIENT_MAP,Ve as CS2_ANUBIS_MAP,_e as CS2_BASE_ODD,p as CS2_CONTAINER_ITEMS,m as CS2_CONTRACT_TOOL_DEF,h as CS2_DEFAULT_MAX_WEAR,g as CS2_DEFAULT_MIN_WEAR,_ as CS2_DISPLAY_ITEMS,He as CS2_DUST2_MAP,v as CS2_EQUIPMENT_ITEMS,y as CS2_GRAPHIC_ART_ITEMS,Ue as CS2_INFERNO_MAP,Ae as CS2_INVENTORY_EQUIPPABLE_ITEMS,je as CS2_INVENTORY_TIMESTAMP,Me as CS2_INVENTORY_VERSION,Fe as CS2_ITEMS,b as CS2_KEYCHAINABLE_ITEMS,x as CS2_MACHINEGUN_MODELS,S as CS2_MAX_BATTLE_SCARRED_WEAR,C as CS2_MAX_FACTORY_NEW_WEAR,w as CS2_MAX_FIELD_TESTED_WEAR,T as CS2_MAX_KEYCHAINS,E as CS2_MAX_KEYCHAIN_SEED,D as CS2_MAX_MINIMAL_WEAR_WEAR,O as CS2_MAX_PATCHES,k as CS2_MAX_SEED,A as CS2_MAX_STATTRAK,j as CS2_MAX_STICKERS,M as CS2_MAX_STICKER_ROTATION,N as CS2_MAX_STICKER_WEAR,P as CS2_MAX_WEAR,F as CS2_MAX_WELL_WORN_WEAR,I as CS2_MIDTIER_CATEGORIES,L as CS2_MIN_BATTLE_SCARRED_WEAR,R as CS2_MIN_FACTORY_NEW_WEAR,z as CS2_MIN_FIELD_TESTED_WEAR,B as CS2_MIN_KEYCHAIN_SEED,V as CS2_MIN_MINIMAL_WEAR_WEAR,H as CS2_MIN_SEED,U as CS2_MIN_STATTRAK,W as CS2_MIN_STICKER_ROTATION,G as CS2_MIN_STICKER_WEAR,K as CS2_MIN_WEAR,q as CS2_MIN_WELL_WORN_WEAR,We as CS2_MIRAGE_MAP,J as CS2_MISC_CATEGORIES,Y as CS2_NAMETAGGABLE_ITEMS,X as CS2_NAMETAG_RE,Z as CS2_NAMETAG_TOOL_DEF,Ge as CS2_NUKE_MAP,Ke as CS2_OVERPASS_MAP,Q as CS2_PAINTABLE_ITEMS,$ as CS2_PATCHABLE_ITEMS,ve as CS2_RARITIES,ye as CS2_RARITY_COLOR_DEFAULT,be as CS2_RARITY_ORDER,ee as CS2_RIFLE_CATEGORIES,te as CS2_SEEDABLE_ITEMS,ne as CS2_SNIPER_RIFLE_MODELS,re as CS2_STATTRAKABLE_ITEMS,xe as CS2_STATTRAK_ODD,ie as CS2_STATTRAK_SWAP_TOOL_DEF,ae as CS2_STICKERABLE_ITEMS,Xe as CS2_STICKER_MARKUP,oe as CS2_STICKER_WEAR_FACTOR,se as CS2_STORAGE_UNIT_TOOL_DEF,ce as CS2_TEAMS_BOTH,le as CS2_TEAMS_CT,ue as CS2_TEAMS_T,qe as CS2_TRAIN_MAP,Je as CS2_VERTIGO_MAP,de as CS2_WEAR_FACTOR,i as assert,a as compare,o as ensure,s as fail,c as float,Ye as getMapnameName,Ne as getNextUid,Pe as getTimestamp,l as isNotUndefined,Se as randomBoolean,Ce as randomFloat,we as randomInt,u as safe,f as toggleCS2Team};
|
package/dist/inventory.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CS2ItemType as e}from"./economy-types.mjs";import{CS2Team as t}from"./teams.mjs";import{CS2_MAX_KEYCHAINS as n,CS2_MAX_KEYCHAIN_SEED as r,CS2_MAX_PATCHES as i,CS2_MAX_STATTRAK as a,CS2_MAX_STICKERS as o,CS2_MAX_STICKER_ROTATION as s,CS2_MAX_STICKER_WEAR as c,CS2_MAX_WEAR as l,CS2_MIN_KEYCHAIN_SEED as u,CS2_MIN_STICKER_WEAR as d,CS2_MIN_WEAR as f,CS2_STICKER_WEAR_FACTOR as p}from"./economy-constants.mjs";import{assert as m,ensure as h,float as g}from"./utils.mjs";import{CS2Economy as _,CS2EconomyItem as v}from"./economy.mjs";import{resolveInventoryData as y}from"./inventory-upgrader.mjs";const b=1,x=1707696138408,S=[e.Agent,e.Collectible,e.Gloves,e.Graffiti,e.Melee,e.MusicKit,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++}}var T=class e{economy;items;options;static parse(e,t){return y(e??void 0,t)}constructor({economy:e,data:t,maxItems:n,storageUnitMaxItems:r}={}){this.economy=e??_,this.items=t===void 0?new Map:this.toInventoryItems(t.items),this.options={maxItems:n??256,storageUnitMaxItems:r??32}}validateAddable(e){e.isGloves()&&m(e.free||!e.base)}validateStickers(e,t){if(e===void 0)return;let n=Object.entries(e);m(n.length<=o),m(t===void 0||t.hasStickers());for(let[e,{id:t,wear:r,rotation:i,x:a,y:l}]of n){let n=parseInt(e,10);m(n>=0&&n<=o-1),this.economy.getById(t).expectSticker(),r!==void 0&&(m(Number.isFinite(r)),m(String(r).length<=String(p).length),m(r>=d&&r<=c)),i!==void 0&&(m(Number.isFinite(i)),m(Number.isInteger(i)),m(String(i).length<=String(s).length)),a!==void 0&&m(Number.isFinite(a)),l!==void 0&&m(Number.isFinite(l))}}validateKeychains(e,t){if(e===void 0)return;let i=Object.entries(e);m(i.length<=n),m(t===void 0||t.hasKeychains());for(let[e,{id:t,seed:a,x:o,y:s}]of i){let i=parseInt(e,10);m(i>=0&&i<=n-1),this.economy.getById(t).expectKeychain(),a!==void 0&&(m(Number.isFinite(a)),m(Number.isInteger(a)),m(a>=u&&a<=r)),o!==void 0&&m(Number.isFinite(o)),s!==void 0&&m(Number.isFinite(s))}}validatePatches(e,t){if(e!==void 0){m(t===void 0||t.isAgent());for(let[t,n]of Object.entries(e)){let e=parseInt(t,10);m(e>=0&&e<=i-1),m(n===void 0||this.economy.getById(n).isPatch())}}}removeInvalidItemReferences(e){if(e.patches!==void 0)for(let[t,n]of Object.entries(e.patches))this.economy.items.has(n)||delete e.patches[t];if(e.stickers!==void 0)for(let[t,n]of Object.entries(e.stickers))this.economy.items.has(n.id)||delete e.stickers[t]}validateBaseInventoryItem({id:e,keychains:t,nameTag:n,patches:r,seed:i,statTrak:a,stickers:o,wear:s}){let c=this.economy.getById(e);this.economy.validateWear(s,c),this.economy.validateSeed(i,c),this.economy.validateNametag(n,c),this.economy.validateStatTrak(a,c),this.validateAddable(c),this.validatePatches(r,c),this.validateStickers(o,c),this.validateKeychains(t,c)}toInventoryItems(e){return new Map(Object.entries(e).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>{this.removeInvalidItemReferences(t);let n=parseInt(e,10);return[n,new E(this,n,t,this.economy.getById(t.id))]}))}toBaseInventoryItems(e){return Object.fromEntries(Array.from(e).map(([e,t])=>[e,t.asBase()]))}stringify(){return JSON.stringify(this.getData())}isFull(){return this.items.size>=this.options.maxItems}add(e){m(!this.isFull());let t=w(this.items),n=this.economy.getById(e.id);return m(!n.isStub()),this.items.set(t,new E(this,t,Object.assign(e,{equipped:void 0,equippedCT:void 0,equippedT:void 0,updatedAt:C()}),n)),this}addInventoryItem(e){m(!this.isFull());let t=w(this.items);return e.equipped=void 0,e.equippedCT=void 0,e.equippedT=void 0,e.uid=t,e.updatedAt=C(),this.items.set(t,e),this}addWithNametag(e,t,n){return this.get(e).expectNameTag(),this.economy.requireNametag(n),this.items.delete(e),this.add({id:t,nameTag:n}),this}addWithSticker(e,t,n){let r=this.get(e).expectSticker();return this.items.delete(e),this.add({id:t,stickers:{[n]:{id:r.id}}}),this}edit(e,t){let n=this.get(e);return m(t.id===void 0||t.id===n.id),n.edit(t,{updatedAt:C()}),this}equip(e,n){let r=this.get(e);m(r.equipped===void 0),m(n!==t.CT||r.equippedCT===void 0),m(n!==t.T||r.equippedT===void 0),m(S.includes(r.type)),m(n===void 0||r.teams?.includes(n)),m(n!==void 0||r.teams===void 0);for(let[i,a]of this.items)e===i?(a.equipped=n===void 0?!0:void 0,a.equippedCT=n===t.CT?!0:a.equippedCT,a.equippedT=n===t.T?!0:a.equippedT):a.type===r.type&&(!r.isWeapon()||a.model===r.model)&&(a.equipped=n===void 0?void 0:a.equipped,a.equippedCT=n===t.CT?void 0:a.equippedCT,a.equippedT=n===t.T?void 0:a.equippedT);return this}unequip(e,n){let r=this.get(e);return r.equipped=n===void 0?void 0:r.equipped,r.equippedCT=n===t.CT?void 0:r.equippedCT,r.equippedT=n===t.T?void 0:r.equippedT,this}unlockContainer(e,t,n){let r=this.get(t);this.economy.validateUnlockedItem(r,e);let i=n===void 0?void 0:this.get(n);return this.economy.validateContainerAndKey(r,i),this.items.delete(t),n!==void 0&&this.items.delete(n),this.add({...e.attributes,id:e.id,updatedAt:C()}),this}renameItem(e,t,n){n=this.economy.trimNametag(n),this.get(e).expectNameTag();let r=this.get(t);return this.economy.validateNametag(n,r),r.nameTag=n,r.updatedAt=C(),this.items.delete(e),this}renameStorageUnit(e,t){let n=this.economy.trimNametag(t),r=this.get(e);return r.expectStorageUnit(),this.economy.requireNametag(n),r.nameTag=n,r.updatedAt=C(),this}isStorageUnitFull(e){return this.get(e).storage?.size===this.options.storageUnitMaxItems}getStorageUnitSize(e){return this.get(e).storage?.size??0}isStorageUnitFilled(e){return this.getStorageUnitSize(e)>0}canDepositToStorageUnit(e,t=1){return this.get(e).nameTag!==void 0&&this.getStorageUnitSize(e)+t<=this.options.storageUnitMaxItems}canRetrieveFromStorageUnit(e,t=1){return this.getStorageUnitSize(e)-t>=0&&this.size()+t<=this.options.maxItems}getStorageUnitItems(e){return Array.from(this.get(e).storage?.values()??[])}depositToStorageUnit(e,t){let n=this.get(e);n.expectStorageUnit(),m(t.length>0),m(this.canDepositToStorageUnit(e,t.length));for(let e of t)m(!this.get(e).isStorageUnit());let r=n.storage??new Map;for(let e of t){let t=w(r);r.set(t,Object.assign(this.get(e),{equipped:void 0,equippedCT:void 0,equippedT:void 0,uid:t})),this.items.delete(e)}return n.storage=r,n.updatedAt=C(),this}retrieveFromStorageUnit(e,t){let n=this.get(e);n.expectStorageUnit();let r=n.storage;m(r!==void 0),m(t.length>0),m(this.canRetrieveFromStorageUnit(e,t.length));for(let e of t)m(r.has(e));for(let e of t){let t=h(r.get(e));this.addInventoryItem(t),r.delete(e)}return n.storage=r.size>0?r:void 0,n.updatedAt=C(),this}applyItemSticker(e,t,n){m(n>=0&&n<=o-1);let r=this.get(e),i=this.get(t);return m(r.hasStickers()),i.expectSticker(),r.stickers??=new Map,m(r.stickers.get(n)===void 0),r.stickers.set(n,{id:i.id}),r.updatedAt=C(),this.items.delete(t),this}scrapeItemSticker(e,t){let n=this.get(e);m(n.stickers!==void 0);let r=h(n.stickers.get(t)),i=g((r.wear??0)+p);return i>l?(n.stickers.delete(t),n.stickers.size===0&&(n.stickers=void 0),this):(r.wear=i,n.updatedAt=C(),this)}applyItemPatch(e,t,n){m(n>=0&&n<=i-1);let r=this.get(e).expectAgent(),a=this.get(t).expectPatch();return r.patches??=new Map,m(r.patches.get(n)===void 0),r.patches.set(n,a.id),r.updatedAt=C(),this.items.delete(t),this}removeItemPatch(e,t){let n=this.get(e);return m(n.patches!==void 0),m(n.patches.get(t)!==void 0),n.patches.delete(t),n.patches.size===0&&(n.patches=void 0),n.updatedAt=C(),this}incrementItemStatTrak(e){let t=this.get(e);return m(t.statTrak!==void 0),t.statTrak<a&&(t.statTrak++,t.updatedAt=C()),this}swapItemsStatTrak(e,t,n){m(t!==n),this.get(e).expectStatTrakSwapTool();let r=this.get(t),i=this.get(n);m(r.statTrak!==void 0&&i.statTrak!==void 0),m(r.type===i.type),m(r.isMusicKit()||r.def===i.def);let a=r.statTrak;return r.statTrak=i.statTrak,r.updatedAt=C(),i.statTrak=a,i.updatedAt=C(),this.items.delete(e),this}remove(e){return this.items.delete(e),this}removeAll(){return this.items.clear(),this}get(e){return h(this.items.get(e))}getAll(){return Array.from(this.items.values())}getAllAsBase(){return Object.values(this.toBaseInventoryItems(this.items))}setAll(e){return this.items=e,this}getData(){return{items:this.toBaseInventoryItems(this.items),version:1}}size(){return this.items.size}move(t={}){return new e({...this.options,economy:this.economy,...t}).setAll(this.items)}},E=class e extends v{containerId;equipped;equippedCT;equippedT;keychains;nameTag;patches;seed;statTrak;stickers;storage;updatedAt;wear;assign({keychains:t,patches:n,stickers:r,storage:i}){n!==void 0&&(this.patches=new Map(Object.entries(n).filter(([,e])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),r!==void 0&&(this.stickers=new Map(Object.entries(r).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),t!==void 0&&(this.keychains=new Map(Object.entries(t).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),i!==void 0&&(m(this.isStorageUnit()),this.storage=new Map(Object.entries(i).filter(([,{id:e}])=>this.economy.items.has(e)).map(([t,n])=>{this.inventory.removeInvalidItemReferences(n);let r=this.economy.getById(n.id);m(n.storage===void 0);let i=parseInt(t,10);return[i,new e(this.inventory,i,n,r)]})))}constructor(e,t,n,{economy:r,item:i,language:a}){super(r,i,a),this.inventory=e,this.uid=t,e.validateBaseInventoryItem(n),Object.assign(this,n),this.assign(n)}edit(...e){for(let t of e)Object.assign(this,t),this.assign(t)}allStickers(){let e=[];for(let t=0;t<o;t++){let n=this.stickers?.get(t);e.push([t,n])}return e}someStickers(){return this.allStickers().filter(e=>e[1]!==void 0)}getStickersCount(){return this.stickers?.size??0}allKeychains(){let e=[];for(let t=0;t<n;t++){let n=this.keychains?.get(t);e.push([t,n])}return e}someKeychains(){return this.allKeychains().filter(e=>e[1]!==void 0)}getKeychainsCount(){return this.keychains?.size??0}allPatches(){let e=[];for(let t=0;t<i;t++){let n=this.patches?.get(t);e.push([t,n])}return e}somePatches(){return this.allPatches().filter(e=>e[1]!==void 0)}getPatchesCount(){return this.patches?.size??0}getWear(){return this.wear??this.wearMin??f}getStickerWear(e){return this.stickers?.get(e)?.wear??d}getKeychainSeed(e){return this.keychains?.get(e)?.seed??u}getImage(e){return super.getImage(e??this.getWear())}asBase(){return{containerId:this.containerId,equipped:this.equipped,equippedCT:this.equippedCT,equippedT:this.equippedT,id:this.id,keychains:this.keychains===void 0?void 0:Object.fromEntries(this.keychains),nameTag:this.nameTag,patches:this.patches===void 0?void 0:Object.fromEntries(this.patches),seed:this.seed,statTrak:this.statTrak,stickers:this.stickers===void 0?void 0:Object.fromEntries(this.stickers),storage:this.storage===void 0?void 0:Object.fromEntries(Array.from(this.storage).map(([e,t])=>[e,t.asBase()])),updatedAt:this.updatedAt,wear:this.wear}}};export{T as CS2Inventory,E as CS2InventoryItem,S as CS2_INVENTORY_EQUIPPABLE_ITEMS,x as CS2_INVENTORY_TIMESTAMP,b as CS2_INVENTORY_VERSION,w as getNextUid,C as getTimestamp};
|
|
1
|
+
import{CS2ItemType as e}from"./economy-types.mjs";import{assert as t,ensure as n,float as r}from"./utils.mjs";import{CS2Team as i}from"./teams.mjs";import{CS2_MAX_KEYCHAINS as a,CS2_MAX_KEYCHAIN_SEED as o,CS2_MAX_PATCHES as s,CS2_MAX_STATTRAK as c,CS2_MAX_STICKERS as l,CS2_MAX_STICKER_ROTATION as u,CS2_MAX_STICKER_WEAR as d,CS2_MAX_WEAR as f,CS2_MIN_KEYCHAIN_SEED as p,CS2_MIN_STICKER_WEAR as m,CS2_MIN_WEAR as h,CS2_STICKER_WEAR_FACTOR as g}from"./economy-constants.mjs";import{CS2Economy as _,CS2EconomyItem as v}from"./economy.mjs";import{resolveInventoryData as y}from"./inventory-upgrader.mjs";const b=1,x=1707696138408,S=[e.Agent,e.Collectible,e.Gloves,e.Graffiti,e.Melee,e.MusicKit,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++}}var T=class e{economy;items;options;static parse(e,t){return y(e??void 0,t)}constructor({economy:e,data:t,maxItems:n,storageUnitMaxItems:r}={}){this.economy=e??_,this.items=t===void 0?new Map:this.toInventoryItems(t.items),this.options={maxItems:n??256,storageUnitMaxItems:r??32}}validateAddable(e){e.isGloves()&&t(e.free||!e.base)}validateStickers(e,n){if(e===void 0)return;let r=Object.entries(e);t(r.length<=l),t(n===void 0||n.hasStickers());for(let[e,{id:n,wear:i,rotation:a,x:o,y:s}]of r){let r=parseInt(e,10);t(r>=0&&r<=l-1),this.economy.getById(n).expectSticker(),i!==void 0&&(t(Number.isFinite(i)),t(String(i).length<=String(g).length),t(i>=m&&i<=d)),a!==void 0&&(t(Number.isFinite(a)),t(Number.isInteger(a)),t(String(a).length<=String(u).length)),o!==void 0&&t(Number.isFinite(o)),s!==void 0&&t(Number.isFinite(s))}}validateKeychains(e,n){if(e===void 0)return;let r=Object.entries(e);t(r.length<=a),t(n===void 0||n.hasKeychains());for(let[e,{id:n,seed:i,x:s,y:c}]of r){let r=parseInt(e,10);t(r>=0&&r<=a-1),this.economy.getById(n).expectKeychain(),i!==void 0&&(t(Number.isFinite(i)),t(Number.isInteger(i)),t(i>=p&&i<=o)),s!==void 0&&t(Number.isFinite(s)),c!==void 0&&t(Number.isFinite(c))}}validatePatches(e,n){if(e!==void 0){t(n===void 0||n.isAgent());for(let[n,r]of Object.entries(e)){let e=parseInt(n,10);t(e>=0&&e<=s-1),t(r===void 0||this.economy.getById(r).isPatch())}}}removeInvalidItemReferences(e){if(e.patches!==void 0)for(let[t,n]of Object.entries(e.patches))this.economy.items.has(n)||delete e.patches[t];if(e.stickers!==void 0)for(let[t,n]of Object.entries(e.stickers))this.economy.items.has(n.id)||delete e.stickers[t]}validateBaseInventoryItem({id:e,keychains:t,nameTag:n,patches:r,seed:i,statTrak:a,stickers:o,wear:s}){let c=this.economy.getById(e);this.economy.validateWear(s,c),this.economy.validateSeed(i,c),this.economy.validateNametag(n,c),this.economy.validateStatTrak(a,c),this.validateAddable(c),this.validatePatches(r,c),this.validateStickers(o,c),this.validateKeychains(t,c)}toInventoryItems(e){return new Map(Object.entries(e).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>{this.removeInvalidItemReferences(t);let n=parseInt(e,10);return[n,new E(this,n,t,this.economy.getById(t.id))]}))}toBaseInventoryItems(e){return Object.fromEntries(Array.from(e).map(([e,t])=>[e,t.asBase()]))}stringify(){return JSON.stringify(this.getData())}isFull(){return this.items.size>=this.options.maxItems}add(e){t(!this.isFull());let n=w(this.items),r=this.economy.getById(e.id);return t(!r.isStub()),this.items.set(n,new E(this,n,Object.assign(e,{equipped:void 0,equippedCT:void 0,equippedT:void 0,updatedAt:C()}),r)),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,t,n){return this.get(e).expectNameTag(),this.economy.requireNametag(n),this.items.delete(e),this.add({id:t,nameTag:n}),this}addWithSticker(e,t,n){let r=this.get(e).expectSticker();return this.items.delete(e),this.add({id:t,stickers:{[n]:{id:r.id}}}),this}edit(e,n){let r=this.get(e);return t(n.id===void 0||n.id===r.id),r.edit(n,{updatedAt:C()}),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(n===void 0||r.teams?.includes(n)),t(n!==void 0||r.teams===void 0);for(let[t,a]of this.items)e===t?(a.equipped=n===void 0?!0:void 0,a.equippedCT=n===i.CT?!0:a.equippedCT,a.equippedT=n===i.T?!0:a.equippedT):a.type===r.type&&(!r.isWeapon()||a.model===r.model)&&(a.equipped=n===void 0?void 0:a.equipped,a.equippedCT=n===i.CT?void 0:a.equippedCT,a.equippedT=n===i.T?void 0:a.equippedT);return this}unequip(e,t){let n=this.get(e);return n.equipped=t===void 0?void 0:n.equipped,n.equippedCT=t===i.CT?void 0:n.equippedCT,n.equippedT=t===i.T?void 0:n.equippedT,this}unlockContainer(e,t,n){let r=this.get(t);this.economy.validateUnlockedItem(r,e);let i=n===void 0?void 0:this.get(n);return this.economy.validateContainerAndKey(r,i),this.items.delete(t),n!==void 0&&this.items.delete(n),this.add({...e.attributes,id:e.id,updatedAt:C()}),this}renameItem(e,t,n){n=this.economy.trimNametag(n),this.get(e).expectNameTag();let r=this.get(t);return this.economy.validateNametag(n,r),r.nameTag=n,r.updatedAt=C(),this.items.delete(e),this}renameStorageUnit(e,t){let n=this.economy.trimNametag(t),r=this.get(e);return r.expectStorageUnit(),this.economy.requireNametag(n),r.nameTag=n,r.updatedAt=C(),this}isStorageUnitFull(e){return this.get(e).storage?.size===this.options.storageUnitMaxItems}getStorageUnitSize(e){return this.get(e).storage?.size??0}isStorageUnitFilled(e){return this.getStorageUnitSize(e)>0}canDepositToStorageUnit(e,t=1){return this.get(e).nameTag!==void 0&&this.getStorageUnitSize(e)+t<=this.options.storageUnitMaxItems}canRetrieveFromStorageUnit(e,t=1){return this.getStorageUnitSize(e)-t>=0&&this.size()+t<=this.options.maxItems}getStorageUnitItems(e){return Array.from(this.get(e).storage?.values()??[])}depositToStorageUnit(e,n){let r=this.get(e);r.expectStorageUnit(),t(n.length>0),t(this.canDepositToStorageUnit(e,n.length));for(let e of n)t(!this.get(e).isStorageUnit());let i=r.storage??new Map;for(let e of n){let t=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){t(r>=0&&r<=l-1);let i=this.get(e),a=this.get(n);return t(i.hasStickers()),a.expectSticker(),i.stickers??=new Map,t(i.stickers.get(r)===void 0),i.stickers.set(r,{id:a.id}),i.updatedAt=C(),this.items.delete(n),this}scrapeItemSticker(e,i){let a=this.get(e);t(a.stickers!==void 0);let o=n(a.stickers.get(i)),s=r((o.wear??0)+g);return s>f?(a.stickers.delete(i),a.stickers.size===0&&(a.stickers=void 0),this):(o.wear=s,a.updatedAt=C(),this)}applyItemPatch(e,n,r){t(r>=0&&r<=s-1);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}incrementItemStatTrak(e){let n=this.get(e);return t(n.statTrak!==void 0),n.statTrak<c&&(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.def===a.def);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}get(e){return n(this.items.get(e))}getAll(){return Array.from(this.items.values())}getAllAsBase(){return Object.values(this.toBaseInventoryItems(this.items))}setAll(e){return this.items=e,this}getData(){return{items:this.toBaseInventoryItems(this.items),version:1}}size(){return this.items.size}move(t={}){return new e({...this.options,economy:this.economy,...t}).setAll(this.items)}},E=class e extends v{containerId;equipped;equippedCT;equippedT;keychains;nameTag;patches;seed;statTrak;stickers;storage;updatedAt;wear;assign({keychains:n,patches:r,stickers:i,storage:a}){r!==void 0&&(this.patches=new Map(Object.entries(r).filter(([,e])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),i!==void 0&&(this.stickers=new Map(Object.entries(i).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),n!==void 0&&(this.keychains=new Map(Object.entries(n).filter(([,{id:e}])=>this.economy.items.has(e)).map(([e,t])=>[parseInt(e,10),t]))),a!==void 0&&(t(this.isStorageUnit()),this.storage=new Map(Object.entries(a).filter(([,{id:e}])=>this.economy.items.has(e)).map(([n,r])=>{this.inventory.removeInvalidItemReferences(r);let i=this.economy.getById(r.id);t(r.storage===void 0);let a=parseInt(n,10);return[a,new e(this.inventory,a,r,i)]})))}constructor(e,t,n,{economy:r,item:i,language:a}){super(r,i,a),this.inventory=e,this.uid=t,e.validateBaseInventoryItem(n),Object.assign(this,n),this.assign(n)}edit(...e){for(let t of e)Object.assign(this,t),this.assign(t)}allStickers(){let e=[];for(let t=0;t<l;t++){let n=this.stickers?.get(t);e.push([t,n])}return e}someStickers(){return this.allStickers().filter(e=>e[1]!==void 0)}getStickersCount(){return this.stickers?.size??0}allKeychains(){let e=[];for(let t=0;t<a;t++){let n=this.keychains?.get(t);e.push([t,n])}return e}someKeychains(){return this.allKeychains().filter(e=>e[1]!==void 0)}getKeychainsCount(){return this.keychains?.size??0}allPatches(){let e=[];for(let t=0;t<s;t++){let n=this.patches?.get(t);e.push([t,n])}return e}somePatches(){return this.allPatches().filter(e=>e[1]!==void 0)}getPatchesCount(){return this.patches?.size??0}getWear(){return this.wear??this.wearMin??h}getStickerWear(e){return this.stickers?.get(e)?.wear??m}getKeychainSeed(e){return this.keychains?.get(e)?.seed??p}getImage(e){return super.getImage(e??this.getWear())}asBase(){return{containerId:this.containerId,equipped:this.equipped,equippedCT:this.equippedCT,equippedT:this.equippedT,id:this.id,keychains:this.keychains===void 0?void 0:Object.fromEntries(this.keychains),nameTag:this.nameTag,patches:this.patches===void 0?void 0:Object.fromEntries(this.patches),seed:this.seed,statTrak:this.statTrak,stickers:this.stickers===void 0?void 0:Object.fromEntries(this.stickers),storage:this.storage===void 0?void 0:Object.fromEntries(Array.from(this.storage).map(([e,t])=>[e,t.asBase()])),updatedAt:this.updatedAt,wear:this.wear}}};export{T as CS2Inventory,E as CS2InventoryItem,S as CS2_INVENTORY_EQUIPPABLE_ITEMS,x as CS2_INVENTORY_TIMESTAMP,b as CS2_INVENTORY_VERSION,w as getNextUid,C as getTimestamp};
|