-
Notifications
You must be signed in to change notification settings - Fork 0
/
KC_ActorFaceConditions.js
907 lines (821 loc) · 35.8 KB
/
KC_ActorFaceConditions.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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
/*!
MIT License
Copyright (c) 2022 K. Chavez <kchavez.dev@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*:
* @author K. Chavez
* @url https://github.com/kchavezdev/RMMZ-Plugins
* @target MZ
*
* @plugindesc [v1.1.1]Display Actor Face based on conditions.
*
* @help
* This plugin switches which actor face is displayed in menus based on
* conditions specified in the actor's notes.
*
* For compatibility, place this plugin after animatedSVEnemies,
* VisuMZ_1_BattleCore, or SoR_EnemySVSprite_MZ if you are using any of
* those plugins.
*
* Changelog:
* v1.0.0 - 2022/07/28
* - Initial release
* v1.0.1 - 2022/08/15
* - Commented out some debug logging
* v1.1.0 - 2022/08/29
* - Fixed svmotion condition behavior by moving the check from Game_Actor
* to Sprite_Actor and tracking the most recently started motion
* - Added ability to comment out lines
* - Fixed a few typos and style errors
* v1.1.1 - 2022/10/05
* - Fixed a bug that caused note tag parsing to fail if more than one
* eval and/or function command was used on the actor
*
* To begin a face condition list, start with the tag <face_conditions>, and to
* end the list, use the tag </face_conditions>. This list will be processed
* line by line. In general, every line has to be true for a face to be shown.
* However, using || between commands on the same line acts as an OR, so any
* condition on that line being true is treated as if the line is true.
*
* The commands that can be used in the list are as follows.
* Arguments will be denoted as <argument_name>. If an argument is invertible
* (i.e. you want the condition to be met when it is false), it can be prefixed
* by '!'.
*
* Also, lines can be "commented out" by starting the line with '//'.
*
* > addface <face_index> <face_name>
* * NOT INVERTIBLE
* | face_index: Index of the face to use if all conditions are true
* | face_name : Optional argument. Name of the face file to use if all
* conditions are true. If this is not specified, the face
* file currently being used by the actor will be used as
* the source image.
* This is the first command that should be written. All commands following
* this one will add conditions that apply to this particular combination of
* index and face file. Every condition must be satisfied for the actor's
* face to be replaced by the one specified in this command.
* # EXAMPLES: addface 2
* addface 4 my_faces_file
* addface 0 my faces file
*
* > svmotion <motion_name>
* * INVERTIBLE
* | motion_name: Name of the motion
* This command only has any effect when the sideview battle system is
* enabled. This condition is true if the actor's current side view
* motion (animation) is the same as motion_name.
*
* In RPG Maker MZ, the possible motion names are walk, wait, chant, guard,
* damage, evade, thrust, swing, missile, skill, spell, item, escape,
* victory, dying, abnormal, sleep, and dead
* # EXAMPLES: svmotion damage
* !svmotion chant
*
* > state <state_id>
* * INVERTIBLE
* | state_id: The single state to look for. This value can be found by
* looking at the number given for the state in the States tab
* of the database.
* This condition is true if the actor currently has the specified state.
* # EXAMPLES: state 1
* !state 5
*
* > stateset <state_id_list>
* * INVERTIBLE
* | state_id_list: A list of state IDs separated by commas. The format x-y
* where x and y are state IDs will add x and y as well as
* every state with an ID between x and y.
* This condition is met if the actor has ANY of the states with the IDs in
* the specified state ID list. For example, if the list was "1 3-5 7," then
* this condition would be true if the actor had state 1, 3, 4, 5, or 7.
* # EXAMPLES: stateset 1 3-10 20
* !stateset 2 4 5
*
* > switch <switch_id>
* * INVERTIBLE
* | switch_id: The ID of the single game switch this condition will check.
* This condition is true if the game switch with the specified ID is ON.
* # EXAMPLE: switch 10
*
* > switchset <switch_id_list>
* * INVERTIBLE
* | switch_id_list: A list of switch IDs separated by commas. The format x-y
* where x and y are switch IDs will add x and y as well as
* every switch with an ID between x and y.
* This condition is met if ANY of the switches in the list are ON. For
* example, if the list is "1 3-5 7", then this condition would be true
* if any of the switches 1, 3, 4, 5, or 7 are on.
* # EXAMPLES: switchset 4 1 5 12-16 2 41-68
* !switchset 1 3 5 9-15 2
*
* > compare <parameter1> <operation> <parameter2>
* * NOT INVERTIBLE
* | parameter1: First parameter. \v[x] gets the value in game variable x,
* and \s[y] gets the value in game switch y
* | operation : Possible symbols include =, !=, <, >, <=, and >=
* | parameter2: Second parameter. Also supports switch and variable
* substitution.
* This is one of the most verastile commands. The operation argument is
* the simplest and most self-explanatory. They are comparison operators,
* where = checks if parameter1 is equal to parameter 2, != checks if
* parameter 1 is NOT equal to parameter 2, and so on.
*
* The parameters can take on many values. As mentioned, game switches and
* game variables can be accessed using the \v[x] and \s[x] special codes.
* Another useful format that can be used is a.<some_property> where a is
* the current actor and <some_property> is a property of the actor. If it
* is accessible in a damage formula, it can be checked here. For example,
* a.atk gets the current attack of the character, and a.hp gets the
* current hp of the character. Unlike most of this list, these properties
* ARE case sensitive! So, a.atk is NOT the same as a.Atk!
*
* The actor properties hp, mp, and tp are special cases. They an be used
* like other properties, but there is another check that is exclusive to
* these stats. If the % symbol is at the end of the other parameter, then
* the percentage of these properties with respect to their maximums is
* calculated. So, a.hp > 90%, for example, would be true if the actor's
* hp is above 90%, regardless of what the 'raw' number values for the hp
* and max hp. This is only valid if one of the parameters is a.hp, a.mp,
* or a.tp and if the other parameter is a raw number or a game variable
* with a number stored in it. Also, to test for strings, only double quotes
* (") are supported.
* # EXAMPLES: compare a.atk > 10
* compare \v[1] = "test string"
* compare \v[11] > a.mp
* compare a.mp > 50%
* compare \v[11]% <= a.tp
* compare \s[2] = \s[5]
* compare "some value" != \v[2]
*
* > eval {<javascript_code>}
* * NOT INVERTIBLE
* | javascript_code: Raw JavaScript code to evaluate
* This condition evaluates the javascript code enclosed in the {} and is
* true if that code resolves to some truthy value. Unlike every other
* command except 'function', this command can span multiple lines as long
* as the opening { is on the same line as 'eval'. For convenience, a
* reference to this actor is stored in the constant 'actor'. To get this
* actor's ID, for example, you would write actor.actorId().
* # EXAMPLES: eval {$gameParty.inBattle() && actor.hp > 0}
* eval {
* Math.random() > 0.5 &&
* actor.hasSkill(1)
* }
*
* > function {<javascript_code>}
* * NOT INVERTIBLE
* | javascript_code: The body of a javascript function that takes no
* arguments.
* This condition is similar to eval. The main difference is that this
* command expects the you to explicitly return some truthy or
* falsey value. If not, nothing is returned and this condition is always
* falsey. Like eval, this command can take up multiple lines as long as the
* opening { is on the same line as 'function'.
* # EXAMPLES: function { return true; }
* function {
* let x = $gamePlayer.x;
* let y = $gamePlayer.y;
* return x < 22 && y >= 5;
* }
*
*/
var KCDev = KCDev || {};
KCDev.ActorFaceConditions = {};
(($) => {
'use strict';
$.comparisonFunctions = {
'=': function (param1, param2) { return param1 === param2; },
'!=': function (param1, param2) { return param1 !== param2; },
'<': function (param1, param2) { return param1 < param2; },
'>': function (param1, param2) { return param1 > param2; },
'<=': function (param1, param2) { return param1 <= param2; },
'>=': function (param1, param2) { return param1 >= param2; },
};
$.actorToCondList = new Map();
$.recentMotions = new Map();
class Face_Condition_Block {
/**
* @param {number} actorId
*/
constructor(actorId) {
/**@type {number}*/ this._actorId = actorId;
this._conditions = [];
}
isAnyTrue() {
const conds = this._conditions;
if (conds.length === 0) return true;
for (let i = 0; i < this._conditions.length; i++) {
const cond = conds[i];
if (cond.isTrue()) return true;
}
return false;
}
/**
* @param {string} param
*/
getParamObj(param) {
// a.someProperty
let matched = param.match(/A\.[A-Z]([A-Z]|\d)*/i);
if (matched) {
const /**@type {string} */ propName = param.slice(2);
if (propName.endsWith('()')) {
return {
actorId: this._actorId,
propertyName: propName.slice(0, propName.length - 2),
get val() { return $gameActors.actor(this.actorId)[this.propertyName](); }
}
}
else {
return {
actorId: this._actorId,
propertyName: propName,
get val() { return $gameActors.actor(this.actorId)[this.propertyName]; }
}
}
}
// game variable \v[x]
matched = param.match(/\\V\[\d+\]/i);
if (matched) {
return {
varId: parseInt(matched[0].match(/\d+/)[0]),
get val() { return $gameVariables.value(this.varId) }
}
}
// game switch \s[x]
matched = param.match(/\\S\[\d+\]/i);
if (matched) {
return {
switchId: parseInt(matched[0].match(/\d+/)[0]),
get val() { return $gameVariables.value(this.switchId) }
}
}
// try and eval; if it fails, then fall back to string
let chkVal;
try {
chkVal = eval(param);
} catch (error) {
// ignore error
}
return { val: chkVal ? chkVal : param }
}
/**
* @param {string} opSym
* @param {string} param1
* @param {string} param2
*/
addComparisonCondition(opSym, param1, param2) {
const op = $.comparisonFunctions[opSym];
const p1 = this.getParamObj(param1);
const p2 = this.getParamObj(param2);
if (param1.charAt(param1.length - 1) === '%') {
if (p2.propertyName === 'mp' || p2.propertyName === 'hp' || p2.propertyName === 'tp') {
this._conditions.push({
param1: this.getParamObj(param1.slice(0, param1.length - 1)),
param2: p2,
op: op,
actorId: this._actorId,
isTrue: function () {
const a = $gameActors.actor(this.actorId);
switch (this.param2.propertyName) {
case 'hp':
case 'mp':
return this.op(this.param1.val, this.param2.val * 1.0 / a['m' + this.param2.propertyName] * 100);
break;
case 'tp':
return this.op(this.param1.val, this.param2.val / 100.0 * 100);
break;
default:
break;
}
}
});
}
else {
throw new Error('Incorrectly formatted %');
}
}
else if (param2.charAt(param2.length - 1) === '%') {
if (p1.propertyName === 'mp' || p1.propertyName === 'hp' || p1.propertyName === 'tp') {
this._conditions.push({
param1: p1,
param2: this.getParamObj(param2.slice(0, param2.length - 1)),
op: op,
actorId: this._actorId,
isTrue: function () {
const a = $gameActors.actor(this.actorId);
switch (this.param1.propertyName) {
case 'hp':
case 'mp':
return this.op(this.param1.val * 1.0 / a['m' + this.param1.propertyName] * 100, this.param2.val);
break;
case 'tp':
return this.op(this.param1.val / 100.0 * 100, this.param2.val);
break;
default:
break;
}
}
});
}
else {
throw new Error('Incorrectly formatted %');
}
}
else {
this._conditions.push({
op: op,
param1: p1,
param2: p2,
isTrue: function () {
return this.op(this.param1.val, this.param2.val);
}
});
}
}
addSvMotionCondition(motionName, invert) {
this._conditions.push({
actorId: this._actorId,
motion: motionName,
truthVal: !invert,
isTrue: function () {
return ($.recentMotions.get(this.actorId) === motionName) === this.truthVal;
}
});
}
/**
* @param {number} switchId
* @param {boolean} invert
*/
addSwitchCondition(switchId, invert) {
this._conditions.push({
switchId: switchId,
truthVal: !invert,
isTrue: function () {
return $gameSwitches.value(this.switchId) === this.truthVal;
}
})
}
/**
* @param {number} stateId
* @param {boolean} invert
*/
addStateCondition(stateId, invert) {
this._conditions.push({
stateId: stateId,
actorId: this._actorId,
truthVal: !invert,
isTrue: function () {
return ($gameActors.actor(this.actorId).states().filter(state => this.stateId === state.id).length > 0) === this.truthVal;
}
});
}
/**
* @param {string} stateset
* @param {boolean} invert
*/
addStateSetCondition(stateset, invert = false) {
const parsedSet = getSetFromNumList(stateset);
this._conditions.push({
stateset: parsedSet,
actorId: this._actorId,
truthVal: !invert,
isTrue: function () {
const a = $gameActors.actor(this.actorId);
const states = a.states();
for (let i = 0; i < states.length; i++) {
if (this.stateset.has(states[i].id) === this.truthVal) return true;
}
return false;
}
});
}
/**
* @param {string} switchset
* @param {boolean} invert
*/
addSwitchSetCondition(switchset, invert = false) {
const parsedArr = Array.from(getSetFromNumList(switchset));
this._conditions.push({
switches: parsedArr,
truthVal: !invert,
isTrue: function () {
for (let i = 0; i < this.switches.length; i++) {
if ($gameSwitches.value(this.switches[i]) === this.truthVal) return true;
}
return false;
}
});
}
/**
* @param {string} evalStr
*/
addEvalCondition(evalStr) {
this._conditions.push({
isTrue: new Function('const actor = $gameActors.actor(' + this._actorId + '); return (' + evalStr + ')')
});
}
/**
* @param {string} fnStr
*/
addFuncCondition(fnStr) {
this._conditions.push({
isTrue: new Function('const actor = $gameActors.actor(' + this._actorId + ');' + fnStr)
});
}
};
/**
* @param {string} numList
*/
function getSetFromNumList(numList) {
const /**@type {string[]} */ list = numList.replaceAll(/\s+/g, ' ').split(' ');
const /**@type {Set<number>}*/ finalSet = new Set();
list.forEach(numStr => {
const split = numStr.split('-');
let errored = false;
switch (split.length) {
case 1:
const num = parseInt(numStr);
if (num) {
finalSet.add(num);
}
else {
errored = true;
}
break;
case 2:
let num1 = parseInt(split[0]);
let num2 = parseInt(split[1]);
if (num1 && num2) {
if (num1 > num2) {
const temp = num1;
num1 = num2;
num2 = temp;
}
for (let i = num1; i <= num2; i++) {
finalSet.add(i);
}
}
else {
errored = true;
}
break;
default:
errored = true;
break;
}
if (errored) {
console.error("tried to add invalid number " + numStr + " to set");
}
});
return finalSet;
}
class Face_Condition_List {
/**
* Face_Condition_List constructor
* @param {number} actorId Actor ID
* @param {number} faceIndex
* @param {string} faceName Name of the face file
*/
constructor(actorId, faceIndex, faceName = '') {
this._actorId = actorId;
this._faceIndex = faceIndex;
if (faceName === '') {
this.faceName = function () { return this.actor().faceName(); }
}
else {
this._faceName = faceName;
}
this._conditionBlocks = [];
}
/**
* @param {Face_Condition_Block} condBlock
*/
addConditionBlock(condBlock) {
this._conditionBlocks.push(condBlock);
}
faceName() {
return this._faceName;
}
actorId() {
return this._actorId;
}
faceIndex() {
return this._faceIndex;
}
/**
* Get the actor this condition applies to
* @returns {Game_Actor}
*/
actor() {
return $gameActors.actor(this.actorId());
}
isAllConditionsTrue() {
for (let i = 0; i < this._conditionBlocks.length; i++) {
if (!this._conditionBlocks[i].isAnyTrue()) return false;
}
return true;
}
};
function printNoteLineError(line, actorId) {
console.error("There was an error processing the line \n" + line + "\n in actor " + actorId + "'s notetag");
}
function printCommandArgNumError(commandName) {
console.error("Incorrect number of arguments for command " + commandName);
}
function throwGenericError() {
throw new Error("An error occurred in KC_ActorFaceConditions");
}
/**
* @param {string} s string to have parts replaced
* @param {string} openingChar Closing wrapper char
* @param {string} closingChar Opening wrapper char
* @param {string} placeholderBase This is the string substituted in for the replaced characters
* @param {string} placeholderPre This is placed before the base when substituting it in
* @param {string} placeholderPost This is placed after the base when substituting it in
* @returns {{newStr: string, blockMap: Map<string, string>}}
*/
function extractWrappers(s, openingChar, closingChar, placeholderBase, placeholderPre, placeholderPost) {
const /**@type {Map<string, string>} */ finalMap = new Map();
let placeholderCounter = 0;
let closeCounter = 0;
let openCounter = 0;
let openIndex = -1;
let pos = 0;
while (pos < s.length) {
if (openIndex < 0) {
openIndex = s.indexOf(openingChar, pos);
if (openIndex < 0) {
break; // no more opening characters so break
}
closeCounter = 0;
openCounter = 1;
pos = openIndex;
}
while (closeCounter < openCounter && pos < s.length) {
pos++;
if (s.charAt(pos) === openingChar) {
openCounter++;
}
else if (s.charAt(pos) === closingChar) {
closeCounter++;
}
}
const extractedText = s.substring(openIndex + 1, pos);
finalMap.set(placeholderBase + placeholderCounter++, extractedText);
openIndex = -1;
}
let finalStr = s;
for (const entry of finalMap.entries()) {
finalStr = finalStr.replace(openingChar + entry[1] + closingChar, placeholderPre + entry[0] + placeholderPost);
}
return {
newStr: finalStr,
blockMap: finalMap
}
}
/**
* Parses note tag to set up face condition list
* @param {string} tag The value of the FACE_CONDITIONS note tag
*/
function parseNoteTag(actorId, tag) {
// console.log(tag);
const extract = extractWrappers(tag, '{', '}', 'code', '', '\n');
// console.log(extract);
const lines = extract.newStr.split('\n');
const /**@type {Face_Condition_List[]} */ finalList = [];
let /**@type {Face_Condition_List} */ currList;
lines.forEach(line => {
const /**@type {string}*/ formattedLine = line.replaceAll(/\s+/g, ' ').trim();
if (formattedLine === '' || formattedLine.startsWith('//')) return;
const firstSpaceIdx = formattedLine.indexOf(' ');
// console.log(formattedLine);
if (firstSpaceIdx > 0) {
const noteKeyword = formattedLine.slice(0, firstSpaceIdx).toLowerCase();
const noteArgs = formattedLine.slice(firstSpaceIdx + 1, line.length);
if (noteKeyword === 'addface') {
const addFaceArgs = noteArgs.split(' ');
if (!addFaceArgs[0].match(/\d+/)) {
printNoteLineError(line, actorId);
throwGenericError();
}
const addFaceIndex = parseInt(addFaceArgs[0]);
currList = new Face_Condition_List(actorId, addFaceIndex, noteArgs.replace(addFaceArgs[0], '').trim());
finalList.push(currList);
}
else {
if (!currList) {
printNoteLineError(line, actorId)
console.error("No face specified before argument!");
throwGenericError();
}
const condBlock = new Face_Condition_Block(actorId);
const /**@type {string[]} */ blockComponents = formattedLine.split('||');
blockComponents.forEach(command => {
const trimmed = command.trim();
// console.log(trimmed);
const commandFirstSpace = trimmed.indexOf(' ');
if (commandFirstSpace > 0) {
const commandKeyword = trimmed.slice(0, commandFirstSpace).toLowerCase();
const commandArgs = trimmed.slice(commandFirstSpace + 1, trimmed.length);
switch (commandKeyword) {
case 'compare':
const extractedQuotes = extractWrappers(commandArgs, '"', '"', "arg");
const cmpArgs = extractedQuotes.newStr.split(' ');
if (cmpArgs.length === 3) {
if ($.comparisonFunctions[cmpArgs[1]]) {
try {
condBlock.addComparisonCondition(cmpArgs[1], cmpArgs[0], cmpArgs[2]);
} catch (error) {
printNoteLineError(line, actorId);
console.error(error.message);
throwGenericError();
}
}
else {
printNoteLineError(line, actorId);
console.error('Invalid operation specified!');
throwGenericError();
}
}
else {
printNoteLineError(line, actorId);
printCommandArgNumError(commandKeyword);
throwGenericError();
}
break;
case 'switch':
case '!switch':
const switchId = parseInt(commandArgs);
if (switchId) {
condBlock.addSwitchCondition(switchId, commandKeyword.charAt(0) === '!');
}
else {
printNoteLineError(line, actorId);
console.error('Invalid switch ID specified');
throwGenericError();
}
break;
case 'switchset':
case '!switchset':
condBlock.addSwitchSetCondition(commandArgs, commandKeyword.charAt(0) === '!')
break;
case 'state':
case '!state':
const stateId = parseInt(commandArgs);
if (stateId) {
condBlock.addStateCondition(stateId, commandKeyword.charAt(0) === '!');
}
else {
printNoteLineError(line, actorId);
console.error('Invalid state ID specified');
throwGenericError();
}
break;
case 'stateset':
case '!stateset':
condBlock.addStateSetCondition(commandArgs, commandKeyword.charAt(0) === '!')
break;
case 'eval':
try {
condBlock.addEvalCondition(extract.blockMap.get(commandArgs));
} catch (error) {
printNoteLineError(line, actorId);
console.error(error.message);
console.error('Error creating function');
throwGenericError();
}
break;
case 'function':
try {
condBlock.addFuncCondition(extract.blockMap.get(commandArgs));
} catch (error) {
printNoteLineError(line, actorId);
console.error(error.message);
console.error('Error creating function');
throwGenericError();
}
break;
case 'svmotion':
case '!svmotion':
condBlock.addSvMotionCondition(commandArgs, commandKeyword.charAt(0) === '!');
break;
default:
printNoteLineError(line, actorId);
console.error('Unrecognized command!');
throwGenericError();
break;
}
}
else {
printNoteLineError(line, actorId);
console.error('No arguments specified!');
throwGenericError();
}
});
currList.addConditionBlock(condBlock);
}
}
else {
printNoteLineError(line, actorId);
console.error('No arguments specified!');
throwGenericError();
}
});
$.actorToCondList.set(actorId, finalList)
};
$.Scene_Boot_onDatabaseLoaded = Scene_Boot.prototype.onDatabaseLoaded;
Scene_Boot.prototype.onDatabaseLoaded = function () {
$.Scene_Boot_onDatabaseLoaded.apply(this, arguments);
for (let i = 1; i < $dataActors.length; i++) {
const actor = $dataActors[i];
const /**@type {string} */ note = actor.note;
const conditionTag = note.match(/<face_conditions>(.|\s)*<\/face_conditions>/i);
if (conditionTag) {
const cond = conditionTag[0];
const endTag = '</face_conditions>';
parseNoteTag(actor.id, cond.slice(endTag.length, cond.length - endTag.length));
}
}
// console.log($.actorToCondList);
};
$.Window_StatusBase_drawActorFace = Window_StatusBase.prototype.drawActorFace;
/**
* @param {Game_Actor} actor
* @param {number} x
* @param {number} y
* @param {number} width
* @param {number} height
*/
Window_StatusBase.prototype.drawActorFace = function (actor, x, y, width, height) {
const /**@type {Face_Condition_List[]} */ faceConditions = $.actorToCondList.get(actor.actorId());
if (faceConditions && actor.isFaceConditionEnabled()) {
for (let i = 0; i < faceConditions.length; i++) {
const condList = faceConditions[i];
if (condList.isAllConditionsTrue()) {
this.drawFace(condList.faceName(), condList.faceIndex(), x, y, width, height);
return;
}
}
}
$.Window_StatusBase_drawActorFace.apply(this, arguments);
};
/**
* @returns {boolean}
*/
Game_Actor.prototype.isFaceConditionEnabled = function () {
return this._faceConditionEnabled;
};
/**
* @param {boolean} enabled
*/
Game_Actor.prototype.setFaceConditionEnabled = function (enabled) {
this._faceConditionEnabled = enabled;
};
$.Game_Actor_setup = Game_Actor.prototype.setup;
Game_Actor.prototype.setup = function () {
$.Game_Actor_setup.apply(this, arguments);
this._faceConditionEnabled = !!$.actorToCondList.get(this.actorId()) && !$dataActors[this.actorId()].note.match(/<face_conditions_disabled>/i);
};
$.BattleManager_displayBattlerStatus = BattleManager.displayBattlerStatus;
BattleManager.displayBattlerStatus = function (battler, current) {
$gameTemp.requestBattleRefresh();
$.BattleManager_displayBattlerStatus.apply(this, arguments);
};
// Enemy side view actor sprite compatibility
if (Game_Enemy.prototype.requestMotion) {
Game_Enemy.prototype.isFaceConditionEnabled = function () { return false; };
}
$.Sprite_Actor_startMotion = Sprite_Actor.prototype.startMotion;
Sprite_Actor.prototype.startMotion = function (motionType) {
if (this._actor.isFaceConditionEnabled?.()) {
$.recentMotions.set(this._actor.actorId(), motionType);
$gameTemp.requestBattleRefresh();
}
$.Sprite_Actor_startMotion.apply(this, arguments);
};
$.BattleManager_startBattle = BattleManager.startBattle;
BattleManager.startBattle = function () {
$.BattleManager_startBattle.apply(this, arguments);
};
$.BattleManager_endBattle = BattleManager.endBattle;
BattleManager.endBattle = function (result) {
$.BattleManager_endBattle.apply(this, arguments);
$.recentMotions.clear();
};
})(KCDev.ActorFaceConditions);