/*:
* @plugindesc Extends RPGMV base objects in useful ways.
* @author Ben Hendel-Doying
*
* @help
* These extensions are intended to be used via the "Script" option, in
* Conditional Branches especially. They can also be used in damage formulas,
* your own extensions, or anywhere else JavaScript is allowed.
*
* Requires RPG Maker MV 1.6.1+ (due to use of ES6 functions and syntax).
*
* =========================================
*
* give a list of switches (by number); if ALL switches are on, then the
* condition passes. example:
*
* $gameSwitches.allOn()
*
* that condition would pass if switches 1 through 5 are all ON.
*
* ========================================
*
* the opposite of allOn; if ALL switches are off, then the condition passes.
* example:
*
* $gameSwitches.allOff();
*
* that condition would pass if switches 8, 9, and 12 are all OFF.
*
* ======================================
*
* give a list of switches (by number); returns a count of how many of those
* switches are on. example:
*
* $gameSwitches.countOn() > 5
*
* that condition would pass if at least 5 of the switches 1 through 10 are ON.
*
* you could also store the result to a variable, using "Control Variables".
*
* another example: in a damage formula:
*
* a.atk - $gameSwitches.countOn()
*
* =======================================
*
* give a list of switches (by number); returns a count of how many of those
* switches are OFF. example:
*
* $gameSwitches.countOff() > 5
*
* that condition would pass if at least 5 of the switches 1 through 10 are OFF.
*
* see $gameSwitches.countOn for more examples.
*
* =======================================
*
* returns the sum total of the given variables.
*
* example use in a Conditional Branch:
*
* $gameVariables.total() > 125
*
* that condition would pass if variable 1 + variable 2 + variable 8 is greater
* than 125.
*
* example setting a variable using the "Control Variables" command:
*
* $gameVariables.total()
*
* example in a damage calculation:
*
* a.atk + $gameVariables.total()
*
* the damage would be the total of the attacker's attack, and the values of
* variables 1, 2, 3, and 4.
*
* =====================================
*
* like $gameVariables.total, but returns the AVERAGE of the indicated
* variables.
*
* ==========================================
*
* returns how many of item "itemId" your party is carrying. example use in a
* Conditional Branch:
*
* $gameParty.itemCount(3) >= 5
*
* that condition would pass if the party has 5 or more of item #3.
*
* ========================================
*
* returns how many of armor "armorId" your party is carrying. see
* $gameParty.itemCount for example uses.
*
* ======================================
*
* returns how many of weapon "weaponId" your party is carrying. see
* $gameParty.itemCount for example uses.
*
*/

Game_Switches.prototype.allOn = function(switches) {
return switches.every(s => {
return !!this._data;
});
};

Game_Switches.prototype.allOff = function(switches) {
return switches.every(s => {
return !this._data;
});
};

Game_Switches.prototype.countOn = function(switches) {
return switches.reduce((a, b) => (!!this._data ? 1 : 0) + b);
};

Game_Switches.prototype.countOff = function(switches) {
return switches.reduce((a, b) => (!this._data ? 1 : 0) + b);
};

Game_Variables.prototype.total = function(variables) {
return variables.reduce((a, b) => this.value(a) + b);
};

Game_Variables.prototype.average = function(variables) {
return this.total(variables) / variables.length;
};

Game_Party.prototype.itemCount = function(itemId)
{
return this._items.hasOwnProperty(itemId) ? this._items : 0;
};

Game_Party.prototype.armorCount = function(itemId)
{
return this._armors.hasOwnProperty(itemId) ? this._armors : 0;
};

Game_Party.prototype.weaponCount = function(itemId)
{
return this._weapons.hasOwnProperty(itemId) ? this._weapons : 0;
};