SHARE
TWEET

Ellye's ATB

Ellye Oct 24th, 2015 (edited) 11,537 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Place file inside /js/plugins
  2. // Remember to save after adding plugins or changing parameters.
  3. //=============================================================================
  4. // Ellye's Active Time Battle
  5. //=============================================================================
  6. /*:
  7.  * Version: 2015-11-28-1906:
  8.  *
  9.  *
  10.  * CHANGE LOG:
  11.  *
  12.  * 2015-11-28-1906: Cast motion should now finish at the proper time.
  13.  * 2015-11-26-1052: Added the option of mid-battle escape.
  14.  * 2015-11-22-1515: Fixed a bug with Confusion/Enrage effects and casting times.
  15.  * 2015-11-22-0925: Made enemy gauges compatible with Yanfly's sprite sideviews for enemies (and possible other similar SV sprites).
  16.  * 2015-11-22-0453: Can now also use <atb_duration_param:PARAM> on states. See HELP.
  17.  * 2015-11-20-1808: Added <haste> notetag for states, actors, classes, equips and enemies, and <atb_duration:> notetag for states.
  18.  * 2015-11-14-2144: Added the <start_atb:NUMBER> note-tag feature. Can be used on actor, class, equip and enemy to set a starting amount of ATB.
  19.  * 2015-11-14-2004: Can now select which parameter to use for casting, instead of it being fixed on Agi. There's a global parameter, and the note <cast_param:>.
  20.  * 2015-11-14-1629: Added Battler EndTurn Effects parameter.
  21.  * 2015-11-14-1518: Added delay system. See HELP.
  22.  * 2015-11-14-1405: Separated a few stuff into their own method, like casting stop/starting and atb ratio.
  23.  * 2015-11-14-0154: Made step back when casting compatible with Yanfly's.
  24.  * 2015-11-14-0134: Turn prediction now predicts casting times when hovering over a skill with cast_time.
  25.  * 2015-11-11-2339: Fixed an issue with Turn Timer and Instant ATB.
  26.  * 2015-11-11-1101: Added paramaters for the Turn Order Display to show symbols when hovering over skills that affect the predction. Work in progress, it looks pretty crude still. And it still needs to predict cast on hover too (it only displays after selection for now). Leave those parameters blank to disable the feature.
  27.  * 2015-11-09-2317: Enemies now also use the different interruptible cast gauge color.
  28.  * 2015-11-09-2317: Separated the drawActorATBGauge method for better compatibility with interface and gauges plugins. (Thanks for the suggestion, Bobstah!)
  29.  * 2015-11-09-0119: Characters with restricted movement (stun, for example) have their cast interrupted and their gauge display stays empty.
  30.  * 2015-11-08-2354: Fixed casting actors staying forward until the next action.
  31.  * 2015-11-08-2354: Added Imported.Ellye_ATB for compatibility.
  32.  * 2015-11-08-2307: Can now mark skills as <interruptible> and other skills as <interrupt>. Also added parameters related to the interrupt system. See HELP.
  33.  * 2015-11-08-2157: Can now add custom <cast_motion:MOTION> and <cast_animation:NUMBER> per skill. See help.
  34.  * 2015-11-08-1557: Added a Default Animation paramter (played at start of cast, defaults to 0 due to compatibility, but I recommend 52 from the default RM MV database).
  35.  * 2015-11-08-1557: Added a Default Cast Motion parameter.
  36.  * 2015-11-08-1557: Added the option of using reversed cast gauges.
  37.  * 2015-11-07-1722: Fixed a bug with lingering enemy cast bars depending on how it finished casting.
  38.  * 2015-11-07-1722: Improved performance of enemy gauges slightly.
  39.  * 2015-11-07-0519: Added ATB gauges and Cast gauges for enemies, and parameters to configure it. PENDING: Offset per enemy (via [Note]), configurable gauge back color, and a few other optional stuff.
  40.  * 2015-11-07-0222: Added parameters for positioning actor name and state icons.
  41.  * 2015-11-07-0036: Made the turn prediction understand casting times (work in progress, still needs improvment (and visual indicators)). It doesn't read casting times on hover yet, though.
  42.  * 2015-11-07-0036: Fixed an issue with the Turn Predction not working properly with skills that delayed the caster turn.
  43.  * 2015-11-07-0036: The cast bar remains visible while the actors executes their skill.
  44.  * 2015-11-06-1036: Fixed an issue when casting time finished at the same time as an input action.
  45.  * 2015-11-05-2319: Added Battle Turn Event parameter.
  46.  * 2015-11-05-2319: Added a casting time bar and parameters for it.
  47.  * 2015-11-03-0945: Fixed a compatibility issue with my States Damage plugin.
  48.  * 2015-11-02-2336: Very early draft of the Casting Time system is now avaliable. If you want to help test it, use <cast_time:NUMBER> on skill notes.
  49.  * 2015-11-02-1423: Fixed an issue with self affecting ATB not showing up properly.
  50.  * 2015-11-02-1350: Turn Prediction interface now reacts to the player hovering over skills that interact with the ATB system (as long as they do it via Notes). (Work in Progress)
  51.  * 2015-11-02-1123: Added option to resize Skill/Item window when using Turn Order Predction, so it stays visible.
  52.  * 2015-11-02-1026: Added option to hide ATB gauge.
  53.  * 2015-11-02-1026: Added instant ATB mode.
  54.  * 2015-11-02-0959: Added configurable opacity gradient for the turn order display.
  55.  * 2015-11-02-0959: Added option to invert CTB display to Right-to-Left.
  56.  * 2015-11-02-0639: Fixed CTB bugs related to dead monsters and actors resulting in incorrect predictions. No dead battler will show up on the bar for now, an option will be given to show them if wanted, in the future.
  57.  * 2015-11-02-0639: Can now use the [Note] field for ATB formulas. SEE HELP.
  58.  * 2015-10-31-1416: Fixed a stepping forward bug when multiple actors filled their AT at the same time (they all stepped forward).
  59.  * 2015-10-31-1416: Made forward stepping optional.
  60.  * 2015-10-31-1254: Added a Average Turn Timer parameter. It overrides the Turn Timer when used. It's ON by default.
  61.  * 2015-10-31-1208: Made the stepping forward animation compatible with Yanfly's Battle Core.
  62.  * 2015-10-31-0325: Monsters now properly show their name instead of their Battler Image name in CTB.
  63.  * 2015-10-31-0325: Characters now step forward when it's their turn.
  64.  * 2015-10-30-0404: Major overhaul on how status are handled. See HELP and/or here: https://ellyeblog.wordpress.com/2015/10/30/status-effects-in-an-atb-system/
  65.  * 2015-10-30-0147: Added parameters for SE playability. Check HELP.
  66.  * 2015-10-30-0021: Rebalanced the duration of status effects - they last 1 turn longer (this actually puts their duration on par with the expected from default combat, due to the different turn structure)
  67.  * 2015-10-29-2330: Added parameters for gauge positions (thanks, djDarkX)
  68.  * 2015-10-28-2300: Implemented iavra's workaround to get parameters without depending on filename.
  69.  * 2015-10-28-2300: Added Gauge Color parameters
  70.  * 2015-10-28-2300: Added Turn Order Prediction interface (WORK IN PROGRESS)
  71.  * Added parameter for random starting ATB bonus.
  72.  * Pre-emptive and surprise attack now function properly.
  73.  * Added starting ATB parameter based on AGI.
  74.  * Fixed battle events set to fire on turn 0+0 not firing (thanks, Kistulot)
  75.  * Fixed dead battlers still gaining ATB.
  76.  * Added the option to display Fight/Escape window.
  77.  * Added a parameter for the gauge name.
  78.  * Added a parameter that allows the developer to select if At-End-Of-Turn effects should happen after an actor takes its action, or for everyone at the end of Turn Timer. (thanks, atreyoray)
  79.  * Corrected a few bugs regarding monsters with the same agility not attacking;
  80.  * Corrected a few bugs regarding Auto-Battle;
  81.  * Corrected a few bugs regarding Status Effects that happened per turn.
  82.  *
  83.  *
  84.  * @plugindesc  V.2015-11-28-1906. A simple Active Time Battle system.
  85.  * <Ellye ATB>
  86.  * @author https://ellyeblog.wordpress.com/ || http://steamcommunity.com/id/Ellye
  87.  *
  88.  * @param ===GAMEPLAY===
  89.  * @desc Parameters below this one are Gameplay-related options
  90.  * @default .
  91.  *
  92.  * @param Agility Weight
  93.  * @desc The higher this integer value, the more noticeable the difference of having high Agility vs. low Agility will be. Default 100.
  94.  * @default 100
  95.  *
  96.  * @param Turn Timer
  97.  * @desc Default: 150. The speed at the virtual "turn" value increases - this is relevant for battles with events that happen on the Nth turn, for example, or for monsters that use skills after the Nth turn, etc. The value entered here will be how much "Agility" the turn timer has. This is invisible to the player.
  98.  * @default 150
  99.  *
  100.  * @param Average Turn Timer
  101.  * @desc 1 = Create a Turn Timer based on the average agility of all Battlers present. 0 = Use the provided turn timer above. Default: 0
  102.  * @default 1
  103.  *
  104.  * @param Base Fill Speed
  105.  * @desc Default: 100. The base speed that the bar fills by itself, also affect Turn Timer in the same way.
  106.  * @default 100
  107.  *
  108.  * @param Display Fight / Escape at beginning of the battle
  109.  * @desc 1 = yes; 0 = no. Default: 0
  110.  * @default 0
  111.  *
  112.  * @param Allow Escape During Battle
  113.  * @desc 1 = yes; 0 = no. Default: 0
  114.  * @default 0
  115.  *
  116.  * @param Starting ATB
  117.  * @desc Multiplied by Agility and Agility Weight/100. Default: 50
  118.  * @default 50
  119.  *
  120.  * @param Starting ATB Random Bonus
  121.  * @desc Maximum random bonus for ATB at battle start. Default: 0
  122.  * @default 0
  123.  *
  124.  * @param Full ATB Gauge
  125.  * @desc The value of a full ATB Gauge. Default: 50000
  126.  * @default 50000
  127.  *
  128.  * @param Instant ATB
  129.  * @desc 1: ON, 0: OFF. Default: 0; Jumps instantly from a turn to the next. Best for CTB style.
  130.  * @default 0
  131.  *
  132.  * @param Battle Event Turn
  133.  * @desc 0: Per timer, 1: per action. Advances the Battle Turn for Events and monster AI. Default: 0
  134.  * @default 0
  135.  *
  136.  * @param Battler EndTurn Effects
  137.  * @desc 0: per timer, 1: per action. Def: 0. Whether "end of turn" for battlers is at turn timer or after they act.
  138.  * @default 0
  139.  *
  140.  * @param Interrupt Compensation Pct
  141.  * @desc What % of the ATB spent in casting is salvaged when interrupted. Default: 25
  142.  * @default 25
  143.  *
  144.  * @param Interrupt Compensation Max
  145.  * @default Maximum % of a full ATB gauge that can be given as compensation when interrupted. Default: 50
  146.  * @default 50
  147.  *
  148.  * @param Maximum Delay Percent
  149.  * @default Maximum that a skill can be delayed, as a % of its cast time. Default: 100
  150.  * @default 100
  151.  *
  152.  * @param Default Delay
  153.  * @default How much % a skill get delayed when hit by a delaying effect. Default: 10
  154.  * @default 10
  155.  *
  156.  * @param Delayable by Default
  157.  * @default 0: No, 1: Yes. Whether every skill is delayable by default.
  158.  * @default 0
  159.  *
  160.  * @param Delays by Default
  161.  * @default 0: No, 1: Yes. Whether every skill applies delay by default.
  162.  * @default 1
  163.  *
  164.  * @param Default Cast Paramater
  165.  * @default Default: agi. Other options: atk, def, mat, mdf, luk, hp, mp...
  166.  * @default agi
  167.  *
  168.  * @param ===SOUND FX===
  169.  * @desc You can override those settings per actor, view HELP.
  170.  * @default .
  171.  *
  172.  * @param Play SE
  173.  * @desc Whether to play SE when Actor is ready. 0 = OFF; 1 = ON. Default: 0
  174.  * @default 0
  175.  *
  176.  * @param SE Name
  177.  * @desc The name of the default Sound Effect file (inside /audio/se), sans extension.
  178.  * @default Cursor3
  179.  *
  180.  * @param SE Volume
  181.  * @desc The default volume for SE (from 0 to 100). Default: 75
  182.  * @default 75
  183.  *
  184.  * @param SE Pitch
  185.  * @desc The default pitch for SE (from 50 to 150). Default: 100
  186.  * @default 100
  187.  *
  188.  * @param SE Pan
  189.  * @desc The default pan for the SE (from -100 to 100). Default: 0
  190.  * @default 0
  191.  *
  192.  * @param ===GAUGE HUD====
  193.  * @desc Parameters below this one are related to the ATB Gauge interface
  194.  * @default .
  195.  *
  196.  * @param Display Gauges
  197.  * @desc 1 = ON; 0 = OFF. Default: 1. If off, all gauge settings are ignored.
  198.  * @default 1
  199.  *
  200.  * @param Actor Name Width
  201.  * @desc Default: 120.
  202.  * @default 120
  203.  *
  204.  * @param Actor Name X Offset
  205.  * @desc Default: 0.
  206.  * @default 0
  207.  *
  208.  * @param Actor State Icons X Offset
  209.  * @desc Default: 0.
  210.  * @default 0
  211.  *
  212.  * @param Gauge Name
  213.  * @desc What label to show on the ATB gauge.
  214.  * @default AT
  215.  *
  216.  * @param Cast Gauge Name
  217.  * @desc What label to show on the cast gauge.
  218.  * @default Cast
  219.  *
  220.  * @param Use Skill Name for Cast Gauge
  221.  * @desc 0: OFF, 1: ON. Default: 1
  222.  * @default 1
  223.  *
  224.  * @param Reversed Cast Gauge
  225.  * @desc 0: OFF, 1: ON. Default: 0.
  226.  * @default 0
  227.  *
  228.  * @param Gauge Color 1
  229.  * @desc First color of the gauge gradient. Default: #505060
  230.  * @default #505060
  231.  *
  232.  * @param Gauge Color 2
  233.  * @desc Second color of the gauge gradient. Default: #D5D5E0
  234.  * @default #D5D5E0
  235.  *
  236.  * @param Cast Gauge Color 1
  237.  * @desc First color of the cast gauge gradient. Default: #8E0B8A
  238.  * @default #8E0B8A
  239.  *
  240.  * @param Cast Gauge Color 2
  241.  * @desc Second color of the cast gauge gradient. Default: #EA7BD9
  242.  * @default #EA7BD9
  243.  *
  244.  * @param Interruptible Gauge Color 1
  245.  * @desc First color of the interruptible cast gauge gradient. Default: #D5D315
  246.  * @default #D5D315
  247.  *
  248.  * @param Interruptible Gauge Color 2
  249.  * @desc Second color of the interruptible cast gauge gradient. Default: #EDEE87
  250.  * @default #EDEE87
  251.  *
  252.  * @param Positive Haste Gauge Color 1
  253.  * @desc ATB Gauge when hasted. Default: #ECAA93
  254.  * @default #ECAA93
  255.  *
  256.  * @param Positive Haste Gauge Color 2
  257.  * @desc ATB Gauge when hasted. Default: #E6BA98
  258.  * @default #E6BA98
  259.  *
  260.  * @param Negative Haste Gauge Color 1
  261.  * @desc ATB Gauge when slowed. Default: #1D5E86
  262.  * @default #1D5E86
  263.  *
  264.  * @param Negative Haste Gauge Color 2
  265.  * @desc ATB Gauge when slowed. Default: #2191A1
  266.  * @default #2191A1
  267.  *
  268.  * @param Zero Haste Gauge Color 1
  269.  * @desc ATB Gauge when stopped. Default: #430F0F
  270.  * @default #430F0F
  271.  *
  272.  * @param Zero Haste Gauge Color 2
  273.  * @desc ATB Gauge when stopped. Default: #4B1618
  274.  * @default #4B1618
  275.  *
  276.  * @param ATB Gauge Text Width
  277.  * @desc Width area for the text. Default: 60
  278.  * @default 60
  279.  *
  280.  * @param Gauge Area Size
  281.  * @desc Width of the area for gauges. Default: 400
  282.  * @default 400
  283.  *
  284.  * @param ==POS WITH TP==
  285.  * @desc Those affect the positions of gauge when you have TP Display enabled.
  286.  * @default .
  287.  *
  288.  * @param HP Gauge X Position (with TP)
  289.  * @desc Default: 0
  290.  * @default 0
  291.  *
  292.  * @param HP Gauge Width (with TP)
  293.  * @desc Default: 97
  294.  * @default 97
  295.  *
  296.  * @param MP Gauge X Position (with TP)
  297.  * @desc Default: 112
  298.  * @default 112
  299.  *
  300.  * @param MP Gauge Width (with TP)
  301.  * @desc Default: 86
  302.  * @default 86
  303.  *
  304.  * @param TP Gauge X Position
  305.  * @desc Default: 213
  306.  * @default 213
  307.  *
  308.  * @param TP Gauge Width
  309.  * @desc Default: 86
  310.  * @default 86
  311.  *
  312.  * @param ATB Gauge X Position (with TP)
  313.  * @desc Default: 314
  314.  * @default 314
  315.  *
  316.  * @param ATB Gauge Width (with TP)
  317.  * @desc Default: 86
  318.  * @default 86
  319.  *
  320.  * @param ==POS WITHOUT TP==
  321.  * @desc Those affect the positions of gauge when you have TP Display disabled.
  322.  * @default .
  323.  *
  324.  * @param HP Gauge X Position
  325.  * @desc Default: 0
  326.  * @default 0
  327.  *
  328.  * @param HP Gauge Width
  329.  * @desc Default: 130
  330.  * @default 130
  331.  *
  332.  * @param MP Gauge X Position
  333.  * @desc Default: 145
  334.  * @default 145
  335.  *
  336.  * @param MP Gauge Width
  337.  * @desc Default: 120
  338.  * @default 120
  339.  *
  340.  * @param ATB Gauge X Position
  341.  * @desc Default: 280
  342.  * @default 280
  343.  *
  344.  * @param ATB Gauge Width
  345.  * @desc Default: 120
  346.  * @default 120
  347.  *
  348.  * @param ===TURN ORDER HUD===
  349.  * @desc Parameters bellow this one are related to the turn order display
  350.  * @default .
  351.  *
  352.  * @param Display Predicted Turn Order
  353.  * @desc 1 = yes, 0 = no. Default: 0
  354.  * @default 0
  355.  *
  356.  * @param Display as Faces or Names
  357.  * @desc 1 = Faces, 0 = Names. See Help. Default: 0
  358.  * @default 0
  359.  *
  360.  * @param Invert TO Direction
  361.  * @desc 0 = Left-to-Right; 1 = Right-to-Left. Default: 0
  362.  * @default 0
  363.  *
  364.  * @param Opacity First TO
  365.  * @desc Opacity of the first actor window (from 0 to 255). Default: 220
  366.  * @default 220
  367.  *
  368.  * @param Opacity Last TO
  369.  * @desc Opacity of the last actor window (from 0 to 255). Default: 160. To disable gradient, set the same value as above.
  370.  * @default 160
  371.  *
  372.  * @param Resize Skill and Item Window
  373.  * @desc 1: ON, 0: OFF. Default: 1. To allow room for the turn prediction interface (only if it's enabled)
  374.  * @default 1
  375.  *
  376.  * @param Prediction Bonus
  377.  * @desc String to show when predicting a buff to ATB. Default: ▲. Leave blank for none.
  378.  * @default ▲
  379.  *
  380.  * @param Prediction Malus
  381.  * @desc String to show when predicting a buff to ATB. Default: ▼. Leave blank for none.
  382.  * @default ▼
  383.  *
  384.  * @param Prediction Cast
  385.  * @desc String to show when predicting a buff to ATB. Default: ♦. Leave blank for none.
  386.  * @default ♦
  387.  *
  388.  * @param Prediction Bonus Color
  389.  * @desc Color for the bonus string. Default: #62D962
  390.  * @default #62D962
  391.  *
  392.  * @param Prediction Malus Color
  393.  * @desc Color for the malus string. Default: #D96262
  394.  * @default #D96262
  395.  *
  396.  * @param Prediction Cast Color
  397.  * @desc Color for the cast string. Default: #8662D9
  398.  * @default #8662D9
  399.  *
  400.  * @param ===ENEMY GAUGES===
  401.  *
  402.  * @param Display Enemy Cast Gauges
  403.  * @desc 0 = off; 1 = on. Default: 1
  404.  * @default 1
  405.  *
  406.  * @param Display Enemy ATB Gauges
  407.  * @desc 0 = off, 1 = on. Default: 0
  408.  * @default 0
  409.  *
  410.  * @param Enemy Gauge Opacity
  411.  * @desc From 0 to 255 (Default: 200)
  412.  * @default 200
  413.  *
  414.  * @param Enemy Show Cast Name
  415.  * @desc 0 = Show no text; 1 = Show skill name; 2 = Show gauge name. Default: 1
  416.  * @default 1
  417.  *
  418.  * @param Enemy Show Name
  419.  * @desc 0 = Show no text; 1 = Show enemy name; 2 = Show gauge name. Default: 1
  420.  * @default 1
  421.  *
  422.  * @param Enemy Gauge Color1
  423.  * @desc Default: #FA8691
  424.  * @default #FA8691
  425.  *
  426.  * @param Enemy Gauge Color2
  427.  * @desc Default: #F0B8C8
  428.  * @default #F0B8C8
  429.  *
  430.  * @param ===MISC UI===
  431.  * @desc Other UI related options
  432.  * @default .
  433.  *
  434.  * @param Step Forward When Ready
  435.  * @desc Whether actors should step forward when its their time for input. 1: ON. 0: OFF. Default: 1
  436.  * @default 1
  437.  *
  438.  * @param Default Cast Motion
  439.  * @desc 0: none, 1: chant, 2: skill, 3: item, 4: spell. Default: 1
  440.  * @default 1
  441.  *
  442.  * @param Default Cast Animation
  443.  * @desc The ID of the default Animation. 0 for none. Suggested (from default DB): 52. Default: 0
  444.  * @default 0
  445.  *
  446.  * @param Interrupt Animation
  447.  * @desc Battle animation to be played when a skill is interrupted. Suggestion: create one with flash and sound only. Default: 0
  448.  * @default 0
  449.  *  
  450.  * @help Actors will act as frequently as their AGILITY attribute allows them to, instead of taking fixed turns.
  451.  * They will have an "AT" Gauge in the interface that goes from 0 to 1000, and they will get a turn to act when it reaches 1000.
  452.  * Gauges are paused while the player is deciding on a command, or while an animation is being played.
  453.  * A full gauge requires 50000 ATB by default (excess ATB is not lost, and the number can be negative).
  454.  *
  455.  * USING THE [NOTE] FIELD TO SETUP SKILLS THAT INTERACT WITH ATB:
  456.  * In each Skill or Combat Usable Item, you can set up [NOTE]s that interact with the ATB system.
  457.  * There's the following notes:
  458.  * <self_atb:FORMULA>
  459.  * <target_atb:FORMULA>
  460.  *
  461.  * It's important to note that those need to be ARITHMETICAL FORMULAS, not commands.
  462.  * The following examples are valid:
  463.  * <self_atb:25000> #This would make a quick skill, as your next turn will come faster.
  464.  * <self_atb:-25000> #This one would delay your next turn
  465.  * <self_atb:50*a.agi - 20*b.agi> #This would give the user some ATB based on the difference of AGI between him and the target
  466.  * <target_atb:25000> #This would GIVE the target some atb, making his turn come quicker.
  467.  * <target_atb:-10000> #This would DELAY the target next turn
  468.  * <target_atb:-50*(3*a.mat - b.mdf)> #This would DELAY the target next turn based on the difference between the attacker Magic Attack and the target Magic Defense
  469.  *
  470.  * So:
  471.  * It needs to be a formula that results in a NUMBER, not a command. Do not use "a.atb+=5000;" or similar assignments.
  472.  * You do can use methods like Math.random or Math.Max; you do can use if-else conditions; just make sure that the end result will be a number and that you aren't executing any action except calculating that number.
  473.  * POSITIVE numbers will always GIVE ATB, no matter if for caster or target.
  474.  * NEGATIVE numbers will always REMOVE ATB, no matter if for caster or target.
  475.  * Important note about SKILL WITH MULTIPLE TARGET: The "self_atb" parameter applies ONCE PER TARGET HIT, so balance accordingly (this was also the case with the Formula field).
  476.  *
  477.  * If you use Display Faces, your enemies require to have a face configured in the Database Editor.
  478.  * In the [Notes] field, you should add, for example: <face_name:Monster><face_id:2> - this would use the RTP Orc face.
  479.  * In that example <face_name> receives the name of the file, and face_id the index of the face, counting left-to-right, top first, then bottom. Starts at 0.
  480.  *
  481.  * You can set up Actor-specific ready Sound Effects (if you enable Play SE). It's similar to the way monster faces are set up.
  482.  * In the [Notes] field of an actor, you can enter: <se_name:Bow4><se_volume:100><se_pitch:150> to play the sound "Bow4" at those settings whenever that Actor is ready, for example.
  483.  *
  484.  * CASTING TIMES:
  485.  * You can now set up casting times by adding:
  486.  * <cast_time:NUMBER>
  487.  * On the [Note] tag of a skill. For example, <cast_time:25000> would require the same time as half of a full default ATB gauge.
  488.  *
  489.  * Skills with casting time can also be marked with
  490.  * <interruptible>
  491.  * (or <interruptable>)
  492.  *
  493.  * This means that they will be broken when hit by a skill that is marked as:
  494.  * <interrupt>
  495.  * (or <interrupts>)
  496.  *
  497.  * By default, interruptable skills have a different cast gauge color.
  498.  * You can also set up an Animation to play whenever a skill is successfully interrupted.
  499.  * SUGGESTION: Create a new Animation with just a flash and some sound effect to use for this, most of the default VFXs are too fancy for that (keep in mind that this plays together with the hit vfx).
  500.  *
  501.  * For the DELAY system, you can set default delay parameters in the Plugin Paramaters, and customize them per skill with the following notes:
  502.  *
  503.  * <delayable>
  504.  * Will mark a skill as delayable, regardless of default settings.
  505.  *
  506.  * <not_delayable>
  507.  * Will mark a skill as not delayable, regardless of default settings.
  508.  *
  509.  * <delays>
  510.  * Will make a skill apply delay regardless of default settings. If no <delay_amount> is specified, it will use the default delay amount. Will also delay even if it targets ally (by default this doesn't happen)
  511.  *
  512.  * <delay_amount:NUMBER>
  513.  * The amount (a % of the total cast time) of delay to be applied. For example, 25 means that it will bring the casting bar down by 25% of its maximum value. If you set to 0, no delay will be applied (in case you're using Delays by Default parameter).
  514.  *
  515.  *
  516.  * Another notes you can have for casting skills:
  517.  * <cast_animation:NUMBER>
  518.  * This is the number of an Animation (from the Animations tab in the database) to be cast at the start of the cast.
  519.  *
  520.  * <cast_motion:MOTION>
  521.  * The movement your character does while casting. Some valid options are:
  522.  * <cast_motion:spell>, <cast_motion:skill>, <cast_motion:item>, <cast_motion:chant>, <cast_motion:swing>, <cast_motion:thrust>, <cast_motion:missile>, <cast_motion:wait>
  523.  *
  524.  * <cast_param:PARAM>
  525.  * Will use that Param instead of the default (agi, normally) for casting that skill. For example:
  526.  * <cast_param:mat> will use MAT instead of AGI.
  527.  *
  528.  * STATES:
  529.  * If you want a State to count down per action taken, you set it up as Action End.
  530.  * If you want a State to count down per virtual turn, you set it up as Turn End.
  531.  *
  532.  * Optionally, you can also opt to use neither of those and instead have your state timed by ATB gauge  (can also be used together with the above, whichever comes first will remove the state)
  533.  * This might be the optimal design overall for the ATB system, at least for states that directly affect the ATB gauge:
  534.  * To do so, use the following tag:
  535.  * <atb_duration:NUMBER>
  536.  * For example, 150000 would last the normal duration of three turns for that actor (not taking modifiers like haste in consideration).
  537.  * Optionally, you can also specify which parameter is used for the speed at which the state comes out. To do so, use:
  538.  * <atb_duration_param:atk>, <atb_duration_param:def>, <atb_duration_param:mat>, <atb_duration_param:mdf>, <atb_duration_param:agi> or <atb_duration_param:luk>
  539.  * You can also use <atb_duration_param:turn> to make it follow Turn Timer and be independent of the target's parameters.
  540.  *
  541.  *
  542.  * STARTING ATB:
  543.  * You can use the note-tag
  544.  * <start_atb:NUMBER>
  545.  * On actors, classes, equips and enemies to set up bonus starting ATB (absolute vlaues).
  546.  *
  547.  * HASTE:
  548.  * You can use the note-tags:
  549.  * <haste:NUMBER>
  550.  * <haste_atb:NUMBER>
  551.  * <haste_cast:NUMBER>
  552.  * This is a multiplicative percent change to all speeds, atb-only speed or cast-only speed.
  553.  * A value of "<haste:100>" means no change. A value of "<haste:200>" would mean double speed, for example, while a value of "<haste:50>" would mean half speed.
  554.  * Those tags can be used on Actors, Classes, Equips and Enemies.
  555.  *
  556.  */
  557.  
  558. //Our plugin needs to be inside a function:
  559.  
  560. var Imported = Imported || {};
  561. Imported.Ellye_ATB = true;
  562.  
  563. (function() {
  564.  
  565.     var parameters = $plugins.filter(function(p) {
  566.         return p.description.contains('<Ellye ATB>');
  567.     })[0].parameters; //Thanks to Iavra
  568.     var turn_atb = 0;
  569.     var ctb_window_width = 90;
  570.     var ctb_window_height = 60;
  571.     var turns_to_predict = Math.floor((SceneManager._boxWidth / ctb_window_width));
  572.     var ctb_window_x_offset = (SceneManager._boxWidth - turns_to_predict * ctb_window_width) / 2;
  573.     var full_atb = Number(parameters['Full ATB Gauge'] || 50000);
  574.     var agi_weight = Number(parameters['Agility Weight'] || 100);
  575.     var turn_timer = Number(parameters['Turn Timer'] || 150);
  576.     var av_turn_timer = Number(parameters['Average Turn Timer'] || 1);
  577.     var base_atb_increase = Number(parameters['Base Fill Speed'] || 100);
  578.     var display_gauges = Number(parameters['Display Gauges'] || 1);
  579.     var actor_name_x_offset = Number(parameters['Actor Name X Offset'] || 0);
  580.     var actor_icons_x_offset = Number(parameters['Actor Icons X Offset'] || 0);
  581.     var actor_name_width = Number(parameters['Actor Name Width'] || 120);
  582.     var gauge_name = String(parameters['Gauge Name'] || "");
  583.     var cast_gauge_name = String(parameters['Cast Gauge Name'] || "");
  584.     var use_skill_name_gauge = Number(parameters['Use Skill Name for Cast Gauge'] || 0);
  585.     var display_party_command = Number(parameters['Display Fight / Escape at beginning of the battle'] || 0);
  586.     var allow_midbattle_escape = Number(parameters['Allow Escape During Battle'] || 0);
  587.     if (allow_midbattle_escape === 1)
  588.     {
  589.         display_party_command = 1;
  590.     }
  591.     var starting_atb = Number(parameters['Starting ATB'] || 50);
  592.     var starting_atb_random = Number(parameters['Starting ATB Random Bonus'] || 0);
  593.     var display_turn_order = Number(parameters['Display Predicted Turn Order'] || 0);
  594.     var display_as_faces_or_names = Number(parameters['Display as Faces or Names'] || 0);
  595.     var invert_turn_order_display = Number(parameters['Invert TO Direction'] || 0);
  596.     var ctb_opacity_first = Number(parameters['Opacity First TO'] || 220);
  597.     var ctb_opacity_last = Number(parameters['Opacity Last TO'] || 160);
  598.     var resize_skill_window = Number(parameters['Resize Skill and Item Window'] || 1);
  599.     var atb_gauge_width = Number(parameters['ATB Gauge Width'] || 120);
  600.     var atb_gauge_color1 = String(parameters['Gauge Color 1'] || "#505060");
  601.     var atb_gauge_color2 = String(parameters['Gauge Color 2'] || "#D5D5E0");
  602.     var cast_gauge_color1 = String(parameters['Cast Gauge Color 1'] || "#8E0B8A");
  603.     var cast_gauge_color2 = String(parameters['Cast Gauge Color 2'] || "#EA7BD9");
  604.     var gauge_area_size = Number(parameters['Gauge Area Size'] || 400);
  605.     var gauge_text_width = Number(parameters['ATB Gauge Text Width'] || 120);
  606.     var hp_gauge_x_tp = Number(parameters['HP Gauge X Position (with TP)'] || 0);
  607.     var mp_gauge_x_tp = Number(parameters['MP Gauge X Position (with TP)'] || 112);
  608.     var tp_gauge_x = Number(parameters['TP Gauge X Position'] || 213);
  609.     var atb_gauge_x_tp = Number(parameters['ATB Gauge X Position (with TP)'] || 314);
  610.     var hp_gauge_width_tp = Number(parameters['HP Gauge Width (with TP)'] || 97);
  611.     var mp_gauge_width_tp = Number(parameters['MP Gauge Width (with TP)'] || 86);
  612.     var tp_gauge_width = Number(parameters['TP Gauge Width'] || 86);
  613.     var atb_gauge_width_tp = Number(parameters['ATB Gauge Width (with TP)'] || 86);
  614.     var hp_gauge_x = Number(parameters['HP Gauge X Position'] || 0);
  615.     var mp_gauge_x = Number(parameters['MP Gauge X Position'] || 145);
  616.     var atb_gauge_x = Number(parameters['ATB Gauge X Position'] || 280);
  617.     var hp_gauge_width = Number(parameters['HP Gauge Width'] || 130);
  618.     var mp_gauge_width = Number(parameters['MP Gauge Width'] || 120);
  619.     var atb_gauge_width = Number(parameters['ATB Gauge Width'] || 120);
  620.     var se_enabled = Number(parameters['Play SE'] || 0);
  621.     var se_name = String(parameters['SE Name'] || "Cursor3");
  622.     var se_volume = Number(parameters['SE Volume'] || 75);
  623.     var se_pitch = Number(parameters['SE Pitch'] || 100);
  624.     var se_pan = Number(parameters['SE Pan'] || 0);
  625.     var step_forward = Number(parameters['Step Forward When Ready'] || 1);
  626.     var instant_atb = Number(parameters['Instant ATB'] || 0);
  627.     var battle_event_turn_mode = Number(parameters['Battle Event Turn'] || 0);
  628.     var enemy_gauge_position = Number(parameters['Enemy Gauge Position'] || 0);
  629.     var enemy_gauge_opacity = Number(parameters['Enemy Gauge Opacity'] || 200);
  630.     var enemy_show_cast_name = Number(parameters['Enemy Show Cast Name'] || 1);
  631.     var enemy_show_name = Number(parameters['Enemy Show Name'] || 1);
  632.     var display_enemy_cast_gauges = Number(parameters['Display Enemy Cast Gauges'] || 1);
  633.     var display_enemy_atb_gauges = Number(parameters['Display Enemy ATB Gauges'] || 0);
  634.     var enemy_gauge_color1 = String(parameters['Enemy Gauge Color1'] || "#F5818B");
  635.     var enemy_gauge_color2 = String(parameters['Enemy Gauge Color2'] || "#EBB3C3");
  636.     var reversed_cast_gauge = Number(parameters['Reversed Cast Gauge'] || 0);
  637.     var default_cast_motion = Number(parameters['Default Cast Motion'] || 1);
  638.     var default_cast_vfx = Number(parameters['Default Cast Animation'] || 0);
  639.     var interrupt_compensation_pct = Number(parameters['Interrupt Compensation Pct'] || 25);
  640.     var interrupt_compensation_max = Number(parameters['Interrupt Compensation Max'] || 50);
  641.     var interrupt_vfx = Number(parameters['Interrupt Animation'] || 0);
  642.     var interrupt_gauge_color1 = String(parameters['Interruptible Gauge Color 1'] || "#D5D315");
  643.     var interrupt_gauge_color2 = String(parameters['Interruptible Gauge Color 2'] || "#EDEE87");
  644.     var ctb_bonus = String(parameters['Prediction Bonus'] || "");
  645.     var ctb_malus = String(parameters['Prediction Malus'] || "");
  646.     var ctb_cast = String(parameters['Prediction Cast'] || "");
  647.     var ctb_cast_skill_name = Number(parameters['Prediction Cast Name'] || 0);
  648.     var ctb_bonus_color = String(parameters['Prediction Bonus Color'] || "#42B942");
  649.     var ctb_malus_color = String(parameters['Prediction Malus Color'] || "#B94242");
  650.     var ctb_cast_color = String(parameters['Prediction Cast Color'] || "#8642B9");
  651.     var max_delay_pct = Number(parameters['Maximum Delay Percent'] || 100);
  652.     var default_delay_amount = Number(parameters['Default Delay'] || 10);
  653.     var default_delayable = Number(parameters['Delayable by Default'] || 0);
  654.     var default_delays = Number(parameters['Delays by Default'] || 1);
  655.     var battler_end_turn_effects = Number(parameters['Battler EndTurn Effects'] || 0);
  656.     var default_cast_parameter = String(parameters['Default Cast Paramater'] || "agi");
  657.     var positive_haste_gauge_color1 = String(parameters['Positive Haste Gauge Color 1'] || "#ECAA93");
  658.     var positive_haste_gauge_color2 = String(parameters['Positive Haste Gauge Color 2'] || "#E6BA98");
  659.     var negative_haste_gauge_color1 = String(parameters['Negative Haste Gauge Color 1'] || "#1D5E86");
  660.     var negative_haste_gauge_color2 = String(parameters['Negative Haste Gauge Color 2'] || "#2191A1");
  661.     var zero_haste_gauge_color1 = String(parameters['Zero Haste Gauge Color 1'] || "#430F0F");
  662.     var zero_haste_gauge_color2 = String(parameters['Zero Haste Gauge Color 2'] || "#4B1618");
  663.    
  664.  
  665.     //==================================================
  666.     // INTERFACE
  667.     //==================================================
  668.  
  669.     //All of those changes depend on the Display Gauge Parameter
  670.     if (display_gauges === 1)
  671.     {
  672.         //Let's increase the area for gauges in the battlescreen from the default value of 330 to 400.
  673.         Window_BattleStatus.prototype.gaugeAreaWidth = function() {
  674.             return gauge_area_size;
  675.         };
  676.  
  677.         Window_BattleStatus.prototype.drawBasicArea = function(rect, actor) {
  678.             this.drawActorName(actor, rect.x + actor_name_x_offset, rect.y, actor_name_width);
  679.             this.drawActorIcons(actor, rect.x + actor_name_width + 4 + actor_icons_x_offset, rect.y, rect.width - actor_name_width - actor_icons_x_offset);
  680.         };
  681.  
  682.         //let's change the DrawGaugeArea methods, to include our ATB gauge.
  683.         //The version with TP:
  684.         Window_BattleStatus.prototype.drawGaugeAreaWithTp = function(rect, actor) {
  685.             this.drawActorHp(actor, rect.x + hp_gauge_x_tp, rect.y, hp_gauge_width_tp);
  686.             this.drawActorMp(actor, rect.x + mp_gauge_x_tp, rect.y, mp_gauge_width_tp);
  687.             this.drawActorTp(actor, rect.x + tp_gauge_x, rect.y, tp_gauge_width);
  688.             this.drawActorATB(actor, rect.x + atb_gauge_x_tp, rect.y, atb_gauge_width_tp);
  689.         };
  690.  
  691.         //The version without TP:
  692.         Window_BattleStatus.prototype.drawGaugeAreaWithoutTp = function(rect, actor) {
  693.             this.drawActorHp(actor, rect.x + hp_gauge_x, rect.y, hp_gauge_width);
  694.             this.drawActorMp(actor, rect.x + mp_gauge_x, rect.y, mp_gauge_width);
  695.             this.drawActorATB(actor, rect.x + atb_gauge_x, rect.y, atb_gauge_width);
  696.         };
  697.  
  698.         //Let's create the method that prepares and calls for the drawing of the ATB or Cast gauge:
  699.         Window_Base.prototype.drawActorATB = function(actor, x, y, width) {
  700.             //Cast:
  701.             var color1;
  702.             var color2;
  703.             if (actor.target_cast_atb !== 0)
  704.             {
  705.                 if (actor.CastHaste() <= 0)
  706.                 {
  707.                     color1 = zero_haste_gauge_color1;
  708.                     color2 = zero_haste_gauge_color2;
  709.                 }
  710.                 else if (actor.IsCastInterruptible())
  711.                 {
  712.                     color1 = interrupt_gauge_color1;
  713.                     color2 = interrupt_gauge_color2;
  714.                 }
  715.                 else
  716.                 {
  717.                     color1 = cast_gauge_color1;
  718.                     color2 = cast_gauge_color2;
  719.                 }
  720.                 this.drawActorATBGauge(x, y, width, actor.castRatio(), color1, color2, actor.castName(), x, y, gauge_text_width);
  721.             }
  722.             //ATB:
  723.             else
  724.             {
  725.                 if (actor.ATBHaste() <= 0)
  726.                 {
  727.                     color1 = zero_haste_gauge_color1;
  728.                     color2 = zero_haste_gauge_color2;
  729.                 }
  730.                 else if (actor.ATBHaste() < 100)
  731.                 {
  732.                     color1 = negative_haste_gauge_color1;
  733.                     color2 = negative_haste_gauge_color2;
  734.                 }
  735.                 else if (actor.ATBHaste() > 100)
  736.                 {
  737.                     color1 = positive_haste_gauge_color1;
  738.                     color2 = positive_haste_gauge_color2;
  739.                 }
  740.                 else
  741.                 {
  742.                     color1 = atb_gauge_color1;
  743.                     color2 = atb_gauge_color2;
  744.                 }
  745.                 this.drawActorATBGauge(x, y, width, actor.atbRatio(), color1, color2, gauge_name, x, y, gauge_text_width);
  746.             }
  747.         };
  748.  
  749.         //The method that handles the actual gauge drawing:
  750.         Window_Base.prototype.drawActorATBGauge = function(x, y, width, ratio, color1, color2, text, text_x, text_y, text_width)
  751.         {
  752.             this.drawGauge(x, y, width, ratio, color1, color2);
  753.             this.changeTextColor(this.systemColor());
  754.             if (typeof text !== 'undefined' && text !== null && text !== "")
  755.             {
  756.                 this.drawText(text, text_x, text_y, text_width);
  757.             }
  758.         };
  759.     }
  760.  
  761.     //If we are going to display ATB Gauges or Cast gauges for enemies
  762.     if (display_enemy_atb_gauges === 1 || display_enemy_cast_gauges === 1)
  763.     {
  764.         //We initialize a _gaugeWindow var.
  765.         _alias_spriteenemy_init = Sprite_Enemy.prototype.initMembers;
  766.         Sprite_Enemy.prototype.initMembers = function() {
  767.             _alias_spriteenemy_init.call(this);
  768.             this._gaugeWindow = null;
  769.         };
  770.  
  771.         //The method that populates it:
  772.         _alias_spre_updatebitmap = Sprite_Enemy.prototype.updateBitmap;
  773.         Sprite_Enemy.prototype.updateBitmap = function() {
  774.             _alias_spre_updatebitmap.call(this);
  775.             //Creates it once the bitmap finishes loading, for width and height information
  776.             if (this._gaugeWindow === null && typeof this.bitmap !== 'undefined' && this.bitmap !== null && this.bitmap.height !== 0)
  777.             {
  778.                 this._gaugeWindow = new Window_Base();
  779.                 var y = (enemy_gauge_position === 0) ? 0 : -this.bitmap.height - 36;
  780.                 var bmpwidth = this.bitmap.width;
  781.                 if (bmpwidth <= 1)
  782.                 {
  783.                     bmpwidth = atb_gauge_width;
  784.                     this._gaugeWindow.initialize(bmpwidth / 2, y, bmpwidth + 36, this._gaugeWindow.lineHeight() + 2 * this._gaugeWindow.standardPadding() + 26);
  785.                     this._gaugeWindow.scale.x *= -1;
  786.                 }
  787.                 else
  788.                 {
  789.                     this._gaugeWindow.initialize(-bmpwidth / 2, y, bmpwidth + 36, this._gaugeWindow.lineHeight() + 2 * this._gaugeWindow.standardPadding() + 26);
  790.                 }
  791.                 this._gaugeWindow.padding = 0;
  792.                 this._gaugeWindow.margin = 0;
  793.                 this._gaugeWindow.backOpacity = 0;
  794.                 this._gaugeWindow.opacity = 0;
  795.                 this._gaugeWindow.hideBackgroundDimmer();
  796.                 this._gaugeWindow.contents.paintOpacity = enemy_gauge_opacity;
  797.                 this.addChild(this._gaugeWindow);
  798.             }
  799.             //Updates it when conditions are met:
  800.             if (this._gaugeWindow !== null && this._battler !== null && BattleManager._phase === 'atb')
  801.             {
  802.                 var gaugeWidth = this.bitmap.width;
  803.                 var mirroredGauge = false;
  804.                 if (gaugeWidth <= 1)
  805.                 {
  806.                     gaugeWidth = atb_gauge_width;
  807.                 }
  808.                 this._gaugeWindow.contents.clear();
  809.                 if (this._battler.isDead() || this._battler.isHidden())
  810.                 {
  811.                     //Do not draw.
  812.                 }
  813.                 else if (this._battler.target_cast_atb !== 0 && display_enemy_cast_gauges === 1)
  814.                 {
  815.                     var color1 = (this._battler.IsCastInterruptible()) ? interrupt_gauge_color1 : cast_gauge_color1;
  816.                     var color2 = (this._battler.IsCastInterruptible()) ? interrupt_gauge_color2 : cast_gauge_color2;
  817.                     if (this._battler.CastHaste() <= 0)
  818.                     {
  819.                         color1 = zero_haste_gauge_color1;
  820.                         color2 = zero_haste_gauge_color2;
  821.                     }
  822.                     this._gaugeWindow.drawGauge(0, 0, gaugeWidth, this._battler.castRatio(), color1, color2);
  823.                     if (enemy_show_cast_name === 1)
  824.                     {
  825.                         this._gaugeWindow.drawText(this._battler.castName(), 0, 0, gaugeWidth);
  826.                     }
  827.                     else if (enemy_show_cast_name === 2)
  828.                     {
  829.                         this._gaugeWindow.drawText(cast_gauge_name, 0, 0, gaugeWidth);
  830.                     }
  831.                 }
  832.                 else if (display_enemy_atb_gauges === 1)
  833.                 {
  834.                     var color1;
  835.                     var color2;
  836.                     if (this._battler.ATBHaste() <= 0)
  837.                     {
  838.                         color1 = zero_haste_gauge_color1;
  839.                         color2 = zero_haste_gauge_color2;
  840.                     }
  841.                     else if (this._battler.ATBHaste() < 100)
  842.                     {
  843.                         color1 = negative_haste_gauge_color1;
  844.                         color2 = negative_haste_gauge_color2;
  845.                     }
  846.                     else if (this._battler.ATBHaste() > 100)
  847.                     {
  848.                         color1 = positive_haste_gauge_color1;
  849.                         color2 = positive_haste_gauge_color2;
  850.                     }
  851.                     else
  852.                     {
  853.                         color1 = enemy_gauge_color1;
  854.                         color2 = enemy_gauge_color2;
  855.                     }
  856.                     this._gaugeWindow.drawGauge(0, 0, gaugeWidth, this._battler.atbRatio(), color1, color2);
  857.                     if (enemy_show_name === 1)
  858.                     {
  859.                         this._gaugeWindow.drawText(this._battler.originalName(), 0, 0, gaugeWidth);
  860.                     }
  861.                     else if (enemy_show_name === 2)
  862.                     {
  863.                         this._gaugeWindow.drawText(gauge_name, 0, 0, gaugeWidth);
  864.                     }
  865.                 }
  866.             }
  867.         };
  868.     } //End of enemy-gauge related block.
  869.  
  870.     //Let's create the method for calculating ATB percent for the gauge:
  871.     Game_BattlerBase.prototype.atbRatio = function() {
  872.         if (typeof this.atb !== 'undefined' && this.canMove()) {
  873.             if (this.atb / full_atb >= 1)
  874.             {
  875.                 return 1;
  876.             }
  877.             if (this.atb <= 0)
  878.             {
  879.                 return 0;
  880.             }
  881.             return this.atb / full_atb;
  882.         }
  883.         return 0;
  884.     };
  885.  
  886.     Game_BattlerBase.prototype.castName = function() {
  887.         if (use_skill_name_gauge === 0)
  888.         {
  889.             return cast_gauge_name;
  890.         }
  891.         if (this.casting_action !== null && typeof this.casting_action.item() !== 'undefined' && typeof this.casting_action.item().name !== 'undefined')
  892.         {
  893.             return this.casting_action.item().name;
  894.         }
  895.         return cast_gauge_name;
  896.     };
  897.  
  898.     //And one for calculating Cast Ratio for th gauge:
  899.     Game_BattlerBase.prototype.castRatio = function() {
  900.         if (this.target_cast_atb !== 0 && this.canMove())
  901.         {
  902.             if (this.current_cast_atb / this.target_cast_atb >= 1)
  903.             {
  904.                 return (reversed_cast_gauge === 1) ? 0 : 1;
  905.             }
  906.             if (this.current_cast_atb <= 0)
  907.             {
  908.                 return (reversed_cast_gauge === 1) ? 1 : 0;
  909.             }
  910.             var value = this.current_cast_atb / this.target_cast_atb;
  911.             return (reversed_cast_gauge === 1) ? 1 - value : value;
  912.         }
  913.         return 0;
  914.     };
  915.  
  916.  
  917.     //Some of our interface options use faces for enemies. We use metadata for that. Let's create the method that access it:
  918.     Game_Enemy.prototype.getFaceName = function() {
  919.         if (typeof $dataEnemies[this._enemyId].meta.face_name !== 'undefined')
  920.         {
  921.             return $dataEnemies[this._enemyId].meta.face_name;
  922.         }
  923.         return false;
  924.     };
  925.     Game_Enemy.prototype.getFaceID = function() {
  926.         if (typeof $dataEnemies[this._enemyId].meta.face_id !== 'undefined')
  927.         {
  928.             return $dataEnemies[this._enemyId].meta.face_id;
  929.         }
  930.         return false;
  931.     };
  932.  
  933.     //Turn Order Window (if selected to be displayed):
  934.     if (display_turn_order)
  935.     {
  936.         //Let's move the Battle Log window down:
  937.         Window_BattleLog.prototype.initialize = function() {
  938.             var width = this.windowWidth();
  939.             var height = this.windowHeight();
  940.             Window_Selectable.prototype.initialize.call(this, 0, ctb_window_height, width, height);
  941.             this.opacity = 0;
  942.             this._lines = [];
  943.             this._methods = [];
  944.             this._waitCount = 0;
  945.             this._waitMode = '';
  946.             this._baseLineStack = [];
  947.             this._spriteset = null;
  948.             this.createBackBitmap();
  949.             this.createBackSprite();
  950.             this.refresh();
  951.         };
  952.  
  953.         //Correcting a minor mistake in the backdrop of the log window.
  954.         //It works fine for the default position, but not for different positions like we use:
  955.         Window_BattleLog.prototype.createBackSprite = function() {
  956.             this._backSprite = new Sprite();
  957.             this._backSprite.bitmap = this._backBitmap;
  958.             this._backSprite.y = 0;
  959.             this.addChildToBack(this._backSprite);
  960.         };
  961.  
  962.         //Resize item and skill window if we want to:
  963.         if (resize_skill_window === 1)
  964.         {
  965.             Window_Help.prototype.initialize = function(numLines) {
  966.                 var width = Graphics.boxWidth;
  967.                 var height = this.fittingHeight(numLines || 2);
  968.                 var y = ($gameParty.inBattle()) ? ctb_window_height : 0;
  969.                 Window_Base.prototype.initialize.call(this, 0, y, width, height);
  970.                 this._text = '';
  971.             };
  972.  
  973.             _alias_scenebattle_createdisplayobjects = Scene_Battle.prototype.createDisplayObjects;
  974.             Scene_Battle.prototype.createDisplayObjects = function() {
  975.                 $gameParty._inBattle = true; //Otherwise the party wouldn't still be consided in battle when we check for the help window
  976.                 _alias_scenebattle_createdisplayobjects.call(this);
  977.             };
  978.         }
  979.  
  980.         //We need to modify the Select method of the BattleSkill and BattleItem windows so that they may predict ATB changes:
  981.         Window_BattleSkill.prototype.select = function(index) {
  982.             Window_SkillList.prototype.select.call(this, index);
  983.             this.predictChanges(this.item());
  984.         };
  985.  
  986.         //Same for BattleItem
  987.         Window_BattleItem.prototype.select = function(index) {
  988.             Window_ItemList.prototype.select.call(this, index);
  989.             this.predictChanges(this.item());
  990.         };
  991.  
  992.         //For the enemy selecting window, we also need to get our action. Same for actor selecting one later.
  993.         _alias_battle_enemy = Window_BattleEnemy.prototype.select;
  994.         Window_BattleEnemy.prototype.select = function(index) {
  995.             _alias_battle_enemy.call(this, index);
  996.             var action = BattleManager.inputtingAction();
  997.             var item = (action === null) ? null : action.item();
  998.             this.predictChanges(item, this.enemy());
  999.         };
  1000.  
  1001.         //And for actors
  1002.         _alias_battle_actor = Window_BattleActor.prototype.select;
  1003.         Window_BattleActor.prototype.select = function(index) {
  1004.             _alias_battle_actor.call(this, index);
  1005.             var action = BattleManager.inputtingAction();
  1006.             var item = (action === null) ? null : action.item();
  1007.             this.predictChanges(item, this.actor());
  1008.         };
  1009.  
  1010.         //Affects prediction based on selectable option
  1011.         Window_Selectable.prototype.predictChanges = function(item, target) {
  1012.             if (item === null || typeof item === 'undefined' || !$gameParty.inBattle())
  1013.             {
  1014.                 return;
  1015.             }
  1016.             var a = BattleManager._subject;
  1017.             if (typeof target !== 'undefined' && target !== null)
  1018.             {
  1019.                 var b = target;
  1020.             }
  1021.             else if (item.scope === 11)
  1022.             {
  1023.                 var b = a;
  1024.             }
  1025.             else if ([7, 8, 9, 10].contains(item.scope))
  1026.             {
  1027.                 var b = $gameParty.smoothTarget();
  1028.             }
  1029.             else
  1030.             {
  1031.                 var b = $gameTroop.smoothTarget();
  1032.             }
  1033.             var v = $gameVariables._data;
  1034.             var selfATB = (typeof item.meta.self_atb !== 'undefined') ? Number(eval(item.meta.self_atb) || 0) : 0;
  1035.             var targetATB = (typeof item.meta.target_atb !== 'undefined') ? Number(eval(item.meta.target_atb) || 0) : 0;
  1036.             var castingTime = (typeof item.meta.cast_time !== 'undefined') ? Number(eval(item.meta.cast_time) || 0) : 0;
  1037.             var battlersAffected = [];
  1038.             var values = [];
  1039.             var battlerCasting = a;
  1040.             if (selfATB !== 0)
  1041.             {
  1042.                 battlersAffected.push(a);
  1043.                 values.push(selfATB);
  1044.             }
  1045.             if (targetATB !== 0)
  1046.             {
  1047.                 if (typeof target !== 'undefined' && target !== null)
  1048.                 {
  1049.                     battlersAffected.push(target);
  1050.                     values.push(targetATB);
  1051.                 }
  1052.                 else if ([1, 3, 7].contains(item.scope))
  1053.                 {
  1054.                     //Still hasen't clicked the single target skill
  1055.                 }
  1056.                 else if ([2, 4, 5, 6].contains(item.scope))
  1057.                 {
  1058.                     $gameTroop.aliveMembers().forEach(function(enemy) {
  1059.                         battlersAffected.push(enemy);
  1060.                         values.push;
  1061.                     }, this);
  1062.                 }
  1063.                 else if (item.scope === 8)
  1064.                 {
  1065.                     $gameParty.aliveMembers().forEach(function(ally) {
  1066.                         battlersAffected.push(ally);
  1067.                         values.push;
  1068.                     }, this);
  1069.                 }
  1070.                 else if (item.scope === 10)
  1071.                 {
  1072.                     $gameParty.deadMembers().forEach(function(ally) {
  1073.                         battlersAffected.push(ally);
  1074.                         values.push;
  1075.                     }, this);
  1076.                 }
  1077.             }
  1078.             BattleManager.predictTurnOrder(battlersAffected, values, battlerCasting, castingTime);
  1079.         };
  1080.  
  1081.         //Reload Turn Order Predction when we cancel windows:
  1082.         _alias_skill_cancel = Scene_Battle.prototype.onSkillCancel;
  1083.         Scene_Battle.prototype.onSkillCancel = function() {
  1084.             BattleManager.predictTurnOrder();
  1085.             _alias_skill_cancel.call(this);
  1086.         };
  1087.         _alias_item_cancel = Scene_Battle.prototype.onItemCancel;
  1088.         Scene_Battle.prototype.onItemCancel = function() {
  1089.             BattleManager.predictTurnOrder();
  1090.             _alias_item_cancel.call(this);
  1091.         };
  1092.         _alias_enemy_cancel = Scene_Battle.prototype.onEnemyCancel;
  1093.         Scene_Battle.prototype.onEnemyCancel = function() {
  1094.             BattleManager.predictTurnOrder();
  1095.             _alias_enemy_cancel.call(this);
  1096.         };
  1097.  
  1098.         //We will add some new windows to Scene Battle:
  1099.         //We will have an array of Turn Order windows.
  1100.         _Scene_Battle_prototype_createAllWindows = Scene_Battle.prototype.createAllWindows;
  1101.         Scene_Battle.prototype.createAllWindows = function() {
  1102.             this._turnOrderWindows = [];
  1103.             var diff = Math.round((ctb_opacity_first - ctb_opacity_last) / (turns_to_predict - 1));
  1104.             var opacity = (invert_turn_order_display !== 1) ? ctb_opacity_first : ctb_opacity_last;
  1105.             for (index = 0; index < turns_to_predict; index++)
  1106.             {
  1107.                 this._turnOrderWindows.push(new Window_CTB(ctb_window_x_offset + index * ctb_window_width, opacity));
  1108.                 this.addWindow(this._turnOrderWindows[index]);
  1109.                 opacity = (invert_turn_order_display !== 1) ? opacity - diff : opacity + diff;
  1110.             }
  1111.             BattleManager.setCTBWindowsArray(this._turnOrderWindows);
  1112.             _Scene_Battle_prototype_createAllWindows.call(this);
  1113.         };
  1114.  
  1115.         //Create a new Window for turn order (there will be an array of those)
  1116.         function Window_CTB() {
  1117.             this.initialize.apply(this, arguments);
  1118.         }
  1119.  
  1120.         Window_CTB.prototype = Object.create(Window_Base.prototype);
  1121.         Window_CTB.prototype.constructor = Window_CTB;
  1122.  
  1123.         Window_CTB.prototype.initialize = function(x, opacity) {
  1124.             Window_Base.prototype.initialize.call(this, x, 0, ctb_window_width, ctb_window_height);
  1125.             this.contents.paintOpacity = opacity;
  1126.             this.contentsWidth = function() {
  1127.                 return this.width - this.padding * 2;
  1128.             };
  1129.             this.contentsHeight = function() {
  1130.                 return this.height - this.padding * 2;
  1131.             };
  1132.             if (display_as_faces_or_names === 1)
  1133.             {
  1134.                 this.layoutForFace();
  1135.             }
  1136.             else
  1137.             {
  1138.                 this.layoutForText();
  1139.             }
  1140.         };
  1141.  
  1142.         //Window layout for face:
  1143.         Window_CTB.prototype.layoutForFace = function() {
  1144.             this.padding = 2;
  1145.             this.opacity = 0;
  1146.             this.hideBackgroundDimmer();
  1147.             this.layoutApply();
  1148.         };
  1149.  
  1150.         //Window layout for text:
  1151.         Window_CTB.prototype.layoutForText = function() {
  1152.             this.padding = 12;
  1153.             this.layoutApply();
  1154.         };
  1155.  
  1156.         //Window layout apply:
  1157.         Window_CTB.prototype.layoutApply = function() {
  1158.             var opacity = this.contents.paintOpacity;
  1159.             this.createContents();
  1160.             this.resetTextColor();
  1161.             this.contents.fontSize = 12;
  1162.             this.contents.paintOpacity = opacity;
  1163.         };
  1164.  
  1165.  
  1166.         //We need to be able to assign a reference to the array of CTB windows to the Battle Manager, so that it can populate it.
  1167.         BattleManager.setCTBWindowsArray = function(ctbWindowsArray) {
  1168.             this._ctbWindowsArray = ctbWindowsArray;
  1169.         };
  1170.  
  1171.         //The function that displays turn order:
  1172.         BattleManager.displayTurnOrder = function() {
  1173.             var predictedTurnOrder = this._predictedTurnOrder;
  1174.             var symbols = this._predictedTurnSymbols;
  1175.             if (invert_turn_order_display === 1)
  1176.             {
  1177.                 predictedTurnOrder.reverse();
  1178.             }
  1179.             if (typeof this._ctbWindowsArray === 'undefined' || this._ctbWindowsArray.constructor !== Array)
  1180.             {
  1181.                 return;
  1182.             }
  1183.             for (index = 0; index < predictedTurnOrder.length; index++)
  1184.             {
  1185.                 if (index >= this._ctbWindowsArray.length)
  1186.                 {
  1187.                     break;
  1188.                 }
  1189.                 var ctbWindow = this._ctbWindowsArray[index];
  1190.                 ctbWindow.resetTextColor();
  1191.                 ctbWindow.contents.fontSize = 12;
  1192.                 var battler = predictedTurnOrder[index];
  1193.  
  1194.                 //Case text:
  1195.                 if (display_as_faces_or_names !== 1)
  1196.                 {
  1197.                     var nameToDisplay = battler.isActor() ? battler._name : battler.originalName() + " " + battler._letter;
  1198.                     ctbWindow.contents.clear();
  1199.                     ctbWindow.drawText(nameToDisplay, 0, 0, ctb_window_width);
  1200.                 }
  1201.                 //Faces:
  1202.                 else
  1203.                 {
  1204.                     ctbWindow.contents.clear();
  1205.                     //For actors, we can just draw faces easily:
  1206.                     if (battler.isActor())
  1207.                     {
  1208.                         ImageManager.loadFace(battler.faceName());
  1209.                         ctbWindow.layoutForFace();
  1210.                         ctbWindow.drawActorFace(battler, 0, 0, ctb_window_width, ctb_window_height);
  1211.                     }
  1212.                     //For enemies, we need to check if they have a face set up
  1213.                     else if (battler.getFaceName() !== false && battler.getFaceID() !== false)
  1214.                     {
  1215.                         ImageManager.loadFace(battler.getFaceName());
  1216.                         ctbWindow.layoutForFace();
  1217.                         ctbWindow.drawFace(battler.getFaceName(), battler.getFaceID(), 0, 0, ctb_window_width, ctb_window_height);
  1218.                         ctbWindow.drawText(battler._letter, ctb_window_width / 2, 0, ctb_window_width);
  1219.                     }
  1220.                     //If they don't, display text:
  1221.                     else
  1222.                     {
  1223.                         ctbWindow.layoutForText();
  1224.                         var nameToDisplay = battler.originalName() + " " + battler._letter;
  1225.                         ctbWindow.drawText(nameToDisplay, 0, 0, ctb_window_width);
  1226.                     }
  1227.                 }
  1228.                 if (typeof symbols[index] !== 'undefined' && symbols[index] !== null && symbols[index] !== false && symbols[index] !== "")
  1229.                 {
  1230.  
  1231.                     if (symbols[index] === ctb_bonus)
  1232.                     {
  1233.                         ctbWindow.contents.textColor = ctb_bonus_color;
  1234.                     }
  1235.                     else if (symbols[index] === ctb_malus)
  1236.                     {
  1237.                         ctbWindow.contents.textColor = ctb_malus_color;
  1238.                     }
  1239.                     else if (symbols[index] === ctb_cast)
  1240.                     {
  1241.                         ctbWindow.contents.textColor = ctb_cast_color;
  1242.                     }
  1243.                     if (display_as_faces_or_names !== 1)
  1244.                     {
  1245.                         ctbWindow.contents.fontSize = 16;
  1246.                         var y = ctb_window_height / 5;
  1247.                     }
  1248.                     else
  1249.                     {
  1250.                         ctbWindow.contents.fontSize = 24;
  1251.                         var y = ctb_window_height / 2;
  1252.                     }
  1253.                     ctbWindow.drawText(symbols[index], 0, y, ctb_window_width);
  1254.                 }
  1255.             }
  1256.         };
  1257.     } //End of turn-order-display dependent stuff.
  1258.  
  1259.     //Play Sound Effect when ATB bar is full, if enabled:
  1260.     AudioManager.playFullATB = function(actor) {
  1261.         if (se_enabled !== 1)
  1262.         {
  1263.             return;
  1264.         }
  1265.         var se = {name: actor.getSEName(), volume: actor.getSEVolume(), pitch: actor.getSEPitch(), pan: actor.getSEPan()};
  1266.         AudioManager.playStaticSe(se);
  1267.     };
  1268.  
  1269.     //Get data related to Actor-specific sound, if it exists:
  1270.     Game_Actor.prototype.getSEName = function() {
  1271.         if (typeof $dataActors[this._actorId].meta.se_name !== 'undefined')
  1272.         {
  1273.             return $dataActors[this._actorId].meta.se_name;
  1274.         }
  1275.         return se_name;
  1276.     };
  1277.     Game_Actor.prototype.getSEVolume = function() {
  1278.         if (typeof $dataActors[this._actorId].meta.se_volume !== 'undefined')
  1279.         {
  1280.             return $dataActors[this._actorId].meta.se_volume;
  1281.         }
  1282.         return se_volume;
  1283.     };
  1284.     Game_Actor.prototype.getSEPitch = function() {
  1285.         if (typeof $dataActors[this._actorId].meta.se_pitch !== 'undefined')
  1286.         {
  1287.             return $dataActors[this._actorId].meta.se_pitch;
  1288.         }
  1289.         return se_pitch;
  1290.     };
  1291.     Game_Actor.prototype.getSEPan = function() {
  1292.         if (typeof $dataActors[this._actorId].meta.se_pan !== 'undefined')
  1293.         {
  1294.             return $dataActors[this._actorId].meta.se_pan;
  1295.         }
  1296.         return se_pan;
  1297.     };
  1298.     //End of Sound Effect related stuff
  1299.  
  1300.     //Cast motion
  1301.     Game_Battler.prototype.performCastMotion = function() {
  1302.         if (this.target_cast_atb > 0 && defaultCastMotion() !== false && BattleManager.actor() !== this && BattleManager._subject !== this)
  1303.         {
  1304.             if (this.casting_action !== null && typeof this.casting_action.item() !== 'undefined' && typeof this.casting_action.item().meta !== 'undefined' && typeof this.casting_action.item().meta.cast_motion !== 'undefined')
  1305.             {
  1306.                 this.requestMotion(this.casting_action.item().meta.cast_motion);
  1307.             }
  1308.             else
  1309.             {
  1310.                 this.requestMotion(defaultCastMotion());
  1311.             }
  1312.         }
  1313.     };
  1314.  
  1315.     //Ask cast motion for all:
  1316.     BattleManager.requestAllCastMotions = function() {
  1317.         this.aliveBattleMembers().forEach(function(battler) {
  1318.             battler.performCastMotion();
  1319.         });
  1320.     };
  1321.  
  1322.     _alias_sb_updateBattleProcess = Scene_Battle.prototype.updateBattleProcess;
  1323.     Scene_Battle.prototype.updateBattleProcess = function() {
  1324.         if (!BattleManager.isBattleEnd() && !BattleManager.isAborting())
  1325.         {
  1326.             BattleManager.requestAllCastMotions();
  1327.         }
  1328.         _alias_sb_updateBattleProcess.call(this);
  1329.     };
  1330.  
  1331.     defaultCastMotion = function() {
  1332.         switch (default_cast_motion)
  1333.         {
  1334.             case 1:
  1335.                 return 'chant';
  1336.             case 2:
  1337.                 return 'skill';
  1338.             case 3:
  1339.                 return 'item';
  1340.             case 4:
  1341.                 return 'spell';
  1342.             default:
  1343.                 return false;
  1344.         }
  1345.     };
  1346.  
  1347.     //==================================================
  1348.     // SYSTEM
  1349.     //==================================================
  1350.  
  1351.     //Let's add a new property for battlers, called "atb", and two properties for the casting time system:
  1352.     Object.defineProperties(Game_BattlerBase.prototype, {
  1353.         atb: {
  1354.             writable: true,
  1355.             value: 0,
  1356.             configurable: true,
  1357.             enumerable: true
  1358.         },
  1359.         target_cast_atb: {
  1360.             writable: true,
  1361.             value: 0,
  1362.             configurable: true,
  1363.             enumerable: true
  1364.         },
  1365.         current_cast_atb: {
  1366.             writable: true,
  1367.             value: 0,
  1368.             configurable: true,
  1369.             enumerable: true
  1370.         },
  1371.         casting_action: {
  1372.             writable: true,
  1373.             value: null,
  1374.             configurable: true,
  1375.             enumerable: true
  1376.         },
  1377.         finished_casting: {
  1378.             writable: true,
  1379.             value: false,
  1380.             configurable: true,
  1381.             enumerable: true
  1382.         },
  1383.         cast_delay_current: {
  1384.             writable: true,
  1385.             value: 0,
  1386.             configurable: true,
  1387.             enumerable: true
  1388.         },
  1389.         cast_delay_max: {
  1390.             writable: true,
  1391.             value: 0,
  1392.             configurable: true,
  1393.             enumerable: true
  1394.         },
  1395.         _cast_rate: {
  1396.             writable: true,
  1397.             value: 0,
  1398.             configurable: true,
  1399.             enumerable: true
  1400.         },
  1401.         _states_atb_current: {
  1402.             writable: true,
  1403.             value: [],
  1404.             configurable: true,
  1405.             enumerable: true
  1406.         },
  1407.         _states_atb_duration: {
  1408.             writable: true,
  1409.             value: [],
  1410.             configurable: true,
  1411.             enumerable: true
  1412.         },
  1413.         _states_atb_rate: {
  1414.             writable: true,
  1415.             value: [],
  1416.             configurable: true,
  1417.             enumerable: true
  1418.         },
  1419.         _haste_all: {
  1420.             writable: true,
  1421.             value: 100,
  1422.             configurable: true,
  1423.             enumerable: true
  1424.         },
  1425.         _haste_atb: {
  1426.             writable: true,
  1427.             value: 100,
  1428.             configurable: true,
  1429.             enumerable: true
  1430.         },
  1431.         _haste_cast: {
  1432.             writable: true,
  1433.             value: 100,
  1434.             configurable: true,
  1435.             enumerable: true
  1436.         }
  1437.     });
  1438.  
  1439.     //A generic function for determining if there's bonus ATB rate to be had (used in class, item and enemy check)
  1440.     CheckForBonusStartingATB = function(item) {
  1441.         if (typeof item !== 'undefined' && item !== null && typeof item.meta !== 'undefined' && typeof item.meta.start_atb !== 'undefined' && !isNaN(item.meta.start_atb))
  1442.         {
  1443.             return Number(item.meta.start_atb);
  1444.         }
  1445.         return 0;
  1446.     };
  1447.  
  1448.     //A generic function to calculate ATB rate, used both by battlers and turn timer:
  1449.     CalculateATBRate = function(agi, haste) {
  1450.         if (typeof haste === 'undefined')
  1451.         {
  1452.             var haste = 100;
  1453.         }
  1454.         return (base_atb_increase + agi * (agi_weight / 100)) * haste / 100;
  1455.     };
  1456.  
  1457.     //Checks class, equips and self for bonus starting ATB:
  1458.     Game_Battler.prototype.bonusStartingATB = function()
  1459.     {
  1460.         var bonus = 0;
  1461.         if (this.isActor())
  1462.         {
  1463.             bonus += CheckForBonusStartingATB(this.actor());
  1464.             bonus += CheckForBonusStartingATB(this.currentClass());
  1465.             this.equips().forEach(function(equip)
  1466.             {
  1467.                 bonus += CheckForBonusStartingATB(equip);
  1468.             }, this);
  1469.         }
  1470.         else
  1471.         {
  1472.             bonus += CheckForBonusStartingATB(this.enemy());
  1473.         }
  1474.         return bonus;
  1475.     };
  1476.  
  1477.     //A method to reset all cast related stuff:
  1478.     Game_Battler.prototype.resetCast = function() {
  1479.         this.setActionState('undecided');
  1480.         this.clearMotion();
  1481.         $gameParty.requestMotionRefresh();
  1482.         this.target_cast_atb = 0;
  1483.         this.current_cast_atb = 0;
  1484.         this.casting_action = null;
  1485.         this.finished_casting = false;
  1486.         this.cast_delay_current = 0;
  1487.         this.cast_delay_max = 0;
  1488.         this.calculateCastRate();
  1489.     };
  1490.  
  1491.     //And one to start cast:
  1492.     Game_Battler.prototype.startCast = function(castAction, castTime) {
  1493.         this.casting_action = castAction;
  1494.         this.target_cast_atb = castTime;
  1495.         this.current_cast_atb = 0;
  1496.         this.cast_delay_max = 0;
  1497.         this.calculateCastRate();
  1498.         if (this.IsCastDelayable())
  1499.         {
  1500.             this.cast_delay_max = this.target_cast_atb * max_delay_pct / 100;
  1501.         }
  1502.         if (this.casting_action !== null && typeof this.casting_action.item() !== 'undefined' && typeof this.casting_action.item().meta !== 'undefined' && typeof this.casting_action.item().meta.cast_animation !== 'undefined')
  1503.         {
  1504.             this.startAnimation(Number(this.casting_action.item().meta.cast_animation), 0, 0);
  1505.         }
  1506.         else if (default_cast_vfx > 0)
  1507.         {
  1508.             this.startAnimation(default_cast_vfx, 0, 0);
  1509.         }
  1510.     };
  1511.  
  1512.     //Our battlers need a property to calculate their ATB rate
  1513.     Game_Battler.prototype.calculateATBRate = function() {
  1514.         return CalculateATBRate(this.agi, this.ATBHaste());
  1515.     };
  1516.  
  1517.     //Haste for ATB:
  1518.     Game_Battler.prototype.ATBHaste = function() {
  1519.         return this._haste_atb * this._haste_all / 100;
  1520.     };
  1521.  
  1522.     //Haste for Cast:
  1523.     Game_Battler.prototype.CastHaste = function() {
  1524.         return this._haste_cast * this._haste_all / 100;
  1525.     };
  1526.  
  1527.     //At the start of battle, ATB values are reset to 0:
  1528.     _Game_Battler_prototype_onBattleStart = Game_Battler.prototype.onBattleStart;
  1529.     Game_Battler.prototype.onBattleStart = function() {
  1530.         this.resetCast();
  1531.         this._states_atb_current = [];
  1532.         this._states_atb_duration = [];
  1533.         this._states_atb_rate = [];
  1534.         this.CalculateHaste();
  1535.         this.atb = this.bonusStartingATB() + (Math.random() * starting_atb_random) + starting_atb * this.agi * (agi_weight / 100);
  1536.         if (BattleManager._surprise && this.isEnemy() && this.isAppeared())
  1537.         {
  1538.             this.atb += full_atb;
  1539.         }
  1540.         else if (BattleManager._preemptive && this.isActor())
  1541.         {
  1542.             this.atb += full_atb;
  1543.         }
  1544.         _Game_Battler_prototype_onBattleStart.call(this);
  1545.     };
  1546.  
  1547.     //Battle starts in the new phase "atb" (except if we're going to show PartyCommand).
  1548.     //And we calculate the Turn Timer if we're using Average Turn Timer
  1549.     _BattleManager_startBattle = BattleManager.startBattle;
  1550.     BattleManager.startBattle = function() {
  1551.         if (av_turn_timer === 1)
  1552.         {
  1553.             var totalAgi = 0;
  1554.             var numberOfBattlers = this.allBattleMembers().length;
  1555.             for (index = 0; index < numberOfBattlers; index++)
  1556.             {
  1557.                 totalAgi += Number(this.allBattleMembers()[index].agi || 1);
  1558.             }
  1559.             turn_timer = totalAgi / numberOfBattlers;
  1560.         }
  1561.         _BattleManager_startBattle.call(this);
  1562.         $gameParty.makeActions();
  1563.         $gameTroop.makeActions();
  1564.         this.makeActionOrders();
  1565.         this.predictTurnOrder();
  1566.         this._phase = 'start';
  1567.         this._actorIndex = -1;
  1568.         this._pending_atb_removal = false;
  1569.     };
  1570.  
  1571.     //Skip party command if the player so wishes:
  1572.     if (display_party_command !== 1)
  1573.     {
  1574.         Scene_Battle.prototype.startPartyCommandSelection = function() {
  1575.             this.refreshStatus();
  1576.             this.commandFight();
  1577.         };
  1578.     }
  1579.  
  1580.     //Change the end of turn:
  1581.     BattleManager.updateTurnEnd = function() {
  1582.         $gameParty.makeActions();
  1583.         $gameTroop.makeActions();
  1584.         this._phase = 'atb';
  1585.     };
  1586.  
  1587.     //Changing the flow of battle
  1588.     _BattleManager_update = BattleManager.update;
  1589.     BattleManager.update = function() {
  1590.         if (!this.isBusy() && !this.updateEvent())
  1591.         {
  1592.             switch (this._phase)
  1593.             {
  1594.                 case 'atb':
  1595.                     this.increaseAtbGauges();
  1596.                     break;
  1597.                 default:
  1598.                     _BattleManager_update.call(this);
  1599.                     break;
  1600.             }
  1601.         }
  1602.     };
  1603.  
  1604.     //Increases the ATB gauges when idle:
  1605.     BattleManager.increaseAtbGauges = function() {
  1606.         var loopForInstantATB = instant_atb;
  1607.         var oneATBFilledAlready = false;
  1608.         //================================================
  1609.         //ATB LOOP
  1610.         //We need to be in a loop here if we're using instant ATB option, but run only once in other cases.
  1611.         //================================================
  1612.         do
  1613.         {
  1614.             //==========================================
  1615.             //Turn Timer
  1616.             //==========================================
  1617.             turn_atb += CalculateATBRate(turn_timer);
  1618.             //Turn timer finished:
  1619.             if (turn_atb >= full_atb)
  1620.             {
  1621.                 turn_atb -= full_atb;
  1622.                 //We advance the troops page (for events and AI) depending on parameter:
  1623.                 if (battle_event_turn_mode === 0)
  1624.                 {
  1625.                     $gameTroop.increaseTurn();
  1626.                 }
  1627.                 //We apply onTurnEnd if paramaters are set so
  1628.                 if (battler_end_turn_effects !== 1)
  1629.                 {
  1630.                     this.allBattleMembers().forEach(function(battler)
  1631.                     {
  1632.                         battler.onTurnEnd();
  1633.                         this.refreshStatus();
  1634.                         this._logWindow.displayAutoAffectedStatus(battler);
  1635.                         this._logWindow.displayRegeneration(battler);
  1636.                     }, this);
  1637.                 }
  1638.             }
  1639.             //========================================
  1640.             //End of turn timer related stuff
  1641.             //========================================
  1642.  
  1643.             this.allBattleMembers().forEach(function(battler)
  1644.             {
  1645.                 //States with ATB duration:
  1646.                 battler._states_atb_duration.forEach(function(duration, stateID)
  1647.                 {
  1648.                     battler._states_atb_current[stateID] += CalculateATBRate(battler._states_atb_rate[stateID], 100);
  1649.                     if (battler._states_atb_current[stateID] >= duration)
  1650.                     {
  1651.                         battler.removeState(stateID);
  1652.                     }
  1653.                 }, this);
  1654.  
  1655.                 //Dead battler has no ATB nor cast:
  1656.                 if (battler.isDead())
  1657.                 {
  1658.                     battler.atb = 0;
  1659.                     battler.resetCast();
  1660.                 }
  1661.                 //====================
  1662.                 //Casting time logic:
  1663.                 //====================
  1664.                 //Cast finished:
  1665.                 else if (battler.finished_casting === true)
  1666.                 {
  1667.                     battler.resetCast();
  1668.                 }
  1669.                 //Currently casting:
  1670.                 else if (battler.target_cast_atb > 0)
  1671.                 {
  1672.                     //Got stunned or similar while casting, auto-interrupt for now:
  1673.                     if (!battler.canMove())
  1674.                     {
  1675.                         battler.BreakCurrentCast(true);
  1676.                     }
  1677.                     else
  1678.                     {
  1679.                         battler.current_cast_atb += battler._cast_rate * (battler.CastHaste() / 100);
  1680.                         if (battler.current_cast_atb >= battler.target_cast_atb && oneATBFilledAlready === false)
  1681.                         {
  1682.                             battler.finished_casting = true;
  1683.                             this.battlerHasFullAtb(battler, true);
  1684.                             oneATBFilledAlready = true;
  1685.                             loopForInstantATB = 0;
  1686.                         }
  1687.                     }
  1688.                 }
  1689.                 //===================
  1690.                 //Not casting, ATB INCREASE:
  1691.                 //===================
  1692.                 else
  1693.                 {
  1694.                     battler.atb += battler.calculateATBRate();
  1695.                 }
  1696.                 if (battler.atb >= full_atb && oneATBFilledAlready === false && battler.target_cast_atb <= 0)
  1697.                 {
  1698.                     this.battlerHasFullAtb(battler);
  1699.                     oneATBFilledAlready = true;
  1700.                     loopForInstantATB = 0;
  1701.                 }
  1702.             }, this);
  1703.         } while (loopForInstantATB === 1);
  1704.         //==============================
  1705.         //END OF THE ATB LOOP
  1706.         //=============================
  1707.         this.refreshStatus();
  1708.     };
  1709.  
  1710.     //When a Battler (might be party or enemy) has full ATB:
  1711.     BattleManager.battlerHasFullAtb = function(battler, wasCasting)
  1712.     {
  1713.         BattleManager.refreshStatus();
  1714.         if (typeof wasCasting === 'undefined')
  1715.         {
  1716.             wasCasting = false;
  1717.         }
  1718.         this.predictTurnOrder();
  1719.         this._subject = battler;
  1720.         this._turn_end_subject = battler;
  1721.         this._pending_atb_removal = true;
  1722.         //If the character already has an action that he was casting:
  1723.         if (wasCasting)
  1724.         {
  1725.             battler.setAction(0, battler.casting_action);
  1726.             this._phase = 'turn';
  1727.             return;
  1728.         }
  1729.         if (battler.isActor())
  1730.         {
  1731.             battler.makeActions();
  1732.             if (battler.canInput())
  1733.             {
  1734.                 AudioManager.playFullATB(battler);
  1735.                 this._actorIndex = battler.index();
  1736.                 //If the Step_Forward_When_Ready parameter is turned on:
  1737.                 if (step_forward === 1)
  1738.                 {
  1739.                     battler.setActionState('inputting');
  1740.                     if (typeof battler.spriteStepForward === 'function')
  1741.                     {
  1742.                         //This is for compatibility with Yanfly's.
  1743.                         battler.spriteStepForward();
  1744.                     }
  1745.                 }
  1746.                 this._phase = 'input';
  1747.             }
  1748.             else
  1749.             {
  1750.                 this._phase = 'turn';
  1751.             }
  1752.         }
  1753.         else if (battler.isEnemy())
  1754.         {
  1755.             battler.makeActions();
  1756.             if (battler.CheckIfSkillHasCastingTime())
  1757.             {
  1758.                 this._phase = 'atb';
  1759.             }
  1760.             else
  1761.             {
  1762.                 this._phase = 'turn';
  1763.             }
  1764.         }
  1765.     };
  1766.  
  1767.     //Never jumps to another battler, we will control them individually:
  1768.     BattleManager.getNextSubject = function() {
  1769.         return null;
  1770.     };
  1771.  
  1772.     //Process turn when we finish inputing command
  1773.     BattleManager.selectNextCommand = function() {
  1774.         do {
  1775.             if (!this.actor() || !this.actor().selectNextCommand())
  1776.             {
  1777.                 $gameParty.requestMotionRefresh();
  1778.                 if (this.actor() !== null && this.actor().CheckIfSkillHasCastingTime())
  1779.                 {
  1780.                     this.actor().setActionState('waiting');
  1781.                     if (typeof this.actor().spriteStepBack === 'function')
  1782.                     {
  1783.                         //This is for compatibility with Yanfly's.
  1784.                         this.actor().spriteStepBack();
  1785.                     }
  1786.                     this._phase = 'atb';
  1787.                     break;
  1788.                 }
  1789.                 this._phase = 'turn';
  1790.                 break;
  1791.             }
  1792.         } while (!this.actor().canInput());
  1793.     };
  1794.  
  1795.     //Don't let us jump to another character by cancelling.
  1796.     BattleManager.selectPreviousCommand = function() {
  1797.         do {
  1798.             if (!this.actor() || !this.actor().selectPreviousCommand()) {
  1799.                 if (allow_midbattle_escape === 1)
  1800.                 {
  1801.                     this.changeActor(-1, 'undecided');
  1802.                 }
  1803.                 return;
  1804.             }
  1805.         } while (!this.actor().canInput());
  1806.     };
  1807.  
  1808.     //We need to change the OnTurnEnd method, because otherwise it will apply to all battlers whenever anyone acts:
  1809.     BattleManager.endTurn = function() {
  1810.         this._phase = 'turnEnd';
  1811.         this._preemptive = false;
  1812.         this._surprise = false;
  1813.         this.predictTurnOrder();
  1814.         this.clearActor();
  1815.         if (battle_event_turn_mode !== 0)
  1816.         {
  1817.             $gameTroop.increaseTurn();
  1818.         }
  1819.     };
  1820.  
  1821.  
  1822.     //Remove the ATB value when a turn is processed:
  1823.     _BattleManager_processTurn = BattleManager.processTurn;
  1824.     BattleManager.processTurn = function() {
  1825.         if (this._pending_atb_removal === true)
  1826.         {
  1827.             this._subject.atb -= full_atb;
  1828.             this._pending_atb_removal = false;
  1829.         }
  1830.         _BattleManager_processTurn.call(this);
  1831.  
  1832.     };
  1833.  
  1834.     //We need a function that only gets alive battle members
  1835.     BattleManager.aliveBattleMembers = function()
  1836.     {
  1837.         var allAlive = [];
  1838.         this.allBattleMembers().forEach(function(battler)
  1839.         {
  1840.             if (!battler.isDead() && !battler.isHidden())
  1841.             {
  1842.                 allAlive.push(battler);
  1843.             }
  1844.         }, this);
  1845.         return allAlive;
  1846.     };
  1847.  
  1848.     //We'll need a function to predict the turn order for the next few turns, in case the developer wants to display this:
  1849.     BattleManager.predictTurnOrder = function(battlersToApplyModifiersTo, modifiersValues, battlerCasting, castingTime)
  1850.     {
  1851.         if (display_turn_order !== 1)
  1852.         {
  1853.             return null;
  1854.         }
  1855.         if (typeof battlersToApplyModifiersTo === 'undefined')
  1856.         {
  1857.             battlersToApplyModifiersTo = [];
  1858.         }
  1859.         if (typeof modifiersValues === 'undefined')
  1860.         {
  1861.             modifiersValues = [];
  1862.         }
  1863.         if (typeof battlerCasting === 'undefined' || typeof castingTime === 'undefined')
  1864.         {
  1865.             var battlerCasting = null;
  1866.             var castingTime = 0;
  1867.         }
  1868.         var numberOfTurns = turns_to_predict;
  1869.         var mmodifierValue = Number(mmodifierValue) || 0;
  1870.         var arrayOfATBValues = [];
  1871.         var arrayOfCastValues = [];
  1872.         var arrayOfCastingTimes = [];
  1873.         var arrayOfSymbols = [];
  1874.         var predictedTurnOrder = [];
  1875.         var predictedTurnOrderSymbols = [];
  1876.         var validBattlers = this.aliveBattleMembers();
  1877.         var delayedModForActiveActor = 0;
  1878.         var delayedModHasBeenApplied = false;
  1879.         if (numberOfTurns === 0)
  1880.         {
  1881.             return false;
  1882.         }
  1883.         //We cannot work directly on our Battlers for this simulation, or else we would mess their values
  1884.         //So instead we copy the numbers that are necessary, and we use them.
  1885.         validBattlers.forEach(function(battler)
  1886.         {
  1887.             var modIndex = battlersToApplyModifiersTo.indexOf(battler);
  1888.             var modValue = 0;
  1889.             var cast = 0;
  1890.             var symbol = false;
  1891.             if (modIndex >= 0)
  1892.             {
  1893.                 modValue = modifiersValues[modIndex];
  1894.             }
  1895.             //Add the plus, minus or neutral symbol:
  1896.             if (modValue > 0)
  1897.             {
  1898.                 symbol = ctb_bonus;
  1899.             }
  1900.             else if (modValue < 0)
  1901.             {
  1902.                 symbol = ctb_malus;
  1903.             }
  1904.             arrayOfSymbols.push(symbol);
  1905.             //See if it's hovering over a casting skill:
  1906.             if (battlerCasting === battler && castingTime > 0)
  1907.             {
  1908.                 cast += castingTime;
  1909.             }
  1910.             //If the battler is already casting something:
  1911.             cast += battler.target_cast_atb;
  1912.  
  1913.  
  1914.             //Compensate for the full ATB that casting battlers have behind the curtains:
  1915.             if (cast > 0 && battler.atb >= full_atb)
  1916.             {
  1917.                 modValue -= full_atb;
  1918.             }
  1919.             //If we're selecting the action of an actor:
  1920.             if (typeof this.actor() !== 'undefined' && this.actor() === battler)
  1921.             {
  1922.                 arrayOfATBValues.push(battler.atb);
  1923.                 delayedModForActiveActor = modValue;
  1924.             }
  1925.             else
  1926.             {
  1927.                 arrayOfATBValues.push(battler.atb + modValue);
  1928.             }
  1929.             //Add the current cast time as normal:
  1930.             arrayOfCastValues.push(battler.current_cast_atb);
  1931.             //And the target cast time:
  1932.             arrayOfCastingTimes.push(cast);
  1933.         }, this);
  1934.  
  1935.         //Now we simulate until we have enough turns:
  1936.         while (predictedTurnOrder.length < numberOfTurns)
  1937.         {
  1938.             for (index = 0; index < arrayOfATBValues.length; index++)
  1939.             {
  1940.                 var battler = validBattlers[index];
  1941.                 var target_cast = arrayOfCastingTimes[index];
  1942.                 if (typeof this.actor() !== 'undefined' && this.actor() === battler && predictedTurnOrder.length >= 1 && delayedModHasBeenApplied === false)
  1943.                 {
  1944.                     arrayOfATBValues[index] += delayedModForActiveActor;
  1945.                     delayedModHasBeenApplied = true;
  1946.                 }
  1947.  
  1948.                 //If is casting, check by cast time and don't increase virtual atb
  1949.                 if (arrayOfCastValues[index] < target_cast)
  1950.                 {
  1951.                     arrayOfCastValues[index] += battler._cast_rate * (battler.CastHaste() / 100);
  1952.                     if (arrayOfCastValues[index] >= target_cast)
  1953.                     {
  1954.                         predictedTurnOrder.push(battler);
  1955.                         predictedTurnOrderSymbols.push(ctb_cast);
  1956.                     }
  1957.                 }
  1958.                 else
  1959.                 {
  1960.                     arrayOfATBValues[index] += battler.calculateATBRate();
  1961.                     if (arrayOfATBValues[index] >= full_atb)
  1962.                     {
  1963.                         arrayOfATBValues[index] -= full_atb;
  1964.                         predictedTurnOrder.push(battler);
  1965.                         predictedTurnOrderSymbols.push(arrayOfSymbols[index]);
  1966.                     }
  1967.                 }
  1968.             }
  1969.         }
  1970.         predictedTurnOrder = predictedTurnOrder.slice(0, numberOfTurns);
  1971.         //Let's show them in our CTB Windows, if they are being used:
  1972.         this._predictedTurnOrder = predictedTurnOrder;
  1973.         this._predictedTurnSymbols = predictedTurnOrderSymbols;
  1974.         this.displayTurnOrder();
  1975.     };
  1976.  
  1977.     //At the end of Turns Timers, we only reduce the duration of states set to Turn End:
  1978.     _Game_Battler_onTurnEnd = Game_Battler.prototype.onTurnEnd;
  1979.     Game_Battler.prototype.onTurnEnd = function() {
  1980.         this.updateStateTurns(2);
  1981.         _Game_Battler_onTurnEnd.call(this);
  1982.     };
  1983.  
  1984.     //Because we now reduce the duration of states set to Action End on the end of actions (after, not before, checking for removal of previous one):
  1985.     _Game_Battler_On_AllActionsEnd = Game_Battler.prototype.onAllActionsEnd;
  1986.     Game_Battler.prototype.onAllActionsEnd = function() {
  1987.         this.updateStateTurns(1);
  1988.         //We apply end of turn stuff if paramaters are set so
  1989.         if (battler_end_turn_effects === 1)
  1990.         {
  1991.             this.onTurnEnd();
  1992.             BattleManager.refreshStatus();
  1993.             BattleManager._logWindow.displayAutoAffectedStatus(this);
  1994.             BattleManager._logWindow.displayRegeneration(this);
  1995.         }
  1996.         _Game_Battler_On_AllActionsEnd.call(this);
  1997.     };
  1998.  
  1999.     //This now receives a parameter for timing.
  2000.     Game_BattlerBase.prototype.updateStateTurns = function(timing) {
  2001.         if (typeof timing === 'undefined')
  2002.         {
  2003.             return;
  2004.         }
  2005.         this._states.forEach(function(stateId) {
  2006.             if (this._stateTurns[stateId] > 0 && $dataStates[stateId].autoRemovalTiming === timing) {
  2007.                 this._stateTurns[stateId]--;
  2008.             }
  2009.         }, this);
  2010.     };
  2011.  
  2012.     //Our items need new methods, to retrieve ATB-related data from the Note field
  2013.     //To retrive the <self_atb:> field
  2014.     Game_Item.prototype.selfATB = function() {
  2015.         if (typeof this.object() !== 'undefined' && typeof this.object().meta !== 'undefined' && typeof this.object().meta.self_atb !== 'undefined')
  2016.         {
  2017.             return this.object().meta.self_atb;
  2018.         }
  2019.         return 0;
  2020.     };
  2021.  
  2022.     //And one to retrieve the <target_atb:> field:
  2023.     Game_Item.prototype.targetATB = function() {
  2024.         if (typeof this.object() !== 'undefined' && typeof this.object().meta !== 'undefined' && typeof this.object().meta.target_atb !== 'undefined')
  2025.         {
  2026.             return this.object().meta.target_atb;
  2027.         }
  2028.         return 0;
  2029.     };
  2030.  
  2031.     //A formula to eval this ATB:
  2032.     Game_Action.prototype.evalATBFormula = function(formula, target) {
  2033.         try {
  2034.             var item = this.item();
  2035.             var a = this.subject();
  2036.             var b = target;
  2037.             var v = $gameVariables._data;
  2038.             return Number(eval(formula) || 0);
  2039.         } catch (e) {
  2040.             return 0;
  2041.         }
  2042.     };
  2043.  
  2044.     //When we Apply a Game_Action, we now need to check if it had an ATB bonus, so we can apply it too:
  2045.     //We also check for spellcasting interrupts and delays.
  2046.     _alias_ga_apply = Game_Action.prototype.apply;
  2047.     Game_Action.prototype.apply = function(target) {
  2048.         _alias_ga_apply.call(this, target);
  2049.         //Only on hit
  2050.         if (target.result().isHit())
  2051.         {
  2052.             var self_atb = this.evalATBFormula(this._item.selfATB(), target);
  2053.             var target_atb = this.evalATBFormula(this._item.targetATB(), target);
  2054.             this.subject().atb += self_atb;
  2055.             target.atb += target_atb;
  2056.             //Interrupts and delays:
  2057.             var delay_amount = default_delay_amount;
  2058.             if (typeof this.item() !== 'undefined' && typeof this.item().meta !== 'undefined')
  2059.             {
  2060.                 if (this.item().meta.interrupt || this.item().meta.interrupts)
  2061.                 {
  2062.                     target.BreakCurrentCast();
  2063.                 }
  2064.                 if (typeof this.item().meta.delay_amount !== 'undefined' && !isNaN(Number(this.item().meta.delay_amount)))
  2065.                 {
  2066.                     delay_amount = Number(this.item().meta.delay_amount);
  2067.                 }
  2068.                 //Care to not delay twice.
  2069.                 if ((this.item().meta.delay || this.item().meta.delays) && default_delays !== 1)
  2070.                 {
  2071.                     target.delayCast(delay_amount);
  2072.                 }
  2073.             }
  2074.             if (default_delays === 1 && ((target.isActor() && this.subject().isEnemy()) || (target.isEnemy() && this.subject().isActor())))
  2075.             {
  2076.                 target.delayCast(delay_amount);
  2077.             }
  2078.         }
  2079.     };
  2080.  
  2081.     //Check if a skill item (the database element, not the Game_Object classes) has Casting Time metadata
  2082.     Game_Battler.prototype.CheckIfSkillHasCastingTime = function()
  2083.     {
  2084.         if (typeof this._actions[0] === 'undefined' || this._actions[0] === null)
  2085.         {
  2086.             return false;
  2087.         }
  2088.         var item = this._actions[0].item();
  2089.         if (item === null || typeof item.meta.cast_time === 'undefined')
  2090.         {
  2091.             return false;
  2092.         }
  2093.         var castTime = Number(item.meta.cast_time || 0);
  2094.         if (castTime <= 0)
  2095.         {
  2096.             return false;
  2097.         }
  2098.         this.startCast(this._actions[0], castTime);
  2099.         return true;
  2100.     };
  2101.  
  2102.     //See if current casting skill is delayable
  2103.     Game_Battler.prototype.IsCastDelayable = function()
  2104.     {
  2105.         //Meta overrides default:
  2106.         if (this.casting_action !== null && typeof this.casting_action.item() !== 'undefined' && typeof this.casting_action.item().meta !== 'undefined')
  2107.         {
  2108.             var delayable = this.casting_action.item().meta.delayable;
  2109.             var not_delayable = this.casting_action.item().meta.not_delayable;
  2110.             if (delayable)
  2111.             {
  2112.                 return true;
  2113.             }
  2114.             if (not_delayable)
  2115.             {
  2116.                 return false;
  2117.             }
  2118.         }
  2119.         //If we don't have meta, or have meta but nothing about delay on it, we go for defaults:
  2120.         if (default_delayable === 1)
  2121.         {
  2122.             return true;
  2123.         }
  2124.         return false;
  2125.     };
  2126.  
  2127.     //See if current casting skill is interruptible
  2128.     Game_Battler.prototype.IsCastInterruptible = function()
  2129.     {
  2130.         if (this.casting_action !== null && typeof this.casting_action.item() !== 'undefined' && typeof this.casting_action.item().meta !== 'undefined')
  2131.         {
  2132.             var meta = this.casting_action.item().meta;
  2133.             return (meta.interruptible || meta.interruptable || meta.easily_interruptible || meta.easily_interruptable);
  2134.         }
  2135.         return false;
  2136.     };
  2137.  
  2138.     //Delays current skill cast:
  2139.     Game_Battler.prototype.delayCast = function(delay_amount)
  2140.     {
  2141.         var delay_amount = this.cast_delay_max * delay_amount / 100;
  2142.         if (delay_amount > 0 && this.IsCastDelayable() && this.cast_delay_current < this.cast_delay_max)
  2143.         {
  2144.             this.cast_delay_current += delay_amount;
  2145.             this.current_cast_atb -= delay_amount;
  2146.             if (this.current_cast_atb < 0)
  2147.             {
  2148.                 this.current_cast_atb = 0;
  2149.             }
  2150.         }
  2151.     };
  2152.  
  2153.     //Breaks current skill cast:
  2154.     Game_Battler.prototype.BreakCurrentCast = function(forceBreak)
  2155.     {
  2156.         if (typeof forceBreak !== 'undefined')
  2157.         {
  2158.             var force = true;
  2159.         }
  2160.         if (this.IsCastInterruptible() || force)
  2161.         {
  2162.             this.atb += Math.min(this.current_cast_atb * interrupt_compensation_pct / 100, full_atb * interrupt_compensation_max / 100);
  2163.             this.atb -= full_atb;
  2164.             this.resetCast();
  2165.             if (interrupt_vfx > 0)
  2166.             {
  2167.                 this.startAnimation(interrupt_vfx, 0, 0);
  2168.             }
  2169.         }
  2170.     };
  2171.  
  2172.     //Computes the cast parameter
  2173.     //Haste is not applied here to keep it dynamic. Change this to only set up a state so we can use the calcATBRate on other functions.
  2174.     Game_Battler.prototype.calculateCastRate = function()
  2175.     {
  2176.         var param = "this.";
  2177.         if (this.casting_action !== null && typeof this.casting_action.item() !== 'undefined' && typeof this.casting_action.item().meta !== 'undefined'
  2178.                 && typeof this.casting_action.item().meta.cast_param !== 'undefined' && this.casting_action.item().meta.cast_param !== "")
  2179.         {
  2180.             param += this.casting_action.item().meta.cast_param;
  2181.         }
  2182.         else
  2183.         {
  2184.             param += default_cast_parameter;
  2185.         }
  2186.         if (typeof eval(param) !== 'undefined' && !isNaN(eval(param)))
  2187.         {
  2188.             var cs = Number(eval(param));
  2189.             this._cast_rate = CalculateATBRate(cs, 100);
  2190.         }
  2191.         else
  2192.         {
  2193.             this._cast_rate = CalculateATBRate(0, 100);
  2194.         }
  2195.     };
  2196.  
  2197.     //Checks for Haste when adding a state
  2198.     _alias_gbb_p_addNewState = Game_BattlerBase.prototype.addNewState;
  2199.     Game_BattlerBase.prototype.addNewState = function(stateId)
  2200.     {
  2201.         _alias_gbb_p_addNewState.call(this, stateId);
  2202.         var state = $dataStates[stateId];
  2203.         if (typeof state.meta !== 'undefined')
  2204.         {
  2205.             this.AddHaste(state);
  2206.             if (typeof state.meta.atb_duration !== 'undefined' && !isNaN(state.meta.atb_duration))
  2207.             {
  2208.                 this._states_atb_duration[stateId] = Number(state.meta.atb_duration);
  2209.                 this._states_atb_current[stateId] = 0;
  2210.                 this._states_atb_rate[stateId] = this.StateATBRate(state);
  2211.             }
  2212.         }
  2213.     };
  2214.  
  2215.     //Resets ATB Duration when reseting a state that has one:
  2216.     _alias_gbb_p_resetStateCounts = Game_BattlerBase.prototype.resetStateCounts;
  2217.     Game_BattlerBase.prototype.resetStateCounts = function(stateId)
  2218.     {
  2219.         _alias_gbb_p_resetStateCounts.call(this, stateId);
  2220.         var state = $dataStates[stateId];
  2221.         if (typeof state.meta !== 'undefined' && typeof state.meta.atb_duration !== 'undefined' && !isNaN(state.meta.atb_duration))
  2222.         {
  2223.             this._states_atb_current[stateId] = 0;
  2224.         }
  2225.     };
  2226.  
  2227.     //Removes state duration and such when removing a state, and re-calculates haste:
  2228.     _alias_gbb_p_EraseState = Game_BattlerBase.prototype.eraseState;
  2229.     Game_BattlerBase.prototype.eraseState = function(stateId) {
  2230.         _alias_gbb_p_EraseState.call(this, stateId);
  2231.         if (typeof this._states_atb_duration[stateId] !== 'undefined')
  2232.         {
  2233.             delete this._states_atb_duration[stateId];
  2234.         }
  2235.         if (typeof this._states_atb_current[stateId] !== 'undefined')
  2236.         {
  2237.             delete this._states_atb_current[stateId];
  2238.         }
  2239.         if (typeof this._states_atb_rate[stateId] !== 'undefined')
  2240.         {
  2241.             delete this._states_atb_rate[stateId];
  2242.         }
  2243.         var state = $dataStates[stateId];
  2244.         if (typeof state.meta !== 'undefined')
  2245.         {
  2246.             this.CalculateHaste();
  2247.         }
  2248.     };
  2249.  
  2250.     //Calculates all haste ratings based on equips, classes, states, etc:
  2251.     Game_BattlerBase.prototype.CalculateHaste = function() {
  2252.         this._haste_all = 100;
  2253.         this._haste_atb = 100;
  2254.         this._haste_cast = 100;
  2255.         this.states().forEach(function(state) {
  2256.             this.AddHaste(state);
  2257.         }, this);
  2258.         if (this.isActor())
  2259.         {
  2260.             this.AddHaste(this.actor());
  2261.             this.AddHaste(this.currentClass());
  2262.             this.equips().forEach(function(equip)
  2263.             {
  2264.                 this.AddHaste(equip);
  2265.             }, this);
  2266.         }
  2267.         else
  2268.         {
  2269.             this.AddHaste(this.enemy());
  2270.         }
  2271.     };
  2272.  
  2273.     //Add individual state or item haste
  2274.     Game_BattlerBase.prototype.AddHaste = function(item) {
  2275.         if (item !== null && typeof item !== 'undefined' && typeof item.meta !== 'undefined')
  2276.         {
  2277.             if (typeof item.meta.haste !== 'undefined' && !isNaN(item.meta.haste))
  2278.             {
  2279.                 this._haste_all = this._haste_all * Number(item.meta.haste) / 100;
  2280.             }
  2281.             if (typeof item.meta.haste_atb !== 'undefined' && !isNaN(item.meta.haste_atb))
  2282.             {
  2283.                 this._haste_atb = this._haste_atb * Number(item.meta.haste_atb) / 100;
  2284.             }
  2285.             if (typeof item.meta.haste_cast !== 'undefined' && !isNaN(item.meta.haste_cast))
  2286.             {
  2287.                 this._haste_cast = this._haste_cast * Number(item.meta.haste_cast) / 100;
  2288.             }
  2289.         }
  2290.     };
  2291.  
  2292.  
  2293.     Game_BattlerBase.prototype.StateATBRate = function(state)
  2294.     {
  2295.         if (typeof state.meta !== 'undefined' && typeof state.meta.atb_duration_param !== 'undefined' && state.meta.atb_duration_param !== null)
  2296.         {
  2297.             switch (state.meta.atb_duration_param)
  2298.             {
  2299.                 case "turn":
  2300.                 case "turn_timer":
  2301.                 case "timer":
  2302.                     return turn_timer;
  2303.                 case "atk":
  2304.                 case "def":
  2305.                 case "mat":
  2306.                 case "mdf":
  2307.                 case "agi":
  2308.                 case "luk":
  2309.                     return Number(eval("this." + state.meta.atb_duration_param));
  2310.                 case "base":
  2311.                 case "fix":
  2312.                 case "fixed":
  2313.                     return 0;
  2314.             }
  2315.         }
  2316.         return this.agi;
  2317.     };
  2318.  
  2319.     //Breaks casting time when restricted, since restriction clears current action:
  2320.     _alias_gbb_p_onRestrict = Game_BattlerBase.prototype.onRestrict;
  2321.     Game_BattlerBase.prototype.onRestrict = function() {
  2322.         this.BreakCurrentCast(true);
  2323.         _alias_gbb_p_onRestrict.call(this);
  2324.     };
  2325.  
  2326.     //Command Fight by default would send us spiraling to a "turn" end (for nobody), instead let's just send us to the ATB phase:
  2327.     Scene_Battle.prototype.commandFight = function() {
  2328.         BattleManager._phase = 'atb';
  2329.     };
  2330. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top