code:
/*:
 * Yami Engine Delta - Sideview Battler Enhancement
 *
 * @plugindesc v1.0.0 This plugin allows user to use any kind of sideview battler.
 * @author Yami Engine Delta [Dr.Yami]
 *
 * @param [Default Setting]
 * @default
 *
 * @param Default Frames
 * @desc Default frames number for each pose.
 * @default 3
 *
 * @param Default Speed
 * @desc Default speed for each pose. The higher number, the slower motion is.
 * @default 12
 *
 * @param Default Frame Width
 * @desc Default frame width.
 * @default 96
 *
 * @param Default Frame Height
 * @desc Default frame height.
 * @default 96
 *
 * @param Enable Weapon
 * @desc Showing weapon for battler.
 * @default false
 *
 * @help
 * There is no Plugin Command for this plugin.
 *
 * ============================================================================
 * Actors & Enemies Notetags
 *
 * <Sideview Battler: FILENAME>
 * Enable custom sideview battler for actor/enemy with battler set FILENAME.
 *
 * <Sideview Battler Default>
 * Make this battler use default kind of battler (MV's SV Battlers).
 *
 * <Sideview Battler Frames: X>
 * Change default number of frames per pose for current battler.
 *
 * <Sideview Battler Speed: X>
 * Change default speed per pose for current battler. The higher number, the
 * slower motion is.
 *
 * <Sideview Battler Size: WIDTH, HEIGHT>
 * Change the frame sizes.
 *
 * <Sideview Battler Weapon: FLAG>
 * Set weapon showing enable for battler. FLAG can be true or false.
 *
 * <Sideview Battler Motion: NAME, INDEX>
 * Add new motion (pose) for current battler, index is row number (start from
 * zero).
 *
 * <Sideview Battler Motion>
 *   Name: NAME
 *   Index: INDEX
 *   Loop
 *   Frames: X
 *   Speed: Y
 * </Sideview Battler Motion>
 * Add new motion (pose) for current battler.
 * Loop is for looping motion.
 * Frames and Speed is for custom frames and speed from the default ones.
 * Loop, Frames and Speed can be omitted.
 * ============================================================================
 * Notes
 *
 * 1. Frame will be started from 0 (first frame of the pose).
 * 2. All default motions to be setup:
 *    walk      wait    chant   guard   damage
 *    evade     thrust  swing   missile skill
 *    spell     item    escape  victory dying
 *    abnormal  sleep   dead
 * 3. All battlers should have the motion "walk". If any of default motions is
 *    not setup, the "other" motion will be used, "walk" will be used instead
 *    if "other" hasn't been setup.
 * 4. Current version only support animated enemies with Yanfly's Animated
 *    Sideview Enemies. This will be standalone on next version.
 * 5. When using with Yanfly's Animated Sideview Enemies, the sprite width and
 *    height should be set manually instead of 'auto'.
 * ============================================================================
 * Compatible
 *
 * The plugin should be placed under any of other Core script, such as YEP -
 * Core Engine.
 *
 * The plugin should be placed under YEP - Battle Engine Core and YEP -
 * Animated Sideview Enemies if used.
 * ============================================================================
 */

/**
 * @namespace SideviewBattler
 * @memberof YED
 */

var YED = YED || {};

// init SideviewBattler module
YED.SideviewBattler = {};

// Imported
var Imported = Imported || {};
Imported.YED_SideviewBattler = true;

/* globals YED: false */

(function ($SideviewBattler) {
  /**
   * Enum for RegExp, used to notetags
   *
   * @readonly
   * @enum {RegExp}
   * @memberof YED.SideviewBattler
   */
  var Regexp = {
    /**
     * Filename for battler
     */
    FILENAME: /<Sideview Battler:[ ]*(.*)>/i,

    /**
     * Default type of set for battler
     */
    DEFAULT_TYPE: /<Sideview Battler Default>/i,

    /**
     * Default frames
     */
    FRAMES: /<Sideview Battler Frames:[ ]*(\d+)>/i,

    /**
     * Default frames
     */
    SPEED: /<Sideview Battler Speed:[ ]*(\d+)>/i,

    /**
     * Frame sizes
     */
    SIZES: /<Sideview Battler Size:[ ]*(\d+),[ ]*(\d+)>/i,

    /**
     * Enable Weapon
     */
    WEAPON_ENABLE: /<Sideview Battler Weapon:[ ]*(true|false)>/i,

    /**
     * Motions setup
     */
    MOTION_QUICK: /<Sideview Battler Motion:[ ]*(.*),[ ]*(\d+)>/i,

    /**
     * Motions setup
     */
    MOTION_BEGIN: /<Sideview Battler Motion>/i,

    /**
     * Motions setup
     */
    MOTION_END: /<\/Sideview Battler Motion>/i,

    /**
     * Motions setup
     */
    MOTION_NAME: /Name:[ ]*(.*)/i,

    /**
     * Motions setup
     */
    MOTION_INDEX: /Index:[ ]*(\d+)/i,

    /**
     * Motions setup
     */
    MOTION_LOOP: /Loop/i,

    /**
     * Motions setup
     */
    MOTION_FRAMES: /Frames:[ ]*(\d+)/i,

    /**
     * Motions setup
     */
    MOTION_SPEED: /Speed:[ ]*(\d+)/i,
  };

  $SideviewBattler.Regexp = Regexp;
})(YED.SideviewBattler);

/* globals YED: false */

(function ($SideviewBattler) {
  /**
   * Shorten Dependencies
   */
  var Regexp = $SideviewBattler.Regexp;

  /**
   * Contains utility tools for module.
   *
   * @namespace Utils
   * @memberof YED.SideviewBattler
   */
  var Utils = {};

  /**
   * Contains module parsed parameters.
   *
   * @type {Object}
   * @memberOf YED.SideviewBattler.Utils
   */
  Utils.parameters = {};

  /**
   * Process parameters function.
   * Should be called with DataManager as current object.
   *
   * @function processParameters
   * @memberof YED.SideviewBattler.Utils
   */
  Utils.processParameters = function () {
    var parameters = PluginManager.parameters("YED_SideviewBattler"),
      result = Utils.parameters;

    result["Default Frames"] = Number(parameters["Default Frames"] || 0);

    result["Default Speed"] = Number(parameters["Default Speed"] || 0);

    result["Default Frame Width"] = Number(
      parameters["Default Frame Width"] || 0
    );

    result["Default Frame Height"] = Number(
      parameters["Default Frame Height"] || 0
    );

    result["Enable Weapon"] = eval(parameters["Enable Weapon"].toLowerCase());
  };

  /**
   * Process notetag function.
   * Should be called with DataManager as current object.
   *
   * @function processNotetag
   * @memberof YED.SideviewBattler.Utils
   */
  Utils.processNotetags = function () {
    var groups = [$dataActors, $dataEnemies],
      group,
      obj,
      notedata,
      line,
      helpers = {}; // multiline notetag

    for (var j = 0; j < groups.length; j++) {
      group = groups[j];

      for (var i = 1; i < group.length; i++) {
        obj = group[i];
        notedata = obj.note.split(/[\r\n]+/);

        Utils._processProperties.call(this, obj);
        Utils._processMethods.call(this, obj);

        for (var n = 0; n < notedata.length; n++) {
          line = notedata[n];
          Utils._processNotetag.call(this, obj, line, helpers);
        }
      }
    }
  };

  /**
   * Add new properties into object.
   *
   * @function _processProperties
   * @memberof YED.SideviewBattler.Utils
   * @param  {Object} obj Data object
   * @private
   */
  Utils._processProperties = function (obj) {
    obj._sideviewBattler = {
      filename: "",
      default: false,
      frames: Utils.parameters["Default Frames"],
      speed: Utils.parameters["Default Speed"],
      weapon: Utils.parameters["Enable Weapon"],
      sizes: [
        Utils.parameters["Default Frame Width"],
        Utils.parameters["Default Frame Height"],
      ],
      motions: {},
    };
  };

  /**
   * Add new methods into object.
   *
   * @function _processMethods
   * @memberof YED.SideviewBattler.Utils
   * @param  {Object} obj Data object
   * @private
   */
  Utils._processMethods = function (obj) {
    obj.getSideviewBattler = Utils.getSideviewBattler;
    obj.isSideviewBattler = Utils.isSideviewBattler;
  };

  /**
   * Process notetag for object.
   *
   * @function _processNotetag
   * @memberof YED.SideviewBattler.Utils
   * @param  {Object} obj Data object
   * @param  {String} notetag Notetag
   * @private
   */
  Utils._processNotetag = function (obj, notetag, helpers) {
    var sideviewBattler = obj._sideviewBattler,
      match,
      motion;

    match = notetag.match(Regexp.FILENAME);
    if (match) {
      sideviewBattler.filename = String(match[1]);
    }

    match = notetag.match(Regexp.DEFAULT_TYPE);
    if (match) {
      sideviewBattler.default = true;
    }

    match = notetag.match(Regexp.FRAMES);
    if (match) {
      sideviewBattler.frames = Number(match[1]);
    }

    match = notetag.match(Regexp.SPEED);
    if (match) {
      sideviewBattler.speed = Number(match[1]);
    }

    match = notetag.match(Regexp.SIZES);
    if (match) {
      sideviewBattler.sizes[0] = Number(match[1]);
      sideviewBattler.sizes[1] = Number(match[2]);
    }

    match = notetag.match(Regexp.WEAPON_ENABLE);
    if (match) {
      sideviewBattler.weapon = eval(match[1].toLowerCase());
    }

    match = notetag.match(Regexp.MOTION_QUICK);
    if (match) {
      motion = {};

      motion.name = match[1].toLowerCase();
      motion.index = Number(match[2]);

      sideviewBattler.motions[motion.name] = motion;
    }

    match = notetag.match(Regexp.MOTION_BEGIN);
    if (match) {
      helpers.motionFlag = true;
      helpers.motion = {};
      return;
    }

    match = notetag.match(Regexp.MOTION_END);
    if (match) {
      motion = helpers.motion;

      helpers.motionFlag = false;
      sideviewBattler.motions[motion.name] = motion;
      return;
    }

    if (helpers.motionFlag) {
      motion = helpers.motion;

      match = notetag.match(Regexp.MOTION_NAME);
      if (match) {
        motion.name = match[1].toLowerCase();
      }

      match = notetag.match(Regexp.MOTION_INDEX);
      if (match) {
        motion.index = Number(match[1]);
      }

      match = notetag.match(Regexp.MOTION_LOOP);
      if (match) {
        motion.loop = true;
      }

      match = notetag.match(Regexp.MOTION_FRAMES);
      if (match) {
        motion.frames = Number(match[1]);
      }

      match = notetag.match(Regexp.MOTION_SPEED);
      if (match) {
        motion.speed = Number(match[1]);
      }
    }
  };

  /**
   * Get sideview battler infos.
   * Should be attached to actor/enemy object.
   *
   * @function getSideviewBattler
   * @memberof YED.SideviewBattler.Utils
   * @return {Object}
   */
  Utils.getSideviewBattler = function () {
    return this._sideviewBattler;
  };

  /**
   * Check if is sideview battler.
   * Should be attached to actor/enemy object.
   *
   * @function getSideviewBattler
   * @memberof YED.SideviewBattler.Utils
   * @return {Object}
   */
  Utils.isSideviewBattler = function () {
    return (
      this._sideviewBattler.filename !== "" && !this._sideviewBattler.default
    );
  };

  $SideviewBattler.Utils = Utils;
})(YED.SideviewBattler);

/* globals YED: false */

/**
 * Pre-processes and notetag parsing
 */
(function ($SideviewBattler) {
  /**
   * Shorten Dependencies
   */
  var Utils = $SideviewBattler.Utils;

  /**
   * Aliasing methods
   */
  var _DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;

  /**
   * Extending: DataManager.isDatabaseLoaded
   *
   * Add notetags and parameters processing for module.
   */
  DataManager.isDatabaseLoaded = function () {
    var loaded = _DataManager_isDatabaseLoaded.call(this);

    if (!loaded) {
      return false;
    }

    Utils.processParameters.call(DataManager);
    Utils.processNotetags.call(DataManager);

    return true;
  };
})(YED.SideviewBattler);

