Inventory item info
This commit is contained in:
parent
2bfce22530
commit
22dc1a5d9c
3 changed files with 64 additions and 5 deletions
|
|
@ -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) => {
|
|||
<li><b>!game help</b> - Prints this help message</li>
|
||||
<li><b>!game status</b> - Prints information about your character</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 nearby</b> - Shows nearby locations</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 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 fullName = getFullItemName(item);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue