-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyBook.js
347 lines (299 loc) · 11.3 KB
/
EnemyBook.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
//=============================================================================
// EnemyBook.js
//=============================================================================
/*:
* @plugindesc Displays detailed statuses of enemies.
* @author Yoji Ojima
*
* @param Unknown Data
* @desc The index name for an unknown enemy.
* @default ??????
*
* @help
*
* Plugin Command:
* EnemyBook open # Open the enemy book screen
* EnemyBook add 3 # Add enemy #3 to the enemy book
* EnemyBook remove 4 # Remove enemy #4 from the enemy book
* EnemyBook complete # Complete the enemy book
* EnemyBook clear # Clear the enemy book
*
* Enemy Note:
* <desc1:foobar> # Description text in the enemy book, line 1
* <desc2:blahblah> # Description text in the enemy book, line 2
* <book:no> # This enemy does not appear in the enemy book
*/
/*:ja
* @plugindesc モンスター図鑑です。敵キャラの詳細なステータスを表示します。
* @author Yoji Ojima
*
* @param Unknown Data
* @desc 未確認の敵キャラの索引名です。
* @default ??????
*
* @help
*
* プラグインコマンド:
* EnemyBook open # 図鑑画面を開く
* EnemyBook add 3 # 敵キャラ3番を図鑑に追加
* EnemyBook remove 4 # 敵キャラ4番を図鑑から削除
* EnemyBook complete # 図鑑を完成させる
* EnemyBook clear # 図鑑をクリアする
*
* 敵キャラのメモ:
* <desc1:なんとか> # 説明1行目
* <desc2:かんとか> # 説明2行目
* <book:no> # 図鑑に載せない場合
*/
(function() {
var parameters = PluginManager.parameters('EnemyBook');
var unknownData = String(parameters['Unknown Data'] || '??????');
var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'EnemyBook') {
switch (args[0]) {
case 'open':
SceneManager.push(Scene_EnemyBook);
break;
case 'add':
$gameSystem.addToEnemyBook(Number(args[1]));
break;
case 'remove':
$gameSystem.removeFromEnemyBook(Number(args[1]));
break;
case 'complete':
$gameSystem.completeEnemyBook();
break;
case 'clear':
$gameSystem.clearEnemyBook();
break;
}
}
};
Game_System.prototype.addToEnemyBook = function(enemyId) {
if (!this._enemyBookFlags) {
this.clearEnemyBook();
}
this._enemyBookFlags[enemyId] = true;
};
Game_System.prototype.removeFromEnemyBook = function(enemyId) {
if (this._enemyBookFlags) {
this._enemyBookFlags[enemyId] = false;
}
};
Game_System.prototype.completeEnemyBook = function() {
this.clearEnemyBook();
for (var i = 1; i < $dataEnemies.length; i++) {
this._enemyBookFlags[i] = true;
}
};
Game_System.prototype.clearEnemyBook = function() {
this._enemyBookFlags = [];
};
Game_System.prototype.isInEnemyBook = function(enemy) {
if (this._enemyBookFlags && enemy) {
return !!this._enemyBookFlags[enemy.id];
} else {
return false;
}
};
var _Game_Troop_setup = Game_Troop.prototype.setup;
Game_Troop.prototype.setup = function(troopId) {
_Game_Troop_setup.call(this, troopId);
this.members().forEach(function(enemy) {
if (enemy.isAppeared()) {
$gameSystem.addToEnemyBook(enemy.enemyId());
}
}, this);
};
var _Game_Enemy_appear = Game_Enemy.prototype.appear;
Game_Enemy.prototype.appear = function() {
_Game_Enemy_appear.call(this);
$gameSystem.addToEnemyBook(this._enemyId);
};
var _Game_Enemy_transform = Game_Enemy.prototype.transform;
Game_Enemy.prototype.transform = function(enemyId) {
_Game_Enemy_transform.call(this, enemyId);
$gameSystem.addToEnemyBook(enemyId);
};
function Scene_EnemyBook() {
this.initialize.apply(this, arguments);
}
Scene_EnemyBook.prototype = Object.create(Scene_MenuBase.prototype);
Scene_EnemyBook.prototype.constructor = Scene_EnemyBook;
Scene_EnemyBook.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_EnemyBook.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this._indexWindow = new Window_EnemyBookIndex(0, 0);
this._indexWindow.setHandler('cancel', this.popScene.bind(this));
var wy = this._indexWindow.height;
var ww = Graphics.boxWidth;
var wh = Graphics.boxHeight - wy;
this._statusWindow = new Window_EnemyBookStatus(0, wy, ww, wh);
this.addWindow(this._indexWindow);
this.addWindow(this._statusWindow);
this._indexWindow.setStatusWindow(this._statusWindow);
};
function Window_EnemyBookIndex() {
this.initialize.apply(this, arguments);
}
Window_EnemyBookIndex.prototype = Object.create(Window_Selectable.prototype);
Window_EnemyBookIndex.prototype.constructor = Window_EnemyBookIndex;
Window_EnemyBookIndex.lastTopRow = 0;
Window_EnemyBookIndex.lastIndex = 0;
Window_EnemyBookIndex.prototype.initialize = function(x, y) {
var width = Graphics.boxWidth;
var height = this.fittingHeight(6);
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
this.refresh();
this.setTopRow(Window_EnemyBookIndex.lastTopRow);
this.select(Window_EnemyBookIndex.lastIndex);
this.activate();
};
Window_EnemyBookIndex.prototype.maxCols = function() {
return 3;
};
Window_EnemyBookIndex.prototype.maxItems = function() {
return this._list ? this._list.length : 0;
};
Window_EnemyBookIndex.prototype.setStatusWindow = function(statusWindow) {
this._statusWindow = statusWindow;
this.updateStatus();
};
Window_EnemyBookIndex.prototype.update = function() {
Window_Selectable.prototype.update.call(this);
this.updateStatus();
};
Window_EnemyBookIndex.prototype.updateStatus = function() {
if (this._statusWindow) {
var enemy = this._list[this.index()];
this._statusWindow.setEnemy(enemy);
}
};
Window_EnemyBookIndex.prototype.refresh = function() {
this._list = [];
for (var i = 1; i < $dataEnemies.length; i++) {
var enemy = $dataEnemies[i];
if (enemy.name && enemy.meta.book !== 'no') {
this._list.push(enemy);
}
}
this.createContents();
this.drawAllItems();
};
Window_EnemyBookIndex.prototype.drawItem = function(index) {
var enemy = this._list[index];
var rect = this.itemRectForText(index);
var name;
if ($gameSystem.isInEnemyBook(enemy)) {
name = enemy.name;
} else {
name = unknownData;
}
this.drawText(name, rect.x, rect.y, rect.width);
};
Window_EnemyBookIndex.prototype.processCancel = function() {
Window_Selectable.prototype.processCancel.call(this);
Window_EnemyBookIndex.lastTopRow = this.topRow();
Window_EnemyBookIndex.lastIndex = this.index();
};
function Window_EnemyBookStatus() {
this.initialize.apply(this, arguments);
}
Window_EnemyBookStatus.prototype = Object.create(Window_Base.prototype);
Window_EnemyBookStatus.prototype.constructor = Window_EnemyBookStatus;
Window_EnemyBookStatus.prototype.initialize = function(x, y, width, height) {
Window_Base.prototype.initialize.call(this, x, y, width, height);
this._enemy = null;
this._enemySprite = new Sprite();
this._enemySprite.anchor.x = 0.5;
this._enemySprite.anchor.y = 0.5;
this._enemySprite.x = width / 2 - 20;
this._enemySprite.y = height / 2;
this.addChildToBack(this._enemySprite);
this.refresh();
};
Window_EnemyBookStatus.prototype.setEnemy = function(enemy) {
if (this._enemy !== enemy) {
this._enemy = enemy;
this.refresh();
}
};
Window_EnemyBookStatus.prototype.update = function() {
Window_Base.prototype.update.call(this);
if (this._enemySprite.bitmap) {
var bitmapHeight = this._enemySprite.bitmap.height;
var contentsHeight = this.contents.height;
var scale = 1;
if (bitmapHeight > contentsHeight) {
scale = contentsHeight / bitmapHeight;
}
this._enemySprite.scale.x = scale;
this._enemySprite.scale.y = scale;
}
};
Window_EnemyBookStatus.prototype.refresh = function() {
var enemy = this._enemy;
var x = 0;
var y = 0;
var lineHeight = this.lineHeight();
this.contents.clear();
if (!enemy || !$gameSystem.isInEnemyBook(enemy)) {
this._enemySprite.bitmap = null;
return;
}
var name = enemy.battlerName;
var hue = enemy.battlerHue;
var bitmap;
if ($gameSystem.isSideView()) {
bitmap = ImageManager.loadSvEnemy(name, hue);
} else {
bitmap = ImageManager.loadEnemy(name, hue);
}
this._enemySprite.bitmap = bitmap;
this.resetTextColor();
this.drawText(enemy.name, x, y);
x = this.textPadding();
y = lineHeight + this.textPadding();
for (var i = 0; i < 8; i++) {
this.changeTextColor(this.systemColor());
this.drawText(TextManager.param(i), x, y, 160);
this.resetTextColor();
this.drawText(enemy.params[i], x + 160, y, 60, 'right');
y += lineHeight;
}
var rewardsWidth = 280;
x = this.contents.width - rewardsWidth;
y = lineHeight + this.textPadding();
this.resetTextColor();
this.drawText(enemy.exp, x, y);
x += this.textWidth(enemy.exp) + 6;
this.changeTextColor(this.systemColor());
this.drawText(TextManager.expA, x, y);
x += this.textWidth(TextManager.expA + ' ');
this.resetTextColor();
this.drawText(enemy.gold, x, y);
x += this.textWidth(enemy.gold) + 6;
this.changeTextColor(this.systemColor());
this.drawText(TextManager.currencyUnit, x, y);
x = this.contents.width - rewardsWidth;
y += lineHeight;
for (var j = 0; j < enemy.dropItems.length; j++) {
var di = enemy.dropItems[j];
if (di.kind > 0) {
var item = Game_Enemy.prototype.itemObject(di.kind, di.dataId);
this.drawItemName(item, x, y, rewardsWidth);
y += lineHeight;
}
}
var descWidth = 480;
x = this.contents.width - descWidth;
y = this.textPadding() + lineHeight * 7;
this.drawTextEx(enemy.meta.desc1, x, y + lineHeight * 0, descWidth);
this.drawTextEx(enemy.meta.desc2, x, y + lineHeight * 1, descWidth);
};
})();