(function () {
  Game_Battler.prototype.getBattler = function () {
    var battler;

    if (this.isActor()) {
      battler = this.actor();
    }

    if (this.isEnemy()) {
      battler = this.enemy();
    }

    return !!battler ? battler : null;
  };

  Game_Battler.prototype.getSideviewBattler = function () {
    var battler = this.getBattler();

    return !!battler ? battler.getSideviewBattler() : null;
  };

  Game_Battler.prototype.isSideviewBattler = function () {
    var battler = this.getBattler();

    return !!battler ? battler.isSideviewBattler() : false;
  };

  Game_Battler.prototype.isUseWeapon = function () {
    var sideviewBattler = this.getSideviewBattler();

    if (!this.isSideviewBattler()) {
      return true;
    }

    return sideviewBattler.weapon;
  };

  Game_Battler.prototype.getSideviewFilename = function () {
    var sideviewBattler = this.getSideviewBattler();

    if (!this.isSideviewBattler()) {
      return null;
    }

    return sideviewBattler.filename;
  };

  Game_Battler.prototype.getSideviewSizes = function () {
    var sideviewBattler = this.getSideviewBattler();

    if (!this.isSideviewBattler()) {
      return null;
    }

    return sideviewBattler.sizes;
  };

  Game_Battler.prototype.getSideviewMotions = function () {
    var sideviewBattler = this.getSideviewBattler();

    if (!this.isSideviewBattler()) {
      return null;
    }

    return sideviewBattler.motions;
  };

  Game_Battler.prototype.getFallbackMotion = function () {
    var motions = this.getSideviewMotions();

    if (!this.isSideviewBattler()) {
      return null;
    }

    if (!!motions.other) {
      return motions.other;
    }

    return motions.walk;
  };

  Game_Battler.prototype.getSideviewMotion = function (motionName) {
    var motions = this.getSideviewMotions();

    if (!motionName) {
      return null;
    }

    if (!this.isSideviewBattler()) {
      return null;
    }

    if (!motions[motionName]) {
      return this.getFallbackMotion();
    }

    return motions[motionName];
  };

  Game_Battler.prototype.getSideviewFrames = function (motionName) {
    var sideviewBattler = this.getSideviewBattler(),
      motion = this.getSideviewMotion(motionName);

    if (!this.isSideviewBattler()) {
      return null;
    }

    if (!!motion && !!motion.frames) {
      return motion.frames;
    }

    return sideviewBattler.frames;
  };

  Game_Battler.prototype.getSideviewSpeed = function (motionName) {
    var sideviewBattler = this.getSideviewBattler(),
      motion = this.getSideviewMotion(motionName);

    if (!this.isSideviewBattler()) {
      return null;
    }

    if (!!motion && !!motion.speed) {
      return motion.speed;
    }

    return sideviewBattler.speed;
  };
})();

(function () {
  /**
   * Aliasing methods
   */
  var _Game_Actor_battlerName = Game_Actor.prototype.battlerName;

  Game_Actor.prototype.battlerName = function () {
    if (this.isSideviewBattler()) {
      return this.getSideviewFilename();
    }

    return _Game_Actor_battlerName.call(this);
  };
})();

(function () {
  /**
   * Aliasing methods
   */
  var _Game_Enemy_battlerName = Game_Enemy.prototype.battlerName;

  Game_Enemy.prototype.battlerName = function () {
    if (this.isSideviewBattler()) {
      return this.getSideviewFilename();
    }

    return _Game_Enemy_battlerName.call(this);
  };
})();

(function () {
  /**
   * Aliasing methods
   */
  var _Sprite_Actor_initMembers = Sprite_Actor.prototype.initMembers;
  var _Sprite_Actor_setupWeaponAnimation =
    Sprite_Actor.prototype.setupWeaponAnimation;
  var _Sprite_Actor_startMotion = Sprite_Actor.prototype.startMotion;
  var _Sprite_Actor_forceMotion = Sprite_Actor.prototype.forceMotion;
  var _Sprite_Actor_motionSpeed = Sprite_Actor.prototype.motionSpeed;
  var _Sprite_Actor_updateFrame = Sprite_Actor.prototype.updateFrame;
  var _Sprite_Actor_updateMotionCount =
    Sprite_Actor.prototype.updateMotionCount;

  Sprite_Actor.prototype.initMembers = function () {
    _Sprite_Actor_initMembers.call(this);

    this._motionName = "";
  };

  Sprite_Actor.prototype.setupWeaponAnimation = function () {
    if (this._actor.isUseWeapon()) {
      _Sprite_Actor_setupWeaponAnimation.call(this);
      return;
    }

    this._actor.clearWeaponAnimation();
  };

  Sprite_Actor.prototype.startMotion = function (motionType) {
    if (this._actor.isSideviewBattler()) {
      this.startSideviewMotion(motionType);
      return;
    }

    _Sprite_Actor_startMotion.call(this, motionType);
  };

  Sprite_Actor.prototype.forceMotion = function (motionType) {
    if (this._actor.isSideviewBattler()) {
      this.forceSideviewMotion(motionType);
      return;
    }

    _Sprite_Actor_forceMotion.call(this, motionType);
  };

  Sprite_Actor.prototype.startSideviewMotion = function (motionType) {
    if (this._motionName !== motionType) {
      this._motionName = motionType;
      this._motionCount = 0;
      this._pattern = 0;
    }
  };

  Sprite_Actor.prototype.forceSideviewMotion = function (motionType) {
    this._motionName = motionType;
    this._motionCount = 0;
    this._pattern = 0;
  };

  Sprite_Actor.prototype.getCurrentMotion = function () {
    return this._actor.getSideviewMotion(this._motionName);
  };

  Sprite_Actor.prototype.frameSizes = function () {
    return this._actor.getSideviewSizes();
  };

  Sprite_Actor.prototype.motionFrames = function () {
    var motionName = this._motionName;

    if (this._actor.isSideviewBattler()) {
      return this._actor.getSideviewFrames(motionName);
    }

    return 3;
  };

  Sprite_Actor.prototype.motionSpeed = function () {
    var motionName = this._motionName;

    if (this._actor.isSideviewBattler()) {
      return this._actor.getSideviewSpeed(motionName);
    }

    return _Sprite_Actor_motionSpeed.call(this);
  };

  Sprite_Actor.prototype.updateFrame = function () {
    if (this._actor.isSideviewBattler()) {
      this.updateSideviewFrame();
      return;
    }

    _Sprite_Actor_updateFrame.call(this);
  };

  Sprite_Actor.prototype.updateSideviewFrame = function () {
    var bitmap = this._mainSprite.bitmap,
      motion = this.getCurrentMotion(),
      frameSizes = this.frameSizes();

    Sprite_Battler.prototype.updateFrame.call(this);

    if (bitmap) {
      var motionIndex = motion.index;
      var pattern = this._pattern;
      var cw = frameSizes[0];
      var ch = frameSizes[1];
      var cx = pattern;
      var cy = motionIndex;
      this._mainSprite.setFrame(cx * cw, cy * ch, cw, ch);
    }
  };

  Sprite_Actor.prototype.updateMotionCount = function () {
    if (this._actor.isSideviewBattler()) {
      this.updateSideviewMotionCount();
      return;
    }

    _Sprite_Actor_updateMotionCount.call(this);
  };

  Sprite_Actor.prototype.updateSideviewMotionCount = function () {
    var motion = this.getCurrentMotion(),
      speed = this.motionSpeed(),
      frames = this.motionFrames();

    if (!!motion && ++this._motionCount >= speed) {
      if (!!motion.loop) {
        this._pattern = (this._pattern + 1) % frames;
      } else if (this._pattern < frames - 1) {
        this._pattern++;
      } else {
        this.refreshMotion();
      }
      this._motionCount = 0;
    }
  };
})();

(function () {
  if (!Imported.YEP_X_AnimatedSVEnemies) {
    return;
  }
  /**
   * Aliasing methods
   */
  var _Sprite_Enemy_initMembers = Sprite_Enemy.prototype.initMembers;
  var _Sprite_Enemy_setupWeaponAnimation =
    Sprite_Enemy.prototype.setupWeaponAnimation;
  var _Sprite_Enemy_startMotion = Sprite_Enemy.prototype.startMotion;
  var _Sprite_Enemy_forceMotion = Sprite_Enemy.prototype.forceMotion;
  var _Sprite_Enemy_updateFrame = Sprite_Enemy.prototype.updateFrame;
  var _Sprite_Enemy_updateMotionCount =
    Sprite_Enemy.prototype.updateMotionCount;

  Sprite_Enemy.prototype.initMembers = function () {
    _Sprite_Enemy_initMembers.call(this);

    this._motionName = "";
  };

  Sprite_Enemy.prototype.setupWeaponAnimation = function () {
    if (this._enemy.isUseWeapon()) {
      _Sprite_Enemy_setupWeaponAnimation.call(this);
      return;
    }

    this._enemy.clearWeaponAnimation();
  };

  Sprite_Enemy.prototype.startMotion = function (motionType) {
    if (this._enemy.isSideviewBattler()) {
      this.startSideviewMotion(motionType);
      return;
    }

    _Sprite_Enemy_startMotion.call(this, motionType);
  };

  Sprite_Enemy.prototype.forceMotion = function (motionType) {
    if (this._enemy.isSideviewBattler()) {
      this.forceSideviewMotion(motionType);
      return;
    }

    _Sprite_Enemy_forceMotion.call(this, motionType);
  };

  Sprite_Enemy.prototype.startSideviewMotion = function (motionType) {
    if (this._motionName !== motionType) {
      this._motionName = motionType;
      this._motionCount = 0;
      this._pattern = 0;
    }
  };

  Sprite_Enemy.prototype.forceSideviewMotion = function (motionType) {
    this._motionName = motionType;
    this._motionCount = 0;
    this._pattern = 0;
  };

  Sprite_Enemy.prototype.getCurrentMotion = function () {
    return this._enemy.getSideviewMotion(this._motionName);
  };

  Sprite_Enemy.prototype.frameSizes = function () {
    return this._enemy.getSideviewSizes();
  };

  Sprite_Enemy.prototype.motionFrames = function () {
    var motionName = this._motionName;

    if (this._enemy.isSideviewBattler()) {
      return this._enemy.getSideviewFrames(motionName);
    }

    return 3;
  };

  Sprite_Enemy.prototype.motionSpeed = function () {
    var motionName = this._motionName;

    if (this._enemy.isSideviewBattler()) {
      return this._enemy.getSideviewSpeed(motionName);
    }

    return 12;
  };

  Sprite_Enemy.prototype.updateMotionCount = function () {
    if (this._enemy.isSideviewBattler()) {
      this.updateSideviewMotionCount();
      return;
    }

    _Sprite_Enemy_updateMotionCount.call(this);
  };

  Sprite_Enemy.prototype.updateSideviewMotionCount = function () {
    var motion = this.getCurrentMotion(),
      speed = this.motionSpeed(),
      frames = this.motionFrames();

    if (!!motion && ++this._motionCount >= speed) {
      if (!!motion.loop) {
        this._pattern = (this._pattern + 1) % frames;
      } else if (this._pattern < frames - 1) {
        this._pattern++;
      } else {
        this.refreshMotion();
      }
      this._motionCount = 0;
    }
  };

  Sprite_Enemy.prototype.updateFrame = function () {
    if (this._enemy.isSideviewBattler()) {
      if (Imported.YEP_X_AnimatedSVEnemies) {
        this.updateSideviewFrame();
        return;
      }

      this.updateSideviewFrame();
      return;
    }

    _Sprite_Enemy_updateFrame.call(this);
  };

  // compatible with YEP - Animated Sideview Enemies
  Sprite_Enemy.prototype.updateSideviewFrame = function () {
    var bitmap = this._mainSprite.bitmap,
      motion = this.getCurrentMotion(),
      frameSizes = this.frameSizes();

    Sprite_Battler.prototype.updateFrame.call(this);

    if (bitmap.width <= 0) {
      return;
    }

    this._effectTarget = this._mainSprite;

    var motionIndex = motion.index;
    var pattern = this._pattern;
    var cw = frameSizes[0];
    var ch = frameSizes[1];
    var cx = pattern;
    var cy = motionIndex;
    var cdh = 0;

    if (this._effectType === "bossCollapse") {
      cdh = ch - this._effectDuration;
    }

    this.setFrame(cx * cw, cy * ch, cw, ch);
    this._mainSprite.setFrame(cx * cw, cy * ch, cw, ch - cdh);
    this.adjustMainBitmapSettings(bitmap);
    this.adjustSVShadowSettings();
  };
})();


