code:
//=============================================================================
// Foreground.js (Ver1.0.1)
//=============================================================================
// [History]
// 2015.Nov. 7  1.0.0 First Release
// 2018.Sep.19  1.0.1 Fix bug when 'event command -> test' becomes error

/*:
 * @plugindesc display foreground tiling sprite(Ver1.0.1)
 * @author Sasuke KANNAZUKI (thanks to Yoji Ojima)
 *
 * @noteParam fgName
 * @noteRequire 1
 * @noteDir img/parallaxes/
 * @noteType file
 * @noteData maps
 *
 * @help  This plugin does not provide plugin commands.
 *
 * 'foreground' is like a parallax that displays over the map.
 * put bitmap file at img/parallaxes.
 *
 * Map Note:
 *  write down following 5 settings at map's note.
 *  <fgName:name>     name is the string, file name of tiling sprite.
 *    if the name starts '!', it is regarded as "foreground zero".
 *    the filename is searched from img/parallaxes.
 *  <fgLoopX:number>  number is the flag of loop x. 0:no 1:yes
 *    if this is not written on the note, it'll be 0(=no).
 *  <fgLoopY:number>  number is the flag of loop y. 0:no 1:yes
 *    if this is not written on the note, it'll be 0(=no).
 *  <fgSx:number>     number is x scroll speed.
 *    when it doesn't loop x, this is ignored.
 *    if this is not written on the note, it'll be 0.
 *  <fgSy:number>     number is y scroll speed.
 *    when it doesn't loop y, this is ignored.
 *    if this is not written on the note, it'll be 0.
 *
 * Ex.
 * <fgName:sample1><fgLoopX:1><fgLoopY:1>
 *
 * <fgName:!sample1>
 *
 * [License]
 * this plugin is released under MIT license.
 * http://opensource.org/licenses/mit-license.php
 */

/*:ja
 * @plugindesc マップに合わせてスクロールする近景の設定(Ver1.0.1)
 * @author 神無月サスケ (thanks to Yoji Ojima)
 *
 * @noteParam fgName
 * @noteRequire 1
 * @noteDir img/parallaxes/
 * @noteType file
 * @noteData maps
 *
 * @help このプラグインにプラグインコマンドはありません。
 * 近景(foreground)は、マップの上に表示される遠景のようなものです。
 * 使用する画像ファイルは、img/parallaxes に置いてください。
 *
 * マップのメモ:
 *  以下の5項目を書いてください(設定項目は、遠景と似ています)。
 *  <fgName:ファイル名> 前景として使うファイル名です（拡張子なし）
 *    名前が '!'で始まる場合、遠景同様視差ゼロとなります。
 *    ファイルは img/parallaxes に置いてください
 *  <fgLoopX:数字> X座標にループするかどうか  (0:no 1:yes)。
 *    省略時は0(=no)になります。
 *  <fgLoopY:number> Y座標にループするかどうか  (0:no 1:yes)。
 *    省略時は0(=no)になります。
 *  <fgSx:数字>    X座標のスクロール速度です
 *    X座標にループしない場合は無視されます。
 *    省略時は0になります。
 *  <fgSy:数字>    Y座標のスクロール速度です
 *    Y座標にループしない場合は無視されます。
 *    省略時は0になります。
 *
 * 例：
 * <fgName:sample1><fgLoopX:1><fgLoopY:1>
 * sample1.png が前景になり、斜め上にループします。
 *
 * <fgName:!sample1>
 * 視差ゼロで!sample1.png が表示されます。
 *
 * ■ライセンス表記
 * このプラグインは MIT ライセンスで配布されます。
 * ご自由にお使いください。
 * http://opensource.org/licenses/mit-license.php
 */

(function () {
  //
  // check zero foreground or not.
  //
  ImageManager.isZeroForeground = function (filename) {
    return filename.charAt(0) === "!";
  };

  //
  // map initialization
  //
  var _Game_Map_initialize = Game_Map.prototype.initialize;
  Game_Map.prototype.initialize = function () {
    _Game_Map_initialize.call(this);
    this.initForeground();
  };

  Game_Map.prototype.initForeground = function () {
    this._foregroundDefined = true;
    this._foregroundName = "";
    this._foregroundZero = false;
    this._foregroundLoopX = false;
    this._foregroundLoopY = false;
    this._foregroundSx = 0;
    this._foregroundSy = 0;
    this._foregroundX = 0;
    this._foregroundY = 0;
  };

  //
  // if foreground is undefined, initialize it.
  //
  Game_Map.prototype.guardForeground = function () {
    if (!this._foregroundDefined) {
      this.initForeground();
    }
  };

  //
  // an accessor
  //
  Game_Map.prototype.foregroundName = function () {
    this.guardForeground();
    return this._foregroundName;
  };

  //
  // set foreground by reading map's note.
  //
  var _Game_Map_setup = Game_Map.prototype.setup;
  Game_Map.prototype.setup = function (mapId) {
    _Game_Map_setup.call(this, mapId);
    this.setupForeground();
  };

  Game_Map.prototype.setupForeground = function () {
    if ($dataMap.meta) {
      this._foregroundName = $dataMap.meta.fgName || "";
      this._foregroundZero = ImageManager.isZeroForeground(
        this._foregroundName
      );
      this._foregroundLoopX = !!$dataMap.meta.fgLoopX;
      this._foregroundLoopY = !!$dataMap.meta.fgLoopY;
      this._foregroundSx = Number($dataMap.meta.fgSx) || 0;
      this._foregroundSy = Number($dataMap.meta.fgSy) || 0;
    }
    this._foregroundX = 0;
    this._foregroundY = 0;
  };

  //
  // to display foreground
  //
  var _Game_Map_setDisplayPos = Game_Map.prototype.setDisplayPos;
  Game_Map.prototype.setDisplayPos = function (x, y) {
    _Game_Map_setDisplayPos.call(this, x, y);
    this.guardForeground();
    if (this.isLoopHorizontal()) {
      this._foregroundX = x;
    } else {
      this._foregroundX = this._displayX;
    }
    if (this.isLoopVertical()) {
      this._foregroundY = y;
    } else {
      this._foregroundY = this._displayY;
    }
  };

  Game_Map.prototype.foregroundOx = function () {
    this.guardForeground();
    if (this._foregroundZero) {
      return this._foregroundX * this.tileWidth();
    } else if (this._foregroundLoopX) {
      return (this._foregroundX * this.tileWidth()) / 2;
    } else {
      return 0;
    }
  };

  Game_Map.prototype.foregroundOy = function () {
    this.guardForeground();
    if (this._foregroundZero) {
      return this._foregroundY * this.tileHeight();
    } else if (this._foregroundLoopY) {
      return (this._foregroundY * this.tileHeight()) / 2;
    } else {
      return 0;
    }
  };

  //
  // to scroll foreground
  //
  var _Game_Map_scrollDown = Game_Map.prototype.scrollDown;
  Game_Map.prototype.scrollDown = function (distance) {
    var lastY = this._displayY;
    _Game_Map_scrollDown.call(this, distance);
    this.guardForeground();
    if (this.isLoopVertical()) {
      if (this._foregroundLoopY) {
        this._foregroundY += distance;
      }
    } else if (this.height() >= this.screenTileY()) {
      var displayY = Math.min(
        lastY + distance,
        this.height() - this.screenTileY()
      );
      this._foregroundY += displayY - lastY;
    }
  };

  var _Game_Map_scrollLeft = Game_Map.prototype.scrollLeft;
  Game_Map.prototype.scrollLeft = function (distance) {
    var lastX = this._displayX;
    _Game_Map_scrollLeft.call(this, distance);
    this.guardForeground();
    if (this.isLoopHorizontal()) {
      if (this._foregroundLoopX) {
        this._foregroundX -= distance;
      }
    } else if (this.width() >= this.screenTileX()) {
      var displayX = Math.max(lastX - distance, 0);
      this._foregroundX += displayX - lastX;
    }
  };

  var _Game_Map_scrollRight = Game_Map.prototype.scrollRight;
  Game_Map.prototype.scrollRight = function (distance) {
    var lastX = this._displayX;
    _Game_Map_scrollRight.call(this, distance);
    this.guardForeground();
    if (this.isLoopHorizontal()) {
      if (this._foregroundLoopX) {
        this._foregroundX += distance;
      }
    } else if (this.width() >= this.screenTileX()) {
      var displayX = Math.min(
        lastX + distance,
        this.width() - this.screenTileX()
      );
      this._foregroundX += displayX - lastX;
    }
  };

  var _Game_Map_scrollUp = Game_Map.prototype.scrollUp;
  Game_Map.prototype.scrollUp = function (distance) {
    var lastY = this._displayY;
    _Game_Map_scrollUp.call(this, distance);
    this.guardForeground();
    if (this.isLoopVertical()) {
      if (this._foregroundLoopY) {
        this._foregroundY -= distance;
      }
    } else if (this.height() >= this.screenTileY()) {
      var displayY = Math.max(lastY - distance, 0);
      this._foregroundY += displayY - lastY;
    }
  };

  //
  // update foreground
  //
  var _Game_Map_update = Game_Map.prototype.update;
  Game_Map.prototype.update = function (sceneActive) {
    _Game_Map_update.call(this, sceneActive);
    this.updateForeground();
  };

  Game_Map.prototype.updateForeground = function () {
    this.guardForeground();
    if (this._foregroundLoopX) {
      this._foregroundX += this._foregroundSx / this.tileWidth() / 2;
    }
    if (this._foregroundLoopY) {
      this._foregroundY += this._foregroundSy / this.tileHeight() / 2;
    }
  };

  //
  // sprites
  //
  var _Spriteset_Map_createLowerLayer =
    Spriteset_Map.prototype.createLowerLayer;
  Spriteset_Map.prototype.createLowerLayer = function () {
    _Spriteset_Map_createLowerLayer.call(this);
    this.createForeground();
  };

  var _Spriteset_Map_update = Spriteset_Map.prototype.update;
  Spriteset_Map.prototype.update = function () {
    _Spriteset_Map_update.call(this);
    this.updateForeground();
  };

  Spriteset_Map.prototype.createForeground = function () {
    this._foreground = new TilingSprite();
    this._foreground.move(0, 0, Graphics.width, Graphics.height);
    // in order to display under the weather sprites:
    this._baseSprite.removeChild(this._weather);
    this._baseSprite.addChild(this._foreground);
    this._baseSprite.addChild(this._weather);
  };

  Spriteset_Map.prototype.updateForeground = function () {
    if (this._foregroundName !== $gameMap.foregroundName()) {
      this._foregroundName = $gameMap.foregroundName();
      this._foreground.bitmap = ImageManager.loadParallax(this._foregroundName);
    }
    if (this._foreground.bitmap) {
      this._foreground.origin.x = $gameMap.foregroundOx();
      this._foreground.origin.y = $gameMap.foregroundOy();
    }
  };
})();


