code:
var _SceneManager_onKeyDown = SceneManager.onKeyDown;
SceneManager.onKeyDown = function (event) {
  _SceneManager_onKeyDown.call(this, event);
  if (!event.ctrlKey && !event.altKey) {
    if (!$gameTemp || !$gameTemp.isPlaytest()) {
      return;
    }
    if (SceneManager._scene instanceof Scene_Battle) {
      // F9
      if (event.keyCode == 120) {
        for (var _i = 0, _a = $gameTroop.aliveMembers(); _i < _a.length; _i++) {
          var e = _a[_i];
          var action = new Game_Action($gameActors.actor(1));
          action.setSkill(1);
          e.gainHp(-9999);
          if (e.isAlive()) {
            e.gainHp(-9999);
          }
          BattleManager.checkBattleEnd();
        }
      }
      // F10
    }
  }
};
var Nore;
(function (Nore) {
  function debugSkip() {
    if (!$gameTemp || !$gameTemp.isPlaytest()) {
      //return false;
    }
    if ($gameSwitches.value(999)) {
      return false;
    }
    if (isSkipKey()) {
      return true;
    }
    return false;
  }
  Nore.debugSkip = debugSkip;
})(Nore || (Nore = {}));


code:
var __extends =
  (this && this.__extends) ||
  (function () {
    var extendStatics = function (d, b) {
      extendStatics =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&
          function (d, b) {
            d.__proto__ = b;
          }) ||
        function (d, b) {
          for (var p in b)
            if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
        };
      return extendStatics(d, b);
    };
    return function (d, b) {
      if (typeof b !== "function" && b !== null)
        throw new TypeError(
          "Class extends value " + String(b) + " is not a constructor or null"
        );
      extendStatics(d, b);
      function __() {
        this.constructor = d;
      }
      d.prototype =
        b === null
          ? Object.create(b)
          : ((__.prototype = b.prototype), new __());
    };
  })();
/*:ja
 * @target MZ
 * @author ル
 *
 * @command addFacility
 * @text 施設追加
 * @des 施設追加
 * @arg facilityId
 * @type number
 * @text facilityId
 * @desc facilityId
 * @arg level
 * @type number
 * @text level
 * @desc level
 * @arg note
 * @type sting
 *
 * @command levelUp
 * @text レベルアップ
 * @des レベルアップ
 * @arg facilityId
 * @type number
 * @text facilityId
 * @desc facilityId
 * @arg level
 * @type number
 * @text level
 * @desc level
 * @arg note
 * @type sting
 */