code:
/*:
 * Yami Engine Delta - Single State
 *
 * @plugindesc v1.0.0 This plugin restricts battlers to be affected by only one state.
 * @author Yami Engine Delta [Dr.Yami]
 *
 * @param Replace State
 * @desc Allows replacing old state with the new one.
 * @default false
 *
 * @help
 * States Notetags
 *
 * To make state an exception, which can be added when battler has a state.
 *   <Not Single State>
 */

/**
 * @namespace SingleState
 * @memberof YED
 */

var YED = YED || {};

// init SingleState module
YED.SingleState = {};

/* globals YED: false */

(function ($SingleState) {
  /**
   * Enum for RegExp, used to notetags
   *
   * @readonly
   * @enum {RegExp}
   * @memberof YED.SingleState
   */
  var Regexp = {
    /**
     * Makes state not single ~
     */
    NOT_SINGLE: /<(?:not single state)>/i,
  };

  $SingleState.Regexp = Regexp;
})(YED.SingleState);

/* globals YED: false */

(function ($SingleState) {
  /**
   * Shorten Dependencies
   */
  var Regexp = $SingleState.Regexp;

  /**
   * Contains utility tools for module.
   *
   * @namespace Utils
   * @memberof YED.SingleState
   */
  var Utils = {};

  /**
   * Contains module parsed parameters.
   *
   * @type {Object}
   * @memberOf  YED.SingleState.Utils
   */
  Utils.parameters = {};

  /**
   * Process parameters function.
   * Should be called with DataManager as current object.
   *
   * @function processParameters
   * @memberof YED.SingleState.Utils
   */
  Utils.processParameters = function () {
    var parameters = PluginManager.parameters("YED_SingleState"),
      result = Utils.parameters;

    result["Replace State"] = eval(parameters["Replace State"].toLowerCase());
  };

  /**
   * Process notetag function.
   * Should be called with DataManager as current object.
   *
   * @function processNotetag
   * @memberof YED.SingleState.Utils
   */
  Utils.processNotetags = function () {
    var group = $dataStates, // shorten group name
      obj,
      notedata,
      line;

    for (var i = 1; i < group.length; i++) {
      obj = group[i];
      notedata = obj.note.split(/[\r\n]+/);

      Utils._processProperties.call(this, obj);
      Utils._processMethods.call(this, obj);

      for (var n = 0; n < notedata.length; n++) {
        line = notedata[n];
        Utils._processNotetag.call(this, obj, line);
      }
    }
  };

  /**
   * Add new properties into object.
   *
   * @function _processProperties
   * @memberof YED.SingleState.Utils
   * @param  {Object} obj Data object
   * @private
   */
  Utils._processProperties = function (obj) {
    obj._notSingleState = false;
  };

  /**
   * Add new methods into object.
   *
   * @function _processMethods
   * @memberof YED.SingleState.Utils
   * @param  {Object} obj Data object
   * @private
   */
  Utils._processMethods = function (obj) {
    obj.getNotSingleState = Utils.getNotSingleState;
  };

  /**
   * Process notetag for object.
   *
   * @function _processNotetag
   * @memberof YED.SingleState.Utils
   * @param  {Object} obj Data object
   * @param  {String} notetag Notetag
   * @private
   */
  Utils._processNotetag = function (obj, notetag) {
    var match;

    match = notetag.match(Regexp.NOT_SINGLE);
    if (match) {
      obj._notSingleState = true;
    }
  };

  /**
   * Get not single state flag.
   *
   * @function getNotSingleState
   * @memberof YED.SingleState.Utils
   * @return {Boolean} Single State?!
   */
  Utils.getNotSingleState = function () {
    return !!this._notSingleState;
  };

  $SingleState.Utils = Utils;
})(YED.SingleState);

/* globals YED: false */

/**
 * Pre-processes and notetag parsing
 */
(function ($SingleState) {
  /**
   * Shorten Dependencies
   */
  var Utils = $SingleState.Utils;

  /**
   * Aliasing methods
   */
  var _DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;

  /**
   * Extending: DataManager.isDatabaseLoaded
   *
   * Add notetags and parameters processing for module.
   */
  DataManager.isDatabaseLoaded = function () {
    var loaded = _DataManager_isDatabaseLoaded.call(this);

    if (!loaded) {
      return false;
    }

    Utils.processParameters.call(DataManager);
    Utils.processNotetags.call(DataManager);

    return true;
  };
})(YED.SingleState);

/* globals YED: false */

(function ($SingleState) {
  /**
   * Shorten Dependencies
   */
  var Utils = $SingleState.Utils;

  /**
   * Aliasing methods
   */
  var _Game_Battler_addState = Game_Battler.prototype.addState;
  var _Game_Battler_isStateAddable = Game_Battler.prototype.isStateAddable;

  Game_Battler.prototype.addState = function (stateId) {
    var replace = Utils.parameters["Replace State"],
      dead = this.isDead(),
      addable = this.isStateAddable(stateId),
      notSingle = $dataStates[stateId].getNotSingleState();

    if (!dead && addable && replace && !notSingle) {
      for (var i = 0; i < this.states().length; i++) {
        if (this.states()[i].getNotSingleState()) {
          continue;
        }

        this.eraseState(this.states()[i].id);
        this.refresh();
      }
    }

    _Game_Battler_addState.call(this, stateId);
  };

  Game_Battler.prototype.isStateAddable = function (stateId) {
    var result = _Game_Battler_isStateAddable.call(this, stateId),
      single = true;

    if (!Utils.parameters["Replace State"]) {
      single =
        !this.states().some(function (state) {
          return !state.getNotSingleState();
        }) || this.states().length === 0;
      single = single || $dataStates[stateId].getNotSingleState();
    }

    result = result && single;

    return result;
  };
})(YED.SingleState);

repo_name: dazed/translations

license: unknown


code:
/*:
 * Yami Engine Delta - Tilemap
 *
 * @plugindesc v1.1.3 Implementation for Tiled Map Editor.
 * @author Yami Engine Delta [Dr.Yami]
 *
 * @help This plugin is to use TileD generated maps for your RPG Maker MV games!
 * Follow the instructions to use it:
 *
 * 1. Create a New Folder named **maps** (without asterisks) inside game project's root folder.
 * 2. Create a new map in TileD. The settings must be CSV and Orthogonal. The Tile size you set will be the grid in the game!
 * When loading your images, make sure to reference them all in the game's **img/tilesets** folder.
 * 3. Export as json file and make sure that the filename is Map*ID*.json. ID being the map's index as seen in the editor.
 * 4. Put all json files from Tiled into the **maps** folder.
 * 5. Put all tilesets into the game's **img/tilesets** This is a reminder!
 * 6. Put `<position: X, Y>` into an event comment box for positioning.
 * 7. For upper layer (layer that ABOVE player), add *Custom Properties* (in Tiled) `layer` with value `upper`
 * 8. For lower layer (layer that BELOW player), no need to add anything
 * 9. For collision: any Tile Layer with *Custom Properties* (in Tiled) `collision` with value `true` has collision.
 * Which mean any tile that is not empty in that Layer will have collision. You can turn off Visible for Collision Layer if you want.
 * 10. For Region ID: any Tile Layer with *Custom Properties* (in Tiled) `regionId` with value is number will make any tile that is not empty has a region ID of entered number.
 * You can turn off Visible for Region Layer if you want.
 * 11. Images for Image Layers should be put in **img/parallaxes**
 * 12. For parallax: add *Custom Properties* (in Tiled) `parallax` with value `true` to Image Layer. Add *Custom Properties* `planeX` and `planeY` for parallax moving.
 * 13. For arrow passable: add *Custom Properties* (in Tiled) `arrowImpassable` with value `up` `down` `left` or `right` to Tile Layer. Any tile that is not empty on that
 * layer will make the *direction* based on `arrowImpassable` value impassable.
 *
 */
/*:ja
 * Yami Engine Delta - Tilemap
 *
 * @plugindesc v1.1.3 デフォルトのエディタの代わりに、TileDをマップエディタとして使うことができます。
 * @author Yami Engine Delta [Dr.Yami]
 *
 * @help デフォルトのエディタの代わりに、TileDをマップエディタとして使うことができます。
 * 使用方法は以下の通りです。
 *
 * 1. ゲームのプロジェクト直下のサブフォルダ内に "maps" という名前の新しいフォ
 * ルダを作成してください。
 * 2. TileD内で新規マップを作成します。セッティングはCSVとOrthogonalに設定して
 * ください。設定したタイルサイズが、ゲーム内のグリッドとなります。
 * イメージをロードする際には、参照先が必ず "img/tilesets" になるようにして
 * ください。
 * 3. ファイルをJSON形式でエクスポートし、ファイル名は 「Map*ID*.json」となる
 * ようにしてください。(任意のIDを入れる) ここのIDは、エディタ内ではマップの
 * インデックスとして表示されます。"00"は使わないようにしてください。
 * 4. TileDから全てのJSONファイルを、 "maps" のフォルダに入れてください。
 * 5. 全てのタイルセットがゲームの "img/tilesets" に入っているか今一度確認して
 * ください。
 * 6. `<position: X, Y>` という文字列をイベントコマンドボックスに挿入し、位置
 * を指定します。
 * 7. 上層(プレイヤーより上)のレイヤーに対しては、"Custom Properties" で、
 * `layer` を `upper` という値で指定してください。
 * 8. 下層(プレイヤーより下)のレイヤーに対しては、何か追加する必要はありません。
 * 9. コリジョンについて："Custom Properties" を持つタイルレイヤーで、
 * `collision` の値が `true` である場合には、コリジョンを持ちます。
 * つまり、レイヤーの中身が空ではない全てのタイルが、コリジョンを持つという
 * ことになります。コリジョンレイヤーを見えなくすることもできます。
 * 10. リージョンIDについて: "Custom Properties" を持つタイルレイヤーで、
 * `regionId` に値が入っている場合には、値が空ではない全てのタイルにその数値が
 * 与えられます。リージョンレイヤーを見えなくすることもできます。
 * 11. イメージレイヤーに使われる画像については、"img/parallaxes" に格納して
 * ください。
 * 12. パララックスについて：TileD内の *Custom Properties* で、 `parallax` の
 * 値を `true` で指定してください。*Custom Properties* で `planeX` と `planeY`
 * を指定して、パララックスの動きを指定します。
 * 13. 進行可能方向について：TileD内の *Custom Properties* で、
 * `arrowImpassable` の値を `up` `down` `left` `right` で指定してください。
 * そのレイヤー上の値が空ではない全てのタイルは、`arrowImpassable`の値に基づい
 * て、進行不可になります。
 *
 */

/**
 * @namespace Tilemap
 * @memberof YED
 */

var YED = YED || {};

// init Tilemap module
YED.Tilemap = {};

(function () {
  ImageManager.loadParserTileset = function (path, hue) {
    var paths = path.split("/"),
      filename = paths[paths.length - 1],
      realPath = "img/tilesets/" + filename;

    return this.loadNormalBitmap(realPath, hue);
  };

  ImageManager.loadParserParallax = function (path, hue) {
    var paths = path.split("/"),
      filename = paths[paths.length - 1],
      realPath = "img/parallaxes/" + filename;

    return this.loadNormalBitmap(realPath, hue);
  };
})();

/* globals YED: false */

