-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTyruswoo_EventGenerator.js
1604 lines (1522 loc) · 67.4 KB
/
Tyruswoo_EventGenerator.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
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=============================================================================
// Event Generator
// For RPG Maker MZ
// By Kathy "McKathlin" Bunn and Scott Tyrus "Tyruswoo" Washburn
//=============================================================================
/*
* MIT License
*
* Copyright (c) 2023 Kathy Bunn and Scott Tyrus Washburn
*
* 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.
*/
var Imported = Imported || {};
Imported.Tyruswoo_EventGenerator = true;
var Tyruswoo = Tyruswoo || {};
Tyruswoo.EventGenerator = Tyruswoo.EventGenerator || {};
/*:
* @target MZ
* @plugindesc MZ v2.0.2 Generate events during gameplay! Model events from any map. Use formulas to determine quantity to generate.
* @author McKathlin and Tyruswoo
* @url https://www.tyruswoo.com
*
* @help Tyruswoo Event Generator for RPG Maker MZ
* ============================================================================
* Compatibility Note
*
* If VisuStella plugins are present, place Tyruswoo Event Generator UNDER all
* VisuStella plugins in your plugin list.
*
* Tyruswoo Event Generator aims to be compatible with most other plugins.
* If you encounter any compatibility issues, please contact us at Tyruswoo.com
* and we'll do our best to work out a fix.
* ============================================================================
* This plugin makes it possible to generate events at runtime (during
* gameplay).
*
* Generated events are modeled after events from other maps. Locations for
* newly generated events can be determined by coordinates, by region(s), or by
* area. The quantity of events generated can be determined by a quantity
* formula, so that multiple events can generate simultaneously from one plugin
* command.
*
* If there are multiple designated models, one model is selected at random for
* each event spawned. If there are multiple valid spawn locations, one of the
* valid locations is selected at random for each spawned event.
* ============================================================================
* Plugin commands, their arguments, and short explanations:
*
* Generate Event(s) This plugin command allows you to spawn
* events! Duplicates a model event from any
* other map, and places the new event in the
* current map, at the desired location!
* - Model Event(s) A list of event ID numbers and/or event
* names that may be generated. Each time an
* event generates, a random model is
* selected. Event models in this list all
* come from default map (as defined in the
* plugin parameters).
* - Model Event(s) from Maps Allows using event models from any map.
* Events from multiple different maps can all
* be used as models simultaneously. Combines
* with the Default Model Map's model event(s)
* list (see above).
* > Model Map ID Map ID of any map, to use for model event.
* (If not entered, uses Default Model Map.)
* > Model Event The event ID number and/or event name of
* this model event.
* - Loc Criteria for valid location(s) where
* event(s) may spawn.
* > X X coordinate of origin (may be relative).
* > Y Y coordinate of origin (may be relative).
* > Location Mode Coordinates, Region, or Area
* * Region(s) If region mode, use region(s) listed here.
* * Area If area mode, use this area.
* - X1 First X coord of area (may be relative).
* - Y1 First Y coord of area (may be relative).
* - X2 Second X coord of area (may be relative).
* - Y2 Second Y coord of area (may be relative).
* > Relativity How to interpret the origin coordinates.
* * Relativity Mode Absolutes, or relative to event or player.
* - Event ID Loc relative to event of this event ID.
* - Party Member Loc relative to selected party member.
* - Orientational Shift Shift loc based on character's direction.
* > Forward Shift Shift dir character is facing (- backward).
* > Rightward Shift Shift toward right of character (- left).
* > Gen on Blocked Tiles True: Allow spawns on impassible tiles.
* > Gen on Walls True: Allow spawns on tops of walls.
* > Gen on Solid Events True: Allow spawns on other solid events.
* > Gen on Player True: Allow spawns on player/followers.
* > Min Player Distance Only allows spawns at least this distance
* number of tiles away from player.
* - Quantity Determines number of events to spawn.
* > Maximum Maximum number of events to spawn.
* > Minimum Minimum number of events to spawn.
* > Formula Formula determines how many events spawn.
* (Note that Slain in formula by default is
* number of events ever slain in the map. If
* only one region is being used for this
* command's event generation, then map's
* regional slain count is used in formula.)
* * Slain Name If using Slain in formula, then this name
* specifies a single enemy name that is used
* for calculations. Slain of other names will
* be ignored for calculations.
*
* Add Slain Add 1 to the map's current slain count. Always
* adds 1 to total slain of the current save file.
* (This is useful in order to change the Slain
* count, if a Formula uses Slain count for
* determining number of events to generate.)
* - Map ID Map ID to which one slain is added. Defaults to
* the map ID of the event that is running the
* plugin command (which is always current map).
* - Event Name Event name to which one slain is added.
* Defaults to the name of the event that is
* running the plugin command.
* - Generation Region Region to which one slain is added (for the
* current map). Defaults to the region in which
* the current event was purposefully generated.
* (To be considered a purposeful regional
* generation, a generated event must be spawned
* using a location mode of Region, and there must
* have been only 1 region in the Region(s) list.)
*
* ============================================================================
* Plugin parameters:
* Default Model Map When a model does not specify a model map ID,
* use this default model map ID.
* Gen on Blocked Tiles Generated events may spawn on impassible tiles.
* Gen on Walls Generated events may spawn on top of walls.
* Gen on Solid Events Generated events may spawn on other events.
* Gen on Player Generated events may spawn on player/followers.
* Min Player Distance Generated events only can spawn if at least
* this many tiles away from player.
* Default Quantity Formula When the Generate Event(s) plugin command does
* not specify quantity formula, use this formula.
* Default Maximum Default number of events to spawn each time a
* Generate Event(s) command runs.
* Default Minimum Default minimum number of events to spawn each
* time a Generate Event(s) command runs. Even if
* formula determines a lesser quantity, at least
* the minimum quantity of events will be
* generated.
* ============================================================================
* Script calls:
*
* This first script call can be used to generate an event without using the
* plugin command Generate Event(s). However, the plugin command makes it much
* easier to change the location and quantity of events created, and therefore
* the plugin command is highly recommended. However, this script call is here
* in case you would like to use it.
*
* $gameMap.generateEvent(modelMapId, modelEventId, x, y, genRegion)
* Where modelMapId is the ID number of the model map; modelEventId is
* the ID number of the model event (from the model map); x and y are the
* absolute coordinates on the current map, at which to place the newly
* generated event; and genRegion is the ID number of the region that claims
* this generated event (region from 1 to 255; leave blank or 0 for no
* region). This plugin command generates/spawns an event at absolute
* coordinates (x, y) on the current map. The event generated is based on
* the model event. The model event is found on the map with ID number of
* modelMapId, with an eventId of modelEventId. The genRegion (Generation
* Region) is used in assigning the generated event to a Slain region, if
* it ever runs the Add Slain command.
*
* Note that the following script calls are most useful within Conditional
* Branches that make changes in what occurs based on number of slain events.
*
* $gameSystem.slain()
* Returns the total number of Slain (in the current save file).
*
* $gameSystem.slain(mapId)
* Where mapId is a number of the desired map. Returns the number of slain
* in the current map (for the current save file).
*
* $gameSystem.slain(mapId, regionId)
* Where mapId is a number ID of a map and regionId is a region (1 to 255).
* Returns number of slain of the specified region of the specified map.
* (Only includes slain if generated events were purposefully generated
* into that single region, or if Add Slain command specified the region.)
*
* $gameSystem.slain(mapId, 0, "eventName")
* Where mapId is a number of a map, regionId is 0 (to be ignored), and
* eventName is the name of the slain events. Returns number of slain in the
* map that had the specified name. (Ignores regions.)
*
* $gameSystem.slain(mapId, regionId, "eventName")
* Where mapId is a number ID of a map, regionId is a region number (1 to
* 255), and eventName is the name of the slain events. Returns number of
* slain in specified region of specified map, only if the slain events
* had the specified name. (Only includes slain if generated events were
* purposefully generated into that single region, or if Add Slain command
* specified the region.)
*
* $gameSystem.slain(0, 0, "eventName")
* Where eventName is the name of the slain events. mapId is 0 (to be
* ignored), and regionId is 0 (to also be ignored). Returns number of slain
* from any map that had the specified name.
*
* In some cases, you might only want the event to do something if the event
* was generated by the Event Generator plugin. For example, you might only
* want to add to the slain count if the event was generated. For this reason,
* the following script calls are available. Use one of these scripts inside
* a Conditional Branch to make it only happen when the event was generated.
*
* $gameMap.eventWasGenerated()
* Checks if the map's currently active event was generated, and returns
* true or false.
*
* $gameMap.enemyWasGenerated()
* Same as $gameMap.eventWasGenerated(). Checks if the map's currently
* active event was generated, and returns true or false.
*
* If you are using the Troop Control plugin, you might want to vary your
* troop's enemies depending on the name of the currently active event. For
* this reason, the following script calls are available. You can put these
* script calls within your troop's commands to check the current
* on-map-event's name, in order to determine which enemies to add using
* Troop Control.
*
* $gameMap.eventName()
* Gets the name of the map's currently active event.
*
* $gameMap.enemyName()
* This is the same as $gameMap.eventName(). It gets the name of the map's
* currently active event. This function exists to make the troop's script
* calls easier to understand for game designers.
* ============================================================================
* Basics of how to use this plugin:
* 1. Install the plugin, and activate it using your project's Plugin Manager.
* 2. Define which map you want to be the Default Model Map where most of your
* model events will be found. You can define this in the plugin parameters.
* 3. Somewhere on your map, run the Generate Event(s) plugin command.
* > Be sure to select at least one model event. You can either use the
* model's event ID number, or the name of the event.
* > Be sure to define the location at which the event should spawn. The
* location may be Coordinates, Region, or Area. Keep in mind that by
* default, the events do not spawn on other solid events or other solid
* tiles, or on the player. So, make sure that there is at least one
* valid spawn location, so that the event can spawn.
* > The Quantity is by default 1. If you want to change the number of
* events to spawn, you can do so by changing the Quantity arguments.
* ============================================================================
* Advanced uses for this plugin:
*
* - Randomly generated on-map enemies!
* 1. When the player enters a new map, have an Autorun event that spawns in
* events, with each event representing a troop. (The Autorun event will
* need to use the Erase event command to disappear after done generating
* events.) Using location mode of Region can be useful for indicating
* numerous valid spawn locations, but Area also can be used.
* 2. Make sure the model events use the "Battle Processing..." event
* command. Now you have on-map enemies that are randomly generated each
* time the player enters the map!
* 3. Optional: If the player wins the battle, then use the Add Slain
* plugin command to keep track of how many enemies were slain in the
* current map where the player fought the battle. This allows you to
* use a formula incorporating the Slain count to determine the number of
* events to generate next time event generation occurs on the current
* map.
*
* - Use the Slain feature to make the number of generated events change!
* > Use the Add Slain plugin command to increase the number of slain on
* the current map. Then, make sure that your Generate Event(s) plugin
* command uses a formula that incorporates the number of slain.
* * For example, the "Maximum - Slain" formula will make 1 less event
* appear for each Add Slain plugin command that is run. This makes
* it seem like events can be cleared quickly.
* * Another example: "Maximum - Slain / 2" makes the number of events
* generated decrease more gradually. So, when the player leaves a map
* and later returns, there may be fewer amounts, but the decrease is
* less drastic. This can be useful for making it seem like maps are
* slowly being cleared of events, but that the events still are
* increasing/generating while the player is gone from the map.
*
* - Weighted event lists!
* > You can make a certain model be selected more often than other models!
* Since models are selected randomly by the Generate Event(s) plugin,
* simply duplicate the model by using Ctrl+C then Ctrl+V, and that model
* will be weighted to be selected more often than other models in the
* list. This is because each model entry is counted, even if it is the
* same as another entry.
*
* - Moving spawner!
* > Using a Generate Event(s) location mode of Area or Coordinates, you
* can have an event spawner that moves!
* * An event could move on its own, generating other events from itself
* while it moves.
* - A fire event could move around, with little spark events
* generating off of it!
* * A spawner event could be pushed by the player, with enemies
* generating from it as it is moved. (Combine this with the Min
* Player Distance argument to make events generate slightly distant
* from the player while the player is pushing.)
* - This might be a quest to destroy a spawner by pushing it to
* a certain place on the map!
* - Imagine bandits that try to sneak up on the player whenever the
* player moves a pushable treasure!
*
* - Script calls in Conditional Branches: Change story based on events slain!
* > Using script calls, you can check the number of slain in various ways.
* You can use this to make any event happen differently, depending on
* the number of slain! This could be total slain anywhere in the world,
* number slain in a certain map, number slain of a certain region of
* a map, or number slain of a certain event name!
* > This plugin could be used for keeping track of numbers of events slain
* of various (any) names in various (any) maps or regions. Then, this
* information could be used to determine story and quest components of
* the game.
* * For example, script calls with Conditional Branches can be used to
* make a story change happen if certain enemy names are slain
* sufficiently in a map. There may be a map full of wild beasts, but
* then if the player slays a sufficient quantity of wild beasts and
* leaves, the player may return to the map later to find a different
* enemy type (such as goblins) have made the map their home since the
* wild beasts were gone! Many such story elements can be accomplished
* by using script calls in conditional branches!
* ============================================================================
* Note: The maximum number of events that can be placed using the RPG Maker MZ
* editor is 999 events. For this reason, events generated by this plugin
* begin with eventId of 1000 and higher.
* ============================================================================
* Visit Tyruswoo.com to ask for help, donate, or browse more of our plugins.
* ============================================================================
* Version History:
*
* v1.0 9/28/2020
* - Event Generator released for RPG Maker MZ!
*
* v2.0 1/12/2023
* - Events now generate 20+ times faster! Efficiency greatly improved!
* - Script calls added, useful for conditional branches:
* $gameMap.eventWasGenerated()
* $gameMap.enemyWasGenerated()
* $gameMap.eventName()
* $gameMap.enemyName()
* - New Feature: Shared slain count map groups. Maps in the same group share
* their slain counts.
* - Bugfix: Fixed duplicative creation of sprites for events that already
* existed on the map at the time of the event generator function running.
* The bug resulted in many events (and party members) having decreased
* transparency of transparent pixels. Now, this bugfix results in the
* transparency of all sprites remaining as intended.
* - Bugfix: Fixed a bug in which encounters belonging to a region did not
* correctly determine an eventNames index when creating a new slain record.
* This fix prevents a crash when looking up indices that were inadvertently
* created without a name or value.
* - Bugfix: Fixed slain count crash that happened when player enters a map
* that didn't exist when the save file was first created.
* - Code Improvement: Moderately reduced save bloat by overhauling save
* counting and replacing the array of arrays with a minimal object that
* takes multi-part keys (in a similar fashion to Game_SelfSwitches).
*
* v2.0.1 8/28/2023
* - This plugin is now free and open source under the MIT license.
*
* v2.0.2 9/23/2024
* - Fixed a compatibility issue with with VisuMZ_1_EventsMoveCore.js
* and confirmed compatibility when placed BELOW VisuStella plugins.
* - Fixed generated events not knowing their starting location,
* a property used by Tyruswoo Event AI.
*
* ============================================================================
* MIT License
*
* Copyright (c) 2023 Kathy Bunn and Scott Tyrus Washburn
*
* 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.
* ============================================================================
* Remember, only you can build your dreams!
* -Scott Tyrus "Tyruswoo" Washburn and Kathy "McKathlin" Bunn
*
* @param Default Model Map
* @type number
* @min 1
* @default 1
* @desc Enter a valid map ID number. When a model event does not specify its model map, use this map ID as the model map.
*
* @param Gen on Blocked Tiles
* @type boolean
* @default false
* @desc True: Events can generate on impassible tiles.
* False: Events cannot generate on impassible tiles.
*
* @param Gen on Walls
* @parent Gen on Blocked Tiles
* @type boolean
* @default false
* @desc True: Events can generate on walls (tileset's A4 tiles).
* False: Events cannot generate on walls (tileset's A4 tiles).
*
* @param Gen on Solid Events
* @parent Gen on Blocked Tiles
* @type boolean
* @default false
* @desc True: Events can generate on solid/impassible events.
* False: Events cannot generate on solid/impassible events.
*
* @param Gen on Player
* @parent Gen on Blocked Tiles
* @type boolean
* @default false
* @desc True: Events can generate on party leader or followers.
* False: Events cannot generate on party leader/followers.
*
* @param Min Player Distance
* @parent Gen on Blocked Tiles
* @type number
* @min 0
* @desc Minimum distance away from player to be considered a valid spawn point for a generated event.
*
* @param Default Quantity Formula
* @type select
* @option Maximum
* @option Random number between Minimum and Maximum
* @option Average of 2 random numbers between Minimum and Maximum
* @option Average of 3 random numbers between Minimum and Maximum
* @option Max - Slain
* @option Max - Slain / 2
* @option Max - Slain / 3
* @option Max - Slain / 4
* @option Max - Slain / 5
* @option Max - Slain / 6
* @option Max - Slain / 7
* @option Max - Slain / 8
* @option Max - Slain / 9
* @option Max - Slain / 10
* @default Maximum
* @desc Formula used to calculate number of events to generate. Slain uses map total, unless location is a single region.
*
* @param Default Maximum
* @parent Default Quantity Formula
* @type number
* @min 1
* @default 1
* @desc Maximum number of events to be generated by commands, by default.
* If not defined, then defaults to 1.
*
* @param Default Minimum
* @parent Default Quantity Formula
* @type number
* @min 0
* @default 1
* @desc Minimum number of events to be generated by commands, by default.
* If not defined, then Minimum is the same as Maximum.
*
* @param Slain Count Sharing Map Groups
* @type text[][]
* @default ["[]"]
* @desc Each group is a set of maps, by map name or map ID,
* that share slain count among them.
*
* @command generate_event
* @text Generate Event(s)
* @desc Generate a new event, based on a model event. If multiple model events, selects a random model. Use default model map.
*
* @arg model_event_from_default_map
* @type text[]
* @text Model Event(s)
* @desc Enter the ID number of the model event. Or, type the Name of the event. (If a letter is present, Name will be used.)
*
* @arg model_event_from_any_map
* @type struct<modelEvent>[]
* @text Model Event(s) from Maps
* @desc Model event to use when generating an event. May be from any map. (Does not need to be from default model map.)
*
* @arg location
* @type struct<location>
* @default
* @text Loc
* @desc Location at which generated event will spawn. If Region or Area, then a random valid location will be selected.
*
* @arg quantity
* @type struct<quantity>
* @text Quantity
* @desc Number of events to generate. Uses formula, if any.
* Default: 1.
*
* @command add_slain
* @text Add Slain
* @desc Add 1 to this map's slain count. For regionally generated events, adds 1 to slain for region where event was generated.
*
* @arg mapId
* @type number
* @min 0
* @text Map ID
* @desc Map ID to which 1 slain will be added. Blank or 0 to add to current map. Default: 0.
*
* @arg eventName
* @type text
* @text Event Name
* @desc Name to which 1 slain will be added. Blank to use current event's name. Default: Current event's name.
*
* @arg genRegion
* @type number
* @min 0
* @text Generation Region
* @desc Region to which 1 slain will be added. Blank to use region in which current event was purposely generated (if any).
*/
/*~struct~modelEvent:
* @desc Model event to use when creating the generated event.
*
* @param map
* @type number
* @min 1
* @text Model Map ID
* @desc Enter the ID number of the map that contains the model event. If blank or invalid, default map will be used.
*
* @param event
* @text Model Event
* @desc Enter the ID number of the model event. Or, type the Name of the event. (If a letter is present, Name will be used.)
*/
/*~struct~location:
* @param x
* @type number
* @min -256
* @max 256
* @text X
* @desc X coordinate value. Default: 0.
* +x for east. If relative: -x for west.
*
* @param y
* @type number
* @min -256
* @max 256
* @text Y
* @desc Y coordinate value. Default: 0.
* +y for south. If relative: -y for north.
*
* @param mode
* @type select
* @option Coordinates
* @option Region
* @option Area
* @default Coordinates
* @text Location Mode
* @desc Choose how a location will be determined for the generated event. By coordinates, region(s), or area.
*
* @param region
* @parent mode
* @type number[]
* @text Region(s)
* @desc Region (or regions) at which a generated event may be placed.
*
* @param area
* @parent mode
* @type struct<area>
* @text Area
* @desc An area in which the generated event may be placed.
* Uses coordinates as the origin, and uses relativity.
*
* @param relativity
* @type struct<relativity>
* @text Relativity
* @desc Coordinates may be interpreted as absolute, or relative to an event or the player.
*
* @param gen_on_blocked_tiles
* @type boolean
* @text Gen on Blocked Tiles
* @desc True: Events can generate on impassible tiles.
* False: Events cannot generate on impassible tiles.
*
* @param gen_on_walls
* @type boolean
* @text Gen on Walls
* @desc True: Events can generate on walls (tileset's A4 tiles).
* False: Events cannot generate on walls (tileset's A4 tiles).
*
* @param gen_on_solid_events
* @type boolean
* @text Gen on Solid Events
* @desc True: Events can generate on solid/impassible events.
* False: Events cannot generate on solid/impassible events.
*
* @param gen_on_player
* @type boolean
* @text Gen on Player
* @desc True: Events can generate on party leader or followers.
* False: Events cannot generate on party leader/followers.
*
* @param gen_distance_from_player
* @type number
* @min 0
* @text Min Player Distance
* @desc Minimum distance away from player to be considered a valid spawn point for a generated event.
*/
/*~struct~area:
* @param x1
* @type number
* @default 0
* @min -256
* @max 256
* @text X1
* @desc X1 coordinate value. Default: 0.
* +x for east. If relative: -x for west.
*
* @param y1
* @type number
* @default 0
* @min -256
* @max 256
* @text Y1
* @desc Y1 coordinate value. Default: 0.
* +y for south. If relative: -y for north.
*
* @param x2
* @type number
* @default 0
* @min -256
* @max 256
* @text X2
* @desc X2 coordinate value. Default: 0.
* +x for east. If relative: -x for west.
*
* @param y2
* @type number
* @default 0
* @min -256
* @max 256
* @text Y2
* @desc Y2 coordinate value. Default: 0.
* +y for south. If relative: -y for north.
*/
/*~struct~relativity:
* @param mode
* @type select
* @option Absolute
* @option Relative to Event
* @option Relative to Player
* @default Relative to Event
* @text Relativity Mode
* @desc Select how coordinates are to be interpreted. If relative, defaults either to this event or to player.
*
* @param eventId
* @parent mode
* @type number
* @text Event ID
* @desc Event ID number of the event whose coordinates are to be used for "Relative to Event." 0 (or empty) for this event.
*
* @param party_member
* @parent mode
* @type select
* @option Player
* @option Leader
* @option Follower 1
* @option Follower 2
* @option Follower 3
* @option Follower 4
* @option Follower 5
* @option Follower 6
* @option Follower 7
* @option Follower 8
* @option Follower 9
* @text Party Member
* @desc Party member whose coordinates are used for "Relative to Player". Default: Player. Can use Follower Control plugin.
*
* @param orientational_shift
* @parent mode
* @type struct<shift>
* @text Orientational Shift
* @desc With "Relative to Event" or "Relative to Player", modify coordinates based on direction character is facing.
*/
/*~struct~shift:
* @param forward_shift
* @type number
* @default 0
* @min -256
* @max 256
* @text Forward Shift
* @desc Modify coordinates based on the direction the character is facing. Positive for forward. Negative for backward.
*
* @param rightward_shift
* @type number
* @default 0
* @min -256
* @max 256
* @text Rightward Shift
* @desc Modify coordinates based on the direction the character is facing. Positive for rightward. Negative for leftward.
*/
/*~struct~quantity:
* @param max
* @type number
* @min 1
* @text Maximum
* @desc Maximum number of events to be generated by this command.
* If not defined, then defaults to 1.
*
* @param min
* @type number
* @min 0
* @text Minimum
* @desc Minimum number of events to be generated by this command.
* If not defined, then Minimum is the same as Maximum.
*
* @param formula
* @type select
* @option Maximum
* @option Random number between Minimum and Maximum
* @option Average of 2 random numbers between Minimum and Maximum
* @option Average of 3 random numbers between Minimum and Maximum
* @option Max - Slain
* @option Max - Slain / 2
* @option Max - Slain / 3
* @option Max - Slain / 4
* @option Max - Slain / 5
* @option Max - Slain / 6
* @option Max - Slain / 7
* @option Max - Slain / 8
* @option Max - Slain / 9
* @option Max - Slain / 10
* @text Formula
* @desc Formula used to calculate number of events to generate. Slain uses map total, unless location is a single region.
*
* @param slain_name
* @parent formula
* @type text
* @text Slain Name
* @desc Name of slain events to count in formula. Specifies slain to include in calculation. Default: blank (all slain).
*/
(() => {
const pluginName = "Tyruswoo_EventGenerator";
//=============================================================================
// Parameters and globals
//=============================================================================
// Parameter declarations
Tyruswoo.EventGenerator.parameters = PluginManager.parameters(pluginName);
Tyruswoo.EventGenerator.param = Tyruswoo.EventGenerator.param || {};
// User-Defined Plugin Parameters
Tyruswoo.EventGenerator.param.defaultModelMap = Number(
Tyruswoo.EventGenerator.parameters['Default Model Map']);
Tyruswoo.EventGenerator.param.genOnBlockedTiles =
(Tyruswoo.EventGenerator.parameters['Gen on Blocked Tiles'] == "true") ? true : false;
Tyruswoo.EventGenerator.param.genOnWalls =
(Tyruswoo.EventGenerator.parameters['Gen on Walls'] == "true") ? true : false;
Tyruswoo.EventGenerator.param.genOnSolidEvents =
(Tyruswoo.EventGenerator.parameters['Gen on Solid Events'] == "true") ? true : false;
Tyruswoo.EventGenerator.param.genOnPlayer =
(Tyruswoo.EventGenerator.parameters['Gen on Player'] == "true") ? true : false;
Tyruswoo.EventGenerator.param.minPlayerDistance =
Number(Tyruswoo.EventGenerator.parameters['Min Player Distance']);
Tyruswoo.EventGenerator.param.defaultQuantityFormula =
Tyruswoo.EventGenerator.parameters['Default Quantity Formula'];
Tyruswoo.EventGenerator.param.defaultMaximum = Number(
Tyruswoo.EventGenerator.parameters['Default Maximum']);
Tyruswoo.EventGenerator.param.defaultMinimum = Number(
Tyruswoo.EventGenerator.parameters['Default Minimum']);
Tyruswoo.EventGenerator.param.slainCountGroupJson =
Tyruswoo.EventGenerator.parameters['Slain Count Sharing Map Groups'];
// Variables
Tyruswoo.EventGenerator.modelMapData = [null]; //An array, organized by mapId, to hold the corresponding data of each map.
Tyruswoo.EventGenerator._pluginCommandEventId = 0; //Keep track of the most recent event to run a plugin command.
// Default values for plugin command arguments.
const defaultGenLocation = {"x":"","y":"","mode":"Coordinates","region":"","area":"","relativity":"","gen_on_blocked_tiles":"","gen_on_solid_events":"","gen_on_player":"","gen_distance_from_player":""};
const defaultGenQuantity = {"max":"","min":"","formula":""};
const defaultGenRelativity = {"mode":"Relative to Event","eventId":"","party_member":"","orientational_shift":""};
const defaultOrientationalShift = {"forward_shift":"0","rightward_shift":"0"};
//=============================================================================
// PluginManager
//=============================================================================
// generate_event
PluginManager.registerCommand(pluginName, "generate_event", args => {
Tyruswoo.EventGenerator.generateEventBatch(args);
});
// add_slain
PluginManager.registerCommand(pluginName, "add_slain", args => {
const mapId = Number(args.mapId) ? Number(args.mapId) : $gameMap._mapId;
const eventName = args.eventName ? args.eventName : $gameMap.event(Tyruswoo.EventGenerator._pluginCommandEventId)._name;
const genRegion = Number(args.genRegion) ? Number(args.genRegion) : $gameMap.event(Tyruswoo.EventGenerator._pluginCommandEventId)._genRegion;
$gameSystem.addSlain(mapId, genRegion, eventName);
});
//=============================================================================
// Tyruswoo.EventGenerator
//=============================================================================
Tyruswoo.EventGenerator.getMapIdByString = function(mapName) {
if (/^[1-9]\d*$/.test(mapName)) {
// It's a whole number, 1 or greater.
return Number(mapName);
}
let mapInfo = $dataMapInfos.find(
element => element && element.name == mapName);
if (!mapInfo) {
return null;
}
return mapInfo.id;
};
Tyruswoo.EventGenerator.generateEventBatch = function(args) {
if (!Tyruswoo.EventGenerator.validateModelMap(Tyruswoo.EventGenerator.param.defaultModelMap)) {
console.warn("Default model map has not been set, or has been set incorrectly.\n" +
"Please open the plugin manager, open Default Model Map, and " +
"set the ID of the map your game will reference for model events.\n" +
"Until this is done, events will not generate.");
return;
}
const genGoal = Tyruswoo.EventGenerator.genGoal(args);
const models = Tyruswoo.EventGenerator.models(args);
const genLocation = Tyruswoo.EventGenerator.parseGenLocationArgs(args);
const genRegion = Tyruswoo.EventGenerator.genRegion(genLocation);
// Available tiles are found once;
// the map and the player's position on it are the same for all iterations.
const tilesInScope = Tyruswoo.EventGenerator.tilesInScope(genLocation);
for (var i = 0; i < genGoal; i++) {
// Events are added as we go, so check event clearance each iteration.
let tiles = Tyruswoo.EventGenerator.tilesClearOfEvents(tilesInScope, genLocation);
if (tiles.length) {
const r = Math.floor(Math.random() * tiles.length); // Select a random valid location.
const m = Math.floor(Math.random() * models.length); // Select a random model.
$gameMap.generateEvent(models[m].mapId, models[m].eventId, tiles[r].x, tiles[r].y, genRegion, true);
};
};
};
Tyruswoo.EventGenerator.validateModelMap = function(mapId) {
// Verify that the model map data exists.
return !!mapId && !!Tyruswoo.EventGenerator.modelMapData[mapId];
};
// New method
// Unpacks the struct at args.location and prepares it for use.
// Where anything is missing, the global default is used in its place.
Tyruswoo.EventGenerator.parseGenLocationArgs = function(args) {
const genLocation = args.location ? JSON.parse(args.location) : defaultGenLocation;
genLocation.x = Number(genLocation.x);
genLocation.y = Number(genLocation.y);
genLocation.area = genLocation.area ? JSON.parse(genLocation.area) : null;
const getBooleanOrFallback = function(str, fallback) {
str ? (str == "true") : fallback;
}
genLocation.gen_on_blocked_tiles = getBooleanOrFallback(
genLocation.gen_on_blocked_tiles,
Tyruswoo.EventGenerator.param.genOnBlockedTiles);
genLocation.gen_on_walls = getBooleanOrFallback(
genLocation.gen_on_walls,
Tyruswoo.EventGenerator.param.genOnWalls);
genLocation.gen_on_solid_events = getBooleanOrFallback(
genLocation.gen_on_solid_events,
Tyruswoo.EventGenerator.param.genOnSolidEvents);
genLocation.gen_on_player = getBooleanOrFallback(
genLocation.gen_on_player,
Tyruswoo.EventGenerator.param.genOnPlayer);
if (genLocation.gen_distance_from_player) {
genLocation.gen_distance_from_player = Number(
genLocation.gen_distance_from_player);
} else {
genLocation.gen_distance_from_player =
Tyruswoo.EventGenerator.param.genDistance;
}
genLocation.regionList = genLocation.region ? JSON.parse(genLocation.region) : [];
for (var i = 0; i < genLocation.regionList.length; i++) {
genLocation.regionList[i] = Number(genLocation.regionList[i]);
}
return genLocation;
};
// New method
// If there is only one region, then this region should be remembered by the generated events.
Tyruswoo.EventGenerator.genRegion = function(genLocation) {
var genRegion = 0;
var regions = genLocation.regionList;
if (genLocation.mode == "Region" && regions.length == 1 && Number(regions[0])) {
genRegion = Number(regions[0]);
};
return genRegion;
};
// New method.
// Modeled from the similar Tyruswoo_TileControl function, known as Tyruswoo.TileControl.extract_xyz_array().
// With input of args from the plugin command, outputs an array [x, y], with accounting for relativity options.
Tyruswoo.EventGenerator.extract_xy_array = function(genLocation) {
const relativity = (genLocation && genLocation.relativity) ? JSON.parse(genLocation.relativity) : defaultGenRelativity;
const orientational_shift = relativity.orientational_shift ? JSON.parse(relativity.orientational_shift) : defaultOrientationalShift;
var x = Number(genLocation.x);
var y = Number(genLocation.y);
if (relativity.mode == "Relative to Event") {
const eventId = Number(relativity.eventId) ? Number(relativity.eventId) : Tyruswoo.EventGenerator._pluginCommandEventId;
const e = $gameMap.event(eventId);
if (e) {
const f = Number(orientational_shift.forward_shift) ? Number(orientational_shift.forward_shift) : 0;
const r = Number(orientational_shift.rightward_shift) ? Number(orientational_shift.rightward_shift) : 0;
const xy_shift = Tyruswoo.EventGenerator.orientationalShift(e.direction(), f, r);
x = x + e.x + xy_shift[0];
y = y + e.y + xy_shift[1];
};
} else if (relativity.mode == "Relative to Player") {
var p = $gamePlayer; //By default, the party leader is selected.
if (Imported.Tyruswoo_FollowerControl) { //However, if Tyruswoo_FollowerControl is installed, then the currently selected follower is automatically selected.
p = Tyruswoo.FollowerControl.follower();
};
if (relativity.party_member == "Leader") {
p = $gamePlayer; //Regardless of whether Tyruswoo_FollowerControl is installed, the "Leader" option can be used to select the leader.
} else if (relativity.party_member.substr(0, 8) == "Follower") {
const n = Number(relativity.party_member.substr(9)); //Get the number found after this string's last space.
p = $gamePlayer.followers().follower(n - 1);
};
if (p) {
const f = Number(orientational_shift.forward_shift) ? Number(orientational_shift.forward_shift) : 0;
const r = Number(orientational_shift.rightward_shift) ? Number(orientational_shift.rightward_shift) : 0;
const xy_shift = Tyruswoo.EventGenerator.orientationalShift(p.direction(), f, r);
x = x + p.x + xy_shift[0];
y = y + p.y + xy_shift[1];
};
};
return [x, y];
};
// New method
// Modeled from the similar Tyruswoo_TileControl function, known as Tyruswoo.TileControl.orientationalShift().
Tyruswoo.EventGenerator.orientationalShift = function(direction, f = 0, r = 0) { //direction, forward shift, and rightward shift.
var xShift = 0;
var yShift = 0;
switch(direction) {
case 2:
xShift -= r;
yShift += f;
break;
case 4:
xShift -= f;
yShift -= r;
break;
case 6:
xShift += f;
yShift += r;
break;
case 8:
xShift += r;
yShift -= f;
break;
};
return [xShift, yShift];
};
// New method
// Finds all valid tiles within the area specified in genLocation.
Tyruswoo.EventGenerator.genAreaTiles = function(genLocation, origin) {
const genArea = genLocation.area;
const x1 = Number(genArea.x1) ? Number(genArea.x1) + origin.x : origin.x;
const y1 = Number(genArea.y1) ? Number(genArea.y1) + origin.y : origin.y;
const x2 = Number(genArea.x2) ? Number(genArea.x2) + origin.x : origin.x;
const y2 = Number(genArea.y2) ? Number(genArea.y2) + origin.y : origin.y;
const genAreaTiles = [];
for (var j = y1; j <= y2; j++) { // Find all tiles in this area.
for (var i = x1; i <= x2; i++) {