@ianlucas/cs2-lib 7.6.0 → 7.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/economy-constants.mjs +1 -1
  2. package/dist/economy.mjs +1 -1
  3. package/dist/inventory.mjs +1 -1
  4. package/dist/items.mjs +1 -1
  5. package/dist/translations/brazilian.mjs +112 -78
  6. package/dist/translations/bulgarian.mjs +568 -506
  7. package/dist/translations/czech.mjs +35 -1
  8. package/dist/translations/danish.mjs +35 -1
  9. package/dist/translations/dutch.mjs +537 -501
  10. package/dist/translations/english.mjs +35 -1
  11. package/dist/translations/finnish.mjs +41 -7
  12. package/dist/translations/french.mjs +35 -1
  13. package/dist/translations/german.mjs +37 -3
  14. package/dist/translations/greek.mjs +37 -3
  15. package/dist/translations/hungarian.mjs +35 -1
  16. package/dist/translations/indonesian.mjs +62 -28
  17. package/dist/translations/italian.mjs +35 -3
  18. package/dist/translations/japanese.mjs +35 -1
  19. package/dist/translations/koreana.mjs +231 -197
  20. package/dist/translations/latam.mjs +35 -1
  21. package/dist/translations/norwegian.mjs +34 -1
  22. package/dist/translations/polish.mjs +35 -1
  23. package/dist/translations/portuguese.mjs +35 -1
  24. package/dist/translations/romanian.mjs +36 -2
  25. package/dist/translations/russian.mjs +36 -2
  26. package/dist/translations/schinese.mjs +41 -7
  27. package/dist/translations/spanish.mjs +35 -1
  28. package/dist/translations/swedish.mjs +35 -1
  29. package/dist/translations/tchinese.mjs +36 -5
  30. package/dist/translations/thai.mjs +36 -2
  31. package/dist/translations/turkish.mjs +35 -1
  32. package/dist/translations/ukrainian.mjs +36 -2
  33. package/dist/translations/vietnamese.mjs +35 -1
  34. package/package.json +9 -9
