/*=============================================================================
* Gilgamar - ButtonCast
* By Gilgamar
* G_ButtonCast.js
* Version: 1.05.1
* Free for commercial and non commercial use.
*=============================================================================*/
var Imported = Imported || {};
Imported.G_ButtonCast = true;
/*:
* @plugindesc v1.05.1 Adds ability to instantly cast skills with button.
* @author Gilgamar
*
* @param ---Top Row---
* @default
*
* @param Key ~
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 1
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 2
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 3
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 4
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 5
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 6
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 7
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 8
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 9
* @desc ID of skill to bind to key
* @default 0
*
* @param Key 0
* @desc ID of skill to bind to key
* @default 0
*
* @param Key -
* @desc ID of skill to bind to key
* @default 0
*
* @param Key =
* @desc ID of skill to bind to key
* @default 0
*
* @param ---2nd Row---
* @default
*
* @param Key Q (PageUp)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key W (PageDown)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key E
* @desc ID of skill to bind to key
* @default 0
*
* @param Key R
* @desc ID of skill to bind to key
* @default 0
*
* @param Key T
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Y
* @desc ID of skill to bind to key
* @default 0
*
* @param Key U
* @desc ID of skill to bind to key
* @default 0
*
* @param Key I
* @desc ID of skill to bind to key
* @default 0
*
* @param Key O
* @desc ID of skill to bind to key
* @default 0
*
* @param Key P
* @desc ID of skill to bind to key
* @default 0
*
* @param Key [
* @desc ID of skill to bind to key
* @default 0
*
* @param Key ]
* @desc ID of skill to bind to key
* @default 0
*
* @param Key \
* @desc ID of skill to bind to key
* @default 0
*
* @param ---3rd Row---
* @default
*
* @param Key A
* @desc ID of skill to bind to key
* @default 0
*
* @param Key S
* @desc ID of skill to bind to key
* @default 0
*
* @param Key D
* @desc ID of skill to bind to key
* @default 0
*
* @param Key F
* @desc ID of skill to bind to key
* @default 0
*
* @param Key G
* @desc ID of skill to bind to key
* @default 0
*
* @param Key H
* @desc ID of skill to bind to key
* @default 0
*
* @param Key J
* @desc ID of skill to bind to key
* @default 0
*
* @param Key K
* @desc ID of skill to bind to key
* @default 0
*
* @param Key L
* @desc ID of skill to bind to key
* @default 0
*
* @param Key ;
* @desc ID of skill to bind to key
* @default 0
*
* @param Key "
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Enter (OK)
* @desc ID of skill to bind to key
* @default 0
*
* @param ---4th Row---
* @default
*
* @param Key Shift (Dash)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Z (OK)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key X (Cancel)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key C
* @desc ID of skill to bind to key
* @default 0
*
* @param Key V
* @desc ID of skill to bind to key
* @default 0
*
* @param Key B
* @desc ID of skill to bind to key
* @default 0
*
* @param Key N
* @desc ID of skill to bind to key
* @default 0
*
* @param Key M
* @desc ID of skill to bind to key
* @default 0
*
* @param Key ,
* @desc ID of skill to bind to key
* @default 0
*
* @param Key .
* @desc ID of skill to bind to key
* @default 0
*
* @param Key /
* @desc ID of skill to bind to key
* @default 0
*
* @param ---Misc---
* @default
*
* @param Key Space (OK)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Left (Left)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Up (Up)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Right (Right)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Down (Down)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Insert (Cancel)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Delete
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Home
* @desc ID of skill to bind to key
* @default 0
*
* @param Key End
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Page Up (PageUp)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key Page Down (PageDown)
* @desc ID of skill to bind to key
* @default 0
*
* @param ---NumPad---
* @default
*
* @param Key NumPad 0 (Cancel)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 1
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 2 (Down)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 3
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 4 (Left)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 5
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 6 (Right)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 7
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 8 (Up)
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad 9
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad .
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad +
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad -
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad *
* @desc ID of skill to bind to key
* @default 0
*
* @param Key NumPad /
* @desc ID of skill to bind to key
* @default 0
*
* @help
* ============================================================================
* Introduction
* ============================================================================
* This plugin modifies Yanfly's ATB system to support button cast
*
* Skills are assigned to keys using the plugin parameter list
* Keys are assigned to actors using actor notetags, for example:
* <ButtonCast Keys: num1 q keyShift>
*
* For a full list of key names see the Key Names section below
*
* When a skill key is pressed, the actor or actors assigned to the key will
* perform the skill bound to the key in sequence so long as they have learned
* the skill and are not under status effects that would otherwise prevent them
* from using the skill
*
* ============================================================================
* Changelog
* ============================================================================
* Next Version:
* - Menu key assignments and skill bindings
*
* Version 1.05.1:
* - Fixed a bug where checkButtonCast() would crash if an actor had no keys assigned
* - Added actor notetag <ButtonCast Key: keyName:skillId>
*
* Version 1.05:
* - Support for multiple actors using same key
* - Grouped button cast functions under BattleManager instead of global
* - Added debug statements at each phase of button cast
* - Redirected on cancel functions to ensure skill and atb reset correctly
* - Notetags for actor key assignments
* - Changed checkInput() to use isTriggered() so debouncing is no longer required
* - Fixed help section and added key naming reference
* - Cleaned up code and various bugfixes
*
* Version 1.04:
* - Target selection for allies and enemies
* - Fixed sprite not moving back if button cast canceled
* - Added nearly full keyboard support excluding keys that shouldn't be altered
* - Renamed runSkill() to checkButtonCast()
* - Improved code efficiency by debouncing checkButtonCast()
* - Checks if user has status effects to prevent casting while sleep/dead etc
* - Improved source code formatting and added references at the end of script
*
* Version 1.03:
* - Enemy target selection after using button cast
*
* Version 1.02:
* - Can now button cast with multiple actors!
* - Assign keys to actors in parameter
*
* Version 1.01:
* - Buttons not activated unless skill assigned
* - Skill assignments now stored in ButtonCast.keyList for easier access
* - Added a,s,d keys
* - Choose actor in parameter
* - Simplified checkInput() function for scalability
* - runSkill() function checks if user has skill and plays buzzer sound if not
* - Cool down timer to prevent overlapping sound effects
*
* Version 1.00:
* - Single actor button cast!
*
* ============================================================================
* Key Names
* ============================================================================
* NAME: KEY
* tilde: ['Key ~']
* 1: ['Key 1']
* 2: ['Key 2']
* 3: ['Key 3']
* 4: ['Key 4']
* 5: ['Key 5']
* 6: ['Key 6']
* 7: ['Key 7']
* 8: ['Key 8']
* 9: ['Key 9']
* 0: ['Key 0']
* minus: ['Key -']
* equal: ['Key =']
*
* NAME: KEY
* q: ['Key Q']
* w: ['Key W']
* e: ['Key E']
* r: ['Key R']
* t: ['Key T']
* y: ['Key Y']
* u: ['Key U']
* i: ['Key I']
* o: ['Key O']
* p: ['Key P']
* foreBrack: ['Key [']
* backBrack: ['Key ]']
* backSlash: ['Key \']
*
* NAME: KEY
* a: ['Key A']
* s: ['Key S']
* d: ['Key D']
* f: ['Key F']
* g: ['Key G']
* h: ['Key H']
* j: ['Key J']
* k: ['Key K']
* l: ['Key L']
* semicolon: ['Key ;']
* quote: ['Key "']
* enter: ['Key Enter']
*
* NAME: KEY
* keyShift: ['Key Shift']
* z: ['Key Z']
* x: ['Key X']
* c: ['Key C']
* v: ['Key V']
* b: ['Key B']
* n: ['Key N']
* m: ['Key M']
* comma: ['Key ,']
* period: ['Key .']
* foreSlash: ['Key /']
*
* NAME: KEY
* space: ['Key Space']
* dirLeft: ['Key Left']
* dirUp: ['Key Up']
* dirRight: ['Key Right']
* dirDown: ['Key Down']
* ins: ['Key Insert']
* del: ['Key Delete']
* home: ['Key Home']
* end: ['Key End']
* pageUp: ['Key Page Up']
* pageDown: ['Key Page Down']
*
* NAME: KEY
* num0: ['Key NumPad 0']
* num1: ['Key NumPad 1']
* num2: ['Key NumPad 2']
* num3: ['Key NumPad 3']
* num4: ['Key NumPad 4']
* num5: ['Key NumPad 5']
* num6: ['Key NumPad 6']
* num7: ['Key NumPad 7']
* num8: ['Key NumPad 8']
* num9: ['Key NumPad 9']
* numPeriod: ['Key NumPad .']
* numPlus: ['Key NumPad +']
* numMinus: ['Key NumPad -']
* numTimes: ['Key NumPad *']
* numDivide: ['Key NumPad /']
*
*/
if (Imported.YEP_X_BattleSysAT

{
//=============================================================================
// Parameters
//=============================================================================
var parameters = PluginManager.parameters('G_ButtonCast');
// console.log(parameters)
var ButtonCast = {};
ButtonCast.keyList = {
tilde: Number(parameters['Key ~']),
1: Number(parameters['Key 1']),
2: Number(parameters['Key 2']),
3: Number(parameters['Key 3']),
4: Number(parameters['Key 4']),
5: Number(parameters['Key 5']),
6: Number(parameters['Key 6']),
7: Number(parameters['Key 7']),
8: Number(parameters['Key 8']),
9: Number(parameters['Key 9']),
0: Number(parameters['Key 0']),
minus: Number(parameters['Key -']),
equal: Number(parameters['Key =']),
q: Number(parameters['Key Q (PageUp)']),
w: Number(parameters['Key W (PageDown)']),
e: Number(parameters['Key E']),
r: Number(parameters['Key R']),
t: Number(parameters['Key T']),
y: Number(parameters['Key Y']),
u: Number(parameters['Key U']),
i: Number(parameters['Key I']),
o: Number(parameters['Key O']),
p: Number(parameters['Key P']),
foreBrack: Number(parameters['Key [']),
backBrack: Number(parameters['Key ]']),
backSlash: Number(parameters['Key \\']),
a: Number(parameters['Key A']),
s: Number(parameters['Key S']),
d: Number(parameters['Key D']),
f: Number(parameters['Key F']),
g: Number(parameters['Key G']),
h: Number(parameters['Key H']),
j: Number(parameters['Key J']),
k: Number(parameters['Key K']),
l: Number(parameters['Key L']),
semicolon: Number(parameters['Key ;']),
quote: Number(parameters['Key "']),
enter: Number(parameters['Key Enter (OK)']),
keyShift: Number(parameters['Key Shift (Dash)']),
z: Number(parameters['Key Z (OK)']),
x: Number(parameters['Key X (Cancel)']),
c: Number(parameters['Key C']),
v: Number(parameters['Key V']),
b: Number(parameters['Key B']),
n: Number(parameters['Key N']),
m: Number(parameters['Key M']),
comma: Number(parameters['Key ,']),
period: Number(parameters['Key .']),
foreSlash: Number(parameters['Key /']),
space: Number(parameters['Key Space (OK)']),
dirLeft: Number(parameters['Key Left (Left)']),
dirUp: Number(parameters['Key Up (Up)']),
dirRight: Number(parameters['Key Right (Right)']),
dirDown: Number(parameters['Key Down (Down)']),
ins: Number(parameters['Key Insert (Cancel)']),
del: Number(parameters['Key Delete']),
home: Number(parameters['Key Home']),
end: Number(parameters['Key End']),
pageUp: Number(parameters['Key Page Up (PageUp)']),
pageDown: Number(parameters['Key Page Down (PageDown)']),
num0: Number(parameters['Key NumPad 0 (Cancel)']),
num1: Number(parameters['Key NumPad 1']),
num2: Number(parameters['Key NumPad 2 (Down)']),
num3: Number(parameters['Key NumPad 3']),
num4: Number(parameters['Key NumPad 4 (Left)']),
num5: Number(parameters['Key NumPad 5']),
num6: Number(parameters['Key NumPad 6 (Right)']),
num7: Number(parameters['Key NumPad 7']),
num8: Number(parameters['Key NumPad 8 (Up)']),
num9: Number(parameters['Key NumPad 9']),
numPeriod: Number(parameters['Key NumPad .']),
numPlus: Number(parameters['Key NumPad +']),
numMinus: Number(parameters['Key NumPad -']),
numTimes: Number(parameters['Key NumPad *']),
numDivide: Number(parameters['Key NumPad /'])
}
//=============================================================================
// Input Key Mapper
//=============================================================================
{
if (ButtonCast.keyList['tilde'] !== 0) Input.keyMapper[192] = 'tilde';
if (ButtonCast.keyList['1'] !== 0) Input.keyMapper[49] = '1';
if (ButtonCast.keyList['2'] !== 0) Input.keyMapper[50] = '2';
if (ButtonCast.keyList['3'] !== 0) Input.keyMapper[51] = '3';
if (ButtonCast.keyList['4'] !== 0) Input.keyMapper[52] = '4';
if (ButtonCast.keyList['5'] !== 0) Input.keyMapper[53] = '5';
if (ButtonCast.keyList['6'] !== 0) Input.keyMapper[54] = '6';
if (ButtonCast.keyList['7'] !== 0) Input.keyMapper[55] = '7';
if (ButtonCast.keyList['8'] !== 0) Input.keyMapper[56] = '8';
if (ButtonCast.keyList['9'] !== 0) Input.keyMapper[57] = '9';
if (ButtonCast.keyList['0'] !== 0) Input.keyMapper[48] = '0';
if (ButtonCast.keyList['minus'] !== 0) Input.keyMapper[189] = 'minus';
if (ButtonCast.keyList['equal'] !== 0) Input.keyMapper[187] = 'equal';
if (ButtonCast.keyList['q'] !== 0) Input.keyMapper[81] = 'q';
if (ButtonCast.keyList['w'] !== 0) Input.keyMapper[87] = 'w';
if (ButtonCast.keyList['e'] !== 0) Input.keyMapper[69] = 'e';
if (ButtonCast.keyList['r'] !== 0) Input.keyMapper[82] = 'r';
if (ButtonCast.keyList['t'] !== 0) Input.keyMapper[84] = 't';
if (ButtonCast.keyList['y'] !== 0) Input.keyMapper[89] = 'y';
if (ButtonCast.keyList['u'] !== 0) Input.keyMapper[85] = 'u';
if (ButtonCast.keyList['i'] !== 0) Input.keyMapper[73] = 'i';
if (ButtonCast.keyList['o'] !== 0) Input.keyMapper[79] = 'o';
if (ButtonCast.keyList['p'] !== 0) Input.keyMapper[80] = 'p';
if (ButtonCast.keyList['foreBrack'] !== 0) Input.keyMapper[219] = 'foreBrack';
if (ButtonCast.keyList['backBrack'] !== 0) Input.keyMapper[221] = 'backBrack';
if (ButtonCast.keyList['backSlash'] !== 0) Input.keyMapper[220] = 'backSlash';
if (ButtonCast.keyList['a'] !== 0) Input.keyMapper[65] = 'a';
if (ButtonCast.keyList['s'] !== 0) Input.keyMapper[83] = 's';
if (ButtonCast.keyList['d'] !== 0) Input.keyMapper[68] = 'd';
if (ButtonCast.keyList['f'] !== 0) Input.keyMapper[70] = 'f';
if (ButtonCast.keyList['g'] !== 0) Input.keyMapper[71] = 'g';
if (ButtonCast.keyList['h'] !== 0) Input.keyMapper[72] = 'h';
if (ButtonCast.keyList['j'] !== 0) Input.keyMapper[74] = 'j';
if (ButtonCast.keyList['k'] !== 0) Input.keyMapper[75] = 'k';
if (ButtonCast.keyList['l'] !== 0) Input.keyMapper[76] = 'l';
if (ButtonCast.keyList['semicolon'] !== 0) Input.keyMapper[186] = 'semicolon';
if (ButtonCast.keyList['quote'] !== 0) Input.keyMapper[222] = 'quote';
if (ButtonCast.keyList['enter'] !== 0) Input.keyMapper[13] = 'enter';
if (ButtonCast.keyList['keyShift'] !== 0) Input.keyMapper[16] = 'keyShift';
if (ButtonCast.keyList['z'] !== 0) Input.keyMapper[90] = 'z';
if (ButtonCast.keyList['x'] !== 0) Input.keyMapper[88] = 'x';
if (ButtonCast.keyList['c'] !== 0) Input.keyMapper[67] = 'c';
if (ButtonCast.keyList['v'] !== 0) Input.keyMapper[86] = 'v';
if (ButtonCast.keyList['b'] !== 0) Input.keyMapper[66] = 'b';
if (ButtonCast.keyList['n'] !== 0) Input.keyMapper[78] = 'n';
if (ButtonCast.keyList['m'] !== 0) Input.keyMapper[77] = 'm';
if (ButtonCast.keyList['comma'] !== 0) Input.keyMapper[188] = 'comma';
if (ButtonCast.keyList['period'] !== 0) Input.keyMapper[190] = 'period';
if (ButtonCast.keyList['foreSlash'] !== 0) Input.keyMapper[191] = 'foreSlash';
if (ButtonCast.keyList['space'] !== 0) Input.keyMapper[32] = 'space';
if (ButtonCast.keyList['dirLeft'] !== 0) Input.keyMapper[37] = 'dirLeft';
if (ButtonCast.keyList['dirUp'] !== 0) Input.keyMapper[38] = 'dirUp';
if (ButtonCast.keyList['dirRight'] !== 0) Input.keyMapper[39] = 'dirRight';
if (ButtonCast.keyList['dirDown'] !== 0) Input.keyMapper[40] = 'dirDown';
if (ButtonCast.keyList['ins'] !== 0) Input.keyMapper[45] = 'ins';
if (ButtonCast.keyList['del'] !== 0) Input.keyMapper[46] = 'del';
if (ButtonCast.keyList['home'] !== 0) Input.keyMapper[36] = 'home';
if (ButtonCast.keyList['end'] !== 0) Input.keyMapper[35] = 'end';
if (ButtonCast.keyList['pageUp'] !== 0) Input.keyMapper[33] = 'pageUp';
if (ButtonCast.keyList['pageDown'] !== 0) Input.keyMapper[34] = 'pageDown';
if (ButtonCast.keyList['num0'] !== 0) Input.keyMapper[96] = 'num0';
if (ButtonCast.keyList['num1'] !== 0) Input.keyMapper[97] = 'num1';
if (ButtonCast.keyList['num2'] !== 0) Input.keyMapper[98] = 'num2';
if (ButtonCast.keyList['num3'] !== 0) Input.keyMapper[99] = 'num3';
if (ButtonCast.keyList['num4'] !== 0) Input.keyMapper[100] = 'num4';
if (ButtonCast.keyList['num5'] !== 0) Input.keyMapper[101] = 'num5';
if (ButtonCast.keyList['num6'] !== 0) Input.keyMapper[102] = 'num6';
if (ButtonCast.keyList['num7'] !== 0) Input.keyMapper[103] = 'num7';
if (ButtonCast.keyList['num8'] !== 0) Input.keyMapper[104] = 'num8';
if (ButtonCast.keyList['num9'] !== 0) Input.keyMapper[105] = 'num9';
if (ButtonCast.keyList['numPeriod'] !== 0) Input.keyMapper[110] = 'numPeriod';
if (ButtonCast.keyList['numPlus'] !== 0) Input.keyMapper[107] = 'numPlus';
if (ButtonCast.keyList['numMinus'] !== 0) Input.keyMapper[109] = 'numMinus';
if (ButtonCast.keyList['numTimes'] !== 0) Input.keyMapper[106] = 'numTimes';
if (ButtonCast.keyList['numDivide'] !== 0) Input.keyMapper[111] = 'numDivide';
}
ButtonCast.keysActor = [];
//=============================================================================
// Notetags
//=============================================================================
ButtonCast.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function() {
if (!ButtonCast.DataManager_isDatabaseLoaded.call(this)) return false;
DataManager.processBUTTONCASTNotetags1($dataActors);
// DataManager.processBUTTONCASTNotetags2($dataSkills);
return true;
};
DataManager.processBUTTONCASTNotetags1 = function(group) {
// Old way of matching button cast keys
var note2 = /<(?:BUTTONCAST KEYS):[ ](.+)>/i;
for (var n = 1; n < group.length; n++) {
var obj = group[n];
var notedata = obj.note.split(/[\r\n]+/);
for (var i = 0; i < notedata.length; i++) {
var line = notedata
;
if (line.match(note2)) {
keys = RegExp.$1.trim().toLowerCase().split(' ').map(String)
ButtonCast.keysActor[n] = keys
}
}
}
// <ButtonCast Key: keyName : skillId>
var note1 = /<(?:BUTTONCAST KEY):[ ](.+)
\d+)>/i;
for (var n = 1; n < group.length; n++) {
// console.log($dataActors[n].name)
ButtonCast.keysActor[n] = [];
var obj = group[n];
var notedata = obj.note.split(/[\r\n]+/);
// console.log(notedata)
for (var i = 0; i < notedata.length; i++) {
var line = notedata;
if (line.match(note1)) {
var keyName = String(RegExp.$1.trim().toLowerCase().split(' '))
var skillId = parseInt(RegExp.$2)
// console.log(keyName, skillId)
// Assign skillId to key
for (k in ButtonCast.keyList) {
if (k.toLowerCase() == keyName.toLowerCase()) {
ButtonCast.keyList[k] = skillId;
}
}
ButtonCast.keysActor[n].push(keyName);
}
}
}
// console.log(ButtonCast.keysActor)
};
//=============================================================================
// Plugin Commands
//=============================================================================
//
// var aliasPluginCommand = Game_Interpreter.prototype.pluginCommand;
// Game_Interpreter.prototype.pluginCommand = function(command, args) {
// aliasPluginCommand.call(this, command, args);
// if (command == 'ButtonCast') {
// switch (args[0]) {
// case 'init':
// break;
// }
// }
// }
//=============================================================================
// ButtonCast Functions
//=============================================================================
// Checks if key is pressed
// Called from BattleManager.checkButtonCast
BattleManager.checkInput = function(args) {
for (var k in args) {
if (Input.isTriggered(String(k))) return k;
}
return null;
};
// Checks inputs and skill bindings to see if actor can button cast
// Called from BattleManager.updateATBTicks
BattleManager.checkButtonCast = function() {
var k = this.checkInput(ButtonCast.keyList)
if (!k) return; // Check if input is valid
var battlers = [];
for (var i = 1; i < ButtonCast.keysActor.length; i++) {
// Check if key assigned to battler
if (ButtonCast.keysActor.length === 0) continue; // Actor has no keys assigned
if (ButtonCast.keysActor.indexOf(k) > -1) {
var actor = $gameActors.actor(i);
if (actor.isBattleMember()) battlers.push(actor);
}
}
// console.log(battlers)
// Check if battler can take action
for (var i = 0; i < battlers.length; i++){
battler = battlers;
if (battler.isATBCharging()) continue; // Action already queued
if (!battler.canInput()) continue; // Check in case of status effects
console.log('Check Skill', battler.name())
var skillId = ButtonCast.keyList[k];
if (!battler.isLearnedSkill(skillId)) { // Check if battler has skill
SoundManager.playBuzzer();
continue;
}
console.log('Skill:', skillId);
console.log('');
battler.clearActions();
var action = new Game_Action(battler);
action.setSkill(skillId);
if (!action.isValid()) continue; // Check if action is valid
battler._actions.push(action);
this.buttonCastBattlers.push(battler);
}
};
// Prepare the actor for action and target selection
// Called from BattleManager.updateATBTicks
BattleManager.prepareButtonCast = function() {
this.buttonCastBattler = this.buttonCastBattlers.shift();
var battler = this.buttonCastBattler;
console.log('Prepare Action', battler.name());
console.log('');
this.playATBReadySound();
battler.spriteStepForward();
battler.requestMotionRefresh();
battler.setATBSpeed(this.atbTarget());
battler.setupATBCharge();
this.statusUpdateATB();
this._actorIndex = battler.index();
var action = this.inputtingAction();
if (action.needsSelection()) {
console.log('Select Target', battler.name());
console.log('');
SceneManager._scene.onSelectAction();
}
}
// Reset battler atb and actions
// Called from Scene_Battle.onActorCancel and Scene_Battle.onEnemyCancel
BattleManager.cancelButtonCast = function(){
battler = this.buttonCastBattler;
console.log('Cancel Selection', battler.name())
console.log('');
battler.spriteStepBack();
battler.requestMotionRefresh();
}
//=============================================================================
// Yanfly Overrides
//=============================================================================
BattleManager.buttonCastBattlers = [];
ButtonCast.BattleManager_updateATBTicks = BattleManager.updateATBTicks
BattleManager.updateATBTicks = function() {
if (SceneManager._scene.isAnyInputWindowActive()) return;
this.buttonCastBattler = undefined;
if (this.buttonCastBattlers.length === 0) this.checkButtonCast();
if (this.buttonCastBattlers.length > 0) return this.prepareButtonCast();
ButtonCast.BattleManager_updateATBTicks.call(this);
};
// if (this.seCooldown) this.seCooldown -= 1;
//=============================================================================
// Debugging and References
//=============================================================================
// Some of this code from Yanfly's BattleEngine v1.32
ButtonCast.Scene_Battle_onActorCancel = Scene_Battle.prototype.onActorCancel
Scene_Battle.prototype.onActorCancel = function() {
if (eval(Yanfly.Param.BECSelectHelp)) this._helpWindow.hide();
this._helpWindow.clear();
if (BattleManager.buttonCastBattler) {
this._actorWindow.hide();
BattleManager.cancelButtonCast();
} else {
ButtonCast.Scene_Battle_onActorCancel.call(this);
}
BattleManager.stopAllSelection();
BattleManager.clearInputtingAction();
};
// Some of this code from Yanfly's BattleEngine v1.32
ButtonCast.Scene_Battle_onEnemyCancel = Scene_Battle.prototype.onEnemyCancel
Scene_Battle.prototype.onEnemyCancel = function() {
if (eval(Yanfly.Param.BECSelectHelp)) this._helpWindow.hide();
this._helpWindow.clear();
if (BattleManager.buttonCastBattler) {
this._enemyWindow.hide();
BattleManager.cancelButtonCast();
} else {
ButtonCast.Scene_Battle_onEnemyCancel.call(this);
}
BattleManager.stopAllSelection();
BattleManager.clearInputtingAction();
};
// Window_BattleEnemy.prototype.select = function(index) {
// Window_Selectable.prototype.select.call(this, index);
// $gameTroop.select(this.enemy());
// if(BattleManager.buttonCastBattler) console.log(this.enemy().name());
// };
}; // Leave this alone