code:
//=============================================================================
// Gacha.js
//
// (c)2016 KADOKAWA CORPORATION./YOJI OJIMA
//=============================================================================

/*:
 * @plugindesc Get the item at random
 * @author Takeya Kimura
 *
 * @param Help Message Text
 * @desc The help message for gacha window. "Required Amount" is replaced with the Required Amount.
 * @default 1回Required Amount\Gでガチャを引きます
 *
 * @param Button Text
 * @desc The button text for gacha commands.
 * @default ガチャを引く
 *
 * @param Get Message Text
 * @desc The message of After receiving. "Item Name" is replaced with the received item name.
 * @default GET Item Name
 *
 * @param Show Item Description
 * @desc The switch of item description display
 * @default 0
 *
 * @param Effect
 * @desc The animation number for get effect.
 * @default 119
 * @require 1
 * @type animation
 *
 * @param Rank1 Effect
 * @desc The animation number for rank 1 effect. If you specify -1, does not display the animation.
 * @default -1
 * @require 1
 * @type animation
 *
 * @param Rank2 Effect
 * @desc The animation number for rank 2 effect. If you specify -1, does not display the animation.
 * @default -1
 * @require 1
 * @type animation
 *
 * @param Rank3 Effect
 * @desc The animation number for rank 3 effect. If you specify -1, does not display the animation.
 * @default -1
 * @require 1
 * @type animation
 *
 * @param Rank4 Effect
 * @desc The animation number for rank 4 effect. If you specify -1, does not display the animation.
 * @default -1
 * @require 1
 * @type animation
 *
 * @param Rank5 Effect
 * @desc The animation number for rank 5 effect. If you specify -1, does not display the animation.
 * @default -1
 * @require 1
 * @type animation
 *
 * @param ME
 * @desc The ME name for get music effect.
 * @default Organ
 * @require 1
 * @dir audio/me/
 * @type file
 *
 * @param  Required Amount
 * @desc The Gold for gacha.
 * @default 100
 *
 * @noteParam gachaImage
 * @noteRequire 1
 * @noteDir img/gacha/
 * @noteType file
 * @noteData items
 *
 * @help
 *
 * Plugin Command:
 *   Gacha open                 # Open the Gacha screen
 *   Gacha add item 1           # Add item #1 to the Gacha
 *   Gacha remove item 1        # Remove item #1 from the Gacha
 *   Gacha clear                # Clear the Gacha
 *
 *
 * Item Note:
 *   <gachaImage:image>        # Gacha image file name. Please image put in "img/gacha/" folder.
 *   <gachaNumLot:10>          # The number of the lottery.
 *   <gachaRank:5>             # The rank of the item(1-5).
 */

/*:ja
 * @plugindesc ランダムにアイテムを取得します。
 * @author Takeya Kimura
 *
 * @param Help Message Text
 * @desc ガチャ画面のヘルプメッセージです。「Required Amount」は消費Gと置換されます。
 * @default 1回Required Amount\Gでガチャを引きます
 *
 * @param Button Text
 * @desc ガチャボタンに表示するテキストです。
 * @default ガチャを引く
 *
 * @param Get Message Text
 * @desc ガチャを引いた後のメッセージです。「Item Name」は取得アイテム名と置換されます。
 * @default GET Item Name
 *
 * @param Show Item Description
 * @desc 1でアイテム取得時に説明を表示します。[0: 説明非表示 1: 説明表示]
 * @default 0
 *
 * @param Effect
 * @desc アイテム取得時のアニメーションIDを指定します。
 * @default 119
 * @require 1
 * @type animation
 *
 * @param Rank1 Effect
 * @desc ランク1の時のアニメーションIDを指定します。-1を指定するとアニメーションを表示しません。
 * @default -1
 * @require 1
 * @type animation
 *
 * @param Rank2 Effect
 * @desc ランク2の時のアニメーションIDを指定します。-1を指定するとアニメーションを表示しません。
 * @default -1
 * @require 1
 * @type animation
 *
 * @param Rank3 Effect
 * @desc ランク3の時のアニメーションIDを指定します。-1を指定するとアニメーションを表示しません。
 * @default -1
 * @require 1
 * @type animation
 *
 * @param Rank4 Effect
 * @desc ランク4の時のアニメーションIDを指定します。-1を指定するとアニメーションを表示しません。
 * @default -1
 * @require 1
 * @type animation
 *
 * @param Rank5 Effect
 * @desc ランク5の時のアニメーションIDを指定します。-1を指定するとアニメーションを表示しません。
 * @default -1
 * @require 1
 * @type animation
 *
 * @param ME
 * @desc アイテム取得時のMEを指定します。
 * @default Organ
 * @require 1
 * @dir audio/me/
 * @type file
 *
 * @param  Required Amount
 * @desc ガチャを引くのに必要なGです。
 * @default 100
 *
 * @noteParam gachaImage
 * @noteRequire 1
 * @noteDir img/gacha/
 * @noteType file
 * @noteData items
 *
 * @help
 *
 * Plugin Command:
 *   Gacha open                 # ガチャ画面を開きます。
 *   Gacha add item 1           # アイテム番号1をガチャ対象に追加します。
 *   Gacha remove item 1        # アイテム番号1をガチャ対象から外します。
 *   Gacha clear                # 全てのガチャ対象をクリアします。
 *
 *
 * Item Note:
 *   <gachaImage:image>        # ガチャアイテムの画像を指定します。画像はimg/gacha/フォルダ内に入れてください。
 *   <gachaNumLot:10>          # ガチャアイテムのくじ数を指定します。
 *   <gachaRank:5>             # ガチャアイテムのランクを1から5の間で指定します。
 */

