This repository has been archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as Athena from '@AthenaServer/api'; | ||
import { BaseItemEx, ItemEx, StoredItemEx } from '@AthenaShared/interfaces/item'; | ||
|
||
/** | ||
* Converts a stored item into a full item. | ||
* | ||
* Does not perform any inventory changes. | ||
* | ||
* Returns undefined if base item was not found. | ||
* | ||
* @export | ||
* @template CustomData | ||
* @param {StoredItemEx<CustomData>} storedItem | ||
*/ | ||
export function toItem<CustomData = {}>(storedItem: StoredItemEx<CustomData>): ItemEx<CustomData> | undefined { | ||
const results = Athena.systems.inventory.manager.convertFromStored<CustomData>([storedItem]); | ||
|
||
if (results.length <= 0) { | ||
return undefined; | ||
} | ||
|
||
return results[0]; | ||
} | ||
|
||
/** | ||
* Convert a stored Item to a base item | ||
* | ||
* Does not perform any inventory changes. | ||
* | ||
* @export | ||
* @template CustomData | ||
* @param {StoredItemEx<CustomData>} storedItem | ||
* @return {BaseItemEx<CustomData>} | ||
*/ | ||
export function toBaseItem<CustomData = {}>(storedItem: StoredItemEx<CustomData>): BaseItemEx<CustomData> { | ||
return Athena.systems.inventory.factory.getBaseItem<CustomData>(storedItem.dbName, storedItem.version); | ||
} | ||
|
||
/** | ||
* Convert a Base Item to a stored item | ||
* | ||
* Does not perform any inventory changes. | ||
* | ||
* @export | ||
* @template CustomData | ||
* @param {BaseItemEx<CustomData>} baseItem | ||
* @param {number} quantity | ||
* @return {*} | ||
*/ | ||
export function toStoredItem<CustomData = {}>(baseItem: BaseItemEx<CustomData>, quantity: number) { | ||
return Athena.systems.inventory.factory.fromBaseToStored(baseItem, quantity); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters