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

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

  var p = adventurejs.Parser.prototype;

  /**
   * Exclude from a list of assets all assets in player's inventory.
   * @method adventurejs.Parser#selectNotInInventory
   * @memberOf adventurejs.Parser
   * @param {Array} list
   * @returns {Array}
   */
  p.selectNotInInventory = function Parser_selectNotInInventory(list) {
    if ("string" === typeof list) list = [list];
    if (!Array.isArray(list)) {
      this.game.log(
        "L1283",
        "warn",
        "critical",
        "selectNotInInventory.js > received non-array",
        "Parser"
      );
      return [];
    }
    var foundObjects = [];
    for (var i = 0; i < list.length; i++) {
      var object = this.game.getAsset(list[i]);
      if (object.isWithin(this.game.getPlayer())) {
        continue;
      }

      foundObjects.push(list[i]);
    }

    return foundObjects;
  };
})();