Files
pirate-corsaire-server/Game/InventoryList.js
T
2026-08-24 22:20:36 +02:00

41 lines
1.0 KiB
JavaScript

const LinkedList = require("../Utility/LinkedList");
class LinkedListNode {
constructor(key, value) {
this.key = key;
this.value = value;
this.next = null;
};
};
class InventoryList extends LinkedList {
constructor() {
super();
};
accumulateItem(key, value) {
const entry = this.map.get(key);
const updatedValue = entry ? entry.value.amount + value.amount : value;
if (entry) entry.value.amount = updatedValue;
else this.addItem(key, updatedValue); /// eeeh
}
addItem(key, value) {
if (!key || !value || !value.categoryID || !value.id || isNaN(value.amount)) return console.info("addItem", key, value);
const temp = new LinkedListNode(key, value);
if (!this.head) {
this.head = temp;
this.tail = temp;
} else {
this.tail.next = temp;
this.tail = temp;
};
this.map.set(key, temp);
}
};
module.exports = InventoryList;