var Nore;
(function (Nore) {
  var pluginName = "Nore_Facility";
  PluginManager.registerCommand(pluginName, "addFacility", function (args) {
    var facilityId = parseInt(args.facilityId);
    var level = parseInt(args.level);
    $slg.facilityInfo().addFacility(facilityId, level);
  });
  PluginManager.registerCommand(pluginName, "levelUp", function (args) {
    var facilityId = parseInt(args.facilityId);
    var level = parseInt(args.level);
    var facility = $slg.facilityInfo().findFacility(facilityId);
    if (!facility) {
      return;
    }
    var count = level - facility.level();
    for (var i = 0; i < count; i++) {
      $slg.facilityInfo().levelUp(facilityId);
    }
  });
})(Nore || (Nore = {}));
var MAP_CHANGED_SW = 110;
var MAP_CHANGED_VAR = 27;
var FacilityType;
(function (FacilityType) {
  FacilityType[(FacilityType["headquarters"] = 0)] = "headquarters";
  FacilityType[(FacilityType["combatant"] = 1)] = "combatant";
  FacilityType[(FacilityType["monster"] = 2)] = "monster";
  FacilityType[(FacilityType["shootingStudio"] = 3)] = "shootingStudio";
  FacilityType[(FacilityType["sharedRoom"] = 4)] = "sharedRoom";
  FacilityType[(FacilityType["barracks"] = 5)] = "barracks";
  FacilityType[(FacilityType["soupKitchen"] = 6)] = "soupKitchen";
  FacilityType[(FacilityType["baby"] = 7)] = "baby";
  FacilityType[(FacilityType["gene"] = 8)] = "gene";
  FacilityType[(FacilityType["kichen"] = 9)] = "kichen";
  FacilityType[(FacilityType["radar"] = 10)] = "radar";
  FacilityType[(FacilityType["weapon"] = 11)] = "weapon";
  FacilityType[(FacilityType["live"] = 12)] = "live";
  FacilityType[(FacilityType["stage4"] = 13)] = "stage4";
  FacilityType[(FacilityType["piercingStudio"] = 14)] = "piercingStudio";
  FacilityType[(FacilityType["stage5"] = 15)] = "stage5";
  FacilityType[(FacilityType["bodyCustom"] = 16)] = "bodyCustom";
  FacilityType[(FacilityType["douseiFree"] = 17)] = "douseiFree";
  FacilityType[(FacilityType["training"] = 18)] = "training";
  FacilityType[(FacilityType["trainingPlus"] = 19)] = "trainingPlus";
  FacilityType[(FacilityType["accelerator"] = 20)] = "accelerator";
  FacilityType[(FacilityType["ninshinSokusei"] = 22)] = "ninshinSokusei";
  FacilityType[(FacilityType["douseiNinshin"] = 23)] = "douseiNinshin";
  FacilityType[(FacilityType["aloma"] = 24)] = "aloma";
})(FacilityType || (FacilityType = {}));
var FacilityId;
(function (FacilityId) {
  FacilityId[(FacilityId["sharedRoom"] = 46)] = "sharedRoom";
  FacilityId[(FacilityId["barracks"] = 37)] = "barracks";
  FacilityId[(FacilityId["soupKichen"] = 43)] = "soupKichen";
})(FacilityId || (FacilityId = {}));
var FacilityCommand;
(function (FacilityCommand) {
  FacilityCommand["levelUp"] = "levelUp";
})(FacilityCommand || (FacilityCommand = {}));
var FacilityEvent = /** @class */ (function () {
  function FacilityEvent(commonId, sceratioId) {
    if (sceratioId === void 0) {
      sceratioId = "";
    }
    this._commonId = 0;
    this._sceratioId = "";
    this._commonId = commonId;
    this._sceratioId = sceratioId;
  }
  FacilityEvent.prototype.run = function () {
    if (this._commonId > 0) {
      $gameParty.addCommonEvent(this._commonId, -1);
    }
    if (this._sceratioId.length > 0) {
      $gameParty.addScenario(this._sceratioId, -1);
    }
  };
  return FacilityEvent;
})();
var FacilityInfo = /** @class */ (function () {
  function FacilityInfo() {
    this._facilityList = [];
    this._resultList = [];
  }
  FacilityInfo.prototype.resultList = function () {
    return this._resultList || [];
  };
  FacilityInfo.prototype.clearResultList = function () {
    this._resultList = [];
  };
  FacilityInfo.prototype.onStart = function () {
    //this.addFacility(21);
    //this.addFacility(41, 1);
  };
  FacilityInfo.prototype.hasFacility = function (itemId) {
    for (var _i = 0, _a = this._facilityList; _i < _a.length; _i++) {
      var f = _a[_i];
      if (f.itemId() == itemId) {
        return true;
      }
    }
    return false;
  };
  FacilityInfo.prototype.hasDouseiRoom = function () {
    for (var _i = 0, _a = this._facilityList; _i < _a.length; _i++) {
      var f = _a[_i];
      if (f.type() == FacilityType.sharedRoom) {
        return true;
      }
    }
    return false;
  };
  FacilityInfo.prototype.matchFacilityType = function (type, level) {
    for (var _i = 0, _a = this._facilityList; _i < _a.length; _i++) {
      var f = _a[_i];
      if (f.type() == type) {
        return f.level() >= level;
      }
    }
    return false;
  };
  FacilityInfo.prototype.addFacility = function (itemId) {
    var facility = this.facilityAt(itemId);
    if (!facility.isValid()) {
      console.error("施設が不正です:" + itemId);
      return;
    }
    this._facilityList.push(facility);
    //this.checkFacilityEvent(facility);
    //this.checkNextFacility(facility);
    this._dirty = true;
  };
  /*checkNextFacility(facility: Facility) {
        for (let i = 21; i <= 100; i++) {
            const item = $dataItems[i];
            if (! item) {
                continue;
            }
            if (! item.name || item.name.length == 0) {
                continue;
            }
            const before = parseInt(item.meta['before']);
            if (before == facility.itemId()) {
                this.addFacility(item.id);

            }
        }
    }*/
  FacilityInfo.prototype.checkFacilityEvent = function (facility) {
    if (facility.type() == FacilityType.combatant) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "1面_03_施設イベント_01");
      }
      if (facility.level() == 2) {
        return new FacilityEvent(0, "1面_03_施設イベント_02");
      }
    }
    if (facility.type() == FacilityType.sharedRoom) {
      //$gameVariables.setValue(MAP_CHANGED_VAR, facility.level());
      var actorId = parseInt(facility.item().meta["actor"]);
      switch (actorId) {
        case 9:
          return new FacilityEvent(206);
        case 4:
          return new FacilityEvent(247);
        case 13:
          return new FacilityEvent(250);
        case 17:
          return new FacilityEvent(251);
      }
      return null;
    }
    if (facility.type() == FacilityType.soupKitchen) {
      if (facility.level() == 1) {
        var time = this.calcSoupKichenReloadTime();
        //$slg.addTimeGaugeEvent(new SoupKichenTimeGaugeEvent(time));
        return new FacilityEvent(0, "炊き出し所イベント_01");
      }
      $slg.manInfo().soupKichen().reload();
    }
    if (facility.type() == FacilityType.baby) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "分娩室イベント_01");
      }
    }
    if (facility.type() == FacilityType.kichen) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "キッチンイベント_01");
      }
    }
    if (facility.type() == FacilityType.piercingStudio) {
      if (facility.level() == 1) {
        if ($gameSwitches.value(356)) {
          return new FacilityEvent(0, "ピアススタジオイベント_02");
        } else {
          return new FacilityEvent(0, "ピアススタジオイベント_01");
        }
      }
    }
    if (facility.type() == FacilityType.radar) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "3面_03_01");
      }
    }
    if (facility.type() == FacilityType.live) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "センリ_同棲ライブ_02");
      }
    }
    if (facility.type() == FacilityType.monster) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "研究所イベント_01");
      }
    }
    if (facility.type() == FacilityType.stage4) {
      if (facility.level() == 1) {
        return new FacilityEvent(258);
      }
    }
    if (facility.type() == FacilityType.stage5) {
      if (facility.level() == 1) {
        return new FacilityEvent(261);
      }
    }
    if (facility.type() == FacilityType.weapon) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "武器イベント_01");
      }
    }
    if (facility.type() == FacilityType.bodyCustom) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "肉体変化イベント_01");
      }
    }
    if (facility.type() == FacilityType.douseiFree) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "同棲制限解除イベント_01");
      }
    }
    if (facility.type() == FacilityType.training) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "怪人訓練イベント_01");
      }
    }
    if (facility.type() == FacilityType.trainingPlus) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "怪人促成所イベント_01");
      }
    }
    if (facility.type() == FacilityType.accelerator) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "粒子加速器イベント_01");
      }
    }
    if (facility.type() == FacilityType.ninshinSokusei) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "妊娠促成所イベント_01");
      }
    }
    if (facility.type() == FacilityType.douseiNinshin) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "受精研究所イベント_01");
      }
    }
    if (facility.type() == FacilityType.aloma) {
      if (facility.level() == 1) {
        return new FacilityEvent(0, "友好アロマイベント_01");
      }
    }
    return null;
  };
  FacilityInfo.prototype.calcSoupKichenReloadTime = function () {
    var level = this.findMaxFacility(FacilityType.soupKitchen);
    return 3000;
  };
  FacilityInfo.prototype.facilityList = function () {
    return this._facilityList;
  };
  FacilityInfo.prototype.update = function () {
    this._resultList = [];
    for (var _i = 0, _a = this._facilityList; _i < _a.length; _i++) {
      var f = _a[_i];
      var result = f.update();
      if (result) {
        this._resultList.push(result);
      }
    }
  };
  FacilityInfo.prototype.levelUp = function (facilityId, eventId) {
    //$gameParty.loseGold(facility.price());
    this.addFacility(facilityId);
    var facility = this.findFacility(facilityId);
    if (facility.type() == FacilityType.combatant) {
      $factoryManager.onFactoryLevelUp(facility.level());
    }
    this._dirty = true;
    var facilityEvent = this.checkFacilityEvent(facility);
    if (facilityEvent) {
      facilityEvent.run();
      $slg.fadeoutTimeGaugeEvent(eventId);
    } else {
      AudioManager.playSe({ name: "Recovery", volume: 80, pitch: 100, pan: 0 });
      $slg.removeTimeGaugeEvent(eventId);
    }
    //this.removeFacility(facility);
    //this.addFacility(facility.itemId() + 1);
  };
  FacilityInfo.prototype.removeFacility = function (facility) {
    var index = -1;
    for (var i = 0; i < this._facilityList.length; i++) {
      var f = this._facilityList[i];
      if (f.itemId() == facility.itemId()) {
        index = i;
        break;
      }
    }
    if (index < 0) {
      return;
    }
    this._facilityList.splice(index, 1);
  };
  FacilityInfo.prototype.facilityAt = function (itemId) {
    var item = $dataItems[itemId];
    return new Facility(itemId, parseInt(item.meta["lv"]));
  };
  FacilityInfo.prototype.isDirty = function () {
    return this._dirty;
  };
  FacilityInfo.prototype.clearDirty = function () {
    this._dirty = false;
  };
  FacilityInfo.prototype.maxPower = function () {
    for (var i = 0; i < this._facilityList.length; i++) {
      var f = this._facilityList[i];
      if (f.type() == FacilityType.monster) {
        return f.max();
      }
    }
  };
  FacilityInfo.prototype.avRewardRate = function () {
    for (var i = 0; i < this._facilityList.length; i++) {
      var f = this._facilityList[i];
      if (f.type() == FacilityType.headquarters) {
        return f.value();
      }
    }
    return 0;
  };
  FacilityInfo.prototype.findFacility = function (itemId) {
    var max = null;
    for (var i = 0; i < this._facilityList.length; i++) {
      var f = this._facilityList[i];
      if (f.itemId() == itemId) {
        if (!max) {
          max = f;
        } else if (max.level() < f.level()) {
          max = f;
        }
      }
    }
    return max;
  };
  FacilityInfo.prototype.findMaxFacility = function (type) {
    var max = null;
    for (var i = 0; i < this._facilityList.length; i++) {
      var f = this._facilityList[i];
      if (f.type() == type) {
        if (!max) {
          max = f;
        } else if (max.level() < f.level()) {
          max = f;
        }
      }
    }
    return max;
  };
  FacilityInfo.prototype.findMaxFacilityLevel = function (type) {
    var f = this.findMaxFacility(type);
    if (!f) {
      return 0;
    }
    return f.level();
  };
  FacilityInfo.prototype.isFacilityExists = function (facilityId) {
    for (var i = 0; i < this._facilityList.length; i++) {
      var f = this._facilityList[i];
      if (f.itemId() == facilityId) {
        return true;
      }
    }
    return false;
  };
  FacilityInfo.prototype.inConstruction = function (facility) {
    var list = $slg.timeGaugeEventList();
    for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
      var e = list_1[_i];
      if (e.type() == TimeGaugeEventType.facility) {
        var f = e;
        if (f.facilityId() == facility.itemId()) {
          if (f._remain > 0) {
            return true;
          }
        }
      }
    }
    return false;
  };
  FacilityInfo.prototype.isDouseiOptionEnabled = function (play) {
    if (play.itemId() == 12) {
      return this.hasFacility(56);
    }
    return false;
  };
  return FacilityInfo;
})();
var FacilityResult = /** @class */ (function () {
  function FacilityResult(type1, value1, type2, value2, facilityType) {
    this._type1 = type1;
    this._type2 = type2;
    this._value1 = value1;
    this._value2 = value2;
    this._facilityType = facilityType;
  }
  FacilityResult.prototype.type1 = function () {
    return this._type1;
  };
  FacilityResult.prototype.type2 = function () {
    return this._type2;
  };
  FacilityResult.prototype.value1 = function () {
    return this._value1;
  };
  FacilityResult.prototype.value2 = function () {
    return this._value2;
  };
  FacilityResult.prototype.facilityType = function () {
    return this._facilityType;
  };
  return FacilityResult;
})();
var Facility = /** @class */ (function () {
  function Facility(itemId, lv) {
    this._time = 0;
    this._itemId = itemId;
    this._lv = lv;
  }
  Facility.prototype.itemId = function () {
    return this._itemId;
  };
  Facility.prototype.item = function () {
    return $dataItems[this._itemId];
  };
  Facility.prototype.maxLevel = function () {
    return parseInt(this.item().meta["maxLevel"]);
  };
  Facility.prototype.type = function () {
    return parseInt(this.item().meta["type"]);
  };
  Facility.prototype.max = function () {
    if (this.level() == 0) {
      return 0;
    }
    return (
      parseInt(this.item().meta["max"]) +
      (this.level() - 1) * this.levelUpMaxValue()
    );
  };
  Facility.prototype.levelUpMaxValue = function () {
    return parseInt(this.item().meta["levelUpMaxValue"]);
  };
  Facility.prototype.levelUpValue = function () {
    return parseInt(this.item().meta["levelUpValue"]);
  };
  Facility.prototype.levelUp = function () {
    this._lv++;
  };
  Facility.prototype.level = function () {
    return this._lv;
  };
  Facility.prototype.value = function () {
    return (
      parseInt(this.item().meta["value"]) +
      (this.level() - 1) * this.levelUpValue()
    );
  };
  Facility.prototype.cost = function () {
    return parseInt(this.item().meta["cost"]);
  };
  Facility.prototype.name = function () {
    switch (ConfigManager.language) {
      case "en":
        if (this.item().meta["nameEn"]) {
          return this.item().meta["nameEn"];
        }
        break;
      case "ch":
      case "jp":
        break;
    }
    return this.item().name;
  };
  Facility.prototype.nameWithoutLevel = function () {
    var texts = this.name().split(" ");
    if (texts && texts.length > 0) {
      return texts[0];
    }
    return this.name();
  };
  Facility.prototype.iconIndex = function () {
    return this.item().iconIndex;
  };
  Facility.prototype.price = function () {
    return this.item().price;
  };
  Facility.prototype.expForLevel = function (level) {
    var c = this.currentClass();
    var basis = c.expParams[0];
    var extra = c.expParams[1];
    var acc_a = c.expParams[2];
    var acc_b = c.expParams[3];
    return Math.round(
      (basis * Math.pow(level - 1, 0.9 + acc_a / 250) * level * (level + 1)) /
        (6 + Math.pow(level, 2) / 50 / acc_b) +
        (level - 1) * extra
    );
  };
  Facility.prototype.currentClass = function () {
    return $dataClasses[this.itemId()];
  };
  Facility.prototype.description = function () {
    if (this.type() == FacilityType.combatant) {
      return this.factoryDescription();
    }
    if (this.type() == FacilityType.barracks) {
      return this.barracksDescription();
    }
    if (this.level() == 1) {
      switch (ConfigManager.language) {
        case "en":
          if (this.item().meta["descLv0En"]) {
            return this.item().meta["descLv0En"].replace("\\n", "\n");
          }
          break;
        case "ch":
        case "jp":
          break;
      }
      if (this.item().meta["descLv0"]) {
        return this.item().meta["descLv0"].replace("\\n", "\n");
      }
    }
    switch (ConfigManager.language) {
      case "en":
        if (this.item().meta["descEn"]) {
          return this.item().meta["descEn"].format(this.value(), this.max());
        }
        if (this.item().meta["desc1En"]) {
          var desc1 = this.item().meta["desc1En"];
          if (this.item().meta["desc2En"]) {
            var desc2 = this.item().meta["desc2En"];
            return desc1 + "\n" + desc2;
          }
          return desc1;
        }
        break;
      case "ch":
      case "jp":
        break;
    }
    return this.item().description.format(this.value(), this.max());
  };
  Facility.prototype.factoryDescription = function () {
    if (this.level() == 1) {
      return TextManager.facilityFactory1;
    }
    return TextManager.facilityFactory2;
  };
  Facility.prototype.barracksDescription = function () {
    if (this.level() >= 0) {
      return "バトルに参加できるユニットが１つ増えます";
    }
    return "";
  };
  Facility.prototype.rate = function () {
    return this._time / this.maxTime();
  };
  Facility.prototype.update = function () {
    if (this.level() == 0) {
      return null;
    }
    this._time++;
    if (this._time > this.maxTime()) {
      this._time -= this.maxTime();
      return this.onTime();
    }
    return null;
  };
  Facility.prototype.onTime = function () {
    return null;
    /*
        switch (this.type()) {
            case FacilityType.headquarters:
                return this.onHeadquarters();
            case FacilityType.combatant:
            case FacilityType.shootingStudio:
                return;
            default:
                console.error('不正な施設です');
        }
        return null;*/
  };
  Facility.prototype.onHeadquarters = function () {
    return null;
    /*
        const reward = $slg.calcAllAvReward();
        $gameParty.gainGold(reward);
        $slg.avInfo().onReward();
        return new FacilityResult(Nore.EffectType.gold, reward, Nore.EffectType.none, 0, this.type());
        */
  };
  Facility.prototype.onShootingStudio = function () {};
  Facility.prototype.maxTime = function () {
    return parseInt(this.item().meta["time"]);
  };
  Facility.prototype.isValid = function () {
    return !isNaN(this.level());
  };
  Facility.prototype.timeRate = function () {
    if (!this.item().meta["timeRate"]) {
      return 1;
    }
    return parseInt(this.item().meta["timeRate"]);
  };
  Facility.prototype.constructionTime = function () {
    return parseInt(this.item().meta["time"]);
  };
  Facility.prototype.inConstruction = function () {
    for (var _i = 0, _a = $slg.timeGaugeEventList(); _i < _a.length; _i++) {
      var e = _a[_i];
      if (e.type() == TimeGaugeEventType.facility) {
        var event_1 = e;
        if (event_1.facilityId() == this.itemId()) {
          return true;
        }
      }
    }
    return false;
  };
  return Facility;
})();
(function (Nore) {
  var Window_FacilityList = /** @class */ (function (_super) {
    __extends(Window_FacilityList, _super);
    function Window_FacilityList() {
      var _this = this;
      var r = new Rectangle(160, Nore.TOP_Y, 400, 540);
      _this = _super.call(this, r) || this;
      _this._dataList = [];
      _this._additionalSprites = {};
      _this.makeItems();
      _this.refresh();
      return _this;
    }
    Window_FacilityList.prototype.maxItems = function () {
      return this._dataList.length;
    };
    Window_FacilityList.prototype.makeItems = function () {
      this._dataList = [];
      this._dataList = $slg.facilityInfo().facilityList();
    };
    Window_FacilityList.prototype.itemHeight = function () {
      return 100;
    };
    Window_FacilityList.prototype.update = function () {
      if ($slg.facilityInfo().isDirty()) {
        $slg.facilityInfo().clearDirty();
        this.refresh();
      }
      _super.prototype.update.call(this);
    };
    Window_FacilityList.prototype.refresh = function () {
      this._windowContentsSprite.removeChildren();
      _super.prototype.refresh.call(this);
    };
    Window_FacilityList.prototype.drawItem = function (index) {
      this.resetFontSettings();
      var rect = this.itemRect(index);
      var facility = this._dataList[index];
      var inConstruction = $slg.facilityInfo().inConstruction(facility);
      if (inConstruction) {
        this.changePaintOpacity(false);
      } else {
        this.changePaintOpacity(true);
      }
      this.contents.fontSize = 22;
      this.drawIcon(facility.iconIndex(), rect.x, rect.y);
      var name = facility.name();
      if (inConstruction) {
        name += " 建設中";
      }
      this.drawText(name, rect.x + 40, rect.y, 300);
      if (facility.level() > 0 && facility.maxLevel() > 1) {
        this.drawText(
          "Lv " + facility.level(),
          rect.x + 240,
          rect.y,
          120,
          "right"
        );
      }
      if (facility.level() < facility.maxLevel()) {
        this.drawText(facility.price(), rect.x + 80, rect.y + 32, 120);
        this.drawIcon(Icon.gold, rect.x + 40, rect.y + 32);
      }
      this.drawTextEx(facility.description(), rect.x + 140, rect.y + 40, 300);
    };
    Window_FacilityList.prototype.resetFontSettings = function () {
      _super.prototype.resetFontSettings.call(this);
      this.contents.fontSize = 14;
    };
    Window_FacilityList.prototype.lineHeight = function () {
      return 28;
    };
    Window_FacilityList.prototype.placeGauge = function (actor, type, x, y) {
      var key = "actor%1-gauge-%2".format(actor.actorId(), type);
      var sprite = this.createInnerSprite(key, Sprite_Gauge);
      sprite.setup(actor, type);
      sprite.move(x, y);
      sprite.show();
    };
    Window_FacilityList.prototype.createInnerSprite = function (
      key,
      spriteClass
    ) {
      var dict = this._additionalSprites;
      if (dict[key]) {
        return dict[key];
      } else {
        var sprite = new spriteClass();
        dict[key] = sprite;
        this.addInnerChild(sprite);
        return sprite;
      }
    };
    Window_FacilityList.prototype.selectedFacility = function () {
      return this._dataList[this.index()];
    };
    Window_FacilityList.prototype.isCurrentItemEnabled = function () {
      var facility = this.selectedFacility();
      return !$slg.facilityInfo().inConstruction(facility);
    };
    return Window_FacilityList;
  })(Window_Selectable);
  Nore.Window_FacilityList = Window_FacilityList;
  var Window_FacilityCommand = /** @class */ (function (_super) {
    __extends(Window_FacilityCommand, _super);
    function Window_FacilityCommand() {
      var _this = this;
      var r = new Rectangle(570, Nore.TOP_Y, 260, 146);
      _this = _super.call(this, r) || this;
      _this.refresh();
      _this.hide();
      return _this;
    }
    Window_FacilityCommand.prototype.itemHeight = function () {
      return 60;
    };
    Window_FacilityCommand.prototype.makeCommandList = function () {
      if (!this._facility) {
        return;
      }
      var enable = this._facility.price() <= $gameParty.gold();
      this.addCommand(
        TextManager.levelUpFacility.format(this._facility.price()),
        FacilityCommand.levelUp,
        enable
      );
      this.addCommand(TextManager._cancel, "cancel", true);
    };
    Window_FacilityCommand.prototype.resetFontSettings = function () {
      this.contents.fontFace = $gameSystem.mainFontFace();
      this.contents.fontSize = 22;
      this.resetTextColor();
    };
    Window_FacilityCommand.prototype.setFacility = function (facility) {
      this._facility = facility;
      this.refresh();
    };
    return Window_FacilityCommand;
  })(Window_Command);
  Nore.Window_FacilityCommand = Window_FacilityCommand;
})(Nore || (Nore = {}));

