Guest User

Untitled

a guest
Jan 25th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Yanfly Engine Plugins - Battle Engine Core
  3. // YEP_BattleEngineCore.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.YEP_BattleEngineCore = true;
  8.  
  9. var Yanfly = Yanfly || {};
  10. Yanfly.BEC = Yanfly.BEC || {};
  11. Yanfly.BEC.version = 1.43;
  12.  
  13. //=============================================================================
  14.  /*:
  15.  * @plugindesc v1.43a Have more control over the flow of the battle system
  16.  * with this plugin and alter various aspects to your liking.
  17.  * @author Yanfly Engine Plugins
  18.  *
  19.  * @param ---General---
  20.  * @default
  21.  *
  22.  * @param Action Speed
  23.  * @desc This is the formula used for an action's base speed.
  24.  * Default: agi + Math.randomInt(Math.floor(5 + agi / 4))
  25.  * @default agi
  26.  *
  27.  * @param Default System
  28.  * @desc This is the default battle system your game uses.
  29.  * Default: dtb
  30.  * @default dtb
  31.  *
  32.  * @param ---Escape---
  33.  * @default
  34.  *
  35.  * @param Escape Ratio
  36.  * @desc This is the formula used to determine escape success.
  37.  * Default: 0.5 * $gameParty.agility() / $gameTroop.agility()
  38.  * @default 0.5 * $gameParty.agility() / $gameTroop.agility()
  39.  *
  40.  * @param Fail Escape Boost
  41.  * @desc Each time the player fails escape, increase the success
  42.  * rate by this much. Default: 0.1
  43.  * @default 0.1
  44.  *
  45.  * @param ---Animation---
  46.  * @default
  47.  *
  48.  * @param Animation Base Delay
  49.  * @desc This sets the base delay in between animations.
  50.  * Default: 8
  51.  * @default 0
  52.  *
  53.  * @param Animation Next Delay
  54.  * @desc This sets the sequential delay in between animations.
  55.  * Default: 12
  56.  * @default 0
  57.  *
  58.  * @param Certain Hit Animation
  59.  * @desc Default animation to play for certain hit skills.
  60.  * Use 0 if you wish for no animation.
  61.  * @default 120
  62.  *
  63.  * @param Physical Animation
  64.  * @desc Default animation to play for physical skills.
  65.  * Use 0 if you wish for no animation.
  66.  * @default 52
  67.  *
  68.  * @param Magical Animation
  69.  * @desc Default animation to play for magical skills.
  70.  * Use 0 if you wish for no animation.
  71.  * @default 51
  72.  *
  73.  * @param Enemy Attack Animation
  74.  * @desc This is the default attack animation played by enemies.
  75.  * Default: 0
  76.  * @default 39
  77.  *
  78.  * @param Reflect Animation
  79.  * @desc The animation used when magic attacks are reflected.
  80.  * @default 42
  81.  *
  82.  * @param Motion Waiting
  83.  * @desc Play animations after performing an action or during?
  84.  * During - false     After - true     Default: false
  85.  * @default false
  86.  *
  87.  * @param ---Frontview---
  88.  * @default
  89.  *
  90.  * @param Front Position X
  91.  * @desc This formula determines the actor's home X position.
  92.  * Default: 0
  93.  * @default Graphics.boxWidth / 8 + Graphics.boxWidth / 4 * index
  94.  *
  95.  * @param Front Position Y
  96.  * @desc This formula determines the actor's home Y position.
  97.  * Default: 0
  98.  * @default Graphics.boxHeight - 180
  99.  *
  100.  * @param Front Actor Sprite
  101.  * @desc Show the actor battle sprite in frontview?
  102.  * NO - false     YES - true     Default - false
  103.  * @default false
  104.  *
  105.  * @param Front Sprite Priority
  106.  * @desc Give actor sprites the priority of always being on top?
  107.  * 0 - Normal   1 - Actors on Top   2 - Enemies on Top
  108.  * @default 1
  109.  *
  110.  * @param ---Sideview---
  111.  * @default
  112.  *
  113.  * @param Home Position X
  114.  * @desc This formula determines the actor's home X position.
  115.  * Default: 600 + index * 32
  116.  * @default screenWidth - 16 - (maxSize + 2) * 32 + index * 32
  117.  *
  118.  * @param Home Position Y
  119.  * @desc This formula determines the actor's home Y position.
  120.  * Default: 280 + index * 48
  121.  * @default screenHeight - statusHeight - maxSize * 48 + (index+1) * 48 - 32
  122.  *
  123.  * @param Side Sprite Priority
  124.  * @desc Give actor sprites the priority of always being on top?
  125.  * 0 - Normal   1 - Actors on Top   2 - Enemies on Top
  126.  * @default 1
  127.  *
  128.  * @param ---Sprites---
  129.  * @default
  130.  *
  131.  * @param Default X Anchor
  132.  * @desc Default value used for your sprites's X Anchor.
  133.  * Default: 0.5
  134.  * @default 0.5
  135.  *
  136.  * @param Default Y Anchor
  137.  * @desc Default value used for your sprites's Y Anchor.
  138.  * Default: 1.0
  139.  * @default 1.0
  140.  *
  141.  * @param Step Distance
  142.  * @desc This is the distance a unit steps forward for actions.
  143.  * Default: 48
  144.  * @default 48
  145.  *
  146.  * @param Flinch Distance
  147.  * @desc In sideview, when a unit takes damage or dodges, it will
  148.  * flinch a certain distance in pixels.
  149.  * @default 12
  150.  *
  151.  * @param Show Shadows
  152.  * @desc Do you wish to have shadows appear under actors?
  153.  * NO - false     YES - true
  154.  * @default true
  155.  *
  156.  * @param ---Damage Popups---
  157.  * @default
  158.  *
  159.  * @param Popup Duration
  160.  * @desc Adjusts how many frames a popup will stay visible for.
  161.  * Default: 90
  162.  * @default 128
  163.  *
  164.  * @param Newest Popup Bottom
  165.  * @desc Places the newest popup at the bottom of a group.
  166.  * NO - false     YES - true
  167.  * @default true
  168.  *
  169.  * @param Popup Overlap Rate
  170.  * @desc When multiple damage popups appear, they cover each other.
  171.  * Use this to change the buffer rate amount for each sprite.
  172.  * @default 0.9
  173.  *
  174.  * @param Critical Popup
  175.  * @desc Adjusts the popup's flashing color for critical hits.
  176.  * Default: 255, 0, 0, 160
  177.  * @default 255, 0, 0, 160
  178.  *
  179.  * @param Critical Duration
  180.  * @desc How many frames the flashing will remain for a critical.
  181.  * Default: 60
  182.  * @default 60
  183.  *
  184.  * @param ---Tick-Settings---
  185.  * @default
  186.  *
  187.  * @param Timed States
  188.  * @desc If the battle system is Tick-based, use time instead of
  189.  * turns for states? NO - false   YES - true
  190.  * @default false
  191.  *
  192.  * @param Timed Buffs
  193.  * @desc If the battle system is Tick-based, use time instead of
  194.  * turns for buffs? NO - false   YES - true
  195.  * @default false
  196.  *
  197.  * @param Turn Time
  198.  * @desc How many ticks must past to equal 1 turn?
  199.  * @default 100
  200.  *
  201.  * @param AI Self Turns
  202.  * @desc Set AI to be based on their own individual turns?
  203.  * NO - false     YES - true
  204.  * @default true
  205.  *
  206.  * @param ---Window Settings---
  207.  * @default
  208.  *
  209.  * @param Lower Windows
  210.  * @desc Places the skill and item windows at the screen's bottom.
  211.  * OFF - false     ON - true
  212.  * @default true
  213.  *
  214.  * @param Window Rows
  215.  * @desc For lower windows, how many rows of items do you wish for
  216.  * the windows to display?
  217.  * @default 4
  218.  *
  219.  * @param Command Window Rows
  220.  * @desc Sets the number of rows for each command window to display.
  221.  * Default: 4
  222.  * @default 4
  223.  *
  224.  * @param Command Alignment
  225.  * @desc Sets the text alignment for the Party/Actor Commands.
  226.  * Default: left
  227.  * @default center
  228.  *
  229.  * @param Start Actor Command
  230.  * @desc Starts turn with the Actor Command Window instead of Party.
  231.  * OFF - false     ON - true
  232.  * @default true
  233.  *
  234.  * @param Current Max
  235.  * @desc Display the entire current / max value of HP/MP?
  236.  * NO - false     YES - true     Default: true
  237.  * @default false
  238.  *
  239.  * @param ---Selection Help---
  240.  * @default
  241.  *
  242.  * @param Mouse Over
  243.  * @desc Allows you to mouse over the enemies to auto-select them.
  244.  * OFF - false     ON - true
  245.  * @default true
  246.  *
  247.  * @param Select Help Window
  248.  * @desc When selecting actors and enemies, show the help window?
  249.  * NO - false     YES - true
  250.  * @default true
  251.  *
  252.  * @param User Help Text
  253.  * @desc The singular form of 'User' used in a help window.
  254.  * @default User
  255.  *
  256.  * @param Ally Help Text
  257.  * @desc The singular form of 'Ally' used in a help window.
  258.  * @default Ally
  259.  *
  260.  * @param Allies Help Text
  261.  * @desc The plural form of 'Allies' used in a help window.
  262.  * @default Allies
  263.  *
  264.  * @param Enemy Help Text
  265.  * @desc The singular form of 'Enemy' used in a help window.
  266.  * @default Enemy
  267.  *
  268.  * @param Enemies Help Text
  269.  * @desc The plural form of 'Enemy' used in a help window.
  270.  * @default Enemies
  271.  *
  272.  * @param All Help Text
  273.  * @desc When selecting a entire group of targets.
  274.  * %1 - Target Group (Allies or Enemies)
  275.  * @default All %1
  276.  *
  277.  * @param Random Help Text
  278.  * @desc When selecting a random selection of targets.
  279.  * %1 - Target Group (Allies or Enemies)     %2 - Number
  280.  * @default %2 Random %1
  281.  *
  282.  * @param ---Enemy Select---
  283.  * @default
  284.  *
  285.  * @param Visual Enemy Select
  286.  * @desc Replaces the enemy selection screen with a more visual one.
  287.  * OFF - false     ON - true
  288.  * @default true
  289.  *
  290.  * @param Show Enemy Name
  291.  * @desc Show enemy names with Visual Enemy Select.
  292.  * OFF - false     ON - true
  293.  * @default true
  294.  *
  295.  * @param Show Select Box
  296.  * @desc Show a selection box when selecting enemies.
  297.  * OFF - false     ON - true
  298.  * @default false
  299.  *
  300.  * @param Enemy Font Size
  301.  * @desc Changes the font size used to display enemy names.
  302.  * Default: 28
  303.  * @default 20
  304.  *
  305.  * @param Enemy Auto Select
  306.  * @desc Changes what enemy is automatically selected at first.
  307.  * LEFT - 0     RIGHT - this.furthestRight()
  308.  * @default this.furthestRight()
  309.  *
  310.  * @param ---Actor Select---
  311.  * @default
  312.  *
  313.  * @param Visual Actor Select
  314.  * @desc Allows you to click the actor on screen to select it.
  315.  * OFF - false     ON - true
  316.  * @default true
  317.  *
  318.  * @param ---Battle Log---
  319.  * @default
  320.  *
  321.  * @param Show Emerge Text
  322.  * @desc Shows the battle start text for enemies appearing.
  323.  * OFF - false     ON - true
  324.  * @default false
  325.  *
  326.  * @param Show Pre-Emptive Text
  327.  * @desc Shows the text for getting a pre-emptive attack.
  328.  * OFF - false     ON - true
  329.  * @default true
  330.  *
  331.  * @param Show Surprise Text
  332.  * @desc Shows the text for getting a surprise attack.
  333.  * OFF - false     ON - true
  334.  * @default true
  335.  *
  336.  * @param Optimize Speed
  337.  * @desc Cuts log base line process to optimize the battle speed.
  338.  * OFF - false     ON - true
  339.  * @default true
  340.  *
  341.  * @param Show Action Text
  342.  * @desc Displays full action text or a simplified version of it.
  343.  * SIMPLE - false     FULL - true
  344.  * @default false
  345.  *
  346.  * @param Show State Text
  347.  * @desc Shows all text regarding states.
  348.  * OFF - false     ON - true
  349.  * @default false
  350.  *
  351.  * @param Show Buff Text
  352.  * @desc Shows all text regarding buffs.
  353.  * OFF - false     ON - true
  354.  * @default false
  355.  *
  356.  * @param Show Counter Text
  357.  * @desc Shows text regarding counter attacks.
  358.  * OFF - false     ON - true
  359.  * @default true
  360.  *
  361.  * @param Show Reflect Text
  362.  * @desc Shows text regarding reflected spells.
  363.  * OFF - false     ON - true
  364.  * @default true
  365.  *
  366.  * @param Show Substitute Text
  367.  * @desc Shows text regarding substituted damage.
  368.  * OFF - false     ON - true
  369.  * @default true
  370.  *
  371.  * @param Show Fail Text
  372.  * @desc Shows text regarding failed attacks.
  373.  * OFF - false     ON - true
  374.  * @default false
  375.  *
  376.  * @param Show Critical Text
  377.  * @desc Shows text regarding critical hits.
  378.  * OFF - false     ON - true
  379.  * @default false
  380.  *
  381.  * @param Show Miss Text
  382.  * @desc Shows text regarding missed attacks.
  383.  * OFF - false     ON - true
  384.  * @default false
  385.  *
  386.  * @param Show Evasion Text
  387.  * @desc Shows text regarding evaded attacks.
  388.  * OFF - false     ON - true
  389.  * @default false
  390.  *
  391.  * @param Show HP Text
  392.  * @desc Shows text regarding HP damage or heals.
  393.  * OFF - false     ON - true
  394.  * @default false
  395.  *
  396.  * @param Show MP Text
  397.  * @desc Shows text regarding MP damage or heals.
  398.  * OFF - false     ON - true
  399.  * @default false
  400.  *
  401.  * @param Show TP Text
  402.  * @desc Shows text regarding TP damage or heals.
  403.  * OFF - false     ON - true
  404.  * @default false
  405.  *
  406.  * @help
  407.  * ============================================================================
  408.  * Introduction
  409.  * ============================================================================
  410.  *
  411.  * This plugin alters the various aspects of the default battle system,
  412.  * allowing it to be more streamlined like most modern RPG's and less clunky
  413.  * like older RPG's. This ranges from choosing what text will appear in the
  414.  * battle log window at the top and how it will be displayed.
  415.  *
  416.  * ============================================================================
  417.  * Battle Messages
  418.  * ============================================================================
  419.  *
  420.  * When changing "Terms" and the "Messages" that appear in battle, inserting
  421.  * the following tag anywhere in the message will cause the message to center
  422.  * itself in the battle log.
  423.  *
  424.  *   <CENTER>
  425.  *   This tag must be all caps in order for the battle log window to recognize
  426.  *   it as an instruction to center the displayed battle text message.
  427.  *
  428.  * There are a couple of notetags you can use to change the way certain skills
  429.  * and items will show up incase you don't want a name like 'Harold's Attack'
  430.  * to appear in the name.
  431.  *
  432.  * Skill and Item Notetags:
  433.  *
  434.  *   <Display Text: x>
  435.  *   This will change the text displayed to x.
  436.  *
  437.  *   <Display Icon: x>
  438.  *   This will change the icon displayed to x.
  439.  *
  440.  * ============================================================================
  441.  * Battle Windows
  442.  * ============================================================================
  443.  *
  444.  * There's various options to adjust the window settings found in the battle
  445.  * system to make navigating the battle system more intuitive. Such options
  446.  * include starting the turns with the Actor Command Window instead of the
  447.  * Party Command Window (the Fight/Escape Window). The Party Command Window is
  448.  * still accessible but only by pressing cancel on the first actor's window.
  449.  *
  450.  * ============================================================================
  451.  * Battle Order
  452.  * ============================================================================
  453.  *
  454.  * The battle turn order is also fixed, too. This way, any battlers that Have
  455.  * their AGI value changed over the course of battle will reflect those changes
  456.  * during the current turn rather than the following turn. The action speed
  457.  * calculation can also be adjusted and finetuned to have the random factor of
  458.  * its speed calculation formula removed, too, making AGI actually worthwhile
  459.  * as a tactical parameter.
  460.  *
  461.  * Skill and Item Notetag:
  462.  *   <speed: +x>
  463.  *   <speed: -x>
  464.  *   This lets you break past the editor's limit of -2000 and 2000 allowing you
  465.  *   to set the speed of your actions with more control.
  466.  *
  467.  * ============================================================================
  468.  * Multiple Hits
  469.  * ============================================================================
  470.  *
  471.  * Multi-hit action will no longer end prematurely if the target dies midway
  472.  * through the action. This is done through toggling immortal states. To make
  473.  * use of feature, make sure your database has an Immortal State somewhere. If
  474.  * you do not wish to use this feature, set the Parameter for Immortal State ID
  475.  * to 0 instead.
  476.  *
  477.  * ============================================================================
  478.  * Popup Revamp
  479.  * ============================================================================
  480.  *
  481.  * Although the damage popups may still look the same as the default ones from
  482.  * MV, the process in which they're created is now different to streamline the
  483.  * damage popup process. Before, popups would only appear one a time with a
  484.  * frame's different at minimum in order for them to show. Now, any actions
  485.  * that occur at the same frame will now all show popups at the same frame,
  486.  * making for smoother and less clunky damage popups.
  487.  *
  488.  * ============================================================================
  489.  * Common Events
  490.  * ============================================================================
  491.  *
  492.  * Common Events will now occur at the end of each action regardless of whether
  493.  * or not the enemy party is still alive. With proper placing of the action
  494.  * sequence tags, you can make the skill's common event occur in the middle of
  495.  * an action, too. However, keep in mind if you force an action in the middle
  496.  * of another action, the remainder of the former action's sequence list will
  497.  * become null and void in favor of the new forced action.
  498.  *
  499.  * ============================================================================
  500.  * Casting Animations
  501.  * ============================================================================
  502.  *
  503.  * Casting Animations help provide visual hints for players either by letting
  504.  * them know which battler is going to perform an action or what type of skill
  505.  * that action will be. This plugin enables skills to have casting animations
  506.  * that can be modified universally or customized for each individual skill.
  507.  *
  508.  * Skill Notetag:
  509.  *   <Cast Animation: x>
  510.  *   Sets the skill's cast animation to animation ID x. Setting x to zero will
  511.  *   cause the skill to not have any animaton at all.
  512.  *
  513.  * ============================================================================
  514.  * Changing Battle Systems
  515.  * ============================================================================
  516.  *
  517.  * While the player is not in battle, you can change the battle system using a
  518.  * Plugin Command. With only this plugin, there is only one battle system
  519.  * included: the default battle system.
  520.  *
  521.  * Plugin Command:
  522.  *   setBattleSys DTB      Sets battle system to Default Turn Battle.
  523.  *
  524.  * Other future plugins may include other battle systems that may utilize the
  525.  * Battle Engine Core.
  526.  *
  527.  * ============================================================================
  528.  * Sideview Actions
  529.  * ============================================================================
  530.  *
  531.  * In RPG Maker MV's default battle system, both the sideview and the frontview
  532.  * settings do not display counterattacks, reflected magic attacks, nor any
  533.  * case of substituting for battle members. The Battle Engine Core provides
  534.  * games that are using the sideview settings small amounts of animations to
  535.  * relay information to the player in a more visual sense.
  536.  *
  537.  * Magic Reflection will also display a reflection animation to indicate the
  538.  * battler has reflection properties. This animation can be changed in the
  539.  * parameters, but certain actors, classes, enemies, weapons, armors, and
  540.  * states can display a unique kind of animation for reflection if desired.
  541.  *
  542.  * Actor, Class, Enemy, Weapon, Armor, and State Notetag:
  543.  *   <Reflect Animation ID: x>
  544.  *   Changes the user's reflect animation to x. This will take priority in the
  545.  *   following order: Actor, Class, Enemy, Weapon, Armor, State, Default.
  546.  *
  547.  * Sometimes, you don't want your enemies to be able to move. Or you don't want
  548.  * certain actors to be able to move. They're just stationary for whatever
  549.  * reason. To accomplish that, you can use this notetag to forbid the battler
  550.  * from moving.
  551.  *
  552.  * Actor, Class, Enemy, Weapon, Armor, and State Notetag:
  553.  *   <Sprite Cannot Move>
  554.  *   Prevents the battler's sprite from moving. This will take priority in the
  555.  *   following order: Actor, Class, Enemy, Weapon, Armor, and State. If an
  556.  *   enemy is unable to move when it performs an action, it will flash white as
  557.  *   if it normally does in front view.
  558.  *
  559.  * ============================================================================
  560.  * Custom Sideview Battler Anchor
  561.  * ============================================================================
  562.  *
  563.  * Sideview battlers are generally centered horizontally, and grounded at their
  564.  * feet. However, not all sideview battler spritesheets work this way. In the
  565.  * event you have a sideview battler that doesn't conform to those standards,
  566.  * you can 'anchor' them a different way.
  567.  *
  568.  * Actor, Class, Weapon, Armor, State Notetags:
  569.  *   <Anchor X: y.z>
  570.  *   <Anchor Y: y.z>
  571.  *   This sets the anchor location for the actor's sideview battler at y.z.
  572.  *   By default, the X anchor is 0.5 while the Y anchor is 1.0. If you want
  573.  *   the X anchor to be a bit more to the left, make it less than 0.5. Make it
  574.  *   more than 0.5 to make the X anchor more towards the right. To raise the
  575.  *   Y anchor, set the number value to less than 1.0. Keep adjusting until you
  576.  *   find that perfect anchor setting.
  577.  *
  578.  * If an anchor has multiple traits that yield different anchors, it will be
  579.  * used in a priority list akin to this order:
  580.  *
  581.  *   States
  582.  *   Weapons
  583.  *   Armors
  584.  *   Class
  585.  *   Actor
  586.  *   Default
  587.  *
  588.  * The higher it is on the priority list, the higher its priority.
  589.  *
  590.  * ============================================================================
  591.  * Enemy Attack Animation
  592.  * ============================================================================
  593.  *
  594.  * To give your enemies unique attack animations, you can use this notetag:
  595.  *
  596.  * Enemy Notetag:
  597.  *   <Attack Animation: x>
  598.  *   Replace x with the ID of the battle animation you wish to set as the
  599.  *   enemy's default attack animation.
  600.  *
  601.  * ============================================================================
  602.  * Automatic State Removal Conditions
  603.  * ============================================================================
  604.  *
  605.  * By default, RPG Maker MV's battle system has automatic state removal under
  606.  * three different conditions: none, action end, turn end.
  607.  *
  608.  * None and Turn End are working as intended. However, Action End, however, had
  609.  * the states removed at the start of the battler's action rather than the end.
  610.  * This is changed and updated to occur only at the end of a battler's action.
  611.  *
  612.  * Two more automatic conditions are now added: Action Start and Turn Start.
  613.  * These can be added and implemented using the following notetags:
  614.  *
  615.  * State Notetags:
  616.  *   <Action Start: x>
  617.  *   <Action Start: x to y>
  618.  *   This will cause this state to update its turns remaining at the start of
  619.  *   an action. x is the number of turns it will last. If you use x to y, upon
  620.  *   applying the state, the state will be removed a random number of turns
  621.  *   from x to y.
  622.  *
  623.  *   <Turn Start: x>
  624.  *   <Turn Start: x to y>
  625.  *   This will cause the state to update its turns remaining at the start of a
  626.  *   battle turn. x is the number of turns it will last. If you use x to y,
  627.  *   upon applying the state, the state will be removed a random number of
  628.  *   turns from x to y.
  629.  *
  630.  * States with Action End have a unique trait to them where if the caster of
  631.  * the state is the current active battler (subject) and if the state is then
  632.  * applied on the user itself, they will gain a 'free turn'. The 'free turn' is
  633.  * to mitigate the user from losing 1 duration of the turn since with an Action
  634.  * End timing, they would lose the benefit of being under the state for that
  635.  * turn's timing.
  636.  *
  637.  * ============================================================================
  638.  * Action Sequences
  639.  * ============================================================================
  640.  *
  641.  * The Yanfly Engine Plugins - Battle Engine Core includes the capability of
  642.  * using custom action sequences. Action sequences are basic instructions for
  643.  * the game to creating a customized skill both visually and mechanically.
  644.  * The Battle Engine Core, however, will only include the most basic of action
  645.  * sequences so the instructions on how to create a custom action sequence will
  646.  * be included in the Help file on future extension plugins for this plugin.
  647.  *
  648.  * ============================================================================
  649.  * Changelog
  650.  * ============================================================================
  651.  *
  652.  * Version 1.43a:
  653.  * - Bug fixed to prevent crash if non-existent actions are used.
  654.  * - Optimization update.
  655.  *
  656.  * Version 1.42:
  657.  * - Optimization update.
  658.  *
  659.  * Version 1.41:
  660.  * - Fixed a bug that allowed certain sprites to remain in the active pool
  661.  * while party members were removed midway through battle.
  662.  *
  663.  * Version 1.40:
  664.  * - Updated for RPG Maker MV version 1.3.2.
  665.  *
  666.  * Version 1.39c:
  667.  * - Fixed a bug that caused dead actors to not be a part of action sequence
  668.  * targeting for "Not Focus".
  669.  * - Optimization update.
  670.  * - Updated "queueForceAction" to utilize both numbers and actual targets.
  671.  *
  672.  * Version 1.38a:
  673.  * - Optimization update.
  674.  * - Compatibility update for Selection Control v1.08.
  675.  * - Bug fixed for mirrored animations on enemies.
  676.  *
  677.  * Version 1.37:
  678.  * - Fixed a bug where if the enemy's size is too small, the enemy's name
  679.  * during selection will be cut off.
  680.  *
  681.  * Version 1.36d:
  682.  * - Made an update for the battle background image snaps when there is no
  683.  * battleback being used. This will prevent the player party and enemy troop
  684.  * from appearing in the background snapshot when entering menus mid-battle.
  685.  * - 'Death Break' action sequence now only triggers upon dead status and not
  686.  * an 'or 0 HP' condition.
  687.  * - Updated Forced Action sequencing for more efficiency.
  688.  * - 'Action Times+' traits now work properly for DTB again.
  689.  * - Optimized message displaying for battle log.
  690.  * - Optimized z sorting algorithm for sprites.
  691.  *
  692.  * Verison 1.35d:
  693.  * - Scopes that target a dead ally will automatically target the first dead
  694.  * ally now. Scopes that target all dead allies will lock onto the first dead
  695.  * ally. This will hopefully provide less confusion amongst playing.
  696.  * - Added anti-crash measure for sprite bitmaps.
  697.  * - Added anti-crash measure for faux actions.
  698.  * - Added anti-crash measure to prevent non-existant animations from playing.
  699.  * - Added a check that prevents hidden battlers from appearing when using
  700.  * certain action sequences.
  701.  *
  702.  * Version 1.34a:
  703.  * - Fixed a bug where 'NOT FOCUS' targets were not including dead members.
  704.  * - Fixed a bug where using NOT FOCUS would cause dead targets to be visible.
  705.  *
  706.  * Version 1.33:
  707.  * - Updated for RPG Maker MV version 1.1.0.
  708.  *
  709.  * Version 1.32d:
  710.  * - Fixed a bug that caused a crash when an actor died.
  711.  * - Added a motion engine to be used for future plugins.
  712.  * - Preparation for a future plugin.
  713.  * - <Anchor X: y.z> and <Anchor Y: y.z> notetags for actors are now extended
  714.  * to actors, classes, weapons, armors, and states.
  715.  * - Added <Display Text: x> and <Display Icon: x> notetags for skills and
  716.  * items. These notetags will alter the display name shown and icon shown
  717.  * respectively while performing a skill.
  718.  * - Switched Magic Reflect checking order with Counterattack checking order.
  719.  * This is to give priority to reflected actions over countered actions.
  720.  *
  721.  * Version 1.31b:
  722.  * - States with Action End now have a unique trait to them where if the caster
  723.  * of the state is the current active battler (subject) and if the state is
  724.  * then applied on the user itself, they will gain a 'free turn'. The 'free
  725.  * turn' is to mitigate the user from losing 1 duration of the turn since with
  726.  * an Action End timing, they would lose the benefit of being under the state
  727.  * for that turn's timing.
  728.  * - Added failsafes for Free Turns in case other plugins have overwritten the
  729.  * on battle start functions.
  730.  * - Added a compatibility update to Animated SV Enemies for dead motion.
  731.  *
  732.  * Version 1.30:
  733.  * - Optimization update.
  734.  * - Fixed a bug that prevented added state effects be unable to apply if they
  735.  * are an added Death state.
  736.  * - Battlelog lines are now able to display text codes.
  737.  *
  738.  * Version 1.29:
  739.  * - Fixed a bug with the 'else if' action sequences not working in the right
  740.  * order of sequence conditions.
  741.  *
  742.  * Version 1.28d:
  743.  * - Fixed a bug if instant casting a skill that would make an opponent battler
  744.  * to force an action to end incorrectly. Thanks to DoubleX for the fix.
  745.  * - Fixed a bug with mouse over not working properly.
  746.  * - Fixed a bug regarding forced actions that will cause the battle to freeze
  747.  * if the forced action causes the main active subject to leave the battle.
  748.  * - Fixed a bug with timed states not updating their turns properly.
  749.  * - Changed priority of IF action sequences to higher to no longer interfere
  750.  * other action sequences.
  751.  *
  752.  * Version 1.27:
  753.  * - Mechanic change. This will only affect those using turn-based state timing
  754.  * mechanics. Turn End state updates are now shifted from Turn End to occur at
  755.  * Regeneration timing to have a more synchronized aspect. The timings are very
  756.  * close so there's next to no notice in difference. Buff turn updates are also
  757.  * moved to the regeneration timing, too.
  758.  *
  759.  * Version 1.26:
  760.  * - Added 'Mouse Over' parameter to Selection Help. This parameter enables
  761.  * mouse users to simply hover over the enemy to select them rather than having
  762.  * to click an enemy twice to select them.
  763.  *
  764.  * Version 1.25f:
  765.  * - Added failsafes for Forced Action queues.
  766.  * - Added 'Show Select Box' parameter when selecting enemies.
  767.  * - Fixed a bug that caused End Turn events to not function properly.
  768.  * - Battle animations, by default, are positioned relative to the base bitmap
  769.  * for its target sprite. However, actor sprites do not have a base bitmap and
  770.  * therefore, battle animations, regardless of position, will always target the
  771.  * actor sprite's feet. This update now gives actor sprites a base bitmap.
  772.  * - Readjusted sprite width and sprite height calculations.
  773.  * - Added a failsafe for when no sideview actor graphics are used.
  774.  *
  775.  * Version 1.24:
  776.  * - Implemented a Forced Action queue list. This means if a Forced Action
  777.  * takes place in the middle of an action, the action will resume after the
  778.  * forced action finishes rather than cancels it out like MV does.
  779.  *
  780.  * Version 1.23:
  781.  * - Fixed a bug that didn't regenerate HP/MP/TP properly for tick-based.
  782.  *
  783.  * Version 1.22:
  784.  * - Fixed a bug within MV that caused Forced Actions at Turn End to prompt and
  785.  * trigger all turn-end related activities (such as regeneration and state turn
  786.  * updating).
  787.  * - Made a mechanic change so that Action Start and Action End state turns do
  788.  * not update their turns through forced actions.
  789.  *
  790.  * Version 1.21:
  791.  * - Fixed a bug where states Action End weren't going down properly with DTB.
  792.  *
  793.  * Version 1.20:
  794.  * - Fixed a bug where revived actors using instant cast aren't properly set to
  795.  * use actions immediately.
  796.  *
  797.  * Version 1.19:
  798.  * - Added <Attack Animation: x> notetag for enemies.
  799.  * - Added 'AI Self Turns' for Tick-Based Battles. Enemies can now have their
  800.  * A.I. revolve around their own individual turns rather than the battle's.
  801.  * - Mechanic change for states. Following suit with the change to Action End
  802.  * removal, there are now two more conditions added: Action Start, Turn Start.
  803.  * - Added <Action Start: x>, <Action Start: x to y>, <Turn Start: x>, and
  804.  * <Turn Start: x to y> notetags for automatic state removal.
  805.  *
  806.  * Version 1.18:
  807.  * - Fixed a bug with irregular targeting scopes.
  808.  * - Fixed an MV-related bug with Recover All event not refreshing battlers.
  809.  *
  810.  * Version 1.17b:
  811.  * - Fixed a bug with action end states to remove multiple at once.
  812.  * - Fixed a visual error with flinching sprites.
  813.  * - Added 'Current Max' parameter to change HP current/max display in battle.
  814.  * - Mechanic change for states that update on Action End to end at the end of
  815.  * a battler's turn instead of at the start.
  816.  * - Began preparations for another battle system.
  817.  *
  818.  * Version 1.16:
  819.  * - Fixed an issue with mirrored enemies having mirrored state icons.
  820.  *
  821.  * Version 1.15a:
  822.  * - Fixed a bug revolving the status window not updating.
  823.  * - Updated default home position formula to better fit other party sizes.
  824.  * New Home Position X:
  825.  *   screenWidth - 16 - (maxSize + 2) * 32 + index * 32
  826.  * New Home Position Y:
  827.  *   screenHeight - statusHeight - maxSize * 48 + (index+1) * 48 - 16
  828.  *
  829.  * Version 1.14:
  830.  * - Fixed a bug with Forced Actions locking out the battle.
  831.  * - New mechanic: For tick-based battle systems, states with action-end will
  832.  * go down in turns based on how many actions took place for the actor instead.
  833.  * Previously, they were indistinguishable from states with Turn End removal.
  834.  * - New mechanic: Using Instant Skills/Items from YEP_InstantCast.js will also
  835.  * cause states with action-end to go down in turns upon using actions.
  836.  *
  837.  * Version 1.13a:
  838.  * - Fixed a bug that made battlebacks disappear.
  839.  * - Reworked visual enemy selection.
  840.  * - Victory phase doesn't immediately display level up changes in battle
  841.  * status window.
  842.  * - Fixed a bug with the visual enemy select showing dead enemy names.
  843.  *
  844.  * Version 1.12b:
  845.  * - If the Battle HUD has been hidden for whatever reason during the victory
  846.  * sequence, it will be returned.
  847.  * - Added <speed: +x> and <speed: -x> notetags to break past editor limits.
  848.  * - Added new conditions where the battle won't end until all action sequences
  849.  * have been fulfilled.
  850.  *
  851.  * Version 1.11:
  852.  * - Fixed a bug that didn't show HP/MP Regeneration.
  853.  *
  854.  * Version 1.10:
  855.  * - Removed immortal state dependancy. Immortality is now its own setting.
  856.  * - Added more abbreviated variables for action speed calculation.
  857.  * - Fixed a bug where all-scope attacks would reveal Appear-Halfway enemies.
  858.  * - Fixed a bug where the battle wouldn't end if the final enemy was killed
  859.  * by state damage.
  860.  *
  861.  * Version 1.09:
  862.  * - Fixed a undefined actor bug for refreshing the status window.
  863.  * - Added 'Show Shadows' parameter to the plugin settings.
  864.  * - Reworked the default action sequences so that forced actions do not appear
  865.  * on top of each other and party-heal animations occur simultaneously.
  866.  *
  867.  * Version 1.08:
  868.  * - Fixed a bug where battlers gaining HP/MP in the damage formula for
  869.  * themselves wouldn't trigger popups.
  870.  * - Fixed a bug where if the party failed to escape from battle, states that
  871.  * would be removed by battle still get removed. *Fixed by Emjenoeg*
  872.  * - Fixed a bug where instant death skills didn't work.
  873.  * - Changed Sprite Priority settings to decide whether actors, enemies, or
  874.  * neither would always be on top.
  875.  *
  876.  * Version 1.07:
  877.  * - Optimized status window to refresh at a minimum.
  878.  * - Set up frame work for future plugins:
  879.  * - Added 'Escape Ratio' and 'Fail Escape Boost' to parameters to allow users
  880.  * to set the escape ratio they want.
  881.  * - Added 'Front Sprite Priority' and 'Side Sprite Priority' to parameters to
  882.  * dictate if actor sprites are always on top.
  883.  * - Added 'Tick-Settings' category for tick-based battle systems.
  884.  *
  885.  * Version 1.06:
  886.  * - Fixed a bug that causes dead actors at the start of battle to not spawn.
  887.  * - Fixed a bug where the help window on an empty slot would show the
  888.  * previous skill's message.
  889.  *
  890.  * Version 1.05:
  891.  * - Added new target typing: Character X, which allows you to select
  892.  * specifically the actor with an actor ID of X if he/she/it is in the party.
  893.  * - Fixed a bug that prevented Miss and Evade popups from showing.
  894.  *
  895.  * Version 1.04:
  896.  * - Fixed a bug where popups didn't show under certain animation types.
  897.  * - Fixed certain battler motions from not refreshing correctly.
  898.  * - Actions with no scope will not trigger the confirmation selection window.
  899.  *
  900.  * Version 1.03:
  901.  * - Added 'Wait for Effect' action sequence.
  902.  * - Actions now wait for effects (such as collapsing) to be done before
  903.  * continuing on with battle or to end battle.
  904.  *
  905.  * Version 1.02:
  906.  * - Fixed a bug where the help window would retain descriptions on no skills.
  907.  * - Synched up weapons with actor sprites so they would occur simultaneously.
  908.  * - Fixed an issue where requesting certain motions from enemies that don't
  909.  * exist would cause them to crash.
  910.  *
  911.  * Version 1.01:
  912.  * - Skills and items that affect both HP and MP will now show popups for both.
  913.  *
  914.  * Version 1.00:
  915.  * - Finished plugin!
  916.  */
  917. //=============================================================================
  918.  
  919. //=============================================================================
  920. // Parameter Variables
  921. //=============================================================================
  922.  
  923. Yanfly.Parameters = PluginManager.parameters('YEP_BattleEngineCore');
  924. Yanfly.Param = Yanfly.Param || {};
  925.  
  926. Yanfly.Param.BECSystem = String(Yanfly.Parameters['Default System']);
  927. Yanfly.Param.BECEscRatio = String(Yanfly.Parameters['Escape Ratio']);
  928. Yanfly.Param.BECEscFail = String(Yanfly.Parameters['Fail Escape Boost']);
  929. Yanfly.Param.CastCertHit = Number(Yanfly.Parameters['Certain Hit Animation']);
  930. Yanfly.Param.CastPhysical = Number(Yanfly.Parameters['Physical Animation']);
  931. Yanfly.Param.CastMagical = Number(Yanfly.Parameters['Magical Animation']);
  932. Yanfly.Param.EnemyAtkAni = Number(Yanfly.Parameters['Enemy Attack Animation']);
  933. Yanfly.Param.BECOptSpeed = String(Yanfly.Parameters['Optimize Speed']);
  934. Yanfly.Param.BECOptSpeed = eval(Yanfly.Param.BECOptSpeed);
  935. Yanfly.Param.BECEmergeText = String(Yanfly.Parameters['Show Emerge Text']);
  936. Yanfly.Param.BECEmergeText = eval(Yanfly.Param.BECEmergeText);
  937. Yanfly.Param.BECPreEmpText = String(Yanfly.Parameters['Show Pre-Emptive Text']);
  938. Yanfly.Param.BECPreEmpText = eval(Yanfly.Param.BECPreEmpText);
  939. Yanfly.Param.BECSurpText = String(Yanfly.Parameters['Show Surprise Text']);
  940. Yanfly.Param.BECSurpText = eval(Yanfly.Param.BECSurpText);
  941. Yanfly.Param.BECPopupOverlap = String(Yanfly.Parameters['Popup Overlap Rate']);
  942. Yanfly.Param.BECPopupOverlap = eval(Yanfly.Param.BECPopupOverlap);
  943. Yanfly.Param.BECNewPopBottom = String(Yanfly.Parameters['Newest Popup Bottom']);
  944. Yanfly.Param.BECNewPopBottom = eval(Yanfly.Param.BECNewPopBottom);
  945. Yanfly.Param.BECStartActCmd = String(Yanfly.Parameters['Start Actor Command']);
  946. Yanfly.Param.BECStartActCmd = eval(Yanfly.Param.BECStartActCmd);
  947. Yanfly.Param.BECCurMax = eval(String(Yanfly.Parameters['Current Max']));
  948. Yanfly.Param.BECSelectHelp = String(Yanfly.Parameters['Select Help Window']);
  949. Yanfly.Param.BECSelectHelp = eval(Yanfly.Param.BECSelectHelp);
  950. Yanfly.Param.BECHelpUserTx = String(Yanfly.Parameters['User Help Text']);
  951. Yanfly.Param.BECHelpAllyTx = String(Yanfly.Parameters['Ally Help Text']);
  952. Yanfly.Param.BECHelpAlliesTx = String(Yanfly.Parameters['Allies Help Text']);
  953. Yanfly.Param.BECHelpEnemyTx = String(Yanfly.Parameters['Enemy Help Text']);
  954. Yanfly.Param.BECHelpEnemiesTx = String(Yanfly.Parameters['Enemies Help Text']);
  955. Yanfly.Param.BECHelpAllTx = String(Yanfly.Parameters['All Help Text']);
  956. Yanfly.Param.BECHelpRandTx = String(Yanfly.Parameters['Random Help Text']);
  957. Yanfly.Param.BECFrontPosX = String(Yanfly.Parameters['Front Position X']);
  958. Yanfly.Param.BECFrontPosY = String(Yanfly.Parameters['Front Position Y']);
  959. Yanfly.Param.BECFrontSprite = String(Yanfly.Parameters['Front Actor Sprite']);
  960. Yanfly.Param.BECFrontSprite = eval(Yanfly.Param.BECFrontSprite);
  961. Yanfly.Param.BECFrSpPrio = String(Yanfly.Parameters['Front Sprite Priority']);
  962. Yanfly.Param.BECHomePosX = String(Yanfly.Parameters['Home Position X']);
  963. Yanfly.Param.BECHomePosY = String(Yanfly.Parameters['Home Position Y']);
  964. Yanfly.Param.BECSideSpPrio = String(Yanfly.Parameters['Side Sprite Priority']);
  965. Yanfly.Param.BECSideSpPrio = eval(Yanfly.Param.BECSideSpPrio);
  966. Yanfly.Param.BECAnchorX = Number(Yanfly.Parameters['Default X Anchor']);
  967. Yanfly.Param.BECAnchorY = Number(Yanfly.Parameters['Default Y Anchor']);
  968. Yanfly.Param.BECStepDist = Number(Yanfly.Parameters['Step Distance']);
  969. Yanfly.Param.BECFlinchDist = Number(Yanfly.Parameters['Flinch Distance']);
  970. Yanfly.Param.BECShowShadows = String(Yanfly.Parameters['Show Shadows']);
  971. Yanfly.Param.BECShowShadows = eval(Yanfly.Param.BECShowShadows);
  972. Yanfly.Param.BECPopupDur = Number(Yanfly.Parameters['Popup Duration']);
  973. Yanfly.Param.BECCritPopup = String(Yanfly.Parameters['Critical Popup']);
  974. Yanfly.Param.BECCritDur = Number(Yanfly.Parameters['Critical Duration']);
  975. Yanfly.Param.BECActionSpeed = String(Yanfly.Parameters['Action Speed']);
  976. Yanfly.Param.BECReflectAni = Number(Yanfly.Parameters['Reflect Animation']);
  977. Yanfly.Param.BECMotionWait = String(Yanfly.Parameters['Motion Waiting']);
  978. Yanfly.Param.BECMotionWait = eval(Yanfly.Param.BECMotionWait);
  979. Yanfly.Param.BECTimeStates = String(Yanfly.Parameters['Timed States']);
  980. Yanfly.Param.BECTimeStates = eval(Yanfly.Param.BECTimeStates);
  981. Yanfly.Param.BECTimeBuffs = String(Yanfly.Parameters['Timed Buffs']);
  982. Yanfly.Param.BECTimeBuffs = eval(Yanfly.Param.BECTimeBuffs);
  983. Yanfly.Param.BECTurnTime = Number(Yanfly.Parameters['Turn Time']);
  984. Yanfly.Param.BECAISelfTurn = eval(String(Yanfly.Parameters['AI Self Turns']));
  985. Yanfly.Param.BECLowerWindows = String(Yanfly.Parameters['Lower Windows']);
  986. Yanfly.Param.BECLowerWindows = eval(Yanfly.Param.BECLowerWindows);
  987. Yanfly.Param.BECSelectMouseOver = eval(String(Yanfly.Parameters['Mouse Over']));
  988. Yanfly.Param.BECEnemySelect = String(Yanfly.Parameters['Visual Enemy Select']);
  989. Yanfly.Param.BECEnemySelect = eval(Yanfly.Param.BECEnemySelect);
  990. Yanfly.Param.BECActorSelect = String(Yanfly.Parameters['Visual Actor Select']);
  991. Yanfly.Param.BECActorSelect = eval(Yanfly.Param.BECActorSelect);
  992. Yanfly.Param.BECWindowRows = Number(Yanfly.Parameters['Window Rows']);
  993. Yanfly.Param.BECEnemyFontSize = Number(Yanfly.Parameters['Enemy Font Size']);
  994. Yanfly.Param.BECShowEnemyName = String(Yanfly.Parameters['Show Enemy Name']);
  995. Yanfly.Param.BECShowEnemyName = eval(Yanfly.Param.BECShowEnemyName);
  996. Yanfly.Param.BECShowSelectBox = String(Yanfly.Parameters['Show Select Box']);
  997. Yanfly.Param.BECShowSelectBox = eval(Yanfly.Param.BECShowSelectBox);
  998. Yanfly.Param.BECEnemyAutoSel = String(Yanfly.Parameters['Enemy Auto Select']);
  999. Yanfly.Param.BECCommandAlign = String(Yanfly.Parameters['Command Alignment']);
  1000. Yanfly.Param.BECCommandRows = Number(Yanfly.Parameters['Command Window Rows']);
  1001. Yanfly.Param.BECAniBaseDel = Number(Yanfly.Parameters['Animation Base Delay']);
  1002. Yanfly.Param.BECAniNextDel = Number(Yanfly.Parameters['Animation Next Delay']);
  1003.  
  1004. Yanfly.Param.BECFullActText = String(Yanfly.Parameters['Show Action Text']);
  1005. Yanfly.Param.BECFullActText = eval(Yanfly.Param.BECFullActText);
  1006. Yanfly.Param.BECShowCntText = String(Yanfly.Parameters['Show Counter Text']);
  1007. Yanfly.Param.BECShowCntText = eval(Yanfly.Param.BECShowCntText);
  1008. Yanfly.Param.BECShowRflText = String(Yanfly.Parameters['Show Reflect Text']);
  1009. Yanfly.Param.BECShowRflText = eval(Yanfly.Param.BECShowRflText);
  1010. Yanfly.Param.BECShowSubText = String(Yanfly.Parameters['Show Substitute Text']);
  1011. Yanfly.Param.BECShowSubText = eval(Yanfly.Param.BECShowSubText);
  1012. Yanfly.Param.BECShowFailText = String(Yanfly.Parameters['Show Fail Text']);
  1013. Yanfly.Param.BECShowFailText = eval(Yanfly.Param.BECShowFailText);
  1014. Yanfly.Param.BECShowCritText = String(Yanfly.Parameters['Show Critical Text']);
  1015. Yanfly.Param.BECShowCritText = eval(Yanfly.Param.BECShowCritText);
  1016. Yanfly.Param.BECShowMissText = String(Yanfly.Parameters['Show Miss Text']);
  1017. Yanfly.Param.BECShowMissText = eval(Yanfly.Param.BECShowMissText);
  1018. Yanfly.Param.BECShowEvaText = String(Yanfly.Parameters['Show Evasion Text']);
  1019. Yanfly.Param.BECShowEvaText = eval(Yanfly.Param.BECShowEvaText);
  1020. Yanfly.Param.BECShowHpText = String(Yanfly.Parameters['Show HP Text']);
  1021. Yanfly.Param.BECShowHpText = eval(Yanfly.Param.BECShowHpText);
  1022. Yanfly.Param.BECShowMpText = String(Yanfly.Parameters['Show MP Text']);
  1023. Yanfly.Param.BECShowMpText = eval(Yanfly.Param.BECShowMpText);
  1024. Yanfly.Param.BECShowTpText = String(Yanfly.Parameters['Show TP Text']);
  1025. Yanfly.Param.BECShowTpText = eval(Yanfly.Param.BECShowTpText);
  1026. Yanfly.Param.BECShowStateText = String(Yanfly.Parameters['Show State Text']);
  1027. Yanfly.Param.BECShowStateText = eval(Yanfly.Param.BECShowStateText);
  1028. Yanfly.Param.BECShowBuffText = String(Yanfly.Parameters['Show Buff Text']);
  1029. Yanfly.Param.BECShowBuffText = eval(Yanfly.Param.BECShowBuffText);
  1030.  
  1031. //=============================================================================
  1032. // DataManager
  1033. //=============================================================================
  1034.  
  1035. Yanfly.BEC.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  1036. DataManager.isDatabaseLoaded = function() {
  1037.   if (!Yanfly.BEC.DataManager_isDatabaseLoaded.call(this)) return false;
  1038.   if (!Yanfly._loaded_YEP_BattleEngineCore) {
  1039.     this.processMELODYNotetags($dataSkills);
  1040.     this.processMELODYNotetags($dataItems);
  1041.     this.processBECNotetags1($dataSkills);
  1042.     this.processBECNotetags2($dataSkills);
  1043.     this.processBECNotetags2($dataItems);
  1044.     this.processBECNotetags3($dataEnemies);
  1045.     this.processBECNotetags4($dataActors);
  1046.     this.processBECNotetags4($dataClasses);
  1047.     this.processBECNotetags4($dataWeapons);
  1048.     this.processBECNotetags4($dataArmors);
  1049.     this.processBECNotetags4($dataEnemies);
  1050.     this.processBECNotetags4($dataStates);
  1051.     this.processBECNotetags5($dataActors, true);
  1052.     this.processBECNotetags5($dataClasses, false);
  1053.     this.processBECNotetags5($dataWeapons, false);
  1054.     this.processBECNotetags5($dataArmors, false);
  1055.     this.processBECNotetags5($dataStates, false);
  1056.     this.processBECNotetags6($dataStates);
  1057.     Yanfly._loaded_YEP_BattleEngineCore = true;
  1058.   }
  1059.   return true;
  1060. };
  1061.  
  1062. DataManager.processMELODYNotetags = function(group) {
  1063.   for (var n = 1; n < group.length; n++) {
  1064.     var obj = group[n];
  1065.     if (obj.actionsMade) continue;
  1066.     obj.actionsMade = true;
  1067.     var notedata = obj.note.split(/[\r\n]+/);
  1068.  
  1069.     var actionType = 0;
  1070.     this.setDefaultActions(obj);
  1071.  
  1072.     for (var i = 0; i < notedata.length; i++) {
  1073.       var line = notedata[i];
  1074.       if (line.match(/<(?:SETUP ACTION|setup)>/i)) {
  1075.         actionType = 1;
  1076.         obj.setupActions = [];
  1077.       } else if (line.match(/<\/(?:SETUP ACTION|setup)>/i)) {
  1078.         var actionType = 0;
  1079.       } else if (line.match(/<(?:WHOLE ACTION|whole)>/i)) {
  1080.         actionType = 2;
  1081.         obj.wholeActions = [];
  1082.       } else if (line.match(/<\/(?:WHOLE ACTION|whole)>/i)) {
  1083.         var actionType = 0;
  1084.       } else if (line.match(/<(?:TARGET ACTION|target)>/i)) {
  1085.         actionType = 3;
  1086.         obj.targetActions = [];
  1087.       } else if (line.match(/<\/(?:TARGET ACTION|target)>/i)) {
  1088.         var actionType = 0;
  1089.       } else if (line.match(/<(?:FOLLOW ACTION|follow)>/i)) {
  1090.         actionType = 4;
  1091.         obj.followActions = [];
  1092.       } else if (line.match(/<\/(?:FOLLOW ACTION|follow)>/i)) {
  1093.         var actionType = 0;
  1094.       } else if (line.match(/<(?:FINISH ACTION|finish)>/i)) {
  1095.         actionType = 5;
  1096.         obj.finishActions = [];
  1097.       } else if (line.match(/<\/(?:FINISH ACTION|finish)>/i)) {
  1098.         var actionType = 0;
  1099.       } else {
  1100.         this.convertSequenceLine(obj, line, actionType);
  1101.       }
  1102.     }
  1103.   }
  1104. };
  1105.  
  1106. Yanfly.BEC.DefaultActionSetup = [
  1107.     ['CLEAR BATTLE LOG'],
  1108.     ['DISPLAY ACTION'],
  1109.     ['IMMORTAL', ['TARGETS', 'TRUE']],
  1110.     ['PERFORM START'],
  1111.     ['WAIT FOR MOVEMENT'],
  1112.     ['CAST ANIMATION'],
  1113.     ['WAIT FOR ANIMATION']
  1114. ];
  1115. Yanfly.BEC.DefaultActionWhole = [
  1116.     ['PERFORM ACTION'],
  1117. ];
  1118. Yanfly.BEC.DefaultActionTarget = [
  1119.     ['PERFORM ACTION'],
  1120. ];
  1121. if (Yanfly.Param.BECMotionWait) {
  1122.   Yanfly.BEC.DefaultActionWhole.push(['MOTION WAIT', ['USER']]);
  1123.   Yanfly.BEC.DefaultActionTarget.push(['MOTION WAIT', ['USER']]);
  1124. } else {
  1125.   Yanfly.BEC.DefaultActionWhole.push(['WAIT', [10]]);
  1126.   Yanfly.BEC.DefaultActionTarget.push(['WAIT', [10]]);
  1127. };
  1128. Yanfly.BEC.DefaultActionWhole.push(['ACTION ANIMATION']);
  1129. Yanfly.BEC.DefaultActionWhole.push(['WAIT FOR ANIMATION']);
  1130. Yanfly.BEC.DefaultActionTarget.push(['ACTION ANIMATION']);
  1131. Yanfly.BEC.DefaultActionTarget.push(['WAIT FOR ANIMATION']);
  1132. Yanfly.BEC.DefaultActionFollow = [
  1133. ];
  1134. Yanfly.BEC.DefaultActionFinish = [
  1135.     ['IMMORTAL', ['TARGETS', 'FALSE']],
  1136.     ['WAIT FOR NEW LINE'],
  1137.     ['CLEAR BATTLE LOG'],
  1138.     ['PERFORM FINISH'],
  1139.     ['WAIT FOR MOVEMENT'],
  1140.     ['WAIT FOR EFFECT'],
  1141.     ['ACTION COMMON EVENT'],
  1142. ];
  1143. DataManager.setDefaultActions = function(obj) {
  1144.     obj.setupActions = Yanfly.BEC.DefaultActionSetup.slice();
  1145.     if (this.isWholeAction(obj)) {
  1146.       obj.wholeActions = Yanfly.BEC.DefaultActionWhole.slice();
  1147.       this.addActionEffects(obj, obj.wholeActions);
  1148.       obj.targetActions = [];
  1149.     } else {
  1150.       obj.wholeActions = [];
  1151.       obj.targetActions = Yanfly.BEC.DefaultActionTarget.slice();
  1152.       this.addActionEffects(obj, obj.targetActions);
  1153.     }
  1154.     obj.followActions = Yanfly.BEC.DefaultActionFollow.slice();
  1155.     obj.finishActions = Yanfly.BEC.DefaultActionFinish.slice();
  1156. };
  1157.  
  1158. DataManager.isWholeAction = function(obj) {
  1159.   if (obj.animationId > 0 && $dataAnimations[obj.animationId]) {
  1160.     var animation = $dataAnimations[obj.animationId];
  1161.     if (animation.position === 3) return true;
  1162.     if (animation.position !== 3 && [2, 8, 10].contains(obj.scope)) return true;
  1163.   }
  1164.   return false;
  1165. };
  1166.  
  1167. DataManager.addActionEffects = function(obj, array) {
  1168.     for (;;) {
  1169.       array[array.length] = ['ACTION EFFECT'];
  1170.       array[array.length] = ['DEATH BREAK'];
  1171.       obj.repeats -= 1;
  1172.       if (obj.repeats <= 0) break;
  1173.       array[array.length] = ['WAIT', [8]];
  1174.     }
  1175.     obj.repeats = 1;
  1176. };
  1177.  
  1178. Yanfly.BEC.SeqType6 =
  1179.   /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i;
  1180. Yanfly.BEC.SeqType5 =
  1181.   /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i;
  1182. Yanfly.BEC.SeqType4 =
  1183.   /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*),[ ](.*)/i;
  1184. Yanfly.BEC.SeqType3 =
  1185.   /[ ]*(.*):[ ](.*),[ ](.*),[ ](.*)/i;
  1186. Yanfly.BEC.SeqType2 =
  1187.   /[ ]*(.*):[ ](.*),[ ](.*)/i;
  1188. Yanfly.BEC.SeqType1 =
  1189.   /[ ]*(.*):[ ](.*)/i;
  1190. Yanfly.BEC.SeqType0 =
  1191.   /[ ]*(.*)/i;
  1192. DataManager.convertSequenceLine = function(obj, line, actionType) {
  1193.   if (actionType <= 0 || actionType > 5) return;
  1194.   Yanfly.BEC.SeqType;
  1195.   var seqArgs;
  1196.   if (line.match(Yanfly.BEC.SeqType6)) {
  1197.     Yanfly.BEC.SeqType = RegExp.$1;
  1198.     seqArgs =
  1199.       [RegExp.$2, RegExp.$3, RegExp.$4, RegExp.$5, RegExp.$6, RegExp.$7];
  1200.   } else if (line.match(Yanfly.BEC.SeqType5)) {
  1201.     Yanfly.BEC.SeqType = RegExp.$1;
  1202.     seqArgs = [RegExp.$2, RegExp.$3, RegExp.$4, RegExp.$5, RegExp.$6];
  1203.   } else if (line.match(Yanfly.BEC.SeqType4)) {
  1204.     Yanfly.BEC.SeqType = RegExp.$1;
  1205.     seqArgs = [RegExp.$2, RegExp.$3, RegExp.$4, RegExp.$5];
  1206.   } else if (line.match(Yanfly.BEC.SeqType3)) {
  1207.     Yanfly.BEC.SeqType = RegExp.$1;
  1208.     seqArgs = [RegExp.$2, RegExp.$3, RegExp.$4];
  1209.   } else if (line.match(Yanfly.BEC.SeqType2)) {
  1210.     Yanfly.BEC.SeqType = RegExp.$1;
  1211.     seqArgs = [RegExp.$2, RegExp.$3];
  1212.   } else if (line.match(Yanfly.BEC.SeqType1)) {
  1213.     Yanfly.BEC.SeqType = RegExp.$1;
  1214.     seqArgs = [RegExp.$2];
  1215.   } else if (line.match(Yanfly.BEC.SeqType0)) {
  1216.     Yanfly.BEC.SeqType = RegExp.$1;
  1217.     seqArgs = [];
  1218.   } else {
  1219.     return;
  1220.   }
  1221.   var array = [Yanfly.BEC.SeqType, seqArgs];
  1222.   if (actionType === 1) obj.setupActions[obj.setupActions.length] = array;
  1223.   if (actionType === 2) obj.wholeActions[obj.wholeActions.length] = array;
  1224.   if (actionType === 3) obj.targetActions[obj.targetActions.length] = array;
  1225.   if (actionType === 4) obj.followActions[obj.followActions.length] = array;
  1226.   if (actionType === 5) obj.finishActions[obj.finishActions.length] = array;
  1227. };
  1228.  
  1229. DataManager.processBECNotetags1 = function(group) {
  1230.   var note1 = /<(?:CAST ANIMATION|cast ani):[ ](\d+)>/i;
  1231.   for (var n = 1; n < group.length; n++) {
  1232.     var obj = group[n];
  1233.     var notedata = obj.note.split(/[\r\n]+/);
  1234.  
  1235.     obj.castAnimation = 0;
  1236.     if (obj.hitType === 0) obj.castAnimation = Yanfly.Param.CastCertHit;
  1237.     if (obj.hitType === 1) obj.castAnimation = Yanfly.Param.CastPhysical;
  1238.     if (obj.hitType === 2) obj.castAnimation = Yanfly.Param.CastMagical;
  1239.  
  1240.     for (var i = 0; i < notedata.length; i++) {
  1241.       var line = notedata[i];
  1242.       if (line.match(note1)) {
  1243.         obj.castAnimation = parseInt(RegExp.$1);
  1244.       }
  1245.     }
  1246.   }
  1247. };
  1248.  
  1249. DataManager.processBECNotetags2 = function(group) {
  1250.   var note1 = /<(?:ACTION COPY):[ ](.*):[ ]*(\d+)>/i;
  1251.   var note2 = /<(?:SPEED):[ ]([\+\-]\d+)>/i;
  1252.   var note3 = /<(?:DISPLAY NAME|DISPLAY TEXT):[ ](.*)>/i;
  1253.   var note4 = /<(?:DISPLAY ICON):[ ](\d+)>/i;
  1254.   for (var n = 1; n < group.length; n++) {
  1255.     var obj = group[n];
  1256.     var notedata = obj.note.split(/[\r\n]+/);
  1257.  
  1258.     obj.battleDisplayText = obj.name;
  1259.     obj.battleDisplayIcon = obj.iconIndex;
  1260.  
  1261.     for (var i = 0; i < notedata.length; i++) {
  1262.       var line = notedata[i];
  1263.       if (line.match(note1)) {
  1264.         var text = String(RegExp.$1).toUpperCase();
  1265.         var target;
  1266.         if (['I', 'ITEM'].contains(text)) {
  1267.           target = $dataItems[parseInt(RegExp.$2)];
  1268.         } else if (['S', 'SKILL'].contains(text)) {
  1269.           target = $dataSkills[parseInt(RegExp.$2)];
  1270.         }
  1271.         if (target) {
  1272.           obj.setupActions = target.setupActions.slice();
  1273.           obj.wholeActions = target.wholeActions.slice();
  1274.           obj.targetActions = target.targetActions.slice();
  1275.           obj.followActions = target.followActions.slice();
  1276.           obj.finishActions = target.finishActions.slice();
  1277.         }
  1278.       } else if (line.match(note2)) {
  1279.         obj.speed = parseInt(RegExp.$1);
  1280.       } else if (line.match(note3)) {
  1281.         obj.battleDisplayText = String(RegExp.$1);
  1282.       } else if (line.match(note4)) {
  1283.         obj.battleDisplayIcon = parseInt(RegExp.$1);
  1284.       }
  1285.     }
  1286.   }
  1287. };
  1288.  
  1289. DataManager.processBECNotetags3 = function(group) {
  1290.   var note1 = /<(?:ATTACK ANIMATION|attack ani):[ ](\d+)>/i;
  1291.   for (var n = 1; n < group.length; n++) {
  1292.     var obj = group[n];
  1293.     var notedata = obj.note.split(/[\r\n]+/);
  1294.  
  1295.     obj.attackAnimationId = Yanfly.Param.EnemyAtkAni;
  1296.  
  1297.     for (var i = 0; i < notedata.length; i++) {
  1298.       var line = notedata[i];
  1299.       if (line.match(note1)) {
  1300.         obj.attackAnimationId = parseInt(RegExp.$1);
  1301.       }
  1302.     }
  1303.   }
  1304. };
  1305.  
  1306. DataManager.processBECNotetags4 = function(group) {
  1307.   var note1 = /<(?:REFLECT ANIMATION|reflect ani):[ ](\d+)>/i;
  1308.   for (var n = 1; n < group.length; n++) {
  1309.     var obj = group[n];
  1310.     var notedata = obj.note.split(/[\r\n]+/);
  1311.  
  1312.     obj.reflectAnimationId = 0;
  1313.     obj.spriteCannotMove = false;
  1314.  
  1315.     for (var i = 0; i < notedata.length; i++) {
  1316.       var line = notedata[i];
  1317.       if (line.match(note1)) {
  1318.         obj.reflectAnimationId = parseInt(RegExp.$1);
  1319.       } else if (line.match(/<(?:SPRITE CANNOT MOVE)>/i)) {
  1320.         obj.spriteCannotMove = true;
  1321.       }
  1322.     }
  1323.   }
  1324. };
  1325.  
  1326. DataManager.processBECNotetags5 = function(group, isActor) {
  1327.   for (var n = 1; n < group.length; n++) {
  1328.     var obj = group[n];
  1329.     var notedata = obj.note.split(/[\r\n]+/);
  1330.  
  1331.     if (isActor) {
  1332.       obj.anchorX = Yanfly.Param.BECAnchorX;
  1333.       obj.anchorY = Yanfly.Param.BECAnchorY;
  1334.     }
  1335.  
  1336.     for (var i = 0; i < notedata.length; i++) {
  1337.       var line = notedata[i];
  1338.       if (line.match(/<(?:ANCHOR X):[ ](\d+)[.](\d+)>/i)) {
  1339.         obj.anchorX = eval(String(RegExp.$1) + '.' + String(RegExp.$2));
  1340.       } else if (line.match(/<(?:ANCHOR Y):[ ](\d+)[.](\d+)>/i)) {
  1341.         obj.anchorY = eval(String(RegExp.$1) + '.' + String(RegExp.$2));
  1342.       }
  1343.     }
  1344.   }
  1345. };
  1346.  
  1347. DataManager.processBECNotetags6 = function(group) {
  1348.   var note1a = /<(?:ACTION START):[ ](\d+)>/i;
  1349.   var note1b = /<(?:ACTION START):[ ](\d+)[ ](?:THROUGH|to)[ ](\d+)>/i;
  1350.   var note2a = /<(?:TURN START):[ ](\d+)>/i;
  1351.   var note2b = /<(?:TURN START):[ ](\d+)[ ](?:THROUGH|to)[ ](\d+)>/i;
  1352.   for (var n = 1; n < group.length; n++) {
  1353.     var obj = group[n];
  1354.     var notedata = obj.note.split(/[\r\n]+/);
  1355.  
  1356.     for (var i = 0; i < notedata.length; i++) {
  1357.       var line = notedata[i];
  1358.       if (line.match(note1a)) {
  1359.         var turns = parseInt(RegExp.$1);
  1360.         obj.autoRemovalTiming = 3;
  1361.         obj.maxTurns = turns;
  1362.         obj.minTurns = turns;
  1363.       } else if (line.match(note1b)) {
  1364.         var turns1 = parseInt(RegExp.$1);
  1365.         var turns2 = parseInt(RegExp.$2);
  1366.         obj.autoRemovalTiming = 3;
  1367.         obj.maxTurns = turns1;
  1368.         obj.minTurns = turns2;
  1369.       } else if (line.match(note2a)) {
  1370.         var turns = parseInt(RegExp.$1);
  1371.         obj.autoRemovalTiming = 4;
  1372.         obj.maxTurns = turns;
  1373.         obj.minTurns = turns;
  1374.       } else if (line.match(note2b)) {
  1375.         var turns1 = parseInt(RegExp.$1);
  1376.         var turns2 = parseInt(RegExp.$2);
  1377.         obj.autoRemovalTiming = 4;
  1378.         obj.maxTurns = turns1;
  1379.         obj.minTurns = turns2;
  1380.       }
  1381.     }
  1382.   }
  1383. };
  1384.  
  1385. //=============================================================================
  1386. // TouchInput
  1387. //=============================================================================
  1388.  
  1389. Yanfly.BEC.TouchInput_onMouseMove = TouchInput._onMouseMove;
  1390. TouchInput._onMouseMove = function(event) {
  1391.     Yanfly.BEC.TouchInput_onMouseMove.call(this, event);
  1392.     this._mouseOverX = Graphics.pageToCanvasX(event.pageX);
  1393.     this._mouseOverY = Graphics.pageToCanvasY(event.pageY);
  1394. };
  1395.  
  1396. //=============================================================================
  1397. // BattleManager
  1398. //=============================================================================
  1399.  
  1400. Yanfly.BEC.BattleManager_initMembers = BattleManager.initMembers;
  1401. BattleManager.initMembers = function() {
  1402.     Yanfly.BEC.BattleManager_initMembers.call(this);
  1403.     this._forceSelection = false;
  1404.     this._allSelection = false;
  1405.     this._victoryPhase = false;
  1406.     this._forceActionQueue = [];
  1407. };
  1408.  
  1409. BattleManager.isBattleSystem = function(value) {
  1410.     return value.toLowerCase() === $gameSystem.getBattleSystem();
  1411. };
  1412.  
  1413. BattleManager.isDTB = function() {
  1414.     return this.isBattleSystem('dtb');
  1415. };
  1416.  
  1417. BattleManager.isTurnBased = function() {
  1418.     if (this.isDTB()) return true;
  1419.     return false;
  1420. };
  1421.  
  1422. BattleManager.isTickBased = function() {
  1423.     return !this.isTurnBased();
  1424. };
  1425.  
  1426. BattleManager.tickRate = function() {
  1427.     return 1;
  1428. };
  1429.  
  1430. BattleManager.forceSelection = function() {
  1431.     this._forceSelection = true;
  1432. };
  1433.  
  1434. BattleManager.isForceSelection = function() {
  1435.     return this._forceSelection;
  1436. };
  1437.  
  1438. BattleManager.resetSelection = function() {
  1439.     this._forceSelection = false;
  1440. };
  1441.  
  1442. BattleManager.startAllSelection = function() {
  1443.     this._allSelection = true;
  1444. };
  1445.  
  1446. BattleManager.isAllSelection = function() {
  1447.      return this._allSelection && BattleManager.isInputting();
  1448. };
  1449.  
  1450. BattleManager.stopAllSelection = function() {
  1451.     this._allSelection = false;
  1452. };
  1453.  
  1454. Yanfly.BEC.BattleManager_makeEscapeRatio = BattleManager.makeEscapeRatio;
  1455. BattleManager.makeEscapeRatio = function() {
  1456.     if (this.isDTB()) {
  1457.       var code = Yanfly.Param.BECEscRatio;
  1458.       try {
  1459.         this._escapeRatio = eval(code);
  1460.       } catch (e) {
  1461.         this._escapeRatio = 0;
  1462.         Yanfly.Util.displayError(e, code, 'ESCAPE RATIO FORMULA ERROR');
  1463.       }
  1464.       var code = Yanfly.Param.BECEscFail;
  1465.       try {
  1466.         this._escapeFailBoost = eval(code);
  1467.       } catch (e) {
  1468.         this._escapeFailBoost = 0;
  1469.         Yanfly.Util.displayError(e, code, 'ESCAPE FAIL BOOST FORMULA ERROR');
  1470.       }
  1471.     } else {
  1472.       this._escapeFailBoost = 0.1;
  1473.       Yanfly.BEC.BattleManager_makeEscapeRatio.call(this);
  1474.     }
  1475. };
  1476.  
  1477. BattleManager.timeBasedStates = function() {
  1478.     if (!$gameParty.inBattle()) return false;
  1479.     if (this.isTurnBased()) return false;
  1480.     if (this._timeBasedStates !== undefined) return this._timeBasedStates;
  1481.     this._timeBasedStates = Yanfly.Param.BECTimeStates;
  1482.     return this._timeBasedStates;
  1483. };
  1484.  
  1485. BattleManager.timeBasedBuffs = function() {
  1486.     if (!$gameParty.inBattle()) return false;
  1487.     if (this.isTurnBased()) return false;
  1488.     if (this._timeBasedBuffs !== undefined) return this._timeBasedBuffs;
  1489.     this._timeBasedBuffs = Yanfly.Param.BECTimeBuffs;
  1490.     return this._timeBasedBuffs;
  1491. };
  1492.  
  1493. BattleManager.displayStartMessages = function() {
  1494.     if (Yanfly.Param.BECEmergeText) {
  1495.       $gameTroop.enemyNames().forEach(function(name) {
  1496.           $gameMessage.add(TextManager.emerge.format(name));
  1497.       });
  1498.     }
  1499.     if (this._preemptive && Yanfly.Param.BECPreEmpText) {
  1500.         $gameMessage.add(TextManager.preemptive.format($gameParty.name()));
  1501.     } else if (this._surprise && Yanfly.Param.BECSurpText) {
  1502.         $gameMessage.add(TextManager.surprise.format($gameParty.name()));
  1503.     }
  1504. };
  1505.  
  1506. BattleManager.registerSprite = function(battler, sprite) {
  1507.   if (!this._registeredSprites) this._registeredSprites = {};
  1508.   if (battler.isActor()) var id = 100000 + battler.actorId();
  1509.   if (battler.isEnemy()) var id = 200000 + battler.index();
  1510.   this._registeredSprites[id] = sprite;
  1511. };
  1512.  
  1513. BattleManager.getSprite = function(battler) {
  1514.   if (!this._registeredSprites) this._registeredSprites = {};
  1515.   if (battler.isActor()) var id = 100000 + battler.actorId();
  1516.   if (battler.isEnemy()) var id = 200000 + battler.index();
  1517.   return this._registeredSprites[id];
  1518. };
  1519.  
  1520. BattleManager.setSpritePriority = function() {
  1521.     if ($gameSystem.isSideView()) {
  1522.       this._spritePriority = Yanfly.Param.BECSideSpPrio;
  1523.     } else {
  1524.       this._spritePriority = Yanfly.Param.BECFrontSprite;
  1525.     }
  1526.     if (this._spritePriority === false) this._spritePriority = 0;
  1527.     if (this._spritePriority === true) this._spritePriority = 1;
  1528. };
  1529.  
  1530. BattleManager.getSpritePriority = function() {
  1531.     if (!this._spritePriority) this.setSpritePriority();
  1532.     return this._spritePriority;
  1533. };
  1534.  
  1535. BattleManager.changeActor = function(newActorIndex, lastActorActionState) {
  1536.     var lastActor = this.actor();
  1537.     this._actorIndex = newActorIndex;
  1538.     var newActor = this.actor();
  1539.     if (lastActor) {
  1540.         lastActor.setActionState(lastActorActionState);
  1541.         lastActor.spriteReturnHome();
  1542.     }
  1543.     if (newActor) {
  1544.         newActor.setActionState('inputting');
  1545.         newActor.spriteStepForward();
  1546.     }
  1547. };
  1548.  
  1549. BattleManager.createActions = function() {
  1550.     $gameParty.createActions();
  1551.     $gameTroop.createActions();
  1552. };
  1553.  
  1554. BattleManager.clearInputtingAction = function() {
  1555.     if (this.inputtingAction()) this.inputtingAction().clear();
  1556. };
  1557.  
  1558. Yanfly.BEC.BattleManager_checkBattleEnd = BattleManager.checkBattleEnd;
  1559. BattleManager.checkBattleEnd = function() {
  1560.     if (this._phase === 'actionList') return false;
  1561.     if (this._phase === 'actionTargetList') return false;
  1562.     if (this._phase === 'action') return false;
  1563.     if (this._phase === 'phaseChange') return false;
  1564.     if ($gameTroop.isEventRunning()) return false;
  1565.     return Yanfly.BEC.BattleManager_checkBattleEnd.call(this);
  1566. };
  1567.  
  1568. Yanfly.BEC.BattleManager_processTurn = BattleManager.processTurn;
  1569. BattleManager.processTurn = function() {
  1570.     this._processTurn = true;
  1571.     Yanfly.BEC.BattleManager_processTurn.call(this);
  1572.     this._processTurn = false;
  1573. };
  1574.  
  1575. Yanfly.BEC.BattleManager_processVictory = BattleManager.processVictory;
  1576. BattleManager.processVictory = function() {
  1577.     this._logWindow.clear();
  1578.     this._victoryPhase = true;
  1579.     if (this._windowLayer) this._windowLayer.x = 0;
  1580.     Yanfly.BEC.BattleManager_processVictory.call(this);
  1581. };
  1582.  
  1583. BattleManager.processEscape = function() {
  1584.     $gameParty.performEscape();
  1585.     SoundManager.playEscape();
  1586.     var success = this._preemptive ? true : (Math.random() < this._escapeRatio);
  1587.     if ($gamePlayer.isDebugThrough()) success = true;
  1588.     if (success) {
  1589.         $gameParty.performEscapeSuccess();
  1590.         this.displayEscapeSuccessMessage();
  1591.         this._escaped = true;
  1592.         this.processAbort();
  1593.     } else {
  1594.         this.displayEscapeFailureMessage();
  1595.         this._escapeRatio += this._escapeFailBoost;
  1596.         $gameParty.clearActions();
  1597.         this.startTurn();
  1598.     }
  1599.     return success;
  1600. };
  1601.  
  1602. Yanfly.BEC.BattleManager_processAbort = BattleManager.processAbort;
  1603. BattleManager.processAbort = function() {
  1604.     $gameParty.removeBattleStates();
  1605.     Yanfly.BEC.BattleManager_processAbort.call(this);
  1606. };
  1607.  
  1608. BattleManager.refreshAllMembers = function() {
  1609.   $gameParty.refreshMembers();
  1610.   $gameTroop.refreshMembers();
  1611. };
  1612.  
  1613. BattleManager.startTurn = function() {
  1614.     this._enteredEndPhase = false;
  1615.     this._phase = 'turn';
  1616.     this.clearActor();
  1617.     $gameTroop.increaseTurn();
  1618.     $gameParty.onTurnStart();
  1619.     $gameTroop.onTurnStart();
  1620.     this._performedBattlers = [];
  1621.     this.makeActionOrders();
  1622.     $gameParty.requestMotionRefresh();
  1623.     this._logWindow.startTurn();
  1624.     this._subject = this.getNextSubject();
  1625. };
  1626.  
  1627. Yanfly.BEC.BattleManager_endTurn = BattleManager.endTurn;
  1628. BattleManager.endTurn = function() {
  1629.     if (this.isTurnBased() && this._spriteset.isPopupPlaying()) return;
  1630.     if (this.isTurnBased() && this._enteredEndPhase) {
  1631.       this._phase = 'turnEnd';
  1632.       this._preemptive = false;
  1633.       this._surprise = false;
  1634.       return;
  1635.     }
  1636.     this._enteredEndPhase = true;
  1637.     Yanfly.BEC.BattleManager_endTurn.call(this);
  1638.     BattleManager.refreshAllMembers();
  1639. };
  1640.  
  1641. BattleManager.getNextSubject = function() {
  1642.     if ($gameTroop.turnCount() <= 0) return;
  1643.     this._performedBattlers = this._performedBattlers || [];
  1644.     this.makeActionOrders();
  1645.     for (;;) {
  1646.         var battlerArray = [];
  1647.         for (var i = 0; i < this._actionBattlers.length; ++i) {
  1648.           var obj = this._actionBattlers[i];
  1649.           if (!this._performedBattlers.contains(obj)) battlerArray.push(obj);
  1650.         }
  1651.         this._actionBattlers = battlerArray;
  1652.         var battler = this._actionBattlers.shift();
  1653.         if (!battler) return null;
  1654.         if (battler.isBattleMember() && battler.isAlive()) {
  1655.             this._performedBattlers.push(battler);
  1656.             return battler;
  1657.         }
  1658.     }
  1659. };
  1660.  
  1661. BattleManager.update = function() {
  1662.     if (!this.isBusy() && !this.updateEvent()) {
  1663.         switch (this._phase) {
  1664.         case 'start':
  1665.             this.startInput();
  1666.             break;
  1667.         case 'turn':
  1668.             this.updateTurn();
  1669.             break;
  1670.         case 'action':
  1671.             this.updateAction();
  1672.             break;
  1673.         case 'phaseChange':
  1674.             this.updatePhase();
  1675.             break;
  1676.         case 'actionList':
  1677.             this.updateActionList()
  1678.             break;
  1679.         case 'actionTargetList':
  1680.             this.updateActionTargetList()
  1681.             break;
  1682.         case 'turnEnd':
  1683.             this.updateTurnEnd();
  1684.             break;
  1685.         case 'battleEnd':
  1686.             this.updateBattleEnd();
  1687.             break;
  1688.         }
  1689.     }
  1690. };
  1691.  
  1692. BattleManager.updateEvent = function() {
  1693.     if (this._processingForcedAction) return false;
  1694.     switch (this._phase) {
  1695.     case 'start':
  1696.     case 'turn':
  1697.     case 'turnEnd':
  1698.     case 'actionList':
  1699.     case 'actionTargetList':
  1700.       if (this.isActionForced()) {
  1701.         this.processForcedAction();
  1702.         return true;
  1703.       } else {
  1704.         return this.updateEventMain();
  1705.       }
  1706.     }
  1707.     return this.checkAbort();
  1708. };
  1709.  
  1710. BattleManager.queueForceAction = function(user, skillId, target) {
  1711.     if (target === undefined) {
  1712.       var targetIndex = 0;
  1713.     } else if (typeof target === 'number') {
  1714.       var targetIndex = target;
  1715.     } else {
  1716.       var targetIndex = target.index();
  1717.     }
  1718.     var param = [
  1719.       user.isEnemy() ? 0 : 1,
  1720.       user.isActor() ? user.actorId() : user.index(),
  1721.       skillId,
  1722.       targetIndex
  1723.     ];
  1724.     var command = {
  1725.       code: 339,
  1726.       indent: 0,
  1727.       parameters: param
  1728.     }
  1729.     $gameTemp.forceActionQueue(command);
  1730.     this.clearResults();
  1731.     if (this.isTickBased()) this._phase = 'action';
  1732. };
  1733.  
  1734. BattleManager.addText = function(text, wait) {
  1735.   if (!SceneManager._scene._logWindow) return;
  1736.   wait = wait || 0;
  1737.   SceneManager._scene._logWindow.addText(text);
  1738.   if (wait <= 0) return;
  1739.   var last = this._actionList[this._actionList.length - 1];
  1740.   if (last && last[0] === 'WAIT') return;
  1741.   this._actionList.push(['WAIT', [wait]]);
  1742. };
  1743.  
  1744. BattleManager.clearResults = function() {
  1745.   var group = this.allBattleMembers();
  1746.   var length = group.length;
  1747.   for (var i = 0; i < length; ++i) {
  1748.     var member = group[i];
  1749.     if (member) member.clearResult();
  1750.   }
  1751.   this._allTargets = [];
  1752.   this._targets = [];
  1753.   this._target = undefined;
  1754. };
  1755.  
  1756. Yanfly.BEC.BattleManager_forceAction = BattleManager.forceAction;
  1757. BattleManager.forceAction = function(battler) {
  1758.     if (this._subject) this._subject.clearResult();
  1759.     this.createForceActionFailSafes();
  1760.     this.savePreForceActionSettings();
  1761.     Yanfly.BEC.BattleManager_forceAction.call(this, battler);
  1762. };
  1763.  
  1764. BattleManager.createForceActionFailSafes = function() {
  1765.     this._actionList = this._actionList || [];
  1766.     this._targets = this._targets || [];
  1767.     this._allTargets = this._allTargets || [];
  1768.     this._individualTargets = this._individualTargets || [];
  1769.     this._phaseSteps = this._phaseSteps || [];
  1770.     this._conditionFlags = this._conditionFlags || [];
  1771.     this._trueFlags = this._trueFlags || [];
  1772. };
  1773.  
  1774. BattleManager.savePreForceActionSettings = function() {
  1775.     var settings = this.setPreForceActionSettings();
  1776.     this._forceActionQueue.push(settings);
  1777. };
  1778.  
  1779. BattleManager.setPreForceActionSettings = function() {
  1780.     return {
  1781.       subject: this._subject,
  1782.       action: JsonEx.makeDeepCopy(this._action),
  1783.       actionList: JsonEx.makeDeepCopy(this._actionList),
  1784.       targets: this._targets.slice(),
  1785.       allTargets: this._allTargets.slice(),
  1786.       indTargets: this._individualTargets.slice(),
  1787.       phaseSteps: JsonEx.makeDeepCopy(this._phaseSteps),
  1788.       returnPhase: this._returnPhase,
  1789.       phase: this._phase,
  1790.       conditionFlags: JsonEx.makeDeepCopy(this._conditionFlags),
  1791.       trueFlags: JsonEx.makeDeepCopy(this._trueFlags)
  1792.     }
  1793. };
  1794.  
  1795. BattleManager.loadPreForceActionSettings = function() {
  1796.     var settings = this._forceActionQueue[0];
  1797.     if (settings) {
  1798.       this._forceActionQueue.shift();
  1799.       this.resetPreForceActionSettings(settings);
  1800.       return this._subject && this._subject.isAppeared();
  1801.     } else {
  1802.       return false;
  1803.     }    
  1804. };
  1805.  
  1806. BattleManager.resetPreForceActionSettings = function(settings) {
  1807.     this._subject = settings['subject'];
  1808.     this._action = settings['action'];
  1809.     this._actionList = settings['actionList'];
  1810.     this._targets = settings['targets'];
  1811.     this._allTargets = settings['allTargets'];
  1812.     this._individualTargets = settings['indTargets'];
  1813.     this._phaseSteps = settings['phaseSteps'];
  1814.     this._returnPhase = settings['returnPhase'];
  1815.     this._conditionFlags = settings['conditionFlags'];
  1816.     this._trueFlags = settings['trueFlags'];
  1817.     this._phase = settings['phase'];  
  1818. };
  1819.  
  1820. Yanfly.BEC.BattleManager_processForcedAction =
  1821.     BattleManager.processForcedAction;
  1822. BattleManager.processForcedAction = function() {
  1823.     if (this._actionForcedBattler) {
  1824.       this._preForcePhase = this._phase;
  1825.       this._processingForcedAction = true;
  1826.     }
  1827.     Yanfly.BEC.BattleManager_processForcedAction.call(this);
  1828. };
  1829.  
  1830. BattleManager.setTargets = function(array) {
  1831.     this._targets = [];
  1832.     var max = array.length;
  1833.     for (var i = 0; i < max; ++i) {
  1834.       var target = array[i];
  1835.       if (target) this._targets.push(target);
  1836.     }
  1837. };
  1838.  
  1839. BattleManager.updateAction = function() {
  1840.     var target = this._targets.shift();
  1841.     if (target) {
  1842.         this.invokeAction(this._subject, target);
  1843.     } else {
  1844.         if (this._returnPhase === 'target') {
  1845.           this.setTargets([this._individualTargets[0]]);
  1846.           this._phase = 'actionTargetList';
  1847.         } else {
  1848.           this.setTargets(this._allTargets.slice());
  1849.           this._phase = 'actionList';
  1850.         }
  1851.     }
  1852. };
  1853.  
  1854. BattleManager.invokeAction = function(subject, target) {
  1855.   if (!Yanfly.Param.BECOptSpeed)  this._logWindow.push('pushBaseLine');
  1856.   var normal = true;
  1857.   if (Math.random() < this._action.itemMrf(target)) {
  1858.     this.invokeMagicReflection(subject, target);
  1859.   } else if (Math.random() < this._action.itemCnt(target)) {
  1860.     this.invokeCounterAttack(subject, target);
  1861.   } else {
  1862.     this.invokeNormalAction(subject, target);
  1863.   }
  1864.   if (subject) subject.setLastTarget(target);
  1865.   if (!Yanfly.Param.BECOptSpeed) this._logWindow.push('popBaseLine');
  1866. };
  1867.  
  1868. BattleManager.invokeCounterAttack = function(subject, target) {
  1869.     var action = new Game_Action(target);
  1870.     this._logWindow.displayCounter(target);
  1871.     action.setAttack();
  1872.     action.apply(subject);
  1873.     this._logWindow.displayActionResults(target, subject);
  1874.     if (subject.isDead()) subject.performCollapse();
  1875. };
  1876.  
  1877. Yanfly.BEC.BattleManager_invokeMagicReflection =
  1878.     BattleManager.invokeMagicReflection;
  1879. BattleManager.invokeMagicReflection = function(subject, target) {
  1880.     Yanfly.BEC.BattleManager_invokeMagicReflection.call(this, subject, target);
  1881.     if (subject.isDead()) subject.performCollapse();
  1882. };
  1883.  
  1884. BattleManager.updatePhase = function() {
  1885.     var phase = this._phaseSteps.shift();
  1886.     if (phase) this.createPhaseChanges();
  1887.     switch (phase) {
  1888.     case 'setup':
  1889.       this.createSetupActions();
  1890.       break;
  1891.     case 'whole':
  1892.       this.createWholeActions();
  1893.       break;
  1894.     case 'target':
  1895.       this.createTargetActions();
  1896.       break;
  1897.     case 'follow':
  1898.       this.createFollowActions();
  1899.       break;
  1900.     case 'finish':
  1901.       this.createFinishActions();
  1902.       break;
  1903.     default:
  1904.       this.endAction();
  1905.       break;
  1906.     }
  1907. };
  1908.  
  1909. BattleManager.createPhaseChanges = function() {
  1910.     this._phase = 'actionList';
  1911.     this.setTargets(this._allTargets.slice());
  1912.     this._conditionFlags = [];
  1913.     this._trueFlags = [];
  1914. };
  1915.  
  1916. BattleManager.createSetupActions = function() {
  1917.     $gameTemp.clearActionSequenceSettings();
  1918.     this._returnPhase = 'setup';
  1919.     this._actionList = this._action.item().setupActions.slice();
  1920. };
  1921.  
  1922. BattleManager.createWholeActions = function() {
  1923.     this._returnPhase = 'whole';
  1924.     this._actionList = this._action.item().wholeActions.slice();
  1925. };
  1926.  
  1927. BattleManager.createTargetActions = function() {
  1928.     this._returnPhase = 'target';
  1929.     this._phase = 'actionTargetList';
  1930.     this.setTargets([this._individualTargets[0]]);
  1931.     this._actionList = this._action.item().targetActions.slice();
  1932. };
  1933.  
  1934. BattleManager.createFollowActions = function() {
  1935.     this._returnPhase = 'follow';
  1936.     this._actionList = this._action.item().followActions.slice();
  1937. };
  1938.  
  1939. BattleManager.createFinishActions = function() {
  1940.     this._returnPhase = 'finish';
  1941.     this._actionList = this._action.item().finishActions.slice();
  1942. };
  1943.  
  1944. Yanfly.BEC.BattleManager_endAction = BattleManager.endAction;
  1945. BattleManager.endAction = function() {
  1946.     if (this._subject) {
  1947.       this._subject.onAllActionsEnd();
  1948.     }
  1949.     if (this._processingForcedAction) {
  1950.       this._subject.removeCurrentAction();
  1951.       this._phase = this._preForcePhase;
  1952.     }
  1953.     this._processingForcedAction = false;
  1954.     if (this.loadPreForceActionSettings()) return;
  1955.     Yanfly.BEC.BattleManager_endAction.call(this);
  1956. };
  1957.  
  1958. BattleManager.updateActionList = function() {
  1959.     for (;;) {
  1960.       this._actSeq = this._actionList.shift();
  1961.       if (this._actSeq) {
  1962.         if (!this.actionConditionsMet(this._actSeq)) continue;
  1963.         var seqName = this._actSeq[0].toUpperCase();
  1964.         if (!this.processActionSequenceCheck(seqName, this._actSeq[1])) {
  1965.           break;
  1966.         }
  1967.       } else {
  1968.         this._phase = 'phaseChange';
  1969.         break;
  1970.       }
  1971.     }
  1972. };
  1973.  
  1974. BattleManager.updateActionTargetList = function() {
  1975.     for (;;) {
  1976.       this._actSeq = this._actionList.shift();
  1977.       if (this._actSeq) {
  1978.         if (!this.actionConditionsMet(this._actSeq)) continue;
  1979.         var seqName = this._actSeq[0].toUpperCase();
  1980.         if (!this.processActionSequenceCheck(seqName, this._actSeq[1])) {
  1981.           break;
  1982.         }
  1983.       } else if (this._individualTargets.length > 0) {
  1984.         this._individualTargets.shift();
  1985.         if (this._individualTargets.length > 0) {
  1986.           this.setTargets([this._individualTargets[0]]);
  1987.           this._actionList = this._action.item().targetActions.slice();
  1988.         } else {
  1989.           this._phase = 'phaseChange';
  1990.           break;
  1991.         }
  1992.       } else {
  1993.         this._phase = 'phaseChange';
  1994.         break;
  1995.       }
  1996.     }
  1997. };
  1998.  
  1999. BattleManager.updateActionTargetList = function() {
  2000.     for (;;) {
  2001.       this._actSeq = this._actionList.shift();
  2002.       if (this._actSeq) {
  2003.         if (!this.actionConditionsMet(this._actSeq)) continue;
  2004.         var seqName = this._actSeq[0].toUpperCase();
  2005.         if (!this.processActionSequenceCheck(seqName, this._actSeq[1])) {
  2006.           break;
  2007.         }
  2008.       } else if (this._individualTargets.length > 0) {
  2009.         this._individualTargets.shift();
  2010.         if (this._individualTargets.length > 0) {
  2011.           this.setTargets([this._individualTargets[0]]);
  2012.           this._actionList = this._action.item().targetActions.slice();
  2013.         } else {
  2014.           this._phase = 'phaseChange';
  2015.           break;
  2016.         }
  2017.       } else {
  2018.         this._phase = 'phaseChange';
  2019.         break;
  2020.       }
  2021.     }
  2022. };
  2023.  
  2024. BattleManager.startAction = function() {
  2025.     var subject = this._subject;
  2026.     if (!subject) return this.endAction();
  2027.     var action = subject.currentAction();
  2028.     this._action = action;
  2029.     if (!this._action) return this.endAction();
  2030.     if (!this._action.item()) return this.endAction();
  2031.     var targets = action.makeTargets();
  2032.     this.setTargets(targets);
  2033.     this._allTargets = targets.slice();
  2034.     this._individualTargets = targets.slice();
  2035.     this._phase = 'phaseChange';
  2036.     this._phaseSteps = ['setup', 'whole', 'target', 'follow', 'finish'];
  2037.     this._returnPhase = '';
  2038.     this._actionList = [];
  2039.     subject.useItem(this._action.item());
  2040.     this._action.applyGlobal();
  2041.     this._logWindow.startAction(this._subject, this._action, this._targets);
  2042. };
  2043.  
  2044. BattleManager.processActionSequenceCheck = function(actionName, actionArgs) {
  2045.     // IF condition
  2046.     if (actionName.match(/IF[ ](.*)/i)) {
  2047.       return this.actionIfConditions(actionName, actionArgs);
  2048.     }
  2049.     return this.processActionSequence(actionName, actionArgs)
  2050. };
  2051.  
  2052. BattleManager.processActionSequence = function(actionName, actionArgs) {
  2053.     // NO ACTION
  2054.     if (actionName === '') {
  2055.       return true;
  2056.     }
  2057.     // ACTION ANIMATION
  2058.     if (actionName === 'ACTION ANIMATION') {
  2059.       return this.actionActionAnimation(actionArgs);
  2060.     }
  2061.     // ACTION EFFECT
  2062.     if (actionName === 'ACTION COMMON EVENT') {
  2063.       return this.actionActionCommonEvent();
  2064.     }
  2065.     // ACTION EFFECT
  2066.     if (actionName === 'ACTION EFFECT') {
  2067.       return this.actionActionEffect(actionArgs);
  2068.     }
  2069.     // ANI WAIT: frames
  2070.     if (['ANI WAIT', 'ANIWAIT', 'ANIMATION WAIT'].contains(actionName)) {
  2071.       return this.actionAniWait(actionArgs[0]);
  2072.     }
  2073.     // CAST ANIMATION
  2074.     if (actionName === 'CAST ANIMATION') {
  2075.       return this.actionCastAnimation();
  2076.     }
  2077.     // CLEAR BATTLE LOG
  2078.     if (actionName === 'CLEAR BATTLE LOG') {
  2079.       return this.actionClearBattleLog();
  2080.     }
  2081.     // DEATH BREAK
  2082.     if (actionName === 'DEATH BREAK') {
  2083.       return this.actionDeathBreak();
  2084.     }
  2085.     // DISPLAY ACTION
  2086.     if (actionName === 'DISPLAY ACTION') {
  2087.       return this.actionDisplayAction();
  2088.     }
  2089.     // IMMORTAL: targets, true/false
  2090.     if (actionName === 'IMMORTAL') {
  2091.       return this.actionImmortal(actionArgs);
  2092.     }
  2093.     // MOTION WAIT
  2094.     if (actionName === 'MOTION WAIT') {
  2095.       return this.actionMotionWait(actionArgs);
  2096.     }
  2097.     // PERFORM ACTION
  2098.     if (actionName === 'PERFORM ACTION') {
  2099.       return this.actionPerformAction();
  2100.     }
  2101.     // PERFORM FINISH
  2102.     if (actionName === 'PERFORM FINISH') {
  2103.       return this.actionPerformFinish();
  2104.     }
  2105.     // PERFORM START
  2106.     if (actionName === 'PERFORM START') {
  2107.       return this.actionPerformStart();
  2108.     }
  2109.     // WAIT: frames
  2110.     if (actionName === 'WAIT') {
  2111.       return this.actionWait(actionArgs[0]);
  2112.     }
  2113.     // WAIT FOR ANIMATION
  2114.     if (actionName === 'WAIT FOR ANIMATION') {
  2115.       return this.actionWaitForAnimation();
  2116.     }
  2117.     // WAIT FOR EFFECT
  2118.     if (actionName === 'WAIT FOR EFFECT') {
  2119.       return this.actionWaitForEffect();
  2120.     }
  2121.     // WAIT FOR MOVEMENT
  2122.     if (actionName === 'WAIT FOR MOVEMENT') {
  2123.       return this.actionWaitForMovement();
  2124.     }
  2125.     // WAIT FOR NEW LINE
  2126.     if (actionName === 'WAIT FOR NEW LINE') {
  2127.       return this.actionWaitForNewLine();
  2128.     }
  2129.     // WAIT FOR POPUPS
  2130.     if (actionName === 'WAIT FOR POPUPS') {
  2131.       return this.actionWaitForPopups();
  2132.     }
  2133.     return false;
  2134. };
  2135.  
  2136. BattleManager.makeActionTargets = function(string) {
  2137.     var targets = []
  2138.     string = string.toUpperCase()
  2139.     if (['SUBJECT', 'USER'].contains(string)) {
  2140.       return [this._subject];
  2141.     }
  2142.     if (['TARGET', 'TARGETS'].contains(string)) {
  2143.       var group = this._targets;
  2144.       for (var i = 0; i < group.length; ++i) {
  2145.         var target = group[i];
  2146.         if (target && target.isAppeared()) targets.push(target);
  2147.       }
  2148.       return targets;
  2149.     }
  2150.     if (['ACTORS', 'EXISTING ACTORS', 'ALIVE ACTORS'].contains(string)) {
  2151.       var group = $gameParty.aliveMembers();
  2152.       for (var i = 0; i < group.length; ++i) {
  2153.         var target = group[i];
  2154.         if (target && target.isAppeared()) targets.push(target);
  2155.       }
  2156.       return targets;
  2157.     }
  2158.     if (['ACTORS ALL', 'ALL ACTORS', 'PARTY'].contains(string)) {
  2159.       var group = $gameParty.battleMembers();
  2160.       for (var i = 0; i < group.length; ++i) {
  2161.         var target = group[i];
  2162.         if (target && target.isAppeared()) targets.push(target);
  2163.       }
  2164.       return targets;
  2165.     }
  2166.     if (['DEAD ACTORS', 'DEAD ACTOR'].contains(string)) {
  2167.       var group = $gameParty.deadMembers();
  2168.       for (var i = 0; i < group.length; ++i) {
  2169.         var target = group[i];
  2170.         if (target) targets.push(target);
  2171.       }
  2172.       return targets;
  2173.     }
  2174.     if (['ACTORS NOT USER', 'ACTORS NOT SUBJECT'].contains(string)) {
  2175.       var group = $gameParty.aliveMembers();
  2176.       for (var i = 0; i < group.length; ++i) {
  2177.         var target = group[i];
  2178.         if (target && target !== this._subject && target.isAppeared()) {
  2179.           targets.push(target);
  2180.         }
  2181.       }
  2182.       return targets;
  2183.     }
  2184.     if (['ENEMIES', 'EXISTING ENEMIES', 'ALIVE ENEMIES', 'TROOP',
  2185.     'TROOPS'].contains(string)) {
  2186.       var group = $gameTroop.aliveMembers();
  2187.       for (var i = 0; i < group.length; ++i) {
  2188.         var target = group[i];
  2189.         if (target && target.isAppeared()) targets.push(target);
  2190.       }
  2191.       return targets;
  2192.     }
  2193.     if (['ENEMIES ALL', 'ALL ENEMIES'].contains(string)) {
  2194.       var group = $gameTroop.members();
  2195.       for (var i = 0; i < group.length; ++i) {
  2196.         var target = group[i];
  2197.         if (target && target.isAppeared()) targets.push(target);
  2198.       }
  2199.       return targets;
  2200.     }
  2201.     if (['DEAD ENEMIES', 'DEAD ENEMY'].contains(string)) {
  2202.       var group = $gameTroop.deadMembers();
  2203.       for (var i = 0; i < group.length; ++i) {
  2204.         var target = group[i];
  2205.         if (target) targets.push(target);
  2206.       }
  2207.       return targets;
  2208.     }
  2209.     if (['ENEMIES NOT USER', 'ENEMIES NOT SUBJECT', 'TROOP NOT USER',
  2210.     'TROOP NOT SUBJECT'].contains(string)) {
  2211.       var group = $gameTroop.aliveMembers();
  2212.       for (var i = 0; i < group.length; ++i) {
  2213.         var target = group[i];
  2214.         if (target && target !== this._subject && target.isAppeared()) {
  2215.           targets.push(target);
  2216.         }
  2217.       }
  2218.       return targets;
  2219.     }
  2220.     if (string.match(/ACTOR[ ](\d+)/i)) {
  2221.       var target = $gameParty.battleMembers()[parseInt(RegExp.$1)];
  2222.       if (target && target.isAppeared()) return [target];
  2223.     }
  2224.     if (string.match(/ENEMY[ ](\d+)/i)) {
  2225.       var target = $gameTroop.members()[parseInt(RegExp.$1)];
  2226.       if (target && target.isAppeared()) return [target];
  2227.     }
  2228.     if (['FRIEND', 'FRIENDS', 'ALLIES'].contains(string)) {
  2229.       var group = this._action.friendsUnit().aliveMembers();
  2230.       for (var i = 0; i < group.length; ++i) {
  2231.         var target = group[i];
  2232.         if (target && target.isAppeared()) targets.push(target);
  2233.       }
  2234.       return targets;
  2235.     }
  2236.     if (['ALL FRIENDS', 'ALL ALLIES'].contains(string)) {
  2237.       var group = this._action.friendsUnit().members();
  2238.       for (var i = 0; i < group.length; ++i) {
  2239.         var target = group[i];
  2240.         if (target && target.isAppeared()) targets.push(target);
  2241.       }
  2242.       return targets;
  2243.     }
  2244.     if (['DEAD FRIEND', 'DEAD FRIENDS', 'DEAD ALLIES'].contains(string)) {
  2245.       var group = this._action.friendsUnit().deadMembers();
  2246.       for (var i = 0; i < group.length; ++i) {
  2247.         var target = group[i];
  2248.         if (target && target.isAppeared()) targets.push(target);
  2249.       }
  2250.       return targets;
  2251.     }
  2252.     if (['OPPONENT', 'OPPONENTS', 'RIVALS', 'FOES'].contains(string)) {
  2253.       var group = this._action.opponentsUnit().aliveMembers();
  2254.       for (var i = 0; i < group.length; ++i) {
  2255.         var target = group[i];
  2256.         if (target && target.isAppeared()) targets.push(target);
  2257.       }
  2258.       return targets;
  2259.     }
  2260.     if (['ALL OPPONENTS', 'ALL RIVALS', 'ALL FOES'].contains(string)) {
  2261.       var group = this._action.opponentsUnit().members();
  2262.       for (var i = 0; i < group.length; ++i) {
  2263.         var target = group[i];
  2264.         if (target && target.isAppeared()) targets.push(target);
  2265.       }
  2266.       return targets;
  2267.     }
  2268.     if (['DEAD OPPONENT', 'DEAD OPPONENTS', 'DEAD RIVALS',
  2269.     'DEAD FOES'].contains(string)) {
  2270.       var group = this._action.opponentsUnit().deadMembers();
  2271.       for (var i = 0; i < group.length; ++i) {
  2272.         var target = group[i];
  2273.         if (target) targets.push(target);
  2274.       }
  2275.       return targets;
  2276.     }
  2277.     if (['FRIENDS NOT USER', 'ALLIES NOT USER'].contains(string)) {
  2278.       var group = this._action.friendsUnit().aliveMembers();
  2279.       for (var i = 0; i < group.length; ++i) {
  2280.         var target = group[i];
  2281.         if (target && target !== this._subject && target.isAppeared()) {
  2282.           targets.push(target);
  2283.         }
  2284.       }
  2285.       return targets;
  2286.     }
  2287.     if (string.match(/(?:FRIEND|ALLY)[ ](\d+)/i)) {
  2288.       var target = this._action.friendsUnit().members()[parseInt(RegExp.$1)];
  2289.       if (target && target.isAppeared()) return [target];
  2290.     }
  2291.     if (string.match(/(?:OPPONENT|FOE|RIVAL)[ ](\d+)/i)) {
  2292.       var target = this._action.opponentsUnit().members()[parseInt(RegExp.$1)]
  2293.       if (target && target.isAppeared()) return [target];
  2294.     }
  2295.     if (['ALL ALIVE'].contains(string)) {
  2296.       var group = this._action.friendsUnit().aliveMembers();
  2297.       group = group.concat(this._action.opponentsUnit().aliveMembers());
  2298.       for (var i = 0; i < group.length; ++i) {
  2299.         var target = group[i];
  2300.         if (target && target.isAppeared()) targets.push(target);
  2301.       }
  2302.       return targets;
  2303.     }
  2304.     if (['ALL MEMBERS'].contains(string)) {
  2305.       var group = this._action.friendsUnit().members();
  2306.       group = group.concat(this._action.opponentsUnit().members());
  2307.       for (var i = 0; i < group.length; ++i) {
  2308.         var target = group[i];
  2309.         if (target && target.isAppeared()) targets.push(target);
  2310.       }
  2311.       return targets;
  2312.     }
  2313.     if (['ALL DEAD'].contains(string)) {
  2314.       var group = this._action.friendsUnit().deadMembers();
  2315.       group = group.concat(this._action.opponentsUnit().deadMembers());
  2316.       for (var i = 0; i < group.length; ++i) {
  2317.         var target = group[i];
  2318.         if (target) targets.push(target);
  2319.       }
  2320.       return targets;
  2321.     }
  2322.     if (['ALL NOT USER'].contains(string)) {
  2323.       var group = this._action.friendsUnit().aliveMembers();
  2324.       group = group.concat(this._action.opponentsUnit().aliveMembers());
  2325.       for (var i = 0; i < group.length; ++i) {
  2326.         var target = group[i];
  2327.         if (target && target !== this._subject && target.isAppeared()) {
  2328.           targets.push(target);
  2329.         }
  2330.       }
  2331.       return targets;
  2332.     }
  2333.     if (['FOCUS', 'PARTICIPANTS'].contains(string)) {
  2334.       var group = this._targets;
  2335.       for (var i = 0; i < group.length; ++i) {
  2336.         var target = group[i];
  2337.         if (target && target.isAppeared()) targets.push(target);
  2338.       }
  2339.       if (!targets.contains(this._subject)) targets.push(this._subject);
  2340.       return targets;
  2341.     }
  2342.     if (['NOT FOCUS', 'NONPARTICIPANTS'].contains(string)) {
  2343.       var group = this._action.friendsUnit().members();
  2344.       group = group.concat(this._action.opponentsUnit().members());
  2345.       for (var i = 0; i < group.length; ++i) {
  2346.         var target = group[i];
  2347.         if (target) {
  2348.           if (target === this._subject) continue;
  2349.           if (target.isHidden()) continue;
  2350.           if (this._targets.contains(target)) continue;
  2351.  
  2352.           if (target.isDead()) {
  2353.             if (Imported.YEP_X_AnimatedSVEnemies && target.isEnemy()) {
  2354.               if (target.hasSVBattler() && !target.sideviewCollapse()) {
  2355.                 // Ignore
  2356.               } else {
  2357.                 continue;
  2358.               }
  2359.             } else if (target.isActor()) {
  2360.               // Ignore
  2361.             } else {
  2362.               continue;
  2363.             }
  2364.           }
  2365.  
  2366.           targets.push(target);
  2367.         }
  2368.       }
  2369.       return targets;
  2370.     }
  2371.     if (string.match(/(?:CHAR|CHARA|CHARACTER)[ ](\d+)/i)) {
  2372.       var actorId = parseInt(RegExp.$1);
  2373.       var actor = $gameActors.actor(actorId);
  2374.       if (actor && $gameParty.battleMembers().contains(actor)) {
  2375.         return [actor];
  2376.       }
  2377.     }
  2378.     if ('FIRST' === string.toUpperCase()) {
  2379.       return [this._targets[0]];
  2380.     }
  2381.     return targets;
  2382. };
  2383.  
  2384. BattleManager.actionConditionsMet = function(actSeq) {
  2385.   var ci = this._conditionFlags.length - 1;
  2386.   var actionName = actSeq[0];
  2387.   var actionArgs = actSeq[1];
  2388.   var subject = this._subject;
  2389.   var user = this._subject;
  2390.   var target = this._targets[0];
  2391.   var targets = this._targets;
  2392.   var action = this._action;
  2393.   var item = this._action.item();
  2394.   if (actionName.match(/ELSE[ ]IF[ ](.*)/i)) {
  2395.     if (this._conditionFlags.length <= 0) return false;
  2396.     if (this._conditionFlags[ci]) {
  2397.       this._conditionFlags[ci] = false;
  2398.       this._trueFlags[ci] = true;
  2399.     } else if (!this._conditionFlags[ci] && !this._trueFlags[ci]) {
  2400.       var text = String(RegExp.$1);
  2401.       try {
  2402.         this._conditionFlags[ci] = eval(text);
  2403.         this._trueFlags[ci] = eval(text);
  2404.       } catch (e) {
  2405.         Yanfly.Util.displayError(e, text, 'ACTION SEQUENCE IF CONDITION ERROR');
  2406.         this._conditionFlags[ci] = false;
  2407.         this._trueFlags[ci] = false;
  2408.       }
  2409.     }
  2410.     return false;
  2411.   } else if (actionName.match(/ELSE[ ]*(.*)/i)) {
  2412.     if (this._conditionFlags.length <= 0) return false;
  2413.     if (this._conditionFlags[ci]) {
  2414.       this._conditionFlags[ci] = false;
  2415.       this._trueFlags[ci] = true;
  2416.     } else if (!this._conditionFlags[ci] && !this._trueFlags[ci]) {
  2417.       this._conditionFlags[ci] = true;
  2418.       this._trueFlags[ci] = true;
  2419.     }
  2420.     return false;
  2421.   } else if (actionName.toUpperCase() === 'END') {
  2422.     if (this._conditionFlags.length <= 0) return false;
  2423.     this._conditionFlags.pop();
  2424.     this._trueFlags.pop();
  2425.     return false;
  2426.   }
  2427.   if (this._conditionFlags.length > 0) return this._conditionFlags[ci];
  2428.   return true
  2429. };
  2430.  
  2431. BattleManager.actionActionAnimation = function(actionArgs) {
  2432.     if (actionArgs && actionArgs[0]) {
  2433.       var targets = this.makeActionTargets(actionArgs[0]);
  2434.     } else {
  2435.       var targets = this._targets;
  2436.     }
  2437.     var mirror = false;
  2438.     if (actionArgs && actionArgs[1]) {
  2439.       if (actionArgs[1].toUpperCase() === 'MIRROR') mirror = true;
  2440.     }
  2441.     var subject = this._subject;
  2442.     var group = targets.filter(Yanfly.Util.onlyUnique);
  2443.     var aniId = this._action.item().animationId;
  2444.     if (aniId < 0) {
  2445.       if (mirror) {
  2446.         this._logWindow.showActorAtkAniMirror(subject, group);
  2447.       } else {
  2448.         this._logWindow.showAttackAnimation(subject, group);
  2449.       }
  2450.     } else {
  2451.       this._logWindow.showNormalAnimation(group, aniId, mirror);
  2452.     }
  2453.     return true;
  2454. };
  2455.  
  2456. BattleManager.actionActionCommonEvent = function() {
  2457.     this._action.item().effects.forEach(function(effect) {
  2458.         if (effect.code === Game_Action.EFFECT_COMMON_EVENT) {
  2459.             $gameTemp.reserveCommonEvent(effect.dataId);
  2460.         }
  2461.     }, this);
  2462.     return false;
  2463. };
  2464.  
  2465. BattleManager.actionActionEffect = function(actionArgs) {
  2466.     if (actionArgs && actionArgs[0]) {
  2467.       var targets = this.makeActionTargets(actionArgs[0]);
  2468.     } else {
  2469.       var targets = this._targets;
  2470.     }
  2471.     targets.forEach(function(target) {
  2472.       if (target !== undefined) {
  2473.         var alreadyDead = target.isDead();
  2474.         this.invokeAction(this._subject, target);
  2475.         if (target.isDead() && !alreadyDead) {
  2476.             target.performCollapse();
  2477.         }
  2478.       }
  2479.     }, this);
  2480.     return true;
  2481. };
  2482.  
  2483. BattleManager.actionAniWait = function(frames) {
  2484.     frames *= Yanfly.Param.AnimationRate || 4;
  2485.     this._logWindow._waitCount = parseInt(frames);
  2486.     return false;
  2487. };
  2488.  
  2489. BattleManager.actionCastAnimation = function() {
  2490.   if (!$gameSystem.isSideView() && this._subject.isActor()) return true;
  2491.   if (!this._action.isAttack() && !this._action.isGuard() &&
  2492.   this._action.isSkill()) {
  2493.     if (this._action.item().castAnimation > 0) {
  2494.       var ani = $dataAnimations[this._action.item().castAnimation]
  2495.       this._logWindow.showAnimation(this._subject, [this._subject],
  2496.         this._action.item().castAnimation);
  2497.     }
  2498.   }
  2499.   return true;
  2500. };
  2501.  
  2502.  
  2503. BattleManager.actionClearBattleLog = function() {
  2504.     this._logWindow.clear();
  2505.     return false;
  2506. };
  2507.  
  2508. BattleManager.actionDeathBreak = function() {
  2509.     if (this._subject.isDead()) {
  2510.       this._targets = [];
  2511.       this._actionList = [];
  2512.       this._individualTargets = [];
  2513.       this._phase = 'phaseChange';
  2514.       return false;
  2515.     }
  2516.     return true;
  2517. };
  2518.  
  2519. BattleManager.actionDisplayAction = function() {
  2520.     this._logWindow.displayAction(this._subject, this._action.item());
  2521.     return false;
  2522. };
  2523.  
  2524. BattleManager.actionIfConditions = function(actionName, actionArgs) {
  2525.   var subject = this._subject;
  2526.   var user = this._subject;
  2527.   var target = this._targets[0];
  2528.   var targets = this._targets;
  2529.   var action = this._action;
  2530.   var item = this._action.item();
  2531.   var actionName = this._actSeq[0];
  2532.   if (actionName.match(/IF[ ](.*)/i)) {
  2533.     var text = String(RegExp.$1);
  2534.     try {
  2535.       this._conditionFlags.push(eval(text));
  2536.     } catch (e) {
  2537.       this._conditionFlags.push(false);
  2538.       Yanfly.Util.displayError(e, text, 'ACTION SEQUENCE IF CONDITION ERROR');
  2539.     }
  2540.     this._trueFlags.push(false);
  2541.     var ci = this._conditionFlags.length;
  2542.   }
  2543.   return true;
  2544. };
  2545.  
  2546. BattleManager.actionImmortal = function(actionArgs) {
  2547.     var targets =
  2548.       this.makeActionTargets(actionArgs[0]).filter(Yanfly.Util.onlyUnique);
  2549.     try {
  2550.       var value = eval(String(actionArgs[1]).toLowerCase());
  2551.     } catch (e) {
  2552.       var value = false;
  2553.     }
  2554.     targets.forEach(function (target) {
  2555.       if (value) {
  2556.         target.addImmortal();
  2557.       } else {
  2558.         var alreadyDead = target.isDead();
  2559.         target.removeImmortal();
  2560.       }
  2561.     }, this);
  2562.     return true;
  2563. };
  2564.  
  2565. BattleManager.actionMotionWait = function(actionArgs) {
  2566.     var targets = this.makeActionTargets(actionArgs[0]);
  2567.     if (targets[0].isActor() && targets[0].isSpriteVisible()) {
  2568.       this._logWindow._waitCount += 12;
  2569.       return false;
  2570.     }
  2571.     return true;
  2572. };
  2573.  
  2574. BattleManager.actionPerformAction = function() {
  2575.     this._logWindow.performAction(this._subject, this._action);
  2576.     if (this._subject.isActor() && this._subject.isSpriteVisible) {
  2577.       this._logWindow._waitCount += 20;
  2578.       return false;
  2579.     }
  2580.     return true;
  2581. };
  2582.  
  2583. BattleManager.actionPerformFinish = function() {
  2584.     this._logWindow.performActionEnd(this._subject);
  2585.     $gameParty.aliveMembers().forEach(function(member) {
  2586.       member.spriteReturnHome();
  2587.     });
  2588.     $gameTroop.aliveMembers().forEach(function(member) {
  2589.       member.spriteReturnHome();
  2590.     });
  2591.     return true;
  2592. };
  2593.  
  2594. BattleManager.actionPerformStart = function() {
  2595.     this._logWindow.performActionStart(this._subject, this._action);
  2596.     return true;
  2597. };
  2598.  
  2599. BattleManager.actionWait = function(frames) {
  2600.     this._logWindow._waitCount = parseInt(frames);
  2601.     return false;
  2602. };
  2603.  
  2604. BattleManager.actionWaitForAnimation = function() {
  2605.     this._logWindow.waitForAnimation();
  2606.     return false;
  2607. };
  2608.  
  2609. BattleManager.actionWaitForEffect = function() {
  2610.     this._logWindow.waitForEffect();
  2611.     return false;
  2612. };
  2613.  
  2614. BattleManager.actionWaitForMovement = function() {
  2615.     this._logWindow.waitForMovement();
  2616.     return false;
  2617. };
  2618.  
  2619. BattleManager.actionWaitForNewLine = function() {
  2620.     this._logWindow.waitForNewLine();
  2621.     return false;
  2622. };
  2623.  
  2624. BattleManager.actionWaitForPopups = function() {
  2625.     this._logWindow.waitForPopups();
  2626.     return false;
  2627. };
  2628.  
  2629. //=============================================================================
  2630. // SceneManager
  2631. //=============================================================================
  2632.  
  2633. Yanfly.BEC.SceneManager_snapForBackground = SceneManager.snapForBackground;
  2634. SceneManager.snapForBackground = function() {
  2635.     if ($gameParty.inBattle()) {
  2636.       var spriteset = this._scene._spriteset;
  2637.       if (spriteset.battleback1Name() === '' &&
  2638.       spriteset.battleback2Name() === '') {
  2639.         return;
  2640.       }
  2641.     }
  2642.     Yanfly.BEC.SceneManager_snapForBackground.call(this);
  2643. };
  2644.  
  2645. //=============================================================================
  2646. // Sprite_Battler
  2647. //=============================================================================
  2648.  
  2649. Yanfly.BEC.Sprite_Battler_initialize = Sprite_Battler.prototype.initialize;
  2650. Sprite_Battler.prototype.initialize = function(battler) {
  2651.     this.preSpriteInitialize(battler);
  2652.     Yanfly.BEC.Sprite_Battler_initialize.call(this, battler);
  2653. };
  2654.  
  2655. Sprite_Battler.prototype.preSpriteInitialize = function(battler) {
  2656. };
  2657.  
  2658. Yanfly.BEC.Sprite_Battler_update = Sprite_Battler.prototype.update;
  2659. Sprite_Battler.prototype.update = function() {
  2660.     Yanfly.BEC.Sprite_Battler_update.call(this);
  2661.     if (this._postSpriteInitialized) return;
  2662.     this.postSpriteInitialize();
  2663. };
  2664.  
  2665. Sprite_Battler.prototype.postSpriteInitialize = function() {
  2666.     this._postSpriteInitialized = true;
  2667. };
  2668.  
  2669. Yanfly.BEC.Sprite_Battler_initMembers = Sprite_Battler.prototype.initMembers;
  2670. Sprite_Battler.prototype.initMembers = function() {
  2671.     Yanfly.BEC.Sprite_Battler_initMembers.call(this);
  2672.     this.adjustAnchor();
  2673.     this.setZ();
  2674. };
  2675.  
  2676. Sprite_Battler.prototype.adjustAnchor = function() {
  2677.     this.anchor.x = 0.5;
  2678.     this.anchor.y = 1.0;
  2679. };
  2680.  
  2681. Sprite_Battler.prototype.setZ = function() {
  2682.     this.z = 1;
  2683. };
  2684.  
  2685. Sprite_Battler.prototype.setupDamagePopup = function() {
  2686.     if (this._battler.isDamagePopupRequested()) {
  2687.       if (this._battler.isSpriteVisible()) {
  2688.         var sprite = new Sprite_Damage();
  2689.         sprite.x = this.x + this.damageOffsetX();
  2690.         sprite.y = this.y + this.damageOffsetY();
  2691.         sprite.setup(this._battler);
  2692.         this.pushDamageSprite(sprite);
  2693.         BattleManager._spriteset.addChild(sprite);
  2694.         this._battler.clearResult();
  2695.       }
  2696.     } else {
  2697.       this._battler.clearDamagePopup();
  2698.     }
  2699. };
  2700.  
  2701. Sprite_Battler.prototype.pushDamageSprite = function(sprite) {
  2702.     var heightBuffer = Yanfly.Param.BECPopupOverlap;
  2703.     if (Yanfly.Param.BECNewPopBottom) {
  2704.       this._damages.push(sprite);
  2705.       this._damages.forEach(function(spr) {
  2706.         for (var i = 0; i < spr.children.length; i++) {
  2707.           childSprite = spr.children[i];
  2708.           childSprite.anchor.y += heightBuffer;
  2709.         }
  2710.       }, this);
  2711.     } else {
  2712.       this._damages.push(sprite);
  2713.       heightBuffer *= this._damages.length
  2714.       for (var i = 0; i < sprite.children.length; i++) {
  2715.         childSprite = sprite.children[i];
  2716.         childSprite.anchor.y += heightBuffer;
  2717.       }
  2718.     }
  2719. };
  2720.  
  2721. Yanfly.BEC.Sprite_Battler_setBattler = Sprite_Battler.prototype.setBattler;
  2722. Sprite_Battler.prototype.setBattler = function(battler) {
  2723.     Yanfly.BEC.Sprite_Battler_setBattler.call(this, battler);
  2724.     if (battler) battler.setBattler(this);
  2725. };
  2726.  
  2727. Yanfly.BEC.Sprite_Battler_startMove = Sprite_Battler.prototype.startMove;
  2728. Sprite_Battler.prototype.startMove = function(x, y, duration) {
  2729.     if (this._battler && !this._battler.spriteCanMove()) return;
  2730.     Yanfly.BEC.Sprite_Battler_startMove.call(this, x, y, duration);
  2731. };
  2732.  
  2733. Sprite_Battler.prototype.stepForward = function() {
  2734.     this.startMove(Yanfly.Param.BECStepDist, 0, 12);
  2735. };
  2736.  
  2737. Sprite_Battler.prototype.stepBack = function() {
  2738.     this.startMove(0, 0, 12);
  2739. };
  2740.  
  2741. Sprite_Battler.prototype.stepFlinch = function() {
  2742.     var flinchX = this.x - this._homeX - Yanfly.Param.BECFlinchDist;
  2743.     var flinchY = this.y - this._homeY;
  2744.     this.startMove(flinchX, flinchY, 6);
  2745. };
  2746.  
  2747. Sprite_Battler.prototype.stepSubBack = function() {
  2748.     var backX = -1 * this.width / 2;
  2749.     this.startMove(backX, 0, 6);
  2750. };
  2751.  
  2752. Sprite_Battler.prototype.stepToSubstitute = function(focus) {
  2753.     var target = focus.battler();
  2754.     var targetX = (this.x - this._homeX) + (target._homeX - this._homeX);
  2755.     var targetY = (this.y - this._homeY) + (target._homeY - this._homeY);;
  2756.     if (focus.isActor()) targetX -= this._mainSprite.width / 2;
  2757.     if (focus.isEnemy()) targetX += this.width / 2;
  2758.     this.startMove(targetX, targetY, 1);
  2759. };
  2760.  
  2761. Sprite_Battler.prototype.startMotion = function(motionType) {
  2762. };
  2763.  
  2764. Sprite_Battler.prototype.forceMotion = function(motionType) {
  2765. };
  2766.  
  2767. Sprite_Battler.prototype.refreshMotion = function() {
  2768. };
  2769.  
  2770. Sprite_Battler.prototype.startActionMotion = function() {
  2771. };
  2772.  
  2773. Sprite_Battler.prototype.moveForward = function(distance, frames) {
  2774.     distance = parseInt(distance);
  2775.     frames = parseInt(frames);
  2776.     if (this._battler.isActor()) distance *= -1;
  2777.     var moveX = this.x - this._homeX + distance;
  2778.     var moveY = this.y - this._homeY;
  2779.     this.startMove(moveX, moveY, frames);
  2780. };
  2781.  
  2782. Sprite_Battler.prototype.moveToPoint = function(pointX, pointY, frames) {
  2783.     pointX = parseInt(pointX);
  2784.     pointY = parseInt(pointY);
  2785.     var targetX = pointX - this._homeX;
  2786.     var targetY = pointY - this._homeY;
  2787.     this.startMove(targetX, targetY, frames);
  2788. };
  2789.  
  2790. Sprite_Battler.prototype.setMirror = function(value) {
  2791.     if (this.scale.x > 0 && value) this.scale.x *= -1;
  2792.     if (this.scale.x < 0 && !value) this.scale.x *= -1;
  2793. };
  2794.  
  2795. Sprite_Battler.prototype.isPopupPlaying = function() {
  2796.     if (this._damages.length > 0) {
  2797.       for (var i = 0; i < this._damages.length; ++i) {
  2798.         return this._damages[i].isPlaying();
  2799.       }
  2800.     }
  2801.     return false;
  2802. };
  2803.  
  2804. //=============================================================================
  2805. // Sprite_Actor
  2806. //=============================================================================
  2807.  
  2808. Sprite_Actor.prototype.preSpriteInitialize = function(battler) {
  2809.     Sprite_Battler.prototype.preSpriteInitialize.call(this, battler);
  2810. };
  2811.  
  2812. Sprite_Actor.prototype.postSpriteInitialize = function() {
  2813.     Sprite_Battler.prototype.postSpriteInitialize.call(this);
  2814. };
  2815.  
  2816. Yanfly.BEC.Sprite_Actor_updateShadow = Sprite_Actor.prototype.updateShadow;
  2817. Sprite_Actor.prototype.updateShadow = function() {
  2818.     if (this._hideShadows === undefined) {
  2819.       this._hideShadows = Yanfly.Param.BECShowShadows;
  2820.     }
  2821.     if (!this._hideShadows) return this._shadowSprite.visible = false;
  2822.     Yanfly.BEC.Sprite_Actor_updateShadow.call(this);
  2823. };
  2824.  
  2825. Sprite_Actor.prototype.setActorHome = function(index) {
  2826.     var screenWidth = Graphics.boxWidth;
  2827.     var screenHeight = Graphics.boxHeight;
  2828.     var maxSize = $gameParty.maxBattleMembers();
  2829.     var partySize = $gameParty.battleMembers().length;
  2830.     var statusHeight = eval(Yanfly.Param.BECCommandRows);
  2831.     statusHeight *= Window_Base.prototype.lineHeight.call(this);
  2832.     statusHeight += Window_Base.prototype.standardPadding.call(this) * 2;
  2833.     if ($gameSystem.isSideView()) {
  2834.       var code = Yanfly.Param.BECHomePosX;
  2835.       try {
  2836.         var homeX = eval(code);
  2837.       } catch (e) {
  2838.         var homeX = 0;
  2839.         Yanfly.Util.displayError(e, code, 'SIDE VIEW HOME X FORMULA ERROR');
  2840.       }
  2841.       var code = Yanfly.Param.BECHomePosY;
  2842.       try {
  2843.         var homeY = eval(code);
  2844.       } catch (e) {
  2845.         var homeY = 0;
  2846.         Yanfly.Util.displayError(e, code, 'SIDE VIEW HOME Y FORMULA ERROR');
  2847.       }
  2848.     } else {
  2849.       var code = Yanfly.Param.BECFrontPosX;
  2850.       try {
  2851.         var homeX = eval(code);
  2852.       } catch (e) {
  2853.         var homeX = 0;
  2854.         Yanfly.Util.displayError(e, code, 'FRONT VIEW HOME X FORMULA ERROR');
  2855.       }
  2856.       var code = Yanfly.Param.BECFrontPosY;
  2857.       try {
  2858.         var homeY = eval(code);
  2859.       } catch (e) {
  2860.         var homeY = 0;
  2861.         Yanfly.Util.displayError(e, code, 'FRONT VIEW HOME Y FORMULA ERROR');
  2862.       }
  2863.     }
  2864.     this._checkAliveStatus = false;
  2865.     if ($gameParty.battleMembers()[index]) {
  2866.       var actor = $gameParty.battleMembers()[index];
  2867.       if (actor.isAlive()) this._checkAliveStatus = true;
  2868.     }
  2869.     this.setHome(homeX, homeY);
  2870.     this.moveToStartPosition();
  2871. };
  2872.  
  2873. Sprite_Actor.prototype.moveToStartPosition = function() {
  2874.     if (BattleManager._bypassMoveToStartLocation) return;
  2875.     if ($gameSystem.isSideView() && this._checkAliveStatus) {
  2876.       this.startMove(300, 0, 0);
  2877.     }
  2878. };
  2879.  
  2880. Sprite_Actor.prototype.setupMotion = function() {
  2881. };
  2882.  
  2883. Sprite_Actor.prototype.forceMotion = function(motionType) {
  2884.     var newMotion = Sprite_Actor.MOTIONS[motionType];
  2885.     this._motion = newMotion;
  2886.     this._motionCount = 0;
  2887.     this._pattern = 0;
  2888. };
  2889.  
  2890. Sprite_Actor.prototype.updateTargetPosition = function() {
  2891. };
  2892.  
  2893. Sprite_Actor.prototype.updateMotion = function() {
  2894.     this.updateMotionCount();
  2895. };
  2896.  
  2897. Sprite_Actor.prototype.onMoveEnd = function() {
  2898.     Sprite_Battler.prototype.onMoveEnd.call(this);
  2899. };
  2900.  
  2901. Sprite_Actor.prototype.stepForward = function() {
  2902.     this.startMove(-Yanfly.Param.BECStepDist, 0, 12);
  2903. };
  2904.  
  2905. Sprite_Actor.prototype.stepFlinch = function() {
  2906.     var flinchX = this.x - this._homeX + Yanfly.Param.BECFlinchDist;
  2907.     var flinchY = this.y - this._homeY;
  2908.     this.startMove(flinchX, flinchY, 6);
  2909. };
  2910.  
  2911. Sprite_Actor.prototype.stepSubBack = function() {
  2912.     var backX = this._mainSprite.width / 2;
  2913.     this.startMove(backX, 0, 6);
  2914. };
  2915.  
  2916. Yanfly.BEC.Sprite_Actor_updateBitmap = Sprite_Actor.prototype.updateBitmap;
  2917. Sprite_Actor.prototype.updateBitmap = function() {
  2918.     var name = this._actor.battlerName();
  2919.     var needUpdate = false;
  2920.     if (this._battlerName !== name) needUpdate = true;
  2921.     Yanfly.BEC.Sprite_Actor_updateBitmap.call(this);
  2922.     if (needUpdate) this.adjustAnchor();
  2923. };
  2924.  
  2925. Sprite_Actor.prototype.adjustAnchor = function() {
  2926.     if (!this._mainSprite) return;
  2927.     this._mainSprite.anchor.x = this._actor.anchorX();
  2928.     this._mainSprite.anchor.y = this._actor.anchorY();
  2929. };
  2930.  
  2931. Yanfly.BEC.Sprite_Actor_updateFrame = Sprite_Actor.prototype.updateFrame;
  2932. Sprite_Actor.prototype.updateFrame = function() {
  2933.     Yanfly.BEC.Sprite_Actor_updateFrame.call(this);
  2934.     if (!this._mainSprite) return;
  2935.     if (!this._mainSprite.bitmap) return;
  2936.     if (this._mainSprite.bitmap.width > 0 && !this.bitmap) {
  2937.       var sw = this._mainSprite.bitmap.width / 9;
  2938.       var sh = this._mainSprite.bitmap.height / 6;
  2939.       this.bitmap = new Bitmap(sw, sh);
  2940.     }
  2941. };
  2942.  
  2943. Yanfly.BEC.Sprite_Actor_refreshMotion = Sprite_Actor.prototype.refreshMotion;
  2944. Sprite_Actor.prototype.refreshMotion = function() {
  2945.     var actor = this._actor;
  2946.     if (!actor) return;
  2947.     var motionGuard = Sprite_Actor.MOTIONS['guard'];
  2948.     if (this._motion === motionGuard && !BattleManager.isInputting()) return;
  2949.     var stateMotion = actor.stateMotionIndex();
  2950.     if (actor.isInputting() || actor.isActing()) {
  2951.       this.startMotion(actor.idleMotion());
  2952.     } else if (stateMotion === 3) {
  2953.       this.startMotion(actor.deadMotion());
  2954.     } else if (stateMotion === 2) {
  2955.       this.startMotion(actor.sleepMotion());
  2956.     } else if (actor.isChanting()) {
  2957.       this.startMotion(actor.chantMotion());
  2958.     } else if (actor.isGuard() || actor.isGuardWaiting()) {
  2959.       this.startMotion(actor.guardMotion());
  2960.     } else if (stateMotion === 1) {
  2961.       this.startMotion(actor.abnormalMotion());
  2962.     } else if (actor.isDying()) {
  2963.       this.startMotion(actor.dyingMotion());
  2964.     } else if (actor.isUndecided()) {
  2965.       this.startMotion(actor.idleMotion());
  2966.     } else {
  2967.       this.startMotion(actor.waitMotion());
  2968.     }
  2969. };
  2970.  
  2971. //=============================================================================
  2972. // Sprite_Enemy
  2973. //=============================================================================
  2974.  
  2975. Sprite_Enemy.prototype.preSpriteInitialize = function(battler) {
  2976.     Sprite_Battler.prototype.preSpriteInitialize.call(this, battler);
  2977.     this._visualSelect = Yanfly.Param.BECEnemySelect;
  2978.     if (this._visualSelect) this.createVisualSelectWindow();
  2979. };
  2980.  
  2981. Yanfly.BEC.Sprite_Enemy_update = Sprite_Enemy.prototype.update;
  2982. Sprite_Enemy.prototype.update = function() {
  2983.     Yanfly.BEC.Sprite_Enemy_update.call(this);
  2984.     this.addVisualSelectWindow();
  2985. };
  2986.  
  2987. Sprite_Enemy.prototype.addVisualSelectWindow = function() {
  2988.     if (!this._visualSelect) return;
  2989.     if (this._addedVisualSelect) return;
  2990.     if (!SceneManager._scene) return;
  2991.     var scene = SceneManager._scene;
  2992.     if (!scene._windowLayer) return;
  2993.     this._addedVisualSelect = true;
  2994.     scene.addChild(this._visualSelectWindow);
  2995. };
  2996.  
  2997. Sprite_Enemy.prototype.createVisualSelectWindow = function() {
  2998.     this._visualSelectWindow = new Window_EnemyVisualSelect();
  2999. };
  3000.  
  3001. Yanfly.BEC.Sprite_Enemy_setBattler = Sprite_Enemy.prototype.setBattler;
  3002. Sprite_Enemy.prototype.setBattler = function(battler) {
  3003.     Yanfly.BEC.Sprite_Enemy_setBattler.call(this, battler);
  3004.     if (this._visualSelectWindow) this._visualSelectWindow.setBattler(battler);
  3005. };
  3006.  
  3007. //=============================================================================
  3008. // Sprite_Weapon
  3009. //=============================================================================
  3010.  
  3011. Yanfly.BEC.Sprite_Weapon_setup = Sprite_Weapon.prototype.setup;
  3012. Sprite_Weapon.prototype.setup = function(weaponImageId) {
  3013.     Yanfly.BEC.Sprite_Weapon_setup.call(this, weaponImageId);
  3014.     this._animationCount -= 1; // Synch with sprite
  3015. };
  3016.  
  3017. //=============================================================================
  3018. // Sprite_Damage
  3019. //=============================================================================
  3020.  
  3021. Yanfly.BEC.Sprite_Damage_initialize = Sprite_Damage.prototype.initialize;
  3022. Sprite_Damage.prototype.initialize = function() {
  3023.     Yanfly.BEC.Sprite_Damage_initialize.call(this);
  3024.     this._duration = Yanfly.Param.BECPopupDur;
  3025. };
  3026.  
  3027. Sprite_Damage.prototype.setup = function(target) {
  3028.     this._result = target.shiftDamagePopup();
  3029.     var result = this._result;
  3030.     if (result.missed || result.evaded) {
  3031.       this.createMiss();
  3032.     } else if (result.hpAffected) {
  3033.       this.createDigits(0, result.hpDamage);
  3034.     } else if (target.isAlive() && result.mpDamage !== 0) {
  3035.       this.createDigits(2, result.mpDamage);
  3036.     }
  3037.     if (result.critical) {
  3038.       this.setupCriticalEffect();
  3039.     }
  3040. };
  3041.  
  3042. Sprite_Damage.prototype.setupCriticalEffect = function() {
  3043.     this._flashColor = eval('[' + Yanfly.Param.BECCritPopup + ']');
  3044.     this._flashDuration = Yanfly.Param.BECCritDur;
  3045. };
  3046.  
  3047. //=============================================================================
  3048. // Sprite_StateIcon
  3049. //=============================================================================
  3050.  
  3051. Yanfly.BEC.Sprite_StateIcon_update = Sprite_StateIcon.prototype.update;
  3052. Sprite_StateIcon.prototype.update = function() {
  3053.     Yanfly.BEC.Sprite_StateIcon_update.call(this);
  3054.     this.updateMirror();
  3055. };
  3056.  
  3057. Sprite_StateIcon.prototype.updateMirror = function() {
  3058.     if (this.parent.scale.x < 0) this.scale.x = -1 * Math.abs(this.scale.x);
  3059.     if (this.parent.scale.x > 0) this.scale.x = Math.abs(this.scale.x);
  3060. };
  3061.  
  3062. //=============================================================================
  3063. // Sprite_StateOverlay
  3064. //=============================================================================
  3065.  
  3066. Yanfly.BEC.Sprite_StateOverlay_update = Sprite_StateOverlay.prototype.update;
  3067. Sprite_StateOverlay.prototype.update = function() {
  3068.     Yanfly.BEC.Sprite_StateOverlay_update.call(this);
  3069.     this.updateMirror();
  3070. };
  3071.  
  3072. Sprite_StateOverlay.prototype.updateMirror = function() {
  3073.     if (this.parent.scale.x < 0) this.scale.x = -1 * Math.abs(this.scale.x);
  3074.     if (this.parent.scale.x > 0) this.scale.x = Math.abs(this.scale.x);
  3075. };
  3076.  
  3077. //=============================================================================
  3078. // Spriteset_Battle
  3079. //=============================================================================
  3080.  
  3081. Spriteset_Battle.prototype.isBusy = function() {
  3082.     return false;
  3083. };
  3084.  
  3085. Yanfly.BEC.Spriteset_Battle_update = Spriteset_Battle.prototype.update;
  3086. Spriteset_Battle.prototype.update = function() {
  3087.     Yanfly.BEC.Spriteset_Battle_update.call(this);
  3088.     this.updateZCoordinates();
  3089. };
  3090.  
  3091. Spriteset_Battle.prototype.updateZCoordinates = function() {
  3092.   if (Imported.YEP_ImprovedBattlebacks) {
  3093.     this.updateBattlebackGroupRemove();
  3094.   } else {
  3095.     this._battleField.removeChild(this._back1Sprite);
  3096.     this._battleField.removeChild(this._back2Sprite);
  3097.   }
  3098.   this._battleField.children.sort(this.battleFieldDepthCompare);
  3099.   if (Imported.YEP_ImprovedBattlebacks) {
  3100.     this.updateBattlebackGroupAdd();
  3101.   } else {
  3102.     this._battleField.addChildAt(this._back2Sprite, 0);
  3103.     this._battleField.addChildAt(this._back1Sprite, 0);
  3104.   }
  3105. };
  3106.  
  3107. Spriteset_Battle.prototype.battleFieldDepthCompare = function(a, b) {
  3108.     var priority = BattleManager.getSpritePriority();
  3109.     if (a._battler && b._battler && priority !== 0) {
  3110.       if (priority === 1) {
  3111.         if (a._battler.isActor() && b._battler.isEnemy()) return 1;
  3112.         if (a._battler.isEnemy() && b._battler.isActor()) return -1;
  3113.       } else if (priority === 2) {
  3114.         if (a._battler.isActor() && b._battler.isEnemy()) return -1;
  3115.         if (a._battler.isEnemy() && b._battler.isActor()) return 1;
  3116.       }
  3117.     }
  3118.     if (a.z < b.z) return -1;
  3119.     if (a.z > b.z) return 1;
  3120.     if (a.y < b.y) return -1;
  3121.     if (a.y > b.y) return 1;
  3122.     return 0;
  3123. };
  3124.  
  3125. Spriteset_Battle.prototype.isPopupPlaying = function() {
  3126.     return this.battlerSprites().some(function(sprite) {
  3127.         return sprite.isPopupPlaying();
  3128.     });
  3129. };
  3130.  
  3131. Yanfly.BEC.Spriteset_Battle_battlerSprites =
  3132.   Spriteset_Battle.prototype.battlerSprites;
  3133. Spriteset_Battle.prototype.battlerSprites = function() {
  3134.   var sprites = Yanfly.BEC.Spriteset_Battle_battlerSprites.call(this);
  3135.   var length = sprites.length;
  3136.   var result = [];
  3137.   for (var i = 0; i < length; ++i) {
  3138.     var sprite = sprites[i];
  3139.     if (!sprite) continue;
  3140.     if (!sprite._battler) continue;
  3141.     result.push(sprite);
  3142.   }
  3143.   return result;
  3144. };
  3145.  
  3146. //=============================================================================
  3147. // Game_Temp
  3148. //=============================================================================
  3149.  
  3150. Game_Temp.prototype.clearActionSequenceSettings = function() {
  3151. };
  3152.  
  3153. Game_Temp.prototype.forceActionQueue = function(command) {
  3154.   if (!this._forceActionQueue) {
  3155.     this._forceActionQueue = JsonEx.makeDeepCopy($dataCommonEvents[1]);
  3156.     this._forceActionQueue.list = [];
  3157.   }
  3158.   this._forceActionQueue.list.push(command);
  3159. };
  3160.  
  3161. Yanfly.BEC.Game_Temp_clearCommonEvent = Game_Temp.prototype.clearCommonEvent;
  3162. Game_Temp.prototype.clearCommonEvent = function() {
  3163.     this._forceActionQueue = undefined;
  3164.     Yanfly.BEC.Game_Temp_clearCommonEvent.call(this);
  3165. };
  3166.  
  3167. Yanfly.BEC.Game_Temp_isCommonEventReserved =
  3168.   Game_Temp.prototype.isCommonEventReserved;
  3169. Game_Temp.prototype.isCommonEventReserved = function() {
  3170.   if (this._forceActionQueue) return true;
  3171.   return Yanfly.BEC.Game_Temp_isCommonEventReserved.call(this);
  3172. };
  3173.  
  3174. Yanfly.BEC.Game_Temp_reservedCommonEvent =
  3175.   Game_Temp.prototype.reservedCommonEvent;
  3176. Game_Temp.prototype.reservedCommonEvent = function() {
  3177.   if (this._forceActionQueue) {
  3178.     return this._forceActionQueue;
  3179.   }
  3180.   return Yanfly.BEC.Game_Temp_reservedCommonEvent.call(this);
  3181. };
  3182.  
  3183. //=============================================================================
  3184. // Game_System
  3185. //=============================================================================
  3186.  
  3187. Yanfly.BEC.Game_System_initialize = Game_System.prototype.initialize;
  3188. Game_System.prototype.initialize = function() {
  3189.     Yanfly.BEC.Game_System_initialize.call(this);
  3190.     this.initBattleSystem();
  3191. };
  3192.  
  3193. Game_System.prototype.initBattleSystem = function() {
  3194.     this._battleSystem = Yanfly.Param.BECSystem.toLowerCase();
  3195. };
  3196.  
  3197. Game_System.prototype.getBattleSystem = function() {
  3198.     if (this._battleSystem === undefined) this.initBattleSystem();
  3199.     return this._battleSystem;
  3200. };
  3201.  
  3202. Game_System.prototype.setBattleSystem = function(type) {
  3203.     this._battleSystem = type.toLowerCase();
  3204. };
  3205.  
  3206. //=============================================================================
  3207. // Game_Interpreter
  3208. //=============================================================================
  3209.  
  3210. Yanfly.BEC.Game_Interpreter_pluginCommand =
  3211.     Game_Interpreter.prototype.pluginCommand;
  3212. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  3213.     Yanfly.BEC.Game_Interpreter_pluginCommand.call(this, command, args);
  3214.     if (command === 'setBattleSys' && !$gameParty.inBattle()) {
  3215.       this.setBattleSystem(args[0]);
  3216.     }
  3217. };
  3218.  
  3219. Game_Interpreter.prototype.setBattleSystem = function(value) {
  3220.     $gameSystem.setBattleSystem(value);
  3221. };
  3222.  
  3223. //=============================================================================
  3224. // Game_Action
  3225. //=============================================================================
  3226.  
  3227. Game_Action.prototype.speed = function() {
  3228.     var user = this.subject(); var a = user;
  3229.     var maxhp = user.mhp; var mhp = user.mhp; var hp = user.hp;
  3230.     var maxmp = user.mmp; var mmp = user.mmp; var mp = user.mp;
  3231.     var maxtp = user.maxTp(); var mtp = user.maxTp(); var tp = user.tp;
  3232.     var atk = user.atk; var def = user.def; var mat = user.mat;
  3233.     var int = user.mat; var mdf = user.mdf; var res = user.res;
  3234.     var agi = user.agi; var luk = user.luk;
  3235.     var code = Yanfly.Param.BECActionSpeed;
  3236.     try {
  3237.       var speed = eval(code);
  3238.     } catch (e) {
  3239.       var speed = 0;
  3240.       Yanfly.Util.displayError(e, code, 'ACTION SPEED FORMULA ERROR');
  3241.     }
  3242.     if (this.item()) speed += this.item().speed;
  3243.     if (this.isAttack()) speed += this.subject().attackSpeed();
  3244.     return speed;
  3245. };
  3246.  
  3247. Yanfly.BEC.Game_Action_apply = Game_Action.prototype.apply;
  3248. Game_Action.prototype.apply = function(target) {
  3249.     target._result = null;
  3250.     target._result = new Game_ActionResult();
  3251.     this.subject()._result = null;
  3252.     this.subject()._result = new Game_ActionResult();
  3253.     Yanfly.BEC.Game_Action_apply.call(this, target);
  3254.     if ($gameParty.inBattle()) {
  3255.       target.startDamagePopup();
  3256.       target.performResultEffects();
  3257.       if (target !== this.subject()) this.subject().startDamagePopup();
  3258.     }
  3259. };
  3260.  
  3261. Game_Action.prototype.itemEffectAddAttackState = function(target, effect) {
  3262.     this.subject().attackStates().forEach(function(stateId) {
  3263.         var chance = effect.value1;
  3264.         chance *= target.stateRate(stateId);
  3265.         chance *= this.subject().attackStatesRate(stateId);
  3266.         chance *= this.lukEffectRate(target);
  3267.         if (Math.random() < chance) {
  3268.             if (stateId === target.deathStateId()) {
  3269.               if (target.isImmortal()) target.removeImmortal();
  3270.             }
  3271.             target.addState(stateId);
  3272.             this.makeSuccess(target);
  3273.         }
  3274.     }.bind(this), target);
  3275. };
  3276.  
  3277. Game_Action.prototype.itemEffectAddNormalState = function(target, effect) {
  3278.     var stateId = effect.dataId;
  3279.     var chance = effect.value1;
  3280.     if (!this.isCertainHit()) {
  3281.       chance *= target.stateRate(stateId);
  3282.       chance *= this.lukEffectRate(target);
  3283.     }
  3284.     if (Math.random() < chance) {
  3285.       if (stateId === target.deathStateId()) {
  3286.         if (target.isImmortal()) target.removeImmortal();
  3287.       }
  3288.       target.addState(stateId);
  3289.       this.makeSuccess(target);
  3290.     }
  3291. };
  3292.  
  3293. Yanfly.BEC.Game_Action_applyGlobal = Game_Action.prototype.applyGlobal;
  3294. Game_Action.prototype.applyGlobal = function() {
  3295.     if ($gameParty.inBattle()) return;
  3296.     Yanfly.BEC.Game_Action_applyGlobal.call(this);
  3297. };
  3298.  
  3299. Yanfly.BEC.Game_Action_needsSelection = Game_Action.prototype.needsSelection;
  3300. Game_Action.prototype.needsSelection = function() {
  3301.     if ($gameParty.inBattle() && this.item().scope === 0) return false;
  3302.     if ($gameParty.inBattle() && BattleManager.isForceSelection()) return true;
  3303.     return Yanfly.BEC.Game_Action_needsSelection.call(this);
  3304. };
  3305.  
  3306. //=============================================================================
  3307. // Game_BattlerBase
  3308. //=============================================================================
  3309.  
  3310. Yanfly.BEC.Game_BattlerBase_recoverAll = Game_BattlerBase.prototype.recoverAll;
  3311. Game_BattlerBase.prototype.recoverAll = function() {
  3312.     Yanfly.BEC.Game_BattlerBase_recoverAll.call(this);
  3313.     this.refresh();
  3314.     if ($gameParty.inBattle()) this.forceMotionRefresh();
  3315. };
  3316.  
  3317. Game_BattlerBase.prototype.requestStatusRefresh = function() {
  3318.     this._statusRefreshRequested = true;
  3319. };
  3320.  
  3321. Game_BattlerBase.prototype.isStatusRefreshRequested = function() {
  3322.     return this._statusRefreshRequested;
  3323. };
  3324.  
  3325. Game_BattlerBase.prototype.completetStatusRefreshRequest = function() {
  3326.     this._statusRefreshRequested = false;
  3327. };
  3328.  
  3329. Game_BattlerBase.prototype.updateStateTicks = function() {
  3330.     var needRefresh = false;
  3331.     for (var i = 0; i < this._states.length; ++i) {
  3332.       var stateId = this._states[i];
  3333.       var state = $dataStates[stateId];
  3334.       if (!state) continue;
  3335.       if (state.autoRemovalTiming !== 2) continue;
  3336.       if (!this._stateTurns[stateId]) continue;
  3337.       var value = BattleManager.tickRate() / Yanfly.Param.BECTurnTime;
  3338.       var shown1 = Math.ceil(this._stateTurns[stateId]);
  3339.       this._stateTurns[stateId] -= value;
  3340.       var shown2 = Math.ceil(this._stateTurns[stateId]);
  3341.       if (shown1 !== shown2) needRefresh = true;
  3342.       if (this._stateTurns[stateId] <= 0) this.removeState(stateId);
  3343.     }
  3344.     if (needRefresh) this.refresh();
  3345. };
  3346.  
  3347. Game_BattlerBase.prototype.isBypassUpdateTurns = function() {
  3348.     if ($gameTroop.isEventRunning()) return true;
  3349.     return false;
  3350. };
  3351.  
  3352. Game_BattlerBase.prototype.updateStateTurns = function() {
  3353.     this.updateStateTurnEnd();
  3354. };
  3355.  
  3356. Game_BattlerBase.prototype.updateStateTurnTiming = function(timing) {
  3357.     if (this.isBypassUpdateTurns()) return;
  3358.     var statesRemoved = [];
  3359.     this._freeStateTurn = this._freeStateTurn || [];
  3360.     for (var i = 0; i < this._states.length; ++i) {
  3361.       var stateId = this._states[i];
  3362.       var state = $dataStates[stateId];
  3363.       if (!state) continue;
  3364.       if (state.autoRemovalTiming !== timing) continue;
  3365.       if (!this._stateTurns[stateId]) continue;
  3366.       if (this._freeStateTurn.contains(stateId)) {
  3367.         var index = this._freeStateTurn.indexOf(stateId);
  3368.         this._freeStateTurn.splice(index, 1);
  3369.       } else {
  3370.         this._stateTurns[stateId] -= 1;
  3371.       }
  3372.       if (this._stateTurns[stateId] <= 0) statesRemoved.push(stateId);
  3373.     }
  3374.     for (var i = 0; i < statesRemoved.length; ++i) {
  3375.       var stateId = statesRemoved[i];
  3376.       this.removeState(stateId);
  3377.     }
  3378. };
  3379.  
  3380. Game_BattlerBase.prototype.updateStateActionStart = function() {
  3381.     this.updateStateTurnTiming(3);
  3382. };
  3383.  
  3384. Game_BattlerBase.prototype.updateStateActionEnd = function() {
  3385.     this.updateStateTurnTiming(1);
  3386. };
  3387.  
  3388. Game_BattlerBase.prototype.updateStateTurnStart = function() {
  3389.     this.updateStateTurnTiming(4);
  3390. };
  3391.  
  3392. Game_BattlerBase.prototype.updateStateTurnEnd = function() {
  3393.     this.updateStateTurnTiming(2);
  3394. };
  3395.  
  3396. Game_BattlerBase.prototype.updateBuffTicks = function() {
  3397.     var needRefresh = false;
  3398.     for (var i = 0; i < this._buffTurns.length; i++) {
  3399.       if (this._buffTurns[i] <= 0) continue;
  3400.       var value = BattleManager.tickRate() / Yanfly.Param.BECTurnTime;
  3401.       var shown1 = Math.ceil(this._buffTurns[i]);
  3402.       this._buffTurns[i] -= value;
  3403.       var shown2 = Math.ceil(this._buffTurns[i]);
  3404.       if (shown1 !== shown2) needRefresh = true;
  3405.       if (this._buffTurns[i] <= 0) this.removeBuff(i);
  3406.     }
  3407.     if (needRefresh) this.refresh();
  3408. };
  3409.  
  3410. Game_BattlerBase.prototype.timedTick = function() {
  3411.     return 1 * BattleManager.tickRate();
  3412. };
  3413.  
  3414. Yanfly.BEC.Game_BattlerBase_isStateResist =
  3415.     Game_BattlerBase.prototype.isStateResist;
  3416. Game_BattlerBase.prototype.isStateResist = function(stateId) {
  3417.     if (stateId === this.deathStateId() && this.isImmortal()) return true;
  3418.     return Yanfly.BEC.Game_BattlerBase_isStateResist.call(this, stateId);
  3419. };
  3420.  
  3421. Game_BattlerBase.prototype.isImmortal = function() {
  3422.     return this._immortalState;
  3423. };
  3424.  
  3425. Yanfly.BEC.Game_BattlerBase_paySkillCost =
  3426.     Game_BattlerBase.prototype.paySkillCost;
  3427. Game_BattlerBase.prototype.paySkillCost = function(skill) {
  3428.     this.requestStatusRefresh();
  3429.     Yanfly.BEC.Game_BattlerBase_paySkillCost.call(this, skill);
  3430. };
  3431.  
  3432. //=============================================================================
  3433. // Game_Battler
  3434. //=============================================================================
  3435.  
  3436. Yanfly.BEC.Game_Battler_useItem = Game_Battler.prototype.useItem;
  3437. Game_Battler.prototype.useItem = function(item) {
  3438.     Yanfly.BEC.Game_Battler_useItem.call(this, item);
  3439.     this.refresh();
  3440.     if (!$gameParty.inBattle()) return;
  3441.     this.increaseSelfTurnCount();
  3442.     this.updateStateActionStart();
  3443. };
  3444.  
  3445. Yanfly.BEC.Game_Battler_onBattleStart = Game_Battler.prototype.onBattleStart;
  3446. Game_Battler.prototype.onBattleStart = function() {
  3447.     Yanfly.BEC.Game_Battler_onBattleStart.call(this);
  3448.     this._freeStateTurn = [];
  3449.     this._immortalState = false;
  3450.     this._selfTurnCount = 0;
  3451. };
  3452.  
  3453. Yanfly.BEC.Game_Battler_onBattleEnd = Game_Battler.prototype.onBattleEnd;
  3454. Game_Battler.prototype.onBattleEnd = function() {
  3455.     Yanfly.BEC.Game_Battler_onBattleEnd.call(this);
  3456.     this._freeStateTurn = [];
  3457.     this._immortalState = false;
  3458. };
  3459.  
  3460. Yanfly.BEC.Game_Battler_isSelected = Game_Battler.prototype.isSelected;
  3461. Game_Battler.prototype.isSelected = function() {
  3462.     if ($gameParty.inBattle() && BattleManager.isAllSelection()) {
  3463.       if (!this.isAppeared()) return false;
  3464.       var action = BattleManager.inputtingAction();
  3465.       if (action && action.item()) {
  3466.         if (this.isDead() && this.isEnemy()) return false;
  3467.         if (this.isDead() && this.isActor()) return action.isForDeadFriend();
  3468.         if (action.isForFriend() && this.isActor()) return true;
  3469.         if (action.isForOpponent() && this.isEnemy()) return true;
  3470.       }
  3471.     }
  3472.     return Yanfly.BEC.Game_Battler_isSelected.call(this);
  3473. };
  3474.  
  3475. Yanfly.BEC.Game_Battler_regenerateAll = Game_Battler.prototype.regenerateAll;
  3476. Game_Battler.prototype.regenerateAll = function() {
  3477.     this.clearResult();
  3478.     var lifeState = this.isAlive();
  3479.     Yanfly.BEC.Game_Battler_regenerateAll.call(this);
  3480.     if (!BattleManager.timeBasedStates()) this.updateStateTurns();
  3481.     if (!BattleManager.timeBasedBuffs()) {
  3482.       this.updateBuffTurns();
  3483.       this.removeBuffsAuto();
  3484.     }
  3485.     if (this.isDead() && lifeState === true) {
  3486.       this.performCollapse();
  3487.     }
  3488.     if ($gameParty.inBattle()) this.startDamagePopup();
  3489. };
  3490.  
  3491. Game_Battler.prototype.addImmortal = function() {
  3492.     this._immortalState = true;
  3493. };
  3494.  
  3495. Game_Battler.prototype.removeImmortal = function() {
  3496.     var alreadyDead = this.isDead();
  3497.     this._immortalState = false;
  3498.     this.refresh();
  3499.     if (this.isDead() && !alreadyDead) this.performCollapse();
  3500. };
  3501.  
  3502. Yanfly.BEC.Game_Battler_removeState = Game_Battler.prototype.removeState;
  3503. Game_Battler.prototype.removeState = function(stateId) {
  3504.     Yanfly.BEC.Game_Battler_removeState.call(this, stateId);
  3505. };
  3506.  
  3507. Game_Battler.prototype.clearDamagePopup = function() {
  3508.     this._damagePopup = [];
  3509. };
  3510.  
  3511. Game_Battler.prototype.isDamagePopupRequested = function() {
  3512.     if (!this._damagePopup) this.clearDamagePopup();
  3513.     return this._damagePopup.length > 0;
  3514. };
  3515.  
  3516. Game_Battler.prototype.startDamagePopup = function() {
  3517.     var result = this.result();
  3518.     if (result.missed || result.evaded) {
  3519.       var copyResult = JsonEx.makeDeepCopy(result);
  3520.       copyResult.hpAffected = false;
  3521.       copyResult.mpDamage = 0;
  3522.       this._damagePopup.push(copyResult);
  3523.     }
  3524.     if (result.hpAffected) {
  3525.       var copyResult = JsonEx.makeDeepCopy(result);
  3526.       copyResult.mpDamage = 0;
  3527.       this._damagePopup.push(copyResult);
  3528.     }
  3529.     if (result.mpDamage !== 0) {
  3530.       var copyResult = JsonEx.makeDeepCopy(result);
  3531.       copyResult.hpAffected = false;
  3532.       this._damagePopup.push(copyResult);
  3533.     }
  3534. };
  3535.  
  3536. Game_Battler.prototype.shiftDamagePopup = function() {
  3537.     if (!this._damagePopup) this.clearDamagePopup();
  3538.     return this._damagePopup.shift();
  3539. };
  3540.  
  3541. Yanfly.BEC.Game_Battler_performCollapse =
  3542.     Game_Battler.prototype.performCollapse;
  3543. Game_Battler.prototype.performCollapse = function() {
  3544.     Yanfly.BEC.Game_Battler_performCollapse.call(this);
  3545.     if ($gameParty.inBattle()) this.forceMotion(this.deadMotion());
  3546. };
  3547.  
  3548. Game_Battler.prototype.performResultEffects = function() {
  3549.     var result = this.result();
  3550.     if (result.missed && result.physical) this.performMiss();
  3551.     if (result.evaded) {
  3552.       if (result.physical) {
  3553.         this.performEvasion();
  3554.       } else {
  3555.         this.performMagicEvasion();
  3556.       }
  3557.     }
  3558.     if (result.hpAffected) {
  3559.       if (result.hpDamage > 0 && !result.drain) {
  3560.         this.performDamage();
  3561.       }
  3562.       if (result.hpDamage < 0) {
  3563.         this.performRecovery();
  3564.       }
  3565.     }
  3566.     if (this.isAlive() && result.mpDamage !== 0 && result.mpDamage < 0) {
  3567.       this.performRecovery();
  3568.     }
  3569.     if (this.isAlive() && result.tpDamage !== 0 && result.tpDamage < 0) {
  3570.       this.performRecovery();
  3571.     }
  3572. };
  3573.  
  3574. Yanfly.BEC.Game_Battler_performDamage =
  3575.   Game_Battler.prototype.performDamage;
  3576. Game_Battler.prototype.performDamage = function() {
  3577.     Yanfly.BEC.Game_Battler_performDamage.call(this);
  3578.     this.performFlinch();
  3579. };
  3580.  
  3581. Yanfly.BEC.Game_Battler_performMiss = Game_Battler.prototype.performMiss;
  3582. Game_Battler.prototype.performMiss = function() {
  3583.     Yanfly.BEC.Game_Battler_performMiss.call(this);
  3584.     this.performFlinch();
  3585. };
  3586.  
  3587. Yanfly.BEC.Game_Battler_performEvasion =
  3588.     Game_Battler.prototype.performEvasion;
  3589. Game_Battler.prototype.performEvasion = function() {
  3590.     Yanfly.BEC.Game_Battler_performEvasion.call(this);
  3591.     this.performFlinch();
  3592. };
  3593.  
  3594. Yanfly.BEC.Game_Battler_performMagicEvasion =
  3595.     Game_Battler.prototype.performMagicEvasion;
  3596. Game_Battler.prototype.performMagicEvasion = function() {
  3597.     Yanfly.BEC.Game_Battler_performMagicEvasion.call(this);
  3598.     this.performFlinch();
  3599. };
  3600.  
  3601. Game_Battler.prototype.performFlinch = function() {
  3602.     if (this._flinched || !$gameSystem.isSideView()) return;
  3603.     this._flinched = true;
  3604.     this.spriteStepFlinch();
  3605. };
  3606.  
  3607. Yanfly.BEC.Game_Battler_performReflection =
  3608.     Game_Battler.prototype.performReflection;
  3609. Game_Battler.prototype.performReflection = function() {
  3610.     Yanfly.BEC.Game_Battler_performReflection.call(this);
  3611.     if (!$gameSystem.isSideView() && this.isActor()) return;
  3612.     var animationId = this.reflectAnimationId();
  3613.     var mirror = this.isActor();
  3614.     this.startAnimation(animationId, mirror, 0);
  3615. };
  3616.  
  3617. Yanfly.BEC.Game_Battler_performSubstitute =
  3618.     Game_Battler.prototype.performSubstitute;
  3619. Game_Battler.prototype.performSubstitute = function(target) {
  3620.     Yanfly.BEC.Game_Battler_performSubstitute.call(this, target);
  3621.     if (!$gameSystem.isSideView()) return;
  3622.     this._flinched = true;
  3623.     if (BattleManager._action.isForAll()) {
  3624.       this.spriteStepForward();
  3625.       target.spriteStepSubBack();
  3626.     } else {
  3627.       this.spriteStepToSubstitute(target);
  3628.       target.spriteStepSubBack();
  3629.     }
  3630. };
  3631.  
  3632. Game_Battler.prototype.setBattler = function(sprite) {
  3633.     BattleManager.registerSprite(this, sprite);
  3634. };
  3635.  
  3636. Game_Battler.prototype.battler = function() {
  3637.     return BattleManager.getSprite(this);
  3638. };
  3639.  
  3640. Game_Battler.prototype.requestMotion = function(motionType) {
  3641.     this._motionType = motionType;
  3642.     if (this.battler()) {
  3643.       this.battler().startMotion(motionType);
  3644.     }
  3645. };
  3646.  
  3647. Game_Battler.prototype.forceMotion = function(motionType) {
  3648.     this._motionType = motionType;
  3649.     if (this.battler()) {
  3650.       this.battler().forceMotion(motionType);
  3651.     }
  3652. };
  3653.  
  3654. Game_Battler.prototype.startWeaponAnimation = function(weaponImageId) {
  3655.     this._weaponImageId = weaponImageId;
  3656.     if (this.battler()) {
  3657.       this.battler().setupWeaponAnimation();
  3658.     }
  3659. };
  3660.  
  3661. Game_Battler.prototype.performActionStart = function(action) {
  3662.     if (!action.isGuard()) {
  3663.         this.setActionState('acting');
  3664.         this.spriteStepForward();
  3665.     }
  3666. };
  3667.  
  3668. Yanfly.BEC.Game_Battler_performActionEnd =
  3669.     Game_Battler.prototype.performActionEnd;
  3670. Game_Battler.prototype.performActionEnd = function() {
  3671.     Yanfly.BEC.Game_Battler_performActionEnd.call(this);
  3672.     this.spriteReturnHome();
  3673. };
  3674.  
  3675. Game_Battler.prototype.spriteStepForward = function() {
  3676.     if ($gameSystem.isSideView() && this.battler()) {
  3677.       this.battler().stepForward();
  3678.     }
  3679. };
  3680.  
  3681. Game_Battler.prototype.spriteStepBack = function() {
  3682.     if ($gameSystem.isSideView() && this.battler()) {
  3683.       this.battler().stepBack();
  3684.     }
  3685. };
  3686.  
  3687. Game_Battler.prototype.spriteStepSubBack = function() {
  3688.     if ($gameSystem.isSideView() && this.battler()) {
  3689.       this.battler().stepSubBack();
  3690.     }
  3691. };
  3692.  
  3693. Game_Battler.prototype.spriteStepToSubstitute = function(target) {
  3694.     if ($gameSystem.isSideView() && this.battler()) {
  3695.       this.battler().stepToSubstitute(target);
  3696.     }
  3697. };
  3698.  
  3699. Game_Battler.prototype.spriteStepFlinch = function() {
  3700.     if ($gameSystem.isSideView() && this.battler()) {
  3701.       this.battler().stepFlinch();
  3702.     }
  3703. };
  3704.  
  3705. Game_Battler.prototype.spriteReturnHome = function() {
  3706.     if ($gameSystem.isSideView() && this.battler()) {
  3707.       this._flinched = false;
  3708.       this.spriteFaceForward();
  3709.       this.battler().stepBack();
  3710.       if (this.numActions() <= 0) {
  3711.         this.setActionState('undecided');
  3712.       }
  3713.       this.battler().refreshMotion();
  3714.     }
  3715. };
  3716.  
  3717. Game_Battler.prototype.reflectAnimationId = function() {
  3718.     for (var i = 0; i < this.states().length; ++i) {
  3719.       var state = this.states()[i];
  3720.       if (state.reflectAnimationId > 0) return state.reflectAnimationId;
  3721.     }
  3722.     return Yanfly.Param.BECReflectAni;
  3723. };
  3724.  
  3725. Game_Battler.prototype.spriteCanMove = function() {
  3726.     if (!$gameSystem.isSideView()) return false;
  3727.     for (var i = 0; i < this.states().length; ++i) {
  3728.       var state = this.states()[i];
  3729.       if (state.spriteCannotMove) return false;
  3730.     }
  3731.     return this.canMove();
  3732. };
  3733.  
  3734. Game_Battler.prototype.spritePosX = function() {
  3735.     if ($gameSystem.isSideView() && this.battler()) {
  3736.       return this.battler().x;
  3737.     } else if (this.battler()) {
  3738.       return this.battler().x;
  3739.     } else {
  3740.       return 0;
  3741.     }
  3742. };
  3743.  
  3744. Game_Battler.prototype.spritePosY = function() {
  3745.     if ($gameSystem.isSideView() && this.battler()) {
  3746.       return this.battler().y;
  3747.     } else if (this.battler()) {
  3748.       return this.battler().y;
  3749.     } else {
  3750.       return 0;
  3751.     }
  3752. };
  3753.  
  3754. Game_Battler.prototype.spriteWidth = function() {
  3755.     if ($gameSystem.isSideView() && this.battler() && this.battler().bitmap) {
  3756.       return this.battler().bitmap.width;
  3757.     } else if (this.battler() && this.battler().bitmap) {
  3758.       return this.battler().bitmap.width;
  3759.     } else {
  3760.       return 1;
  3761.     }
  3762. };
  3763.  
  3764. Game_Battler.prototype.spriteHeight = function() {
  3765.     if ($gameSystem.isSideView() && this.battler() && this.battler().bitmap) {
  3766.       return this.battler().bitmap.height;
  3767.     } else if (this.battler() && this.battler().bitmap) {
  3768.       return this.battler().bitmap.height;
  3769.     } else {
  3770.       return 1;
  3771.     }
  3772. };
  3773.  
  3774. Game_Battler.prototype.anchorX = function() {
  3775.     return Yanfly.Param.BECAnchorX;
  3776. };
  3777.  
  3778. Game_Battler.prototype.anchorY = function() {
  3779.     return Yanfly.Param.BECAnchorY;
  3780. };
  3781.  
  3782. Game_Battler.prototype.spriteHomeX = function() {
  3783.     if ($gameSystem.isSideView() && this.battler()) {
  3784.       return this.battler()._homeX;
  3785.     } else {
  3786.       return 0;
  3787.     }
  3788. };
  3789.  
  3790. Game_Battler.prototype.spriteHomeY = function() {
  3791.     if ($gameSystem.isSideView() && this.battler()) {
  3792.       return this.battler()._homeY;
  3793.     } else {
  3794.       return 0;
  3795.     }
  3796. };
  3797.  
  3798. Game_Battler.prototype.setMirror = function(value) {
  3799.     if ($gameSystem.isSideView() && this.battler() && this.spriteCanMove()) {
  3800.       this.battler().setMirror(value);
  3801.     }
  3802. };
  3803.  
  3804. Game_Battler.prototype.spriteFaceForward = function() {
  3805.     this.setMirror(false);
  3806. };
  3807.  
  3808. Game_Battler.prototype.spriteFaceBackward = function() {
  3809.     this.setMirror(true);
  3810. };
  3811.  
  3812. Game_Battler.prototype.spriteFacePoint = function(pointX, pointY) {
  3813.     if (this.spritePosX() > pointX) {
  3814.       this.spriteFaceBackward();
  3815.     } else {
  3816.       this.spriteFaceForward();
  3817.     }
  3818. };
  3819.  
  3820. Game_Battler.prototype.spriteFaceAwayPoint = function(pointX, pointY) {
  3821.     if (this.spritePosX() > pointX) {
  3822.       this.spriteFaceForward();
  3823.     } else {
  3824.       this.spriteFaceBackward();
  3825.     }
  3826. };
  3827.  
  3828. Game_Battler.prototype.spriteFaceTarget = function(target) {
  3829.     if (!target) return;
  3830.     var pointX = target.spritePosX();
  3831.     var pointY = target.spritePosY();
  3832.     this.spriteFacePoint(pointX, pointY);
  3833. };
  3834.  
  3835. Game_Battler.prototype.spriteFaceAwayTarget = function(target) {
  3836.     if (!target) return;
  3837.     var pointX = target.spritePosX();
  3838.     var pointY = target.spritePosY();
  3839.     this.spriteFaceAwayPoint(pointX, pointY);
  3840. };
  3841.  
  3842. Game_Battler.prototype.spriteFaceHome = function() {
  3843.     var pointX = this.spriteHomeX();
  3844.     var pointY = this.spriteHomeY();
  3845.     this.spriteFacePoint(pointX, pointY);
  3846. };
  3847.  
  3848. Game_Battler.prototype.spriteFaceAwayHome = function() {
  3849.     var pointX = target.spriteHomeX();
  3850.     var pointY = target.spriteHomeY();
  3851.     this.spriteFaceAwayPoint(pointX, pointY);
  3852. };
  3853.  
  3854. Game_Battler.prototype.attackMotion = function() {
  3855.     return 'thrust';
  3856. };
  3857.  
  3858. Game_Battler.prototype.performAttack = function() {
  3859. };
  3860.  
  3861. Game_Battler.prototype.forceMotionRefresh = function() {
  3862.     if (!$gameParty.inBattle()) return;
  3863.     if (this.battler()) this.battler().refreshMotion();
  3864. };
  3865.  
  3866. Game_Battler.prototype.requestMotionRefresh = function() {
  3867.     var deadMotion = this.deadMotion();
  3868.     if (this.isDead() && this._motionType !== deadMotion) {
  3869.       this.requestMotion(deadMotion);
  3870.     }
  3871.     if (this.isDead() && this._motionType === deadMotion) return;
  3872.     if (this._motionType === 'victory') return;
  3873.     if (this._motionType === 'escape' && !BattleManager.isInputting()) return;
  3874.     if (this._motionType === 'guard' && !BattleManager.isInputting()) return;
  3875.     this.clearMotion();
  3876.     if (this.battler() && BattleManager.isInputting()) {
  3877.       this.battler().refreshMotion();
  3878.     }
  3879. };
  3880.  
  3881. Game_Battler.prototype.onTurnStart = function() {
  3882.     this.updateStateTurnStart();
  3883. };
  3884.  
  3885. Game_Battler.prototype.onTurnEnd = function() {
  3886.     this.clearResult();
  3887.     if (BattleManager.isTurnBased()) {
  3888.       this.regenerateAll();
  3889.     } else if (BattleManager.isTickBased() && !BattleManager.isTurnEnd()) {
  3890.       this.regenerateAll();
  3891.     }
  3892.     this.removeStatesAuto(2);
  3893. };
  3894.  
  3895. Yanfly.BEC.Game_Battler_onAllActionsEnd =
  3896.     Game_Battler.prototype.onAllActionsEnd;
  3897. Game_Battler.prototype.onAllActionsEnd = function() {
  3898.     Yanfly.BEC.Game_Battler_onAllActionsEnd.call(this);
  3899.     if (!BattleManager._processTurn) this.updateStateActionEnd();
  3900. };
  3901.  
  3902. Game_Battler.prototype.updateTick = function() {
  3903.     if (BattleManager.timeBasedStates()) this.updateStateTicks();
  3904.     if (BattleManager.timeBasedBuffs()) this.updateBuffTicks();
  3905. };
  3906.  
  3907. Game_Battler.prototype.increaseSelfTurnCount = function() {
  3908.     if (this._selfTurnCount === undefined) this._selfTurnCount = 0;
  3909.     this._selfTurnCount += 1;
  3910. };
  3911.  
  3912. Game_Battler.prototype.turnCount = function() {
  3913.     if (BattleManager.isTurnBased()) return $gameTroop.turnCount();
  3914.     if (BattleManager.isTickBased() && Yanfly.Param.BECAISelfTurn) {
  3915.       return this._selfTurnCount;
  3916.     }
  3917.     return $gameTroop.turnCount();
  3918. };
  3919.  
  3920. Game_Battler.prototype.createActions = function() {
  3921.     if (this.currentAction()) return;
  3922.     this.makeActions();
  3923. };
  3924.  
  3925. Yanfly.BEC.Game_Battler_addState = Game_Battler.prototype.addState;
  3926. Game_Battler.prototype.addState = function(stateId) {
  3927.     Yanfly.BEC.Game_Battler_addState.call(this, stateId);
  3928.     if (this.canAddStateFreeTurn(stateId)) this.setStateFreeTurn(stateId);
  3929. };
  3930.  
  3931. Game_Battler.prototype.canAddStateFreeTurn = function(stateId) {
  3932.     if (!$gameParty.inBattle()) return false;
  3933.     if (BattleManager._subject !== this) return false;
  3934.     if ($dataStates[stateId].autoRemovalTiming !== 1) return false;
  3935.     if (Imported.YEP_BuffsStatesCore) {
  3936.       if ($dataStates[stateId].reapplyRules === 0) return false;
  3937.     }
  3938.     return true;
  3939. };
  3940.  
  3941. Game_Battler.prototype.setStateFreeTurn = function(stateId) {
  3942.     this._freeStateTurn = this._freeStateTurn || [];
  3943.     this._freeStateTurn.push(stateId);
  3944. };
  3945.  
  3946. Game_Battler.prototype.idleMotion = function() {
  3947.     return 'walk';
  3948. };
  3949.  
  3950. Game_Battler.prototype.deadMotion = function() {
  3951.     return 'dead';
  3952. };
  3953.  
  3954. Game_Battler.prototype.sleepMotion = function() {
  3955.     return 'sleep';
  3956. };
  3957.  
  3958. Game_Battler.prototype.chantMotion = function() {
  3959.     return 'chant';
  3960. };
  3961.  
  3962. Game_Battler.prototype.guardMotion = function() {
  3963.     return 'guard';
  3964. };
  3965.  
  3966. Game_Battler.prototype.abnormalMotion = function() {
  3967.     return 'abnormal';
  3968. };
  3969.  
  3970. Game_Battler.prototype.dyingMotion = function() {
  3971.     return 'dying';
  3972. };
  3973.  
  3974. Game_Battler.prototype.waitMotion = function() {
  3975.     return 'wait';
  3976. };
  3977.  
  3978. Yanfly.BEC.Game_Battler_startAnimation = Game_Battler.prototype.startAnimation;
  3979. Game_Battler.prototype.startAnimation = function(animationId, mirror, delay) {
  3980.   if (!$dataAnimations[animationId]) return;
  3981.   Yanfly.BEC.Game_Battler_startAnimation.call(this, animationId, mirror, delay);
  3982. };
  3983.  
  3984. //=============================================================================
  3985. // Game_Actor
  3986. //=============================================================================
  3987.  
  3988. Yanfly.BEC.Game_Actor_refresh = Game_Actor.prototype.refresh;
  3989. Game_Actor.prototype.refresh = function() {
  3990.     this._anchorX = undefined;
  3991.     this._anchorY = undefined;
  3992.     Yanfly.BEC.Game_Actor_refresh.call(this);
  3993.     if ($gameParty.inBattle()) this.requestStatusRefresh();
  3994. };
  3995.  
  3996. Game_Actor.prototype.isSpriteVisible = function() {
  3997.     if ($gameSystem.isSideView()) return true;
  3998.     return Yanfly.Param.BECFrontSprite;
  3999. };
  4000.  
  4001. Game_Actor.prototype.reflectAnimationId = function() {
  4002.     if (this.actor().reflectAnimationId > 0) {
  4003.       return this.actor().reflectAnimationId;
  4004.     }
  4005.     if (this.currentClass().reflectAnimationId > 0) {
  4006.       return this.currentClass().reflectAnimationId;
  4007.     }
  4008.     for (var i = 0; i < this.equips().length; ++i) {
  4009.       var equip = this.equips()[i];
  4010.       if (equip && equip.reflectAnimationId > 0) {
  4011.         return equip.reflectAnimationId;
  4012.       }
  4013.     }
  4014.     return Game_Battler.prototype.reflectAnimationId.call(this);
  4015. };
  4016.  
  4017. Game_Actor.prototype.spriteCanMove = function() {
  4018.     if (this.actor().spriteCannotMove) return false;
  4019.     if (this.currentClass().spriteCannotMove) return false;
  4020.     for (var i = 0; i < this.equips().length; ++i) {
  4021.       var equip = this.equips()[i];
  4022.       if (equip && equip.spriteCannotMove) return false;
  4023.     }
  4024.     return Game_Battler.prototype.spriteCanMove.call(this);
  4025. };
  4026.  
  4027. Game_Actor.prototype.spriteWidth = function() {
  4028.     if ($gameSystem.isSideView() && this.battler()) {
  4029.       return this.battler()._mainSprite.width;
  4030.     } else {
  4031.       return 1;
  4032.     }
  4033. };
  4034.  
  4035. Game_Actor.prototype.spriteHeight = function() {
  4036.     if ($gameSystem.isSideView() && this.battler()) {
  4037.       return this.battler()._mainSprite.height;
  4038.     } else {
  4039.       return 1;
  4040.     }
  4041. };
  4042.  
  4043. Game_Actor.prototype.anchorX = function() {
  4044.     if (this._anchorX !== undefined) return this._anchorX;
  4045.     var length = this.states().length;
  4046.     for (var i = 0; i < length; ++i) {
  4047.       var obj = this.states()[i];
  4048.       if (obj && obj.anchorX !== undefined) {
  4049.         this._anchorX = obj.anchorX;
  4050.         return this._anchorX;
  4051.       }
  4052.     }
  4053.     length = this.equips().length;
  4054.     for (var i = 0; i < length; ++i) {
  4055.       var obj = this.equips()[i];
  4056.       if (obj && obj.anchorX !== undefined) {
  4057.         this._anchorX = obj.anchorX;
  4058.         return this._anchorX;
  4059.       }
  4060.     }
  4061.     if (this.currentClass().anchorX !== undefined) {
  4062.       this._anchorX = this.currentClass().anchorX;
  4063.       return this._anchorX;
  4064.     }
  4065.     this._anchorX = this.actor().anchorX;
  4066.     return this._anchorX;
  4067. };
  4068.  
  4069. Game_Actor.prototype.anchorY = function() {
  4070.     if (this._anchorY !== undefined) return this._anchorY;
  4071.     var length = this.states().length;
  4072.     for (var i = 0; i < length; ++i) {
  4073.       var obj = this.states()[i];
  4074.       if (obj && obj.anchorY !== undefined) {
  4075.         this._anchorY = obj.anchorY;
  4076.         return this._anchorY;
  4077.       }
  4078.     }
  4079.     length = this.equips().length;
  4080.     for (var i = 0; i < length; ++i) {
  4081.       var obj = this.equips()[i];
  4082.       if (obj && obj.anchorY !== undefined) {
  4083.         this._anchorY = obj.anchorY;
  4084.         return this._anchorY;
  4085.       }
  4086.     }
  4087.     if (this.currentClass().anchorY !== undefined) {
  4088.       this._anchorY = this.currentClass().anchorY;
  4089.       return this._anchorY;
  4090.     }
  4091.     this._anchorY = this.actor().anchorY;
  4092.     return this._anchorY;
  4093. };
  4094.  
  4095. Game_Actor.prototype.spriteFacePoint = function(pointX, pointY) {
  4096.     if (this.spritePosX() > pointX) {
  4097.       this.spriteFaceForward();
  4098.     } else {
  4099.       this.spriteFaceBackward();
  4100.     }
  4101. };
  4102.  
  4103. Game_Actor.prototype.spriteFaceAwayPoint = function(pointX, pointY) {
  4104.     if (this.spritePosX() > pointX) {
  4105.       this.spriteFaceBackward();
  4106.     } else {
  4107.       this.spriteFaceForward();
  4108.     }
  4109. };
  4110.  
  4111. Game_Actor.prototype.performAttack = function() {
  4112.     var weapons = this.weapons();
  4113.     var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
  4114.     var attackMotion = $dataSystem.attackMotions[wtypeId];
  4115.     if (attackMotion) {
  4116.       if (attackMotion.type === 0) {
  4117.         this.forceMotion('thrust');
  4118.       } else if (attackMotion.type === 1) {
  4119.         this.forceMotion('swing');
  4120.       } else if (attackMotion.type === 2) {
  4121.         this.forceMotion('missile');
  4122.       }
  4123.       this.startWeaponAnimation(attackMotion.weaponImageId);
  4124.     }
  4125. };
  4126.  
  4127. Game_Actor.prototype.attackMotion = function() {
  4128.     var weapons = this.weapons();
  4129.     var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
  4130.     var attackMotion = $dataSystem.attackMotions[wtypeId];
  4131.     if (attackMotion) {
  4132.       if (attackMotion.type === 0) {
  4133.         return 'thrust';
  4134.       } else if (attackMotion.type === 1) {
  4135.         return 'swing';
  4136.       } else if (attackMotion.type === 2) {
  4137.         return 'missile';
  4138.       }
  4139.     };
  4140.     return 'thrust';
  4141. };
  4142.  
  4143. Game_Actor.prototype.performEscapeSuccess = function() {
  4144.     if (this.battler()) {
  4145.       this.performEscape();
  4146.       this.battler().startMove(300, 0, 60);
  4147.     }
  4148. };
  4149.  
  4150. //=============================================================================
  4151. // Game_Enemy
  4152. //=============================================================================
  4153.  
  4154. if (!Game_Enemy.prototype.skills) {
  4155. Game_Enemy.prototype.skills = function() {
  4156.   var skills = []
  4157.   for (var i = 0; i < this.enemy().actions.length; ++i) {
  4158.     var skill = $dataSkills[this.enemy().actions[i].skillId]
  4159.     if (skill) skills.push(skill);
  4160.   }
  4161.   return skills;
  4162. }
  4163. }; // (!Game_Enemy.prototype.skills)
  4164.  
  4165. Game_Enemy.prototype.performActionStart = function(action) {
  4166.     Game_Battler.prototype.performActionStart.call(this, action);
  4167.     if (!$gameSystem.isSideView() || !this.spriteCanMove()) {
  4168.       this.requestEffect('whiten');
  4169.     }
  4170. };
  4171.  
  4172. Yanfly.BEC.Game_Enemy_performDamage = Game_Enemy.prototype.performDamage;
  4173. Game_Enemy.prototype.performDamage = function() {
  4174.     if ($gameSystem.isSideView()) {
  4175.       Game_Battler.prototype.performDamage.call(this);
  4176.       SoundManager.playEnemyDamage();
  4177.     } else {
  4178.       Yanfly.BEC.Game_Enemy_performDamage.call(this);
  4179.     }
  4180. };
  4181.  
  4182. Game_Enemy.prototype.attackAnimationId = function() {
  4183.     return this.enemy().attackAnimationId;
  4184. };
  4185.  
  4186. Game_Enemy.prototype.attackAnimationId1 = function() {
  4187.     return this.attackAnimationId();
  4188. };
  4189.  
  4190. Game_Enemy.prototype.attackAnimationId2 = function() {
  4191.     return this.attackAnimationId();
  4192. };
  4193.  
  4194. Game_Enemy.prototype.reflectAnimationId = function() {
  4195.     if (this.enemy().reflectAnimationId > 0) {
  4196.       return this.enemy().reflectAnimationId;
  4197.     }
  4198.     return Game_Battler.prototype.reflectAnimationId.call(this);
  4199. };
  4200.  
  4201. Game_Enemy.prototype.spriteCanMove = function() {
  4202.     if (this.enemy().spriteCannotMove) return false;
  4203.     return Game_Battler.prototype.spriteCanMove.call(this);
  4204. };
  4205.  
  4206. Game_Enemy.prototype.meetsTurnCondition = function(param1, param2) {
  4207.     var n = this.turnCount();
  4208.     if (param2 === 0) {
  4209.         return n === param1;
  4210.     } else {
  4211.         return n > 0 && n >= param1 && n % param2 === param1 % param2;
  4212.     }
  4213. };
  4214.  
  4215. //=============================================================================
  4216. // Game_Unit
  4217. //=============================================================================
  4218.  
  4219. Game_Unit.prototype.createActions = function() {
  4220.     var max = this.members().length;
  4221.     for (var i = 0; i < max; ++i) {
  4222.       var member = this.members()[i];
  4223.       if (member) member.createActions();
  4224.     }
  4225. };
  4226.  
  4227. Game_Unit.prototype.requestMotionRefresh = function() {
  4228.     var max = this.members().length;
  4229.     for (var i = 0; i < max; ++i) {
  4230.       var member = this.members()[i];
  4231.       if (member) member.requestMotionRefresh();
  4232.     }
  4233. };
  4234.  
  4235. Game_Unit.prototype.onTurnStart = function() {
  4236.     var max = this.members().length;
  4237.     for (var i = 0; i < max; ++i) {
  4238.       var member = this.members()[i];
  4239.       if (member) {
  4240.         member.onTurnStart();
  4241.         member.refresh();
  4242.       }
  4243.     }
  4244. };
  4245.  
  4246. Game_Unit.prototype.updateTick = function() {
  4247.     var max = this.members().length;
  4248.     for (var i = 0; i < max; ++i) {
  4249.       var member = this.members()[i];
  4250.       if (member) member.updateTick();
  4251.     }
  4252. };
  4253.  
  4254. Game_Unit.prototype.refreshMembers = function() {
  4255.     var group = this.allMembers();
  4256.     var length = group.length;
  4257.     for (var i = 0; i < length; ++i) {
  4258.       var member = group[i];
  4259.       if (member) member.refresh();
  4260.     }
  4261. };
  4262.  
  4263. //=============================================================================
  4264. // Game_Party
  4265. //=============================================================================
  4266.  
  4267. Game_Party.prototype.performEscapeSuccess = function() {
  4268.     for (var i = 0; i < this.members().length; ++i) {
  4269.       var member = this.members()[i];
  4270.       if (member) member.performEscapeSuccess();
  4271.     }
  4272. };
  4273.  
  4274. //=============================================================================
  4275. // Game_Troop
  4276. //=============================================================================
  4277.  
  4278. Game_Troop.prototype.allMembers = function() {
  4279.   return this.members();
  4280. };
  4281.  
  4282. //=============================================================================
  4283. // Scene_Battle
  4284. //=============================================================================
  4285.  
  4286. Yanfly.BEC.Scene_Battle_update = Scene_Battle.prototype.update;
  4287. Scene_Battle.prototype.update = function() {
  4288.     Yanfly.BEC.Scene_Battle_update.call(this);
  4289.     this.updateStatusWindowRequests();
  4290. };
  4291.  
  4292. Scene_Battle.prototype.updateStatusWindowRequests = function() {
  4293.     if (!this._statusWindow) return;
  4294.     if (this._statusWindow.isClosed()) return;
  4295.     this._statusWindow.updateStatusRequests();
  4296. };
  4297.  
  4298. Yanfly.BEC.Scene_Battle_createSkillWindow =
  4299.     Scene_Battle.prototype.createSkillWindow;
  4300. Scene_Battle.prototype.createSkillWindow = function() {
  4301.     Yanfly.BEC.Scene_Battle_createSkillWindow.call(this);
  4302.     if (Yanfly.Param.BECLowerWindows) {
  4303.       this.adjustLowerWindow(this._skillWindow);
  4304.     }
  4305. };
  4306.  
  4307. Yanfly.BEC.Scene_Battle_createItemWindow =
  4308.     Scene_Battle.prototype.createItemWindow;
  4309. Scene_Battle.prototype.createItemWindow = function() {
  4310.     Yanfly.BEC.Scene_Battle_createItemWindow.call(this);
  4311.     if (Yanfly.Param.BECLowerWindows) {
  4312.       this.adjustLowerWindow(this._itemWindow);
  4313.     }
  4314. };
  4315.  
  4316. Yanfly.BEC.Scene_Battle_createActorWindow =
  4317.     Scene_Battle.prototype.createActorWindow;
  4318. Scene_Battle.prototype.createActorWindow = function() {
  4319.     Yanfly.BEC.Scene_Battle_createActorWindow.call(this);
  4320.     this._actorWindow.x = Graphics.boxWidth - this._actorWindow.width;
  4321.     if (Yanfly.Param.BECSelectHelp) {
  4322.       this._actorWindow.setHelpWindow(this._helpWindow);
  4323.     }
  4324. };
  4325.  
  4326. Yanfly.BEC.Scene_Battle_createEnemyWindow =
  4327.     Scene_Battle.prototype.createEnemyWindow;
  4328. Scene_Battle.prototype.createEnemyWindow = function() {
  4329.     Yanfly.BEC.Scene_Battle_createEnemyWindow.call(this);
  4330.     if (Yanfly.Param.BECSelectHelp) {
  4331.       this._enemyWindow.setHelpWindow(this._helpWindow);
  4332.     }
  4333. };
  4334.  
  4335. Scene_Battle.prototype.adjustLowerWindow = function(win) {
  4336.     win.height = win.fittingHeight(Yanfly.Param.BECWindowRows);
  4337.     win.y = Graphics.boxHeight - win.height;
  4338. };
  4339.  
  4340. Yanfly.BEC.Scene_Battle_startPartyCommandSelection =
  4341.     Scene_Battle.prototype.startPartyCommandSelection;
  4342. Scene_Battle.prototype.startPartyCommandSelection = function() {
  4343.     if (this.isStartActorCommand()) {
  4344.       this.selectNextCommand();
  4345.     } else {
  4346.       Yanfly.BEC.Scene_Battle_startPartyCommandSelection.call(this);
  4347.     }
  4348. };
  4349.  
  4350. Scene_Battle.prototype.isStartActorCommand = function() {
  4351.     if (this._isStartActorCommand === undefined) {
  4352.       this._isStartActorCommand = Yanfly.Param.BECStartActCmd;
  4353.     }
  4354.     return this._isStartActorCommand;
  4355. };
  4356.  
  4357. Yanfly.BEC.Scene_Battle_selectPreviousCommand =
  4358.     Scene_Battle.prototype.selectPreviousCommand;
  4359. Scene_Battle.prototype.selectPreviousCommand = function() {
  4360.     if (this.isStartActorCommand()) {
  4361.       BattleManager.selectPreviousCommand();
  4362.       if (BattleManager.isInputting() && BattleManager.actor()) {
  4363.         this.startActorCommandSelection();
  4364.       } else {
  4365.         Yanfly.BEC.Scene_Battle_startPartyCommandSelection.call(this);
  4366.       }
  4367.     } else {
  4368.       Yanfly.BEC.Scene_Battle_selectPreviousCommand.call(this);
  4369.     }
  4370. };
  4371.  
  4372. Yanfly.BEC.Scene_Battle_selectNextCommand =
  4373.     Scene_Battle.prototype.selectNextCommand;
  4374. Scene_Battle.prototype.selectNextCommand = function() {
  4375.     Yanfly.BEC.Scene_Battle_selectNextCommand.call(this);
  4376.     this._helpWindow.clear();
  4377.     BattleManager.stopAllSelection();
  4378. };
  4379.  
  4380. Yanfly.BEC.Scene_Battle_commandSkill = Scene_Battle.prototype.commandSkill;
  4381. Scene_Battle.prototype.commandSkill = function() {
  4382.     this._helpWindow.clear();
  4383.     Yanfly.BEC.Scene_Battle_commandSkill.call(this);
  4384. };
  4385.  
  4386. Yanfly.BEC.Scene_Battle_commandItem = Scene_Battle.prototype.commandItem;
  4387. Scene_Battle.prototype.commandItem = function() {
  4388.     this._helpWindow.clear();
  4389.     Yanfly.BEC.Scene_Battle_commandItem.call(this);
  4390. };
  4391.  
  4392. Yanfly.BEC.Scene_Battle_startActorCommandSelection =
  4393.     Scene_Battle.prototype.startActorCommandSelection;
  4394. Scene_Battle.prototype.startActorCommandSelection = function() {
  4395.     BattleManager.createActions();
  4396.     Yanfly.BEC.Scene_Battle_startActorCommandSelection.call(this);
  4397.     this._statusWindow.refresh();
  4398. };
  4399.  
  4400. Yanfly.BEC.Scene_Battle_selectActorSelection =
  4401.     Scene_Battle.prototype.selectActorSelection;
  4402. Scene_Battle.prototype.selectActorSelection = function() {
  4403.     if (Yanfly.Param.BECSelectHelp) this._helpWindow.show();
  4404.     this._helpWindow.clear();
  4405.     Yanfly.BEC.Scene_Battle_selectActorSelection.call(this);
  4406.     this._actorWindow.autoSelect();
  4407. };
  4408.  
  4409. Yanfly.BEC.Scene_Battle_onActorCancel = Scene_Battle.prototype.onActorCancel;
  4410. Scene_Battle.prototype.onActorCancel = function() {
  4411.     if (Yanfly.Param.BECSelectHelp) this._helpWindow.hide();
  4412.     this._helpWindow.clear();
  4413.     Yanfly.BEC.Scene_Battle_onActorCancel.call(this);
  4414.     BattleManager.stopAllSelection();
  4415.     BattleManager.clearInputtingAction();
  4416. };
  4417.  
  4418. Yanfly.BEC.Scene_Battle_selectEnemySelection =
  4419.     Scene_Battle.prototype.selectEnemySelection;
  4420. Scene_Battle.prototype.selectEnemySelection = function() {
  4421.     if (Yanfly.Param.BECSelectHelp) this._helpWindow.show();
  4422.     this._helpWindow.clear();
  4423.     Yanfly.BEC.Scene_Battle_selectEnemySelection.call(this);
  4424.     this._enemyWindow.autoSelect();
  4425. };
  4426.  
  4427. Yanfly.BEC.Scene_Battle_onEnemyCancel = Scene_Battle.prototype.onEnemyCancel;
  4428. Scene_Battle.prototype.onEnemyCancel = function() {
  4429.     if (Yanfly.Param.BECSelectHelp) this._helpWindow.hide();
  4430.     this._helpWindow.clear();
  4431.     Yanfly.BEC.Scene_Battle_onEnemyCancel.call(this);
  4432.     BattleManager.stopAllSelection();
  4433.     BattleManager.clearInputtingAction();
  4434. };
  4435.  
  4436. Yanfly.BEC.Scene_Battle_onSelectAction = Scene_Battle.prototype.onSelectAction;
  4437. Scene_Battle.prototype.onSelectAction = function() {
  4438.     if (Yanfly.Param.BECSelectHelp) BattleManager.forceSelection();
  4439.     this._helpWindow.clear();
  4440.     Yanfly.BEC.Scene_Battle_onSelectAction.call(this);
  4441.     if (Yanfly.Param.BECSelectHelp) BattleManager.resetSelection();
  4442. };
  4443.  
  4444. Yanfly.BEC.Scene_Battle_onSkillOk =
  4445.     Scene_Battle.prototype.onSkillOk;
  4446. Scene_Battle.prototype.onSkillOk = function() {
  4447.     this._helpWindow.clear();
  4448.     Yanfly.BEC.Scene_Battle_onSkillOk.call(this);
  4449. };
  4450.  
  4451. Yanfly.BEC.Scene_Battle_onSkillCancel =
  4452.     Scene_Battle.prototype.onSkillCancel;
  4453. Scene_Battle.prototype.onSkillCancel = function() {
  4454.     this._helpWindow.clear();
  4455.     Yanfly.BEC.Scene_Battle_onSkillCancel.call(this);
  4456.     BattleManager.clearInputtingAction();
  4457. };
  4458.  
  4459. Yanfly.BEC.Scene_Battle_onItemOk =
  4460.     Scene_Battle.prototype.onItemOk;
  4461. Scene_Battle.prototype.onItemOk = function() {
  4462.     this._helpWindow.clear();
  4463.     Yanfly.BEC.Scene_Battle_onItemOk.call(this);
  4464. };
  4465.  
  4466. Yanfly.BEC.Scene_Battle_onItemCancel =
  4467.     Scene_Battle.prototype.onItemCancel;
  4468. Scene_Battle.prototype.onItemCancel = function() {
  4469.     this._helpWindow.clear();
  4470.     Yanfly.BEC.Scene_Battle_onItemCancel.call(this);
  4471.     BattleManager.clearInputtingAction();
  4472. };
  4473.  
  4474. //=============================================================================
  4475. // Window_Selectable
  4476. //=============================================================================
  4477.  
  4478. Yanfly.BEC.Window_Selectable_isCursorMovable =
  4479.     Window_Selectable.prototype.isCursorMovable;
  4480. Window_Selectable.prototype.isCursorMovable = function() {
  4481.     if (this._inputLock) return false;
  4482.     return Yanfly.BEC.Window_Selectable_isCursorMovable.call(this);
  4483. };
  4484.  
  4485. //=============================================================================
  4486. // Window_Help
  4487. //=============================================================================
  4488.  
  4489. Yanfly.BEC.Window_Help_clear = Window_Help.prototype.clear;
  4490. Window_Help.prototype.clear = function() {
  4491.     Yanfly.BEC.Window_Help_clear.call(this);
  4492.     this.contents.clear();
  4493. };
  4494.  
  4495. Window_Help.prototype.setBattler = function(battler) {
  4496.     this.contents.clear();
  4497.     this.clear();
  4498.     this.resetFontSettings();
  4499.     if (!$gameParty.inBattle()) return;
  4500.     if (!battler) return;
  4501.     var action = BattleManager.inputtingAction();
  4502.     if (this.specialSelectionText(action)) {
  4503.       this.drawSpecialSelectionText(action);
  4504.     } else {
  4505.       this.drawBattler(battler);
  4506.     }
  4507. };
  4508.  
  4509. Window_Help.prototype.specialSelectionText = function(action) {
  4510.     BattleManager.resetSelection();
  4511.     if (!action) return false;
  4512.     return !action.needsSelection();
  4513. };
  4514.  
  4515. Window_Help.prototype.drawBattler = function(battler) {
  4516.     var text = battler.name();
  4517.     var wx = 0;
  4518.     var wy = (this.contents.height - this.lineHeight()) / 2;
  4519.     this.drawText(text, wx, wy, this.contents.width, 'center');
  4520. };
  4521.  
  4522. Window_Help.prototype.drawSpecialSelectionText = function(action) {
  4523.     var wx = 0;
  4524.     var wy = (this.contents.height - this.lineHeight()) / 2;
  4525.     var text = '';
  4526.     if (action.isForUser()) {
  4527.       text = Yanfly.Param.BECHelpUserTx;
  4528.     } else if (action.isForRandom()) {
  4529.       BattleManager.startAllSelection();
  4530.       var fmt = Yanfly.Param.BECHelpRandTx;
  4531.       if (action.isForOpponent() && action.numTargets() !== 1) {
  4532.         var target = Yanfly.Param.BECHelpEnemiesTx;
  4533.       } else if (action.isForOpponent() && action.numTargets() === 1) {
  4534.         var target = Yanfly.Param.BECHelpEnemyTx;
  4535.       } else if (action.isForFriend() && action.numTargets() !== 1) {
  4536.         var target = Yanfly.Param.BECHelpAlliesTx;
  4537.       } else {
  4538.         var target = Yanfly.Param.BECHelpAllyTx;
  4539.       }
  4540.       text = fmt.format(target, Yanfly.Util.toGroup(action.numTargets()));
  4541.     } else if (action.isForAll()) {
  4542.       BattleManager.startAllSelection();
  4543.       var fmt = Yanfly.Param.BECHelpAllTx;
  4544.       if (action.isForOpponent()) {
  4545.         var target = Yanfly.Param.BECHelpEnemiesTx;
  4546.       } else {
  4547.         var target = Yanfly.Param.BECHelpAlliesTx;
  4548.       }
  4549.       text = fmt.format(target);
  4550.     }
  4551.     this.drawText(text, wx, wy, this.contents.width, 'center');
  4552. };
  4553.  
  4554. //=============================================================================
  4555. // Window_BattleActor
  4556. //=============================================================================
  4557.  
  4558. Window_BattleActor.prototype.autoSelect = function() {
  4559.     var action = BattleManager.inputtingAction();
  4560.     if (!action) return;
  4561.     this._inputLock = false;
  4562.     this._selectDead = false;
  4563.     if (action.isForUser()) {
  4564.       this.select(BattleManager.actor().index());
  4565.       this._inputLock = true;
  4566.     } else if (action.isForDeadFriend()) {
  4567.       this._selectDead = true;
  4568.       this.autoSelectFirstDeadActor();
  4569.       if (action.isForAll()) this._inputLock = true;
  4570.     }
  4571. };
  4572.  
  4573. Window_BattleActor.prototype.autoSelectFirstDeadActor = function() {
  4574.     var length = $gameParty.members().length;
  4575.     for (var i = 0; i < length; ++i) {
  4576.       var member = $gameParty.members()[i];
  4577.       if (member && member.isDead()) return this.select(i);
  4578.     }
  4579. };
  4580.  
  4581. Window_BattleActor.prototype.isOkEnabled = function() {
  4582.     if (this._selectDead) return this.actor().isDead();
  4583.     return Window_Selectable.prototype.isOkEnabled.call(this);
  4584. };
  4585.  
  4586. Window_BattleActor.prototype.updateHelp = function() {
  4587.     if (!this._helpWindow) return;
  4588.     this._helpWindow.setBattler(this.actor());
  4589. };
  4590.  
  4591. Yanfly.BEC.Window_BattleActor_processTouch =
  4592.     Window_BattleActor.prototype.processTouch;
  4593. Window_BattleActor.prototype.processTouch = function() {
  4594.     if (Yanfly.Param.BECActorSelect && this.isOpenAndActive()) {
  4595.       if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
  4596.         if (this.getClickedActor() >= 0) {
  4597.           var index = this.getClickedActor();
  4598.           if (this.index() === index) {
  4599.             return this.processOk();
  4600.           } else {
  4601.             SoundManager.playCursor();
  4602.             return this.select(index);
  4603.           }
  4604.         }
  4605.       }
  4606.       if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
  4607.         if (this.getClickedActor() >= 0) {
  4608.           var index = this.getClickedActor();
  4609.           if (this.index() !== index) {
  4610.             SoundManager.playCursor();
  4611.             return this.select(index);
  4612.           }
  4613.         }
  4614.       }
  4615.       if (Yanfly.Param.BECSelectMouseOver) {
  4616.         var index = this.getMouseOverActor();
  4617.         if (index >= 0 && this.index() !== index) {
  4618.           SoundManager.playCursor();
  4619.           return this.select(index);
  4620.         }
  4621.       }
  4622.     }
  4623.     Yanfly.BEC.Window_BattleActor_processTouch.call(this);
  4624. };
  4625.  
  4626. Window_BattleActor.prototype.getClickedActor = function() {
  4627.     for (var i = 0; i < $gameParty.battleMembers().length; ++i) {
  4628.       var actor = $gameParty.battleMembers().reverse()[i];
  4629.       if (!actor) continue;
  4630.       if (this.isClickedActor(actor)) {
  4631.         if (this._selectDead && !actor.isDead()) continue;
  4632.         if (this._inputLock && actor.index() !== this.index()) continue;
  4633.         return actor.index();
  4634.       }
  4635.     }
  4636.     return -1;
  4637. };
  4638.  
  4639. Window_BattleActor.prototype.isClickedActor = function(actor) {
  4640.     if (!actor) return false;
  4641.     if (!actor.isSpriteVisible()) return false;
  4642.     if (!actor.isAppeared()) return false;
  4643.     if ($gameTemp._disableMouseOverSelect) return false;
  4644.     var x = TouchInput.x;
  4645.     var y = TouchInput.y;
  4646.     var rect = new Rectangle();
  4647.     rect.width = actor.spriteWidth();
  4648.     rect.height = actor.spriteHeight();
  4649.     rect.x = actor.spritePosX() - rect.width / 2;
  4650.     rect.y = actor.spritePosY() - rect.height;
  4651.     return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  4652.       y < rect.y + rect.height);
  4653. };
  4654.  
  4655. Window_BattleActor.prototype.getMouseOverActor = function() {
  4656.     for (var i = 0; i < $gameParty.battleMembers().length; ++i) {
  4657.       var actor = $gameParty.battleMembers().reverse()[i];
  4658.       if (!actor) continue;
  4659.       if (this.isMouseOverActor(actor)) {
  4660.         if (this._selectDead && !actor.isDead()) continue;
  4661.         if (this._inputLock && actor.index() !== this.index()) continue;
  4662.         return actor.index();
  4663.       }
  4664.     }
  4665.     return -1;
  4666. };
  4667.  
  4668. Window_BattleActor.prototype.isMouseOverActor = function(actor) {
  4669.     if (!actor) return false;
  4670.     if (!actor.isSpriteVisible()) return false;
  4671.     if (!actor.isAppeared()) return false;
  4672.     if ($gameTemp._disableMouseOverSelect) return false;
  4673.     var x = TouchInput._mouseOverX;
  4674.     var y = TouchInput._mouseOverY;
  4675.     var rect = new Rectangle();
  4676.     rect.width = actor.spriteWidth();
  4677.     rect.height = actor.spriteHeight();
  4678.     rect.x = actor.spritePosX() - rect.width / 2;
  4679.     rect.y = actor.spritePosY() - rect.height;
  4680.     return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  4681.       y < rect.y + rect.height);
  4682. };
  4683.  
  4684. //=============================================================================
  4685. // Window_BattleEnemy
  4686. //=============================================================================
  4687.  
  4688. Yanfly.DisableWebGLMask = false;
  4689.  
  4690. Yanfly.BEC.Window_BattleEnemy_initialize =
  4691.     Window_BattleEnemy.prototype.initialize;
  4692. Window_BattleEnemy.prototype.initialize = function(x, y) {
  4693.     if (Yanfly.Param.BECEnemySelect) {
  4694.       x -= Graphics.boxWidth * 200;
  4695.       y -= Graphics.boxHeight * 200;
  4696.     };
  4697.     Yanfly.BEC.Window_BattleEnemy_initialize.call(this, x, y);
  4698. };
  4699.  
  4700. Yanfly.BEC.WindowLayer_webglMaskWindow =
  4701.     WindowLayer.prototype._webglMaskWindow;
  4702. WindowLayer.prototype._webglMaskWindow = function(renderSession, win) {
  4703.     if (win._ignoreMask) return;
  4704.     Yanfly.BEC.WindowLayer_webglMaskWindow.call(this, renderSession, win);
  4705. };
  4706.  
  4707. Yanfly.BEC.Window_BattleEnemy_maxCols =
  4708.     Window_BattleEnemy.prototype.maxCols;
  4709. Window_BattleEnemy.prototype.maxCols = function() {
  4710.     if (Yanfly.Param.BECEnemySelect) return this._enemies.length;
  4711.     return Yanfly.BEC.Window_BattleEnemy_maxCols.call(this);
  4712. };
  4713.  
  4714. Window_BattleEnemy.prototype.allowedTargets = function() {
  4715.     var targets = [];
  4716.     targets = targets.concat($gameTroop.aliveMembers());
  4717.     return targets;
  4718. };
  4719.  
  4720. Window_BattleEnemy.prototype.refresh = function() {
  4721.     this._enemies = this.allowedTargets();
  4722.     this.sortTargets();
  4723.     Window_Selectable.prototype.refresh.call(this);
  4724. };
  4725.  
  4726. Window_BattleEnemy.prototype.sortTargets = function() {
  4727.     this._enemies.sort(function(a, b) {
  4728.         if (a.spritePosX() == b.spritePosX()) {
  4729.           return a.spritePosY() - b.spritePosY();
  4730.         }
  4731.         return a.spritePosX() - b.spritePosX();
  4732.     });
  4733. };
  4734.  
  4735. Window_BattleEnemy.prototype.autoSelect = function() {
  4736.     var selectIndex = eval(Yanfly.Param.BECEnemyAutoSel);
  4737.     this.select(selectIndex);
  4738. };
  4739.  
  4740. Window_BattleEnemy.prototype.furthestRight = function() {
  4741.     return this.maxItems() - 1;
  4742. };
  4743.  
  4744. Window_BattleEnemy.prototype.updateHelp = function() {
  4745.     if (!this._helpWindow) return;
  4746.     this._helpWindow.setBattler(this.enemy());
  4747. };
  4748.  
  4749. Yanfly.BEC.Window_BattleEnemy_processTouch =
  4750.     Window_BattleEnemy.prototype.processTouch;
  4751. Window_BattleEnemy.prototype.processTouch = function() {
  4752.     if (Yanfly.Param.BECEnemySelect && this.isOpenAndActive()) {
  4753.       if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
  4754.         if (this.getClickedEnemy() >= 0) {
  4755.           var index = this.getClickedEnemy();
  4756.           if (this.index() === index) {
  4757.             return this.processOk();
  4758.           } else {
  4759.             SoundManager.playCursor();
  4760.             return this.select(index);
  4761.           }
  4762.         }
  4763.       }
  4764.       if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
  4765.         if (this.getClickedEnemy() >= 0) {
  4766.           var index = this.getClickedEnemy();
  4767.           if (this.index() !== index) {
  4768.             SoundManager.playCursor();
  4769.             return this.select(index);
  4770.           }
  4771.         }
  4772.       }
  4773.       if (Yanfly.Param.BECSelectMouseOver) {
  4774.         var index = this.getMouseOverEnemy();
  4775.         if (index >= 0 && this.index() !== index) {
  4776.           SoundManager.playCursor();
  4777.           return this.select(index);
  4778.         }
  4779.       }
  4780.     };
  4781.     Yanfly.BEC.Window_BattleEnemy_processTouch.call(this);
  4782. };
  4783.  
  4784. Window_BattleEnemy.prototype.getClickedEnemy = function() {
  4785.     for (var i = 0; i < this._enemies.length; ++i) {
  4786.       var enemy = this._enemies[i];
  4787.       if (!enemy) continue;
  4788.       if (this.isClickedEnemy(enemy)) {
  4789.         if (this._selectDead && !enemy.isDead()) continue;
  4790.         var index = this._enemies.indexOf(enemy)
  4791.         if (this._inputLock && index !== this.index()) continue;
  4792.         return index;
  4793.       }
  4794.     }
  4795.     return -1;
  4796. };
  4797.  
  4798. Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
  4799.     if (!enemy) return false;
  4800.     if (!enemy.isSpriteVisible()) return false;
  4801.     if ($gameTemp._disableMouseOverSelect) return false;
  4802.     var x = TouchInput.x;
  4803.     var y = TouchInput.y;
  4804.     var rect = new Rectangle();
  4805.     rect.width = enemy.spriteWidth();
  4806.     rect.height = enemy.spriteHeight();
  4807.     rect.x = enemy.spritePosX() - rect.width / 2;
  4808.     rect.y = enemy.spritePosY() - rect.height;
  4809.     return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  4810.       y < rect.y + rect.height);
  4811. };
  4812.  
  4813. Window_BattleEnemy.prototype.getMouseOverEnemy = function() {
  4814.     for (var i = 0; i < this._enemies.length; ++i) {
  4815.       var enemy = this._enemies[i];
  4816.       if (!enemy) continue;
  4817.       if (this.isMouseOverEnemy(enemy)) {
  4818.         if (this._selectDead && !enemy.isDead()) continue;
  4819.         var index = this._enemies.indexOf(enemy)
  4820.         if (this._inputLock && index !== this.index()) continue;
  4821.         return index;
  4822.       }
  4823.     }
  4824.     return -1;
  4825. };
  4826.  
  4827. Window_BattleEnemy.prototype.isMouseOverEnemy = function(enemy) {
  4828.     if (!enemy) return false;
  4829.     if (!enemy.isSpriteVisible()) return false;
  4830.     if ($gameTemp._disableMouseOverSelect) return false;
  4831.     var x = TouchInput._mouseOverX;
  4832.     var y = TouchInput._mouseOverY;
  4833.     var rect = new Rectangle();
  4834.     rect.width = enemy.spriteWidth();
  4835.     rect.height = enemy.spriteHeight();
  4836.     rect.x = enemy.spritePosX() - rect.width / 2;
  4837.     rect.y = enemy.spritePosY() - rect.height;
  4838.     return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  4839.       y < rect.y + rect.height);
  4840. };
  4841.  
  4842. //=============================================================================
  4843. // Window_EnemyVisualSelect
  4844. //=============================================================================
  4845.  
  4846. function Window_EnemyVisualSelect() {
  4847.     this.initialize.apply(this, arguments);
  4848. }
  4849.  
  4850. Window_EnemyVisualSelect.prototype = Object.create(Window_Base.prototype);
  4851. Window_EnemyVisualSelect.prototype.constructor = Window_EnemyVisualSelect;
  4852.  
  4853. Window_EnemyVisualSelect.prototype.initialize = function() {
  4854.     Window_Base.prototype.initialize.call(this, 0, 0, 1, 1);
  4855.     this._battler = null;
  4856.     this._battlerName = '';
  4857.     this._requestRefresh = false;
  4858.     this._showSelectCursor = Yanfly.Param.BECShowSelectBox;
  4859.     this._showEnemyName = Yanfly.Param.BECShowEnemyName;
  4860.     this.contentsOpacity = 0;
  4861.     this.opacity = 0;
  4862. };
  4863.  
  4864. Window_EnemyVisualSelect.prototype.setBattler = function(battler) {
  4865.     if (this._battler === battler) return;
  4866.     this._battler = battler;
  4867.     this._battlerName = battler.name();
  4868. };
  4869.  
  4870. Window_EnemyVisualSelect.prototype.update = function() {
  4871.     Window_Base.prototype.update.call(this);
  4872.     if (!this._battler) return;
  4873.     this.updateWindowAspects();
  4874. };
  4875.  
  4876. Window_EnemyVisualSelect.prototype.updateWindowAspects = function() {
  4877.     this.updateBattlerName();
  4878.     this.updateWindowSize();
  4879.     this.updateWindowPosition();
  4880.     this.updateOpacity();
  4881.     this.updateRefresh();
  4882.     this.updateCursor();
  4883. };
  4884.  
  4885. Window_EnemyVisualSelect.prototype.updateBattlerName = function() {
  4886.     if (this._battlerName !== this._battler.name())
  4887.     this._battlerName = this._battler.name();
  4888.     this._requestRefresh = true;
  4889.     this._nameTextWidth = undefined;
  4890. };
  4891.  
  4892. Window_EnemyVisualSelect.prototype.updateWindowSize = function() {
  4893.     var spriteWidth = this._battler.spriteWidth();
  4894.     this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
  4895.     if (this._nameTextWidth === undefined) {
  4896.       this._nameTextWidth = this.textWidth(this._battler.name());
  4897.     }
  4898.     var textWidth = this._nameTextWidth;
  4899.     textWidth += this.textPadding() * 2;
  4900.     var width = Math.max(spriteWidth, textWidth) + this.standardPadding() * 2;
  4901.     width = Math.ceil(width);
  4902.     var height = this._battler.spriteHeight() + this.standardPadding() * 2;
  4903.     height = Math.ceil(height);
  4904.     height = Math.max(height, this.lineHeight() + this.standardPadding() * 2);
  4905.     if (width === this.width && height === this.height) return;
  4906.     this.width = width;
  4907.     this.height = height;
  4908.     this.createContents();
  4909.     this._requestRefresh = true;
  4910.     this.makeWindowBoundaries();
  4911. };
  4912.  
  4913. Window_EnemyVisualSelect.prototype.makeWindowBoundaries = function() {
  4914.     if (!this._requestRefresh) return;
  4915.     this._minX = -1 * this.standardPadding();
  4916.     this._maxX = Graphics.boxWidth - this.width + this.standardPadding();
  4917.     this._minY = -1 * this.standardPadding();
  4918.     this._maxY = Graphics.boxHeight - this.height + this.standardPadding();
  4919.     this._maxY -= SceneManager._scene._statusWindow.height;
  4920. };
  4921.  
  4922. Window_EnemyVisualSelect.prototype.updateWindowPosition = function() {
  4923.     if (!this._battler) return;
  4924.     this.x = -1 * this.width / 2;
  4925.     this.y = -1 * this.height + this.standardPadding();
  4926.     this.x += this._battler.spritePosX();
  4927.     this.y += this._battler.spritePosY();
  4928.     this.x = this.x.clamp(this._minX, this._maxX);
  4929.     this.y = this.y.clamp(this._minY, this._maxY);
  4930. };
  4931.  
  4932. Window_EnemyVisualSelect.prototype.updateOpacity = function() {
  4933.     if (this.isShowWindow()) {
  4934.       this.contentsOpacity += 32;
  4935.     } else {
  4936.       this.contentsOpacity -= 32;
  4937.     }
  4938. };
  4939.  
  4940. Window_EnemyVisualSelect.prototype.isShowWindow = function() {
  4941.     var scene = SceneManager._scene;
  4942.     if (!scene._enemyWindow) return false;
  4943.     var enemyWindow = scene._enemyWindow;
  4944.     if (!enemyWindow.active) return false;
  4945.     if (!this._battler.isAppeared()) return false;
  4946.     if (this._battler.isDead()) {
  4947.       return enemyWindow._selectDead;
  4948.     }
  4949.     return enemyWindow._enemies.contains(this._battler);
  4950. };
  4951.  
  4952. Window_EnemyVisualSelect.prototype.updateCursor = function() {
  4953.     if (this.isShowCursor()) {
  4954.       var wy = this.contents.height - this.lineHeight();
  4955.       this.setCursorRect(0, wy, this.contents.width, this.lineHeight());
  4956.     } else {
  4957.       this.setCursorRect(0, 0, 0, 0);
  4958.     }
  4959. };
  4960.  
  4961. Window_EnemyVisualSelect.prototype.isShowCursor = function() {
  4962.     if (!this._showSelectCursor) return false;
  4963.     var scene = SceneManager._scene;
  4964.     if (!scene._enemyWindow) return false;
  4965.     var enemyWindow = scene._enemyWindow;
  4966.     if (!enemyWindow.active) return false;
  4967.     if (!this._battler.isAppeared()) return false;
  4968.     return this._battler.isSelected();
  4969. };
  4970.  
  4971. Window_EnemyVisualSelect.prototype.updateRefresh = function() {
  4972.     if (this._requestRefresh) this.refresh();
  4973. };
  4974.  
  4975. Window_EnemyVisualSelect.prototype.refresh = function() {
  4976.     this.contents.clear();
  4977.     if (!this._battler) return;
  4978.     if (!this._showEnemyName) return;
  4979.     if (this._battler.isHidden()) return;
  4980.     this._requestRefresh = false;
  4981.     this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
  4982.     var text = this._battler.name();
  4983.     var wy = this.contents.height - this.lineHeight();
  4984.     this.drawText(text, 0, wy, this.contents.width, 'center');
  4985. };
  4986.  
  4987. //=============================================================================
  4988. // Window_PartyCommand
  4989. //=============================================================================
  4990.  
  4991. Window_PartyCommand.prototype.itemTextAlign = function() {
  4992.     return Yanfly.Param.BECCommandAlign;
  4993. };
  4994.  
  4995. Window_PartyCommand.prototype.numVisibleRows = function() {
  4996.     return Yanfly.Param.BECCommandRows;
  4997. };
  4998.  
  4999. //=============================================================================
  5000. // Window_ActorCommand
  5001. //=============================================================================
  5002.  
  5003. Window_ActorCommand.prototype.itemTextAlign = function() {
  5004.     return Yanfly.Param.BECCommandAlign;
  5005. };
  5006.  
  5007. Window_ActorCommand.prototype.numVisibleRows = function() {
  5008.     return Yanfly.Param.BECCommandRows;
  5009. };
  5010.  
  5011. //=============================================================================
  5012. // Window_BattleStatus
  5013. //=============================================================================
  5014.  
  5015. Window_BattleStatus.prototype.numVisibleRows = function() {
  5016.     return Yanfly.Param.BECCommandRows;
  5017. };
  5018.  
  5019. Window_BattleStatus.prototype.updateStatusRequests = function() {
  5020.     if (BattleManager._victoryPhase) return;
  5021.     for (var i = 0; i < $gameParty.battleMembers().length; ++i) {
  5022.       var actor = $gameParty.battleMembers()[i];
  5023.       if (!actor) continue;
  5024.       if (actor.isStatusRefreshRequested()) this.processStatusRefresh(i);
  5025.     }
  5026. };
  5027.  
  5028. Window_BattleStatus.prototype.processStatusRefresh = function(index) {
  5029.     var actor = $gameParty.battleMembers()[index];
  5030.     if (!actor) return;
  5031.     var rect = this.itemRect(index);
  5032.     this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);
  5033.     this.drawItem(index);
  5034.     actor.completetStatusRefreshRequest();
  5035. };
  5036.  
  5037. Window_BattleStatus.prototype.update = function() {
  5038.     Window_Selectable.prototype.update.call(this);
  5039. };
  5040.  
  5041. if (!Yanfly.Param.BECCurMax) {
  5042.  
  5043. Window_BattleStatus.prototype.drawCurrentAndMax = function(current, max, x, y,
  5044.                                                    width, color1, color2) {
  5045.     var labelWidth = this.textWidth('HP');
  5046.     var valueWidth = this.textWidth(Yanfly.Util.toGroup(max));
  5047.     var slashWidth = this.textWidth('/');
  5048.     var x1 = x + width - valueWidth;
  5049.     this.changeTextColor(color1);
  5050.     this.drawText(Yanfly.Util.toGroup(current), x1, y, valueWidth, 'right');
  5051. };
  5052.  
  5053. }; // Yanfly.Param.BECCurMax
  5054.  
  5055. //=============================================================================
  5056. // Window_BattleLog
  5057. //=============================================================================
  5058.  
  5059. Yanfly.BEC.Window_BattleLog_isFastForward =
  5060.     Window_BattleLog.prototype.isFastForward;
  5061. Window_BattleLog.prototype.isFastForward = function() {
  5062.     if (Yanfly.Param.BECOptSpeed) return true;
  5063.     return Yanfly.BEC.Window_BattleLog_isFastForward.call(this);
  5064. };
  5065.  
  5066. Window_BattleLog.prototype.updateWaitCount = function() {
  5067.     if (this._waitCount > 0) {
  5068.         this._waitCount -= 1;
  5069.         if (this._waitCount < 0) {
  5070.             this._waitCount = 0;
  5071.         }
  5072.         return true;
  5073.     }
  5074.     return false;
  5075. };
  5076.  
  5077. Window_BattleLog.prototype.animationBaseDelay = function() {
  5078.     return Yanfly.Param.BECAniBaseDel;
  5079. };
  5080.  
  5081. Window_BattleLog.prototype.animationNextDelay = function() {
  5082.     return Yanfly.Param.BECAniNextDel;
  5083. };
  5084.  
  5085. Window_BattleLog.prototype.updateWaitMode = function() {
  5086.     var waiting = false;
  5087.     switch (this._waitMode) {
  5088.     case 'effect':
  5089.         waiting = this._spriteset.isEffecting();
  5090.         break;
  5091.     case 'movement':
  5092.         waiting = this._spriteset.isAnyoneMoving();
  5093.         break;
  5094.     case 'animation':
  5095.         waiting = this._spriteset.isAnimationPlaying();
  5096.         break;
  5097.     case 'popups':
  5098.         waiting = this._spriteset.isPopupPlaying();
  5099.         break;
  5100.     }
  5101.     if (!waiting) {
  5102.         this._waitMode = '';
  5103.     }
  5104.     return waiting;
  5105. };
  5106.  
  5107. Window_BattleLog.prototype.startAction = function(subject, action, targets) {
  5108. };
  5109.  
  5110. Window_BattleLog.prototype.endAction = function(subject) {
  5111. };
  5112.  
  5113. Window_BattleLog.prototype.waitForAnimation = function() {
  5114.     this.setWaitMode('animation');
  5115. };
  5116.  
  5117. Window_BattleLog.prototype.waitForEffect = function() {
  5118.     this.setWaitMode('effect');
  5119. };
  5120.  
  5121. Window_BattleLog.prototype.waitForPopups = function() {
  5122.     this.setWaitMode('popups');
  5123. };
  5124.  
  5125. Yanfly.BEC.Window_BattleLog_displayAction =
  5126.     Window_BattleLog.prototype.displayAction;
  5127. Window_BattleLog.prototype.displayAction = function(subject, item) {
  5128.     if (Yanfly.Param.BECFullActText) {
  5129.       Yanfly.BEC.Window_BattleLog_displayAction.call(this, subject, item);
  5130.     } else {
  5131.       this._actionIcon = this.displayIcon(item);
  5132.       var text = this.displayText(item);
  5133.       this.push('addText', '<SIMPLE>' + text);
  5134.       if (item.message2) {
  5135.         this.push('addText', '<CENTER>' + item.message2.format(text));
  5136.       }
  5137.     }
  5138. };
  5139.  
  5140. Window_BattleLog.prototype.displayIcon = function(item) {
  5141.     if (!item) return 0;
  5142.     return item.battleDisplayIcon;
  5143. };
  5144.  
  5145. Window_BattleLog.prototype.displayText = function(item) {
  5146.     if (!item) return '';
  5147.     return item.battleDisplayText;
  5148. };
  5149.  
  5150. Yanfly.BEC.Window_BattleLog_displayActionResults =
  5151.     Window_BattleLog.prototype.displayActionResults;
  5152. Window_BattleLog.prototype.displayActionResults = function(subject, target) {
  5153.     if (Yanfly.Param.BECOptSpeed) {
  5154.       if (target.result().used) {
  5155.           this.displayCritical(target);
  5156.           this.displayDamage(target);
  5157.           this.displayAffectedStatus(target);
  5158.           this.displayFailure(target);
  5159.       }
  5160.     } else {
  5161.       Yanfly.BEC.Window_BattleLog_displayActionResults.call(this, subject,
  5162.           target);
  5163.     }
  5164.     if (target.isDead()) target.performCollapse();
  5165. };
  5166.  
  5167. Yanfly.BEC.Window_BattleLog_drawLineText =
  5168.     Window_BattleLog.prototype.drawLineText;
  5169. Window_BattleLog.prototype.drawLineText = function(index) {
  5170.     if (this._lines[index].match('<CENTER>')) {
  5171.       this.drawCenterLine(index);
  5172.     } else if (this._lines[index].match('<SIMPLE>')) {
  5173.       this.drawSimpleActionLine(index);
  5174.     } else {
  5175.       Yanfly.BEC.Window_BattleLog_drawLineText.call(this, index);
  5176.     }
  5177. };
  5178.  
  5179. Window_BattleLog.prototype.textWidthEx = function(text) {
  5180.     return this.drawTextEx(text, 0, this.contents.height + this.lineHeight());
  5181. };
  5182.  
  5183. Window_BattleLog.prototype.drawCenterLine = function(index) {
  5184.     var text = this._lines[index].replace('<CENTER>', '');
  5185.     var rect = this.itemRectForText(index);
  5186.     this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);
  5187.     var tw = this.textWidthEx(text);
  5188.     var wx = rect.x + (rect.width - tw) / 2;
  5189.     this.resetFontSettings();
  5190.     this.drawTextEx(text, wx, rect.y);
  5191. };
  5192.  
  5193. Window_BattleLog.prototype.drawSimpleActionLine = function(index) {
  5194.     var text = this._lines[index].replace('<SIMPLE>', '');
  5195.     var rect = this.itemRectForText(index);
  5196.     this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);
  5197.     if (this._actionIcon) {
  5198.       var tw = this.textWidth(text);
  5199.       var ix = (rect.width - tw) / 2 - 4;
  5200.       this.drawIcon(this._actionIcon, ix, rect.y + 2);
  5201.     }
  5202.     this.drawText(text, rect.x, rect.y, Graphics.boxWidth, 'center');
  5203. };
  5204.  
  5205. Window_BattleLog.prototype.displayCounter = function(target) {
  5206.     if (Yanfly.Param.BECShowCntText) {
  5207.       this.addText(TextManager.counterAttack.format(target.name()));
  5208.     }
  5209.     target.performCounter();
  5210.     this.showAttackAnimation(target, [BattleManager._subject]);
  5211.     this.waitForAnimation();
  5212. };
  5213.  
  5214. Window_BattleLog.prototype.displayReflection = function(target) {
  5215.     if (Yanfly.Param.BECShowRflText) {
  5216.       this.addText(TextManager.magicReflection.format(target.name()));
  5217.     }
  5218.     target.performReflection();
  5219.     var animationId = BattleManager._action.item().animationId;
  5220.     this.showNormalAnimation([BattleManager._subject], animationId);
  5221.     this.waitForAnimation();
  5222. };
  5223.  
  5224. Window_BattleLog.prototype.displaySubstitute = function(substitute, target) {
  5225.     if (Yanfly.Param.BECShowSubText) {
  5226.       var substName = substitute.name();
  5227.       this.addText(TextManager.substitute.format(substName, target.name()));
  5228.     }
  5229.     substitute.performSubstitute(target);
  5230. };
  5231.  
  5232. Yanfly.BEC.Window_BattleLog_displayFailure =
  5233.     Window_BattleLog.prototype.displayFailure;
  5234. Window_BattleLog.prototype.displayFailure = function(target) {
  5235.     if (!Yanfly.Param.BECShowFailText) return;
  5236.     Yanfly.BEC.Window_BattleLog_displayFailure.call(this, target);
  5237. };
  5238.  
  5239. Yanfly.BEC.Window_BattleLog_displayCritical =
  5240.     Window_BattleLog.prototype.displayCritical;
  5241. Window_BattleLog.prototype.displayCritical = function(target) {
  5242.     if (!Yanfly.Param.BECShowCritText) return;
  5243.     Yanfly.BEC.Window_BattleLog_displayCritical.call(this, target);
  5244. };
  5245.  
  5246. Yanfly.BEC.Window_BattleLog_displayMiss =
  5247.     Window_BattleLog.prototype.displayMiss;
  5248. Window_BattleLog.prototype.displayMiss = function(target) {
  5249.     if (!Yanfly.Param.BECShowMissText) return;
  5250.     Yanfly.BEC.Window_BattleLog_displayMiss.call(this, target);
  5251. };
  5252.  
  5253. Yanfly.BEC.Window_BattleLog_displayEvasion =
  5254.     Window_BattleLog.prototype.displayEvasion;
  5255. Window_BattleLog.prototype.displayEvasion = function(target) {
  5256.     if (!Yanfly.Param.BECShowEvaText) return;
  5257.     Yanfly.BEC.Window_BattleLog_displayEvasion.call(this, target);
  5258. };
  5259.  
  5260. Yanfly.BEC.Window_BattleLog_displayHpDamage =
  5261.     Window_BattleLog.prototype.displayHpDamage;
  5262. Window_BattleLog.prototype.displayHpDamage = function(target) {
  5263.     if (!Yanfly.Param.BECShowHpText) return;
  5264.     Yanfly.BEC.Window_BattleLog_displayHpDamage.call(this, target);
  5265. };
  5266.  
  5267. Yanfly.BEC.Window_BattleLog_displayMpDamage =
  5268.     Window_BattleLog.prototype.displayMpDamage;
  5269. Window_BattleLog.prototype.displayMpDamage = function(target) {
  5270.     if (!Yanfly.Param.BECShowMpText) return;
  5271.     Yanfly.BEC.Window_BattleLog_displayMpDamage.call(this, target);
  5272. };
  5273.  
  5274. Yanfly.BEC.Window_BattleLog_displayTpDamage =
  5275.     Window_BattleLog.prototype.displayTpDamage;
  5276. Window_BattleLog.prototype.displayTpDamage = function(target) {
  5277.     if (!Yanfly.Param.BECShowTpText) return;
  5278.     Yanfly.BEC.Window_BattleLog_displayTpDamage.call(this, target);
  5279. };
  5280.  
  5281. Yanfly.BEC.Window_BattleLog_displayCurrentState =
  5282.     Window_BattleLog.prototype.displayCurrentState;
  5283. Window_BattleLog.prototype.displayCurrentState = function(subject) {
  5284.     if (!Yanfly.Param.BECShowStateText) return;
  5285.     Yanfly.BEC.Window_BattleLog_displayCurrentState.call(this, subject);
  5286. };
  5287.  
  5288. Yanfly.BEC.Window_BattleLog_displayAddedStates =
  5289.     Window_BattleLog.prototype.displayAddedStates;
  5290. Window_BattleLog.prototype.displayAddedStates = function(target) {
  5291.     if (!Yanfly.Param.BECShowStateText) return;
  5292.     Yanfly.BEC.Window_BattleLog_displayAddedStates.call(this, target);
  5293. };
  5294.  
  5295. Yanfly.BEC.Window_BattleLog_displayRemovedStates =
  5296.     Window_BattleLog.prototype.displayRemovedStates;
  5297. Window_BattleLog.prototype.displayRemovedStates = function(target) {
  5298.     if (!Yanfly.Param.BECShowStateText) return;
  5299.     Yanfly.BEC.Window_BattleLog_displayRemovedStates.call(this, target);
  5300. };
  5301.  
  5302. Yanfly.BEC.Window_BattleLog_displayChangedBuffs =
  5303.     Window_BattleLog.prototype.displayChangedBuffs;
  5304. Window_BattleLog.prototype.displayChangedBuffs = function(target) {
  5305.     if (!Yanfly.Param.BECShowBuffText) return;
  5306.     Yanfly.BEC.Window_BattleLog_displayChangedBuffs.call(this, target);
  5307. };
  5308.  
  5309. Window_BattleLog.prototype.popupDamage = function(target) {
  5310. };
  5311.  
  5312. Yanfly.BEC.Window_BattleLog_showEnemyAttackAnimation =
  5313.     Window_BattleLog.prototype.showEnemyAttackAnimation;
  5314. Window_BattleLog.prototype.showEnemyAttackAnimation =
  5315. function(subject, targets) {
  5316.     if ($gameSystem.isSideView()) {
  5317.       this.showNormalAnimation(targets, subject.attackAnimationId(), false);
  5318.     } else {
  5319.       this.showNormalAnimation(targets, subject.attackAnimationId(), false);
  5320.       Yanfly.BEC.Window_BattleLog_showEnemyAttackAnimation.call(this, subject,
  5321.           targets);
  5322.     }
  5323. };
  5324.  
  5325. Window_BattleLog.prototype.showActorAtkAniMirror = function(subject, targets) {
  5326.   if (subject.isActor()) {
  5327.     this.showNormalAnimation(targets, subject.attackAnimationId1(), true);
  5328.     this.showNormalAnimation(targets, subject.attackAnimationId2(), false);
  5329.   } else {
  5330.     this.showNormalAnimation(targets, subject.attackAnimationId1(), true)
  5331.   }
  5332. };
  5333.  
  5334. //=============================================================================
  5335. // New Function
  5336. //=============================================================================
  5337.  
  5338. Yanfly.Util = Yanfly.Util || {};
  5339.  
  5340. Yanfly.Util.displayError = function(e, code, message) {
  5341.   console.log(message);
  5342.   console.log(code || 'NON-EXISTENT');
  5343.   console.error(e);
  5344.   if (Utils.isNwjs() && Utils.isOptionValid('test')) {
  5345.     if (!require('nw.gui').Window.get().isDevToolsOpen()) {
  5346.       require('nw.gui').Window.get().showDevTools();
  5347.     }
  5348.   }
  5349. };
  5350.  
  5351. if (!Yanfly.Util.toGroup) {
  5352.     Yanfly.Util.toGroup = function(inVal) {
  5353.         return inVal;
  5354.     }
  5355. };
  5356.  
  5357. Yanfly.Util.getRange = function(n, m) {
  5358.     var result = [];
  5359.     for (var i = n; i <= m; ++i) result.push(i);
  5360.     return result;
  5361. };
  5362.  
  5363. Yanfly.Util.onlyUnique = function(value, index, self) {
  5364.     return self.indexOf(value) === index;
  5365. };
  5366.  
  5367. //=============================================================================
  5368. // End of File
  5369. //=============================================================================
Add Comment
Please, Sign In to add comment