diff --git a/package.json b/package.json
index 51ace47..9b3f775 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "aslobot-matrix",
- "version": "1.3.0",
+ "version": "1.3.0-dev",
"description": "",
"license": "ISC",
"author": "",
diff --git a/src/modules/game/game.ts b/src/modules/game/game.ts
index 4a595bb..f738e5b 100644
--- a/src/modules/game/game.ts
+++ b/src/modules/game/game.ts
@@ -9,7 +9,9 @@ import {
import { getLevel } from "../../services/game/game.js";
import {
getFullItemName,
+ getTotalStats,
type IItem,
+ type IStat,
type Location,
} from "../../services/game/index.js";
let client: MatrixClient;
@@ -52,7 +54,7 @@ const onHelp = (_text: string, roomId: string) => {
!game help - Prints this help message
!game status - Prints information about your character
!game inventory - Shows your inventory
- (WIP) !game inventory {index} - Shows information about an item in your inventory
+ !game inventory {index} - Shows information about an item in your inventory
!game location - Shows information about your current location
!game nearby - Shows nearby locations
(WIP) !game travel {location} - Travel to a location
@@ -93,9 +95,52 @@ const onStatus = (_text: string, roomId: string, sender: string) => {
);
};
-const onInventory = (_text: string, roomId: string, sender: string) => {
+const onInventory = (text: string, roomId: string, sender: string) => {
const player = getPlayerById(sender);
+ const itemIndex = text.replace(`${gamePrefix} location `, "").trim();
+ const itemIndexInt = Number(itemIndex);
+ if (!isNaN(itemIndexInt)) {
+ const item = player.inventory.items[itemIndexInt];
+ if (!item) {
+ client.sendTextMessage(roomId, "No item with that index found");
+ return;
+ }
+
+ const totalStats = getTotalStats(item);
+
+ const mapDamage = (stat: IStat): string => {
+ return `Damage type: ${stat.damageType}Damage: ${stat.damage}`;
+ };
+
+ const mapAbility = (stat: IStat): string => {
+ return `<${stat.abilityType}`;
+ };
+
+ client.sendHtmlMessage(
+ roomId,
+ "",
+ `${getFullItemName(item)}
+
+ - Description: ${item.description}
+ - Durability: ${item.durability}/100
+ - Value: ${item.value}
+ - Type: ${item.type}
+ - Rarity: ${item.rarity}
+ - Total damage: ${totalStats.damage}
+ - Total defence: ${totalStats.defense}
+
+ Damage:
+
+ ${item.stats.map(mapDamage)}
+
+ Abilities:
+
+ ${item.stats.map(mapAbility)}
+
`,
+ );
+ }
+
const mapItem = (item: IItem, index: number): string => {
const fullName = getFullItemName(item);
diff --git a/src/services/game/item.ts b/src/services/game/item.ts
index b2cd4e7..9e1fa47 100644
--- a/src/services/game/item.ts
+++ b/src/services/game/item.ts
@@ -1,4 +1,4 @@
-import type { IItem } from "./structures/items.js";
+import type { IItem, IStat } from "./structures/items.js";
import {
rarities,
Rarity,
@@ -20,4 +20,18 @@ const getRarity = (id: Rarity): IRarity => {
return rarity ? rarity : rarityCommon;
};
-export { getFullItemName, getRarityName, getRarity };
+const getTotalStats = (item: IItem): IStat => {
+ const totalStats: IStat = {
+ damage: 0,
+ defense: 0,
+ };
+
+ item.stats.forEach((stat) => {
+ totalStats.damage += stat.damage;
+ totalStats.defense += stat.defense;
+ });
+
+ return totalStats;
+};
+
+export { getFullItemName, getRarityName, getRarity, getTotalStats };