(function () {
  /**
   * The Data object is created by {@link YED.Tilemap.Core} to load and
   * contain tilemap data from json file
   *
   * To make sure the scene is ready, loading method should be called
   * manually:
   *
   * ```js
   * var data = new YED.Tilemap.Data();
   * data.loadMapFile();
   * ```
   *
   * @class
   * @memberof YED.Tilemap
   */
  var Data = function (data) {
    this._loadListeners = [];
    this._isExist = false;
    this._collision = []; // collision matrix
    this._region = []; // region matrix
    this._arrows = []; // arrow matrix
    this.data = data;
  };

  Object.defineProperties(Data.prototype, {
    /**
     * Tilemap data, the Data object will load tilemap data into this member
     *
     * @member {Object}
     * @memberof YED.Tilemap.Data#
     */
    data: {
      get: function () {
        return this._data || null;
      },

      set: function (data) {
        this._data = data;
        this._setupData();
      },
    },

    /**
     * Tilemap height, will be number of vertical grids
     *
     * @member {number}
     * @memberof YED.Tilemap.Data#
     * @readonly
     */
    height: {
      get: function () {
        return this.data.height;
      },
    },

    /**
     * Tilemap width, will be number of horizontal grids
     *
     * @member {number}
     * @memberof YED.Tilemap.Data#
     * @readonly
     */
    width: {
      get: function () {
        return this.data.width;
      },
    },

    /**
     * Tile height, will be height of each tile
     *
     * @member {number}
     * @memberof YED.Tilemap.Data#
     * @readonly
     */
    tileHeight: {
      get: function () {
        return this.data.tileheight;
      },
    },

    /**
     * Tile width, will be width of each tile
     *
     * @member {number}
     * @memberof YED.Tilemap.Data#
     * @readonly
     */
    tileWidth: {
      get: function () {
        return this.data.tilewidth;
      },
    },

    /**
     * Tilemap custom properties
     *
     * @member {Object}
     * @memberof YED.Tilemap.Data#
     * @readonly
     */
    properties: {
      get: function () {
        return this.data.properties;
      },
    },

    /**
     * Tilemap layers data
     *
     * @member {Object[]}
     * @memberof YED.Tilemap.Data#
     * @readonly
     */
    layers: {
      get: function () {
        return this.data.layers;
      },
    },

    /**
     * Tilemap tilesets data
     *
     * @member {Object[]}
     * @memberof YED.Tilemap.Data#
     * @readonly
     */
    tilesets: {
      get: function () {
        return this.data.tilesets;
      },
    },

    collision: {
      get: function () {
        return this._collision;
      },
    },

    region: {
      get: function () {
        return this._region;
      },
    },

    arrows: {
      get: function () {
        return this._arrows;
      },
    },
  });

  /**
   * Setup things after loaded data
   *
   * @private
   */
  Data.prototype._setupData = function () {
    if (!!this.data) {
      this._setupCollision();
      this._setupArrows();
      this._setupRegions();
      this._loadTilesets();
    }
  };

  Data.prototype._setupCollision = function () {
    var collisionLayers = this._getCollisionLayers(),
      i,
      j,
      layer;

    for (i = 0; i < this.width * this.height; i++) {
      this.collision[i] = 0;
    }

    for (i = 0; i < collisionLayers.length; i++) {
      layer = collisionLayers[i];

      if (!layer.data) {
        continue;
      }

      for (j = 0; j < layer.data.length; j++) {
        if (layer.data[j] > 0) {
          this.collision[j] = 1;
        }
      }
    }
  };

  Data.prototype._setupRegions = function () {
    var regionLayers = this._getRegionsLayers(),
      i,
      j,
      layer;

    for (i = 0; i < this.width * this.height; i++) {
      this.region[i] = 0;
    }

    for (i = 0; i < regionLayers.length; i++) {
      layer = regionLayers[i];

      if (!layer.data) {
        continue;
      }

      for (j = 0; j < layer.data.length; j++) {
        if (layer.data[j] > 0) {
          this.region[j] = parseInt(layer.properties.regionId);
        }
      }
    }
  };

  Data.prototype._setupArrows = function () {
    var arrowLayers = this._getArrowLayers(),
      i,
      j,
      layer,
      bit;

    for (i = 0; i < this.width * this.height; i++) {
      this.arrows[i] = 1 | 2 | 4 | 8;
    }

    for (i = 0; i < arrowLayers.length; i++) {
      layer = arrowLayers[i];

      if (!layer.data) {
        continue;
      }

      if (layer.properties.arrowImpassable === "left") {
        bit = 1;
      }

      if (layer.properties.arrowImpassable === "up") {
        bit = 2;
      }

      if (layer.properties.arrowImpassable === "right") {
        bit = 4;
      }

      if (layer.properties.arrowImpassable === "down") {
        bit = 8;
      }

      for (j = 0; j < layer.data.length; j++) {
        if (layer.data[j] > 0) {
          this.arrows[j] = this.arrows[j] ^ bit;
        }
      }
    }
  };

  Data.prototype._loadTilesets = function () {
    var tilesetsData = this.tilesets,
      i = 0,
      length = tilesetsData.length,
      data;

    for (; i < length; i++) {
      data = tilesetsData[i];
      ImageManager.loadParserTileset(data.image, 0);
    }
  };

  Data.prototype._getCollisionLayers = function () {
    return this.layers.filter(function (layer) {
      return !!layer.properties && !!layer.properties.collision;
    });
  };

  Data.prototype._getRegionsLayers = function () {
    return this.layers.filter(function (layer) {
      return !!layer.properties && !!layer.properties.regionId;
    });
  };

  Data.prototype._getArrowLayers = function () {
    return this.layers.filter(function (layer) {
      return !!layer.properties && !!layer.properties.arrowImpassable;
    });
  };

  Data.prototype.getImageLayers = function () {
    return this.layers.filter(function (layer) {
      return layer.type === "imagelayer";
    });
  };

  /**
   * Check if the data is finished loading
   *
   * @return {Boolean} Ready flag
   */
  Data.prototype.isReady = function () {
    return !!this.data; // hack boolean
  };

  /**
   * Check if map data exists
   *
   * @return {Boolean} Exist flag
   */
  Data.prototype.isExist = function () {
    return this._isExist;
  };

  YED.Tilemap.Data = Data;
})();

/* globals YED: false */

(function () {
  /**
   * The Tileset objects are created by {@link YED.Tilemap.Core Tilemap.Core} to load
   * tileset textures and return tile blocks when needed
   *
   * A Tileset object is created with a tileset data gets from {@link YED.Tilemap.Data#tilesets Tilemap.Data#tilesets},
   * for example:
   *
   * ```js
   * var tilesetData = data.tilesets[0];
   * var tileset = new YED.Tilemap.Tileset(tilesetData);
   * ```
   * @class
   * @memberof YED.Tilemap
   * @param {Object} data A Tileset data gets from {@link YED.Tilemap.Data#tilesets Tilemap.Data#tilesets}
   */
  var Tileset = function (data) {
    this.data = data;
  };

  Object.defineProperties(Tileset.prototype, {
    /**
     * Tileset data get from tilemap data
     *
     * @member {Object}
     * @memberof YED.Tilemap.Tileset#
     */
    data: {
      get: function () {
        return this._data || null;
      },

      set: function (data) {
        this._data = data;
        this._setupData();
      },
    },

    /**
     * ID of the first tile in tileset
     *
     * @member {number}
     * @memberof YED.Tilemap.Tileset#
     * @readonly
     */
    firstId: {
      get: function () {
        return this.data.firstgid;
      },
    },

    /**
     * Tileset bitmap, use Bitmap object of RMMV framework
     *
     * @member {Bitmap}
     * @memberof YED.Tilemap.Tileset#
     */
    bitmap: {
      get: function () {
        return this._bitmap || null;
      },

      set: function (bitmap) {
        this._bitmap = bitmap || null;
      },
    },

    /**
     * Tileset bitmap height
     *
     * @member {number}
     * @memberof YED.Tilemap.Tileset#
     * @readonly
     */
    imageHeight: {
      get: function () {
        return this.data.imageheight;
      },
    },

    /**
     * Tileset bitmap width
     *
     * @member {number}
     * @memberof YED.Tilemap.Tileset#
     * @readonly
     */
    imageWidth: {
      get: function () {
        return this.data.imagewidth;
      },
    },

    /**
     * @member {number}
     * @memberof YED.Tilemap.Tileset#
     * @readonly
     */
    tileHeight: {
      get: function () {
        return this.data.tileheight;
      },
    },

    /**
     * @member {number}
     * @memberof YED.Tilemap.Tileset#
     * @readonly
     */
    tileWidth: {
      get: function () {
        return this.data.tilewidth || 0;
      },
    },
  });

  /**
   * Setup things after loaded data
   *
   * @private
   */
  Tileset.prototype._setupData = function () {
    if (!!this.data) {
      this.bitmap = ImageManager.loadParserTileset(this.data.image, 0);
    }
  };

  /**
   * Get number of tiles in each line of tileset
   *
   * @return {number} Tiles count
   * @private
   */
  Tileset.prototype._countTilesHorizontal = function () {
    return Math.floor(this.imageWidth / this.tileWidth);
  };

  /**
   * Get number of tiles in each column of tileset
   *
   * @return {number} Tiles count
   * @private
   */
  Tileset.prototype._countTilesVertical = function () {
    return Math.floor(this.imageHeight / this.tileHeight);
  };

  /**
   * Get total tiles in tileset
   *
   * @return {number} Tiles count
   */
  Tileset.prototype.getTotalTiles = function () {
    return this._countTilesHorizontal() * this._countTilesVertical();
  };

  /**
   * Get grid position of tile, take tile ID as param
   *
   * @param  {number} id Tile ID in layer data
   * @return {Object} Object contains {x,y}
   * @private
   */
  Tileset.prototype._getTilePosition = function (id) {
    var realId = id - this.firstId,
      result = { x: 0, y: 0 },
      tileX = realId % this._countTilesHorizontal(),
      tileY = Math.floor(realId / this._countTilesHorizontal());

    result.x = tileX;
    result.y = tileY;

    return result;
  };

  /**
   * Get tile block rectangle, take tile ID as param
   *
   * @param  {number} id Tile ID in layer data
   * @return {Object} Object contains {x,y,width,height}
   * @private
   */
  Tileset.prototype._getTileBlock = function (id) {
    var pos = this._getTilePosition(id);
    var result = { x: 0, y: 0, width: 0, height: 0 };

    result.x = pos.x * this.tileWidth;
    result.y = pos.y * this.tileHeight;
    result.width = this.tileWidth;
    result.height = this.tileHeight;

    return result;
  };

  /**
   * Get parameters for bitmap block transfer function
   *
   * @param  {number} id Tile ID in layer data
   * @param  {number} x Destination X
   * @param  {number} y Destination Y
   * @return {number[]} Array parameters
   */
  Tileset.prototype.getBlockTransferParams = function (id, x, y) {
    var tileBlock = this._getTileBlock(id);
    var result = [];

    result.push(this.bitmap);
    result.push(tileBlock.x, tileBlock.y, tileBlock.width, tileBlock.height);
    result.push(x, y);

    return result;
  };

  /**
   * Check if tile ID is included in tileset
   *
   * @param  {number} id Tile ID in layer data
   * @return {Boolean} Is in tileset
   */
  Tileset.prototype.isInTileset = function (id) {
    var lastId = this.firstId + this.getTotalTiles();

    return id >= this.firstId && id < lastId;
  };

  /**
   * Check if the tileset bitmap is finished loading
   *
   * @return {Boolean} Ready Flag
   */
  Tileset.prototype.isReady = function () {
    return ImageManager.isReady();
  };

  YED.Tilemap.Tileset = Tileset;
})();

/* globals YED: false */

