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

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

  var p = adventurejs.Parser.prototype;

  /**
   * Exclude the subject's parent and room from a list of assets.
   * @method adventurejs.Parser#selectNotParentOrRoom
   * @memberOf adventurejs.Parser
   * @param {Array} list
   * @returns {Array}
   */
  p.selectNotParentOrRoom = function Parser_selectNotParentOrRoom(list) {
    if ("string" === typeof list) list = [list];
    if (!Array.isArray(list)) {
      this.game.log(
        "L1281",
        "error",
        "critical",
        [
          "[selectNotParentOrRoom.js] selectNotParentOrRoom() received non-array",
          list,
        ],
        "Parser"
      );
      return [];
    }
    this.game.log(
      "L1520",
      "log",
      "high",
      `[selectNotParentOrRoom.js] selectNotParentOrRoom() receive:\n${list}`,
      "Parser"
    );
    var foundObjects = [];
    var input = this.game.getInput();
    var player = this.game.getPlayer();
    var subject = input.getSubject();
    var room = this.game.getRoom();
    const nested = subject.isNested();

    for (var i = 0; i < list.length; i++) {
      var object = this.game.getAsset(list[i]);

      if (object.id === room.id) {
        continue;
      }

      if (nested && object.id === subject.getNestId()) {
        continue;
      }

      if (
        nested &&
        object.id === room.id &&
        subject.getNestAsset() instanceof adventurejs.Floor
      ) {
        continue;
      }

      foundObjects.push(list[i]);
    }

    return foundObjects;
  };
})();