Advertisement
ZainWD

Untitled

Mar 17th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /*:
  2.  * @plugindesc v1.00 Press Turn Battle (Requires YEP_BattleEngineCore.js)
  3.  * @author Yorae Rasante (based on work by Archeia and Yanfly)
  4.  *
  5.  *
  6.  * @param ---Settings---
  7.  * @default
  8.  *
  9.  * @param weakPT
  10.  * @text Weakness Threshold
  11.  * @parent ---Settings---
  12.  * @type number
  13.  * @decimals 4
  14.  * @desc Over how much percentage is an element considered a
  15.  * weakness.
  16.  * @default 100
  17.  *
  18.  * @param strongPT
  19.  * @text Resistance Threshold
  20.  * @parent ---Settings---
  21.  * @type number
  22.  * @decimals 4
  23.  * @desc Under how much percentage is an element considered a
  24.  * resistance.
  25.  * @default 100
  26.  *
  27.  * @param defaultPT
  28.  * @text Default Turns
  29.  * @parent ---Settings---
  30.  * @type number
  31.  * @desc How many turns a battler gets by default
  32.  * @default 1
  33.  *
  34.  * @param defaultHPT
  35.  * @text Default Half-Turns
  36.  * @parent ---Settings---
  37.  * @type number
  38.  * @desc How many half-turns a battler gets by default
  39.  * @default 0
  40.  *
  41.  * @param capPT
  42.  * @text Cap on number of turns
  43.  * @parent ---Settings---
  44.  * @type number
  45.  * @desc Max number of turns a side can get
  46.  * @default 8
  47.  *
  48.  * @param defaultCostPT
  49.  * @text Default Skill Cost
  50.  * @parent ---Settings---
  51.  * @type number
  52.  * @desc How many turns a skill costs by default
  53.  * @default 1
  54.  *
  55.  * @param evadeCostPT
  56.  * @text Evasion Skill Cost
  57.  * @parent ---Settings---
  58.  * @type number
  59.  * @desc How many extra turns an evasion costs
  60.  * @default 1
  61.  *
  62.  * @param missCostPT
  63.  * @text Miss Skill Cost
  64.  * @parent ---Settings---
  65.  * @type number
  66.  * @desc How many extra turns a miss costs
  67.  * @default 1
  68.  *
  69.  * @param strongCostPT
  70.  * @text Resist Skill Cost
  71.  * @parent ---Settings---
  72.  * @type number
  73.  * @desc How many extra turns a resistance costs
  74.  * @default 0
  75.  *
  76.  * @param immuneCostPT
  77.  * @text Immunity Skill Cost
  78.  * @parent ---Settings---
  79.  * @type number
  80.  * @desc How many extra turns a immunity costs
  81.  * @default 1
  82.  *
  83.  * @param absorbCostPT
  84.  * @text Absorb Skill Cost
  85.  * @parent ---Settings---
  86.  * @type number
  87.  * @desc How many extra turns an absorption costs
  88.  * @default 99
  89.  *
  90.  * @param reflectCostPT
  91.  * @text Reflect Skill Cost
  92.  * @parent ---Settings---
  93.  * @type number
  94.  * @desc How many extra turns a reflection costs
  95.  * @default 99
  96.  *
  97.  *
  98.  * @param ---Escape---
  99.  * @default
  100.  *
  101.  * @param escapeRatioPT
  102.  * @text Escape Ratio
  103.  * @parent ---Escape---
  104.  * @desc How to calculates escape ratios.
  105.  * Default: 0.5 * $gameParty.agility() / $gameTroop.agility()
  106.  * @default 0.125 * $gameParty.agility() / $gameTroop.agility()
  107.  *
  108.  * @param escapeBoostPT
  109.  * @text Fail Escape Boost
  110.  * @parent ---Escape---
  111.  * @desc Each time the player fails escape, increase the success
  112.  * rate by this much. Default: 0.1
  113.  * @default 0.025
  114.  *
  115.  * @param ---Turn Icons---
  116.  * @default
  117.  *
  118.  * @param partyPTIcon
  119.  * @text Party Icon
  120.  * @parent ---Turn Icons---
  121.  * @type file
  122.  * @dir img/system
  123.  * @require 1
  124.  * @desc The Press Turn icon for the player party
  125.  * @default
  126.  *
  127.  * @param troopPTIcon
  128.  * @text Troop Icon
  129.  * @parent ---Turn Icons---
  130.  * @type file
  131.  * @dir img/system
  132.  * @require 1
  133.  * @desc The Press Turn icon for the enemy troop
  134.  * @default
  135.  *
  136.  * @param batteryIcon
  137.  * @text Battery Icon
  138.  * @parent ---Turn Icons---
  139.  * @type file
  140.  * @dir img/system
  141.  * @require 1
  142.  * @desc The Battery "Shell"
  143.  * @default
  144.  *
  145.  * @param xPTIcon
  146.  * @text X position
  147.  * @parent ---Turn Icons---
  148.  * @desc The icons' x position.
  149.  * You can use a formula.
  150.  * @default Graphics.boxWidth - (width * (index + 1))
  151.  *
  152.  * @param yPTIcon
  153.  * @text Y position
  154.  * @parent ---Turn Icons---
  155.  * @desc The icons' y position.
  156.  * You can use a formula.
  157.  * @default 54 + (height /2 * (index%2))
  158.  *
  159.  * @param disposeSpeedPTIcon
  160.  * @text Dispose Speed
  161.  * @parent ---Turn Icons---
  162.  * @type number
  163.  * @desc How many frames for the icon to disappear
  164.  * @default 10
  165.  *
  166.  * @param flashSpeedPTIcon
  167.  * @text Flash Speed
  168.  * @parent ---Turn Icons---
  169.  * @type number
  170.  * @desc How many frames the icon flashes
  171.  * @default 30
  172.  *
  173.  *
  174.  *
  175.  * @help
  176.  * Press Turn System adapted by Yorae Rasante
  177.  * Using as base VX Ace version by Archeia and STB by Yanfly
  178.  * This plugin requires YEP_BattleEngineCore. Make sure this plugin is located
  179.  * under YEP_BattleEngineCore in the plugin list.
  180.  *
  181.  * Requires you to set Battle System on BEC to 'ptb', be it through the
  182.  * Default System parameter or through a Plugin Command.
  183.  *
  184.  * It can be changed back and forth through your game through the
  185.  * Plugin Command if needed.
  186.  *
  187.  *   setBattleSys PTB      Sets battle system to Press Turn Battle.
  188.  *   setBattleSys DTB      Sets battle system to Default Turn Battle.
  189.  *
  190.  * The Press Turn Battle is a battle system based on the Megami Tensei games.
  191.  * Each side gets a number of turns based, most of the time, on their
  192.  * number of members (bosses may have more turns per turn).
  193.  * A turn can be, under the right circunstances, "half-used". Those "halves"
  194.  * can then be used again as if whole turns.
  195.  * At the same time, circunstances may cause the use of double, or all turns.
  196.  *
  197.  * If an attack is repelled or absorbed, or party failed to retreat,
  198.  *  All remaining turns are lost.
  199.  *
  200.  * If a normal attack is nullified or dodged/misses
  201.  *  An extra turn is used
  202.  *
  203.  * If a skill is set as "missable" and misses/is dodged
  204.  *  One turn is used
  205.  *
  206.  * If a skill crits/hits a weakness
  207.  *  If the cost was paid with any full turn, they are turned into half-turns.
  208.  *  Any half-turns are used completely.
  209.  *
  210.  * Passing turn to next ally, or using a skill set as "low cost"
  211.  *  Uses a half-turn. If no half-turns remain, a whole turn is turned into half.
  212.  *
  213.  * Using a skill that adds turns
  214.  *  Uses one turn or half-turn, gains the number of half-turns set for the skill.
  215.  *
  216.  * Using a skill set as "Instant" (though Yanfly's YEP_InstantCast)
  217.  *  Uses no turn.
  218.  *
  219.  * You may notice a lack of use for the Agility parameter in this battle system.
  220.  * That is because by default in the games it affects Hit and Crit Chance and
  221.  * Evasion. Something reproduceable with Yanfly's Extra Parameters Formula.
  222.  * In a battle system where those two things can give or takes turns...
  223.  *
  224.  * Notetags:
  225.  *  Actors and Enemies:
  226.  *    <PT Turns: x>
  227.  *    <PT Half Turns: x>
  228.  *      Changes the default number of turns/half-turns given by the battler.
  229.  *
  230.  *    <PT Cost: +x>
  231.  *    <PT Cost: -x>
  232.  *      Raises or lowers the cost of turns a skill takes for the battler.
  233.  *      Does not affect "low cost" skills.
  234.  *
  235.  *  Classes, Equipment, and States:
  236.  *    <PT Turns: x>
  237.  *    <PT Turns: +x>
  238.  *    <PT Turns: -x>
  239.  *    <PT Half Turns: x>
  240.  *    <PT Half Turns: +x>
  241.  *    <PT Half Turns: -x>
  242.  *      Changes the number of turns/half-turns given by the battler.
  243.  *      x or +x raises and -x lowers the number.
  244.  *
  245.  *    <PT Cost: +x>
  246.  *    <PT Cost: -x>
  247.  *      Raises or lowers the cost of turns skills takes for the battler.
  248.  *
  249.  *  Skills and Items:
  250.  *    <PT Cost: x>
  251.  *      Sets cost of turns for the skill.
  252.  *
  253.  *    <PT Cost Eval>
  254.  *      value = x;
  255.  *    </PT Cost Eval>
  256.  *      Sets cost of turns for the skill through code.
  257.  *      Number of turns is the value of "value".
  258.  *
  259.  *    <PT Low Cost>
  260.  *      Sets skill to only cost half a turn.
  261.  *
  262.  *    <PT Low Cost Eval>
  263.  *      condition = true;
  264.  *    </PT Low Cost Eval>
  265.  *      Skill will only cost half a turn, if "condition" is true.
  266.  *
  267.  *    <PT Missable>
  268.  *      Sets skill to be "missable" - being dodged or missing causing
  269.  *       no extra cost in turns.
  270.  *
  271.  *    <PT Missable Eval>
  272.  *      condition = true;
  273.  *    </PT Missable Eval>
  274.  *      Sets skill to be "missable" if "condition" is true.
  275.  *
  276.  *    <PT Gain: x>
  277.  *      Target gains x half-turns.
  278.  *
  279.  *    <PT Gain Eval>
  280.  *      value = x;
  281.  *    </PT Cost Eval>
  282.  *      Target gains a number of half-turns.
  283.  *      Number of half-turns is the value of "value".
  284.  *
  285.  *    <PTB Help>
  286.  *      text
  287.  *      text
  288.  *    </PTB Help>
  289.  *      Text for the help box, in case you want a different text
  290.  *      when using different battle systems.
  291.  */
  292.  
  293. var Imported = Imported || {};
  294. Imported.YR_BattleSysPTB = true;
  295.  
  296. if (Imported.YEP_BattleEngineCore) {
  297. if (Yanfly.BEC.version && Yanfly.BEC.version >= 1.42) {
  298.  
  299. var YR = YR || {};
  300. YR.BattleSysPTB = YR.BattleSysPTB || {};
  301.  
  302. YR.parameters = PluginManager.parameters('YR_BattleSysPTB');
  303. YR.BattleSysPTB.weakPT = Number(YR.parameters['weakPT']);
  304. YR.BattleSysPTB.strongPT = Number(YR.parameters['strongPT']);
  305. YR.BattleSysPTB.defaultPT = Number(YR.parameters['defaultPT']);
  306. YR.BattleSysPTB.defaultHPT = Number(YR.parameters['defaultHPT']);
  307. YR.BattleSysPTB.capPT = Number(YR.parameters['capPT']);
  308. YR.BattleSysPTB.defaultCostPT = Number(YR.parameters['defaultCostPT']);
  309. YR.BattleSysPTB.evadeCostPT = Number(YR.parameters['evadeCostPT']);
  310. YR.BattleSysPTB.missCostPT = Number(YR.parameters['missCostPT']);
  311. YR.BattleSysPTB.strongCostPT = Number(YR.parameters['strongCostPT']);
  312. YR.BattleSysPTB.immuneCostPT = Number(YR.parameters['immuneCostPT']);
  313. YR.BattleSysPTB.absorbCostPT = Number(YR.parameters['absorbCostPT']);
  314. YR.BattleSysPTB.reflectCostPT = Number(YR.parameters['reflectCostPT']);
  315. YR.BattleSysPTB.escapeRatioPT = new Function('return ' + String(YR.parameters['escapeRatioPT']));
  316. YR.BattleSysPTB.escapeBoostPT = new Function('return ' + String(YR.parameters['escapeBoostPT']));
  317. YR.BattleSysPTB.partyPTIcon = String(YR.parameters['partyPTIcon']);
  318. YR.BattleSysPTB.troopPTIcon = String(YR.parameters['troopPTIcon']);
  319. YR.BattleSysPTB.batteryIcon = String(YR.parameters['batteryIcon']);
  320. YR.BattleSysPTB.xPTIcon = new Function('width', 'height', 'index', 'return ' + String(YR.parameters['xPTIcon']));
  321. YR.BattleSysPTB.yPTIcon = new Function('width', 'height', 'index', 'return ' + String(YR.parameters['yPTIcon']));
  322. YR.BattleSysPTB.disposeSpeedPTIcon = Number(YR.parameters['disposeSpeedPTIcon']);
  323. YR.BattleSysPTB.flashSpeedPTIcon = Number(YR.parameters['flashSpeedPTIcon']);
  324.  
  325. ImageManager.reserveSystem(YR.BattleSysPTB.partyPTIcon);
  326. ImageManager.reserveSystem(YR.BattleSysPTB.troopPTIcon);
  327. ImageManager.reserveSystem(YR.BattleSysPTB.batteryIcon);
  328.  
  329. YR.BattleSysPTB.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  330. DataManager.isDatabaseLoaded = function() {
  331.   if (!YR.BattleSysPTB.DataManager_isDatabaseLoaded.call(this)) return false;
  332.   if (!YR._loaded_YR_BattleSysPTB) {
  333.     this.processPTBBattlersNotetags($dataActors);
  334.     this.processPTBBattlersNotetags($dataEnemies);
  335.     this.processPTBBattlerDataNotetags($dataClasses);
  336.     this.processPTBBattlerDataNotetags($dataWeapons);
  337.     this.processPTBBattlerDataNotetags($dataArmors);
  338.     this.processPTBBattlerDataNotetags($dataStates);
  339.     this.processPTBSkillsNotetags($dataSkills);
  340.     this.processPTBSkillsNotetags($dataItems);
  341.     YR._loaded_YR_BattleSysPTB = true;
  342.   }
  343.   return true;
  344. };
  345.  
  346. DataManager.processPTBBattlersNotetags = function(group) {
  347.   for (var n = 1; n < group.length; n++) {
  348.     var obj = group[n];
  349.     var notedata = obj.note.split(/[\r\n]+/);
  350.  
  351.     obj.PT = YR.BattleSysPTB.defaultPT;
  352.     obj.HPT = YR.BattleSysPTB.defaultHPT;
  353.     obj.extraPTCost = 0;
  354.  
  355.     for (var i = 0; i < notedata.length; i++) {
  356.       var line = notedata[i];
  357.  
  358.       if (line.match(/<PT Turns:[ ]*(\d+)>/i)) {
  359.         obj.PT = parseInt(RegExp.$1);
  360.       }
  361.       else if (line.match(/<PT (?:Half Turns|Half-Turns):[ ]*(\d+)>/i)) {
  362.         obj.HPT = parseInt(RegExp.$1);
  363.       }
  364.       else if (line.match(/<PT Cost:[ ]*([\+\-]\d+)>/i)) {
  365.         obj.extraPTCost += parseInt(RegExp.$1);
  366.       }
  367.     }
  368.   }
  369. }
  370.  
  371. DataManager.processPTBBattlerDataNotetags = function(group) {
  372.   for (var n = 1; n < group.length; n++) {
  373.     var obj = group[n];
  374.     var notedata = obj.note.split(/[\r\n]+/);
  375.  
  376.     obj.PTPlus = 0;
  377.     obj.HPTPlus = 0;
  378.     obj.extraPTCost = 0;
  379.  
  380.     for (var i = 0; i < notedata.length; i++) {
  381.       var line = notedata[i];
  382.  
  383.       if (line.match(/<PT Turns:[ ]*(\d+)>/i)) {
  384.         obj.PTPlus += parseInt(RegExp.$1);
  385.       }
  386.       else if (line.match(/<PT Turns:[ ]*([\+\-]\d+)>/i)) {
  387.         obj.PTPlus += parseInt(RegExp.$1);
  388.       }
  389.       else if (line.match(/<PT (?:Half Turns|Half-Turns):[ ]*(\d+)>/i)) {
  390.         obj.HPTPlus += parseInt(RegExp.$1);
  391.       }
  392.       else if (line.match(/<PT (?:Half Turns|Half-Turns):[ ]*([\+\-]\d+)>/i)) {
  393.         obj.HPTPlus += parseInt(RegExp.$1);
  394.       }
  395.       else if (line.match(/<PT Cost:[ ]*([\+\-]\d+)>/i)) {
  396.         obj.extraPTCost += parseInt(RegExp.$1);
  397.       }
  398.     }
  399.   }
  400. }
  401.  
  402. DataManager.processPTBSkillsNotetags = function(group) {
  403.   for (var n = 1; n < group.length; n++) {
  404.     var obj = group[n];
  405.     var notedata = obj.note.split(/[\r\n]+/);
  406.  
  407.     var evalMode = 'none';
  408.     obj.PTCost = YR.BattleSysPTB.defaultCostPT;
  409.     obj.PTCostEval = undefined;
  410.     obj.PTLowCost = false;
  411.     obj.PTLowCostEval = undefined;
  412.     obj.PTMissable = false;
  413.     obj.PTMissableEval = undefined;
  414.     obj.PTGain = 0;
  415.     obj.PTGainEval = undefined;
  416.     obj.PTHelp = undefined;
  417.    
  418.     for (var i = 0; i < notedata.length; i++) {
  419.       var line = notedata[i];
  420.      
  421.       if (line.match(/<PT Cost:[ ]*(\d+)>/i)) {
  422.         obj.PTCost = parseInt(RegExp.$1);
  423.       } else if (line.match(/<PT (?:Low Cost|Low-Cost)>/i)) {
  424.         obj.PTLowCost = true;
  425.       } else if (line.match(/<PT Missable>/i)) {
  426.         obj.PTMissable = true;
  427.       } else if (line.match(/<PT Gain:[ ]*(\d+)>/i)) {
  428.         obj.PTGain += parseInt(RegExp.$1);
  429.       } else if (line.match(/<(?:PTB HELP)>/i)) {
  430.         evalMode = 'ptb help';
  431.         obj.PTHelp = '';
  432.       } else if (line.match(/<\/(?:PTB HELP)>/i)) {
  433.         evalMode = 'none';
  434.       } else if (evalMode === 'ptb help') {
  435.         obj.PTHelp += line + '\n';
  436.       } else if (line.match(/<PT Cost Eval>/i)) {
  437.         evalMode = 'pt cost eval';
  438.         obj.PTCostEval = '';
  439.       } else if (line.match(/<\/PT Cost Eval>/i)) {
  440.         evalMode = 'none';
  441.       } else if (evalMode === 'pt cost eval') {
  442.         obj.PTCostEval += line + '\n';
  443.       } else if (line.match(/<PT (?:Low Cost|Low-Cost) Eval>/i)) {
  444.         evalMode = 'pt low cost eval';
  445.         obj.PTLowCostEval = '';
  446.       } else if (line.match(/<\/PT (?:Low Cost|Low-Cost) Eval>/i)) {
  447.         evalMode = 'none';
  448.       } else if (evalMode === 'pt low cost eval') {
  449.         obj.PTLowCostEval += line + '\n';
  450.       } else if (line.match(/<PT Missable Eval>/i)) {
  451.         evalMode = 'pt missable eval';
  452.         obj.PTMissableEval = '';
  453.       } else if (line.match(/<\/PT Missable Eval>/i)) {
  454.         evalMode = 'none';
  455.       } else if (evalMode === 'pt missable eval') {
  456.         obj.PTMissableEval += line + '\n';
  457.       } else if (line.match(/<PT Gain Eval>/i)) {
  458.         evalMode = 'pt gain eval';
  459.         obj.PTGainEval = '';
  460.       } else if (line.match(/<\/PT Gain Eval>/i)) {
  461.         evalMode = 'none';
  462.       } else if (evalMode === 'pt gain eval') {
  463.         obj.PTGainEval += line + '\n';
  464.       }
  465.     }
  466.   }
  467. }
  468.  
  469. BattleManager.isPTB = function() {
  470.   return this.isBattleSystem('ptb');
  471. };
  472.  
  473. YR.BattleSysPTB.BattleManager_isTurnBased = BattleManager.isTurnBased;
  474. BattleManager.isTurnBased = function() {
  475.   if (this.isPTB()) return true;
  476.   return YR.BattleSysPTB.BattleManager_isTurnBased.call(this);
  477. };
  478.  
  479. YR.BattleSysPTB.BattleManager_makeEscapeRatio = BattleManager.makeEscapeRatio;
  480. BattleManager.makeEscapeRatio = function() {
  481.   if (this.isPTB()) {
  482.     try {
  483.       this._escapeRatio = YR.BattleSysPTB['escapeRatioPT'].call(this);
  484.     } catch (e) {
  485.       this._escapeRatio = 0;
  486.       Yanfly.Util.displayError(e, YR.BattleSysPTB['escapeRatioPT'], 'PTB ESCAPE RATIO ERROR');
  487.     }
  488.     try {
  489.       this._escapeFailBoost = YR.BattleSysPTB['escapeBoostPT'].call(this);
  490.     } catch (e) {
  491.       this._escapeFailBoost = 0;
  492.       Yanfly.Util.displayError(e, YR.BattleSysPTB['escapeBoostPT'], 'PTB ESCAPE BOOST ERROR');
  493.     }
  494.   } else {
  495.     this._escapeFailBoost = 0.1;
  496.     YR.BattleSysPTB.BattleManager_makeEscapeRatio.call(this);
  497.   }
  498. };
  499.  
  500. YR.BattleSysPTB.BattleManager_displayEscapeFailureMessage =
  501.   BattleManager.displayEscapeFailureMessage;
  502. BattleManager.displayEscapeFailureMessage = function() {
  503.   YR.BattleSysPTB.BattleManager_displayEscapeFailureMessage.call(this);
  504.   if (this.isPTB()) {
  505.     $gameParty._PTPool = 0;
  506.     $gameParty._HPTPool = 0;
  507.     this.endTurn();
  508.   }
  509. };
  510.  
  511. BattleManager.isTroopTurn = function () {
  512.   return this._troopTurn;
  513. }
  514.  
  515. YR.BattleSysPTB.BattleManager_startBattle = BattleManager.startBattle;
  516. BattleManager.startBattle = function() {
  517.   if (this.isPTB()) {
  518.     if($gameTroop.agility() > $gameParty.agility()) this._troopTurn = true;
  519.     else this._troopTurn = false;
  520.   }
  521.   YR.BattleSysPTB.BattleManager_startBattle.call(this);
  522. };
  523.  
  524. YR.BattleSysPTB.GameTroop_increaseturn = Game_Troop.prototype.increaseTurn;
  525. Game_Troop.prototype.increaseTurn = function() {
  526.   if (!BattleManager.isPTB() || BattleManager.isTroopTurn()) {
  527.     YR.BattleSysPTB.GameTroop_increaseturn.call(this);
  528.   }
  529. };
  530.  
  531. YR.BattleSysPTB.BattleManager_endTurn = BattleManager.endTurn;
  532. BattleManager.endTurn = function() {
  533.   if (!BattleManager.isPTB()) {YR.BattleSysPTB.BattleManager_endTurn.call(this)}
  534.   else {
  535.     this._phase = 'turnEnd';
  536.     if (!this.isTroopTurn() && $gameTroop.turnCount() > 0) this._preemptive = false;
  537.     if (this.isTroopTurn() && $gameTroop.turnCount() > 0) this._surprise = false;
  538.     this.allBattleMembers().forEach(function(battler) {
  539.       if ((battler.isEnemy() && this.isTroopTurn()) || (battler.isActor() && !this.isTroopTurn())) {
  540.         battler.onTurnEnd();
  541.         this.refreshStatus();
  542.         this._logWindow.displayRegeneration(battler);
  543.       }
  544.     }, this);
  545.     this._troopTurn = !this._troopTurn;
  546.     this._orderMade = false;
  547.   }
  548. };
  549.  
  550. YR.BattleSysPTB.Game_Unit_onTurnStart = Game_Unit.prototype.onTurnStart;
  551. Game_Unit.prototype.onTurnStart = function() {
  552.   if (!BattleManager.isPTB()) YR.BattleSysPTB.Game_Unit_onTurnStart.call(this);
  553.   else {
  554.     var max = this.members().length;
  555.     for (var i = 0; i < max; ++i) {
  556.       var member = this.members()[i];
  557.       if (member) {
  558.         if ((member.isEnemy() && BattleManager.isTroopTurn()) || (member.isActor() && !BattleManager.isTroopTurn())) member.onTurnStart();
  559.         member.refresh();
  560.       }
  561.     }
  562.   }
  563. };
  564.  
  565. YR.BattleSysPTB.BattleManager_makeActionOrders = BattleManager.makeActionOrders;
  566. BattleManager.makeActionOrders = function() {
  567.   if (!BattleManager.isPTB()) YR.BattleSysPTB.BattleManager_makeActionOrders.call(this);
  568.   else if (!this._orderMade) {
  569.     var battlers = [];
  570.     var otherTeam = [];
  571.     if (!this._surprise && !this.isTroopTurn()) {
  572.         battlers = battlers.concat($gameParty.members());
  573.         $gameParty.makePTPool();
  574.     } else otherTeam = otherTeam.concat($gameParty.members());
  575.     if (!this._preemptive && this.isTroopTurn()) {
  576.         battlers = battlers.concat($gameTroop.members());
  577.         $gameTroop.makePTPool();
  578.     } else otherTeam = otherTeam.concat($gameTroop.members());
  579.     battlers.sort(function(a, b) {
  580.         return b.agi - a.agi;
  581.     });
  582.     this._actionBattlers = battlers;
  583.     this._performedBattlers = otherTeam;
  584.     this._orderMade = true;
  585.   }
  586. };
  587.  
  588. YR.BattleSysPTB.BattleManager_getNextSubject = BattleManager.getNextSubject;
  589. BattleManager.getNextSubject = function() {
  590.   if (this.isPTB()) {
  591.     if ((this.isTroopTurn() && $gameTroop.totalPTPool() <= 0) || (!this.isTroopTurn() && $gameParty.totalPTPool() <= 0)) {
  592.       return null;
  593.     }
  594.     for (;;) {
  595.       var battler = this._actionBattlers.shift();
  596.       this._actionBattlers.push(battler);
  597.       if (!battler) return null;
  598.       if (battler.isBattleMember() && battler.isAlive()) {
  599.         return battler;
  600.       }
  601.     }
  602.   } else {
  603.     return YR.BattleSysPTB.BattleManager_getNextSubject.call(this);
  604.   }
  605. };
  606.  
  607. YR.BattleSysPTB.BattleManager_startInput = BattleManager.startInput;
  608. BattleManager.startInput = function() {
  609.   YR.BattleSysPTB.BattleManager_startInput.call(this);
  610.   if (this.isPTB() && this._phase !== 'turn') this.startTurn();
  611. };
  612.  
  613. YR.BattleSysPTB.BattleManager_processTurn = BattleManager.processTurn;
  614. BattleManager.processTurn = function() {
  615.   var subject = this._subject;
  616.   if (this.isPTB() && subject.isActor()) {
  617.     this._phase = 'input';
  618.     BattleManager.changeActor(subject.index(), 'undecided');
  619.     if (!subject.canInput()) {
  620.       subject.makeActions();
  621.       this.startAction();
  622.     }
  623.   } else if (this.isPTB() && subject.isEnemy()) {
  624.     subject.clearActions();
  625.     subject.makeActions();
  626.     for (;;) {
  627.       if (subject._actions[0] && subject._actions[0]._item._itemId === 0) {
  628.         subject._actions.shift();
  629.       }
  630.       else break;
  631.     }
  632.     this.startAction();
  633.   } else {
  634.     YR.BattleSysPTB.BattleManager_processTurn.call(this);
  635.   }
  636. };
  637.  
  638. YR.BattleSysPTB.BattleManager_selectPreviousCommand =
  639.   BattleManager.selectPreviousCommand;
  640. BattleManager.selectPreviousCommand = function() {
  641.   if (this.isPTB()) {
  642.     this._activePTBActor = this._subject;
  643.     this._subject = null;
  644.     this.changeActor(-1, 'undecided');
  645.   } else {
  646.     YR.BattleSysPTB.BattleManager_selectPreviousCommand.call(this);
  647.   }
  648. };
  649.  
  650. BattleManager.ptbSetSubject = function() {
  651.   BattleManager.changeActor($gameParty.members().indexOf(this._activePTBActor), 'undecided');
  652.   this._subject = this.actor();
  653. };
  654.  
  655. YR.BattleSysPTB.BattleManager_selectNextCommand = BattleManager.selectNextCommand;
  656. BattleManager.selectNextCommand = function() {
  657.   if (this.isPTB()) {
  658.     if (this._subject) {
  659.       this.startAction();
  660.     } else {
  661.       this.ptbSetSubject();
  662.       this._phase = 'input';
  663.       var battler = this._subject;
  664.       BattleManager.changeActor(battler.index(), 'undecided');
  665.       if (!battler.canInput()) {
  666.         battler.makeActions();
  667.         this.startAction();
  668.       }
  669.     }
  670.   } else {
  671.     YR.BattleSysPTB.BattleManager_selectNextCommand.call(this);
  672.   }
  673. };
  674.  
  675. BattleManager.detectPtbInstantCast = function() {
  676.   this._ptbInstantCast = false;
  677.   if (!this.isPTB()) return;
  678.   if (!this._subject) return;
  679.   if (!this._subject.currentAction()) return;
  680.   if (!this._subject.currentAction().item()) return;
  681.   var item = this._subject.currentAction().item();
  682.   this._ptbInstantCast = this._subject.isInstantCast(item);
  683. };
  684.  
  685. YR.BattleSysPTB.BattleManager_startAction = BattleManager.startAction;
  686. BattleManager.startAction = function() {
  687.   if (Imported.YEP_InstantCast && this.isPTB()) this.detectPtbInstantCast();
  688.   YR.BattleSysPTB.BattleManager_startAction.call(this);
  689. };
  690.  
  691. YR.BattleSysPTB.BattleManager_endAction = BattleManager.endAction;
  692. BattleManager.endAction = function() {
  693.   if (this.isPTB() && this._action) {
  694.     this._action._phase = 'turn';
  695.     if (!this._ptbInstantCast) {
  696.       if (this._action.subject().PTLowCost(this._action.item())) this._action.subject().friendsUnit().useLowCostPT();
  697.       else if(!this._action._critted && !this._action._hitWeakness) this._action.subject().friendsUnit().usePT(this._action.subject().PTCost(this._action.item()));
  698.     }
  699.     if (this._action._absorbed) this._action.subject().friendsUnit().usePT(YR.BattleSysPTB.absorbCostPT);
  700.     else if(this._action._reflected) this._action.subject().friendsUnit().usePT(YR.BattleSysPTB.reflectCostPT);
  701.     else if(this._action._immune) this._action.subject().friendsUnit().usePT(YR.BattleSysPTB.immuneCostPT);
  702.     else if(this._action._missed && !this._action.subject().PTMissable(this._action.item())) this._action.subject().friendsUnit().usePT(YR.BattleSysPTB.missCostPT);
  703.     else if(this._action._evaded && !this._action.subject().PTMissable(this._action.item())) this._action.subject().friendsUnit().usePT(YR.BattleSysPTB.evadeCostPT);
  704.     else if(this._action._critted || this._action._hitWeakness) {
  705.       var value = this._action.subject().PTCost(this._action.item());
  706.       if (this._action.subject().friendsUnit()._PTPool < value) {
  707.         var value2 = value;
  708.         value = this._action.subject().friendsUnit()._PTPool;
  709.         value2 -= value;
  710.         this._action.subject().friendsUnit().gainHPT(value);
  711.         this._action.subject().friendsUnit()._PTPool = 0;
  712.         this._action.subject().friendsUnit().usePT(value2);
  713.       } else {
  714.         this._action.subject().friendsUnit()._PTPool -= value;
  715.         this._action.subject().friendsUnit().gainHPT(value);
  716.       }
  717.     }
  718.     else if(this._action._hitResistance) this._action.subject().friendsUnit().usePT(YR.BattleSysPTB.strongCostPT);
  719.     this._action.subject().friendsUnit().gainHPT(this._action.subject().PTGain(this._action.item()))
  720.     if (this._ptbInstantCast) {
  721.       this._ptbInstantCast = false;
  722.       return YR.BattleSysPTB.BattleManager_endAction.call(this);
  723.     }
  724.     if (this._subject) {
  725.       this._subject.spriteStepBack();
  726.       this._subject.onAllActionsEnd();
  727.       this._subject.removeCurrentAction();
  728.     }
  729.     if (this._processingForcedAction) {
  730.       this._phase = this._preForcePhase;
  731.       this._processingForcedAction = false;
  732.     }
  733.     if (this.loadPreForceActionSettings()) return;
  734.     YR.BattleSysPTB.BattleManager_endAction.call(this);
  735.     this._subject = null;
  736.   } else if (this.isPTB()) {
  737.     if (this._subject) {
  738.       this._subject.friendsUnit().usePT(this._subject.extraPTCost()+1);
  739.       this._subject.onAllActionsEnd();
  740.       this._subject.removeCurrentAction();
  741.     }
  742.     YR.BattleSysPTB.BattleManager_endAction.call(this);
  743.     this._subject = null;
  744.   } else {
  745.     YR.BattleSysPTB.BattleManager_endAction.call(this);
  746.   }
  747. };
  748.  
  749. YR.BattleSysPTB.BattleManager_processVictory = BattleManager.processVictory;
  750. BattleManager.processVictory = function() {
  751.   if (this.isPTB()) SceneManager._scene.removePT();
  752.   YR.BattleSysPTB.BattleManager_processVictory.call(this);
  753. };
  754.  
  755. YR.BattleSysPTB.Scene_Battle_commandFight = Scene_Battle.prototype.commandFight;
  756. Scene_Battle.prototype.commandFight = function() {
  757.   if (BattleManager.isPTB()) {
  758.     BattleManager.ptbSetSubject();
  759.     BattleManager._phase = 'input';
  760.     var battler = BattleManager._subject;
  761.     BattleManager.changeActor(battler.index(), 'undecided');
  762.     if (!battler.canInput()) {
  763.       battler.makeActions();
  764.       BattleManager.startAction();
  765.     }
  766.   } else {
  767.     YR.BattleSysPTB.Scene_Battle_commandFight.call(this);
  768.   }
  769. };
  770.  
  771. YR.BattleSysPTB.Scene_Battle_commandEscape = Scene_Battle.prototype.commandEscape;
  772. Scene_Battle.prototype.commandEscape = function() {
  773.   if (BattleManager.isPTB()) {
  774.     BattleManager.processEscape();
  775.   } else {
  776.     YR.BattleSysPTB.Scene_Battle_commandEscape.call(this);
  777.   }
  778. };
  779.  
  780. YR.BattleSysPTB.Window_Help_setItem = Window_Help.prototype.setItem;
  781. Window_Help.prototype.setItem = function(item) {
  782.     if (this.meetPTBConditions(item)) return this.setText(item.PTHelp);
  783.     YR.BattleSysPTB.Window_Help_setItem.call(this, item);
  784. };
  785.  
  786. Window_Help.prototype.meetPTBConditions = function(item) {
  787.     if (!item) return false;
  788.     if (!BattleManager.isPTB()) return false;
  789.     return item.PTHelp !== undefined;
  790. };
  791.  
  792. Game_Unit.prototype.totalPTPool = function() {
  793.   var value = this._PTPool + this._HPTPool;
  794.   return value;
  795. };
  796.  
  797. YR.BattleSysPTB.Game_Unit_initialize = Game_Unit.prototype.initialize;
  798. Game_Unit.prototype.initialize = function () {
  799.   YR.BattleSysPTB.Game_Unit_initialize.apply(this, arguments);
  800.   this._PTPool = 0;
  801.   this._HPTPool = 0;
  802. }
  803.  
  804. Game_Unit.prototype.makePTPool = function() {
  805.   this._PTPool = 0;
  806.   this._HPTPool = 0;
  807.   for (var i = 0; i < this.members().length; i++) {
  808.     if (this.members()[i].isAlive()) {
  809.       this._PTPool += this.members()[i].PT();
  810.       this._HPTPool += this.members()[i].HPT();
  811.     }
  812.   }
  813.   if (this._PTPool + this._HPTPool > YR.BattleSysPTB.capPT) {
  814.     var difference = this._PTPool + this._HPTPool - YR.BattleSysPTB.capPT;
  815.     if (this._HPTPool >= difference) this._HPTPool -= difference;
  816.     else {
  817.       difference -= this._HPTPool;
  818.       this._HPTPool = 0;
  819.       this._PTPool -= difference;
  820.     }
  821.   }
  822. }
  823.  
  824. Game_Unit.prototype.gainHPT = function (value) {
  825.   if (this.totalPTPool() + value > YR.BattleSysPTB.capPT) {
  826.     var difference = this.totalPTPool() + value - YR.BattleSysPTB.capPT;
  827.     this._HPTPool += value - difference;
  828.   } else this._HPTPool += value;
  829. }
  830.  
  831. Game_Unit.prototype.usePT = function (value) {
  832.   if (this._HPTPool >= value) this._HPTPool -= value;
  833.   else {
  834.     var val = value;
  835.     val -= this._HPTPool;
  836.     this._HPTPool = 0;
  837.     this._PTPool -= val;
  838.     this._PTPool = Math.max(0, this._PTPool);
  839.   }
  840. }
  841.  
  842. Game_Unit.prototype.useLowCostPT = function () {
  843.   if (this._HPTPool >= 1) this._HPTPool--;
  844.   else {
  845.     this._HPTPool++;
  846.     this._PTPool--;
  847.   }
  848. }
  849.  
  850. Game_BattlerBase.prototype.PT = function() {
  851.   return YR.BattleSysPTB.defaultPT;
  852. }
  853.  
  854. Game_BattlerBase.prototype.HPT = function() {
  855.   return YR.BattleSysPTB.defaultHPT;
  856. }
  857.  
  858. Game_Battler.prototype.PT = function() {
  859.   var value = 0;
  860.   var length = this.states().length;
  861.   for (var i = 0; i < length; ++i) {
  862.     var obj = this.states()[i];
  863.     if (obj && obj.PTPlus) value += obj.PTPlus;
  864.   }
  865.   return value;
  866. };
  867.  
  868. Game_Battler.prototype.HPT = function() {
  869.   var value = 0;
  870.   var length = this.states().length;
  871.   for (var i = 0; i < length; ++i) {
  872.     var obj = this.states()[i];
  873.     if (obj && obj.HPTPlus) value += obj.HPTPlus;
  874.   }
  875.   return value;
  876. };
  877.  
  878. Game_Actor.prototype.PT = function() {
  879.   var value = this.actor().PT;
  880.   value += this.currentClass().PTPlus;
  881.   var length = this.equips().length;
  882.   for (var i = 0; i < length; ++i) {
  883.     var obj = this.equips()[i];
  884.     if (!obj) continue;
  885.     if (obj.PTPlus) value += obj.PTPlus;
  886.   }
  887.   value += Game_Battler.prototype.PT.call(this);
  888.   return value;
  889. };
  890.  
  891. Game_Actor.prototype.HPT = function() {
  892.   var value = this.actor().HPT;
  893.   value += this.currentClass().HPTPlus;
  894.   var length = this.equips().length;
  895.   for (var i = 0; i < length; ++i) {
  896.     var obj = this.equips()[i];
  897.     if (!obj) continue;
  898.     if (obj.HPTPlus) value += obj.HPTPlus;
  899.   }
  900.   value += Game_Battler.prototype.HPT.call(this);
  901.   return value;
  902. };
  903.  
  904. Game_Enemy.prototype.PT = function() {
  905.   var value = this.enemy().PT;
  906.   value += Game_Battler.prototype.PT.call(this);
  907.   return value;
  908. };
  909.  
  910. Game_Enemy.prototype.HPT = function() {
  911.   var value = this.enemy().HPT;
  912.   value += Game_Battler.prototype.HPT.call(this);
  913.   return value;
  914. };
  915.  
  916. Game_Battler.prototype.PTCost = function(item) {
  917.   if (!item) return 0;
  918.   var value = Game_BattlerBase.prototype.PTCost.call(this, item);
  919.   value += this.extraPTCost();
  920.   return value;
  921. };
  922.  
  923. Game_Battler.prototype.extraPTCost = function() {
  924.   var value = 0
  925.   var length = this.states().length;
  926.   for (var i = 0; i < length; ++i) {
  927.     var obj = this.states()[i];
  928.     if (obj && obj.extraPTCost) value += obj.extraPTCost;
  929.   }
  930.   return value;
  931. };
  932.  
  933. Game_Actor.prototype.extraPTCost = function() {
  934.   var value = this.actor().extraPTCost;
  935.   value += this.currentClass().extraPTCost;
  936.   var length = this.equips().length;
  937.   for (var i = 0; i < length; ++i) {
  938.     var obj = this.equips()[i];
  939.     if (!obj) continue;
  940.     if (obj.extraPTCost) value += obj.extraPTCost;
  941.   }
  942.   value += Game_Battler.prototype.extraPTCost.call(this);
  943.   return value;
  944. };
  945.  
  946. Game_Enemy.prototype.extraPTCost = function() {
  947.   var value = this.enemy().extraPTCost;
  948.   value += Game_Battler.prototype.extraPTCost.call(this);
  949.   return value;
  950. };
  951.  
  952. Game_BattlerBase.prototype.PTCost = function(item) {
  953.   if (!item) return 0;
  954.   var value = item.PTCost;
  955.   var code = new Function('return ' + item.PTCostEval);
  956.   if (code.call(this) !== undefined) {
  957.     try {
  958.       value = code.call(this);
  959.     } catch (e) {
  960.       value = item.PTCost;
  961.       Yanfly.Util.displayError(e, code, 'PRESS TURN TURNS COST ERROR');
  962.     }
  963.   }
  964.   return value;
  965. };
  966.  
  967. Game_BattlerBase.prototype.PTLowCost = function(item) {
  968.   if (!item) return 0;
  969.   var condition = item.PTLowCost;
  970.   var code = new Function('return ' + item.PTLowCostEval);
  971.   if (code.call(this) !== undefined) {
  972.     try {
  973.       condition = code.call(this);
  974.     } catch (e) {
  975.       condition = item.PTLowCost;
  976.       Yanfly.Util.displayError(e, code, 'PRSS TURN LOW COST EVALUATION ERROR');
  977.     }
  978.   }
  979.   return condition;
  980. };
  981.  
  982. Game_BattlerBase.prototype.PTMissable = function(item) {
  983.   if (!item) return 0;
  984.   var condition = item.PTMissable;
  985.   var code = new Function('return ' + item.PTMissableEval);
  986.   if (code.call(this) !== undefined) {
  987.     try {
  988.       condition = code.call(this);
  989.     } catch (e) {
  990.       condition = item.PTMissable;
  991.       Yanfly.Util.displayError(e, code, 'PRSS TURN MISSABLE EVALUATION ERROR');
  992.     }
  993.   }
  994.   return condition;
  995. };
  996.  
  997. Game_BattlerBase.prototype.PTGain = function(item) {
  998.   if (!item) return 0;
  999.   var value = item.PTGain;
  1000.   var code = new Function('return ' + item.PTGainEval);
  1001.   if (code.call(this) !== undefined) {
  1002.     try {
  1003.       value = code.call(this);
  1004.     } catch (e) {
  1005.       value = item.PTGain;
  1006.       Yanfly.Util.displayError(e, code, 'PRESS TURN TURNS GAIN ERROR');
  1007.     }
  1008.   }
  1009.   return value;
  1010. };
  1011.  
  1012. YR.BattleSysPTB.Game_BattlerBase_meetsUsableItemConditions = Game_BattlerBase.prototype.meetsUsableItemConditions;
  1013. Game_BattlerBase.prototype.meetsUsableItemConditions = function(item) {
  1014.   if (BattleManager.isPTB() && item) {
  1015.     var cost = this.PTCost(item);
  1016.     if (this.friendsUnit().totalPTPool() < cost) return false;
  1017.   }
  1018.   return YR.BattleSysPTB.Game_BattlerBase_meetsUsableItemConditions.call(this, item);
  1019. };
  1020.  
  1021. YR.BattleSysPTB.Game_Action_initialize = Game_Action.prototype.initialize;
  1022. Game_Action.prototype.initialize = function(subject, forcing) {
  1023.   if (BattleManager.isPTB()) {
  1024.     this._absorbed = false;
  1025.     this._reflected = false;
  1026.     this._immune = false;
  1027.     this._missed = false;
  1028.     this._evaded = false;
  1029.     this._hitResistance = false;
  1030.     this._critted = false;
  1031.     this._hitWeakness = false;
  1032.   }
  1033.   YR.BattleSysPTB.Game_Action_initialize.call(this, subject, forcing);
  1034. };
  1035.  
  1036. YR.BattleSysPTB.Game_Action_apply = Game_Action.prototype.apply;
  1037. Game_Action.prototype.apply = function(target) {
  1038.   YR.BattleSysPTB.Game_Action_apply.call(this, target);
  1039.   if (BattleManager.isPTB()) {
  1040.     var result = target.result();
  1041.     if (result.missed) this._missed = true;
  1042.     if (result.evaded) this._evaded = true;
  1043.     if (result.critical) this._critted = true;
  1044.     if (this.calcElementRate(target) === 0) this._immune = true;
  1045.     else if (this.calcElementRate(target) < 0) this._absorbed = true;
  1046.     else if (this.calcElementRate(target) < YR.BattleSysPTB.strongPT / 100) this._hitResistance = true;
  1047.     else if (this.calcElementRate(target) > YR.BattleSysPTB.weakPT / 100) this._hitWeakness = true;
  1048.   }
  1049. };
  1050.  
  1051. YR.BattleSysPTB.BattleManager_invokeAction = BattleManager.invokeAction;
  1052. BattleManager.invokeAction = function(subject, target) {
  1053.   if (this.isPTB()) {
  1054.     if (!Yanfly.Param.BECOptSpeed)  this._logWindow.push('pushBaseLine');
  1055.     var normal = true;
  1056.     if (Math.random() < this._action.itemMrf(target)) {
  1057.       this.invokeMagicReflection(subject, target);
  1058.       this._action._reflected = true;
  1059.     } else if (Math.random() < this._action.itemCnt(target)) {
  1060.       this.invokeCounterAttack(subject, target);
  1061.     } else {
  1062.       this.invokeNormalAction(subject, target);
  1063.     }
  1064.     if (subject) subject.setLastTarget(target);
  1065.     if (!Yanfly.Param.BECOptSpeed) this._logWindow.push('popBaseLine');
  1066.   } else YR.BattleSysPTB.BattleManager_invokeAction.call(this, subject, target);
  1067. };
  1068.  
  1069. function Sprite_PT() {
  1070.   this.initialize.apply(this, arguments);
  1071. }
  1072.  
  1073. function Sprite_Battery() {
  1074.   this.initialize.apply(this, arguments);
  1075. }
  1076.  
  1077. Sprite_PT.prototype = Object.create(Sprite.prototype);
  1078. Sprite_PT.prototype.constructor = Sprite_PT;
  1079.  
  1080. Sprite_Battery.prototype = Object.create(Sprite.prototype);
  1081. Sprite_Battery.prototype.constructor = Sprite_Battery;
  1082.  
  1083.  
  1084. Sprite_PT.prototype.initialize = function() {
  1085.   Sprite.prototype.initialize.call(this);
  1086.   this.opacity = 0;
  1087.   this._half = false;
  1088.   this._dispose = true;
  1089.   this._flashOpacity = 0;
  1090. };
  1091.  
  1092. Sprite_Battery.prototype.initialize = function() {
  1093.   Sprite.prototype.initialize.call(this);
  1094.   this.opacity = 0;
  1095.   this._half = false;
  1096.   this._dispose = true;
  1097.   this._flashOpacity = 0;
  1098. };
  1099.  
  1100. Sprite_PT.prototype.setBitmap = function(bitmap) {
  1101.   this.bitmap = new Bitmap(bitmap.width, bitmap.height);
  1102.   this.bitmap = bitmap;
  1103. }
  1104.  
  1105. Sprite_Battery.prototype.setBitmap = function(bitmap) {
  1106.   this.bitmap = new Bitmap(bitmap.width, bitmap.height);
  1107.   this.bitmap = bitmap;
  1108. }
  1109.  
  1110. Sprite_PT.prototype.update = function() {
  1111.   Sprite.prototype.update.call(this);
  1112.   if (this.opacity < 0) this.opacity = 0;
  1113.   if (this._dispose && this.opacity > 0) this.opacity -= (255 / YR.BattleSysPTB.disposeSpeedPTIcon);
  1114.   if (!this._dispose && this._half) {
  1115.     var alpha = this._flashOpacity;
  1116.     this.setBlendColor([255, 255, 255, alpha]);
  1117.   } else if (!this._dispose && !this._half) {
  1118.     this.setBlendColor([255, 255, 255, 0]);
  1119.   }
  1120. };
  1121.  
  1122. Sprite_Battery.prototype.update = function() {
  1123.   Sprite.prototype.update.call(this);
  1124.   if (this.opacity < 0) this.opacity = 0;
  1125.   if (this._dispose && this.opacity > 0) this.opacity -= (255 / YR.BattleSysPTB.disposeSpeedPTIcon);
  1126.   if (!this._dispose && this._half) {
  1127.     var alpha = this._flashOpacity;
  1128.     this.setBlendColor([255, 255, 255, alpha]);
  1129.   } else if (!this._dispose && !this._half) {
  1130.     this.setBlendColor([255, 255, 255, 0]);
  1131.   }
  1132. };
  1133.  
  1134.  
  1135. Scene_Battle.prototype.updatePTIcons = function() {
  1136.   if ((BattleManager.isTroopTurn() && this.unit === 'party') ||
  1137.       (!BattleManager.isTroopTurn() && this.unit === 'troop')) {
  1138.     this.setIconSprites();
  1139.   }
  1140.  
  1141.   if (this.unit === 'party') {
  1142.     var unit = $gameParty;
  1143.   } else {
  1144.     var unit = $gameTroop;
  1145.   }
  1146.  
  1147.   for (var i = 0; i < this.iconSprites.length; i++) {
  1148.     if (i >= unit.totalPTPool() && this.iconSprites[i].opacity > 0) {
  1149.       this.iconSprites[i]._dispose = true;
  1150.     } else if (i < unit.totalPTPool()) {
  1151.       this.iconSprites[i]._dispose = false;
  1152.       this.iconSprites[i].opacity = 255;
  1153.       if (i >= unit._PTPool) this.iconSprites[i]._half = true;
  1154.       else this.iconSprites[i]._half = false;
  1155.  
  1156.       this.iconSprites[i]._flashOpacity += (128 / YR.BattleSysPTB.flashSpeedPTIcon);
  1157.       if (this.iconSprites[i]._flashOpacity > 128) this.iconSprites[i]._flashOpacity = 0;
  1158.     }
  1159.   }
  1160. };
  1161.  
  1162. Scene_Battle.prototype.setIconSprites = function() {
  1163.   if (BattleManager.isTroopTurn()) this.unit = 'troop';
  1164.   else this.unit = 'party';
  1165.  
  1166.   if (this.unit === 'party') {
  1167.     var iconPT = ImageManager.loadSystem(YR.BattleSysPTB.partyPTIcon);
  1168.     var unit = $gameParty;
  1169.   } else {
  1170.     var iconPT = ImageManager.loadSystem(YR.BattleSysPTB.troopPTIcon);
  1171.     var unit = $gameTroop;
  1172.   }
  1173.   var iconBattery = ImageManager.loadSystem(YR.BattleSysPTB.batteryIcon);
  1174.  
  1175.   for (var i = 0; i < this.batterySprites.length; i++) {
  1176.     this.batterySprites[i].setBitmap(iconBattery);
  1177.     this.batterySprites[i].opacity = 0;
  1178.     var width = this.iconBattery[i].width;
  1179.     var height = this.iconBattery[i].height;
  1180.     var index = i;
  1181.     this.batterySprites[i].x = YR.BattleSysPTB.xPTIcon.call(this, width, height, index);
  1182.     this.batterySprites[i].y = YR.BattleSysPTB.yPTIcon.call(this, width, height, index);
  1183.     this.iconSprites[i]._dispose = false;
  1184.     this.iconSprites[i].opacity = 255;
  1185.   }
  1186.  
  1187.   for (var i = 0; i < this.iconSprites.length; i++) {
  1188.     this.iconSprites[i].setBitmap(iconPT);
  1189.     this.iconSprites[i].opacity = 0;
  1190.     var width = this.iconSprites[i].width;
  1191.     var height = this.iconSprites[i].height;
  1192.     var index = i;
  1193.     try {
  1194.       this.iconSprites[i].x = YR.BattleSysPTB.xPTIcon.call(this, width, height, index);
  1195.     } catch (e) {
  1196.       this.iconSprites[i].x = 0;
  1197.       Yanfly.Util.displayError(e, YR.BattleSysPTB.xPTIcon, 'PTB ICON X ERROR');
  1198.     }
  1199.     try {
  1200.       this.iconSprites[i].y = YR.BattleSysPTB.yPTIcon.call(this, width, height, index);
  1201.     } catch (e) {
  1202.       this.iconSprites[i].y = 0;
  1203.       Yanfly.Util.displayError(e, YR.BattleSysPTB.yPTIcon, 'PTB ICON Y ERROR');
  1204.     }
  1205.  
  1206.     if (i >= unit.totalPTPool()) {
  1207.       this.iconSprites[i]._dispose = true;
  1208.     } else {
  1209.       this.iconSprites[i]._dispose = false;
  1210.       this.iconSprites[i].opacity = 255;
  1211.       if (i >= unit._PTPool) this.iconSprites[i]._half = true;
  1212.       else this.iconSprites[i]._half = false;
  1213.  
  1214.     this.iconSprites[i]._flashOpacity = 0;
  1215.     this.batterySprites[i]._flashOpacity = 0;
  1216.     }
  1217.   }
  1218. }
  1219.  
  1220. YR.BattleSysPTB.Scene_Battle_createAllWindows = Scene_Battle.prototype.createAllWindows;
  1221. Scene_Battle.prototype.createAllWindows = function() {
  1222.   if (BattleManager.isPTB()) this.createPTIcons();
  1223.   YR.BattleSysPTB.Scene_Battle_createAllWindows.call(this);
  1224. };
  1225.  
  1226. Scene_Battle.prototype.createPTIcons = function() {
  1227.   this.flashOpacity = 0;
  1228.   this.unit = undefined;
  1229.   this.iconSprites = [];
  1230.   this.batterySprites = [];
  1231.   for (var i = 0; i < YR.BattleSysPTB.capPT; i++) {
  1232.     var iconPT = new Sprite_PT();
  1233.     this.iconSprites.push(iconPT);
  1234.     this.addChild(iconPT);
  1235.   }
  1236.   var iconBattery = new Sprite_Battery();
  1237.   this.batterySprites = [iconBattery]
  1238.   this.addChild(iconBattery);
  1239.   this.setIconSprites();
  1240. }
  1241.  
  1242. Scene_Battle.prototype.removePT = function() {
  1243.   for (var i = 0; i < this.iconSprites.length; i++) {
  1244.     this.iconSprites[i]._dispose = true;
  1245.     this.iconSprites[i].opacity = 0;
  1246.   }
  1247. }
  1248.  
  1249. YR.BattleSysPTB.Scene_Battle_update = Scene_Battle.prototype.update;
  1250. Scene_Battle.prototype.update = function() {
  1251.   if (BattleManager.isPTB()) this.updatePTIcons();
  1252.   YR.BattleSysPTB.Scene_Battle_update.call(this);
  1253. };
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260. } // Yanfly.BEC.version
  1261. }; // YEP_BattleEngineCore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement