-
Notifications
You must be signed in to change notification settings - Fork 0
/
bentelk_GameObjectExtensions.js
145 lines (136 loc) · 4.46 KB
/
bentelk_GameObjectExtensions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*:
* @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).
*
* ===[ $gameSwitches.allOn(switches) ]======================================
*
* give a list of switches (by number); if ALL switches are on, then the
* condition passes. example:
*
* $gameSwitches.allOn([ 1, 2, 3, 4, 5 ])
*
* that condition would pass if switches 1 through 5 are all ON.
*
* ===[ $gameSwitches.allOff(switches) ]=====================================
*
* the opposite of allOn; if ALL switches are off, then the condition passes.
* example:
*
* $gameSwitches.allOff([ 8, 9, 12 ]);
*
* that condition would pass if switches 8, 9, and 12 are all OFF.
*
* ===[ $gameVariables.countOn(switches) ]===================================
*
* give a list of switches (by number); returns a count of how many of those
* switches are on. example:
*
* $gameSwitches.countOn([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]) > 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([ 1, 7, 12, 13 ])
*
* ===[ $gameSwitches.countOff(switches) ]====================================
*
* give a list of switches (by number); returns a count of how many of those
* switches are OFF. example:
*
* $gameSwitches.countOff([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]) > 5
*
* that condition would pass if at least 5 of the switches 1 through 10 are OFF.
*
* see $gameSwitches.countOn for more examples.
*
* ===[ $gameVariables.total(variables) ]====================================
*
* returns the sum total of the given variables.
*
* example use in a Conditional Branch:
*
* $gameVariables.total([ 1, 2, 8 ]) > 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([ 5, 8, 13, 14 ])
*
* example in a damage calculation:
*
* a.atk + $gameVariables.total([ 1, 2, 3, 4 ])
*
* the damage would be the total of the attacker's attack, and the values of
* variables 1, 2, 3, and 4.
*
* ===[ $gameVariables.average(variables) ]==================================
*
* like $gameVariables.total, but returns the AVERAGE of the indicated
* variables.
*
* ===[ $gameParty.itemCount(itemId) ]=======================================
*
* 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.
*
* ===[ $gameParty.armorCount(armorId) ]=====================================
*
* returns how many of armor "armorId" your party is carrying. see
* $gameParty.itemCount for example uses.
*
* ===[ $gameParty.weaponCount(weaponId) ]===================================
*
* 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[s];
});
};
Game_Switches.prototype.allOff = function(switches) {
return switches.every(s => {
return !this._data[s];
});
};
Game_Switches.prototype.countOn = function(switches) {
return switches.reduce((a, b) => (!!this._data[s] ? 1 : 0) + b);
};
Game_Switches.prototype.countOff = function(switches) {
return switches.reduce((a, b) => (!this._data[s] ? 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[itemId] : 0;
};
Game_Party.prototype.armorCount = function(itemId)
{
return this._armors.hasOwnProperty(itemId) ? this._armors[itemId] : 0;
};
Game_Party.prototype.weaponCount = function(itemId)
{
return this._weapons.hasOwnProperty(itemId) ? this._weapons[itemId] : 0;
};