(function () {
  var parameters = PluginManager.parameters("Gacha");
  var message = String(
    parameters["Help Message Text"] || "1回Required Amount\\Gでガチャを引きます"
  );
  var buttonText = String(parameters["Button Text"] || "ガチャを引く");
  var getText = String(parameters["Get Message Text"] || "GET Item Name");
  var itemDescEnable = !!Number(parameters["Show Item Description"] || 0);
  var effect = Number(parameters["Effect"] || "119");
  var rankEffect = [];
  rankEffect.push(Number(parameters["Rank1 Effect"] || "-1"));
  rankEffect.push(Number(parameters["Rank2 Effect"] || "-1"));
  rankEffect.push(Number(parameters["Rank3 Effect"] || "-1"));
  rankEffect.push(Number(parameters["Rank4 Effect"] || "-1"));
  rankEffect.push(Number(parameters["Rank5 Effect"] || "-1"));
  var me = String(parameters["ME"] || "Organ");
  var amount = Number(parameters["Required Amount"] || "100");
  var reg = /Required Amount/gi;
  message = message.replace(reg, String(amount));

  var _Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function (command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if (command === "Gacha") {
      switch (args[0]) {
        case "open":
          SceneManager.push(Scene_Gacha);
          break;

        case "add":
          $gameSystem.addToGacha(args[1], Number(args[2]));
          break;

        case "remove":
          $gameSystem.removeFromGacha(args[1], Number(args[2]));
          break;

        case "clear":
          $gameSystem.clearGacha();
          break;
      }
    }
  };

  Game_System.prototype.addToGacha = function (type, dataId) {
    if (!this._GachaFlags) {
      this.clearGacha();
    }
    var typeIndex = this.gachaTypeToIndex(type);
    if (typeIndex >= 0) {
      this._GachaFlags[typeIndex][dataId] = true;
    }
  };

  Game_System.prototype.removeFromGacha = function (type, dataId) {
    if (this._GachaFlags) {
      var typeIndex = this.gachaTypeToIndex(type);
      if (typeIndex >= 0) {
        this._GachaFlags[typeIndex][dataId] = false;
      }
    }
  };

  Game_System.prototype.gachaTypeToIndex = function (type) {
    switch (type) {
      case "item":
        return 0;
      case "weapon":
        return 1;
      case "armor":
        return 2;
      default:
        return -1;
    }
  };

  Game_System.prototype.clearGacha = function () {
    this._GachaFlags = [[], [], []];
  };

  Game_System.prototype.isInGacha = function (item) {
    if (this._GachaFlags && item) {
      var typeIndex = -1;
      if (DataManager.isItem(item)) {
        typeIndex = 0;
      } else if (DataManager.isWeapon(item)) {
        typeIndex = 1;
      } else if (DataManager.isArmor(item)) {
        typeIndex = 2;
      }
      if (typeIndex >= 0) {
        return !!this._GachaFlags[typeIndex][item.id];
      } else {
        return false;
      }
    } else {
      return false;
    }
  };

  function Scene_Gacha() {
    this.initialize.apply(this, arguments);
  }

  Scene_Gacha.prototype = Object.create(Scene_MenuBase.prototype);
  Scene_Gacha.prototype.constructor = Scene_Gacha;

  Scene_Gacha.prototype.initialize = function () {
    Scene_MenuBase.prototype.initialize.call(this);
    this._item = null;
    this._effectPlaying = false;
    this._resultShowing = false;
    this._wait = 0;
    this._effectSprite = null;
    this._windowFadeSprite = null;
    this._screenFadeOutDuration = 0;
    this._screenFadeInDuration = 0;

    this._lot = [];
    var numLot;
    var item, i, j;
    for (i = 1; i < $dataItems.length; i++) {
      item = $dataItems[i];
      if ($gameSystem.isInGacha(item)) {
        numLot = Number(item.meta.gachaNumLot || "0");
        for (j = 0; j < numLot; j++) {
          this._lot.push(item);
        }
      }
    }
    for (i = 1; i < $dataWeapons.length; i++) {
      item = $dataWeapons[i];
      if ($gameSystem.isInGacha(item)) {
        numLot = Number(item.meta.gachaNumLot || "0");
        for (j = 0; j < numLot; j++) {
          this._lot.push(item);
        }
      }
    }
    for (i = 1; i < $dataArmors.length; i++) {
      item = $dataArmors[i];
      if ($gameSystem.isInGacha(item)) {
        numLot = Number(item.meta.gachaNumLot || "0");
        for (j = 0; j < numLot; j++) {
          this._lot.push(item);
        }
      }
    }
  };

  Scene_Gacha.prototype.create = function () {
    Scene_MenuBase.prototype.create.call(this);

    this.createHelpWindow();
    this.createGoldWindow();
    this.createCommandWindow();
    this.createDummyWindow();
    this.createGetCommandWindow();
    this.createGetWindow();

    this._rankSprite = new Sprite_GachaEffect();
    this._rankSprite.keepDisplay(true);
    this.addChild(this._rankSprite);

    this._windowFadeSprite = new ScreenSprite();
    this._windowFadeSprite.setColor(0, 0, 0);
    this._windowFadeSprite.opacity = 0;
    this._windowFadeSprite.visible = false;
    this.addChild(this._windowFadeSprite);

    this._effectSprite = new Sprite_GachaEffect();
    this._effectSprite.x = Graphics.boxWidth / 2;
    this._effectSprite.y = Graphics.boxHeight / 2;
    this.addChild(this._effectSprite);

    this._helpWindow.setText(message);
  };

  Scene_Gacha.prototype.createGoldWindow = function () {
    this._goldWindow = new Window_Gold(0, this._helpWindow.height);
    this._goldWindow.x = Graphics.boxWidth - this._goldWindow.width;
    this.addWindow(this._goldWindow);
  };

  Scene_Gacha.prototype.createCommandWindow = function () {
    this._commandWindow = new Window_GachaCommand(
      this._goldWindow.x,
      this._purchaseOnly
    );
    this._commandWindow.y = this._helpWindow.height;
    this._commandWindow.setHandler("gacha", this.commandGacha.bind(this));
    this._commandWindow.setHandler("cancel", this.popScene.bind(this));
    this._commandWindow.lotIsValid(this._lot.length > 0);
    this._commandWindow.clearCommandList();
    this._commandWindow.makeCommandList();
    this._commandWindow.refresh();
    this.addWindow(this._commandWindow);
  };

  Scene_Gacha.prototype.createDummyWindow = function () {
    var wy = this._commandWindow.y + this._commandWindow.height;
    var wh = Graphics.boxHeight - wy;
    this._dummyWindow = new Window_Base(0, wy, Graphics.boxWidth, wh);
    this.addWindow(this._dummyWindow);
  };

  Scene_Gacha.prototype.createGetCommandWindow = function () {
    this._getCommandWindow = new Window_GachaGetCommand(
      Graphics.boxWidth,
      false
    );
    this._getCommandWindow.y =
      Graphics.boxHeight - this._getCommandWindow.height;
    this._getCommandWindow.setHandler("cancel", this.commandOk.bind(this));
    this._getCommandWindow.hide();
    this.addWindow(this._getCommandWindow);
  };

  Scene_Gacha.prototype.createGetWindow = function () {
    var wy = this._helpWindow.height;
    var wh = Graphics.boxHeight - wy - this._getCommandWindow.height;
    this._getWindow = new Window_GachaGet(0, wy, Graphics.boxWidth, wh);
    this._getWindow.itemDescEnable(itemDescEnable);
    this._getWindow.hide();
    this.addWindow(this._getWindow);
  };

  Scene_Gacha.prototype.commandGacha = function () {
    // Draw lots
    if (this._lot.length <= 0) {
      this._item = null;
    } else {
      this._item = this._lot[(Math.random() * this._lot.length) >> 0];
      $gameParty.loseGold(amount);
      $gameParty.gainItem(this._item, 1);
      this._goldWindow.refresh();
    }

    this._commandWindow.deactivate();
    this._getCommandWindow.deactivate();

    if (this._item) {
      this._getWindow.setItem(this._item);

      this._screenFadeOut();
      this._effectPlaying = true;
      this._wait = 0;

      var animation = $dataAnimations[effect];
      this._effectSprite.startAnimation(animation, false, 0);

      AudioManager.playMe({ name: me, volume: 90, pitch: 100, pan: 0 });
    } else {
      this._commandWindow.activate();
    }
  };

  Scene_Gacha.prototype.commandOk = function () {
    this._effectSprite.allRemove();
    this._rankSprite.allRemove();
    this._goldWindow.show();
    this._commandWindow.show();
    this._commandWindow.activate();
    this._dummyWindow.show();
    this._getCommandWindow.hide();
    this._getWindow.hide();
    this._helpWindow.setText(message);
    this._item = null;

    this._commandWindow.clearCommandList();
    this._commandWindow.makeCommandList();
    this._commandWindow.refresh();
  };

  Scene_Gacha.prototype.update = function () {
    Scene_Menu.prototype.update.call(this);
    this._updateScreenFlashSprite();

    this._wait++;
    if (this._wait > 12) {
      if (this._effectPlaying) {
        if (!this._effectSprite.isAnimationPlaying()) {
          this._screenFadeIn();
          if (!!this._item.meta.gachaImage) {
            var rank = Number(this._item.meta.gachaRank || "-1");
            if (rank > 0 && rank < 6) {
              if (rankEffect[rank - 1] > 0) {
                var animation = $dataAnimations[rankEffect[rank - 1]];
                this._rankSprite.x =
                  this._getWindow.width / 2 + this._getWindow.x - 20;
                this._rankSprite.y =
                  this._getWindow.contentsHeight() + this._getWindow.y;
                if (itemDescEnable) {
                  this._rankSprite.y -= this._getWindow.lineHeight() * 3;
                }
                this._rankSprite.startAnimation(animation, false, 0);
              }
            }
          }

          this._effectPlaying = false;
          this._goldWindow.hide();
          this._commandWindow.hide();
          this._dummyWindow.hide();
          this._getCommandWindow.show();
          this._getWindow.show();
          var message = getText;
          var reg = /Item Name/gi;
          message = message.replace(reg, String(this._item.name));
          this._helpWindow.setText(message);
          this._wait = 0;
          this._resultShowing = true;
        } else {
          if (TouchInput.isTriggered() || Input.isTriggered("ok")) {
            this._effectSprite.allRemove();
          }
        }
      } else if (this._resultShowing) {
        this._resultShowing = false;
        this._getCommandWindow.activate();
      }
    }
  };

  Scene_Gacha.prototype._updateScreenFlashSprite = function () {
    var d;
    if (this._screenFadeOutDuration > 0) {
      d = this._screenFadeOutDuration--;
      this._windowFadeSprite.opacity += 255 * (1 - (d - 1) / d);
    }
    if (this._screenFadeInDuration > 0) {
      d = this._screenFadeInDuration--;
      this._windowFadeSprite.opacity *= (d - 1) / d;
      this._windowFadeSprite.visible = this._screenFadeInDuration > 0;
    }
  };

  Scene_Gacha.prototype._screenFadeOut = function () {
    this._windowFadeSprite.visible = true;
    this._screenFadeOutDuration = 15;
    this._screenFadeInDuration = 0;
  };

  Scene_Gacha.prototype._screenFadeIn = function () {
    this._windowFadeSprite.visible = true;
    this._screenFadeOutDuration = 0;
    this._screenFadeInDuration = 15;
  };

  function Window_Gacha() {
    this.initialize.apply(this, arguments);
  }

  Window_Gacha.prototype = Object.create(Window_Selectable.prototype);
  Window_Gacha.prototype.constructor = Window_Gacha;

  Window_Gacha.prototype.initialize = function (x, y) {
    var width = Graphics.boxWidth;
    var height = this.fittingHeight(6);
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
    this.activate();
  };

  function Window_GachaCommand() {
    this.initialize.apply(this, arguments);
  }

  Window_GachaCommand.prototype = Object.create(Window_HorzCommand.prototype);
  Window_GachaCommand.prototype.constructor = Window_GachaCommand;

  Window_GachaCommand.prototype.initialize = function (width, purchaseOnly) {
    this._windowWidth = width;
    this._purchaseOnly = purchaseOnly;
    Window_HorzCommand.prototype.initialize.call(this, 0, 0);
  };

  Window_GachaCommand.prototype.windowWidth = function () {
    return this._windowWidth;
  };

  Window_GachaCommand.prototype.maxCols = function () {
    return 2;
  };

  Window_GachaCommand.prototype.makeCommandList = function () {
    this.addCommand(
      buttonText,
      "gacha",
      $gameParty.gold() >= amount && !!this._lotIsValid
    );
    this.addCommand(TextManager.cancel, "cancel");
  };

  Window_GachaCommand.prototype.lotIsValid = function (value) {
    this._lotIsValid = value;
  };

  function Window_GachaGetCommand() {
    this.initialize.apply(this, arguments);
  }

  Window_GachaGetCommand.prototype = Object.create(
    Window_HorzCommand.prototype
  );
  Window_GachaGetCommand.prototype.constructor = Window_GachaGetCommand;

  Window_GachaGetCommand.prototype.initialize = function (width, purchaseOnly) {
    this._windowWidth = width;
    this._purchaseOnly = purchaseOnly;
    Window_HorzCommand.prototype.initialize.call(this, 0, 0);
  };

  Window_GachaGetCommand.prototype.windowWidth = function () {
    return this._windowWidth;
  };

  Window_GachaGetCommand.prototype.maxCols = function () {
    return 1;
  };

  Window_GachaGetCommand.prototype.makeCommandList = function () {
    this.addCommand("OK", "cancel");
  };

  function Window_GachaGet() {
    this.initialize.apply(this, arguments);
  }

  Window_GachaGet.prototype = Object.create(Window_Base.prototype);
  Window_GachaGet.prototype.constructor = Window_GachaGet;

  Window_GachaGet.prototype.initialize = function (x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this._item = null;
    this._itemDescEnable = true;
    this._gachaSprite = new Sprite();
    this._gachaSprite.anchor.x = 0.5;
    this._gachaSprite.anchor.y = 0;
    this._gachaSprite.x = width / 2 - 20;
    this._gachaSprite.y = this.padding;
    this.addChildToBack(this._gachaSprite);
    this.refresh();
  };

  Window_GachaGet.prototype.itemDescEnable = function (value) {
    if (this._itemDescEnable !== value) {
      this._itemDescEnable = value;
      this.refresh();
    }
  };

  Window_GachaGet.prototype.setItem = function (item) {
    if (this._item !== item) {
      this._item = item;
      this.refresh();
    }
  };

  Window_GachaGet.prototype.update = function () {
    Window_Base.prototype.update.call(this);
    if (this._gachaSprite.bitmap) {
      var bitmapHeight = this._gachaSprite.bitmap.height;
      var contentsHeight = this.contents.height;
      if (this._itemDescEnable) {
        contentsHeight -= this.lineHeight() * 3;
      }
      var scale = 1;
      if (bitmapHeight > contentsHeight) {
        scale = contentsHeight / bitmapHeight;
      }
      this._gachaSprite.scale.x = scale;
      this._gachaSprite.scale.y = scale;
    }
  };

  Window_GachaGet.prototype.refresh = function () {
    var item = this._item;
    this.contents.clear();

    if (this._itemDescEnable) {
      var y = this.contentsHeight() - this.lineHeight() * 3;
      this.drawHorzLine(y);
      this.drawDescription(0, y + this.lineHeight());
    }

    if (!item || !item.meta.gachaImage) {
      this._gachaSprite.bitmap = null;
      return;
    } else {
      var bitmap;
      bitmap = ImageManager.loadBitmap(
        "img/gacha/",
        this._item.meta.gachaImage
      );
      this._gachaSprite.bitmap = bitmap;
      bitmap.smooth = true;
    }
  };

  Window_GachaGet.prototype.drawDescription = function (x, y) {
    if (this._item) this.drawTextEx(this._item.description, x, y);
  };

  Window_GachaGet.prototype.drawHorzLine = function (y) {
    var lineY = y + this.lineHeight() / 2 - 1;
    this.contents.paintOpacity = 48;
    this.contents.fillRect(0, lineY, this.contentsWidth(), 2, this.lineColor());
    this.contents.paintOpacity = 255;
  };

  Window_GachaGet.prototype.lineColor = function () {
    return this.normalColor();
  };

  function Sprite_GachaEffect() {
    this.initialize.apply(this, arguments);
  }

  Sprite_GachaEffect.prototype = Object.create(Sprite.prototype);
  Sprite_GachaEffect.prototype.constructor = Sprite_GachaEffect;

  Sprite_GachaEffect.prototype.initialize = function () {
    Sprite.prototype.initialize.call(this);
    this._animationSprites = [];
    this._endSprites = [];
    this._effectTarget = this;
    this._hiding = false;
    this._keepDisplay = false;
  };

  Sprite_GachaEffect.prototype.keepDisplay = function (value) {
    this._keepDisplay = value;
  };

  Sprite_GachaEffect.prototype.update = function () {
    Sprite.prototype.update.call(this);
    this.updateVisibility();
    this.updateAnimationSprites();
  };

  Sprite_GachaEffect.prototype.hide = function () {
    this._hiding = true;
    this.updateVisibility();
  };

  Sprite_GachaEffect.prototype.show = function () {
    this._hiding = false;
    this.updateVisibility();
  };

  Sprite_GachaEffect.prototype.updateVisibility = function () {
    this.visible = !this._hiding;
  };

  Sprite_GachaEffect.prototype.updateAnimationSprites = function () {
    if (this._animationSprites.length > 0) {
      var sprites = this._animationSprites.clone();
      this._animationSprites = [];
      for (var i = 0; i < sprites.length; i++) {
        var sprite = sprites[i];
        if (sprite.isPlaying()) {
          this._animationSprites.push(sprite);
        } else {
          if (!this._keepDisplay) {
            sprite.remove();
          } else {
            this._endSprites.push(sprite);
          }
        }
      }
    }
  };

  Sprite_GachaEffect.prototype.startAnimation = function (
    animation,
    mirror,
    delay
  ) {
    var sprite = new Sprite_Animation();
    sprite.setup(this._effectTarget, animation, mirror, delay);
    this.parent.addChild(sprite);
    this._animationSprites.push(sprite);
  };

  Sprite_GachaEffect.prototype.isAnimationPlaying = function () {
    return this._animationSprites.length > 0;
  };

  Sprite_GachaEffect.prototype.allRemove = function () {
    var sprites, sprite, i;
    if (this._animationSprites.length > 0) {
      sprites = this._animationSprites.clone();
      this._animationSprites = [];
      for (i = 0; i < sprites.length; i++) {
        sprite = sprites[i];
        sprite.remove();
      }
    }
    if (this._endSprites.length > 0) {
      sprites = this._endSprites.clone();
      this._endSprites = [];
      for (i = 0; i < sprites.length; i++) {
        sprite = sprites[i];
        sprite.remove();
      }
    }
  };
})();

