Advertisement
TamFey

TimedButtonAttacks

Feb 11th, 2016
2,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Timed Button Attacks v1.2.0
  3. // by TamFey
  4. // Last Update: 07.03.2016
  5. //=============================================================================
  6.  
  7. var TamFey = TamFey || {};
  8.  
  9. /*:
  10. * @plugindesc v1.2.0 - Adds a DDR-like minigame to the combat system.
  11. * @author TamFey
  12.  
  13. * @param hitSound
  14. * @desc the soundeffect that plays when you hit a button correctly.
  15. * @default Saint5
  16.  
  17. * @param missSound
  18. * @desc the soundeffect that plays when you hit a button too early or miss it entirely.
  19. * @default Buzzer1
  20.  
  21. * @param triggerAreaSize
  22. * @desc This is the size of the trigger area sprites.
  23. * @default 48
  24.  
  25. * @param triggerAreaXpos1
  26. * @desc The distance in pixels between the left border of the screen and the first TriggerArea.
  27. * @default 0
  28.  
  29. * @param triggerAreaXpos2
  30. * @desc The distance in pixels between the left border of the screen and the second TriggerArea.
  31. * @default 48
  32.  
  33. * @param triggerAreaXpos3
  34. * @desc The distance in pixels between the left border of the screen and the third TriggerArea.
  35. * @default 96
  36.  
  37. * @param triggerAreaXpos4
  38. * @desc The distance in pixels between the left border of the screen and the fourth TriggerArea.
  39. * @default 144
  40.  
  41. * @param popupPosX
  42. * @desc The distance in pixels between the left border of the screen and the Spawnpoint for Popups.
  43. * @default 0
  44.  
  45. * @param popupPosY
  46. * @desc The distance in pixels between the upper border of the screen and the Spawnpoint for Popups.
  47. * @default 400
  48.  
  49. * @param popupFontSize
  50. * @desc The font size for the "Hit!!!" and "Miss!" popups.
  51. * @default 35
  52.  
  53. * @param defaultPitch
  54. * @desc The pitch for hitSound and missSound.
  55. * @default 100
  56.  
  57. * @param defaultVolume
  58. * @desc The volume for hitSound and missSound.
  59. * @default 100
  60.  
  61. * @param disableHitAndMissSounds
  62. * @desc Disables 'Hit' and 'Miss' sounds for Custom Buttons.
  63. * true: sounds disabled - false: sounds enabled
  64. * @default false
  65.  
  66. * @param currentComboVariable
  67. * @desc The variable that is used to store the current combo counter.
  68. * @default 10
  69.  
  70. * @param maxComboVariable
  71. * @desc The variable that is used to store the highest combo that was achieved during the most recent action.
  72. * @default 11
  73.  
  74. * @param hitCounterVariable
  75. * @desc The variable that is used to store the number of buttons that were hit correctly during the most recent action.
  76. * @default 12
  77.  
  78. * @param showCurrentCombo
  79. * @desc true: show - false don't show
  80. * @default true
  81.  
  82. * @param showMaxCombo
  83. * @desc true: show - false don't show
  84. * @default true
  85.  
  86. * @param showHitCounter
  87. * @desc true: show - false don't show
  88. * @default true
  89.  
  90. * @param comboWindowX
  91. * @desc The distance in pixels between the left border of the screen and the combo window.
  92. * @default 0
  93.  
  94. * @param comboWindowY
  95. * @desc The distance in pixels between the upper border of the screen and the combo window.
  96. * @default 300
  97.  
  98. * @param comboFontSize
  99. * @desc The font size used for the combo window.
  100. * @default 28
  101.  
  102. * @param defaultDirection
  103. * @desc The default travel direction for timed buttons.
  104. * @default down
  105.  
  106. * @param enableTBASystem
  107. * @desc determines if the tba system is enabled by default.
  108. * @default true
  109.  
  110. * @help
  111. * ==============================================================================
  112. * Introduction
  113. * ==============================================================================
  114. * This plugin changes the way skills and items work in combat. Instead of just
  115. * starting an animation and an effect, skill/items will start a small minigame,
  116. * where icons appear on the top part of the screen. These icons move downwards
  117. * and when they reach a certain area, the player has to press the arrow keys.
  118. * The plugin will then start different animations and effects depending on whether
  119. * the player hit the button correctly or not.
  120. * ==============================================================================
  121. * Notetags
  122. * ==============================================================================
  123. * Skills/Items:
  124. *
  125. * <tba [type] [icon] [birthtime] [speed] [hitEffect] [missEffect]>
  126. * This notetag adds a button with the specified parameters to a skill/item.
  127. * [type] - 'up', 'down', 'left' or 'right'
  128. * determines the column that the button will appear in.
  129. * [icon] - the icon that is used for the button. (i.e. ArrowUp)
  130. * NOTE: Icons have to be located in the '/img/system/' folder of your project.
  131. * [birthtime] - The number of frames the game is going to wait before spawning the button.
  132. * the time is measured from the start of the action. (60 frames = 1 sec)
  133. * [speed] - The number of pixels the button is going to move every frame.
  134. * [hitEffect] - the ID of the skill that is used when the player hits the button.
  135. * [missEffect] - the ID of the skill that is used when the player misses the button.
  136. * NOTE: For details on hit/miss effects, see section 'Hit/Miss Effects' below.
  137. * IMPORTANT: Skills/items with at least one of these notetags will not process
  138. * action sequence notetags of the type 'whole actions' and 'target actions'.
  139. *
  140. * Example:
  141. * <tba up ArrowDown 110 3 5 11>
  142. * This notetag will create a button in the 'up' column. The button will have
  143. * the icon 'ArrowDown'. It will be spawned 110 frames after the action started
  144. * (~1.85 sec). It will move 3 pixels per frame. When the player hits it correctly,
  145. * skill #5 will be used, else skill #11 will be used.
  146. *
  147. * Randomness:
  148. * You can add randomness to the spawntimes of buttons by adding 'rX' at the end of
  149. * the notetag, where X is a positive integer.
  150. *
  151. * Randomness Example:
  152. * <tba down ArrowDown 1 2 4 12 r60>
  153. * this button will spawn sometimes between frame 1 and frame 61 of the attack.
  154. *
  155. * <tba no modifiers>
  156. * Speed modifiers don't apply to skill/items with this notetag.
  157. *
  158. * Equipment:
  159. *
  160. * <tba speed [operator] [value]>
  161. * Equipment pieces with this notetag modify the speed of all buttons as long as
  162. * the are worn.
  163. * [operator] - 'increase', 'decrease', 'divide' or 'multiply'.
  164. * determines how the speed will be modified.
  165. * [value] - determines how big the effect of the modifier is.
  166. * NOTE: No matter how many modifiers are applied to a button, its speed can't
  167. * become lower than 1.
  168. *
  169. * ==============================================================================
  170. * Hit/Miss Effects
  171. * ==============================================================================
  172. * NOTE: Hit and miss effects are processed the same way. The only difference is
  173. * that hit effects are called when the player hits a button correctly and miss
  174. * effects are called when the player hits the button too early or misses it
  175. * entirely.
  176. *
  177. * When a hit/miss effect is called, the plugin will read the notebox from the skill
  178. * with the appropriate ID (You can see an example in the 'notetags' section).
  179. * The plugin will then process and execute the action sequence notetags of the type
  180. * 'target actions' in that notebox.
  181. * NOTE: The plugin only reads the notetags of the effect skill. It will still use
  182. * the damage formula and other parameters of the skill that produced the button.
  183. * ==============================================================================
  184. * Combos
  185. * ==============================================================================
  186. * The plugin keeps track of the player's current combo, highest combo per battle
  187. * and the total amount of buttons the player hit per action. These values can be
  188. * displayed on the screen.
  189. * Combo values are also stored in variables for use in damage formulas and events.
  190. * ==============================================================================
  191. * Plugin Commands
  192. * ==============================================================================
  193. * 'TBA moveLeft [value]' - Moves the left column [value] pixels to the right.
  194. * 'TBA moveRight [value]' - Moves the right column [value] pixels to the right.
  195. * 'TBA moveUp [value]' - Moves the up column [value] pixels to the right.
  196. * 'TBA moveDown [value]' - Moves the down column [value] pixels to the right.
  197. * 'TBA setLeftX [value]' - Sets the left column's horizontal coordinate to [value].
  198. * 'TBA setRightX [value]' - Sets the right column's horizontal coordinate to [value].
  199. * 'TBA setUpX [value]' - Sets the up column's horizontal coordinate to [value].
  200. * 'TBA setDownX [value]' - Sets the down column's horizontal coordinate to [value].
  201. * 'TBA resetTriggerAreas' - Resets all column's horizontal coordinate to its default value.
  202. * 'TBA enable' - enables timed button attacks.
  203. * 'TBA disable' - disables timed button attacks.
  204. * NOTE: [value] can be negative.
  205. * ==============================================================================
  206. * Compatibility Notes
  207. * ==============================================================================
  208. * This plugin does not overwrite any functions.
  209. * This plugin alias the following functions:
  210. * - Game_Interpreter.prototype.pluginCommand
  211. * - DataManager.isDatabaseLoaded
  212. * - BattleManager.startAction
  213. * - BattleManager.update
  214. * - BattleManager.updatePhase
  215. * - BattleManager.endAction
  216. * - Scene_Battle.prototype.createDisplayObjects
  217. * - Scene_Battle.prototype.update
  218. * ==============================================================================
  219. * Changelog
  220. * ==============================================================================
  221. * Version 1.2.0:
  222. * -Added the possibility to change the direction that buttons travel.
  223. * -Added mouse/touch input.
  224. *
  225. * Version 1.1.0:
  226. * -Added the possibility to randomize button spawntimes.
  227. * -fixed issues with displaying the combo variables.
  228. *
  229. * Version 1.0.1:
  230. * -fixed enabling/disabling the plugin.
  231. *
  232. * Version 1.0:
  233. * -Plugin finished.
  234. */
  235. (function() {
  236.   TamFey.parameters = PluginManager.parameters('TimedButtonAttacks');
  237.   TamFey.param = TamFey.param || {};
  238.  
  239.   TamFey.param.hitSound = String(TamFey.parameters['hitSound']);
  240.   TamFey.param.missSound = String(TamFey.parameters['missSound']);
  241.   TamFey.param.triggerAreaSize = Number(TamFey.parameters['triggerAreaSize']);
  242.   TamFey.param.defaultPitch = Number(TamFey.parameters['defaultPitch']);
  243.   TamFey.param.defaultVolume = Number(TamFey.parameters['defaultVolume']);
  244.   TamFey.param.disableHitAndMissSounds = String(TamFey.parameters['disableHitAndMissSounds']);
  245.   TamFey.param.triggerAreaXpositions = [
  246.     Number(TamFey.parameters['triggerAreaXpos1']),
  247.     Number(TamFey.parameters['triggerAreaXpos2']),
  248.     Number(TamFey.parameters['triggerAreaXpos3']),
  249.     Number(TamFey.parameters['triggerAreaXpos4'])
  250.   ];
  251.   TamFey.param.popupPosX = Number(TamFey.parameters['popupPosX']);
  252.   TamFey.param.popupPosY = Number(TamFey.parameters['popupPosY']);
  253.   TamFey.param.popupFontSize = Number(TamFey.parameters['popupFontSize']);
  254.   TamFey.param.currentComboVariable = Number(TamFey.parameters['currentComboVariable']);
  255.   TamFey.param.maxComboVariable = Number(TamFey.parameters['maxComboVariable']);
  256.   TamFey.param.hitCounterVariable = Number(TamFey.parameters['hitCounterVariable']);
  257.   if (TamFey.parameters['showCurrentCombo'] == 'true') {
  258.     TamFey.param.showCurrentCombo = true;
  259.   } else {
  260.     TamFey.param.showCurrentCombo = false;
  261.   }
  262.   if (TamFey.parameters['showMaxCombo'] == 'true') {
  263.     TamFey.param.showMaxCombo = true;
  264.   } else {
  265.     TamFey.param.showMaxCombo = false;
  266.   }
  267.   if (TamFey.parameters['showHitCounter'] == 'true') {
  268.     TamFey.param.showHitCounter = true;
  269.   } else {
  270.     TamFey.param.showHitCounter = false;
  271.   }
  272.   TamFey.param.comboWindowX = Number(TamFey.parameters['comboWindowX']);
  273.   TamFey.param.comboWindowY = Number(TamFey.parameters['comboWindowY']);
  274.   TamFey.param.comboFontSize = Number(TamFey.parameters['comboFontSize']);
  275.   TamFey.param.travelDirection = String(TamFey.parameters['defaultDirection']);
  276.   if (TamFey.parameters['enableTBASystem'] == 'true' ) {
  277.     TamFey.param.tbaEnabled = true;
  278.   } else {
  279.     TamFey.param.tbaEnabled = false;
  280.   }
  281.  
  282.   var TamFey_TBA_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  283.   Game_Interpreter.prototype.pluginCommand = function(command, args) {
  284.     TamFey_TBA_Game_Interpreter_pluginCommand.call(this, command, args);
  285.     if (command === 'TBA') {
  286.       switch (args[0]) {
  287.         case 'moveLeft':
  288.           SceneManager._scene.moveTriggerArea('left', Number(args[1]));
  289.           break;
  290.         case 'moveDown':
  291.           SceneManager._scene.moveTriggerArea('down', Number(args[1]));
  292.           break;
  293.         case 'moveUp':
  294.           SceneManager._scene.moveTriggerArea('up', Number(args[1]));
  295.           break;
  296.         case 'moveRight':
  297.           SceneManager._scene.moveTriggerArea('right', Number(args[1]));
  298.           break;
  299.         case 'setLeftX':
  300.           SceneManager._scene.setTriggerAreaX('left', Number(args[1]));
  301.           break;
  302.         case 'setDownX':
  303.           SceneManager._scene.setTriggerAreaX('down', Number(args[1]));
  304.           break;
  305.         case 'setUpX':
  306.           SceneManager._scene.setTriggerAreaX('up', Number(args[1]));
  307.           break;
  308.         case 'setRightX':
  309.           SceneManager._scene.setTriggerAreaX('right', Number(args[1]));
  310.           break;
  311.         case 'resetTriggerAreas':
  312.           SceneManager._scene.resetTriggerAreaPositions();
  313.           break;
  314.         case 'enable':
  315.           BattleManager.enableTBA();
  316.           break;
  317.         case 'disable':
  318.           BattleManager.disableTBA();
  319.           break;
  320.       }
  321.     }
  322.   };
  323.  
  324.  
  325.   /*============================================================================
  326.   DataManager
  327.   ============================================================================*/
  328.   /*
  329.   (ALIAS)
  330.   parameters:
  331.   none.
  332.   Calls the functions that process this plugin's notetags when the database is loaded.
  333.   */
  334.   var TamFey_TBA_DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  335.   DataManager.isDatabaseLoaded = function() {
  336.     if (!TamFey_TBA_DataManager_isDatabaseLoaded.call(this)) return false;
  337.     this.processTBANotetags($dataSkills);
  338.     this.processTBANotetags($dataItems);
  339.     this.processTBAModifierNotetags($dataWeapons);
  340.     this.processTBAModifierNotetags($dataArmors);
  341.     return true;
  342.   };
  343.  
  344.   /*
  345.   parameters:
  346.   -group: An array of objects that belong to a certain group(e.g. skills)
  347.   This function reads the notetags of every object in the group, saves the attackButtons
  348.   in an array and determines if the object allows modifiers.
  349.   */
  350.   DataManager.processTBANotetags = function(group) {
  351.     for (var n = 1; n < group.length; n++) {
  352.       var obj = group[n];
  353.       var notedata = obj.note.split(/[\r\n]+/);
  354.  
  355.       obj.attackButtons = [];
  356.       obj.allowModifiers = true;
  357.  
  358.       for (var i = 0; i < notedata.length; i++) {
  359.         var line = notedata[i];
  360.         if (line.match(/<tba\s*no\s*modifiers>/i)) {
  361.           obj.allowModifiers = false;
  362.         }else if (line.match(/<tba\s*(\w*)\s*(\w*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*r?(\d*)>/i)) {
  363.           var attbtn = {};
  364.           if(RegExp.$1 == 'up'||RegExp.$1 == 'down'||RegExp.$1 == 'left'||RegExp.$1 == 'right') {
  365.             var btntype = RegExp.$1;
  366.           }
  367.  
  368.           var spritename =String(RegExp.$2)
  369.  
  370.           var birthtime = parseInt(RegExp.$3);
  371.  
  372.           var v = parseInt(RegExp.$4);
  373.  
  374.           var hitID = parseInt(RegExp.$5);
  375.  
  376.           var missID = parseInt(RegExp.$6);
  377.  
  378.           var sprite = new Sprite();
  379.  
  380.           var eff1 = group[hitID].targetActions;
  381.  
  382.           var eff2 = group[missID].targetActions;
  383.  
  384.           var randomAdd = 0;
  385.  
  386.           if (RegExp.$7) {
  387.             randomAdd = RegExp.$7;
  388.           }
  389.  
  390.           attbtn = {button:btntype, buttonname:spritename, spawntime:birthtime, speed:v, hitEffect:eff1, missEffect:eff2, btnsprite:sprite, random:randomAdd};
  391.           obj.attackButtons.push(attbtn);
  392.         }
  393.  
  394.       }
  395.     }
  396.   };
  397.  
  398.   /*
  399.   parameters:
  400.   -group: An array of objects that belong to a certain group(e.g. skills)
  401.   This function reads the notetags of every object in the group and determines
  402.   their speed modifier and speed multiplier.
  403.   */
  404.   DataManager.processTBAModifierNotetags = function(group) {
  405.     for (var n = 1; n < group.length; n++) {
  406.       var obj = group[n];
  407.       var notedata = obj.note.split(/[\r\n]+/);
  408.  
  409.       obj.speedMod = 0;
  410.       obj.speedMultiplier = 1;
  411.  
  412.       for (var i = 0; i < notedata.length; i++) {
  413.         var line = notedata[i];
  414.         if (line.match(/<tba\s*speed\s*(\w*)\s*(\d*)>/i)) {
  415.           var value;
  416.           value = parseInt(RegExp.$2);
  417.           switch (RegExp.$1) {
  418.             case 'decrease':
  419.               value *= -1;
  420.               obj.speedMod += value;
  421.               break;
  422.             case 'multiply':
  423.               obj.speedMultiplier *= value;
  424.               break;
  425.             case 'divide':
  426.               obj.speedMultiplier /= value;
  427.               break;
  428.             default:
  429.  
  430.           }
  431.  
  432.         }
  433.       }
  434.     }
  435.   };
  436.  
  437.  
  438.   /*============================================================================
  439.   BattleManager
  440.   ============================================================================*/
  441.  
  442.   var TamFey_TBA_BattleManager_startBattle = BattleManager.startBattle;
  443.   BattleManager.startBattle = function() {
  444.     TamFey_TBA_BattleManager_startBattle.call(this);
  445.     SceneManager._scene.resetComboVariables();
  446.   };
  447. /*
  448. (ALIAS)
  449. parameters:
  450. -none.
  451. Initializes the variables needed for the action. If the action uses AttackButtons,
  452. it also removes the 'whole' and 'target' action phases, as they are not needed.
  453. */
  454.   var TamFey_TBA_BattleManager_startAction = BattleManager.startAction;
  455.   BattleManager.startAction = function() {
  456.     this.allowTBAInputs = false;
  457.     this.battleTimeCounter = 0;
  458.     this.initializeTBAVariables();
  459.     TamFey_TBA_BattleManager_startAction.call(this);
  460.     if (TamFey.param.tbaEnabled == true && this._action.item().attackButtons.length >= 1) {
  461.       SceneManager._scene.remainingAttackButtons = this._action.item().attackButtons.slice();
  462.       SceneManager._scene.calculateSpawntimes();
  463.       this.allowTBAInputs = true;
  464.       this._phaseSteps = ['setup', 'follow', 'finish'];
  465.     }
  466.   };
  467.  
  468.   /*
  469.   parameters:
  470.   -none.
  471.   Initializes the variables that are needed for TBA actions.
  472.   */
  473.   BattleManager.initializeTBAVariables = function() {
  474.     SceneManager._scene.tbaActions = [];
  475.     SceneManager._scene.remainingAttackButtons = [];
  476.     SceneManager._scene.activeAttackButtons = [];
  477.     SceneManager._scene.activeTriggeredSprites = [];
  478.     SceneManager._scene.activePopupWindows = [];
  479.     SceneManager._scene.activePopupSprites = [];
  480.     SceneManager._scene.tbaSoundPitch = TamFey.param.defaultPitch;
  481.     SceneManager._scene.tbaCombo = 0;
  482.     SceneManager._scene.resetComboVariables();
  483.   };
  484.  
  485.   BattleManager.enableTBA = function() {
  486.     TamFey.param.tbaEnabled = true;
  487.   };
  488.  
  489.   BattleManager.disableTBA = function() {
  490.     TamFey.param.tbaEnabled = false;
  491.   };
  492.  
  493.   /*
  494.   (ALIAS)
  495.   parameters:
  496.   -none.
  497.   Checks whether the current action has attackButtons assigned. If so, the function calls
  498.   checkForButtonSpawns, moves active attackButtons and checks for input from the player.
  499.   */
  500.   var TamFey_TBA_BattleManager_update = BattleManager.update;
  501.   BattleManager.update = function() {
  502.     this.battleTimeCounter += 1;
  503.     TamFey_TBA_BattleManager_update.call(this);
  504.     if (TamFey.param.tbaEnabled == true && this._action && this._action.item().attackButtons.length >= 1) {
  505.       this.updateTBAActions();
  506.       this.checkForButtonSpawns(this.battleTimeCounter);
  507.       SceneManager._scene.moveAllActiveButtons();
  508.       SceneManager._scene.checkForTBAInput();
  509.       SceneManager._scene.updateActiveTriggeredSprites();
  510.     }
  511.   };
  512.  
  513.   /*
  514.   parameters:
  515.   -attackTime: Time passed since the start of the action.
  516.   This function checks if the current action has buttons with a spawntime equals to 'attackTime'.
  517.   If so, it will spawn that button and remove it from the remaining buttons.
  518.   */
  519.   BattleManager.checkForButtonSpawns = function(attackTime) {
  520.     SceneManager._scene.remainingAttackButtons.forEach(function(btn, i, o) {
  521.       if (btn.spawntime == attackTime) {
  522.         SceneManager._scene.spawnButton(btn);
  523.         SceneManager._scene.removeFromRemainingButtons(btn);
  524.       }
  525.     });
  526.   };
  527.  
  528.   /*
  529.   (ALIAS)
  530.   parameters:
  531.   -none.
  532.   Calls TBAPhaseIsEndable to determine whether the current phase can be ended.
  533.   This is done, so 'follow' and 'finish' actions are only called after all
  534.   attack buttons have been processed.
  535.   */
  536.   TamFey_TBA_BattleManager_updatePhase = BattleManager.updatePhase;
  537.   BattleManager.updatePhase = function() {
  538.     if(this._phaseSteps[0] === 'follow' && !this.TBAPhaseIsEndable() ) return;
  539.     TamFey_TBA_BattleManager_updatePhase.call(this);
  540.   };
  541.  
  542.   /*
  543.   (ALIAS)
  544.   parameters:
  545.   -none.
  546.   Prevents the end of the action until there are no more attack buttons left.
  547.   */
  548.   TamFey_TBA_BattleManager_endAction = BattleManager.endAction;
  549.   BattleManager.endAction = function() {
  550.     if (this._action.item().attackButtons.length >= 1) {
  551.       if ( !this.TBAPhaseIsEndable() ) {
  552.         return;
  553.       }
  554.     }
  555.     this.allowTBAInputs = false;
  556.     TamFey_TBA_BattleManager_endAction.call(this);
  557.   };
  558.  
  559.   /*
  560.   parameters:
  561.   -none.
  562.   Checks if activeAttackButtons, remainingAttackButtons and activeTriggeredSprites are empty.
  563.   */
  564.   BattleManager.TBAPhaseIsEndable = function() {
  565.     if (SceneManager._scene.remainingAttackButtons.length >= 1) return false;
  566.     if (SceneManager._scene.activeAttackButtons.length >= 1) return false;
  567.     if (SceneManager._scene.activeTriggeredSprites.length >= 1) return false;
  568.     return true;
  569.   };
  570.  
  571.   /*
  572.   parameters:
  573.   -none.
  574.   Processes the action sequence notetags of all active TBA actions.
  575.   */
  576.   BattleManager.updateTBAActions = function() {
  577.     if (SceneManager._scene.tbaActions.length <= 0) return;
  578.     SceneManager._scene.tbaActions.forEach(function(actionl, i, o) {
  579.       var actseq = actionl.shift();
  580.       if (actseq) {
  581.         var seqName = actseq[0].toUpperCase();
  582.         BattleManager.processActionSequence(seqName,actseq[1])
  583.       }
  584.     });
  585.   };
  586.  
  587.  
  588.   /*============================================================================
  589.   Scene_Battle
  590.   ============================================================================*/
  591.   /*
  592.   (ALIAS)
  593.   parameters:
  594.   -none.
  595.   Creates objects that have to be created at battle start.
  596.   */
  597.   var TamFey_TBA_Scene_Battle_createDisplayObjects = Scene_Battle.prototype.createDisplayObjects;
  598.   Scene_Battle.prototype.createDisplayObjects = function() {
  599.     TamFey_TBA_Scene_Battle_createDisplayObjects.call(this);
  600.     if(TamFey.param.tbaEnabled == true) {
  601.       this.createTriggerAreas();
  602.       this.createComboWindow();
  603.     }
  604.   };
  605.  
  606.  
  607.   /*
  608.   parameters:
  609.   -none.
  610.   Creates four sprites that indicate the keys the player has to press in order to
  611.   activate the buttons in the same column.
  612.   */
  613.   Scene_Battle.prototype.createTriggerAreas = function() {
  614.     this.triggerAreaSprites = [];
  615.     var spriteSize = TamFey.param.triggerAreaSize;
  616.     var numberOfTriggerAreas = 4;
  617.     for(i = 0; i < numberOfTriggerAreas; i++) {
  618.       var sprite;
  619.       var area;
  620.       var areaX;
  621.       var areaY;
  622.       var rect;
  623.       var triggerTrack;
  624.       switch (i) {
  625.         case 0:
  626.           sprite = new Sprite(ImageManager.loadSystem("TriggerArrowLeft"));
  627.           break;
  628.         case 1:
  629.           sprite = new Sprite(ImageManager.loadSystem("TriggerArrowDown"));
  630.           break;
  631.         case 2:
  632.           sprite = new Sprite(ImageManager.loadSystem("TriggerArrowUp"));
  633.           break;
  634.         case 3:
  635.           sprite = new Sprite(ImageManager.loadSystem("TriggerArrowRight"));
  636.           break;
  637.         default:
  638.  
  639.       }
  640.       switch (TamFey.param.travelDirection) {
  641.         case 'up':
  642.           areaY = spriteSize;
  643.           break;
  644.         case 'down':
  645.           areaY = Graphics.height - (spriteSize + this._partyCommandWindow.height);
  646.           break;
  647.         default:
  648.           areaY = Graphics.height - (spriteSize + this._partyCommandWindow.height);
  649.       }
  650.  
  651.       sprite.x = TamFey.param.triggerAreaXpositions[i];
  652.       sprite.y = areaY;
  653.  
  654.  
  655.       areaX = sprite.x;
  656.  
  657.       triggerTrack = this.createTriggerAreaTrack(areaX);
  658.  
  659.       area = {areasprite:sprite, track:triggerTrack, xpos:areaX, ypos:areaY};
  660.       this.triggerAreaSprites.push(area);
  661.       this.addChild(sprite);
  662.     }
  663.   };
  664.  
  665.   /*
  666.   parameters:
  667.   -areaX: An Integer that determines the x position of the trigger track.
  668.   Creates a 'track' at the desired position. During actions active attack
  669.   buttons will move on the track.
  670.   */
  671.   Scene_Battle.prototype.createTriggerAreaTrack = function(areaX) {
  672.     var track;
  673.     var trackX;
  674.     var trackY = 0;
  675.     var trackWidth;
  676.     var trackHeight;
  677.     var trackBitmap;
  678.     var trackOffset = 3;
  679.     var trackColor = Utils.rgbToCssColor(40, 37, 43);
  680.     var trackOpacity = 125;
  681.  
  682.     trackX = areaX + trackOffset;
  683.     trackWidth = TamFey.param.triggerAreaSize - (trackOffset * 2);
  684.     trackHeight = Graphics.height - this._partyCommandWindow.height;
  685.     trackBitmap = new Bitmap(trackWidth, trackHeight);
  686.     trackBitmap.fillAll(trackColor);
  687.     track = new Sprite(trackBitmap);
  688.     track.opacity = trackOpacity;
  689.     track.x = trackX;
  690.     track.y = trackY;
  691.     track.z = 0;
  692.     this._spriteset.addChild(track);
  693.     return track;
  694.   };
  695.  
  696.   /*
  697.   parameters:
  698.   -attbtn: An object that describes a button.
  699.   This function creates a sprite for the passed attackButton.
  700.   */
  701.   Scene_Battle.prototype.spawnButton = function(attbtn) {
  702.     var buttonSprite;
  703.     var buttonColumn = 0;
  704.     var buttonY;
  705.     var spriteSize = TamFey.param.triggerAreaSize;
  706.  
  707.     if (attbtn.button == "left") {
  708.  
  709.     }else if (attbtn.button == "down") {
  710.       buttonColumn = 1;
  711.     }else if (attbtn.button == "up") {
  712.       buttonColumn = 2;
  713.     }else if (attbtn.button == "right") {
  714.       buttonColumn = 3;
  715.     }
  716.     switch (TamFey.param.travelDirection) {
  717.       case 'up':
  718.         buttonY = Graphics.height - (spriteSize + this._partyCommandWindow.height);
  719.         break;
  720.       case 'down':
  721.         buttonY = 0;
  722.         break;
  723.       default:
  724.         buttonY = 0;
  725.     }
  726.  
  727.     buttonSprite = new Sprite(ImageManager.loadSystem(attbtn.buttonname));
  728.  
  729.     attbtn.btnsprite = buttonSprite;
  730.  
  731.     buttonSprite.x = TamFey.param.triggerAreaXpositions[buttonColumn];
  732.     buttonSprite.y = buttonY;
  733.     this.addChild(buttonSprite);
  734.     this.activeAttackButtons.push(attbtn);
  735.  
  736.   };
  737.  
  738.   /*
  739.   parameters:
  740.   -none.
  741.   Iterates through all active attack buttons and moves them. Afterwards this checks if the button has to be removed.
  742.   */
  743.   Scene_Battle.prototype.moveAllActiveButtons = function() {
  744.     this.activeAttackButtons.forEach( function(attbtn, i, o) {
  745.       SceneManager._scene.moveButtonSprite(attbtn.btnsprite, attbtn.speed);
  746.       SceneManager._scene.checkForButtonRemove(attbtn);
  747.     });
  748.   };
  749.  
  750.   /*
  751.   parameters:
  752.   -sprite: The sprite of an attackButton.
  753.   -speed: The speed the button is supposed to be moved at.
  754.   This function moves the passed attackButton by [speed] pixels in the y-direction.
  755.   */
  756.   Scene_Battle.prototype.moveButtonSprite = function(sprite, speed) {
  757.     var distance = speed;
  758.     var distanceMultiplier = 1;
  759.     if(BattleManager._action.item().allowModifiers) {
  760.       $gameActors._data.forEach( function (actr, i, o) {
  761.         actr.equips().forEach( function(equ, i, o) {
  762.           if (equ) distance += equ.speedMod;
  763.           if (equ) distanceMultiplier *= equ.speedMultiplier;
  764.         });
  765.       });
  766.       distance *= distanceMultiplier;
  767.     }
  768.     if (distance < 1) distance = 1;
  769.     switch (TamFey.param.travelDirection) {
  770.       case 'up':
  771.         sprite.y -= distance;
  772.         break;
  773.       case 'down':
  774.         sprite.y += distance;
  775.         break;
  776.       default:
  777.         sprite.y += distance;
  778.     }
  779.  
  780.   };
  781.  
  782.   /*
  783.   parameters:
  784.   -startingPos: An Integer, default position of the buttons that will be moved.
  785.   -distance:An Integer, amount of pixels the buttons will be moved.
  786.   Takes all active buttons at position 'startingPos' and moves them 'distance' pixels to the right.
  787.   */
  788.   Scene_Battle.prototype.adjustButtonXposition = function(startingPos, distance) {
  789.     this.activeAttackButtons.forEach( function(attbtn, i, o) {
  790.       if (attbtn.btnsprite.x == startingPos) {
  791.         attbtn.btnsprite.x += distance;
  792.       }
  793.     });
  794.   };
  795.  
  796.   /*
  797.   parameters:
  798.   -startingPos: An Integer, default position of the buttons that will be moved.
  799.   -newPos:An Integer, new position for the moved buttons.
  800.   Takes all active buttons at position 'startingPos' and moves them to 'newPos'.
  801.   */
  802.   Scene_Battle.prototype.setButtonXposition = function(startingPos, newPos) {
  803.     this.activeAttackButtons.forEach( function(attbtn, i, o) {
  804.       if (attbtn.btnsprite.x == startingPos) {
  805.         attbtn.btnsprite.x = newPos;
  806.       }
  807.     });
  808.   };
  809.  
  810.   /*
  811.   parameters:
  812.   -area: A String ('up', 'down', 'left' or 'right')
  813.   -distance: An Integer
  814.   Takes the triggerArea 'area' and moves it 'distance' pixels to the right.
  815.   */
  816.   Scene_Battle.prototype.moveTriggerArea = function(area, distance) {
  817.     var target;
  818.     var triggerTrackOffset = 3;
  819.     var buttonXpos = 0;
  820.     switch (area) {
  821.       case 'left':
  822.         target = this.triggerAreaSprites[0];
  823.         TamFey.param.triggerAreaXpositions[0] += distance;
  824.         break;
  825.       case 'down':
  826.         target = this.triggerAreaSprites[1];
  827.         TamFey.param.triggerAreaXpositions[1] += distance;
  828.         break;
  829.       case 'up':
  830.         target = this.triggerAreaSprites[2];
  831.         TamFey.param.triggerAreaXpositions[2] += distance;
  832.         break;
  833.       case 'right':
  834.         target = this.triggerAreaSprites[3];
  835.         TamFey.param.triggerAreaXpositions[3] += distance;
  836.         break;
  837.       default:
  838.  
  839.     }
  840.     buttonXpos = target.xpos;
  841.     target.xpos += distance;
  842.     target.areasprite.x = target.xpos;
  843.     target.track.x = target.xpos + triggerTrackOffset;
  844.     this.adjustButtonXposition(buttonXpos, distance);
  845.   };
  846.  
  847.   /*
  848.   parameters:
  849.   -area: A String ('up', 'down', 'left' or 'right')
  850.   -position: An Integer
  851.   Takes the triggerArea 'area' and moves it to position 'position'.
  852.   */
  853.   Scene_Battle.prototype.setTriggerAreaX = function(area, position) {
  854.     var target;
  855.     var triggerTrackOffset = 3;
  856.     var buttonXpos = 0;
  857.     switch (area) {
  858.       case 'left':
  859.         target = this.triggerAreaSprites[0];
  860.         TamFey.param.triggerAreaXpositions[0] = position;
  861.         break;
  862.       case 'down':
  863.         target = this.triggerAreaSprites[1];
  864.         TamFey.param.triggerAreaXpositions[1] = position;
  865.         break;
  866.       case 'up':
  867.         target = this.triggerAreaSprites[2];
  868.         TamFey.param.triggerAreaXpositions[2] = position;
  869.         break;
  870.       case 'right':
  871.         target = this.triggerAreaSprites[3];
  872.         TamFey.param.triggerAreaXpositions[3] = position;
  873.         break;
  874.       default:
  875.  
  876.     }
  877.     buttonXpos = target.xpos;
  878.     target.xpos = position;
  879.     target.areasprite.x = target.xpos;
  880.     target.track.x = target.xpos + triggerTrackOffset;
  881.     this.setButtonXposition(buttonXpos, position);
  882.   };
  883.  
  884.   /*
  885.   parameters:
  886.   -none.
  887.   Resets the positions of all TriggerAreas.
  888.   */
  889.   Scene_Battle.prototype.resetTriggerAreaPositions = function() {
  890.     var target;
  891.     var triggerTrackOffset = 3;
  892.     TamFey.param.triggerAreaXpositions = [
  893.       Number(TamFey.parameters['triggerAreaXpos1']),
  894.       Number(TamFey.parameters['triggerAreaXpos2']),
  895.       Number(TamFey.parameters['triggerAreaXpos3']),
  896.       Number(TamFey.parameters['triggerAreaXpos4'])
  897.     ];
  898.     this.triggerAreaSprites.forEach( function(tArea, i, o) {
  899.       var buttonXpos = 0;
  900.       buttonXpos = target.xpos;
  901.       target.xpos = TamFey.param.triggerAreaXpositions[i];
  902.       target.areasprite.x = target.xpos;
  903.       target.track.x = target.xpos + triggerTrackOffset;
  904.       this.setButtonXposition(buttonXpos, position);
  905.     });
  906.   };
  907.  
  908.   Scene_Battle.prototype.calculateSpawntimes = function() {
  909.     this.remainingAttackButtons.forEach( function(atkbtn, i, o) {
  910.       var add = Math.randomInt(atkbtn.random);
  911.       atkbtn.spawntime += add;
  912.     });
  913.   };
  914.  
  915.   /*
  916.   parameters:
  917.   -attbtn: An object that describes an attackButton.
  918.   Checks if the button has moved past the triggerArea.
  919.   If so, it's passed to the reomveButton function.
  920.   */
  921.   Scene_Battle.prototype.checkForButtonRemove = function(attbtn) {
  922.     if (this.buttonIsPastTriggerArea(attbtn)) {
  923.       if( !(TamFey.param.disableHitAndMissSounds && this.buttonIsCustom(attbtn)) ) this.playTBASound(TamFey.param.missSound);
  924.       var missActions = attbtn.missEffect.slice();
  925.       this.tbaActions.push(missActions);
  926.       this.createTriggeredWrongSprite(attbtn.btnsprite.x);
  927.       this.createMissWindow();
  928.       this.removeButton(attbtn);
  929.       this.tbaCombo = 0;
  930.       this.resetComboVariables();
  931.     }
  932.   };
  933.  
  934.   Scene_Battle.prototype.buttonIsPastTriggerArea = function(attbtn) {
  935.     switch (TamFey.param.travelDirection) {
  936.       case 'up':
  937.         if (attbtn.btnsprite.y <= (TamFey.param.triggerAreaSize / 2)) {
  938.           return true;
  939.         } else {
  940.           return false;
  941.         }
  942.         break;
  943.       case 'down':
  944.         if (attbtn.btnsprite.y >= (Graphics.height - this._partyCommandWindow.height)) {
  945.           return true;
  946.         } else {
  947.           return false;
  948.         }
  949.         break;
  950.       default:
  951.         return false;
  952.     }
  953.   };
  954.  
  955.  
  956.   /*
  957.   parameters:
  958.   -attbtn: An object that describes an attackButton.
  959.   Reomves the passed button from activeAttackButtons, deletes it and reomves its sprite.
  960.   */
  961.   Scene_Battle.prototype.removeButton = function(attbtn) {
  962.     var arr = [];
  963.     var btnIndex = this.activeAttackButtons.indexOf(attbtn);
  964.     this.removeChild(attbtn.btnsprite);
  965.     arr = this.activeAttackButtons.slice(0, btnIndex).concat( this.activeAttackButtons.slice(btnIndex + 1) );
  966.     this.activeAttackButtons = arr;
  967.     delete attbtn;
  968.   };
  969.  
  970.  
  971.   /*
  972.   parameters:
  973.   -attbtn: An object that describes an attackButton.
  974.   Reomves the passed button from remainingAttackButtons.
  975.   */
  976.   Scene_Battle.prototype.removeFromRemainingButtons = function(attbtn) {
  977.     var arr = [];
  978.     var btnIndex = this.remainingAttackButtons.indexOf(attbtn);
  979.     arr = this.remainingAttackButtons.slice(0, btnIndex).concat( this.remainingAttackButtons.slice(btnIndex + 1) );
  980.     this.remainingAttackButtons = arr;
  981.   };
  982.  
  983.   Scene_Battle.prototype.buttonIsCustom = function(attbtn) {
  984.     var isCustom = true;
  985.     if (attbtn.buttonname == "ArrowUp") isCustom = false;
  986.     if (attbtn.buttonname == "ArrowDown") isCustom = false;
  987.     if (attbtn.buttonname == "ArrowLeft") isCustom = false;
  988.     if (attbtn.buttonname == "ArrowRight") isCustom = false;
  989.     return isCustom;
  990.   };
  991.  
  992.   /*
  993.   parameters:
  994.   -none.
  995.   Checks if any of the arrow keys are pressed.
  996.   If so, it calls triggerTriggerArea.
  997.   Only works when there are active attackButtons.
  998.   */
  999.   Scene_Battle.prototype.checkForTBAInput = function() {
  1000.     if (this.activeAttackButtons.length < 1) return;
  1001.     var touchIsPressed = false;
  1002.     var touchedX = 0;
  1003.     var touchedY = 0;
  1004.     //TODO die boolean variablen durch ein array ersetzen und checkForPressedLeft in checkForPressedAreas umschreiben.
  1005.     var pressedDirections = [false, false, false, false]//left, down, up, right
  1006.     /*var pressedLeft = false;
  1007.     var pressedDown = false;
  1008.     var pressedUp = false;
  1009.     var pressedRight = false;*/
  1010.     if ( TouchInput.isPressed() ){
  1011.       touchIsPressed = true;
  1012.       touchedX = TouchInput.x;
  1013.       touchedY = TouchInput.y;
  1014.       pressedDirections = this.checkForPressedAreas(touchedX, touchedY);
  1015.       console.log("Touch X: " + touchedX + ", Touch Y: " + touchedY);
  1016.     }
  1017.     if( Input.isTriggered('left') || pressedDirections[0] == true) {
  1018.       this.triggerTriggerArea('left');
  1019.     }
  1020.     if (Input.isTriggered('down') || pressedDirections[1] == true) {
  1021.       this.triggerTriggerArea('down');
  1022.     }
  1023.     if (Input.isTriggered('up') || pressedDirections[2] == true) {
  1024.       this.triggerTriggerArea('up');
  1025.     }
  1026.     if (Input.isTriggered('right') || pressedDirections[3] == true) {
  1027.       this.triggerTriggerArea('right');
  1028.     }
  1029.   };
  1030.  
  1031.   Scene_Battle.prototype.checkForPressedAreas = function(x, y) {
  1032.     var pressedDirections = [false, false, false, false]//left, down, up, right
  1033.     var areaSize = TamFey.param.triggerAreaSize;
  1034.     for (var i = 0; i < pressedDirections.length; i++) {
  1035.       var areaX = TamFey.param.triggerAreaXpositions[i];
  1036.       var areaY = this.triggerAreaSprites[i].areasprite.y;
  1037.       pressedDirections[i] = ( (x >= areaX) && (x <= (areaX + areaSize)) && (y >= areaY) && (y <= (areaY + areaSize)))
  1038.     }
  1039.     console.log(pressedDirections);
  1040.     return pressedDirections;
  1041.   };
  1042.  
  1043.   /*
  1044.   parameters:
  1045.   -dir: A String ('left', 'down', 'up' or 'right')
  1046.   This function determines size and position of the desired trigger area,
  1047.   creates a 'triggered' sprite at its position and calls checkForButtonsWithinArea.
  1048.   */
  1049.   Scene_Battle.prototype.triggerTriggerArea = function(dir) {
  1050.     var areaSize = TamFey.param.triggerAreaSize;
  1051.     var areaX = 0;
  1052.     var areaY = 0; //Graphics.height - (areaSize + this._partyCommandWindow.height);
  1053.     switch (dir) {
  1054.       case "left":
  1055.         areaX = TamFey.param.triggerAreaXpositions[0];
  1056.         areaY = this.triggerAreaSprites[0].areasprite.y;
  1057.         break;
  1058.       case "down":
  1059.         areaX = TamFey.param.triggerAreaXpositions[1];
  1060.         areaY = this.triggerAreaSprites[1].areasprite.y;
  1061.         break;
  1062.       case "up":
  1063.         areaX = TamFey.param.triggerAreaXpositions[2];
  1064.         areaY = this.triggerAreaSprites[2].areasprite.y;
  1065.         break;
  1066.       case "right":
  1067.         areaX = TamFey.param.triggerAreaXpositions[3];
  1068.         areaY = this.triggerAreaSprites[3].areasprite.y;
  1069.         break;
  1070.       default:
  1071.         areaX = 0;
  1072.  
  1073.     }
  1074.     this.createTriggeredSprite("Triggered", areaX);
  1075.     this.checkForButtonsWithinArea(areaX, areaY, areaSize);
  1076.  
  1077.   };
  1078.  
  1079.   /*
  1080.   parameters:
  1081.   -x: An Integer
  1082.   -y: An Integer
  1083.   -size: An Integer
  1084.   This function checks if there are active attack buttons within the target area.
  1085.   If so, it creates a TriggeredCorrect sprite and removes the button.
  1086.   If not, the function calls processNoButtonHit.
  1087.   */
  1088.   Scene_Battle.prototype.checkForButtonsWithinArea = function(x, y, size) {
  1089.     var upperBorder = y - (size / 4);
  1090.     var lowerBorder = y + size;
  1091.     var buttonWasHit = false;
  1092.     this.activeAttackButtons.forEach(function(btn, i, o){
  1093.  
  1094.       if ( (btn.btnsprite.x == x) && (btn.btnsprite.y >= upperBorder) && (btn.btnsprite.y <= lowerBorder) ) {
  1095.         if( !(TamFey.param.disableHitAndMissSounds && SceneManager._scene.buttonIsCustom(btn)) ) SceneManager._scene.playTBASound(TamFey.param.hitSound);
  1096.         var hitActions = btn.hitEffect.slice();
  1097.         SceneManager._scene.tbaActions.push(hitActions);
  1098.         SceneManager._scene.createTriggeredCorrectSprite(x);
  1099.         SceneManager._scene.createHitWindow();
  1100.         SceneManager._scene.removeButton(btn);
  1101.         SceneManager._scene.tbaCombo += 1;
  1102.         SceneManager._scene.updateComboVariables(SceneManager._scene.tbaCombo);
  1103.         buttonWasHit = true;
  1104.       }
  1105.     });
  1106.     if (!buttonWasHit && ( this.buttonsInColumnExist(x) )) {
  1107.       this.processNoButtonHit(x, upperBorder);
  1108.     }
  1109.   };
  1110.  
  1111.   /*
  1112.   parameters:
  1113.   -x: An Integer
  1114.   This function checks, if any of the active attack buttons has the passed
  1115.   x-position.
  1116.   */
  1117.   Scene_Battle.prototype.buttonsInColumnExist = function(x) {
  1118.     var buttonsExist = false;
  1119.     this.activeAttackButtons.forEach(function(btn, i, o){
  1120.       if(btn.btnsprite.x == x){
  1121.         buttonsExist = true;
  1122.       }
  1123.     });
  1124.     return buttonsExist;
  1125.   };
  1126.  
  1127.   /*
  1128.   parameters:
  1129.   -x: An Integer
  1130.   -upperBorder: An Integer. Buttons with an y-position higher than this will be processed.
  1131.   This function looks for the button with the highest y-position that has the passed x-position.
  1132.   That button is then removed and the function creates a miss! message and updates the combo variables.
  1133.   */
  1134.   Scene_Battle.prototype.processNoButtonHit = function(x, upperBorder) {
  1135.     var closestButton;
  1136.     var closestY = 0;
  1137.     this.activeAttackButtons.forEach(function(btn, i, o){
  1138.       if ( this.buttonIsInFrontOfTriggerArea(btn, x, upperBorder) ) {
  1139.         var distance;
  1140.         distance = this.calculateDistanceToTriggerArea(btn);
  1141.         if ((distance < closestY) || (closestY == 0)) {
  1142.           closestButton = btn;
  1143.           closestY = btn.btnsprite.y;
  1144.         }
  1145.       }
  1146.     });
  1147.     if( !(TamFey.param.disableHitAndMissSounds && this.buttonIsCustom(closestButton)) ) this.playTBASound(TamFey.param.missSound);
  1148.     var missActions = closestButton.missEffect.slice();
  1149.     SceneManager._scene.tbaActions.push(missActions);
  1150.     SceneManager._scene.createTriggeredWrongSprite(x);
  1151.     SceneManager._scene.createMissWindow();
  1152.     SceneManager._scene.removeButton(closestButton);
  1153.     SceneManager._scene.tbaCombo = 0;
  1154.     SceneManager._scene.updateComboVariables(SceneManager._scene.tbaCombo);
  1155.   };
  1156.  
  1157.   Scene_Battle.prototype.buttonIsInFrontOfTriggerArea = function(btn, x, border) {
  1158.     var isInFront;
  1159.     switch (TamFey.param.travelDirection) {
  1160.       case 'up':
  1161.         if ( (btn.btnsprite.x == x) && (btn.btnsprite.y <= border) ) isInFront = true;
  1162.         break;
  1163.       case 'down':
  1164.         if ( (btn.btnsprite.x == x) && (btn.btnsprite.y >= border) ) isInFront = true;
  1165.         break;
  1166.       default:
  1167.         isInFront = false;
  1168.     }
  1169.     return isInFront;
  1170.   };
  1171.  
  1172.   //NOTE This doesn't actually calculate the distance to the trigger area, but rather the distance to the window border.
  1173.   Scene_Battle.prototype.calculateDistanceToTriggerArea = function(btn) {
  1174.     var distance = 0;
  1175.     switch (TamFey.param.travelDirection) {
  1176.       case 'up':
  1177.         distance = btn.btnsprite.y;
  1178.         break;
  1179.       case 'down':
  1180.         distance = Graphics.height - btn.btnsprite.y;
  1181.         break;
  1182.       default:
  1183.         isInFront = false;
  1184.     }
  1185.     return distance;
  1186.   };
  1187.  
  1188.   /*
  1189.   parameters:
  1190.   -x: An Integer
  1191.   -name: A String
  1192.   This function creates a sprite and adds it to the activeTriggeredSprites.
  1193.   The sprite will be determined by the passed name.
  1194.   */
  1195.   Scene_Battle.prototype.createTriggeredSprite = function(name, x) {
  1196.     var triggeredSprite;
  1197.     var spriteColumn = x;
  1198.     var spriteSize = TamFey.param.triggerAreaSize;
  1199.     var spriteLifeTime = 8;
  1200.     var spriteY = 0;
  1201.     var trig;
  1202.  
  1203.     triggeredSprite = new Sprite(ImageManager.loadSystem(name));
  1204.     triggeredSprite.x = spriteColumn;
  1205.     switch (TamFey.param.travelDirection) {
  1206.       case 'up':
  1207.         spriteY = spriteSize;
  1208.         break;
  1209.       case 'down':
  1210.         spriteY = Graphics.height - (spriteSize + this._partyCommandWindow.height);
  1211.         break;
  1212.       default:
  1213.         spriteY = Graphics.height - (spriteSize + this._partyCommandWindow.height);
  1214.     }
  1215.     triggeredSprite.y = spriteY;
  1216.  
  1217.     trig = {trigsprite:triggeredSprite, lifetime:spriteLifeTime};
  1218.     this.activeTriggeredSprites.push(trig);
  1219.     this.addChild(triggeredSprite);
  1220.   };
  1221.  
  1222.  
  1223.   /*
  1224.   parameters:
  1225.   -x: An Integer
  1226.   Creates a triggeredSprite with the name 'TriggeredCorrect'.
  1227.   */
  1228.   Scene_Battle.prototype.createTriggeredCorrectSprite = function(x) {
  1229.     this.createTriggeredSprite("TriggeredCorrect", x);
  1230.   };
  1231.  
  1232.   /*
  1233.   parameters:
  1234.   -x: An Integer
  1235.   Creates a triggeredSprite with the name 'TriggeredCorrect'.
  1236.   */
  1237.   Scene_Battle.prototype.createTriggeredWrongSprite = function(x) {
  1238.     this.createTriggeredSprite("TriggeredWrong", x);
  1239.   };
  1240.  
  1241.   /*
  1242.   parameters:
  1243.   -none.
  1244.   This function lowers the lifetime of all activeTriggeredSprites by 1,
  1245.   changes their opacity and removes them if their lifetime is 0.
  1246.   */
  1247.   Scene_Battle.prototype.updateActiveTriggeredSprites = function() {
  1248.     this.activeTriggeredSprites.forEach(function(trig, i, o){
  1249.       var opacityDivisor = 5;
  1250.       trig.lifetime -= 1;
  1251.       opacityDivisor -= trig.lifetime;
  1252.       if (opacityDivisor > 0) trig.trigsprite.opacity = 255 / opacityDivisor;
  1253.       if (trig.lifetime <= 0) {
  1254.         SceneManager._scene.removeTriggeredSprite(trig);
  1255.       }
  1256.     });
  1257.   };
  1258.  
  1259.   /*
  1260.   parameters:
  1261.   -trig: An object that contains a sprite and an Integer
  1262.   Reomes trig from activeTriggeredSprites and deletes it.
  1263.   */
  1264.   Scene_Battle.prototype.removeTriggeredSprite = function(trig) {
  1265.     var arr = [];
  1266.     var trigIndex = this.activeTriggeredSprites.indexOf(trig);
  1267.     this.removeChild(trig.trigsprite);
  1268.     arr = this.activeTriggeredSprites.slice(0, trigIndex).concat( this.activeTriggeredSprites.slice(trigIndex + 1) );
  1269.     this.activeTriggeredSprites = arr;
  1270.     delete trig;
  1271.   };
  1272.  
  1273.   /*
  1274.   parameters:
  1275.   -sound: A String
  1276.   Calculates the correct pitch for the passed soundeffect and plays it.
  1277.   */
  1278.   Scene_Battle.prototype.playTBASound = function(sound) {
  1279.     var normalPitch = TamFey.param.defaultPitch;
  1280.     var highestPitch = 200
  1281.     var soundEffect = {};
  1282.     var seName = sound;
  1283.     var seVolume = TamFey.param.defaultVolume;
  1284.     var sePitch = this.tbaSoundPitch;
  1285.     soundEffect = {name:seName, volume:seVolume, pitch:sePitch};
  1286.     AudioManager.playSe(soundEffect);
  1287.     if (seName == TamFey.param.missSound) {
  1288.       this.tbaSoundPitch = normalPitch;
  1289.     }else if ( (seName == TamFey.param.hitSound) && (this.tbaSoundPitch <= highestPitch) ) {
  1290.       this.tbaSoundPitch += 5;
  1291.     }
  1292.   };
  1293.  
  1294.   /*
  1295.   parameters:
  1296.   -none.
  1297.   This function creates a PopupWindow with the hit-text.
  1298.   */
  1299.   Scene_Battle.prototype.createHitWindow = function() {
  1300.     this.createPopupWindow("\\c[3]Hit!!!");
  1301.   };
  1302.  
  1303.   /*
  1304.   parameters:
  1305.   -none.
  1306.   This function creates a PopupWindow with the miss-text.
  1307.   */
  1308.   Scene_Battle.prototype.createMissWindow = function() {
  1309.     this.createPopupWindow("\\c[18]Miss!");
  1310.   };
  1311.  
  1312.   /*
  1313.   parameters:
  1314.   -name: A String.
  1315.   Creates a PopupWindow with the passed name as text.
  1316.   */
  1317.   Scene_Battle.prototype.createPopupWindow = function(name) {
  1318.     var pop = new Window_Popup(name);
  1319.     this.addChild(pop);
  1320.     this.activePopupWindows.push(pop);
  1321.   };
  1322.  
  1323.   /*
  1324.   (ALIAS)
  1325.   parameters:
  1326.   -none.
  1327.   Calls the update functions of trigger areas and the combo window, if they exist.
  1328.   */
  1329.   var TamFey_TBA_Scene_Battle_Update = Scene_Battle.prototype.update;
  1330.   Scene_Battle.prototype.update = function() {
  1331.     TamFey_TBA_Scene_Battle_Update.call(this);
  1332.     if (TamFey.param.tbaEnabled == true) {
  1333.       if (this.triggerAreaSprites.length >= 1) this.updateTBATriggerAreas();
  1334.       if (TamFey.param.showCurrentCombo || TamFey.param.showMaxCombo || TamFey.param.showHitCounter) this._comboWindow.update();
  1335.     }
  1336.   };
  1337.  
  1338.   /*
  1339.   parameters:
  1340.   -none.
  1341.   Makes the trigger areas invisible if there is an important window active and
  1342.   makes them visible again if there is no important window active.
  1343.   */
  1344.   Scene_Battle.prototype.updateTBATriggerAreas = function() {
  1345.     if ((this._equipSlotWindow && this._equipSlotWindow.visible) || $gameMessage.isBusy() ) {
  1346.       this.triggerAreaSprites.forEach(function(area, i, o) {
  1347.         area.areasprite.opacity = 0;
  1348.         area.track.opacity = 0;
  1349.       });
  1350.     } else if (this.isActive() && !this._messageWindow.isClosing()) {
  1351.       this.triggerAreaSprites.forEach(function(area, i, o) {
  1352.         area.areasprite.opacity = 255;
  1353.         area.track.opacity = 125;
  1354.       });
  1355.     }
  1356.   }
  1357.  
  1358.   /*
  1359.   parameters:
  1360.   -none.
  1361.   Sets currentCombo, maxCombo and Hitcounter to 0.
  1362.   */
  1363.   Scene_Battle.prototype.resetComboVariables = function() {
  1364.     $gameVariables.setValue(TamFey.param.currentComboVariable, 0);
  1365.     $gameVariables.setValue(TamFey.param.maxComboVariable, 0);
  1366.     $gameVariables.setValue(TamFey.param.hitCounterVariable, 0);
  1367.   };
  1368.  
  1369.   /*
  1370.   parameters:
  1371.   -counter: An Integer.
  1372.   Sets the combo variables to the newest values.
  1373.   */
  1374.   Scene_Battle.prototype.updateComboVariables = function(counter) {
  1375.     var newHitCount = $gameVariables.value(TamFey.param.hitCounterVariable) + 1;
  1376.  
  1377.     if (counter > 0) {
  1378.       $gameVariables.setValue(TamFey.param.currentComboVariable, counter);
  1379.       $gameVariables.setValue(TamFey.param.hitCounterVariable, newHitCount);
  1380.       if (counter > $gameVariables.value(TamFey.param.maxComboVariable)) {
  1381.         $gameVariables.setValue(TamFey.param.maxComboVariable, counter);
  1382.       }
  1383.     } else {
  1384.       $gameVariables.setValue(TamFey.param.currentComboVariable, 0);
  1385.     }
  1386.   };
  1387.  
  1388.  
  1389.   /*
  1390.   parameters:
  1391.   -none.
  1392.   Creates a new combo window and adds it as a child to the scene.
  1393.   */
  1394.   Scene_Battle.prototype.createComboWindow = function() {
  1395.     this._comboWindow = new Window_Combo();
  1396.     this.addChild(this._comboWindow);
  1397.   };
  1398.  
  1399.   /*============================================================================
  1400.   Window_Combo
  1401.   ============================================================================*/
  1402.   function Window_Combo() {
  1403.     this.initialize.apply(this, arguments);
  1404.   }
  1405.  
  1406.   Window_Combo.prototype = Object.create(Window_Base.prototype);
  1407.   Window_Combo.prototype.constructor = Window_Combo;
  1408.  
  1409.   /*
  1410.   parameters:
  1411.   -none.
  1412.   Initializes size, display values and position of the window.
  1413.   */
  1414.   Window_Combo.prototype.initialize = function() {
  1415.     var xPos = TamFey.param.comboWindowX;
  1416.     var yPos = TamFey.param.comboWindowY;
  1417.     var width = Graphics.width;
  1418.     var height = (this.lineHeight() * 3) + (this.standardPadding() * 2);
  1419.     Window_Base.prototype.initialize.call(this, xPos, yPos, width, height);
  1420.     this.createContents();
  1421.     this.updateOpacity
  1422.     this.displayValue = 0;
  1423.     this.displayMaxValue = 0;
  1424.     this.displayTotal = 0;
  1425.     this.refresh();
  1426.   };
  1427.  
  1428.   /*
  1429.   parameters:
  1430.   -none.
  1431.   Updates the display values.
  1432.   If they have changed, the displayed values get updated as well.
  1433.   */
  1434.   Window_Combo.prototype.update = function() {
  1435.     Window_Base.prototype.update.call(this);
  1436.     var oldOpacity = this.contentsOpacity;
  1437.     var oldDisplayValue = this.displayValue
  1438.     this.updateOpacity();
  1439.     this.displayValue = $gameVariables.value(TamFey.param.currentComboVariable);
  1440.     this.displayMaxValue = $gameVariables.value(TamFey.param.maxComboVariable);
  1441.     this.displayTotal = $gameVariables.value(TamFey.param.hitCounterVariable);
  1442.     if((oldOpacity != this.contentsOpacity) || (oldDisplayValue != this.displayValue)) {
  1443.       this.refresh();
  1444.     }
  1445.   };
  1446.  
  1447.   /*
  1448.   parameters:
  1449.   -none.
  1450.   Makes the combo display invisible, when it's not needed.
  1451.   */
  1452.   Window_Combo.prototype.updateOpacity = function() {
  1453.     if( (TamFey.param.showCurrentCombo == true || TamFey.param.showMaxCombo == true || TamFey.param.showHitCounter == true) && BattleManager.allowTBAInputs) {
  1454.       this.contentsOpacity = 255;
  1455.     } else {
  1456.       this.contentsOpacity = 0;
  1457.     }
  1458.     this.opacity = 0;
  1459.   };
  1460.  
  1461.   /*
  1462.   parameters:
  1463.   -none.
  1464.   Adjusts the displayed text to show the current displayValues
  1465.   */
  1466.   Window_Combo.prototype.refresh = function() {
  1467.     this.contents.clear();
  1468.     this.contents.fontSize = TamFey.param.comboFontSize;
  1469.     var text = "";
  1470.     if(TamFey.param.showCurrentCombo == true) text = text + "\\C[9]Combo: " + this.getComboColor(this.displayValue) + this.displayValue + "\\C[0]\n";
  1471.     if(TamFey.param.showMaxCombo == true) text = text + "\\C[9]MaxCombo:\\C[0] " + this.displayMaxValue + "\n";
  1472.     if(TamFey.param.showHitCounter == true) text = text + "\\C[9]Total:\\C[0] " + this.displayTotal + "\\C[0]";
  1473.     this.drawTextEx(text, 0, 0 );
  1474.   };
  1475.  
  1476.   /*
  1477.   parameters:
  1478.   -combo: An Integer that contains the current combo.
  1479.   Returns a different color code, depending on the current combo.
  1480.   */
  1481.   Window_Combo.prototype.getComboColor = function(combo) {
  1482.     if (combo >= 10) {
  1483.       return "\\c[18]";
  1484.     } else if (combo >= 9) {
  1485.       return "\\c[10]";
  1486.     } else if (combo >= 7) {
  1487.       return "\\c[2]";
  1488.     } else if (combo >= 5) {
  1489.       return "\\c[14]";
  1490.     } else if (combo >= 4) {
  1491.       return "\\c[17]";
  1492.     } else if (combo >= 3) {
  1493.       return "\\c[6]";
  1494.     } else if (combo >= 2) {
  1495.       return "\\c[3]";
  1496.     } else {
  1497.     return "\\c[0]";
  1498.     }
  1499.   };
  1500.  
  1501.   /*============================================================================
  1502.   Window_Popup
  1503.   ============================================================================*/
  1504.   function Window_Popup(displayText) {
  1505.     this.initialize.apply(this, arguments, displayText);
  1506.   }
  1507.  
  1508.   Window_Popup.prototype = Object.create(Window_Base.prototype);
  1509.   Window_Popup.prototype.constructor = Window_Popup;
  1510.  
  1511.   /*
  1512.   parameters:
  1513.   -none.
  1514.   Initializes size, display values and position of the window.
  1515.   */
  1516.   Window_Popup.prototype.initialize = function(displayText) {
  1517.     var yPos = TamFey.param.popupPosY;
  1518.     var width = Graphics.width;
  1519.     var height = (this.lineHeight() * 3) + (this.standardPadding() * 2);
  1520.     Window_Base.prototype.initialize.call(this, 0, yPos, width, height);
  1521.     this.displayText = displayText;
  1522.     this.lifetime = 24;
  1523.     this.createContents();
  1524.     this.updateOpacity();
  1525.     this.refresh();
  1526.   };
  1527.  
  1528.   /*
  1529.   parameters:
  1530.   -none.
  1531.   refreshes window, if opacity has changed.
  1532.   */
  1533.   Window_Popup.prototype.update = function() {
  1534.     Window_Base.prototype.update.call(this);
  1535.     var oldOpacity = this.contentsOpacity;
  1536.     this.updateOpacity();
  1537.     if((oldOpacity != this.contentsOpacity)) {
  1538.       this.refresh();
  1539.     }
  1540.   };
  1541.  
  1542.   /*
  1543.   parameters:
  1544.   -none.
  1545.   Changes opacity based on lifetime left.
  1546.   */
  1547.   Window_Popup.prototype.updateOpacity = function() {
  1548.     var speed = 3;
  1549.     var opacityDivisor = 6;
  1550.     this.lifetime -= 1;
  1551.     opacityDivisor -= this.lifetime;
  1552.     if (opacityDivisor > 0) this.contentsOpacity = 255 / opacityDivisor;
  1553.     this.y -= speed;
  1554.     if (this.lifetime <= 0) {
  1555.       this.close();
  1556.     }
  1557.     this.opacity = 0;
  1558.   };
  1559.  
  1560.   /*
  1561.   parameters:
  1562.   -none.
  1563.   rewrites the displayed text.
  1564.   */
  1565.   Window_Popup.prototype.refresh = function() {
  1566.     this.contents.clear();
  1567.     this.contents.fontSize = TamFey.param.popupFontSize;
  1568.     this.drawTextEx(this.displayText, 0, 0 );
  1569.   };
  1570.  
  1571.  
  1572. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement