Stuff ad things
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user