// Player.js
(function () {
/*global adventurejs A*/
/**
* @ajspath adventurejs.Atom.Asset.Matter.Tangible.Character.Player
* @augments adventurejs.Character
* @class adventurejs.Player
* @ajsnavheading CharacterClasses
* @param {String} game_name The name of the top level game object.
* @param {String} name A name for the object, to be serialized and used as ID.
* @summary The player character.
* @todo Character swapping.
* @classdesc
* <p>
* <strong>Player</strong> is a subclass of
* {@link adventurejs.Character|Character}, used for
* the player character(s). It will be possible to have
* multiple player characters, though that hasn't been
* implemented yet.
* </p>
* <h3 class="examples">Example:</h3>
* <pre class="display"><code class="language-javascript">
* </code></pre>
**/
class Player extends adventurejs.Character {
constructor(name, game_name) {
super(name, game_name);
this.class = "Player";
this.is.active = false;
this.is._known = true;
this.is._seen = true;
this.setIOVs([{ hold: { with_params: { max_connections: 2 } } }]);
this.setDOVs([
"aft",
"down",
"east",
"enter",
"exit",
"fore",
"in",
"north",
"northeast",
"northwest",
"out",
"port",
"south",
"southeast",
"southwest",
"starboard",
"up",
"west",
]);
}
get articlename() {
return this.game.dictionary.pronouns[this.pronouns]["ourself"];
}
validate(game) {
super.validate(game);
// do we already have an active player?
if (
"" !== this.game.world._player &&
"undefined" !== typeof this.game.world[this.game.world._player] &&
Object.keys(this.game.world[this.game.world._player]).length > 0
) {
var msg = `Player.js > ${this.game.world[this.game.world._player].name} and ${this.name} are both set is.active.
Only one Player can be active. Using ${this.game.world[this.game.world._player].name}. `;
this.game.log("L1450", "warn", "critical", msg, "warning");
this.is.active = false;
} else {
this.game.world._player = this.id;
this.synonyms.push("me", "myself");
}
return true;
}
}
adventurejs.Player = Player;
})();