repo_name: dazed/translations

license: unknown


code:
//=============================================================================
// GachaBook.js
//
// (c)2016 KADOKAWA CORPORATION./YOJI OJIMA
//=============================================================================

/*:
 * @plugindesc Displays detailed statuses of "gacha" items.
 * @author Takeya Kimura
 *
 * @param Unknown Data
 * @desc The index name for an unknown item.
 * @default ??????
 *
 * @param Price Text
 * @desc The text for "Price".
 * @default Price
 *
 * @param Equip Text
 * @desc The text for "Equip".
 * @default Equip
 *
 * @param Type Text
 * @desc The text for "Type".
 * @default Type
 *
 * @param Rank Text
 * @desc The text for "Rank".
 * @default Rank
 *
 * @param Simple Display
 * @desc The switch to display the name and description only.
 * @default 0
 *
 * @help
 *
 * Plugin Command:
 *   GachaBook open            # Open the gacha book screen
 *   GachaBook add weapon 3    # Add weapon #3 to the gacha book
 *   GachaBook add armor 4     # Add armor #4 to the gacha book
 *   GachaBook remove armor 5  # Remove armor #5 from the gacha book
 *   GachaBook remove item 6   # Remove item #6 from the gacha book
 *   GachaBook clear           # Clear the item book
 */

/*:ja
 * @plugindesc ガチャアイテム一覧を表示します。
 * @author Takeya Kimura
 *
 * @param Unknown Data
 * @desc 未確認のガチャアイテムの名前です。
 * @default ??????
 *
 * @param Price Text
 * @desc 「価格」の文字列です。
 * @default Price
 *
 * @param Equip Text
 * @desc 「装備」の文字列です。
 * @default Equip
 *
 * @param Type Text
 * @desc 「タイプ」の文字列です。
 * @default Type
 *
 * @param Rank Text
 * @desc 「ランク」の文字列です。
 * @default Rank
 *
 * @param Simple Display
 * @desc 1と入力すると詳細表示が名前と説明だけになります。[0: 通常表示 1: シンプル表示]
 * @default 0
 *
 * @help
 *
 * Plugin Command:
 *   GachaBook open            # ガチャブックを開きます
 *   GachaBook add weapon 3    # 武器３番をガチャブックに追加
 *   GachaBook add armor 4     # 防具4番をガチャブックに追加
 *   GachaBook remove armor 5  # 防具5番をガチャブックから削除
 *   GachaBook remove item 6   # アイテム6番をガチャブックから削除
 *   GachaBook clear           # ガチャブックをクリアする
 */