repo_name: onms/dead

license: unknown


code:
var FactoryManager = /** @class */ (function () {
  function FactoryManager() {}
  FactoryManager.prototype.onFactoryLevelUp = function (level) {
    if (level == 1) {
      this.addLevel1();
    } else if (level == 2) {
      this.addLevel2();
    } else if (level == 3) {
      this.addLevel3();
    } else if (level == 4) {
      this.addLevel4();
    }
  };
  FactoryManager.prototype.addLevel1 = function () {
    var f = $slg.formation();
    f.addMember(187, 1);
    f.addMember(188, 1);
    f.addMember(189, 1);
    f.addMember(190, 1);
    f.addMember(191, 1);
    f.setActor(0, f.findBattleActorByActorId(187));
    f.setActor(1, f.findBattleActorByActorId(188));
    f.setActor(2, f.findBattleActorByActorId(189));
    f.setActor(3, f.findBattleActorByActorId(190));
    f.setActor(4, f.findBattleActorByActorId(191));
  };
  FactoryManager.prototype.addLevel2 = function () {
    var f = $slg.formation();
    f.findBattleActorByActorId(187).levelUp();
    f.findBattleActorByActorId(188).levelUp();
    f.findBattleActorByActorId(189).levelUp();
    f.findBattleActorByActorId(190).levelUp();
    f.findBattleActorByActorId(191).levelUp();
  };
  FactoryManager.prototype.addLevel3 = function () {
    var f = $slg.formation();
    f.findBattleActorByActorId(187).levelUp();
    f.findBattleActorByActorId(188).levelUp();
    f.findBattleActorByActorId(189).levelUp();
    f.findBattleActorByActorId(190).levelUp();
    f.findBattleActorByActorId(191).levelUp();
  };
  FactoryManager.prototype.addLevel4 = function () {
    var f = $slg.formation();
    f.addMember(191, 1);
    if (f.isEmpty(4)) {
      f.setActor(4, f.findBattleActorByActorId(191));
    }
  };
  return FactoryManager;
})();
var $factoryManager = new FactoryManager();


