Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// NPC.js
(function () {
  /*global adventurejs A*/

  /**
   * @ajspath adventurejs.Atom.Asset.Matter.Tangible.Character.NPC
   * @augments adventurejs.Character
   * @class adventurejs.NPC
   * @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 For non-player characters.
   * @todo AI, movement, conversation.
   * @tutorial Characters_NPCs
   * @tutorial Scripting_NPCs
   * @todo more methods, better example
   * @classdesc
   * <p>
   * <strong>NPC</strong> is a subclass of
   * {@link adventurejs.Character|Character} and the base class
   * for all non-player characters.
   * </p>
   * <h3 class="examples">Example:</h3>
   * <pre class="display"><code class="language-javascript">MyGame.createAsset({
   *   "class": "NPC",
   *   "name": "Floyd",
   *   "synonyms": ["robot"],
   *   "place":{ in: "Utility Closet" },
   * })
   * </code></pre>
   **/
  class NPC extends adventurejs.Character {
    constructor(name, game_name) {
      super(name, game_name);
      this.class = "NPC";
      this.game.NPCs[this.id] = this.id;

      this.setDOVs(["ask", "tell"]);
      this.setIOVs(["show"]);
      // this.setIOVs([]);
      // this.acceptsCommands

      this.can_use_verbs = [];

      // this.onInputParsed = (e) => {
      //   this.game.print(
      //     `${this.UID} ${this.uuid} ${this.Name} does something. `
      //   );
      //   console.warn(
      //     `${this.UID} ${this.uuid} ${this.id} received inputParseComplete`,
      //     e
      //   );
      // };

      // this.game.reactor.removeEventListener(
      //   "inputParseComplete",
      //   this.onInputParsed
      // );
      // this.game.reactor.addEventListener(
      //   "inputParseComplete",
      //   this.onInputParsed
      // );

      /**
       * Container for author's string|array|function to print
       * when NPC is idling in current room.
       * @var {Object} adventurejs.Character#on_idle
       * @default {}
       */
      this.on_idle = {};

      /**
       * Container for author's string|array|function methods
       * to print when NPC is asked about assets. This is a
       * streamlined alternative to using doAskThisAboutThat.
       * @var {Object} adventurejs.Character#on_ask_about
       * @default {}
       */
      this.on_ask_about = {};

      /**
       * Container for author's string|array|function methods
       * to print when NPC is told about assets. This is a
       * streamlined alternative to using doTellThisAboutThat.
       * @var {Object} adventurejs.Character#on_tell_about
       * @default {}
       */
      this.on_tell_about = {};

      /**
       * Container for author's string|array|function methods
       * to print when player tries to give assets to NPC.
       * This is a streamlined alternative to using doGiveThatToThis.
       * @var {Object} adventurejs.Character#on_give_to
       * @default {}
       */
      this.on_give_to = {};

      /**
       * Container for author's string|array|function methods
       * to print when player tries to show assets to NPC.
       * This is a streamlined alternative to using doShowThatToThis.
       * @var {Object} adventurejs.Character#on_show_to
       * @default {}
       */
      this.on_show_to = {};

      /**
       * Container for author's string|array|function methods
       * to print when player tries to take assets from NPC.
       * This is a streamlined alternative to using doTakeThatFromThis.
       * @var {Object} adventurejs.Character#on_take_from
       * @default {}
       */
      this.on_take_from = {};
    }

    // onInputParsed(e) {
    //   this.game.print(`Something does something. `);
    //   console.warn(`Something received inputParseComplete`, e);
    // }
    //
  }
  adventurejs.NPC = NPC;
})();