Advertisement
ZainWD

Untitled

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