Inventory item info

This commit is contained in:
Aslan 2026-01-21 14:53:49 -05:00
parent 2bfce22530
commit 22dc1a5d9c
3 changed files with 64 additions and 5 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "aslobot-matrix", "name": "aslobot-matrix",
"version": "1.3.0", "version": "1.3.0-dev",
"description": "", "description": "",
"license": "ISC", "license": "ISC",
"author": "", "author": "",

View file

@ -9,7 +9,9 @@ import {
import { getLevel } from "../../services/game/game.js"; import { getLevel } from "../../services/game/game.js";
import { import {
getFullItemName, getFullItemName,
getTotalStats,
type IItem, type IItem,
type IStat,
type Location, type Location,
} from "../../services/game/index.js"; } from "../../services/game/index.js";
let client: MatrixClient; let client: MatrixClient;
@ -52,7 +54,7 @@ const onHelp = (_text: string, roomId: string) => {
<li><b>!game help</b> - Prints this help message</li> <li><b>!game help</b> - Prints this help message</li>
<li><b>!game status</b> - Prints information about your character</li> <li><b>!game status</b> - Prints information about your character</li>
<li><b>!game inventory</b> - Shows your inventory</li> <li><b>!game inventory</b> - Shows your inventory</li>
<li><b>(WIP) !game inventory {index}</b> - Shows information about an item in your inventory</li> <li><b>!game inventory {index}</b> - Shows information about an item in your inventory</li>
<li><b>!game location</b> - Shows information about your current location</li> <li><b>!game location</b> - Shows information about your current location</li>
<li><b>!game nearby</b> - Shows nearby locations</li> <li><b>!game nearby</b> - Shows nearby locations</li>
<li><b>(WIP) !game travel {location}</b> - Travel to a location</li> <li><b>(WIP) !game travel {location}</b> - Travel to a location</li>
@ -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 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 `<li><b>Damage type:</b> ${stat.damageType}</li><li><b>Damage:</b> ${stat.damage}</li>`;
};
const mapAbility = (stat: IStat): string => {
return `<li><${stat.abilityType}</li>`;
};
client.sendHtmlMessage(
roomId,
"",
`<p>${getFullItemName(item)}</p>
<ul>
<li><b>Description:</b> ${item.description}</li>
<li><b>Durability:</b> ${item.durability}/100</li>
<li><b>Value:</b> ${item.value}</li>
<li><b>Type:</b> ${item.type}</li>
<li><b>Rarity:</b> ${item.rarity}</li>
<li><b>Total damage:</b> ${totalStats.damage}</li>
<li><b>Total defence:</b> ${totalStats.defense}</li>
</ul>
<p>Damage:</p>
<ul>
${item.stats.map(mapDamage)}
</ul>
<p>Abilities:</p>
<ul>
${item.stats.map(mapAbility)}
</ul>`,
);
}
const mapItem = (item: IItem, index: number): string => { const mapItem = (item: IItem, index: number): string => {
const fullName = getFullItemName(item); const fullName = getFullItemName(item);

View file

@ -1,4 +1,4 @@
import type { IItem } from "./structures/items.js"; import type { IItem, IStat } from "./structures/items.js";
import { import {
rarities, rarities,
Rarity, Rarity,
@ -20,4 +20,18 @@ const getRarity = (id: Rarity): IRarity => {
return rarity ? rarity : rarityCommon; 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 };