(function () {
  var parameters = PluginManager.parameters("GachaBook");
  var unknownData = String(parameters["Unknown Data"] || "??????");
  var priceText = String(parameters["Price Text"] || "Price");
  var equipText = String(parameters["Equip Text"] || "Equip");
  var typeText = String(parameters["Type Text"] || "Type");
  var rankText = String(parameters["Rank Text"] || "Rank");
  var simpleDisplay = !!Number(parameters["Simple Display"] || 0);

  var _Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function (command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if (command === "GachaBook") {
      switch (args[0]) {
        case "open":
          SceneManager.push(Scene_GachaBook);
          break;
        case "add":
          $gameSystem.addToGachaBook(args[1], Number(args[2]));
          break;
        case "remove":
          $gameSystem.removeFromGachaBook(args[1], Number(args[2]));
          break;
        case "complete":
          $gameSystem.completeGachaBook();
          break;
        case "clear":
          $gameSystem.clearGachaBook();
          break;
      }
    }
  };

  Game_System.prototype.addToGachaBook = function (type, dataId) {
    if (!this._GachaBookFlags) {
      this.clearGachaBook();
    }
    var typeIndex = this.gachaBookTypeToIndex(type);
    if (typeIndex >= 0) {
      this._GachaBookFlags[typeIndex][dataId] = true;
    }
  };

  Game_System.prototype.removeFromGachaBook = function (type, dataId) {
    if (this._GachaBookFlags) {
      var typeIndex = this.gachaBookTypeToIndex(type);
      if (typeIndex >= 0) {
        this._GachaBookFlags[typeIndex][dataId] = false;
      }
    }
  };

  Game_System.prototype.gachaBookTypeToIndex = function (type) {
    switch (type) {
      case "item":
        return 0;
      case "weapon":
        return 1;
      case "armor":
        return 2;
      default:
        return -1;
    }
  };

  Game_System.prototype.completeGachaBook = function () {
    var i;
    this.clearGachaBook();
    for (i = 1; i < $dataItems.length; i++) {
      this._GachaBookFlags[0][i] = true;
    }
    for (i = 1; i < $dataWeapons.length; i++) {
      this._GachaBookFlags[1][i] = true;
    }
    for (i = 1; i < $dataArmors.length; i++) {
      this._GachaBookFlags[2][i] = true;
    }
  };

  Game_System.prototype.clearGachaBook = function () {
    this._GachaBookFlags = [[], [], []];
  };

  Game_System.prototype.isInGachaBook = function (item) {
    if (this._GachaBookFlags && item) {
      var typeIndex = -1;
      if (DataManager.isItem(item)) {
        typeIndex = 0;
      } else if (DataManager.isWeapon(item)) {
        typeIndex = 1;
      } else if (DataManager.isArmor(item)) {
        typeIndex = 2;
      }
      if (typeIndex >= 0) {
        return !!this._GachaBookFlags[typeIndex][item.id];
      } else {
        return false;
      }
    } else {
      return false;
    }
  };

  var _Game_Party_gainItem = Game_Party.prototype.gainItem;
  Game_Party.prototype.gainItem = function (item, amount, includeEquip) {
    _Game_Party_gainItem.call(this, item, amount, includeEquip);
    if (item && amount > 0) {
      var type;
      if (DataManager.isItem(item)) {
        type = "item";
      } else if (DataManager.isWeapon(item)) {
        type = "weapon";
      } else if (DataManager.isArmor(item)) {
        type = "armor";
      }
      $gameSystem.addToGachaBook(type, item.id);
    }
  };

  function Scene_GachaBook() {
    this.initialize.apply(this, arguments);
  }

  Scene_GachaBook.prototype = Object.create(Scene_MenuBase.prototype);
  Scene_GachaBook.prototype.constructor = Scene_GachaBook;

  Scene_GachaBook.prototype.initialize = function () {
    Scene_MenuBase.prototype.initialize.call(this);
  };

  Scene_GachaBook.prototype.create = function () {
    Scene_MenuBase.prototype.create.call(this);
    this._indexWindow = new Window_GachaBookIndex(0, 0);
    this._indexWindow.setHandler("cancel", this.popScene.bind(this));
    var wy = this._indexWindow.height;
    var ww = Graphics.boxWidth;
    var wh = Graphics.boxHeight - wy;
    this._statusWindow = new Window_GachaBookStatus(0, wy, ww, wh);
    this.addWindow(this._indexWindow);
    this.addWindow(this._statusWindow);
    this._indexWindow.setStatusWindow(this._statusWindow);
  };

  function Window_GachaBookIndex() {
    this.initialize.apply(this, arguments);
  }

  Window_GachaBookIndex.prototype = Object.create(Window_Selectable.prototype);
  Window_GachaBookIndex.prototype.constructor = Window_GachaBookIndex;

  Window_GachaBookIndex.lastTopRow = 0;
  Window_GachaBookIndex.lastIndex = 0;

  Window_GachaBookIndex.prototype.initialize = function (x, y) {
    var width = Graphics.boxWidth;
    var height = this.fittingHeight(6);
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
    this.setTopRow(Window_GachaBookIndex.lastTopRow);
    this.select(Window_GachaBookIndex.lastIndex);
    this.activate();
  };

  Window_GachaBookIndex.prototype.maxCols = function () {
    return 3;
  };

  Window_GachaBookIndex.prototype.maxItems = function () {
    return this._list ? this._list.length : 0;
  };

  Window_GachaBookIndex.prototype.setStatusWindow = function (statusWindow) {
    this._statusWindow = statusWindow;
    this.updateStatus();
  };

  Window_GachaBookIndex.prototype.update = function () {
    Window_Selectable.prototype.update.call(this);
    this.updateStatus();
  };

  Window_GachaBookIndex.prototype.updateStatus = function () {
    if (this._statusWindow) {
      var item = this._list[this.index()];
      this._statusWindow.setItem(item);
    }
  };

  Window_GachaBookIndex.prototype.refresh = function () {
    var i, item;
    this._list = [];
    for (i = 1; i < $dataItems.length; i++) {
      item = $dataItems[i];
      //if (item.name && item.itypeId === 1 && $gameSystem.isInGacha(item)) { //itypeIdはみない
      if (item.name && $gameSystem.isInGacha(item)) {
        //itypeIdはみない
        this._list.push(item);
      }
    }
    for (i = 1; i < $dataWeapons.length; i++) {
      item = $dataWeapons[i];
      if (item.name && $gameSystem.isInGacha(item)) {
        this._list.push(item);
      }
    }
    for (i = 1; i < $dataArmors.length; i++) {
      item = $dataArmors[i];
      if (item.name && $gameSystem.isInGacha(item)) {
        this._list.push(item);
      }
    }
    this.createContents();
    this.drawAllItems();
  };

  Window_GachaBookIndex.prototype.drawItem = function (index) {
    var item = this._list[index];
    var rect = this.itemRect(index);
    var width = rect.width - this.textPadding();
    if ($gameSystem.isInGachaBook(item)) {
      this.drawItemName(item, rect.x, rect.y, width);
    } else {
      var iw = Window_Base._iconWidth + 4;
      this.drawText(unknownData, rect.x + iw, rect.y, width - iw);
    }
  };

  Window_GachaBookIndex.prototype.processCancel = function () {
    Window_Selectable.prototype.processCancel.call(this);
    Window_GachaBookIndex.lastTopRow = this.topRow();
    Window_GachaBookIndex.lastIndex = this.index();
  };

  function Window_GachaBookStatus() {
    this.initialize.apply(this, arguments);
  }

  Window_GachaBookStatus.prototype = Object.create(Window_Base.prototype);
  Window_GachaBookStatus.prototype.constructor = Window_GachaBookStatus;

  Window_GachaBookStatus.prototype.initialize = function (x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this._itemSprite = new Sprite();
    this._itemSprite.anchor.x = 0.5;
    this._itemSprite.anchor.y = 0.5;
    this._itemSprite.x = width / 2 - 20;
    this._itemSprite.y = height / 2;
    this.addChildToBack(this._itemSprite);
    this.refresh();
  };

  Window_GachaBookStatus.prototype.setItem = function (item) {
    if (this._item !== item) {
      this._item = item;
      this.refresh();
    }
  };

  Window_GachaBookStatus.prototype.update = function () {
    Window_Base.prototype.update.call(this);
    if (this._itemSprite.bitmap) {
      var bitmapHeight = this._itemSprite.bitmap.height;
      var contentsHeight = this.contents.height;
      var scale = 1;
      if (bitmapHeight > contentsHeight) {
        scale = contentsHeight / bitmapHeight;
      }
      this._itemSprite.scale.x = scale;
      this._itemSprite.scale.y = scale;
    }
  };

  Window_GachaBookStatus.prototype.refresh = function () {
    var item = this._item;
    var x = 0;
    var y = 0;
    var lineHeight = this.lineHeight();

    this.contents.clear();

    if (!item || !$gameSystem.isInGachaBook(item)) {
      this._itemSprite.bitmap = null;
      return;
    }

    var bitmap;
    if (!!item.meta.gachaImage) {
      bitmap = ImageManager.loadBitmap("img/gacha/", item.meta.gachaImage);
      bitmap.smooth = true;
    }
    this._itemSprite.bitmap = bitmap;

    var iconBoxWidth = Window_Base._iconWidth + 4;
    this.drawItemName(item, x, y);
    this.drawItemNumber(item, x + this.textWidth(item.name) + iconBoxWidth, y);

    x = this.textPadding();
    y = lineHeight + this.textPadding();

    if (!simpleDisplay) {
      var rank = "-";
      if (item.meta.gachaRank) rank = item.meta.gachaRank;
      this.changeTextColor(this.systemColor());
      this.drawText(rankText, x, y, 120);
      this.resetTextColor();
      this.drawText(rank, x + 120, y, 120, "right");
      y += lineHeight;

      var price = item.price > 0 ? item.price : "-";
      this.changeTextColor(this.systemColor());
      this.drawText(priceText, x, y, 120);
      this.resetTextColor();
      this.drawText(price, x + 120, y, 120, "right");
      y += lineHeight;

      if (DataManager.isWeapon(item) || DataManager.isArmor(item)) {
        var etype = $dataSystem.equipTypes[item.etypeId];
        this.changeTextColor(this.systemColor());
        this.drawText(equipText, x, y, 120);
        this.resetTextColor();
        this.drawText(etype, x + 120, y, 120, "right");
        y += lineHeight;

        var type;
        if (DataManager.isWeapon(item)) {
          type = $dataSystem.weaponTypes[item.wtypeId];
        } else {
          type = $dataSystem.armorTypes[item.atypeId];
        }
        this.changeTextColor(this.systemColor());
        this.drawText(typeText, x, y, 120);
        this.resetTextColor();
        this.drawText(type, x + 120, y, 120, "right");

        //x = this.textPadding() + 300;
        //y = lineHeight + this.textPadding();
        var rewardsWidth = 220;
        x = this.contents.width - rewardsWidth;
        y = lineHeight + this.textPadding();
        for (var i = 2; i < 8; i++) {
          this.changeTextColor(this.systemColor());
          this.drawText(TextManager.param(i), x, y, 160);
          this.resetTextColor();
          this.drawText(item.params[i], x + 160, y, 60, "right");
          y += lineHeight;
        }
      }
    }

    x = 0;
    y = this.textPadding() * 2 + lineHeight * 7;
    this.drawTextEx(item.description, x, y);
  };

  Window_GachaBookStatus.prototype.numberWidth = function () {
    return this.textWidth("000");
  };

  Window_GachaBookStatus.prototype.drawItemNumber = function (item, x, y) {
    this.drawText(":", x, y);
    this.drawText($gameParty.numItems(item), x + this.textWidth("00"), y);
  };
})();


code:
//+=======================================================================+
// Script: GameFocus
// Version: 1.0.0
// Last Update: October 12th, 2015
// Author: Zalerinian
//+=======================================================================+

var Imported = Imported || {};

var Zale = Zale || {};
Zale.GameFocus = Zale.GameFocus || {};

(function () {
  if (Imported["MVCommons"] || Imported["PluginManagement"]) {
    var author = [
      {
        email: "support@razelon.com",
        name: "Zalerinian",
        website: "http://www.razelon.com",
      },
    ];
    var v = PluginManager.register(
      "GameFocus",
      "1.0.0",
      PluginManager.getBasicPlugin("GameFocus").description,
      author,
      "2015-10-12"
    );
    if (v === undefined) {
      throw new Error("Unable to load GameFocus due to mising dependencies!");
    } else if (v === false) {
      PluginManager.printPlugin("GameFocus");
      throw new Error(
        "Unable to load GameFocus due to registration failure! Is there another version running?"
      );
    }
  } else {
    Imported["GameFocus"] = "1.0.0";
    console.log(
      "Neither MVCommons nor PluginManagement are imported - Please install the MVCommons script to maintain an updated list of scripts in the project."
    );
  }
});

/*:
 * @plugindesc Pauses the Audio and/or Video when the game loses focus. Has callbacks for onPause, whilePaused, and onResume.
 * @author Zalerinian
 * @param Pause Audio
 * @desc Pause the game audio when the window loses focus.
 * Default: true
 * @default true
 *
 * @param Pause Graphics
 * @desc Pause the game processing when the window loses focus.
 * Default: true
 * @default true
 *
 * @help
 * ===========================================================================
 *    Introduction
 * ===========================================================================
 *
 * This plugin allows you to have the game pause the audio, video, or both
 * when the game is not the active window. In previous versions of RPG Maker,
 * the engine would pause the video and leave the audio running. This
 * aggrivated not only developers, who had carefully timed cutscenes that
 * relied on audio, but also players, who kept hearing the game's audio loop
 * while it was in the background.
 *
 * ===========================================================================
 *    Usage - Game Developers
 * ===========================================================================
 *
 * For game developers, using this plugin is really easy! You just install it
 * in the Plugin Manager like you already have, and then you set which options
 * you want with the plugin. It can't get too much easier!
 *
 * ===========================================================================
 *    Usage - Plugin Developers
 * ===========================================================================
 *
 * Integrating your plugin with GameFocus is also really easy! GameFocus
 * provides a callback system to let you run a function when the game first
 * losses focus, while the game is out of focus, and on resume, right before
 * everything starts back up.
 *
 * To demonstrate the callback system, GameFocus uses it itself for the
 * functions that pause and restart the game and audio! Please note that these
 * functions are always the first in the callback stack, and so your onPause
 * callbacks technically happen immediately after the game is paused, while
 * onResume will happen immediately after the game resumes. Because the game
 * sets up a callback on the browser's draw method first, it will complete a
 * single update before your onResume callback is called.
 *
 * ===========================================================================
 *    Changing the music mid-pause
 * ===========================================================================
 *
 * While there is very little reason to modify the music that will be played
 * once the game is resumed, you can switch it from within whilePaused. In
 * order to change the BGM or BGS and not cause the music to start playing for
 * no apparent reason to the end user, change the value of the this._audio.bgm
 * and this._audio.bgs objects. The objects were obtained from the
 * AudioManager, and as such hold the same object it has. In most cases, all
 * you need to do is change the "name" field of the object and it will load
 * the new file in when it's ready.
 *
 */

