Stuff ad things

This commit is contained in:
Kim Ravn Hansen
2026-02-12 16:54:27 +01:00
parent de96d45ade
commit 7ecb4f724b
5 changed files with 274 additions and 251 deletions

View File

@@ -60,8 +60,11 @@ export class Character {
/** @type {Set<string>} Things the character is particularly proficient at. */
proficiencies = new Set();
/** @type {Map<Item,number} Things the character is particularly proficient at. */
items = new Map();
/** @type {Set<Item} Things the character is particularly proficient at. */
items = new Set();
/** @type {string[]} */
freeSlots = [];
/**
* @param {string} name The name of the character
@@ -72,44 +75,18 @@ export class Character {
/** Add an item to the equipment list
* @param {Item} item
* @param {number} count
*
* Maybe return the accumulated ItemSlots used?
*/
addItem(item, count = 1) {
if (!Number.isInteger(count)) {
throw new Error("Number must be an integer");
}
addItem(item) {
if (!(item instanceof Item)) {
console.debug("bad item", item);
throw new Error("item must be an instance of Item!");
}
if (count <= 0) {
throw new Error("Number must be > 0");
}
const existingItemCount = this.items.get(item) || 0;
this.items.set(item, count + existingItemCount);
this.items.add(item)
}
clamp(skill, min, max) {
const val = this[skill];
if (val === undefined) {
throw new Error(`Invalid skill >>>${skill}<<<`)
}
if (val < min) {
this[skill] = min
return
}
if (val > max) {
this.skill = max;
return
}
}
// todo removeItem(item, count)
}

View File

@@ -41,6 +41,9 @@ export class ItemAttributes {
/** @constant @readonly @type {string[]} Type of ammo that this item is, or that this item uses */
skills = [];
/** @constant @readonly @type {boolean} Can a person wearing this armor be stealthy? */
sneak;
}
/**
@@ -53,7 +56,7 @@ export class ItemBlueprint extends ItemAttributes {
/**
* Constructor
*
* @param {object} o Object whose attributes we copy
* @param {ItemAttributes} o Object whose attributes we copy
*/
constructor(o) {
super();
@@ -106,4 +109,4 @@ export class ItemBlueprint extends ItemAttributes {
* arrows that are consumed. In this case, each individual arrow is not tracked
* as its own entity, only the quiver is tracked.
*/
export class Item extends ItemAttributes {}
export class Item extends ItemAttributes { }