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

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

  var p = adventurejs.Parser.prototype;

  /**
   * Exclude from a list of assets all assets held in player's hands.
   * @method adventurejs.Parser#selectNotInHands
   * @memberOf adventurejs.Parser
   * @param {Array} list
   * @returns {Array}
   */
  p.selectNotInHands = function Parser_selectNotInHands(list) {
    if ("string" === typeof list) list = [list];
    if (!Array.isArray(list)) {
      this.game.log(
        "L1210",
        "warn",
        "critical",
        "selectNotInHands.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 instanceof adventurejs.Substance) {
        foundObjects.push(list[i]);
        continue;
      }

      if (object instanceof adventurejs.Room) {
        foundObjects.push(list[i]);
        continue;
      }
      // if it hasn't got a parent, it's not in inventory
      // not originally intended but this applies directly to substances
      if (!object.getPlaceAsset) continue;
      var parent = object.getPlaceAsset();
      if (!parent) continue;
      if (parent.id === this.game.world._player && !object.is.worn) {
        continue;
      }

      foundObjects.push(list[i]);
    }

    return foundObjects;
  };
})();