@@ -1 +1 @@
1
- import{CS2ItemType as e}from"./economy-types.mjs";import{CS2Team as t}from"./teams.mjs";const n=0,r=999999,i=0,a=1,o=.06,s=.8,c=i,l=.07,u=.070001,d=.15,f=.150001,p=.37,m=.370001,h=.44,g=.440001,_=a,v=1,y=1e3,b=0,x=.9,S=0,C=359,w=1,T=1e5,E=5,D=5,O=1,ee=.1,k=1e-6,A=/^[A-Za-z0-9`!@#$%^&*-+=(){}\[\]\/\|\\,.?:;'_\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\s]{0,20}$/u,j=62,M=1200,N=1324,P=1201,F=[e.Container,e.Tool],I=[e.Collectible,e.MusicKit],L=[e.Weapon,e.Agent,e.Gloves,e.Melee,e.MusicKit],R=[e.Patch,e.Sticker,e.Graffiti,e.Keychain],z=[e.Melee,e.Weapon],B=[e.Gloves,e.Melee,e.Weapon],V=[e.Agent],H=[e.Weapon,e.Melee,e.Gloves,e.Keychain],U=[e.Melee,e.Weapon,e.MusicKit],W=[e.Weapon],G=[e.Weapon],K=[`heavy`,`smg`],q=[`rifle`],J=[`c4`,`equipment`],Y=[`awp`,`g3sg1`,`scar20`,`ssg08`],X=[`m249`,`negev`],Z=[t.T,t.CT],Q=[t.CT],$=[t.T];export{F as CS2_CONTAINER_ITEMS,j as CS2_CONTRACT_TOOL_DEF,s as CS2_DEFAULT_MAX_WEAR,o as CS2_DEFAULT_MIN_WEAR,I as CS2_DISPLAY_ITEMS,L as CS2_EQUIPMENT_ITEMS,R as CS2_GRAPHIC_ART_ITEMS,G as CS2_KEYCHAINABLE_ITEMS,X as CS2_MACHINEGUN_MODELS,_ as CS2_MAX_BATTLE_SCARRED_WEAR,l as CS2_MAX_FACTORY_NEW_WEAR,p as CS2_MAX_FIELD_TESTED_WEAR,O as CS2_MAX_KEYCHAINS,T as CS2_MAX_KEYCHAIN_SEED,d as CS2_MAX_MINIMAL_WEAR_WEAR,D as CS2_MAX_PATCHES,y as CS2_MAX_SEED,r as CS2_MAX_STATTRAK,E as CS2_MAX_STICKERS,C as CS2_MAX_STICKER_ROTATION,x as CS2_MAX_STICKER_WEAR,a as CS2_MAX_WEAR,h as CS2_MAX_WELL_WORN_WEAR,K as CS2_MIDTIER_CATEGORIES,g as CS2_MIN_BATTLE_SCARRED_WEAR,c as CS2_MIN_FACTORY_NEW_WEAR,f as CS2_MIN_FIELD_TESTED_WEAR,w as CS2_MIN_KEYCHAIN_SEED,u as CS2_MIN_MINIMAL_WEAR_WEAR,v as CS2_MIN_SEED,n as CS2_MIN_STATTRAK,S as CS2_MIN_STICKER_ROTATION,b as CS2_MIN_STICKER_WEAR,i as CS2_MIN_WEAR,m as CS2_MIN_WELL_WORN_WEAR,J as CS2_MISC_CATEGORIES,z as CS2_NAMETAGGABLE_ITEMS,A as CS2_NAMETAG_RE,M as CS2_NAMETAG_TOOL_DEF,B as CS2_PAINTABLE_ITEMS,V as CS2_PATCHABLE_ITEMS,q as CS2_RIFLE_CATEGORIES,H as CS2_SEEDABLE_ITEMS,Y as CS2_SNIPER_RIFLE_MODELS,U as CS2_STATTRAKABLE_ITEMS,N as CS2_STATTRAK_SWAP_TOOL_DEF,W as CS2_STICKERABLE_ITEMS,ee as CS2_STICKER_WEAR_FACTOR,P as CS2_STORAGE_UNIT_TOOL_DEF,Z as CS2_TEAMS_BOTH,Q as CS2_TEAMS_CT,$ as CS2_TEAMS_T,k as CS2_WEAR_FACTOR};
1
+ import{CS2ItemType as e}from"./economy-types.mjs";import{CS2Team as t}from"./teams.mjs";const n=0,r=999999,i=0,a=1,o=.06,s=.8,c=0,l=.07,u=.070001,d=.15,f=.150001,p=.37,m=.370001,h=.44,g=.440001,_=1,v=1,y=1e3,b=0,x=.9,S=0,C=359,w=1,T=1e5,E=5,D=5,O=1,k=.1,A=1e-6,j=/^[A-Za-z0-9`!@#$%^&*-+=(){}\[\]\/\|\\,.?:;'_\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\s]{0,20}$/u,M=62,N=1200,P=1324,F=1201,I=[e.Container,e.Tool],L=[e.Collectible,e.MusicKit],R=[e.Weapon,e.Agent,e.Gloves,e.Melee,e.MusicKit],z=[e.Patch,e.Sticker,e.Graffiti,e.Keychain],B=[e.Melee,e.Weapon],V=[e.Gloves,e.Melee,e.Weapon],H=[e.Agent],U=[e.Weapon,e.Melee,e.Gloves,e.Keychain],W=[e.Melee,e.Weapon,e.MusicKit],G=[e.Weapon],K=[e.Weapon],q=[`heavy`,`smg`],J=[`rifle`],Y=[`c4`,`equipment`],X=[`awp`,`g3sg1`,`scar20`,`ssg08`],Z=[`m249`,`negev`],Q=[t.T,t.CT],$=[t.CT],ee=[t.T];export{I as CS2_CONTAINER_ITEMS,M as CS2_CONTRACT_TOOL_DEF,s as CS2_DEFAULT_MAX_WEAR,o as CS2_DEFAULT_MIN_WEAR,L as CS2_DISPLAY_ITEMS,R as CS2_EQUIPMENT_ITEMS,z as CS2_GRAPHIC_ART_ITEMS,K as CS2_KEYCHAINABLE_ITEMS,Z as CS2_MACHINEGUN_MODELS,_ as CS2_MAX_BATTLE_SCARRED_WEAR,l as CS2_MAX_FACTORY_NEW_WEAR,p as CS2_MAX_FIELD_TESTED_WEAR,O as CS2_MAX_KEYCHAINS,T as CS2_MAX_KEYCHAIN_SEED,d as CS2_MAX_MINIMAL_WEAR_WEAR,D as CS2_MAX_PATCHES,y as CS2_MAX_SEED,r as CS2_MAX_STATTRAK,E as CS2_MAX_STICKERS,C as CS2_MAX_STICKER_ROTATION,x as CS2_MAX_STICKER_WEAR,a as CS2_MAX_WEAR,h as CS2_MAX_WELL_WORN_WEAR,q as CS2_MIDTIER_CATEGORIES,g as CS2_MIN_BATTLE_SCARRED_WEAR,c as CS2_MIN_FACTORY_NEW_WEAR,f as CS2_MIN_FIELD_TESTED_WEAR,w as CS2_MIN_KEYCHAIN_SEED,u as CS2_MIN_MINIMAL_WEAR_WEAR,v as CS2_MIN_SEED,n as CS2_MIN_STATTRAK,S as CS2_MIN_STICKER_ROTATION,b as CS2_MIN_STICKER_WEAR,i as CS2_MIN_WEAR,m as CS2_MIN_WELL_WORN_WEAR,Y as CS2_MISC_CATEGORIES,B as CS2_NAMETAGGABLE_ITEMS,j as CS2_NAMETAG_RE,N as CS2_NAMETAG_TOOL_DEF,V as CS2_PAINTABLE_ITEMS,H as CS2_PATCHABLE_ITEMS,J as CS2_RIFLE_CATEGORIES,U as CS2_SEEDABLE_ITEMS,X as CS2_SNIPER_RIFLE_MODELS,W as CS2_STATTRAKABLE_ITEMS,P as CS2_STATTRAK_SWAP_TOOL_DEF,G as CS2_STICKERABLE_ITEMS,k as CS2_STICKER_WEAR_FACTOR,F as CS2_STORAGE_UNIT_TOOL_DEF,Q as CS2_TEAMS_BOTH,$ as CS2_TEAMS_CT,ee as CS2_TEAMS_T,A as CS2_WEAR_FACTOR};
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{CS2_CONTAINER_ITEMS as i,CS2_CONTRACT_TOOL_DEF as a,CS2_DISPLAY_ITEMS as o,CS2_EQUIPMENT_ITEMS as s,CS2_GRAPHIC_ART_ITEMS as c,CS2_KEYCHAINABLE_ITEMS as l,CS2_MACHINEGUN_MODELS as u,CS2_MAX_FACTORY_NEW_WEAR as d,CS2_MAX_FIELD_TESTED_WEAR as f,CS2_MAX_KEYCHAIN_SEED as p,CS2_MAX_MINIMAL_WEAR_WEAR as ee,CS2_MAX_SEED as m,CS2_MAX_STATTRAK as h,CS2_MAX_WEAR as g,CS2_MAX_WELL_WORN_WEAR as _,CS2_MIDTIER_CATEGORIES as v,CS2_MIN_KEYCHAIN_SEED as y,CS2_MIN_SEED as b,CS2_MIN_STATTRAK as x,CS2_MIN_WEAR as S,CS2_MISC_CATEGORIES as C,CS2_NAMETAGGABLE_ITEMS as w,CS2_NAMETAG_RE as T,CS2_NAMETAG_TOOL_DEF as E,CS2_PAINTABLE_ITEMS as D,CS2_PATCHABLE_ITEMS as te,CS2_RIFLE_CATEGORIES as ne,CS2_SEEDABLE_ITEMS as O,CS2_SNIPER_RIFLE_MODELS as k,CS2_STATTRAKABLE_ITEMS as A,CS2_STATTRAK_SWAP_TOOL_DEF as j,CS2_STICKERABLE_ITEMS as M,CS2_STORAGE_UNIT_TOOL_DEF as N,CS2_TEAMS_BOTH as P,CS2_TEAMS_CT as F,CS2_TEAMS_T as I,CS2_WEAR_FACTOR as L}from"./economy-constants.mjs";import{CS2RarityColorName as R,CS2RarityColorOrder as z,CS2RaritySoundName as B,CS2_BASE_ODD as V,CS2_RARITY_COLOR_DEFAULT as H,CS2_RARITY_ORDER as U,CS2_STATTRAK_ODD as W,randomFloat as G,randomInt as K}from"./economy-container.mjs";import{assert as q,compare as J,ensure as Y,safe as X}from"./utils.mjs";function Z(e){return function(t){return J(e.type,t.type)&&J(e.free,t.free)&&J(e.model,t.model)&&J(e.base,t.base)&&J(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,Y(n[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),this.categories.add(Y(t.category))),this.itemsAsArray.push(t)}}getById(e){return Y(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return Y(this.itemsAsArray.find(Z(e)))}filterItems(e){let t=this.itemsAsArray.filter(Z(e));return q(t.length>0),t}validateWear(e,t){return e===void 0?!0:(q(Number.isFinite(e)),q(String(e).length<=String(L).length),q(e>=S&&e<=g),t!==void 0&&(q(t.hasWear()),q(t.wearMin===void 0||e>=t.wearMin),q(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return X(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0?!0:(q(Number.isFinite(e)),q(Number.isInteger(e)),q(t===void 0||t.hasSeed()),q(e>=(t?.getMinimumSeed()??b)&&e<=(t?.getMaximumSeed()??m)),!0)}safeValidateSeed(e,t){return X(()=>this.validateSeed(e,t))}trimNametag(e){let t=e?.trim();return t===``?void 0:t}validateNametag(e,t){return e!==void 0&&(q(t===void 0||t.hasNametag()),q(e[0]!==` `&&T.test(e))),!0}safeValidateNametag(e,t){return X(()=>this.validateNametag(e,t))}requireNametag(e,t){return q(e===void 0||e.trim().length>0),this.validateNametag(e,t)}safeRequireNametag(e,t){return X(()=>this.requireNametag(e,t))}validateStatTrak(e,t){return e===void 0?!0:(q(t===void 0||t.hasStatTrak()),q(Number.isInteger(e)),q(e>=x&&e<=h),!0)}safeValidateStatTrak(e,t){return X(()=>this.validateStatTrak(e,t))}getWearFromValue(e){switch(!0){case e<=d:return r.FactoryNew;case e<=ee:return r.MinimalWear;case e<=f:return r.FieldTested;case e<=_: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?q(e.keys===void 0):(t.expectKey(),q(e.keys!==void 0),q(e.keys.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return X(()=>this.validateContainerAndKey(e,t))}validateUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),q(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),q(typeof this.id==`number`),q(this.name),q(this.type),q(t.type===n.Stub||typeof this.rarity==`string`)}set contents(e){this._contents=e}get contents(){return this.expectContainer(),Y(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 P;case t.T:return I;case t.CT:return F;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&&k.includes(this.model)}isMachinegun(){return this.model!==void 0&&u.includes(this.model)}isHeavy(){return this.category===`heavy`}isEquipment(){return this.category===`equipment`}isInMidTiers(){return this.category!==void 0&&v.includes(this.category)}isInRifles(){return this.category!==void 0&&ne.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===N}isNameTag(){return this.isTool()&&this.def===E}isStatTrakSwapTool(){return this.isTool()&&this.def===j}isContract(){return this.isTool()&&this.def===a}expectAgent(){return q(this.isAgent()),this}expectPatch(){return q(this.isPatch()),this}expectSticker(){return q(this.isSticker()),this}expectKeychain(){return q(this.isKeychain()),this}expectStorageUnit(){return q(this.isStorageUnit()),this}expectNameTag(){return q(this.isNameTag()),this}expectStatTrakSwapTool(){return q(this.isStatTrakSwapTool()),this}expectContainer(){return q(this.isContainer()),this}expectKey(){return q(this.isKey()),this}hasWear(){return D.includes(this.type)&&!this.free&&this.index!==0}hasSeed(){return O.includes(this.type)&&!this.free&&this.index!==0}hasStickers(){return M.includes(this.type)&&!this.isC4()}hasKeychains(){return l.includes(this.type)&&!this.isC4()}hasPatches(){return te.includes(this.type)}hasNametag(){return w.includes(this.type)||this.isStorageUnit()}hasStatTrak(){return A.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 s.includes(this.type)}isInGraphicArts(){return c.includes(this.type)}isInContainers(){return i.includes(this.type)}isInDisplay(){return o.includes(this.type)}isPaintable(){return D.includes(this.type)}getImage(e){if(q(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(),q(this.rawSpecials),q(this.specialsImage),`${this.economy.baseUrl}${this.specialsImage}`}getTextureImage(){return`${this.economy.baseUrl}${Y(this.textureImage)}`}getModelBinary(){let{modelBinary:e}=this.parent??this;return`${this.economy.baseUrl}${Y(e)}`}getMinimumWear(){return this.wearMin??S}getMaximumWear(){return this.wearMax??g}getMinimumSeed(){return this.isKeychain()?y:b}getMaximumSeed(){return this.isKeychain()?p:m}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=R[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,n=[...this.contents,...!e&&t!==void 0?t:[]];return n.sort((e,t)=>(z[e.rarity]??H)-(z[t.rarity]??H))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=U.filter(e=>n.includes(e)),i=e?.computeOdds?.(r)??r.map((e,t)=>V/5**t),a=i.reduce((e,t)=>e+t,0),o=r.map((e,t)=>[e,Y(i[t])/a]),s=Math.random(),[c]=Y(o[0]),l=0;for(let[e,t]of o)if(l+=t,s<=l){c=e;break}let u=Y(t[c]),d=Y(u[Math.floor(Math.random()*u.length)]),f=this.statTrakless!==!0,p=this.statTrakOnly===!0;return{attributes:{containerId:this.id,seed:d.hasSeed()?K(b,m):void 0,statTrak:f&&d.hasStatTrak()&&(p||Math.random()<=W)?0:void 0,wear:d.hasWear()?Number(G(d.wearMin??S,d.wearMax??g).toString().substring(0,L.toString().length)):void 0},id:d.id,rarity:B[d.rarity],special:c===`special`}}};const re=new Q;export{re as CS2Economy,Q as CS2EconomyInstance,$ as CS2EconomyItem};
1
+ import{CS2ContainerType as e,CS2ItemTeam as t,CS2ItemType as n,CS2ItemWear as r}from"./economy-types.mjs";import{CS2_CONTAINER_ITEMS as i,CS2_CONTRACT_TOOL_DEF as a,CS2_DISPLAY_ITEMS as o,CS2_EQUIPMENT_ITEMS as s,CS2_GRAPHIC_ART_ITEMS as c,CS2_KEYCHAINABLE_ITEMS as l,CS2_MACHINEGUN_MODELS as u,CS2_MAX_FACTORY_NEW_WEAR as d,CS2_MAX_FIELD_TESTED_WEAR as f,CS2_MAX_KEYCHAIN_SEED as p,CS2_MAX_MINIMAL_WEAR_WEAR as ee,CS2_MAX_SEED as m,CS2_MAX_STATTRAK as h,CS2_MAX_WEAR as g,CS2_MAX_WELL_WORN_WEAR as _,CS2_MIDTIER_CATEGORIES as v,CS2_MIN_KEYCHAIN_SEED as y,CS2_MIN_SEED as b,CS2_MIN_STATTRAK as x,CS2_MIN_WEAR as S,CS2_MISC_CATEGORIES as C,CS2_NAMETAGGABLE_ITEMS as w,CS2_NAMETAG_RE as T,CS2_NAMETAG_TOOL_DEF as E,CS2_PAINTABLE_ITEMS as D,CS2_PATCHABLE_ITEMS as te,CS2_RIFLE_CATEGORIES as ne,CS2_SEEDABLE_ITEMS as O,CS2_SNIPER_RIFLE_MODELS as k,CS2_STATTRAKABLE_ITEMS as A,CS2_STATTRAK_SWAP_TOOL_DEF as j,CS2_STICKERABLE_ITEMS as M,CS2_STORAGE_UNIT_TOOL_DEF as N,CS2_TEAMS_BOTH as P,CS2_TEAMS_CT as F,CS2_TEAMS_T as I,CS2_WEAR_FACTOR as L}from"./economy-constants.mjs";import{CS2RarityColorName as R,CS2RarityColorOrder as z,CS2RaritySoundName as B,CS2_BASE_ODD as V,CS2_RARITY_COLOR_DEFAULT as H,CS2_RARITY_ORDER as U,CS2_STATTRAK_ODD as W,randomFloat as G,randomInt as K}from"./economy-container.mjs";import{assert as q,compare as J,ensure as Y,safe as X}from"./utils.mjs";function Z(e){return function(t){return J(e.type,t.type)&&J(e.free,t.free)&&J(e.model,t.model)&&J(e.base,t.base)&&J(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,Y(n[e.id]));this.items.set(e.id,t),t.isSticker()&&(this.stickers.add(t),this.categories.add(Y(t.category))),this.itemsAsArray.push(t)}}getById(e){return Y(this.items.get(e))}get(e){return typeof e==`number`?this.getById(e):e}findItem(e){return Y(this.itemsAsArray.find(Z(e)))}filterItems(e){let t=this.itemsAsArray.filter(Z(e));return q(t.length>0),t}validateWear(e,t){return e===void 0?!0:(q(Number.isFinite(e)),q(String(e).length<=String(L).length),q(e>=S&&e<=g),t!==void 0&&(q(t.hasWear()),q(t.wearMin===void 0||e>=t.wearMin),q(t.wearMax===void 0||e<=t.wearMax)),!0)}safeValidateWear(e,t){return X(()=>this.validateWear(e,t))}validateSeed(e,t){return e===void 0?!0:(q(Number.isFinite(e)),q(Number.isInteger(e)),q(t===void 0||t.hasSeed()),q(e>=(t?.getMinimumSeed()??b)&&e<=(t?.getMaximumSeed()??m)),!0)}safeValidateSeed(e,t){return X(()=>this.validateSeed(e,t))}trimNametag(e){let t=e?.trim();return t===``?void 0:t}validateNametag(e,t){return e!==void 0&&(q(t===void 0||t.hasNametag()),q(e[0]!==` `&&T.test(e))),!0}safeValidateNametag(e,t){return X(()=>this.validateNametag(e,t))}requireNametag(e,t){return q(e===void 0||e.trim().length>0),this.validateNametag(e,t)}safeRequireNametag(e,t){return X(()=>this.requireNametag(e,t))}validateStatTrak(e,t){return e===void 0?!0:(q(t===void 0||t.hasStatTrak()),q(Number.isInteger(e)),q(e>=x&&e<=h),!0)}safeValidateStatTrak(e,t){return X(()=>this.validateStatTrak(e,t))}getWearFromValue(e){switch(!0){case e<=d:return r.FactoryNew;case e<=ee:return r.MinimalWear;case e<=f:return r.FieldTested;case e<=_: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?q(e.keys===void 0):(t.expectKey(),q(e.keys!==void 0),q(e.keys.includes(t.id))),!0}safeValidateContainerAndKey(e,t){return X(()=>this.validateContainerAndKey(e,t))}validateUnlockedItem(e,{id:t}){e=this.get(e).expectContainer(),q(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),q(typeof this.id==`number`),q(this.name),q(this.type),q(t.type===n.Stub||typeof this.rarity==`string`)}set contents(e){this._contents=e}get contents(){return this.expectContainer(),Y(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 P;case t.T:return I;case t.CT:return F;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&&k.includes(this.model)}isMachinegun(){return this.model!==void 0&&u.includes(this.model)}isHeavy(){return this.category===`heavy`}isEquipment(){return this.category===`equipment`}isInMidTiers(){return this.category!==void 0&&v.includes(this.category)}isInRifles(){return this.category!==void 0&&ne.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===N}isNameTag(){return this.isTool()&&this.def===E}isStatTrakSwapTool(){return this.isTool()&&this.def===j}isContract(){return this.isTool()&&this.def===a}expectAgent(){return q(this.isAgent()),this}expectPatch(){return q(this.isPatch()),this}expectSticker(){return q(this.isSticker()),this}expectKeychain(){return q(this.isKeychain()),this}expectStorageUnit(){return q(this.isStorageUnit()),this}expectNameTag(){return q(this.isNameTag()),this}expectStatTrakSwapTool(){return q(this.isStatTrakSwapTool()),this}expectContainer(){return q(this.isContainer()),this}expectKey(){return q(this.isKey()),this}hasWear(){return D.includes(this.type)&&!this.free&&this.index!==0}hasSeed(){return O.includes(this.type)&&!this.free&&this.index!==0}hasStickers(){return M.includes(this.type)&&!this.isC4()}hasKeychains(){return l.includes(this.type)&&!this.isC4()}hasPatches(){return te.includes(this.type)}hasNametag(){return w.includes(this.type)||this.isStorageUnit()}hasStatTrak(){return A.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 s.includes(this.type)}isInGraphicArts(){return c.includes(this.type)}isInContainers(){return i.includes(this.type)}isInDisplay(){return o.includes(this.type)}isPaintable(){return D.includes(this.type)}getImage(e){if(q(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(),q(this.rawSpecials),q(this.specialsImage),`${this.economy.baseUrl}${this.specialsImage}`}getTextureImage(){return`${this.economy.baseUrl}${Y(this.textureImage)}`}getModelBinary(){let{modelBinary:e}=this.parent??this;return`${this.economy.baseUrl}${Y(e)}`}getMinimumWear(){return this.wearMin??S}getMaximumWear(){return this.wearMax??g}getMinimumSeed(){return this.isKeychain()?y:b}getMaximumSeed(){return this.isKeychain()?p:m}groupContents(){let e={},t=this.specials;for(let t of this.contents){let n=R[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)=>(z[e.rarity]??H)-(z[t.rarity]??H))}unlockContainer(e){let t=this.groupContents(),n=Object.keys(t),r=U.filter(e=>n.includes(e)),i=e?.computeOdds?.(r)??r.map((e,t)=>V/5**t),a=i.reduce((e,t)=>e+t,0),o=r.map((e,t)=>[e,Y(i[t])/a]),s=Math.random(),[c]=Y(o[0]),l=0;for(let[e,t]of o)if(l+=t,s<=l){c=e;break}let u=Y(t[c]),d=Y(u[Math.floor(Math.random()*u.length)]),f=this.statTrakless!==!0,p=this.statTrakOnly===!0;return{attributes:{containerId:this.id,seed:d.hasSeed()?K(b,m):void 0,statTrak:f&&d.hasStatTrak()&&(p||Math.random()<=W)?0:void 0,wear:d.hasWear()?Number(G(d.wearMin??S,d.wearMax??g).toString().substring(0,L.toString().length)):void 0},id:d.id,rarity:B[d.rarity],special:c===`special`}}};const re=new Q;export{re as CS2Economy,Q as CS2EconomyInstance,$ as CS2EconomyItem};
@@ -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=r.wear??0,a=g(i+p);return a>l?(n.stickers.delete(t),n.stickers.size===0&&(n.stickers=void 0),this):(r.wear=a,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:b}}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{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=r.wear??0,a=g(i+p);return a>l?(n.stickers.delete(t),n.stickers.size===0&&(n.stickers=void 0),this):(r.wear=a,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};