code:
var __extends =
  (this && this.__extends) ||
  (function () {
    var extendStatics = function (d, b) {
      extendStatics =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&
          function (d, b) {
            d.__proto__ = b;
          }) ||
        function (d, b) {
          for (var p in b)
            if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
        };
      return extendStatics(d, b);
    };
    return function (d, b) {
      if (typeof b !== "function" && b !== null)
        throw new TypeError(
          "Class extends value " + String(b) + " is not a constructor or null"
        );
      extendStatics(d, b);
      function __() {
        this.constructor = d;
      }
      d.prototype =
        b === null
          ? Object.create(b)
          : ((__.prototype = b.prototype), new __());
    };
  })();
var Window_FacilityTree = /** @class */ (function (_super) {
  __extends(Window_FacilityTree, _super);
  function Window_FacilityTree() {
    var _this = this;
    var r = new Rectangle(Nore.MAIN_MENU_W, Nore.TOP_Y, 1040, 636);
    _this = _super.call(this, r) || this;
    _this._timeGaugeEventSpriteList = [];
    ImageManager.loadSystem("tree");
    _this.createHelpWindow();
    return _this;
  }
  Window_FacilityTree.prototype.start = function () {
    this.makeItems();
    this.refresh();
    //this.selectInitialAv();
    this.setHandler("change", this.onChange.bind(this));
  };
  Window_FacilityTree.prototype.refresh = function () {
    this.removeTutoArrow();
    this._windowContentsBackSprite.removeChildren();
    this._windowContentsBackSprite2.removeChildren();
    this._windowContentsSprite.removeChildren();
    this._timeGaugeEventSpriteList = [];
    _super.prototype.refresh.call(this);
  };
  Window_FacilityTree.prototype.removeTutoArrow = function () {
    if (!this._tutoArrow) {
      return;
    }
    this._windowContentsSprite.removeChild(this._tutoArrow);
    this._tutoArrow = null;
  };
  Window_FacilityTree.prototype.onChange = function () {
    var item = this.selectedItem();
    if (item) {
      if (item.isTaikenbanNg()) {
        this._helpWindow.setText(TextManager.facilityTaikenbanNg);
      } else {
        this._helpWindow.setText(item.facility().description());
      }
    } else {
      this._helpWindow.clear();
    }
  };
  Window_FacilityTree.prototype.updateHelp = function () {};
  Window_FacilityTree.prototype.createHelpWindow = function () {
    var rect = this.helpWindowRect();
    this._helpWindow = new Window_Help2(rect);
    this.addChild(this._helpWindow);
  };
  Window_FacilityTree.prototype.helpWindowRect = function () {
    var wx = 0;
    var wy = this.height;
    var ww = this.width;
    var wh = 120;
    return new Rectangle(wx, wy, ww, wh);
  };
  Window_FacilityTree.prototype.selectInitialAv = function () {
    if ($gameTemp.av) {
      var av = this.findAv($gameTemp.av.itemId());
      if (!av) {
        this.selectCenter();
        return;
      }
      var index = this.indexOf(av);
      if (index >= 0) {
        this.select(index);
      }
    } else {
      this.selectCenter();
    }
  };
  Window_FacilityTree.prototype.selectCenter = function () {};
  Window_FacilityTree.prototype.indexOf = function (av) {
    return av.y * this.maxCols() + av.x;
  };
  Window_FacilityTree.prototype.refreshCursor = function () {
    if (this._cursorAll) {
      this.refreshCursorForAll();
    } else if (this.index() >= 0) {
      var rect = this.itemRect(this.index());
      this.setCursorRect(
        rect.x - 5,
        rect.y - 5,
        rect.width - 9,
        rect.height - 14
      );
    } else {
      this.setCursorRect(0, 0, 0, 0);
    }
  };
  Window_FacilityTree.prototype.itemWidth = function () {
    var w = _super.prototype.itemWidth.call(this);
    return w - 5;
  };
  Window_FacilityTree.prototype.itemRect = function (index) {
    var rect = _super.prototype.itemRect.call(this, index);
    rect.x += 22;
    rect.y += 40;
    return rect;
  };
  Window_FacilityTree.prototype.findAv = function (itemId) {
    for (var key in this._avMap) {
      var av = this._avMap[key];
      if (av.itemId() == itemId) {
        return av;
      }
    }
    return null;
  };
  Window_FacilityTree.prototype.makeItems = function () {
    this._avMap = {};
    var list = FACILITY_LIST;
    for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
      var f = list_1[_i];
      if (!f.isVisible()) {
        continue;
      }
      this._avMap[this.createKey(f.x, f.y)] = f;
    }
  };
  Window_FacilityTree.prototype.checkFinished = function (list) {
    var avList = $slg.avInfo().actorAvList(this._actor.actorId());
    for (var _i = 0, list_2 = list; _i < list_2.length; _i++) {
      var FacilityItem_1 = list_2[_i];
      FacilityItem_1.clear();
    }
    for (var _a = 0, list_3 = list; _a < list_3.length; _a++) {
      var FacilityItem_2 = list_3[_a];
      if (this.contains(FacilityItem_2, avList)) {
        FacilityItem_2.countUp();
      }
    }
  };
  Window_FacilityTree.prototype.contains = function (FacilityItem, avList) {
    for (var _i = 0, avList_1 = avList; _i < avList_1.length; _i++) {
      var av = avList_1[_i];
      if (av.itemId() == FacilityItem.itemId()) {
        return true;
      }
    }
    return false;
  };
  Window_FacilityTree.prototype.maxCols = function () {
    return 5;
  };
  Window_FacilityTree.prototype.itemHeight = function () {
    return 70;
  };
  Window_FacilityTree.prototype.maxItems = function () {
    if (!this._avMap) {
      return 0;
    }
    return this.maxY() * this.maxCols();
  };
  Window_FacilityTree.prototype.maxY = function () {
    var max = 0;
    for (var key in this._avMap) {
      var num = parseInt(key);
      var y = Math.round(num / AV_ITEM_Y);
      if (max < y) {
        max = y;
      }
    }
    return max + 1;
  };
  Window_FacilityTree.prototype.createKey = function (x, y) {
    return x + y * AV_ITEM_Y;
  };
  Window_FacilityTree.prototype.drawAllItems = function () {
    _super.prototype.drawAllItems.call(this);
  };
  Window_FacilityTree.prototype.drawItemBackground = function (index) {};
  Window_FacilityTree.prototype.isCurrentItemEnabled = function () {
    var av = this.selectedItem();
    if (!av) {
      return false;
    }
    return this.isItemEnabled(av);
  };
  Window_FacilityTree.prototype.drawAvBg = function (facility, rect) {
    if (facility.isFinished() || facility.isConstruction()) {
      var sprite_1 = this.getSprite(0, 48 * 2, 172, 48);
      sprite_1.x = rect.x;
      sprite_1.y = rect.y;
      this._windowContentsBackSprite.addChild(sprite_1);
      return;
    }
    if (facility.canSelect(this._avMap)) {
      var index = 10;
      if (facility.price() <= $gameParty.gold()) {
        index = 6;
      }
      var sprite_2 = this.getSprite(0, 48 * index, 172, 48);
      sprite_2.x = rect.x;
      sprite_2.y = rect.y;
      this._windowContentsBackSprite.addChild(sprite_2);
      return;
    }
    var sprite = this.getSprite(0, 48 * 5, 172, 48);
    sprite.x = rect.x;
    sprite.y = rect.y;
    this._windowContentsBackSprite.addChild(sprite);
  };
  Window_FacilityTree.prototype.getSprite = function (x, y, w, h) {
    var baseTexture = Nore.getSystemBaseTexture("tree");
    var r = new Rectangle(x, y, w, h);
    var texture = new PIXI.Texture(baseTexture, r);
    var s = new PIXI.Sprite(texture);
    return s;
  };
  Window_FacilityTree.prototype.isItemEnabled = function (av) {
    return av.canSelect(this._avMap);
  };
  Window_FacilityTree.prototype.drawItem = function (index) {
    var rect = this.itemRect(index);
    var key = this.createKey(
      index % this.maxCols(),
      Math.floor(index / this.maxCols())
    );
    var f = this._avMap[key];
    if (!f) {
      return;
    }
    if (!f.isVisible()) {
      return;
    }
    rect.y -= 2;
    this.drawAvBg(f, rect);
    this.drawFacilityName(f, rect);
    this.drawLock(f, rect);
    this.drawTaikenbanNg(f, rect);
    this.drawGold(f, rect);
    this.drawAvLine(f, rect);
    this.drawConstruction(f, rect);
    this.drawTutoArrow(f, rect);
  };
  Window_FacilityTree.prototype.drawTutoArrow = function (f, rect) {
    if (!this.isDrawTutoArrow(f)) {
      return;
    }
    var baseTexture2 = Nore.getSystemBaseTexture("0213_sys");
    var texture = new PIXI.Texture(baseTexture2);
    var sprite = new PIXI.Sprite(texture);
    sprite.x = rect.x + 147;
    sprite.y = rect.y + 50;
    sprite.rotation = (90 / 180) * Math.PI;
    this._tutoArrow = sprite;
    this._windowContentsSprite.addChild(sprite);
  };
  Window_FacilityTree.prototype.isDrawTutoArrow = function (f) {
    if (f.itemId() == 31) {
      if ($gameTutorial.nextTarget() == TextManager.target_1_3) {
        if (f.isConstruction()) {
          return false;
        }
        return true;
      }
    }
    if (f.itemId() == 46) {
      if ($gameTutorial.nextTarget() == TextManager.target_2_2) {
        if (f.isConstruction()) {
          return false;
        }
        return true;
      }
    }
    if (f.itemId() == 48) {
      if ($gameTutorial.nextTarget() == TextManager.target_0_2) {
        if (f.isConstruction()) {
          return false;
        }
        return true;
      }
    }
    if (f.itemId() == 50) {
      if ($gameTutorial.nextTarget() == TextManager.target_4_2) {
        if (f.isConstruction()) {
          return false;
        }
        return true;
      }
    }
    if (f.itemId() == 53) {
      if ($gameTutorial.nextTarget() == TextManager.target_5_2) {
        if (f.isConstruction()) {
          return false;
        }
        return true;
      }
    }
    return false;
  };
  Window_FacilityTree.prototype.drawTaikenbanNg = function (f, rect) {
    if (!f.isTaikenbanNg()) {
      return;
    }
    this.contents.fontSize = 11;
    this.drawText(TextManager.taikenbanNg, rect.x - 5, rect.y - 24, 100);
  };
  Window_FacilityTree.prototype.drawLock = function (f, rect) {
    if (!f.isLocked(this._avMap)) {
      return;
    }
    this.drawIcon(Icon.lock, rect.x - 5, rect.y - 20);
  };
  Window_FacilityTree.prototype.drawGold = function (f, rect) {
    if (f.isFinished()) {
      return;
    }
    this.contents.fontSize = 12;
    var yy = rect.y + 17;
    this.drawIcon(Icon.gold, rect.x + 106, yy + 1);
    if (f.price() > $gameParty.gold()) {
      if (f.canSelect(this._avMap)) {
        this.contents.textColor = ColorManager.deathColor();
      } else {
        this.contents.textColor = ColorManager.normalColor();
      }
    } else {
      this.contents.textColor = ColorManager.normalColor();
    }
    this.drawText(f.price(), rect.x + 136, yy, 84);
    this.contents.textColor = ColorManager.normalColor();
  };
  Window_FacilityTree.prototype.drawFacilityName = function (facility, rect) {
    var left = rect.x;
    this.contents.textColor = ColorManager.normalColor();
    if (facility.canSelect(this._avMap)) {
      this.changePaintOpacity(true);
      if (facility.isFinished()) {
        //this.contents.textColor = '#ffffBB'
        //this.contents.textColor = ColorManager.crisisColor();
      }
    } else {
      this.changePaintOpacity(false);
    }
    this.drawIcon(facility.iconIndex(), left + 5, rect.y + 7);
    this.contents.fontSize = 16;
    if (facility.isFinished()) {
      this.drawText(facility.name(), left + 42, rect.y + 4, rect.width - 72);
    } else {
      this.drawText(facility.name(), left + 42, rect.y - 4, rect.width - 72);
    }
  };
  Window_FacilityTree.prototype.drawConstruction = function (f, rect) {
    var e = f.timeGaugeEvent();
    if (!e) {
      return;
    }
    var left = rect.x;
    var miniSprite = new Sprite_MiniTimeGaugeEvent(
      e,
      5,
      true,
      TextManager.facilityConstrunction
    );
    miniSprite.x = left;
    miniSprite.y = rect.y;
    this._windowContentsSprite.addChild(miniSprite);
    this._timeGaugeEventSpriteList.push(miniSprite);
  };
  Window_FacilityTree.prototype.drawAvLine = function (av, rect) {
    switch (av.direction) {
      case AvItemDirection.left:
        this.drawLineLeft(rect);
        break;
      case AvItemDirection.top:
        this.drawLineTop(rect);
        break;
      case AvItemDirection.bottom:
        this.drawLineBottom(rect);
        break;
      case AvItemDirection.right:
        this.drawLineRight(rect);
        break;
    }
  };
  Window_FacilityTree.prototype.drawLineLeft = function (rect) {
    this.contents.fillRect(rect.x - 38, rect.y + 15, 38, 8, "#bbbbbb");
  };
  Window_FacilityTree.prototype.drawLineRight = function (rect) {
    this.contents.fillRect(rect.x + 130, rect.y + 15, 38, 8, "#bbbbbb");
  };
  Window_FacilityTree.prototype.drawLineTop = function (rect) {
    var s = this.getSprite(0, 48 * 8, 10, 40);
    s.x = rect.x + 85;
    s.y = rect.y - 27;
    this._windowContentsBackSprite2.addChild(s);
    //this.contents.fillRect(rect.x + 60, rect.y - 27, 8, 28, '#bbbbbb');
  };
  Window_FacilityTree.prototype.drawLineBottom = function (rect) {
    var s = this.getSprite(0, 48 * 8, 10, 40);
    s.x = rect.x + 85;
    s.y = rect.y + 41;
    this._windowContentsBackSprite2.addChild(s);
    //this.contents.fillRect(rect.x + 60, rect.y + 42, 8, 28, '#bbbbbb');
  };
  Window_FacilityTree.prototype.selectedItem = function () {
    var index = this.index();
    var key = this.createKey(
      index % this.maxCols(),
      Math.floor(index / this.maxCols())
    );
    var av = this._avMap[key];
    return av;
  };
  Window_FacilityTree.prototype.selectedFacility = function () {
    return this.selectedItem();
  };
  Window_FacilityTree.prototype.commandX = function () {
    var rect = this.itemRect(this.index());
    var x = rect.x + this.x + 140;
    if (x > 1000) {
      return 1000;
    }
    return x;
  };
  Window_FacilityTree.prototype.commandY = function () {
    var rect = this.itemRect(this.index());
    var y = rect.y + this.y + 0;
    if (y > 700 + y) {
      return 700;
    }
    return y;
  };
  return Window_FacilityTree;
})(Window_Selectable);
var FacilityItem = /** @class */ (function () {
  function FacilityItem(itemId, x, y, direction) {
    if (direction === void 0) {
      direction = null;
    }
    this._itemId = itemId;
    this.x = x;
    this.y = y;
    this.direction = direction;
  }
  FacilityItem.prototype.itemId = function () {
    return this._itemId;
  };
  FacilityItem.prototype.canSelect = function (map) {
    if (this.isConstruction()) {
      return false;
    }
    if (!this.isStageConditionOk()) {
      return false;
    }
    if (this.isInitial()) {
      return true;
    }
    var before = this.searchBeforeAv(map);
    if (!before) {
      return true;
    }
    return before.isFinished();
  };
  FacilityItem.prototype.isStageConditionOk = function () {
    var stage = parseInt(this.item().meta["stage"]);
    if (stage > 1) {
      return stage <= $slg.stage();
    }
    return true;
  };
  FacilityItem.prototype.isLocked = function (map) {
    if (this.isConstruction()) {
      return false;
    }
    if (this.isFinished()) {
      return false;
    }
    if (this.isTaikenbanNg()) {
      return false;
    }
    return !this.canSelect(map);
  };
  FacilityItem.prototype.isTaikenbanNg = function () {
    if (Nore.isTaikenban()) {
      if (this.item().meta["taikenbanNg"]) {
        return true;
      }
    }
    return false;
  };
  FacilityItem.prototype.isConstruction = function () {
    return this.timeGaugeEvent() != null;
  };
  FacilityItem.prototype.timeGaugeEvent = function () {
    for (var _i = 0, _a = $slg.timeGaugeEventList(); _i < _a.length; _i++) {
      var e = _a[_i];
      if (e.type() == TimeGaugeEventType.facility) {
        var event_1 = e;
        if (event_1.facilityId() == this.itemId()) {
          return event_1;
        }
      }
    }
    return null;
  };
  FacilityItem.prototype.isInitial = function () {
    return this.item().meta["initial"];
  };
  FacilityItem.prototype.searchBeforeAv = function (map) {
    var x = this.x;
    var y = this.y;
    switch (this.direction) {
      case AvItemDirection.top:
        y--;
        break;
      case AvItemDirection.bottom:
        y++;
        break;
      case AvItemDirection.left:
        x--;
        break;
      case AvItemDirection.right:
        x++;
        break;
    }
    for (var key in map) {
      var av = map[key];
      if (av.x == x && av.y == y) {
        return av;
      }
    }
    return null;
  };
  FacilityItem.prototype.isFinished = function () {
    return $slg.facilityInfo().hasFacility(this.itemId());
  };
  FacilityItem.prototype.isStageVisible = function () {
    var stage = parseInt(this.item().meta["stage"]);
    if (stage > 1) {
      return $slg.stage() >= stage;
    } else {
      return true;
    }
  };
  FacilityItem.prototype.item = function () {
    return $dataItems[this._itemId];
  };
  FacilityItem.prototype.iconIndex = function () {
    var item = this.item();
    if (!item) {
      return 0;
    }
    return item.iconIndex;
  };
  FacilityItem.prototype.name = function () {
    var item = this.item();
    if (!item) {
      return "";
    }
    switch (ConfigManager.language) {
      case "en":
        if (item.meta["nameEn"]) {
          return item.meta["nameEn"];
        }
        break;
      case "ch":
      case "jp":
        break;
    }
    return item.name;
  };
  FacilityItem.prototype.level = function () {
    return parseInt(this.item().meta["lv"]);
  };
  FacilityItem.prototype.price = function () {
    return this.item().price;
  };
  FacilityItem.prototype.facility = function () {
    return $slg.facilityInfo().facilityAt(this.itemId());
  };
  FacilityItem.prototype.isVisible = function () {
    if (!this.isVisibleStage()) {
      return false;
    }
    if (!this.isVisibleSw()) {
      return false;
    }
    return true;
  };
  FacilityItem.prototype.isVisibleStage = function () {
    var stage = parseInt(this.item().meta["stage"]);
    if (!isNaN(stage)) {
      if ($slg.stage() < stage) {
        return false;
      }
    }
    return true;
  };
  FacilityItem.prototype.isVisibleSw = function () {
    var sw = parseInt(this.item().meta["sw"]);
    if (!isNaN(sw)) {
      if (!$gameSwitches.value(sw)) {
        return false;
      }
    }
    return true;
  };
  return FacilityItem;
})();
var FACILITY_LIST = [
  new FacilityItem(31, 0, 0), // 工場 LV1
  new FacilityItem(32, 0, 1, AvItemDirection.top), // 工場 LV2
  new FacilityItem(33, 0, 2, AvItemDirection.top), // 工場 LV3
  //new FacilityItem(34, 0, 3, AvItemDirection.top), // 工場 LV4
  //new FacilityItem(38, 0, 4), // 武器 Lv1
  //new FacilityItem(39, 0, 5,  AvItemDirection.top), // 武器 Lv2
  //new FacilityItem(40, 0, 6,  AvItemDirection.top), // 武器 Lv3
  new FacilityItem(75, 0, 3), // ライブ
  new FacilityItem(76, 0, 4, AvItemDirection.top), // ライブ Lv2
  new FacilityItem(28, 2, 0), // 訓練 Lv1
  new FacilityItem(29, 2, 1, AvItemDirection.top), // 訓練 Lv2
  new FacilityItem(30, 2, 2, AvItemDirection.top), // 訓練 Lv3
  new FacilityItem(26, 2, 3, AvItemDirection.top), // 訓練 Lv4
  new FacilityItem(27, 2, 4, AvItemDirection.top), // 訓練 Lv5
  new FacilityItem(24, 2, 5), // 促進
  new FacilityItem(71, 1, 0), // 研究所
  new FacilityItem(72, 1, 1, AvItemDirection.top), // 研究所 Lv2
  new FacilityItem(73, 1, 2, AvItemDirection.top), // 研究所 Lv3
  new FacilityItem(74, 1, 3, AvItemDirection.top), // 研究所 Lv4
  new FacilityItem(77, 1, 4, AvItemDirection.top), // 研究所 Lv5
  new FacilityItem(64, 1, 5), // レーダー
  new FacilityItem(79, 1, 6), // ニセ施設
  new FacilityItem(80, 1, 7), // ミサイル施設
  //new FacilityItem(37, 2, 0), // 兵舎
  new FacilityItem(43, 3, 0), // 炊き出し所
  new FacilityItem(44, 3, 1, AvItemDirection.top), // 炊き出し所
  new FacilityItem(45, 3, 2, AvItemDirection.top), // 炊き出し所
  new FacilityItem(46, 4, 0), // 同棲部屋
  //new FacilityItem(52, 4, 1, AvItemDirection.top), // 同棲部屋(センリ)
  new FacilityItem(48, 4, 1, AvItemDirection.top), // 同棲部屋(マリナ)
  new FacilityItem(50, 4, 2, AvItemDirection.top), // 同棲部屋(サキ)
  new FacilityItem(53, 4, 3, AvItemDirection.top), // 同棲部屋(ココナ)
  //new FacilityItem(47, 4, 1, AvItemDirection.top), // 同棲部屋(ノノカ)
  //new FacilityItem(49, 4, 3, AvItemDirection.top), // 同棲部屋(マリナ)
  //new FacilityItem(51, 4, 5, AvItemDirection.top), // 同棲部屋(サキ)
  //new FacilityItem(55, 0, 4), // 催眠研究所
  //new FacilityItem(61, 3, 3), // SM部屋
  new FacilityItem(59, 0, 5), // ピアススタジオ
  new FacilityItem(60, 0, 6), // アロマ LV1
  new FacilityItem(61, 0, 7, AvItemDirection.top), // アロマ LV2
  //new FacilityItem(58, 0, 6), // タトゥースタジオ
  new FacilityItem(68, 3, 3), // 分娩室
  new FacilityItem(69, 3, 4, AvItemDirection.top), // 分娩室LV2
  new FacilityItem(67, 3, 5), // 調理室
  new FacilityItem(65, 2, 6), // 遺伝子実験センター LV1
  new FacilityItem(66, 2, 7, AvItemDirection.top), // 遺伝子実験センター LV2
  new FacilityItem(57, 3, 6), // 妊娠促進所
  new FacilityItem(56, 3, 7), // 受精研究所
  new FacilityItem(23, 4, 4), // 加速器
  new FacilityItem(62, 4, 5), // 宣伝広告室
  new FacilityItem(83, 4, 6), // 同棲条件なくす
  new FacilityItem(82, 4, 7), // 肉体改造研究所
];


