@ianlucas/cs2-lib 7.30.0 → 7.31.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/inventory.mjs +1 -1
- package/dist/items.mjs +1 -1
- package/package.json +1 -1
package/dist/inventory.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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_STICKER_WEAR_FACTOR as a}from"./economy-constants.mjs";import{CS2Economy as o,CS2EconomyItem as s}from"./economy.mjs";import{resolveInventoryData as c}from"./inventory-upgrader.mjs";const l=1,u=1707696138408,d=[e.Agent,e.Collectible,e.Gloves,e.Graffiti,e.Melee,e.MusicKit,e.Weapon];function f(){return Math.ceil((Date.now()-u)/1e3)}function p(e){let t=0;for(;;){if(!e.has(t))return t;t++}}var m=class e{economy;items;options;static parse(e,t){return c(e??void 0,t)}constructor({economy:e,data:t,maxItems:n,storageUnitMaxItems:r}={}){this.economy=e??o,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<=5),t(n===void 0||n.hasStickers());for(let[e,{id:i,wear:o,rotation:s,x:c,y:l,schema:u}]of r){let r=parseInt(e,10);t(r>=0&&r<5),this.economy.getById(i).expectSticker(),o!==void 0&&(t(Number.isFinite(o)),t(String(o).length<=String(a).length),t(o>=0&&o<=.9)),s!==void 0&&(t(Number.isInteger(s)),t(s>=0&&s<=359)),c!==void 0&&t(Number.isFinite(c)),l!==void 0&&t(Number.isFinite(l)),u!==void 0&&(t(Number.isInteger(u)),t(u>=0&&u<(n?.getStickerSlotCount()??5)))}}validateKeychains(e,n){if(e===void 0)return;let r=Object.entries(e);t(r.length<=1),t(n===void 0||n.hasKeychains());for(let[e,{id:n,seed:i,x:a,y:o,z:s}]of r){let r=parseInt(e,10);t(r>=0&&r<=0),this.economy.getById(n).expectKeychain(),i!==void 0&&(t(Number.isFinite(i)),t(Number.isInteger(i)),t(i>=1&&i<=1e5)),a!==void 0&&t(Number.isFinite(a)),o!==void 0&&t(Number.isFinite(o)),s!==void 0&&t(Number.isFinite(o))}}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<=4),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 h(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=p(this.items),r=this.economy.getById(e.id);return t(!r.isStub()),this.items.set(n,new h(this,n,Object.assign(e,{equipped:void 0,equippedCT:void 0,equippedT:void 0,updatedAt:f()}),r)),this}addInventoryItem(e){t(!this.isFull());let n=p(this.items);return e.equipped=void 0,e.equippedCT=void 0,e.equippedT=void 0,e.uid=n,e.updatedAt=f(),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:f()}),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(d.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:f()}),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=f(),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=f(),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=p(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=f(),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=f(),this}applyItemSticker(e,n,r){t(r>=0&&r<=4);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=f(),this.items.delete(n),this}scrapeItemSticker(e,i){let o=this.get(e);t(o.stickers!==void 0);let s=n(o.stickers.get(i)),c=r((s.wear??0)+a);return c>1?(o.stickers.delete(i),o.stickers.size===0&&(o.stickers=void 0),this):(s.wear=c,o.updatedAt=f(),this)}applyItemPatch(e,n,r){t(r>=0&&r<=4);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=f(),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=f(),this}incrementItemStatTrak(e){let n=this.get(e);return t(n.statTrak!==void 0),n.statTrak<999999&&(n.statTrak++,n.updatedAt=f()),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=f(),a.statTrak=o,a.updatedAt=f(),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)}},h=class e extends s{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<5;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<1;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<5;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??0}getStickerWear(e){return this.stickers?.get(e)?.wear??0}getKeychainSeed(e){return this.keychains?.get(e)?.seed??1}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{m as CS2Inventory,h as CS2InventoryItem,d as CS2_INVENTORY_EQUIPPABLE_ITEMS,u as CS2_INVENTORY_TIMESTAMP,l as CS2_INVENTORY_VERSION,p as getNextUid,f 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_STICKER_WEAR_FACTOR as a}from"./economy-constants.mjs";import{CS2Economy as o,CS2EconomyItem as s}from"./economy.mjs";import{resolveInventoryData as c}from"./inventory-upgrader.mjs";const l=1,u=1707696138408,d=[e.Agent,e.Collectible,e.Gloves,e.Graffiti,e.Melee,e.MusicKit,e.Weapon];function f(){return Math.ceil((Date.now()-u)/1e3)}function p(e){let t=0;for(;;){if(!e.has(t))return t;t++}}var m=class e{economy;items;options;static parse(e,t){return c(e??void 0,t)}constructor({economy:e,data:t,maxItems:n,storageUnitMaxItems:r}={}){this.economy=e??o,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<=5),t(n===void 0||n.hasStickers());for(let[e,{id:i,wear:o,rotation:s,x:c,y:l,schema:u}]of r){let r=parseInt(e,10);t(r>=0&&r<5),this.economy.getById(i).expectSticker(),o!==void 0&&(t(Number.isFinite(o)),t(String(o).length<=String(a).length),t(o>=0&&o<=.9)),s!==void 0&&(t(Number.isInteger(s)),t(s>=0&&s<=359)),c!==void 0&&t(Number.isFinite(c)),l!==void 0&&t(Number.isFinite(l)),u!==void 0&&(t(Number.isInteger(u)),t(u>=0&&u<(n?.getStickerSlotCount()??5)))}}validateKeychains(e,n){if(e===void 0)return;let r=Object.entries(e);t(r.length<=1),t(n===void 0||n.hasKeychains());for(let[e,{id:n,seed:i,x:a,y:o,z:s}]of r){let r=parseInt(e,10);t(r>=0&&r<=0),this.economy.getById(n).expectKeychain(),i!==void 0&&(t(Number.isFinite(i)),t(Number.isInteger(i)),t(i>=1&&i<=1e5)),a!==void 0&&t(Number.isFinite(a)),o!==void 0&&t(Number.isFinite(o)),s!==void 0&&t(Number.isFinite(s))}}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<=4),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 h(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=p(this.items),r=this.economy.getById(e.id);return t(!r.isStub()),this.items.set(n,new h(this,n,Object.assign(e,{equipped:void 0,equippedCT:void 0,equippedT:void 0,updatedAt:f()}),r)),this}addInventoryItem(e){t(!this.isFull());let n=p(this.items);return e.equipped=void 0,e.equippedCT=void 0,e.equippedT=void 0,e.uid=n,e.updatedAt=f(),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:f()}),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(d.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:f()}),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=f(),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=f(),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=p(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=f(),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=f(),this}applyItemSticker(e,n,r){t(r>=0&&r<=4);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=f(),this.items.delete(n),this}scrapeItemSticker(e,i){let o=this.get(e);t(o.stickers!==void 0);let s=n(o.stickers.get(i)),c=r((s.wear??0)+a);return c>1?(o.stickers.delete(i),o.stickers.size===0&&(o.stickers=void 0),this):(s.wear=c,o.updatedAt=f(),this)}applyItemPatch(e,n,r){t(r>=0&&r<=4);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=f(),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=f(),this}incrementItemStatTrak(e){let n=this.get(e);return t(n.statTrak!==void 0),n.statTrak<999999&&(n.statTrak++,n.updatedAt=f()),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=f(),a.statTrak=o,a.updatedAt=f(),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)}},h=class e extends s{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<5;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<1;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<5;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??0}getStickerWear(e){return this.stickers?.get(e)?.wear??0}getKeychainSeed(e){return this.keychains?.get(e)?.seed??1}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{m as CS2Inventory,h as CS2InventoryItem,d as CS2_INVENTORY_EQUIPPABLE_ITEMS,u as CS2_INVENTORY_TIMESTAMP,l as CS2_INVENTORY_VERSION,p as getNextUid,f as getTimestamp};
|