(function () {
  /**
   * The Layer object extends Sprite object in RMMV framework, is created
   * by {@link YED.Tilemap.Core} to render a layer in tilemap
   *
   * A Layer can be created and render by simply creating a new Layer object
   * and add into a {@link http://www.goodboydigital.com/pixijs/docs/classes/DisplayObjectContainer.html PIXI.DisplayObjectContainer} object:
   *
   * ```js
   * var layer = new YED.Tilemap.Layer(data, tilesets, tileWidth, tileHeight);
   * scene.addChild(layer);
   * ```
   *
   * @class
   * @extends Sprite
   * @memberof YED.Tilemap
   * @param {Object} data A Layer data gets from {@link YED.Tilemap.Data#layers Tilemap.Data#layers}
   * @param {YED.Tilemap.Tileset[]} tilesets An array of {@link YED.Tilemap.Tileset Tilemap.Tileset}
   * @param {number} tileWidth Width of each tile
   * @param {number} tileHeight Height of each tile
   */
  var Layer = function () {
    this.initialize.apply(this, arguments);
  };

  // extends Sprite
  Layer.prototype = Object.create(Sprite.prototype);
  Layer.prototype.constructor = Layer;

  // initialize, inherited from Sprite
  Layer.prototype.initialize = function (
    data,
    tilesets,
    tileWidth,
    tileHeight
  ) {
    Sprite.prototype.initialize.call(this);

    this.data = data;
    this.tilesets = tilesets;

    this.tileWidth = tileWidth;
    this.tileHeight = tileHeight;

    this._tilingSprite = null;

    if (!this.data.visible) {
      this.visible = false;
    }
  };

  Object.defineProperties(Layer.prototype, {
    /**
     * Layer data get from tilemap data
     *
     * @member {Object}
     * @memberof YED.Tilemap.Layer#
     */
    data: {
      get: function () {
        return this._data || null;
      },

      set: function (data) {
        this._data = data;
        this._setupData();
      },
    },

    gridHorz: {
      get: function () {
        return this._gridHorz || 0;
      },

      set: function (grid) {
        this._gridHorz = grid;
      },
    },

    gridVert: {
      get: function () {
        return this._gridVert || 0;
      },

      set: function (grid) {
        this._gridVert = grid;
      },
    },

    /**
     * Height of each tile in layer
     *
     * @member {number}
     * @memberof YED.Tilemap.Layer#
     */
    tileHeight: {
      get: function () {
        return this._tileHeight || 0;
      },

      set: function (height) {
        this._tileHeight = height;
      },
    },

    /**
     * Width of each tile in layer
     *
     * @member {number}
     * @memberof YED.Tilemap.Layer#
     */
    tileWidth: {
      get: function () {
        return this._tileWidth || 0;
      },

      set: function (width) {
        this._tileWidth = width;
      },
    },

    /**
     * Tiles data, an one dimensional array contains tile IDs
     *
     * @member {number[]}
     * @memberof YED.Tilemap.Layer#
     * @readonly
     */
    tilesData: {
      get: function () {
        return this.data.data;
      },
    },

    /**
     * Objects data, an one dimensional array contains object data
     *
     * @member {Object[]}
     * @memberof YED.Tilemap.Layer#
     * @readonly
     */
    objectsData: {
      get: function () {
        return this.data.objects;
      },
    },

    /**
     * Tilesets used for layer
     *
     * @member {YED.Tilemap.Tileset[]}
     * @memberof YED.Tilemap.Layer#
     */
    tilesets: {
      get: function () {
        return this._tilesets || [];
      },

      set: function (tilesets) {
        this._tilesets = tilesets;
      },
    },

    /**
     * Layer custom properties
     *
     * @member {Object}
     * @memberof YED.Tilemap.Layer#
     * @readonly
     */
    properties: {
      get: function () {
        return this.data.properties || {};
      },
    },
  });

  /**
   * Setup things after loaded data
   *
   * @private
   */
  Layer.prototype._setupData = function () {
    if (!!this.data) {
      this.gridHorz = this.data.width;
      this.gridVert = this.data.height;
    }
  };

  /**
   * Check if layer is tile-based layer
   *
   * @return {Boolean}
   */
  Layer.prototype.isTileLayer = function () {
    return this.data.type === "tilelayer";
  };

  /**
   * Check if layer is object-based layer or tile-based layer
   *
   * @return {Boolean}
   */
  Layer.prototype.isObjectLayer = function () {
    return this.data.type === "objectgroup";
  };

  /**
   * Check if layer is image-based layer
   *
   * @return {Boolean}
   */
  Layer.prototype.isImageLayer = function () {
    return this.data.type === "imagelayer";
  };

  /**
   * Check if layer is plane layer
   *
   * @return {Boolean}
   */
  Layer.prototype.isPlaneLayer = function () {
    return (
      this.isImageLayer() && !!this.properties && !!this.properties.parallax
    );
  };

  Layer.prototype.isLoopHorizontal = function () {
    return $gameMap.isLoopHorizontal();
  };

  Layer.prototype.isLoopVertical = function () {
    return $gameMap.isLoopVertical();
  };

  Layer.prototype.isLoop = function () {
    return this.isLoopHorizontal() || this.isLoopVertical();
  };

  Layer.prototype.isCollisionLayer = function () {
    return !!this.properties && !!this.properties.collision;
  };

  Layer.prototype.isRegionLayer = function () {
    return !!this.properties && !!this.properties.regionId;
  };

  Layer.prototype.isUpperLayer = function () {
    if (!!this.properties.layer) {
      return this.properties.layer.toLowerCase() === "upper";
    }

    return false;
  };

  /**
   * Render layer with given data and tilesets
   */
  Layer.prototype.renderLayer = function () {
    this._layerBitmap =
      this._layerBitmap ||
      new Bitmap(
        this.gridHorz * this.tileWidth,
        this.gridVert * this.tileHeight
      );

    // different methods for tile-based and object-based layer
    if (this.isObjectLayer()) {
      this._renderObjectLayer();
    }

    if (this.isTileLayer()) {
      this._renderTileLayer();
    }

    if (this.isImageLayer() && !this.isPlaneLayer()) {
      this._renderImageLayer();
    }

    if (this.isPlaneLayer()) {
      this._renderPlaneLayer();
    }
  };

  /**
   * Render tile-based layer
   *
   * @private
   */
  Layer.prototype._renderTileLayer = function () {
    var i = 0,
      length = this.tilesData.length, // tiles data iterator, fuck js
      tileId,
      bitmapX,
      bitmapY;

    for (; i < length; i++) {
      tileId = this.tilesData[i];

      bitmapX = i % this._gridHorz;
      bitmapX = bitmapX * this.tileWidth;

      bitmapY = Math.floor(i / this._gridHorz);
      bitmapY = bitmapY * this.tileHeight;

      // skip tileId zero (none tile)
      if (tileId === 0) {
        continue;
      }

      this._drawTile(tileId, bitmapX, bitmapY);
    }

    if (this.isLoop) {
      this._renderLoopLayer();
    } else {
      this.bitmap = this._layerBitmap;
    }
  };

  /**
   * Render object-based layer
   *
   * @private
   */
  Layer.prototype._renderObjectLayer = function () {
    var i = 0,
      length = this.objectsData.length,
      tileId,
      bitmapX,
      bitmapY,
      data;

    for (; i < length; i++) {
      data = this.objectsData[i];

      tileId = data.gid;

      bitmapX = Math.round(data.x);
      bitmapY = Math.round(data.y - data.height);

      if (tileId === 0) {
        continue;
      }

      this._drawTile(tileId, bitmapX, bitmapY);
    }

    if (this.isLoop) {
      this._renderLoopLayer();
    } else {
      this.bitmap = this._layerBitmap;
    }
  };

  Layer.prototype._renderLoopLayer = function () {
    var tilingWidth, tilingHeight;

    tilingWidth = this.isLoopHorizontal()
      ? Graphics.width
      : this._layerBitmap.width;

    tilingHeight = this.isLoopVertical()
      ? Graphics.height
      : this._layerBitmap.height;

    this._tilingSprite = new TilingSprite(this._layerBitmap);
    this._tilingSprite.move(0, 0, tilingWidth, tilingHeight);
    this.addChild(this._tilingSprite);
  };

  /**
   * Render object-based layer
   *
   * @private
   */
  Layer.prototype._renderImageLayer = function () {
    var dest = this._layerBitmap,
      img = ImageManager.loadParserParallax(this.data.image, 0);

    dest.blt(img, 0, 0, img.width, img.height, this.data.x, this.data.y);
    this.bitmap = this._layerBitmap;
  };

  /**
   * Render object-based layer
   *
   * @private
   */
  Layer.prototype._renderPlaneLayer = function () {
    var img = ImageManager.loadParserParallax(this.data.image, 0);

    this._tilingSprite = new TilingSprite(img);
    this._tilingSprite.move(
      this.data.x,
      this.data.y,
      Graphics.width,
      Graphics.height
    );
    this.addChild(this._tilingSprite);
  };

  /**
   * Get tileset which contains the drawing tile
   *
   * @param  {number} tileId Tile ID in layer data
   * @return {YED.Tilemap.Tileset|null} Tileset contains tile ID
   * @private
   */
  Layer.prototype._getTileset = function (tileId) {
    var i = 0,
      length = this.tilesets.length,
      tileset; // for tilesets iterator

    for (; i < length; i++) {
      tileset = this.tilesets[i];

      // skip current tileset if tileId is not in this tileset
      if (tileset.isInTileset(tileId) === false) {
        continue;
      }

      return tileset;
    } // end tilesets loop

    return null;
  };

  /**
   * Draw a tile on specific coordination
   *
   * @param  {number} tileId Tile ID in layer data
   * @param  {number} x Real X on bitmap
   * @param  {number} y Real Y on bitmap
   */
  Layer.prototype._drawTile = function (tileId, x, y) {
    var tileset = this._getTileset(tileId);
    var params = tileset.getBlockTransferParams(tileId, x, y);
    var dest = this._layerBitmap;

    dest.blt.apply(dest, params);
  };

  Layer.prototype.update = function () {
    this._updatePlane();
  };

  Layer.prototype._updatePlane = function () {
    var xSpeed = parseInt(this.properties.planeX),
      ySpeed = parseInt(this.properties.planeY),
      ox,
      oy,
      mOx,
      mOy;

    if (!this._tilingSprite) {
      return;
    }

    ox = this._tilingSprite.origin.x;
    oy = this._tilingSprite.origin.y;

    mOx = this._tilingSprite.bitmap.width;
    mOy = this._tilingSprite.bitmap.height;

    if (!!xSpeed) {
      this._tilingSprite.origin.x = (ox + xSpeed) % mOx;
    }

    if (!!ySpeed) {
      this._tilingSprite.origin.y = (oy + ySpeed) % mOy;
    }
  };

  Layer.prototype.moveLoopLayer = function (x, y) {
    if (!this._tilingSprite) {
      return;
    }

    this._tilingSprite.origin.x = x;
    this._tilingSprite.origin.y = y;
  };

  YED.Tilemap.Layer = Layer;
})();

/* globals YED: false */

