Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// selectNotPlayer.js

(function () {
  /* global adventurejs A */

  var p = adventurejs.Parser.prototype;

  /**
   * Exclude the player from a list of assets.
   * @method adventurejs.Parser#selectNotPlayer
   * @memberOf adventurejs.Parser
   * @param {Array} list
   * @returns {Array}
   */
  p.selectNotPlayer = function Parser_selectNotPlayer(list) {
    if ("string" === typeof list) list = [list];
    if (!Array.isArray(list)) {
      this.game.log(
        "L1262",
        "error",
        "critical",
        ["[selectNotPlayer.js] selectNotPlayer() received non-array", list],
        "Parser"
      );
      return [];
    }
    this.game.log(
      "L1193",
      "log",
      "high",
      `[selectNotPlayer.js] selectNotPlayer() receive:\n${list}`,
      "Parser"
    );

    var input = this.game.getInput();
    var player = this.game.getPlayer();
    var subject = input.getSubject();

    var foundObjects = [];
    for (var i = 0; i < list.length; i++) {
      var object = this.game.getAsset(list[i]);
      if (!object) continue;
      if (object.id === player.id) continue;
      foundObjects.push(list[i]);
    }

    //console.warn( "selectNotPlayer returned " + JSON.stringify(foundObjects) );
    return foundObjects;
  };
})();