-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPHO_BattleTest.js
469 lines (468 loc) · 15.7 KB
/
APHO_BattleTest.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
//==========================================
// APHO_BattleTest.js
//==========================================
/*:
* @title Battle Test
* @author Apho
* @plugindesc v1.0 Provides various features to help with battle testing.
*
* @param BattleTestInitCode
* @text Battle Test Initialise Code
* @desc Code to run whenever a battle test starts. This runs after the default functions.
* @type note
* @default ""
*
* @param OverridesetupBattleTestItems
* @text Override setupBattleTestItems?
* @desc Override the default setupBattleTestItems function which gives the max number of all items?
* @type boolean
* @default false
*
* @param ExcludeItemPrefix
* @parent OverridesetupBattleTestItems
* @text Exclude Item Prefix
* @desc Items whose names start with this are never given during battle test. Leave blank to not exclude anything.
* @type string
* @default
*
* @param RegularItemQty
* @parent OverridesetupBattleTestItems
* @text Regular Item Quantity
* @desc Quantity of each regular item that will be given at the start of a battle test. This is an eval.
* @type string
* @default this.maxItems(item)
*
* @param KeyItemQty
* @parent OverridesetupBattleTestItems
* @text Key Item Quantity
* @desc Quantity of each key item that will be given at the start of a battle test. This is an eval.
* @type string
* @default 0
*
* @param HiddenItemAQty
* @parent OverridesetupBattleTestItems
* @text Hidden Item A Quantity
* @desc Quantity of each hidden item A that will be given at the start of a battle test. This is an eval.
* @type string
* @default 0
*
* @param HiddenItemBQty
* @parent OverridesetupBattleTestItems
* @text Hidden Item B Quantity
* @desc Quantity of each hidden item B that will be given at the start of a battle test. This is an eval.
* @type string
* @default 0
*
* @param HpRate
* @text HP Rate
* @desc Starting HP rate of the party during battle test.
* @type number
* @decimals 10
* @max 1
* @min 0
* @default 1
*
* @param MpRate
* @text MP Rate
* @desc Starting MP rate of the party during battle test.
* @type number
* @decimals 10
* @max 1
* @min 0
* @default 1
*
* @param TpBonus
* @text TP Bonus
* @desc Grant a flat bonus (or penalty) to TP at the start of battle test. Requires 'Preserve TP'.
* @type number
* @min -999999
* @default 0
*
* @param DetailedLog
* @text Detailed Log
* @desc Displays detailed information about the battle in the console.
* @type boolean
* @default true
*
* @param ValueDisplay
* @parent DetailedLog
* @text Value Display
* @desc How should values in the log be displayed as?
* @type select
* @option Decimal
* @value 0
* @option Percentage
* @value 1
* @default 1
*
* @param Decimals
* @parent DetailedLog
* @text Decimals
* @desc How many decimal places should values in the log be rounded to? Set to -1 for no rounding.
* @type number
* @min -1
* @default -1
*
* @param EscapeRate
* @parent DetailedLog
* @text Escape Rate
* @desc Show the current escape success rate. This is shown as a decimal, where 1.0 = 100%.
* @type boolean
* @default true
*
* @param PartyAvgHP
* @parent DetailedLog
* @text Party Average HP
* @desc Show the average HP% of party members. Dead members count as having 0%.
* @type boolean
* @default true
*
* @param PartyAvgMP
* @parent DetailedLog
* @text Party Average MP
* @desc Show the average MP% of party members. Members with 0 max MP count as having 0%.
* @type boolean
* @default true
*
* @param PartyAvgTP
* @parent DetailedLog
* @text Party Average TP
* @desc Show the average TP% of party members.
* @type boolean
* @default true
* @param TroopAvgHP
* @parent DetailedLog
* @text Troop Average HP
* @desc Show the average HP% of enemy troop members. Dead members count as having 0%.
* @type boolean
* @default true
*
* @param TroopAvgMP
* @parent DetailedLog
* @text Troop Average MP
* @desc Show the average MP% of enemy troop members. Members with 0 max MP count as having 0%.
* @type boolean
* @default true
*
* @param TroopAvgTP
* @parent DetailedLog
* @text Troop Average TP
* @desc Show the average TP% of enemy troop members.
* @type boolean
* @default true
*
* @param CloseAfterBattleTest
* @text Close after battle test
* @desc Close the game after a battle test ends?
* @type boolean
* @default true
*
* @help
* Battle Test Initialise Code:
* Allows for running custom code upon starting a battle test.
*
* Override setupBattleTestItems:
* Allows for overriding the default function that gives the max amount of items.
* If enabled, you may exclude items, as well as specify the quantity based on
* type. (regular item, key item, etc)
* Evals may also be used. Use 'item' to refer to the item.
*
* HP Rate, MP Rate, TP Bonus:
* Set the starting HP/MP Rate of the party during battle test.
* HP/MP Rate must be a value from 0 to 1, where 1 is full HP/MP.
* TP Bonus is a flat value added to starting TP. Can be negative.
* Requires 'Preserve TP'.
*
* Detailed Log:
* Allows for logging details of the battle to the console (F8).
* Unlike the other features, this also works during regular test play battles.
* This log will be updated at the end of each turn / battle.
* You may have the values displayed either as a decimal (where 1.0 = 100%), or
* as a percentage, as well as specify which values will be logged and number of
* decimal places rounded to.
*
* Close after battle test:
* By default, the game will close itself after a battle test.
* You may optionally choose to not close the game.
* This might be useful if you wish to review the logs at the end of battle.
* Note that doing so requires overriding BattleManager.updateBattleEnd
* whenever in a battle test.
*
* NOTES
* - Since this plugin is purely for testing purposes, it can be removed or
* disabled prior to deployment.
* - If using YEP_BattleEngineCore.js, place this plugin above it in the Plugin
* Manager.
*
* TERMS OF USE
* - Edits allowed for personal use.
* - Do not repost or claim as your own, even if edited.
*
* VERSION HISTORY
* v1.0 - 2023/10/19 - Initial release.
*/
(function(){
var parameters = PluginManager.parameters('APHO_BattleTest');
const GameParty_setupBattleTest = Game_Party.prototype.setupBattleTest;
Game_Party.prototype.setupBattleTest = function()
{
GameParty_setupBattleTest.call(this);
let HpRate = parseFloat(parameters['HpRate']);
let MpRate = parseFloat(parameters['MpRate']);
let TpBonus = parseInt(parameters['TpBonus']);
$gameParty.members().forEach(function(member) {
if(HpRate < 1)member.setHp(Math.round(member.mhp * HpRate));
if(MpRate < 1)member.setMp(Math.round(member.mmp * MpRate));
if(TpBonus != 0)member.gainTp(TpBonus);
});
eval(JSON.parse(parameters['BattleTestInitCode']));
};
const Game_Party_setupBattleTestItems = Game_Party.prototype.setupBattleTestItems;
Game_Party.prototype.setupBattleTestItems = function()
{
if(!parameters['OverridesetupBattleTestItems'])
{
Game_Party_setupBattleTestItems.call(this);
}
else
{
let ExcludeItemPrefix = parameters['ExcludeItemPrefix'];
let NeedsExclude = ExcludeItemPrefix && (ExcludeItemPrefix.length > 0);
$dataItems.forEach(function(item) {
if (item && item.name.length > 0 && (!NeedsExclude || !item.name.startsWith(ExcludeItemPrefix)))
{
switch(item.itypeId)
{
case 1:
this.gainItem(item, eval(parameters['RegularItemQty']));
break;
case 2:
this.gainItem(item, eval(parameters['KeyItemQty']));
break;
case 3:
this.gainItem(item, eval(parameters['HiddenItemAQty']));
break;
case 4:
this.gainItem(item, eval(parameters['HiddenItemBQty']));
break;
}
}
}, this);
}
}
//DETAILED LOGGING
var DetailedLog = JSON.parse(parameters['DetailedLog']);
if(DetailedLog)
{
//setting up functions and stuff
var ValueDisplay = parseInt(parameters['ValueDisplay']);
var Decimals = parseInt(parameters['Decimals']);
function round(n)
{
if(ValueDisplay == 0)
{
if(Decimals == -1)
{
return n;
}
else
{
return n.toFixed(Decimals);
}
}
else if(ValueDisplay == 1)
{
n *= 100;
if(Decimals == -1)
{
return n + "%";
}
else
{
return n.toFixed(Decimals) + "%";
}
}
}
var NeedsEscapeRate = JSON.parse(parameters['EscapeRate']);
function EscapeRate()
{
if(NeedsEscapeRate)
{
console.log("Escape Rate: " + round(BattleManager._escapeRatio));
}
}
var NeedsPartyAvgHP = JSON.parse(parameters['PartyAvgHP']);
function PartyAvgHP()
{
if(NeedsPartyAvgHP)
{
let total = 0, average = 0;
$gameParty.members().forEach(function(member){
total += member.hpRate();
});
average = total / $gameParty.members().length
console.log("Party HP: " + round(average));
}
}
var NeedsPartyAvgMP = JSON.parse(parameters['PartyAvgMP']);
function PartyAvgMP()
{
if(NeedsPartyAvgMP)
{
let total = 0, average = 0;
$gameParty.members().forEach(function(member){
total += member.mpRate();
});
average = total / $gameParty.members().length
console.log("Party MP: " + round(average));
}
}
var NeedsPartyAvgTP = JSON.parse(parameters['PartyAvgTP']);
function PartyAvgTP()
{
if(NeedsPartyAvgTP)
{
let total = 0, average = 0;
$gameParty.members().forEach(function(member){
total += member.tpRate();
});
average = total / $gameParty.members().length
console.log("Party TP: " + round(average));
}
}
var NeedsTroopAvgHP = JSON.parse(parameters['TroopAvgHP']);
function TroopAvgHP()
{
if(NeedsTroopAvgHP)
{
let total = 0, average = 0;
$gameTroop.members().forEach(function(member){
total += member.hpRate();
});
average = total / $gameTroop.members().length
console.log("Enemy Troop HP: " + round(average));
}
}
var NeedsTroopAvgMP = JSON.parse(parameters['TroopAvgMP']);
function TroopAvgMP()
{
if(NeedsTroopAvgMP)
{
let total = 0, average = 0;
$gameTroop.members().forEach(function(member){
total += member.mpRate();
});
average = total / $gameTroop.members().length
console.log("Enemy Troop MP: " + round(average));
}
}
var NeedsTroopAvgTP = JSON.parse(parameters['TroopAvgTP']);
function TroopAvgTP()
{
if(NeedsTroopAvgTP)
{
let total = 0, average = 0;
$gameTroop.members().forEach(function(member){
total += member.tpRate();
});
average = total / $gameTroop.members().length
console.log("Enemy Troop TP: " + round(average));
}
}
//actual logging
const BattleManager_startBattle = BattleManager.startBattle
BattleManager.startBattle = function()
{
BattleManager_startBattle.call(this);
console.log("==BATTLE START!==");
EscapeRate();
PartyAvgTP();
TroopAvgTP();
}
const BattleManager_endTurn = BattleManager.endTurn;
BattleManager.endTurn = function()
{
BattleManager_endTurn.call(this);
console.log("==TURN " + $gameTroop.turnCount() + " END==");
EscapeRate();
PartyAvgHP();
PartyAvgMP();
PartyAvgTP();
TroopAvgHP();
TroopAvgMP();
TroopAvgTP();
}
const BattleManager_processVictory = BattleManager.processVictory;
BattleManager.processVictory = function()
{
BattleManager_processVictory.call(this);
console.log("==VICTORY (TURN " + $gameTroop.turnCount() + ")==");
EscapeRate();
PartyAvgHP();
PartyAvgMP();
PartyAvgTP();
TroopAvgHP();
TroopAvgMP();
TroopAvgTP();
}
if(NeedsEscapeRate)
{
const BattleManager_processEscape = BattleManager.processEscape;
BattleManager.processEscape = function()
{
let OriginalEscapeRate = round(BattleManager._escapeRatio);
let EscapeSuccess = BattleManager_processEscape.call(this);
if(EscapeSuccess)
{
console.log("==ESCAPED (TURN " + ($gameTroop.turnCount() + 1) + ")==");
EscapeRate();
PartyAvgHP();
PartyAvgMP();
PartyAvgTP();
TroopAvgHP();
TroopAvgMP();
TroopAvgTP();
}else
{
console.log("==ESCAPE FAILED==\nEscape Rate: " + OriginalEscapeRate + " → " + round(BattleManager._escapeRatio));
}
}
}
const BattleManager_processAbort = BattleManager.processAbort;
BattleManager.processAbort = function()
{
BattleManager_processAbort.call(this);
console.log("==ABORTED (TURN " + $gameTroop.turnCount() + ")==");
EscapeRate();
PartyAvgHP();
PartyAvgMP();
PartyAvgTP();
TroopAvgHP();
TroopAvgMP();
TroopAvgTP();
}
const BattleManager_processDefeat = BattleManager.processDefeat;
BattleManager.processDefeat = function()
{
BattleManager_processDefeat.call(this);
console.log("==DEFEATED (TURN " + $gameTroop.turnCount() + ")==");
EscapeRate();
PartyAvgHP();
PartyAvgMP();
PartyAvgTP();
TroopAvgHP();
TroopAvgMP();
TroopAvgTP();
}
}
//Don't close the game after battleTest
var CloseAfterBattleTest = JSON.parse(parameters['CloseAfterBattleTest']);
if(!CloseAfterBattleTest)
{
const BattleManager_updateBattleEnd = BattleManager.updateBattleEnd;
BattleManager.updateBattleEnd = function()
{
if (!this.isBattleTest()) BattleManager_updateBattleEnd.call(this);
};
}
})();