(function () {
  // Shorten dependencies
  var Data = YED.Tilemap.Data,
    Tileset = YED.Tilemap.Tileset,
    Layer = YED.Tilemap.Layer;

  /**
   * The Core object is the bootstrap to load and render tilemap to the screen
   *
   * A tilemap can be created inside a scene with a single statement
   *
   * ```js
   * var tilemap = new YED.Tilemap.Core();
   * this.addChild(tilemap); // add tilemap to scene
   * ```
   *
   * @class
   * @extends PIXI.DisplayObjectContainer
   * @memberof YED.Tilemap
   */
  var Core = function () {
    PIXI.DisplayObjectContainer.call(this);

    this.setup();
  };

  Core.dataMap = null;
  Core.noMap = false;
  Core.singleton = null;

  Core.loadMapFile = function () {
    var filePath = Core.getFilePath();
    Core.loadFile(filePath);
  };

  Core.unloadMap = function () {
    Core.dataMap = null;
    Core.noMap = false;
  };

  Core.loadFile = function (filePath) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", filePath);
    xhr.overrideMimeType("application/json");

    // on success callback
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
        if (xhr.status === 200 || xhr.responseText !== "") {
          Core.dataMap = JSON.parse(xhr.responseText);
        } else {
          // Core.noMap = true;
          throw new Error("[YED#Tilemap] Loading error");
        }
      }
    };

    // set data to null and send request
    Core.unloadMap();
    xhr.send();
  };

  /**
   * Get file path with filename to the json file for automatically loading
   *
   * @return {string} The path and filename to json file
   * @private
   */
  Core.getFilePath = function () {
    return Core.getPath() + Core.getFilename();
  };

  /**
   * Get path to json file
   *
   * @return {string} The path to json file
   * @private
   */
  Core.getPath = function () {
    return "./maps/";
  };

  /**
   * Get json filename
   *
   * @return {string} Filename
   * @private
   */
  Core.getFilename = function () {
    var id = Core.getMapId();
    return "Map" + id + ".json";
  };

  /**
   * Get map ID from RMMV framework for search json file
   *
   * @return {number} Map ID
   * @private
   */
  Core.getMapId = function () {
    var isTransferring = $gamePlayer.isTransferring();
    return isTransferring ? $gamePlayer.newMapId() : $gameMap.mapId();
  };

  Core.isMapLoaded = function () {
    return !!Core.dataMap || !!Core.noMap;
  };

  Core.isDefaultMap = function () {
    return !Core.dataMap && !!Core.noMap;
  };

  Core.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
  Core.prototype.constructor = Core;

  Object.defineProperties(Core.prototype, {
    data: {
      get: function () {
        return this._data || null;
      },

      set: function (data) {
        this._data = data;
      },
    },

    tilesets: {
      get: function () {
        return this._tilesets || [];
      },

      set: function (tilesets) {
        this._tilesets = tilesets;
      },
    },

    layers: {
      get: function () {
        return this.lowerLayers.concat(this.upperLayers);
      },
    },

    upperLayers: {
      get: function () {
        return this._upperLayers;
      },
    },

    lowerLayers: {
      get: function () {
        return this._lowerLayers;
      },
    },
  });

  Core.prototype.setup = function () {
    this._clearData();
    this._setupData();
    this._setupLayers();
    this._setupTilesets();
    this._setupParallaxes();
  };

  Core.prototype._clearData = function () {
    this._data = null;
    this._tilesets = [];
    this._needRefresh = false;
    this._upperLayers = [];
    this._lowerLayers = [];
    this.z = -1;
  };

  Core.prototype._setupData = function () {
    this.data = new Data(Core.dataMap);
  };

  Core.prototype._setupTilesets = function () {
    var tilesetsData = this.data.tilesets,
      i = 0,
      length = tilesetsData.length,
      data;

    for (; i < length; i++) {
      data = tilesetsData[i];
      this.tilesets.push(new Tileset(data));
    }
  };

  Core.prototype._setupParallaxes = function () {
    var imageData = this.data.getImageLayers(),
      i = 0,
      length = imageData.length;

    for (; i < length; i++) {
      ImageManager.loadParserParallax(imageData[i].image, 0);
    }
  };

  Core.prototype._setupLayers = function () {
    var layersData = this.data.layers,
      i = 0,
      length = layersData.length,
      data,
      layer;

    for (; i < length; i++) {
      data = layersData[i];
      layer = new Layer(
        data,
        this.tilesets,
        this.data.tileWidth,
        this.data.tileHeight
      );

      if (layer.isUpperLayer()) {
        this.upperLayers.push(layer);
      } else {
        this.lowerLayers.push(layer);
      }

      // this.addChild(layer);
      // this.layers.push(layer);
    }
  };

  Core.prototype.update = function () {
    this._updateRender();
  };

  Core.prototype._updateRender = function () {
    if (this._needRefresh && ImageManager.isReady()) {
      this.render();
      this._needRefresh = false;
    }
  };

  Core.prototype.render = function () {
    var layers = this.layers,
      i = 0,
      length = layers.length,
      layer;

    for (; i < length; i++) {
      layer = layers[i];
      layer.renderLayer();
    }
  };

  Core.prototype.refresh = function () {
    this._needRefresh = true;
  };

  /**
   * Check if map data exists
   *
   * @return {Boolean} Exist flag
   */
  Core.prototype.isExist = function () {
    return this.data.isExist();
  };

  YED.Tilemap.Core = Core;
})();

/* globals YED: false */

(function () {
  var _DataManager_loadMapData = DataManager.loadMapData;
  var _DataManager_isMapLoaded = DataManager.isMapLoaded;
  var _Scene_Map_onMapLoaded = Scene_Map.prototype.onMapLoaded;
  var _Game_Map_setup = Game_Map.prototype.setup;
  var _Game_Map_tileWidth = Game_Map.prototype.tileWidth;
  var _Game_Map_tileHeight = Game_Map.prototype.tileHeight;
  var _Game_Map_width = Game_Map.prototype.width;
  var _Game_Map_height = Game_Map.prototype.height;
  var _Game_Event_setupPage = Game_Event.prototype.setupPage;
  var _Game_CharacterBase_distancePerFrame =
    Game_CharacterBase.prototype.distancePerFrame;
  var _Spriteset_Map_createTilemap = Spriteset_Map.prototype.createTilemap;

  DataManager.loadMapData = function (mapId) {
    _DataManager_loadMapData.call(this, mapId);

    this.loadYEDMapData(mapId);
  };

  DataManager.loadYEDMapData = function (mapId) {
    if (mapId > 0) {
      YED.Tilemap.Core.loadMapFile();
    } else {
      YED.Tilemap.Core.unloadMap();
    }
  };

  DataManager.isMapLoaded = function () {
    var defaultLoaded = _DataManager_isMapLoaded.call(this);
    var yedTilemapLoaded = YED.Tilemap.Core.isMapLoaded();

    return defaultLoaded && yedTilemapLoaded;
  };

  Scene_Map.prototype.onMapLoaded = function () {
    $gameMap.setupYEDTilemap();

    _Scene_Map_onMapLoaded.call(this);
  };

  Game_Map.prototype.setup = function (mapId) {
    this.setupYEDTilemap();

    _Game_Map_setup.call(this, mapId);
  };

  Game_Map.prototype.setupYEDTilemap = function () {
    // this._yed_tilemap = new YED.Tilemap.Core();
    YED.Tilemap.Core.singleton =
      YED.Tilemap.Core.singleton || new YED.Tilemap.Core();

    YED.Tilemap.Core.singleton.setup();

    // overwrite dataMap width/height
    $dataMap.width = this._yedTilemapData().width;
    $dataMap.height = this._yedTilemapData().height;
  };

  Game_Map.prototype._yedTilemapData = function () {
    return YED.Tilemap.Core.singleton.data;
  };

  Game_Map.prototype.oldTileWidth = function () {
    return _Game_Map_tileWidth.call(this);
  };

  Game_Map.prototype.oldTileHeight = function () {
    return _Game_Map_tileHeight.call(this);
  };

  Game_Map.prototype.oldWidth = function () {
    return _Game_Map_width.call(this);
  };

  Game_Map.prototype.oldHeight = function () {
    return _Game_Map_height.call(this);
  };

  Game_Map.prototype.tileWidth = function () {
    return this._yedTilemapData().tileWidth;
  };

  Game_Map.prototype.tileHeight = function () {
    return this._yedTilemapData().tileHeight;
  };

  Game_Map.prototype.width = function () {
    return this._yedTilemapData().width;
  };

  Game_Map.prototype.height = function () {
    return this._yedTilemapData().height;
  };

  Game_Map.prototype.defaultMapX = function () {
    return this._yedTilemapData().properties.defaultMapX || 0;
  };

  Game_Map.prototype.defaultMapY = function () {
    return this._yedTilemapData().properties.defaultMapY || 0;
  };

  Game_Map.prototype.tilemapUpperLayers = function () {
    return YED.Tilemap.Core.singleton.upperLayers;
  };

  Game_Map.prototype.tilemapLowerLayers = function () {
    return YED.Tilemap.Core.singleton.lowerLayers;
  };

  Game_Map.prototype.tilemapRefresh = function () {
    YED.Tilemap.Core.singleton.refresh();
  };

  Game_Map.prototype.isPassable = function (x, y, d) {
    var collision = this._yedTilemapData().collision,
      arrows = this._yedTilemapData().arrows,
      index = this.width() * y + x;

    if (d === 4) {
      if (!(arrows[index] & 1)) {
        return false;
      }
    }

    if (d === 8) {
      if (!(arrows[index] & 2)) {
        return false;
      }
    }

    if (d === 6) {
      if (!(arrows[index] & 4)) {
        return false;
      }
    }

    if (d === 2) {
      if (!(arrows[index] & 8)) {
        return false;
      }
    }

    return collision[index] === 0;
  };

  Game_Map.prototype.regionId = function (x, y) {
    var regions = this._yedTilemapData().region,
      index = this.width() * y + x;

    return regions[index];
  };

  Game_CharacterBase.prototype.distancePerFrame = function () {
    var distance = _Game_CharacterBase_distancePerFrame.call(this);
    return distance * (48 / $gameMap.tileWidth());
  };

  Game_Event.prototype.setupPage = function () {
    this.setupInitPosition();

    _Game_Event_setupPage.call(this);
  };

  Game_Event.prototype.setupInitPosition = function () {
    var list,
      tag = /<position:[ ]*(\d+),[ ]*(\d+)>/i,
      command,
      comment,
      matches,
      x,
      y;

    if (!this.page()) {
      return;
    }

    list = this.list();

    for (var i = 0; i < list.length; i++) {
      command = list[i];

      if (command.code !== 108) {
        continue;
      }

      comment = command.parameters[0];
      matches = comment.match(tag);
      if (matches) {
        x = parseInt(matches[1]);
        y = parseInt(matches[2]);
        this.setPosition(x, y);
      }
    }
  };

  Spriteset_Map.prototype.createTilemap = function () {
    _Spriteset_Map_createTilemap.call(this);
    this._tilemap.tileWidth = $gameMap.oldTileWidth();
    this._tilemap.tileHeight = $gameMap.oldTileHeight();
    this._tilemap.setData(
      $gameMap.oldWidth(),
      $gameMap.oldHeight(),
      $gameMap.data()
    );
  };

  Tilemap.prototype.refresh = function () {
    this._needsRepaint = true; // no need to draw default tiles
    this._lastTiles.length = 0;
    $gameMap.tilemapRefresh();
  };

  Tilemap.prototype._createLayers = function () {
    var margin = this._margin,
      upperLayers = $gameMap.tilemapUpperLayers(),
      lowerLayers = $gameMap.tilemapLowerLayers(),
      tileCols = Math.ceil(this._width / this._tileWidth) + 1,
      tileRows = Math.ceil(this._height / this._tileHeight) + 1,
      layerWidth = tileCols * this._tileWidth,
      layerHeight = tileRows * this._tileHeight,
      i;

    this._lowerBitmap = new Bitmap(layerWidth, layerHeight);
    this._upperBitmap = new Bitmap(layerWidth, layerHeight);

    this._layerWidth = layerWidth;
    this._layerHeight = layerHeight;

    /*
     * Z coordinate:
     *
     * 0 : Lower tiles
     * 1 : Lower characters
     * 3 : Normal characters
     * 4 : Upper tiles
     * 5 : Upper characters
     * 6 : Airship shadow
     * 7 : Balloon
     * 8 : Animation
     * 9 : Destination
     */

    this._lowerLayer = new Sprite();
    this._lowerLayer.move(-margin, -margin, this._width, this._height);
    this._lowerLayer.z = 0;

    this._upperLayer = new Sprite();
    this._upperLayer.move(-margin, -margin, this._width, this._height);
    this._upperLayer.z = 4;

    for (i = 0; i < lowerLayers.length; i++) {
      this._lowerLayer.addChild(lowerLayers[i]);
    }

    for (i = 0; i < upperLayers.length; i++) {
      this._upperLayer.addChild(upperLayers[i]);
    }

    this.addChild(this._lowerLayer);
    this.addChild(this._upperLayer);
    this.addChild(YED.Tilemap.Core.singleton);
  };

  Tilemap.prototype._updateLayerPositions = function (startX, startY) {
    /* jshint unused:vars */
    var m = this._margin,
      ox = Math.floor(this.origin.x),
      oy = Math.floor(this.origin.y),
      x2 = -(ox - m),
      y2 = -(oy - m);

    // TODO: Loop map!!!

    var moveFunc = function (layer) {
      if (
        !layer.isPlaneLayer() &&
        !layer.isLoopVertical() &&
        !layer.isLoopHorizontal()
      ) {
        layer.move(x2, y2);
      }

      if (
        !layer.isPlaneLayer() &&
        layer.isLoopVertical() &&
        layer.isLoopHorizontal()
      ) {
        layer.move(m, m);
        layer.moveLoopLayer(ox, oy);
        return;
      }

      if (!layer.isPlaneLayer() && layer.isLoopHorizontal()) {
        layer.move(m, y2);
        layer.moveLoopLayer(ox, 0);
        return;
      }

      if (!layer.isPlaneLayer() && layer.isLoopVertical()) {
        layer.move(x2, m);
        layer.moveLoopLayer(0, oy);
        return;
      }

      if (layer.isPlaneLayer()) {
        layer.move(m, m);
      }
    };

    for (var i = 0; i < 2; i++) {
      var children;

      if (i === 0) {
        children = this._lowerLayer.children;
      } else {
        children = this._upperLayer.children;
      }

      children.forEach(moveFunc);
    }

    // this._updateDefaultLayerPositions(startX, startY);
  };

  // Tilemap.prototype._paintAllTiles = function(startX, startY) {
  //     /* jshint unused:vars */
  //     // destroy method
  // };
})();