code:
var __extends =
  (this && this.__extends) ||
  (function () {
    var extendStatics = function (d, b) {
      extendStatics =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&
          function (d, b) {
            d.__proto__ = b;
          }) ||
        function (d, b) {
          for (var p in b)
            if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
        };
      return extendStatics(d, b);
    };
    return function (d, b) {
      if (typeof b !== "function" && b !== null)
        throw new TypeError(
          "Class extends value " + String(b) + " is not a constructor or null"
        );
      extendStatics(d, b);
      function __() {
        this.constructor = d;
      }
      d.prototype =
        b === null
          ? Object.create(b)
          : ((__.prototype = b.prototype), new __());
    };
  })();
/*:ja
 * @target MZ
 * @author ル
 *
 *
 * @command addRandomActor
 * @text ランダムな怪人を追加
 * @des ランダムな怪人を追加
 *
 * @command addGachaActor
 * @text ガチャチケで怪人を追加
 * @des ガチャチケで怪人を追加
 *

 */
var Nore;
(function (Nore) {
  var pluginName = "Nore_Formation";
  PluginManager.registerCommand(pluginName, "addRandomActor", function (args) {
    $slg.formation().addRandomMonster();
  });
  PluginManager.registerCommand(pluginName, "addGachaActor", function (args) {
    $slg.formation().addGachaMonster();
  });
})(Nore || (Nore = {}));
var MonsterRare;
(function (MonsterRare) {
  MonsterRare[(MonsterRare["none"] = -1)] = "none";
  MonsterRare[(MonsterRare["zako"] = 0)] = "zako";
  MonsterRare[(MonsterRare["common"] = 1)] = "common";
  MonsterRare[(MonsterRare["rare"] = 2)] = "rare";
  MonsterRare[(MonsterRare["sr"] = 3)] = "sr";
  MonsterRare[(MonsterRare["ssr"] = 4)] = "ssr";
})(MonsterRare || (MonsterRare = {}));
var BattleObject = /** @class */ (function () {
  function BattleObject() {
    this._x = 0;
    this._y = 0;
    this._pattern = 0;
    this._direction = 2;
    this._opacity = 255;
    this._animationCount = 0;
    this._transparent = false;
  }
  BattleObject.prototype.id = function () {
    return this._id;
  };
  BattleObject.prototype.actor = function () {
    var actor = $gameActors.actor(this._actorId);
    if (!actor) {
      console.error("actorが見つかりません:" + this._actorId);
    }
    return actor;
  };
  BattleObject.prototype.characterName = function () {
    return this.actor().characterName();
  };
  BattleObject.prototype.characterIndex = function () {
    return this.actor().characterIndex();
  };
  BattleObject.prototype.pattern = function () {
    return this._pattern < 3 ? this._pattern : 1;
  };
  BattleObject.prototype.updateAnimation = function () {
    this.updateAnimationCount();
    if (this._animationCount >= this.animationWait()) {
      this.updatePattern();
      this._animationCount = 0;
    }
  };
  BattleObject.prototype.animationWait = function () {
    return 9;
  };
  BattleObject.prototype.updateAnimationCount = function () {
    this._animationCount++;
  };
  BattleObject.prototype.updatePattern = function () {
    this._pattern = (this._pattern + 1) % this.maxPattern();
  };
  BattleObject.prototype.maxPattern = function () {
    return 4;
  };
  BattleObject.prototype.direction = function () {
    if (this._enemy) {
      return 2;
    } else {
      return 8;
    }
    return this._direction;
  };
  BattleObject.prototype.opacity = function () {
    return this._opacity;
  };
  BattleObject.prototype.blendMode = function () {
    return 0;
  };
  BattleObject.prototype.bushDepth = function () {
    return 0;
  };
  BattleObject.prototype.x = function () {
    return this._x;
  };
  BattleObject.prototype.y = function () {
    return this._y;
  };
  BattleObject.prototype.atk = function () {
    return this.actor().atk;
  };
  BattleObject.prototype.isTransparent = function () {
    return this._transparent;
  };
  BattleObject.prototype.tileId = function () {
    return 0;
  };
  return BattleObject;
})();
var BattleUnit = /** @class */ (function (_super) {
  __extends(BattleUnit, _super);
  function BattleUnit(id, battleActor) {
    var _this = _super.call(this) || this;
    _this._knockBackFrame = 0;
    _this._guardCount = 0;
    _this._id = id;
    _this._battleActor = battleActor;
    _this._actorId = battleActor.actorId();
    _this.setup();
    return _this;
  }
  BattleUnit.prototype.setup = function () {
    this._hp = this.mhp();
    this._x = 0;
    this._y = 520;
  };
  BattleUnit.prototype.mhp = function () {
    return this.battleActor().mhp();
  };
  BattleUnit.prototype.battleActor = function () {
    return this._battleActor;
  };
  BattleUnit.prototype.hp = function () {
    return this._hp;
  };
  BattleUnit.prototype.isDead = function () {
    return this._hp <= 0;
  };
  BattleUnit.prototype.hpRate = function () {
    return this.hp() / this.mhp();
  };
  return BattleUnit;
})(BattleObject);
var BattleUnitDir2 = /** @class */ (function (_super) {
  __extends(BattleUnitDir2, _super);
  function BattleUnitDir2(battleActor, disable) {
    var _this = _super.call(this, -1, battleActor) || this;
    _this._battleActor = battleActor;
    _this._disable = disable;
    return _this;
  }
  BattleUnitDir2.prototype.direction = function () {
    return 2;
  };
  BattleUnitDir2.prototype.opacity = function () {
    if (this._disable) {
      return 120;
    } else {
      return _super.prototype.opacity.call(this);
    }
  };
  BattleUnitDir2.prototype.characterName = function () {
    return this._battleActor.characterName();
  };
  BattleUnitDir2.prototype.characterIndex = function () {
    return this._battleActor.characterIndex();
  };
  BattleUnitDir2.prototype.pattern = function () {
    return 1;
  };
  return BattleUnitDir2;
})(BattleUnit);
var Sprite_SlotUnit = /** @class */ (function (_super) {
  __extends(Sprite_SlotUnit, _super);
  function Sprite_SlotUnit(battleUnit, rect) {
    var _this = _super.call(this, battleUnit) || this;
    _this._rect = rect;
    _this._battleUnit = battleUnit;
    _this._character = battleUnit;
    _this.update();
    _this._isReady = _this.bitmap.isReady();
    return _this;
  }
  Sprite_SlotUnit.prototype.battleUnit = function () {
    return this._battleUnit;
  };
  Sprite_SlotUnit.prototype.updatePosition = function () {
    this.x = this._rect.x + 25;
    this.y = this._rect.y;
    this.z = 1;
  };
  Sprite_SlotUnit.prototype.isImageChanged = function () {
    if (!this._isReady) {
      return true;
    }
    return _super.prototype.isImageChanged.call(this);
  };
  Sprite_SlotUnit.prototype.setCharacterBitmap = function () {
    _super.prototype.setCharacterBitmap.call(this);
    this._isReady = this.bitmap.isReady();
  };
  return Sprite_SlotUnit;
})(Sprite_Character);
var Slot;
(function (Slot) {
  Slot[(Slot["slot1"] = 1)] = "slot1";
  Slot[(Slot["slot2"] = 2)] = "slot2";
  Slot[(Slot["slot3"] = 3)] = "slot3";
  Slot[(Slot["slot4"] = 4)] = "slot4";
  Slot[(Slot["slot5"] = 5)] = "slot5";
})(Slot || (Slot = {}));
var Formation = /** @class */ (function () {
  function Formation() {
    this._allMembers = [];
    this._battleMembers = [];
    this._changed = false; // 並びやメンバーに変更があった場合
    this._filterChanged = false; //
    this._levelUp = false; //
    this._id = 0;
  }
  Formation.prototype.isComplete = function () {
    return this._allMembers.length == this.totalKaijinNum();
  };
  Formation.prototype.totalKaijinNum = function () {
    var n = 0;
    for (var k in KAIJIN_PARAMS) {
      n++;
    }
    return n;
  };
  Formation.prototype.hasZako = function () {
    for (var _i = 0, _a = this.battleMembers(); _i < _a.length; _i++) {
      var b = _a[_i];
      if (!b) {
        continue;
      }
      if (b.actor().isZako()) {
        return true;
      }
    }
    return false;
  };
  Formation.prototype.onLevelUp = function () {
    this._changed = true;
    this._filterChanged = true;
    this._levelUp = true;
  };
  Formation.prototype.isLevelUp = function () {
    return this._levelUp;
  };
  Formation.prototype.clearLevelUp = function () {
    this._levelUp = false;
  };
  Formation.prototype.nextId = function () {
    this._id++;
    return this._id;
  };
  Formation.prototype.isBattleMamber = function (actor) {
    for (var _i = 0, _a = this.battleMembers(); _i < _a.length; _i++) {
      var b = _a[_i];
      if (!b) {
        continue;
      }
      if (b.actorId() == actor.actorId()) {
        return true;
      }
    }
    return false;
  };
  Formation.prototype.kaijinExists = function () {
    for (var _i = 0, _a = this.battleMembers(); _i < _a.length; _i++) {
      var b = _a[_i];
      if (!b) {
        continue;
      }
      if (b.actor().isKaijin()) {
        return true;
      }
    }
    return false;
  };
  Formation.prototype.kaijinCount = function () {
    var n = 0;
    for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
      var b = _a[_i];
      if (!b) {
        continue;
      }
      if (b.actor().isKaijin()) {
        n++;
      }
    }
    return n;
  };
  Formation.prototype.isEmpty = function (slot) {
    if (this._battleMembers.length <= slot) {
      return false;
    }
    return this._battleMembers[slot] == 0;
  };
  Formation.prototype.saveBattle = function () {};
  Formation.prototype.restoreBattle = function () {};
  Formation.prototype.leader = function () {
    if (!this._leader) {
      this._leader = new BattleActor(this.nextId(), 10, 1);
    }
    return this._leader;
  };
  Formation.prototype.addMember = function (actorId, level) {
    var actor = new BattleActor(this.nextId(), actorId, level);
    this._allMembers.push(actor);
    return actor.id();
  };
  Formation.prototype.allMembers = function () {
    if (!$gameSwitches.value(325)) {
      return this._allMembers;
    }
    var members = [];
    for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
      var m = _a[_i];
      if (!m.isZako()) {
        members.push(m);
      }
    }
    return members;
  };
  Formation.prototype.battleMembers = function () {
    var result = [];
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        result.push(this.findBattleActor(n));
      } else {
        result.push(null);
      }
    }
    return result;
  };
  Formation.prototype.deadMembers = function () {
    var result = [];
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        var b = this.findBattleActor(n);
        if (b.isDead()) {
          result.push(b);
        }
      }
    }
    return result;
  };
  Formation.prototype.existBattleMembers = function () {
    var result = [];
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        result.push(this.findBattleActor(n));
      }
    }
    return result;
  };
  Formation.prototype.battleMemberIds = function () {
    return this._battleMembers.concat();
  };
  Formation.prototype.findBattleActor = function (id) {
    if (id == -1) {
      return;
    }
    for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
      var b = _a[_i];
      if (b.id() == id) {
        return b;
      }
    }
    console.error("IDが" + id + "のBattleActorが見つかりません");
    return null;
  };
  Formation.prototype.findBattleActorByActorId = function (id) {
    for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
      var b = _a[_i];
      if (b.actorId() == id) {
        return b;
      }
    }
    console.error("IDが" + id + "のBattleActorが見つかりません");
    return null;
  };
  Formation.prototype.maxBattleMembers = function () {
    return 5;
  };
  Formation.prototype.totalPower = function () {
    var n = 0;
    for (var _i = 0, _a = this.battleMembers(); _i < _a.length; _i++) {
      var m = _a[_i];
      if (m) {
        n += m.power();
      }
    }
    return n;
  };
  Formation.prototype.slotBy = function (id) {
    for (var i = 0; i < this._battleMembers.length; i++) {
      var m = this._battleMembers[i];
      if (m) {
        var actor = this.findBattleActor(m);
        if (actor && actor.id() == id) {
          return i;
        }
      }
    }
    return -1;
  };
  Formation.prototype.battleMemberAt = function (index) {
    var id = this._battleMembers[index];
    if (id >= 0) {
      return this.findBattleActor(id);
    }
    return null;
  };
  Formation.prototype.slotOf = function (actor) {
    for (var i = 0; i < this._battleMembers.length; i++) {
      var m = this._battleMembers[i];
      if (m) {
        if (actor.id() == m) {
          return i;
        }
      }
    }
    return -1;
  };
  Formation.prototype.setActor = function (slotId, actor) {
    var currentSlot = this.slotOf(actor);
    if (currentSlot >= 0) {
      this._battleMembers[currentSlot] = -1;
    }
    if (actor) {
      this._battleMembers[slotId] = actor.id();
    } else {
      this._battleMembers[slotId] = -1;
    }
    this._changed = true;
    this.calcPassiveSkill();
  };
  Formation.prototype.swap = function (slotId1, slotId2) {
    var temp1 = this._battleMembers[slotId1];
    var temp2 = this._battleMembers[slotId2];
    this._battleMembers[slotId1] = temp2;
    this._battleMembers[slotId2] = temp1;
    this._changed = true;
    this.calcPassiveSkill();
  };
  Formation.prototype.calcPassiveSkill = function () {
    this._passiveSkills = new PassiveSkills();
    var battleMembers = this.battleMembers();
    for (var i = 0; i < this.maxBattleMembers(); i++) {
      var battleActor = this.battleMemberAt(i);
      if (!battleActor) {
        continue;
      }
      var passiveSkills = battleActor.createPassiveSkillList(battleMembers);
      if (passiveSkills.length > 0) {
        for (
          var _i = 0, passiveSkills_1 = passiveSkills;
          _i < passiveSkills_1.length;
          _i++
        ) {
          var s = passiveSkills_1[_i];
          this._passiveSkills.push(s);
        }
      }
    }
    for (var _a = 0, _b = this.allMembers(); _a < _b.length; _a++) {
      var m = _b[_a];
      m.setPassiveSkills(this._passiveSkills);
    }
  };
  Formation.prototype.addRandomMonster = function () {
    var actorId = this.selectRandomMonster();
    this.joinMonster(actorId);
  };
  Formation.prototype.addGachaMonster = function () {
    var t = $gameParty.useGachaTicket();
    if (!t) {
      console.error("ガチャチケを持っていません");
      return;
    }
    if ($gameParty.gachaTicket() == 0) {
      $gameSwitches.setValue(33, false);
    }
    var actorId = t.actorId();
    this.joinMonster(actorId);
  };
  Formation.prototype.selectRandomMonster = function () {
    var actorId = this.roulette();
    if ($slg.facilityInfo().hasFacility(65)) {
      if (this.isExists(actorId)) {
        p("怪人かぶり1:" + actorId);
        actorId = this.roulette();
        if ($slg.facilityInfo().hasFacility(66)) {
          if (this.isExists(actorId)) {
            p("怪人かぶり2:" + actorId);
            actorId = this.roulette();
          }
          if (this.isExists(actorId)) {
            p("怪人かぶり3:" + actorId);
            actorId = this.roulette();
          }
        }
      }
    }
    return actorId;
  };
  Formation.prototype.joinMonster = function (actorId) {
    if (actorId < 0) {
      console.error("不正な怪人が追加されました");
      return;
    }
    var actor = $gameActors.actor(actorId);
    var battleActor = new BattleActor(-1, actorId, 1);
    $gameVariables.setValue(59, battleActor.name());
    if (this.isExists(actor.actorId())) {
      $gameSwitches.setValue(59, true);
      var battleActorId = this.levelUp(actor.actorId());
      $gameTemp.lastJoinBattleActorId = battleActorId;
      $gameTemp.lastJoinBattleActorNew = false;
      var g = this.goldByRare(battleActor.rare());
      $gameVariables.setValue(90, g);
      if (g > 0) {
        p("かぶりG:" + g);
        $gameParty.gainGold(g);
      }
    } else {
      $gameSwitches.setValue(59, false);
      var battleActorId = this.addMember(actor.actorId(), 1);
      $gameTemp.lastJoinBattleActorId = battleActorId;
      $gameTemp.lastJoinBattleActorNew = true;
    }
    var rare = this.findBattleActorByActorId(actor.actorId()).rare();
    var rareEffect = rare >= MonsterRare.sr;
    $gameSwitches.setValue(28, rareEffect);
    $gameSwitches.setValue(29, rare == MonsterRare.ssr);
  };
  Formation.prototype.goldByRare = function (rare) {
    switch (rare) {
      case MonsterRare.common:
        return 50;
      case MonsterRare.rare:
        return 100;
      case MonsterRare.sr:
        return 150;
      case MonsterRare.ssr:
        return 200;
    }
    return 0;
  };
  Formation.prototype.roulette = function () {
    var rare = new Gacha().decideRare();
    var candidates = this.monsterCandidates(rare);
    if (candidates.length == 0) {
      console.error("怪人を追加できません");
      return -1;
    }
    var random = Math.randomInt(candidates.length);
    var actorId = candidates[random];
    return actorId;
  };
  Formation.prototype.isExists = function (actorId) {
    for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
      var b = _a[_i];
      if (b.actorId() == actorId) {
        return true;
      }
    }
    return false;
  };
  Formation.prototype.monsterCandidates = function (r) {
    var result = [];
    var minLevel = 1;
    var maxLevel =
      1 + $slg.facilityInfo().findMaxFacilityLevel(FacilityType.monster);
    for (var i = 102; i < 150; i++) {
      if (!KAIJIN_PARAMS[i]) {
        continue;
      }
      var rare = KAIJIN_PARAMS[i][0];
      if (isNaN(rare)) {
        console.error("怪人のレベルが不正です:" + i);
        continue;
      }
      if (r == rare) {
        result.push(i);
      }
    }
    return result;
  };
  Formation.prototype.leftTarget = function () {
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        var b = this.findBattleActor(n);
        if (b.hp() > 0) {
          return b;
        }
      }
    }
    return null;
  };
  Formation.prototype.priorityTarget = function () {
    var targets = [];
    var battleCount = 0;
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        var b = this.findBattleActor(n);
        if (b.hp() > 0) {
          var value = this.priorityByBattlerCount(battleCount);
          value += this.provokeValue(b);
          for (var i = 0; i < value; i++) {
            targets.push(b);
          }
          battleCount++;
        }
      }
    }
    if (targets.length == 0) {
      return null;
    }
    var dice = Math.randomInt(targets.length);
    return targets[dice];
  };
  Formation.prototype.aliveTargets = function () {
    var targets = [];
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        var b = this.findBattleActor(n);
        if (b.hp() > 0) {
          targets.push(b);
        }
      }
    }
    return targets;
  };
  Formation.prototype.aliveTargetFrontNum = function (num) {
    var targets = this.aliveTargets();
    if (targets.length <= num) {
      return targets;
    }
    var result = [];
    for (var i = 0; i < num; i++) {
      result.push(targets[i]);
    }
    return result;
  };
  Formation.prototype.aliveTargetNum = function (num) {
    var targets = this.aliveTargets();
    if (targets.length <= num) {
      return targets;
    }
    var result = [];
    var list = this.aliveTargetCandidates();
    for (var i = 0; i < num; i++) {
      while (list.length > 0) {
        var b = list.pop();
        if (result.contains(b)) {
          continue;
        }
        result.push(b);
        break;
      }
    }
    return result;
  };
  Formation.prototype.aliveTargetCandidates = function () {
    var result = [];
    var battleCount = 0;
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        var b = this.findBattleActor(n);
        if (b.hp() > 0) {
          var value = this.priorityByBattlerCount(battleCount);
          value += this.provokeValue(b);
          for (var i = 0; i < value; i++) {
            result.push(b);
          }
          battleCount++;
        }
      }
    }
    result = Nore.shuffle(result);
    return result;
  };
  Formation.prototype.provokeValue = function (b) {
    return this._passiveSkills.provokeValue(b);
  };
  Formation.prototype.aliveTargetTop = function () {
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        var b = this.findBattleActor(n);
        if (b.hp() > 0) {
          return [b];
        }
      }
    }
    return [];
  };
  Formation.prototype.aliveTargetBottom = function () {
    for (var i = 0; i < this._battleMembers.length; i++) {
      var n = this._battleMembers[this._battleMembers.length - 1 - i];
      if (n) {
        var b = this.findBattleActor(n);
        if (b.hp() > 0) {
          return [b];
        }
      }
    }
    return [];
  };
  Formation.prototype.priorityByBattlerCount = function (battleCount) {
    switch (battleCount) {
      case 0:
        return 8;
      case 1:
        return 5;
      case 2:
        return 3;
      case 3:
        return 2;
      default:
        return 1;
    }
  };
  Formation.prototype.isAllDead = function () {
    for (var _i = 0, _a = this._battleMembers; _i < _a.length; _i++) {
      var n = _a[_i];
      if (n) {
        var b = this.findBattleActor(n);
        if (b.hp() > 0) {
          return false;
        }
      }
    }
    return true;
  };
  Formation.prototype.recoverAll = function () {
    for (var _i = 0, _a = this.existBattleMembers(); _i < _a.length; _i++) {
      var a = _a[_i];
      a.recoverAll();
    }
  };
  Formation.prototype.levelUp = function (actorId) {
    for (var _i = 0, _a = this._allMembers; _i < _a.length; _i++) {
      var b = _a[_i];
      if (b.actorId() == actorId) {
        b.levelUp();
        if (this.trainingInfo().trainingActorId() == actorId) {
          this.trainingInfo().clearTraining();
        }
        return b.id();
      }
    }
    return -1;
  };
  Formation.prototype.isChanged = function () {
    return this._changed;
  };
  Formation.prototype.clearChanged = function () {
    this._changed = false;
  };
  Formation.prototype.isRareEnabled = function (r) {
    if (this.isRareSelected(r)) {
      return true;
    }
    var onCount = 0;
    for (var f in this._rareFilter) {
      if (this._rareFilter[f]) {
        onCount++;
      }
    }
    return onCount == 0;
  };
  Formation.prototype.isRareSelected = function (r) {
    this._rareFilter = this._rareFilter || {};
    for (var f in this._rareFilter) {
      if (parseInt(f) == r) {
        if (this._rareFilter[f]) {
          return true;
        }
      }
    }
    return false;
  };
  Formation.prototype.clearRareFilter = function () {
    this._rareFilter = {};
    this._filterChanged = true;
  };
  Formation.prototype.clearElementFilter = function () {
    this._elementFilter = {};
    this._filterChanged = true;
  };
  Formation.prototype.putRareFilter = function (r) {
    this._rareFilter = this._rareFilter || {};
    this._rareFilter[r] = !this._rareFilter[r];
    this._filterChanged = true;
  };
  Formation.prototype.isElementEnabled = function (r) {
    if (this.isElementSelected(r)) {
      return true;
    }
    var onCount = 0;
    for (var f in this._elementFilter) {
      if (this._elementFilter[f]) {
        onCount++;
      }
    }
    return onCount == 0;
  };
  Formation.prototype.isElementSelected = function (r) {
    this._elementFilter = this._elementFilter || {};
    for (var f in this._elementFilter) {
      if (parseInt(f) == r) {
        if (this._elementFilter[f]) {
          return true;
        }
      }
    }
    return false;
  };
  Formation.prototype.putElementFilter = function (e) {
    this._elementFilter = this._elementFilter || {};
    this._elementFilter[e] = !this._elementFilter[e];
    this._filterChanged = true;
  };
  Formation.prototype.filterChanged = function () {
    return this._filterChanged;
  };
  Formation.prototype.clearFilterChanged = function () {
    this._filterChanged = false;
  };
  Formation.prototype.sortValue = function () {
    return MonsterSort.rare; //this._sortValue || MonsterSort.rare;
  };
  Formation.prototype.changeSort = function () {
    this._sortValue = this._sortValue || MonsterSort.newArrival;
    this._sortValue++;
    if (this._sortValue > MonsterSort.element) {
      this._sortValue = MonsterSort.newArrival;
    }
    this._filterChanged = true;
  };
  Formation.prototype.trainingInfo = function () {
    this._trainingInfo = this._trainingInfo || new TrainingInfo();
    return this._trainingInfo;
  };
  return Formation;
})();
var MonsterElement;
(function (MonsterElement) {
  MonsterElement[(MonsterElement["none"] = -1)] = "none";
  MonsterElement[(MonsterElement["flame"] = 0)] = "flame";
  MonsterElement[(MonsterElement["water"] = 1)] = "water";
  MonsterElement[(MonsterElement["wood"] = 2)] = "wood";
})(MonsterElement || (MonsterElement = {}));
var MonsterElementColor;
(function (MonsterElementColor) {
  MonsterElementColor[(MonsterElementColor["flame"] = 11141120)] = "flame";
  MonsterElementColor[(MonsterElementColor["water"] = 2237149)] = "water";
  MonsterElementColor[(MonsterElementColor["wood"] = 43520)] = "wood";
})(MonsterElementColor || (MonsterElementColor = {}));
var MonsterElementStringColor;
(function (MonsterElementStringColor) {
  MonsterElementStringColor["flame"] = "#aa0000";
  MonsterElementStringColor["water"] = "#0000aa";
  MonsterElementStringColor["wood"] = "#00aa00";
})(MonsterElementStringColor || (MonsterElementStringColor = {}));