/*:ja
 * @plugindesc ゲームがアクティブウィンドウでなくなった際に、
 * オーディオかビデオ、もしくはその両方を一時停止します。
 * @author Zalerinian
 * @param Pause Audio
 * @desc ウィンドウがアクティブでなくなった際、オーディオを停止します。
 * Default: true
 * @default true
 *
 * @param Pause Graphics
 * @desc ウィンドウがアクティブでなくなった際、ビデオを停止します。
 * Default: true
 * @default true
 *
 * @help
 * ===========================================================================
 *    Introduction
 * ===========================================================================
 *
 * このプラグインは、ゲームがアクティブウィンドウでなくなった際に、
 * オーディオかビデオ、もしくはその両方を一時停止します。
 * 以前のRPGツクールのバージョンでは、
 * エンジンはビデオのみを停止し、音楽を流し続けていました。
 * これはカットシーンを入念に作り込んでいた開発者の悩みの種であり、
 * バックグラウンド表示でBGMを聞き続けなければならない
 * プレイヤーにとっても、煩わしいものでした。
 *
 * ===========================================================================
 *    使用方法 - ゲーム開発者向け
 * ===========================================================================
 *
 * ゲーム開発者向けの使用方法は非常に簡単です。
 * GameFocusをプラグインマネージャーにインストールし、
 * オプション選択をするだけで適用完了することができます！
 *
 * ===========================================================================
 *    使用方法 - プラグイン開発者向け
 * ===========================================================================
 *
 * GameFocusをあなたのプラグインと統合するのは、非常に簡単です。
 * GameFocusは、ゲームフォーカスが外れた際、その最中とゲーム再開時に、
 * 関数を実行するコールバックシステムを提供します。
 * GameFocusはコールバックシステムそれ自身を、
 * ゲーム/オーディオの停止・再開用の関数として用います。
 *
 * GameFocusはonPause, whilePaused, onResumeのコールバックを提供します。
 * これらの関数は常にコールバックスタックの上位に来るため、
 * ゲームが一時停止されると即座に、onPauseコールバックが発生します。
 * 同様に、ゲーム再開時にも即座にonRedumeのコールバックが発生します。
 * 最初にブラウザの描画メソッド上にコールバックがセットされるため、
 * onResumeが呼び出される前に、1つのアップデートが完了されます。
 *
 * ===========================================================================
 *    中断時の音楽変更
 * ===========================================================================
 *
 * ゲーム再開時に、音楽を変更する必要はあまりないかもしれませんが、
 * WhilePaused内から音楽を切り替えることもできます。
 * BGM/BGSを変更するには、"this._audio.bgm" と "this._audio.bgs"
 * オブジェクトの値を変更してください。
 * これらのオブジェクトは AudioManagerから取得されています。
 * オブジェクトの"name"フィールドを変更すれば、
 * 準備ができ次第、新しいファイルが読み込まれます。
 *
 */

function GameFocus() {
  throw new Error("GameFocus is a static class!");
}

(function ($) {
  // --------------------------------------------------------------------------
  //
  // boolFunc(string str)
  //    str: A string to be compared against true.
  //
  //  This function will take the string and compare it to true, returning
  //  true if the given string is also true, or false otherwise.
  //
  //  Returns:
  //  True when str is "true"
  //  False otherwise
  //
  // --------------------------------------------------------------------------
  function boolFunc(str) {
    return Function("return " + str + " === true")();
  }

  var params = PluginManager.parameters("GameFocus");

  Zale.GameFocus.PauseAudio = boolFunc(params["Pause Audio"]);
  Zale.GameFocus.PauseGraphics = boolFunc(params["Pause Graphics"]);

  $._callbacks = { onPause: [], whilePaused: [], onResume: [] };
  $._audio = {};
  $._paused = { audio: false, graphics: false };

  // --------------------------------------------------------------------------
  //
  // GameFocus.registerCallback(string type, function cb)
  //    type: Notes the type of callback being registered. Valid values are
  //          onPause, whilePaused, and onResume
  //
  //    cb:   The function to call when the time comes.
  //
  //  This function will add the given function to the list of functions to
  //  call when it's call type is ready. onPause types are called right when
  //  the game loses focus. whilePaused types only run while the game is
  //  paused. onResume types run when the game first regains focus.
  //
  //  Returns:
  //  This function returns no value.
  //
  // --------------------------------------------------------------------------
  $.registerCallback = function (type, cb) {
    if (
      typeof cb === "function" &&
      ["onPause", "whilePaused", "onResume"].contains(type)
    ) {
      this._callbacks[type].push(cb);
    }
  };

  // --------------------------------------------------------------------------
  //
  // GameFocus.removeCallback(string type, function cb)
  //    type: The type of callback that was previously registered. Valis values
  //          are onPause, whilePaused, and onResume.
  //
  //    cb:   The function to remove from the callback list.
  //
  //  This function will remove the specified function from the list of
  //  callbacks, preventing it from being called without being re-registered.
  //
  //  Returns:
  //  This function returns no value.
  //
  // --------------------------------------------------------------------------
  $.removeCallback = function (type, cb) {
    if (
      typeof cb === "function" &&
      ["onPause", "whilePaused", "onResume"].contains(type)
    ) {
      var index = this._callbacks.indexOf(cb);
      this._callbacks[type].splice(index, 1);
    }
  };

  // --------------------------------------------------------------------------
  //
  // GameFocus.checkForFocus()
  //
  //  This function is called when the game window redraws itself when the game
  //  is paused. It will call the callbacks as needed, and request that it be
  //  rerun at the next frame draw so as to continue checking for focus.
  //
  //  You should NOT call this function yourself, or the onResume callbacks
  //  will be called when they don't expect to be, possibly leading to
  //  undefined behavior.
  //
  //  Returns:
  //  This function returns no value.
  //
  // --------------------------------------------------------------------------
  function checkForFocus() {
    if (document.hasFocus()) {
      var cbs = GameFocus._callbacks.onResume;
      for (var i = 0; i < cbs.length; i++) {
        cbs[i].call(GameFocus);
      }
    } else {
      var cbs = GameFocus._callbacks.whilePaused;
      for (var i = 0; i < cbs.length; i++) {
        cbs[i].call(GameFocus);
      }
      window.requestAnimationFrame(checkForFocus);
    }
  }

  // --------------------------------------------------------------------------
  //
  // Input._onLostFocus()
  //
  //  This function was aliased from the Input class, and is used to call all
  //  onPaused callbacks, and begin the inital checkForFocus call.
  //
  //  Returns:
  //  This function returns no value.
  //
  // --------------------------------------------------------------------------
  Zale.GameFocus.Input_update_POJc32oincwoSn = Input.update;
  Input.update = function () {
    Zale.GameFocus.Input_update_POJc32oincwoSn.call(this);
    if (!document.hasFocus()) {
      var cbs = GameFocus._callbacks.onPause;
      for (var i = 0; i < cbs.length; i++) {
        cbs[i].call(GameFocus);
      }
      checkForFocus();
    }
  };

  // --------------------------------------------------------------------------
  //
  // SceneManager.start()
  //
  //  This function reverts SceneManager.stop() by setting _stopped to false,
  //  allowing the SceneManager to continue updating the game.
  //
  //  Returns:
  //  This function returns no value.
  //
  // --------------------------------------------------------------------------
  SceneManager.start = function () {
    this._stopped = false;
    this.update();
  };

  // --------------------------------------------------------------------------
  //
  // GameFocus onPause Callback
  //
  //  This function is a primary function in GameFocus, and is the first
  //  callback in the onPause stack. It will check it's configuration, and stop
  //  all audio and/or video if it needs to.
  //
  //  Returns:
  //  This function returns no value.
  //
  // --------------------------------------------------------------------------
  $.registerCallback("onPause", function () {
    if (Zale.GameFocus.PauseAudio) {
      this._paused.audio = true;
      this._audio.bgm = AudioManager.saveBgm();
      this._audio.bgs = AudioManager.saveBgs();
      AudioManager.stopMe();
      AudioManager.stopSe();
      if (AudioManager._bgmBuffer) {
        AudioManager._bgmBuffer.stop();
      }
      if (AudioManager._bgsBuffer) {
        AudioManager._bgsBuffer.stop();
      }
    }
    if (Zale.GameFocus.PauseGraphics) {
      this._paused.graphics = true;
      SceneManager.stop();
    }
  });

  // --------------------------------------------------------------------------
  //
  // GameFocus onResume Callback
  //
  //  This function is a primary function in GameFocus, and is the first
  //  callback in the onResume stack. It checks it's configuration to see if
  //  the audio or video was stopped earlier, and if it was, resumes it. If the
  //  AudioManager detects that the stored audio is not the audio that was
  //  playing at the pause, the new audio is played as normal. Otherwise, the
  //  audio buffer is used to directly restart the audio.
  //
  //  Returns:
  //  This function returns no values.
  //
  // --------------------------------------------------------------------------
  $.registerCallback("onResume", function () {
    if (this._paused.audio) {
      this._paused.audio = false;
      var bgm = this._audio.bgm;
      var bgs = this._audio.bgs;
      if (!AudioManager.isCurrentBgm(this._audio.bgm)) {
        AudioManager.playBgm(this._audio.bgm);
      } else if (AudioManager._bgmBuffer) {
        AudioManager._bgmBuffer.play(true, bgm.pos);
      }
      if (!AudioManager.isCurrentBgs(this._audio.bgs)) {
        AudioManager.playBgs(this._audio.bgs);
      } else if (AudioManager._bgsBuffer) {
        AudioManager._bgsBuffer.play(true, bgs.pos);
      }
    }
    if (this._paused.graphics) {
      this._paused.graphics = false;
      SceneManager.start();
    }
  });
})(GameFocus);


code:
//=============================================================================
// Yanfly Engine Plugins - Gamepad Config
// GamepadConfig.js
// Version: 1.00
//=============================================================================

var Imported = Imported || {};
Imported.GamepadConfig = true;

var Yanfly = Yanfly || {};
Yanfly.GamepadConfig = Yanfly.GamepadConfig || {};

//=============================================================================
/*:
 * @plugindesc v1.00 Allows players to adjust their button configuration
 * for gamepads.
 * @author Yanfly Engine Plugins
 *
 * @param Command Name
 * @desc This is the option name that appears in the main menu.
 * @default Gamepad Config
 *
 * @param Button Name
 * @desc This is how a button name will appear in the config menu.
 * @default Button %1
 *
 * @param OK Button
 * @desc This is the command name for the OK button.
 * @default OK / Talk
 *
 * @param OK Help
 * @desc This is the help description for the OK button.
 * @default Used to accept menu actions and talk to people.
 *
 * @param Cancel Button
 * @desc Cancel Button
 * @desc This is the command name for the Cancel button.
 * @default Cancel
 *
 * @param Cancel Help
 * @desc This is the help description for the Cancel button.
 * @default Used to cancel menu actions.
 *
 * @param Shift Button
 * @desc This is the command name for the Shift button.
 * @default Dash
 *
 * @param Shift Help
 * @desc This is the help description for the Shift button.
 * @default Hold this button to dash on the field.
 *
 * @param Menu Button
 * @desc This is the command name for the Menu button.
 * @default Menu
 *
 * @param Menu Help
 * @desc This is the help description for the Menu button.
 * @default Access the Main Menu from the field.
 *
 * @param PageUp Button
 * @desc This is the command name for the Page Up button.
 * @default Page Up
 *
 * @param PageUp Help
 * @desc This is the help description for the Page Up button.
 * @default Use it to quickly scroll up menus.
 *
 * @param PageDown Button
 * @desc This is the command name for the Page Down button.
 * @default Page Down
 *
 * @param PageDown Help
 * @desc This is the help description for the Page Down button.
 * @default Use it to quickly scroll down menus.
 *
 * @param Reset Default
 * @desc This is the command name to reset the config to default.
 * @default Reset to Default
 *
 * @param Reset Help
 * @desc This is the help description for the Reset button.
 * @default Returns your controller to default settings.
 *
 * @param Finish Config
 * @desc This is the command name for the finish button.
 * @default Finish Configuration
 *
 * @param Finish Help
 * @desc This is the help description for the Finish button.
 * @default Are you done configuring your gamepad?
 *
 * @help
 * Adds a "Gamepad Config" option to the Options Menu if a gamepad is detected.
 * Players can then adjust the button configuration to their liking and it will
 * be loaded automatically each time they play the game. Keep in mind that if
 * at any point where a Gamepad is not detected inside of the Option or Gamepad
 * Config menu, the game will automatically eject the player out the prevent
 * the player from being locked inside.
 */