code:
/*:
 * Yami Engine Delta - Transfer and Steal States
 *
 * @plugindesc Allows creating skills that can transfer and/or steal
 * states to/from target.
 * @author Yami Engine Delta [Dr.Yami]
 *
 * @help
 * There is no Configuration and Plugin Command.
 *
 * ============================================================================
 *
 * Skill
 * To allow skill to steal certain states, use the following notetag with
 * X is/are states ID:
 *   <steal allow: X, X, X, ...>
 *
 * To allow skill to transfer certain states, use the following notetag with
 * X is/are states ID:
 *   <transfer allow: X, X, X, ...>
 *
 * To allow skill to steal states, use the following notetag with N is
 * number of states, X is priority order:
 *   <steal N states: X>
 *
 * To allow skill to transfer states, use the following notetag with N is
 * number of states, X is priority order:
 *   <transfer N states: X>
 *
 *
 * Priority order:
 *
 * -------------------------------------------------------------------------
 * high priority
 * low priority
 * last states
 * random
 * -------------------------------------------------------------------------
 *
 * ============================================================================
 */
/*:ja
 * Yami Engine Delta - Transfer and Steal States
 *
 * @plugindesc ステート受け渡しのスキル作成が可能になります。
 * @author Yami Engine Delta [Dr.Yami]
 *
 * @help
 * このプラグインには、コンフィグやプラグインコマンドはありません。
 *
 * ============================================================================
 *
 * Skill
 * 特定のステートを盗むスキルを作成できるようになります。
 * XにはステートIDを記入してください。
 *   <steal allow: X, X, X, ...>
 *
 * 特定のステートを移植するスキルを作成できるようになります。
 * XにはステートIDを記入してください。
 *   <transfer allow: X, X, X, ...>
 *
 * ルールに従ってステートを盗むスキルを作成できるようになります。
 * Nにはステートの番号、Xには優先順位を記入してください。
 *   <steal N states: X>
 *
 * ルールに沿ってステートを移植するスキルを作成できるようになります。
 * Nにはステートの番号、Xには優先順位を記入してください。:
 *   <transfer N states: X>
 *
 *
 * 優先順位:
 * -------------------------------------------------------------------------
 * high priority - 高優先度
 * low priority - 低優先度
 * last states - 最低優先度
 * random - ランダム
 * -------------------------------------------------------------------------
 *
 * ============================================================================
 */

/**
 * @namespace TransferStealStates
 * @memberof YED
 */

var YED = YED || {};

// init TransferStealStates module
YED.TransferStealStates = {};

/* globals YED: false */

(function ($TransferStealStates) {
  /**
   * Enum for RegExp, used to notetags
   *
   * @readonly
   * @enum {RegExp}
   * @memberof YED.TransferStealStates
   */
  var Regexp = {
    /**
     * Allows states to be stolen
     */
    STEAL_ALLOW: /<steal allow:[ ]*(.+)>/i,

    /**
     * Allows states to be transfered
     */
    TRANSFER_ALLOW: /<transfer allow:[ ]*(.+)>/i,

    /**
     * Steal (n) states with different priority
     */
    STEAL_STATES: /<steal (\d+) (?:states|state):[ ]*(.+)>/i,

    /**
     * Transfer (n) states with different priority
     */
    TRANSFER_STATES: /<transfer (\d+) (?:states|state):[ ]*(.+)>/i,
  };

  $TransferStealStates.Regexp = Regexp;
})(YED.TransferStealStates);

/* globals YED: false */

(function ($TransferStealStates, $Regexp) {
  /**
   * Contains utility tools for module.
   *
   * @namespace Utils
   * @memberof YED.TransferStealStates
   */
  var Utils = {};

  /**
   * Process notetag function.
   * Should be called with DataManager as current object.
   *
   * @function processNotetag
   * @memberof YED.TransferStealStates.Utils
   */
  Utils.processNotetags = function () {
    var group = $dataSkills, // shorten group name
      obj,
      notedata,
      line;

    for (var i = 1; i < group.length; i++) {
      obj = group[i];
      notedata = obj.note.split(/[\r\n]+/);

      Utils._processProperties.call(this, obj);
      Utils._processMethods.call(this, obj);

      for (var n = 0; n < notedata.length; n++) {
        line = notedata[n];
        Utils._processNotetag.call(this, obj, line);
      }
    }
  };

  /**
   * Add new properties into object.
   *
   * @function _processProperties
   * @memberof YED.TransferStealStates.Utils
   * @param  {Object} obj Data object
   * @private
   */
  Utils._processProperties = function (obj) {
    obj._stealAllow = [];
    obj._transferAllow = [];

    obj._stealStates = [0, "random"];
    obj._transferStates = [0, "random"];
  };

  /**
   * Add new methods into object.
   *
   * @function _processMethods
   * @memberof YED.TransferStealStates.Utils
   * @param  {Object} obj Data object
   * @private
   */
  Utils._processMethods = function (obj) {
    obj.getAllowStealStates = Utils.getAllowStealStates;
    obj.getAllowTransferStates = Utils.getAllowTransferStates;

    obj.getStealStates = Utils.getStealStates;
    obj.getTransferStates = Utils.getTransferStates;
  };

  /**
   * Process notetag for object.
   *
   * @function _processNotetag
   * @memberof YED.TransferStealStates.Utils
   * @param  {Object} obj Data object
   * @param  {String} notetag Notetag
   * @private
   */
  Utils._processNotetag = function (obj, notetag) {
    var match, ids;

    match = notetag.match($Regexp.STEAL_ALLOW);
    if (match) {
      ids = match[1].match(/\d+/g);

      if (ids) {
        obj._stealAllow = ids.map(function (id) {
          return Number(id);
        });
      }
    }

    match = notetag.match($Regexp.TRANSFER_ALLOW);
    if (match) {
      ids = match[1].match(/\d+/g);
      if (ids) {
        obj._transferAllow = ids.map(function (id) {
          return Number(id);
        });
      }
    }

    match = notetag.match($Regexp.STEAL_STATES);
    if (match) {
      obj._stealStates[0] = Number(match[1]);
      obj._stealStates[1] = match[2].toLowerCase();
    }

    match = notetag.match($Regexp.TRANSFER_STATES);
    if (match) {
      obj._transferStates[0] = Number(match[1]);
      obj._transferStates[1] = match[2].toLowerCase();
    }
  };

  /**
   * Get stealable states IDs.
   * Should be attached to skill object.
   *
   * @function getAllowStealStates
   * @memberof YED.TransferStealStates.Utils
   * @return {Number[]} States ID
   */
  Utils.getAllowStealStates = function () {
    return this._stealAllow;
  };

  /**
   * Get transferable states IDs.
   * Should be attached to skill object.
   *
   * @function getAllowTransferStates
   * @memberof YED.TransferStealStates.Utils
   * @return {Number[]} States ID
   */
  Utils.getAllowTransferStates = function () {
    return this._transferAllow;
  };

  /**
   * Get skill steal states information.
   * Should be attached to skill object.
   *
   * @function getStealStates
   * @memberof YED.TransferStealStates.Utils
   * @return {[Number, String]} Steal Information
   */
  Utils.getStealStates = function () {
    return this._stealStates;
  };

  /**
   * Get skill transfer states information.
   * Should be attached to skill object.
   *
   * @function getTransferStates
   * @memberof YED.TransferStealStates.Utils
   * @return {[Number, String]} Steal Information
   */
  Utils.getTransferStates = function () {
    return this._transferStates;
  };

  $TransferStealStates.Utils = Utils;
})(YED.TransferStealStates, YED.TransferStealStates.Regexp);

/* globals YED: false */

/**
 * Pre-processes and notetag parsing
 */
(function ($Utils) {
  /**
   * Aliasing methods
   */
  var _DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;

  /**
   * Extending: Scene_Boot.prototype.start
   *
   * Add notetags processing for module.
   */
  DataManager.isDatabaseLoaded = function () {
    var loaded = _DataManager_isDatabaseLoaded.call(this);

    if (!loaded) {
      return false;
    }

    $Utils.processNotetags.call(DataManager);

    return true;
  };
})(YED.TransferStealStates.Utils);

/* globals YED: false */

(function () {
  /**
   * Aliasing methods
   */
  var _Game_Action_testApply = Game_Action.prototype.testApply;
  var _Game_Action_applyItemUserEffect =
    Game_Action.prototype.applyItemUserEffect;

  /**
   * Get target states in order.
   *
   * @function external:Game_Action#getOrderedStates
   */
  Game_Action.prototype.getOrderedStates = function (target, order) {
    var states = target.states();

    if (
      order === "low priority" ||
      order === "lower priority" ||
      order === "low"
    ) {
      states = states.reverse();
    }

    if (
      order === "high priority" ||
      order === "higher priority" ||
      order === "high"
    ) {
      states = states; // default is high priority sort
    }

    if (order === "random") {
      states = states.sort(function () {
        return Math.pow(-1, Math.floor(Math.random() * 10));
      });
    }

    if (
      order === "last states" ||
      order === "last state" ||
      order === "last states"
    ) {
      states = target.result().addedStateObjects().reverse();
    }

    return states;
  };

  /**
   * Get stealable and transferrable states of skill.
   *
   * @function external:Game_Action#getTransferStealStates
   */
  Game_Action.prototype.getTransferStealStates = function (target, type) {
    var result = [],
      item = this.item(),
      subject = this.subject(),
      states,
      allows,
      info;

    if (type.toLowerCase() === "steal") {
      allows = item.getAllowStealStates();
      info = item.getStealStates();
      states = this.getOrderedStates(target, info[1]);
    }

    if (type.toLowerCase() === "transfer") {
      allows = item.getAllowTransferStates();
      info = item.getTransferStates();
      states = this.getOrderedStates(subject, info[1]);
    }

    for (var i = 0; i < states.length; i++) {
      if (allows.indexOf(states[i].id) < 0) {
        continue;
      }

      result.push(states[i].id);

      if (result.size >= info[0]) {
        break;
      }
    }

    return result;
  };

  /**
   * Effect for stealing states.
   *
   * @function external:Game_Action#itemEffectStealStates
   */
  Game_Action.prototype.itemEffectStealStates = function (target) {
    var result = target.result(),
      item = this.item(),
      statesId = this.getTransferStealStates(target, "steal"),
      subject = this.subject();

    if (!result.isHit()) {
      return false;
    }

    if (statesId.length === 0) {
      return false;
    }

    this.makeSuccess(target);

    for (var i = 0; i < statesId.length; i++) {
      subject.addState(statesId[i]);
      target.removeState(statesId[i]);
    }
  };

  /**
   * Effect for transferring states.
   *
   * @function external:Game_Action#itemEffectTransferStates
   */
  Game_Action.prototype.itemEffectTransferStates = function (target) {
    var result = target.result(),
      item = this.item(),
      statesId = this.getTransferStealStates(target, "transfer"),
      subject = this.subject();

    if (!result.isHit()) {
      return false;
    }

    if (statesId.length === 0) {
      return false;
    }

    console.log(statesId);

    this.makeSuccess(target);

    for (var i = 0; i < statesId.length; i++) {
      subject.removeState(statesId[i]);
      target.addState(statesId[i]);
    }
  };

  /**
   * Extending: Game_Action.prototype.testApply
   *
   * Add validate skill effect for transfer and steal states.
   */
  Game_Action.prototype.testApply = function (target) {
    if (this.getTransferStealStates(target, "steal").length > 0) {
      return true;
    }

    if (this.getTransferStealStates(target, "transfer").length > 0) {
      return true;
    }

    return _Game_Action_testApply.call(this, target);
  };

  /**
   * Extending: Game_Action.prototype.applyItemUserEffect
   *
   * Add transfer and steal states effect.
   */
  Game_Action.prototype.applyItemUserEffect = function (target) {
    _Game_Action_applyItemUserEffect.call(this, target);

    this.itemEffectStealStates(target);
    this.itemEffectTransferStates(target);
  };
})();


