stuff and junk and things
This commit is contained in:
@@ -7,25 +7,32 @@ import * as id from "../utils/id.js";
|
||||
* @class
|
||||
*/
|
||||
export class Character {
|
||||
|
||||
/** @type {string} character's name */
|
||||
name;
|
||||
|
||||
/** @protected @type {number} The number of XP the character has. */
|
||||
_xp = 0;
|
||||
get xp() { return this._xp; }
|
||||
get xp() {
|
||||
return this._xp;
|
||||
}
|
||||
|
||||
/** @protected @type {number} The character's level. */
|
||||
_level = 1;
|
||||
get level() { return this._level; }
|
||||
get level() {
|
||||
return this._level;
|
||||
}
|
||||
|
||||
/** @protected @type {string} unique name used for chats when there's a name clash and also other things that require a unique character id */
|
||||
_id;
|
||||
get id() { return this._id; }
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
/** @protected @type {string} username of the player that owns this character. */
|
||||
_username;
|
||||
get username() { return this._username; }
|
||||
get username() {
|
||||
return this._username;
|
||||
}
|
||||
|
||||
/** @type {string} Bloodline background */
|
||||
ancestry;
|
||||
@@ -57,7 +64,6 @@ export class Character {
|
||||
* @param {boolean} initialize Should we initialize the character
|
||||
*/
|
||||
constructor(playerUname, name, initialize) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
// Initialize the unique name if this character.
|
||||
@@ -138,7 +144,9 @@ export class Character {
|
||||
this.meleeCombat = Math.max(this.skulduggery, 10);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Logic error, ancestry d8() roll was out of scope');
|
||||
throw new Error(
|
||||
"Logic error, ancestry d8() roll was out of scope",
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -167,7 +175,7 @@ export class Character {
|
||||
this.equipment
|
||||
.set("sickle", 1)
|
||||
.set("poisoner's kit", 1)
|
||||
.set("healer's kit", 1)
|
||||
.set("healer's kit", 1);
|
||||
default:
|
||||
this.foundation = "debug";
|
||||
this.proficiencies.add("heavy_armor");
|
||||
|
||||
@@ -11,8 +11,7 @@ import WebSocket from "ws";
|
||||
import { Character } from "./character.js";
|
||||
import { ItemTemplate } from "./item.js";
|
||||
|
||||
export class Game{
|
||||
|
||||
export class Game {
|
||||
/** @type {Map<string,ItemTemplate>} List of all item templates in the game */
|
||||
_itemTemplates = new Map();
|
||||
|
||||
@@ -33,5 +32,8 @@ export class Game{
|
||||
* @protected
|
||||
* @type {Map<string,Player>} Map of users in the game username->Player
|
||||
*/
|
||||
_players = new Map(); get players() { return this._players; }
|
||||
_players = new Map();
|
||||
get players() {
|
||||
return this._players;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import { cleanName } from "../utils/id.js";
|
||||
* generate these CharacterItems.
|
||||
*/
|
||||
export class ItemTemplate {
|
||||
|
||||
_id;
|
||||
_name;
|
||||
_description;
|
||||
@@ -42,15 +41,18 @@ export class ItemTemplate {
|
||||
* @param {string=} id Item's machine-friendly name.
|
||||
*/
|
||||
constructor(name, itemSlots, description, id) {
|
||||
|
||||
if (typeof name !== "string") {
|
||||
throw new Error("Name must be a string, but " + typeof name + " given.");
|
||||
throw new Error(
|
||||
"Name must be a string, but " + typeof name + " given.",
|
||||
);
|
||||
}
|
||||
if (typeof description === "undefined") {
|
||||
description = "";
|
||||
}
|
||||
if (typeof description !== "string") {
|
||||
throw new Error("Name must be a string, but " + typeof name + " given.");
|
||||
throw new Error(
|
||||
"Name must be a string, but " + typeof name + " given.",
|
||||
);
|
||||
}
|
||||
if (!Number.isFinite(itemSlots)) {
|
||||
throw new Error("itemSlots must be a finite number!");
|
||||
@@ -66,11 +68,15 @@ export class ItemTemplate {
|
||||
this._id = id;
|
||||
this._itemSlots = Number(itemSlots);
|
||||
this._description = "";
|
||||
|
||||
}
|
||||
|
||||
createItem() {
|
||||
return new ChracterItem(this._id, this._name, this._description, this._itemSlots);
|
||||
return new ChracterItem(
|
||||
this._id,
|
||||
this._name,
|
||||
this._description,
|
||||
this._itemSlots,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +88,10 @@ export class ItemTemplate {
|
||||
*
|
||||
* If a character picks up a Pickaxe in the dungeon, a new CharacterItem is spawned and injected into
|
||||
* the character's Equipment Map. If the item is dropped/destroyed/sold, the CharacterItem is removed from
|
||||
* the character's Equipment Map, and then deleted from memory.
|
||||
* the character's Equipment Map, and then deleted from memory.
|
||||
*
|
||||
* If a ChracterItem is traded away to another character, The other character inserts a clone of this item
|
||||
* into their equipment map, and the item is then deleted from the previous owner's equipment list.
|
||||
* If a ChracterItem is traded away to another character, The other character inserts a clone of this item
|
||||
* into their equipment map, and the item is then deleted from the previous owner's equipment list.
|
||||
* This is done so we do not have mulltiple characters with pointers to the same item - we would rather risk
|
||||
* dupes than wonky references.
|
||||
*
|
||||
@@ -94,9 +100,8 @@ export class ItemTemplate {
|
||||
* Another bonus is, that the game can spawn custom items that arent even in the ItemTemplate Set.
|
||||
*/
|
||||
export class CharacterItem {
|
||||
|
||||
/** @type {string?} The unique name if the ItemTemplate this item is based on. May be null. */
|
||||
templateItemId; // We use the id instead of a pointer, could make garbage collection better.
|
||||
templateItemId; // We use the id instead of a pointer, could make garbage collection better.
|
||||
|
||||
/** @type {string} The player's name for this item. */
|
||||
name;
|
||||
@@ -119,7 +124,3 @@ const i = new ItemTemplate("knife", 10000);
|
||||
|
||||
const ci = new CharacterItem();
|
||||
console.log(ci);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Portal } from "./portal";
|
||||
|
||||
/**
|
||||
* Location in the world.
|
||||
*
|
||||
* Can contain characters, quests, monsters, loot, NPCs and more.
|
||||
*
|
||||
* Can contain mundane portals (such as doors or pathways) to adjacent rooms/locations,
|
||||
* or magical portals to distant locations.
|
||||
*/
|
||||
* Location in the world.
|
||||
*
|
||||
* Can contain characters, quests, monsters, loot, NPCs and more.
|
||||
*
|
||||
* Can contain mundane portals (such as doors or pathways) to adjacent rooms/locations,
|
||||
* or magical portals to distant locations.
|
||||
*/
|
||||
export class Location {
|
||||
/** @protected @type string */
|
||||
_id;
|
||||
@@ -34,7 +34,7 @@ export class Location {
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
*/
|
||||
constructor(id, name, description) {
|
||||
this._id = id;
|
||||
this._name = name;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import WebSocket from 'ws';
|
||||
import WebSocket from "ws";
|
||||
|
||||
/**
|
||||
* Player Account.
|
||||
@@ -13,18 +13,24 @@ import WebSocket from 'ws';
|
||||
* We regularly ping and pong to ensure that stale connections are closed.
|
||||
*
|
||||
*/
|
||||
export class Player{
|
||||
export class Player {
|
||||
/** @protected @type {string} unique username */
|
||||
_username;
|
||||
get username() { return this._username; }
|
||||
get username() {
|
||||
return this._username;
|
||||
}
|
||||
|
||||
/** @protected @type {string} */
|
||||
_passwordHash;
|
||||
get passwordHash() { return this._passwordHash; }
|
||||
get passwordHash() {
|
||||
return this._passwordHash;
|
||||
}
|
||||
|
||||
/** @protected @type {WebSocket} Player's current and only websocket. If undefined, the player is not logged in. */
|
||||
_websocket;
|
||||
get websocket() { return this._websocket; }
|
||||
get websocket() {
|
||||
return this._websocket;
|
||||
}
|
||||
|
||||
/** @protected @type {Date} */
|
||||
_latestSocketReceived;
|
||||
@@ -46,7 +52,11 @@ export class Player{
|
||||
*/
|
||||
_send(data) {
|
||||
if (!this._websocket) {
|
||||
console.error("Trying to send a message to an uninitialized websocket", this, data)
|
||||
console.error(
|
||||
"Trying to send a message to an uninitialized websocket",
|
||||
this,
|
||||
data,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (this._websocket.readyState === WebSocket.OPEN) {
|
||||
@@ -54,19 +64,36 @@ export class Player{
|
||||
return true;
|
||||
}
|
||||
if (this._websocket.readyState === WebSocket.CLOSED) {
|
||||
console.error("Trying to send a message through a CLOSED websocket", this, data);
|
||||
console.error(
|
||||
"Trying to send a message through a CLOSED websocket",
|
||||
this,
|
||||
data,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (this._websocket.readyState === WebSocket.CLOSING) {
|
||||
console.error("Trying to send a message through a CLOSING websocket", this, data);
|
||||
console.error(
|
||||
"Trying to send a message through a CLOSING websocket",
|
||||
this,
|
||||
data,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (this._websocket.readyState === WebSocket.CONNECTING) {
|
||||
console.error("Trying to send a message through a CONNECTING (not yet open) websocket", this, data);
|
||||
console.error(
|
||||
"Trying to send a message through a CONNECTING (not yet open) websocket",
|
||||
this,
|
||||
data,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
console.error("Trying to send a message through a websocket with an UNKNOWN readyState (%d)", this.websocket.readyState, this, data);
|
||||
console.error(
|
||||
"Trying to send a message through a websocket with an UNKNOWN readyState (%d)",
|
||||
this.websocket.readyState,
|
||||
this,
|
||||
data,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,5 +101,3 @@ export class Player{
|
||||
this.sendMessage(`\n[${this.currentRoom}] > `);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
* @todo Add encounters to portals
|
||||
*/
|
||||
export class Portal {
|
||||
|
||||
/**
|
||||
* Target Location.
|
||||
* Target Location.
|
||||
*/
|
||||
_targetLocationId;
|
||||
|
||||
@@ -23,5 +22,4 @@ export class Portal {
|
||||
* Description shown to the player when they traverse the portal.
|
||||
*/
|
||||
_traversalDescription;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user