/*:ja
 * @plugindesc ゲームパッド向けにボタンコンフィグを行なうプラグインです。
 * @author Yanfly Engine Plugins
 *
 * @param Command Name
 * @desc メインメニューに表示されるオプション名を変更できます
 * @default Gamepad Config
 *
 * @param Button Name
 * @desc コンフィグメニューでのボタン名の表示方法を変更できます
 * @default Button %1
 *
 * @param OK Button
 * @desc OKボタンに対するコマンド名を変更できます
 * @default OK / Talk
 *
 * @param OK Help
 * @desc OKボタンに対するヘルプを設定できます
 * @default メニューの決定/人に話しかける際に使うボタンです
 *
 * @param Cancel Button
 * @desc キャンセルボタン
 * @desc キャンセルボタンに対するコマンド名を変更できます
 * @default Cancel
 *
 * @param Cancel Help
 * @desc キャンセルボタンに対するヘルプを設定できます
 * @default メニューアクションをキャンセルする際に使うボタンです
 *
 * @param Shift Button
 * @desc シフトボタンに対するコマンド名を変更できます
 * @default ダッシュ
 *
 * @param Shift Help
 * @desc シフトボタンに対するヘルプを設定できます
 * @default 長押しするとフィールド上をダッシュできます
 *
 * @param Menu Button
 * @desc メニューボタンに対するコマンド名を変更できます
 * @default Menu
 *
 * @param Menu Help
 * @desc メニューボタンに対するヘルプを設定できます
 * @default フィールドからメインメニューにアクセスします
 *
 * @param PageUp Button
 * @desc ページアップボタンに対するコマンド名を変更できます
 * @default Page Up
 *
 * @param PageUp Help
 * @desc ページアップボタンに対するヘルプを設定できます
 * @default メニューを素早くスクロールアップできます
 *
 * @param PageDown Button
 * @desc ページダウンボタンに対するコマンド名を変更できます
 * @default Page Down
 *
 * @param PageDown Help
 * @desc ページダウンボタンに対するヘルプを設定できます
 * @default メニューを素早くスクロールダウンできます
 *
 * @param Reset Default
 * @desc コンフィグをリセットする際のコマンド名を変更できます
 * @default Reset to Default
 *
 * @param Reset Help
 * @desc リセットボタンに対するヘルプを設定できます
 * @default コントローラコンフィグをデフォルトに戻します
 *
 * @param Finish Config
 * @desc コンフィグを完了する際のコマンド名を変更できます
 * @default Finish Configuration
 *
 * @param Finish Help
 * @desc 完了ボタンに対するヘルプを設定できます
 * @default ゲームパッドのコンフィグを完了しますか？
 *
 * @help
 * ゲームパッドが使用される場合、
 * "Gamepad Config"をオプションメニューに追加してください。
 * プレイヤーは好みのコンフィグ設定を行うことができ、
 * その設定は毎回プレイ時に自動的にロードされます。
 *
 * ゲームパッドがオプションやゲームパッドコンフィグから検出されなくなると、
 * ゲームは自動的にプレイヤーを排出し、ゲーム内に閉じ込められることを防ぎます。
 *
 */

//=============================================================================

//=============================================================================
// Parameter Variables
//=============================================================================

Yanfly.Parameters = PluginManager.parameters("GamepadConfig");
Yanfly.Param = Yanfly.Param || {};

Yanfly.Param.GamepadConfigName = String(Yanfly.Parameters["Command Name"]);
Yanfly.Param.GamepadConfigButton = String(Yanfly.Parameters["Button Name"]);
Yanfly.Param.GamepadConfigOkTx = String(Yanfly.Parameters["OK Button"]);
Yanfly.Param.GamepadConfigOkHelp = String(Yanfly.Parameters["OK Help"]);
Yanfly.Param.GamepadConfigCancelTx = String(Yanfly.Parameters["Cancel Button"]);
Yanfly.Param.GamepadConfigCancelHelp = String(Yanfly.Parameters["Cancel Help"]);
Yanfly.Param.GamepadConfigShiftTx = String(Yanfly.Parameters["Shift Button"]);
Yanfly.Param.GamepadConfigShiftHelp = String(Yanfly.Parameters["Shift Help"]);
Yanfly.Param.GamepadConfigMenuTx = String(Yanfly.Parameters["Menu Button"]);
Yanfly.Param.GamepadConfigMenuHelp = String(Yanfly.Parameters["Menu Help"]);
Yanfly.Param.GamepadConfigPgUpTx = String(Yanfly.Parameters["PageUp Button"]);
Yanfly.Param.GamepadConfigPgUpHelp = String(Yanfly.Parameters["PageUp Help"]);
Yanfly.Param.GamepadConfigPgDnTx = String(Yanfly.Parameters["PageDown Button"]);
Yanfly.Param.GamepadConfigPgDnHelp = String(Yanfly.Parameters["PageDown Help"]);
Yanfly.Param.GamepadConfigResetTx = String(Yanfly.Parameters["Reset Default"]);
Yanfly.Param.GamepadConfigResetHelp = String(Yanfly.Parameters["Reset Help"]);
Yanfly.Param.GamepadConfigFinishTx = String(Yanfly.Parameters["Finish Config"]);
Yanfly.Param.GamepadConfigFinishHelp = String(Yanfly.Parameters["Finish Help"]);

//=============================================================================
// Input
//=============================================================================

Input.getPressedGamepadButton = function () {
  if (Yanfly.Param.GamepadTimer > 0) {
    Yanfly.Param.GamepadTimer -= 1;
    return -1;
  }
  if (navigator.getGamepads) {
    var gamepads = navigator.getGamepads();
    if (gamepads) {
      for (var i = 0; i < gamepads.length; i++) {
        var gamepad = gamepads[i];
        if (gamepad && gamepad.connected) {
          return this.gamepadButtonId(gamepad);
        }
      }
    }
  }
  return -1;
};

Input.gamepadButtonId = function (gamepad) {
  var buttons = gamepad.buttons;
  for (var i = 0; i < buttons.length; i++) {
    if (buttons[i].pressed) return i;
  }
  return -1;
};

Input.getGamepadButton = function (type) {
  for (var i = 0; i < 12; ++i) {
    if (Input.gamepadMapper[i] === type) return i;
  }
  return null;
};

Input.isControllerConnected = function () {
  if (navigator.getGamepads) {
    var gamepads = navigator.getGamepads();
    if (gamepads) {
      for (var i = 0; i < gamepads.length; i++) {
        var gamepad = gamepads[i];
        if (gamepad && gamepad.connected) return true;
      }
    }
  }
  return false;
};

//=============================================================================
// ConfigManager
//=============================================================================

ConfigManager.gamepadInput = {
  0: "ok",
  1: "cancel",
  2: "shift",
  3: "menu",
  4: "pageup",
  5: "pagedown",
  12: "up",
  13: "down",
  14: "left",
  15: "right",
};

Yanfly.GamepadConfig.ConfigManager_makeData = ConfigManager.makeData;
ConfigManager.makeData = function () {
  var config = Yanfly.GamepadConfig.ConfigManager_makeData.call(this);
  config.gamepadInput = this.gamepadInput;
  return config;
};

Yanfly.GamepadConfig.ConfigManager_applyData = ConfigManager.applyData;
ConfigManager.applyData = function (config) {
  Yanfly.GamepadConfig.ConfigManager_applyData.call(this, config);
  this.gamepadInput = this.readGamepadConfig(config, "gamepadInput");
  this.applyGamepadConfig();
};

ConfigManager.applyGamepadConfig = function () {
  Input.gamepadMapper = this.gamepadInput;
  Input.update();
  Input.clear();
};

ConfigManager.readGamepadConfig = function (config, name) {
  var value = config[name];
  if (value !== undefined) {
    return value;
  } else {
    return {
      0: "ok",
      1: "cancel",
      2: "shift",
      3: "menu",
      4: "pageup",
      5: "pagedown",
      12: "up",
      13: "down",
      14: "left",
      15: "right",
    };
  }
};

//=============================================================================
// Window_MenuCommand
//=============================================================================

Yanfly.GamepadConfig.Window_Options_addGeneralOptions =
  Window_Options.prototype.addGeneralOptions;
Window_Options.prototype.addGeneralOptions = function () {
  Yanfly.GamepadConfig.Window_Options_addGeneralOptions.call(this);
  this.addGameConfigCommand();
};

Window_Options.prototype.addGameConfigCommand = function () {
  if (Input.isControllerConnected()) {
    this.addCommand(Yanfly.Param.GamepadConfigName, "gamepadConfig", true);
    this._addedController = true;
  }
};

Yanfly.GamepadConfig.Window_Options_update = Window_Options.prototype.update;
Window_Options.prototype.update = function () {
  Yanfly.GamepadConfig.Window_Options_update.call(this);
  if (this._addedController && !Input.isControllerConnected()) {
    this.refresh();
    this.height = this.windowHeight();
    this.updatePlacement();
  }
};

Yanfly.GamepadConfig.Window_Options_drawItem =
  Window_Options.prototype.drawItem;
Window_Options.prototype.drawItem = function (index) {
  if (this.commandSymbol(index) === "gamepadConfig") {
    var rect = this.itemRectForText(index);
    var text = this.commandName(index);
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.drawText(text, rect.x, rect.y, rect.width, "left");
  } else {
    Yanfly.GamepadConfig.Window_Options_drawItem.call(this, index);
  }
};

Yanfly.GamepadConfig.Window_Options_processOk =
  Window_Options.prototype.processOk;
Window_Options.prototype.processOk = function () {
  if (this.commandSymbol(this.index()) === "gamepadConfig") {
    Window_Command.prototype.processOk.call(this);
  } else {
    Yanfly.GamepadConfig.Window_Options_processOk.call(this);
  }
};

//=============================================================================
// Window_GamepadConfig
//=============================================================================

function Window_GamepadConfig() {
  this.initialize.apply(this, arguments);
}

Window_GamepadConfig.prototype = Object.create(Window_Command.prototype);
Window_GamepadConfig.prototype.constructor = Window_GamepadConfig;

