Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Weight Calculation for Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Apr 4, 2023
1 parent d2642d1 commit 6e181c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/core/plugins/core-inventory/server/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const offers: { [hash: string]: OfferInfo } = {};
// Storages
const openStorages: { [player_id: string]: Array<StoredItem> } = {};
const openStorageSessions: { [player_id: string]: string } = {};
const openStoragesWeight: { [player_id: string]: number } = {};

// Callbacks
const openCallbacks: Array<PlayerCallback> = [];
Expand Down Expand Up @@ -315,12 +316,24 @@ const Internal = {
}

if (info.startType === 'custom') {
const maxWeight = openStoragesWeight[player.id];
if (Athena.systems.inventory.weight.isWeightExceeded([complexSwap.from], maxWeight)) {
InventoryView.storage.resync(player);
return;
}

openStorages[player.id] = complexSwap.from;
} else {
await Athena.document.character.set(player, info.startType, complexSwap.from);
}

if (info.endType === 'custom') {
const maxWeight = openStoragesWeight[player.id];
if (Athena.systems.inventory.weight.isWeightExceeded([complexSwap.to], maxWeight)) {
InventoryView.storage.resync(player);
return;
}

openStorages[player.id] = complexSwap.to;
} else {
await Athena.document.character.set(player, info.endType, complexSwap.to);
Expand Down Expand Up @@ -649,6 +662,7 @@ export const InventoryView = {
items: Array<StoredItem>,
storageSize: number,
forceOpenInventory = false,
maxWeight: number = Number.MAX_SAFE_INTEGER,
) {
if (forceOpenInventory) {
player.emit(INVENTORY_EVENTS.TO_CLIENT.OPEN);
Expand All @@ -666,6 +680,7 @@ export const InventoryView = {

openStorages[player.id] = deepCloneArray<StoredItem>(items);
openStorageSessions[player.id] = uid;
openStoragesWeight[player.id] = maxWeight;
const fullStorageList = Athena.systems.inventory.manager.convertFromStored(openStorages[player.id]);
Athena.webview.emit(player, INVENTORY_EVENTS.TO_WEBVIEW.SET_CUSTOM, fullStorageList, storageSize);
},
Expand Down
1 change: 0 additions & 1 deletion src/core/server/systems/inventory/clothing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as alt from 'alt-server';

import * as Athena from '@AthenaServer/api';
import { Appearance } from '@AthenaShared/interfaces/appearance';
import { ClothingComponent, ClothingInfo, StoredItem } from '@AthenaShared/interfaces/item';
import { isNullOrUndefined } from '@AthenaShared/utility/undefinedCheck';
import { Character } from '@AthenaShared/interfaces/character';
Expand Down

0 comments on commit 6e181c5

Please sign in to comment.