code:
/*:
 * Yami Engine Delta - Word Wrap
 *
 * @plugindesc This plugin provides word wrap feature, so that a long text
 * will be properly broken down into lines.
 * @author Yami Engine Delta [Dr.Yami]
 *
 * @param Break Word
 * @desc Allows unbreakable words to be broken.
 * @default false
 *
 * @help
 * The word wrap isn't enabled by default. To activate word wrap in any text,
 * for example in Message, you have to put following code into the text:
 *
 * ------------
 *   <wrap>
 * ------------
 *
 * The word wrapper will nullify the break lines in editor, so that you have
 * to manually break line by using following code in text:
 *
 * ------------
 *

 * ------------
 *
 * ============================================================================
 */

/*:ja
 * Yami Engine Delta - Word Wrap
 *
 * @plugindesc 文章の改行機能を提供します。長文を適切な位置で改行します。
 * @author Yami Engine Delta [Dr.Yami]
 *
 * @param Break Word
 * @desc 改行不可の文章を、改行することができます。
 * @default false
 *
 * @help
 * 改行機能はデフォルトでは無効になっています。
 * テキスト内に下記のコードを挿入することで、改行機能を有効にしてください。
 *
 * ------------
 *   <wrap>
 * ------------
 *
 * テキスト内に手動で下記のコードを挿入することで、改行を行います。
 *
 * ------------
 *

 * ------------
 *
 * ============================================================================
 */

/**
 * @namespace WordWrap
 * @memberof YED
 */

var YED = YED || {};

// init WordWrap module
YED.WordWrap = {};

YED.WordWrap.BreakWord = PluginManager.parameters("YED_WordWrap")["Break Word"];

(function ($WordWrap) {
  var _Window_Base_processNormalCharacter =
    Window_Base.prototype.processNormalCharacter;
  var _Window_Base_convertEscapeCharacters =
    Window_Base.prototype.convertEscapeCharacters;

  var breakWord = eval($WordWrap.BreakWord);

  Window_Base.prototype.textAreaWidth = function () {
    return this.contentsWidth();
  };

  Window_Base.prototype.needWrap = function (textState) {
    var c = textState.text[textState.index],
      w = this.textWidth(c),
      nextSpaceIndex = 0,
      nextWord = "",
      nextWidth = 0,
      text = textState.text;

    if (!this._wordWrap) {
      return false;
    }

    if (breakWord && textState.x + w * 2 >= this.textAreaWidth()) {
      textState.index--; // hack for missing character
      return true;
    }

    if (!breakWord && c === " ") {
      nextSpaceIndex = text.indexOf(" ", textState.index + 1);

      if (nextSpaceIndex < 0) {
        nextSpaceIndex = text.length + 1;
      }

      nextWord = text.substring(textState.index, nextSpaceIndex);

      nextWidth = this.textWidth(nextWord);

      if (textState.x + nextWidth >= this.textAreaWidth()) {
        return true;
      }
    }

    return false;
  };

  Window_Base.prototype.convertEscapeCharacters = function (text) {
    text = _Window_Base_convertEscapeCharacters.call(this, text);
    text = this.convertWordWrapEscapeCharacters(text);

    return text;
  };

  Window_Base.prototype.convertWordWrapEscapeCharacters = function (text) {
    text = this.enableWordWrap(text);

    if (!!this._wordWrap) {
      text = text.replace(/[\n\r]+/g, "");
      text = text.replace(/\
/gi, "\n");
    }

    return text;
  };

  Window.prototype.enableWordWrap = function (text) {
    this._wordWrap = false;

    if (!!text.match(/\<wrap\>/i)) {
      this._wordWrap = true;
    }

    text = text.replace(/\<wrap\>/gi, "");

    return text;
  };

  Window_Base.prototype.processNormalCharacter = function (textState) {
    if (this.needWrap(textState)) {
      return this.processNewLine(textState);
    }

    _Window_Base_processNormalCharacter.call(this, textState);
  };
})(YED.WordWrap);


code:
//=============================================================================
// Yanfly Engine Plugins - Auto Passive States
// YEP_AutoPassiveStates.js
//=============================================================================

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

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

//=============================================================================
/*:
 * @plugindesc v1.00 This plugin allows for some states to function as
 * passives for actors, enemies, skills, and equips.
 * @author Yanfly Engine Plugins
 *
 * @help
 * ============================================================================
 * Introduction
 * ============================================================================
 *
 * Passive states are states that are automatically active. You can think of
 * them as an extension of traits but with more flexibility. They will always
 * be there as long as the actor or enemy has auto passive state notetags.
 *
 * ============================================================================
 * Notetags
 * ============================================================================
 *
 * Actor, Class, Skills, Weapon, Armor, Enemy Notetags:
 *   <Passive State: x>
 *   <Passive State: x, x, x>
 *   This will allow the actor or enemy to have state x as a passive state.
 *   If placed inside a weapon or armor notebox, the user will have that
 *   passive state.
 *
 *   <Passive State: x to y>
 *   This will add the states x through y (in a sequence) for the actor or
 *   enemy to have as a passive state. If placed inside a weapon or armor
 *   notebox, the user will have that passive state.
 */

/*:ja
 * @plugindesc アクター、敵、スキル、装備のステートをパッシブにできます
 *
 * @help
 * ============================================================================
 * Introduction
 * ============================================================================
 *
 * パッシブステートは、操作を行わなくても有効になっているステートのことで、
 * 活用することで、より柔軟な特性の拡張が可能になります。
 * 味方や敵がパッシブステートのNotetagを持っている限り、
 * そのステートは常に有効な状態となります。
 *
 * ============================================================================
 * Notetags
 * ============================================================================
 *
 * アクター、クラス、スキル、武器、防具、敵のノートタグ:
 *   <Passive State: x>
 *   <Passive State: x, x, x>
 * アクターや敵に、常に x という状態が付与されます。Notetagを
 * 武器や防具内のNoteboxに配置すれば、その持ち主に対して有効になります。
 *
 *   <Passive State: x to y>
 * アクターや敵に、x から y までのステートを付与します。Notetagを
 * 武器や防具内のNoteboxに配置すれば、その持ち主に対して有効になります
 *
 */

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

//=============================================================================
// DataManager
//=============================================================================

Yanfly.APS.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function () {
  if (!Yanfly.APS.DataManager_isDatabaseLoaded.call(this)) return false;
  this.processAPSNotetags($dataActors);
  this.processAPSNotetags($dataClasses);
  this.processAPSNotetags($dataEnemies);
  this.processAPSNotetags($dataSkills);
  this.processAPSNotetags($dataWeapons);
  this.processAPSNotetags($dataArmors);
  return true;
};

DataManager.processAPSNotetags = function (group) {
  var note1 = /<(?:PASSIVE STATE):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
  var note2 = /<(?:PASSIVE STATE):[ ](\d+)[ ](?:THROUGH|to)[ ](\d+)>/i;
  for (var n = 1; n < group.length; n++) {
    var obj = group[n];
    var notedata = obj.note.split(/[\r\n]+/);

    obj.passiveStates = [];

    for (var i = 0; i < notedata.length; i++) {
      var line = notedata[i];
      if (line.match(note1)) {
        var array = JSON.parse("[" + RegExp.$1.match(/\d+/g) + "]");
        obj.passiveStates = obj.passiveStates.concat(array);
      } else if (line.match(note2)) {
        var range = Yanfly.Util.getRange(
          parseInt(RegExp.$1),
          parseInt(RegExp.$2)
        );
        obj.passiveStates = obj.passiveStates.concat(range);
      }
    }
  }
};

//=============================================================================
// Game_BattlerBase
//=============================================================================

Yanfly.APS.Game_BattlerBase_states = Game_BattlerBase.prototype.states;
Game_BattlerBase.prototype.states = function () {
  var array = Yanfly.APS.Game_BattlerBase_states.call(this);
  array = array.concat(this.passiveStates());
  this.sortPassiveStates(array.filter(Yanfly.Util.onlyUnique));
  return array;
};

Yanfly.APS.Game_BattlerBase_isStateAffected =
  Game_BattlerBase.prototype.isStateAffected;
Game_BattlerBase.prototype.isStateAffected = function (stateId) {
  if (this.isPassiveStateAffected(stateId)) return true;
  return Yanfly.APS.Game_BattlerBase_isStateAffected.call(this, stateId);
};

Game_BattlerBase.prototype.passiveStates = function () {
  var array = [];
  for (var i = 0; i < this.passiveStatesRaw().length; ++i) {
    var state = $dataStates[this.passiveStatesRaw()[i]];
    if (state) array.push(state);
  }
  return array;
};

Game_BattlerBase.prototype.passiveStatesRaw = function () {
  var array = [];
  return array.filter(Yanfly.Util.onlyUnique);
};

Game_BattlerBase.prototype.getPassiveStateData = function (obj) {
  if (!obj) return [];
  if (!obj.passiveStates) return [];
  var array = [];
  for (var i = 0; i < obj.passiveStates.length; ++i) {
    array.push(obj.passiveStates[i]);
  }
  return array;
};

Game_BattlerBase.prototype.sortPassiveStates = function (array) {
  array.sort(function (a, b) {
    var p1 = a.priority;
    var p2 = b.priority;
    if (p1 !== p2) return p2 - p1;
    return a - b;
  });
};

Game_BattlerBase.prototype.isPassiveStateAffected = function (stateId) {
  return this.passiveStatesRaw().contains(stateId);
};

//=============================================================================
// Game_Battler
//=============================================================================

Yanfly.APS.Game_Battler_isStateAddable = Game_Battler.prototype.isStateAddable;
Game_Battler.prototype.isStateAddable = function (stateId) {
  if (this.isPassiveStateAffected(stateId)) return false;
  return Yanfly.APS.Game_Battler_isStateAddable.call(this, stateId);
};

Yanfly.APS.Game_Battler_removeState = Game_Battler.prototype.removeState;
Game_Battler.prototype.removeState = function (stateId) {
  if (this.isPassiveStateAffected(stateId)) return;
  Yanfly.APS.Game_Battler_removeState.call(this, stateId);
};

//=============================================================================
// Game_Actor
//=============================================================================

Game_Actor.prototype.passiveStatesRaw = function () {
  var array = Game_BattlerBase.prototype.passiveStatesRaw.call(this);
  array = array.concat(this.getPassiveStateData(this.actor()));
  array = array.concat(this.getPassiveStateData(this.currentClass()));
  for (var i = 0; i < this.equips().length; ++i) {
    var equip = this.equips()[i];
    array = array.concat(this.getPassiveStateData(equip));
  }
  for (var i = 0; i < this._skills.length; ++i) {
    var skill = $dataSkills[this._skills[i]];
    array = array.concat(this.getPassiveStateData(skill));
  }
  return array;
};

//=============================================================================
// Game_Enemy
//=============================================================================

Game_Enemy.prototype.passiveStatesRaw = function () {
  var array = Game_BattlerBase.prototype.passiveStatesRaw.call(this);
  array = array.concat(this.getPassiveStateData(this.enemy()));
  for (var i = 0; i < this.skills().length; ++i) {
    var skill = this.skills()[i];
    array = array.concat(this.getPassiveStateData(skill));
  }
  return array;
};

if (!Game_Enemy.prototype.skills) {
  Game_Enemy.prototype.skills = function () {
    var skills = [];
    for (var i = 0; i < this.enemy().actions.length; ++i) {
      var skill = $dataSkills[this.enemy().actions[i].skillId];
      if (skill) skills.push(skill);
    }
    return skills;
  };
}

//=============================================================================
// Utilities
//=============================================================================

Yanfly.Util = Yanfly.Util || {};

Yanfly.Util.getRange = function (n, m) {
  var result = [];
  for (var i = n; i <= m; ++i) result.push(i);
  return result;
};

Yanfly.Util.onlyUnique = function (value, index, self) {
  return self.indexOf(value) === index;
};

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