-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMoogle_X_GiveItemOnEvent.js
268 lines (238 loc) · 9.56 KB
/
Moogle_X_GiveItemOnEvent.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//=============================================================================
// Give Item On Event by Moogle_X
// Moogle_X_GiveItemOnEvent.js
// Created on: December 14th 2015
//=============================================================================
var Imported = Imported || {};
Imported.Moogle_X_GIOE = true;
var Moogle_X = Moogle_X || {};
Moogle_X.GIOE = Moogle_X.GIOE || {};
//=============================================================================
/*:
* @plugindesc v1.0 Allows you to use/give item on event.
* @author Moogle_X
*
* @param Category Variable ID
* @desc This is in-game variable ID for storing chosen item category.
* @default 1
*
* @param Item Variable ID
* @desc This is in-game variable ID for storing chosen item ID.
* @default 2
*
* @help
* ============================================================================
* Introduction
* ============================================================================
* This is a special plugin request from Iliketea.
*
* This plugin allows you to use a special plugin command during an event to
* open a custom (yet similar looking) item menu. This item menu has different
* rule on which item become enabled or not.
*
* The list of allowed items, weapons, and armors are defined using Script Call.
*
* GIOE_Items = []; // This is the list of allowed items.
* GIOE_Weapons = []; // This is the list of allowed weapons.
* GIOE_Armors = []; // This is the list of allowed armors.
*
* So, basically you insert the list of allowed items' ID inside the bracket
* separated by comma.
*
* Example:
*
* GIOE_Items = [2,4,5,34,79]; // Five items are allowed to be used.
* GIOE_Weapons = [5]; // Only one weapon is allowed.
* GIOE_Armors = []; // No armor is allowed.
*
* You need to call the above Script Call before you open the custom item menu.
*
* When you are ready to use/give an item, use this plugin command to open the
* custom item menu:
*
* GIOE Open // Open the "Give Item On Event" menu.
*
* In this menu, all of allowed items above will be enabled (highlighted) while
* the rest will be "grey out" or disabled.
*
* There are 2 possible outcomes inside this menu:
* 1. You choose one of the enabled items.
* 2. You "exit" the menu by using cancel button.
*
* In the first scenario, 2 of the in-game variables will be changed.
* I called them "Category Variable" and "Item Variable".
*
* You must first edit the plugin configuration to decide which variables will
* be your "Category Variable" and "Item Variable" in the game. Be default,
* they are Variable 1 and Variable 2.
*
* After an item is chosen in the menu, "Category Variable" will be changed to
* either of the following:
*
* 1 // If the chosen item belong to "Item" category.
* 2 // If the chosen item belong to "Weapon" category.
* 3 // If the chosen item belong to "Armor" category.
*
* Next, "Item Variable" will be changed to the ID number of chosen item.
* If you choose "Hi-Potion" and that item's ID is 2, then "Item Variable" value
* will be 2 as well.
*
* And then your chosen item's total amount will be subtracted by 1.
*
* What happen if you "exit" the item menu?
* Both "Category Variable" and "Item Variable" will be 0.
*
* The rest is simply writing your list of conditional branches involving those
* variables.
*
* IMPORTANT!
* GIOE_Items, GIOE_Weapons, GIOE_Armors, "Category Variable", and "Item Variable"
* will be reseted to empty/0 when...
* 1. The event switch/change its page.
* 2. The moment you "exit" the custom item menu with cancel button.
* 3. When the game decides to perform "event refresh" for one reason or another.
*
* Don't worry, those values won't be reseted in the middle of event page.
*
* But, if for some reason you want to reset those values in the middle of event
* page, you can simply use this plugin command:
*
* GIOE Refresh // Reset those 5 values to empty and 0.
*
* ============================================================================
* Compatibility
* ============================================================================
* Try position this plugin below anything that alter/modify item menu.
* Just to be safe... ^_^
*
* ============================================================================
* Terms of Use
* ============================================================================
* Free to use in both commercial and non-commercial project as long as credit
* is given.
*
* ============================================================================
* Change Log
* ============================================================================
* Version 1.0:
* - Completed plugin.
*
*/
//=============================================================================
//=============================================================================
// Global Variables
//=============================================================================
var GIOE_Items = [];
var GIOE_Weapons = [];
var GIOE_Armors = [];
(function() { // IIFE
//=============================================================================
// Parameter Variables
//=============================================================================
Moogle_X.GIOE.parameters = PluginManager.parameters('Moogle_X_GiveItemOnEvent');
Moogle_X.GIOE.categoryVar = Number(Moogle_X.GIOE.parameters['Category Variable ID'] || 0);
Moogle_X.GIOE.itemVar = Number(Moogle_X.GIOE.parameters['Item Variable ID'] || 0);
//=============================================================================
// Game_Event
//=============================================================================
Moogle_X.GIOE.Game_Event_setupPage = Game_Event.prototype.setupPage;
Game_Event.prototype.setupPage = function() {
Moogle_X.GIOE.Game_Event_setupPage.call(this);
this.refreshGioe();
};
Game_Event.prototype.refreshGioe = function() {
GIOE_Items = [];
GIOE_Weapons = [];
GIOE_Armors = [];
$gameVariables.setValue(Moogle_X.GIOE.categoryVar, 0);
$gameVariables.setValue(Moogle_X.GIOE.itemVar, 0);
};
})(); // IIFE
//=============================================================================
// Scene_GiveItemOnEvent
//=============================================================================
function Scene_GiveItemOnEvent() {
this.initialize.apply(this, arguments);
}
Scene_GiveItemOnEvent.prototype = Object.create(Scene_Item.prototype);
Scene_GiveItemOnEvent.prototype.constructor = Scene_GiveItemOnEvent;
Scene_GiveItemOnEvent.prototype.initialize = function() {
Scene_Item.prototype.initialize.call(this);
};
Scene_GiveItemOnEvent.prototype.onItemOk = function() {
this._itemWindow.updateGioe();
this.popScene();
};
Scene_GiveItemOnEvent.prototype.createCategoryWindow = function() {
Scene_Item.prototype.createCategoryWindow.call(this);
this._categoryWindow.setHandler('cancel', this.exitGioe.bind(this));
};
Scene_GiveItemOnEvent.prototype.exitGioe = function() {
GIOE_Items = [];
GIOE_Weapons = [];
GIOE_Armors = [];
$gameVariables.setValue(Moogle_X.GIOE.categoryVar, 0);
$gameVariables.setValue(Moogle_X.GIOE.itemVar, 0);
this.popScene();
};
//=============================================================================
// Window_ItemList
//=============================================================================
Window_ItemList.prototype.updateGioe = function() {
if (this.item()) {
var category = 0;
var id = 0;
if (DataManager.isItem(this.item())) category = 1;
if (DataManager.isWeapon(this.item())) category = 2;
if (DataManager.isArmor(this.item())) category = 3;
id = this.item().id;
$gameVariables.setValue(Moogle_X.GIOE.categoryVar, category);
$gameVariables.setValue(Moogle_X.GIOE.itemVar, id);
$gameParty.loseItem(this.item(), 1, false);
}
};
Moogle_X.GIOE.Window_ItemList_isEnabled = Window_ItemList.prototype.isEnabled;
Window_ItemList.prototype.isEnabled = function(item) {
if (SceneManager._scene.constructor === Scene_GiveItemOnEvent) {
return this.isGioeEnabled(item);
} else {
return Moogle_X.GIOE.Window_ItemList_isEnabled.call(this, item);
}
};
Window_ItemList.prototype.isGioeEnabled = function(item) {
if (DataManager.isItem(item)) {
return GIOE_Items.contains(item.id);
} else if (DataManager.isWeapon(item)) {
return GIOE_Weapons.contains(item.id);
} else if (DataManager.isArmor(item)) {
return GIOE_Armors.contains(item.id);
} else {
return false;
}
};
(function() { // IIFE
//=============================================================================
// Game_Interpreter
//=============================================================================
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'GIOE') {
switch (args[0]) {
case 'Open':
SceneManager.push(Scene_GiveItemOnEvent);
break;
case 'Refresh':
GIOE_Items = [];
GIOE_Weapons = [];
GIOE_Armors = [];
$gameVariables.setValue(Moogle_X.GIOE.categoryVar, 0);
$gameVariables.setValue(Moogle_X.GIOE.itemVar, 0);
break;
}
}
};
})(); // IIFE
//=============================================================================
// End of File
//=============================================================================