Window_GamepadConfig.prototype.initialize = function (helpWindow) {
  var wy = helpWindow.height;
  Window_Command.prototype.initialize.call(this, 0, wy);
  this.setHelpWindow(helpWindow);
  this.height = Graphics.boxHeight - wy;
  this.refresh();
  this.activate();
  this.select(0);
};

Window_GamepadConfig.prototype.windowWidth = function () {
  return Graphics.boxWidth;
};

Window_GamepadConfig.prototype.makeCommandList = function (index) {
  for (var i = 0; i < 6; ++i) {
    var text = this.getButtonTypeText(i);
    this.addCommand(text, "button", true);
  }
  this.addCommand("", "filler", true);
  this.addCommand(this.getButtonTypeText(7), "reset", true);
  this.addCommand(this.getButtonTypeText(8), "finish", true);
};

Window_GamepadConfig.prototype.drawItem = function (index) {
  if (index > 5) {
    Window_Command.prototype.drawItem.call(this, index);
  } else {
    var rect = this.itemRectForText(index);
    var align = this.itemTextAlign();
    var ww = rect.width / 2;
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.drawText(this.commandName(index), rect.x, rect.y, ww, align);
    var text = this.getButtonConfig(index);
    this.drawText(text, rect.x + ww, rect.y, ww, align);
  }
};

Window_GamepadConfig.prototype.getButtonTypeText = function (index) {
  if (index === 0) return Yanfly.Param.GamepadConfigOkTx;
  if (index === 1) return Yanfly.Param.GamepadConfigCancelTx;
  if (index === 2) return Yanfly.Param.GamepadConfigShiftTx;
  if (index === 3) return Yanfly.Param.GamepadConfigMenuTx;
  if (index === 4) return Yanfly.Param.GamepadConfigPgUpTx;
  if (index === 5) return Yanfly.Param.GamepadConfigPgDnTx;
  if (index === 7) return Yanfly.Param.GamepadConfigResetTx;
  if (index === 8) return Yanfly.Param.GamepadConfigFinishTx;
  return "";
};

Window_GamepadConfig.prototype.getButtonConfig = function (index) {
  if (index > 5) return "";
  var key = this.getButtonKey(index);
  var button = Input.getGamepadButton(key);
  return Yanfly.Param.GamepadConfigButton.format(button);
};

Window_GamepadConfig.prototype.getButtonKey = function (index) {
  if (index === 0) return "ok";
  if (index === 1) return "cancel";
  if (index === 2) return "shift";
  if (index === 3) return "menu";
  if (index === 4) return "pageup";
  if (index === 5) return "pagedown";
};

Window_GamepadConfig.prototype.itemTextAlign = function () {
  return "center";
};

Window_GamepadConfig.prototype.clearButtonConfig = function (index) {
  var rect = this.itemRectForText(index);
  rect.x += rect.width / 2;
  rect.width /= 2;
  this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);
};

Window_GamepadConfig.prototype.updateHelp = function () {
  if (!this._helpWindow) return;
  switch (this.index()) {
    case 0:
      this._helpWindow.setText(Yanfly.Param.GamepadConfigOkHelp);
      break;
    case 1:
      this._helpWindow.setText(Yanfly.Param.GamepadConfigCancelHelp);
      break;
    case 2:
      this._helpWindow.setText(Yanfly.Param.GamepadConfigShiftHelp);
      break;
    case 3:
      this._helpWindow.setText(Yanfly.Param.GamepadConfigMenuHelp);
      break;
    case 4:
      this._helpWindow.setText(Yanfly.Param.GamepadConfigPgUpHelp);
      break;
    case 5:
      this._helpWindow.setText(Yanfly.Param.GamepadConfigPgDnHelp);
      break;
    case 7:
      this._helpWindow.setText(Yanfly.Param.GamepadConfigResetHelp);
      break;
    case 8:
      this._helpWindow.setText(Yanfly.Param.GamepadConfigFinishHelp);
      break;
    default:
      this._helpWindow.clear();
      break;
  }
};

//=============================================================================
// Scene_Options
//=============================================================================

Yanfly.GamepadConfig.Scene_Options_createOptionsWindow =
  Scene_Options.prototype.createOptionsWindow;
Scene_Options.prototype.createOptionsWindow = function () {
  Yanfly.GamepadConfig.Scene_Options_createOptionsWindow.call(this);
  this._optionsWindow.setHandler(
    "gamepadConfig",
    this.commandGamepadConfig.bind(this)
  );
};

Scene_Options.prototype.commandGamepadConfig = function () {
  SceneManager.push(Scene_GamepadConfig);
};

//=============================================================================
// Scene_GamepadConfig
//=============================================================================

function Scene_GamepadConfig() {
  this.initialize.apply(this, arguments);
}

Scene_GamepadConfig.prototype = Object.create(Scene_MenuBase.prototype);
Scene_GamepadConfig.prototype.constructor = Scene_GamepadConfig;

Scene_GamepadConfig.prototype.initialize = function () {
  Scene_MenuBase.prototype.initialize.call(this);
};

Scene_GamepadConfig.prototype.create = function () {
  Scene_MenuBase.prototype.create.call(this);
  this.createHelpWindow();
  this.createGamepadConfigWindow();
};

Scene_GamepadConfig.prototype.terminate = function () {
  Scene_MenuBase.prototype.terminate.call(this);
  ConfigManager.save();
};

Scene_GamepadConfig.prototype.update = function () {
  Scene_MenuBase.prototype.update.call(this);
  this.updateAttachedController();
  this.updateButtonConfig();
  this.updateAfterConfig();
};

Scene_GamepadConfig.prototype.updateAttachedController = function () {
  if (Input.isControllerConnected()) return;
  this.popScene();
};

Scene_GamepadConfig.prototype.createGamepadConfigWindow = function () {
  this._configWindow = new Window_GamepadConfig(this._helpWindow);
  this._configWindow.setHandler("button", this.commandButton.bind(this));
  this._configWindow.setHandler("reset", this.commandReset.bind(this));
  this._configWindow.setHandler("finish", this.popScene.bind(this));
  this.addWindow(this._configWindow);
};

Scene_GamepadConfig.prototype.commandButton = function () {
  var index = this._configWindow.index();
  this._configWindow.clearButtonConfig(index);
  this._configEnabled = true;
  Yanfly.Param.GamepadTimer = 12;
};

Scene_GamepadConfig.prototype.commandReset = function () {
  ConfigManager.gamepadInput = {
    0: "ok",
    1: "cancel",
    2: "shift",
    3: "menu",
    4: "pageup",
    5: "pagedown",
    12: "up",
    13: "down",
    14: "left",
    15: "right",
  };
  ConfigManager.applyGamepadConfig();
  this.refreshWindows();
};

Scene_GamepadConfig.prototype.refreshWindows = function () {
  this._configWindow.refresh();
  this._configWindow.activate();
  ConfigManager.save();
};

Scene_GamepadConfig.prototype.updateButtonConfig = function () {
  if (!this._configEnabled) return;
  var buttonId = Input.getPressedGamepadButton();
  if (buttonId > 11) return;
  if (buttonId >= 0) this.applyButtonConfig(buttonId);
};

Scene_GamepadConfig.prototype.applyButtonConfig = function (buttonId) {
  this._configEnabled = false;
  var index = this._configWindow.index();
  var newConfig = this._configWindow.getButtonKey(index);
  var formerConfig = Input.gamepadMapper[buttonId];
  var formerButton = Input.getGamepadButton(newConfig);
  ConfigManager.gamepadInput[buttonId] = newConfig;
  ConfigManager.gamepadInput[formerButton] = formerConfig;
  ConfigManager.applyGamepadConfig();
  this._configTimer = 12;
};

Scene_GamepadConfig.prototype.updateAfterConfig = function () {
  if (!this._configTimer) return;
  if (--this._configTimer > 0) return;
  SoundManager.playEquip();
  this.refreshWindows();
};

//=============================================================================
// End of File
//=============================================================================


code:
//=============================================================================
// HPConsumeSkill.js
//=============================================================================

/*:
 * @plugindesc make the skill that consumes HP, not only MP and/or TP
 * @author Sasuke KANNAZUKI
 *
 * @help This plugin does not provide plugin commands.
 *
 * write following format at skill's note:
 *  <hp_cost:30>  # the skill consumes 30 HP.
 *
 *  The skill can use even if subject's HP is less than skill's HP Cost.
 *  In that case, let the subject's HP be 1.
 *  (i.e. subject won't die by the skill.)
 */

/*:ja
 * @plugindesc HP消費技
 * @author 神無月サスケ
 *
 * @help このプラグインには、プラグインコマンドはありません。
 *
 * 仕様：
 * スキルのメモ欄に「<hp_cost:30>」といった書式で書いてください。
 * この場合、HPを30消費します。
 *
 * 入力時や術使用時のHPが、消費HPより低い場合でも選択、実行可能で、
 * この場合使用後のHPは1になります。（つまり、この技で戦闘不能にはならない）
 *
 * - HPの消費は、技を使う前になされます。
 * - HPと同時に、MPやTPを消費する技も作成可能ですが、
 *  ウィンドウでは消費HPのみが表示されます。
 */

(function () {
  // --------------------
  // Process Data in item.note
  // *for efficiency, note is processed at first.
  // --------------------

  var _Scene_Boot_start = Scene_Boot.prototype.start;
  Scene_Boot.prototype.start = function () {
    _Scene_Boot_start.call(this);
    DataManager.processHpCost();
  };

  DataManager.processHpCost = function () {
    for (var i = 1; i < $dataSkills.length; i++) {
      var skill = $dataSkills[i];
      var result = skill.meta.hp_cost;
      if (result) {
        skill.hpCost = Number(result);
      } else {
        skill.hpCost = 0;
      }
    }
  };

  // --------------------
  // exec consume HP cost
  // --------------------

  Game_BattlerBase.prototype.skillHpCost = function (skill) {
    return skill.hpCost;
  };

  var _Game_BattlerBase_paySkillCost = Game_BattlerBase.prototype.paySkillCost;
  Game_BattlerBase.prototype.paySkillCost = function (skill) {
    _Game_BattlerBase_paySkillCost.call(this, skill);
    if (this._hp > this.skillHpCost(skill)) {
      this._hp -= this.skillHpCost(skill);
    } else {
      this._hp = 1;
    }
  };

  // --------------------
  // draw HP cost
  // --------------------

  var _Window_SkillList_drawSkillCost =
    Window_SkillList.prototype.drawSkillCost;
  Window_SkillList.prototype.drawSkillCost = function (skill, x, y, width) {
    if (this._actor.skillHpCost(skill) > 0) {
      this.changeTextColor(this.textColor(17));
      this.drawText(this._actor.skillHpCost(skill), x, y, width, "right");
      return;
    }
    _Window_SkillList_drawSkillCost.call(this, skill, x, y, width);
  };
})();