-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTyruswoo_MapProperties.js
624 lines (588 loc) · 27.2 KB
/
Tyruswoo_MapProperties.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
//=============================================================================
// Map Properties
// For RPG Maker MZ
// By Tyruswoo
//=============================================================================
/*
* 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_MapProperties = true;
var Tyruswoo = Tyruswoo || {};
Tyruswoo.MapProperties = Tyruswoo.MapProperties || {};
/*:
* @target MZ
* @plugindesc MZ v2.1.0 Toggle map properties with switches. Use regions to restrict/allow movement.
* @author Tyruswoo and McKathlin
* @url https://www.tyruswoo.com
*
* @help Tyruswoo Map Properties for RPG Maker MZ
*
* Change map parallaxes and BGM during play using switches.
* Use regions to restrict or allow movement of events or players.
* ============================================================================
* Plugin commands, their arguments, and short explanations:
*
* Save Parallax Position Save the current location of scrolling of
* the parallax. (Parallax background must
* exist, and map must be using the Loop
* Horizontally and/or Loop Vertically feature
* with a scroll value other than 0, in order
* for this plugin command to do anything.)
* This is not included in player save files.
*
* Load Parallax Position Load the location of scrolling of the
* parallax, from the most recently saved
* parallax location.
* ============================================================================
* Plugin parameters, their arguments, and short explanations:
*
* Parallax Switch A list of alternative parallaxes to be used
* when certain switches are on. (Later in list
* takes precedence if the same default parallax
* is used multiple times.)
* - Default Parallax The name of the parallax image, as listed in
* the map's Parallax Background image selection.
* (Do not include file extension.)
* - Switch Switch ID number for the switch that must be On
* for the alternative parallax to be used instead
* of the default parallax.
* - Alternative Parallax The name of the alternative parallax image to
* use when the switch is On. (Do not include file
* extension.)
* - Affected Maps Select which maps will be affected by this
* parallax alternative. By default, all maps are
* affected. Other options include affecting all
* maps except certain selected maps, or affecting
* only the selected maps.
* > Selected Maps Choose which maps will have special rules
* applied for this parallax alternative.
*
* Background Music Switch A list of alternative background musics to be
* used when certain switches are on. (Later in
* list takes precedence if the same default music
* is used multiple times.)
* - Default Music The name of the map's default background music
* (Autoplay BGM) as found in the map properties.
* - Switch Switch ID number for the switch that must be On
* for the alternative background music to be used
* instead of the default background music.
* - Alternative Music The name of the alternative background music to
* use when the switch is On. (Do not include file
* extension.)
* - Affected Maps Select which maps will be affected by this
* background music alternative. By default, all
* maps are affected. Other options include
* affecting all maps except certain selected
* maps, or affecting only the selected maps.
* > Selected Maps Choose which maps will have special rules
* applied for this background music alternative.
*
* Region Restrict All A list of region IDs that act as walls.
* No player or event can pass through,
* unless their "Through" property is on.
*
* Region Restrict Player A list of region IDs that players cannot
* pass through. Events may still pass through,
* if tiles permit.
*
* Region Restrict Events A list of region IDs that events cannot pass
* through. Players may pass, if tiles permit.
*
* Region Allow All A list of region IDs that players and events
* may freely pass through, even if the contained
* tiles would not normally be passable.
*
* Region Allow Player A list of region IDs that players can always
* pass through. No passability change for events.
*
* Region Allow Events A list of region IDs that events can freely
* pass through. Players are still subject to
* normal tile passability in these regions.
*
* ============================================================================
* Example features:
* - Make a different parallax appear in the same map, based on whether a
* certain switch is On. This can be done by changing the Parallax
* Alternative plugin parameter.
* - Keep the same parallax scrolling position even when transferring between
* maps! Use the Save Parallax Position plugin command just prior to player
* transfer and the Load Parallax Position plugin command immediately after
* player transfer; this allows the new map's parallax background to be at
* the same point of scrolling as the previous map's parallax background.
* (This is useful if the maps both have a parallax image and both use
* Loop Horizontally and/or Loop Vertically with a scroll value greater than
* or less than 0.)
* - Make a hidden path. Add a region number to the Region Allow Player list
* in the plugin parameters, and then paint that region anywhere that you
* want to place the hidden paths.
* - Keep NPCs out of the way in a specific area. Find the plugin parameter
* Region Restrict Events, add a region number to its list, and paint that
* region wherever you need to block NPCs from passing while allowing the
* player to pass.
* ============================================================================
* Visit Tyruswoo.com to ask for help, donate, or browse more of our plugins.
* ============================================================================
* Version History:
*
* v1.0 10/9/2020
* - Map Properties released for RPG Maker MZ!
*
* v2.0 10/22/2021
* - Introduced region-based passability restrictions and allowances.
*
* v2.0.1 8/30/2023
* - This plugin is now free and open source under the MIT license.
*
* v2.0.2 8/8/2024
* - Region list plugin parameters now only use positive integers.
* Zero, negative numbers, and other invalid values are ignored.
* This fixes the bug where someone might put a 0 in a list by mistake
* and cause undesired effects in the default empty region.
*
* v2.1.0 8/9/2024
* - Made Tyruswoo Map Properties compatible with Tyruswoo Altimit
* Movement v0.9.2 and up.
* - Game_Map's isPassable function now checks Region Restrict All and
* Region Allow All lists. This may make region-based passability
* apply more consistently in some edge cases.
* ============================================================================
* 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!
* -Tyruswoo
*
* @param Parallax Switch
* @type struct<parallaxSwitch>[]
* @desc For given parallax images, if switch is active, use alternative parallax. Later in list takes precedence.
*
* @param Background Music Switch
* @type struct<bgmSwitch>[]
* @desc For given background music, if switch is active, use alternative music. Later in list takes precedence.
*
* @command save_parallax_position
* @text Save Parallax Position
* @desc Saves the current X and Y of the parallax's scroll position.
*
* @command load_parallax_position
* @text Load Parallax Position
* @desc Loads the saved X and Y of the parallax's scroll position.
*
* @param Region Restrict All
* @type number[]
* @default []
* @desc These Region IDs don't let players or events pass; they act as walls.
*
* @param Region Restrict Player
* @parent Region Restrict All
* @type number[]
* @default []
* @desc These Region IDs don't let players pass through. No change to event movement.
*
* @param Region Restrict Events
* @parent Region Restrict All
* @type number[]
* @default []
* @desc These Region IDs don't let events in. No change in whether players pass.
*
* @param Region Allow All
* @type number[]
* @default []
* @desc These Region IDs let players and events pass through their tiles freely.
*
* @param Region Allow Player
* @parent Region Allow All
* @type number[]
* @default []
* @desc These Region IDs let players pass through. No change in whether events pass.
*
* @param Region Allow Events
* @parent Region Allow All
* @type number[]
* @default []
* @desc These Region IDs let events pass through. No change in whether players pass.
*/
/*~struct~parallaxSwitch:
* @param p
* @text Default Parallax
* @desc Name of the default parallax image. (Do not include file extension.)
*
* @param switch
* @text Switch
* @type switch
* @min 1
* @desc If this switch is On, then alternative parallax will be used.
*
* @param alt
* @text Alternative Parallax
* @desc Name of the alternative parallax. (Do not include file extension.)
*
* @param map_mode
* @text Affected Maps
* @type select
* @option All Maps
* @option All Maps Except Selected Maps
* @option Only Selected Maps
* @default All Maps
* @desc Choose how this alternative parallax will apply to maps.
*
* @param map_id
* @parent map_mode
* @text Selected Map IDs
* @type number[]
* @min 1
* @desc Selected Map ID to use in determining how to apply this alternative parallax.
*/
/*~struct~bgmSwitch:
* @param m
* @text Default Music
* @desc Name of the default background music. (Do not include file extension.)
*
* @param switch
* @text Switch
* @type switch
* @min 1
* @desc If this switch is On, then alternative background music will be used.
*
* @param alt
* @text Alternative Music
* @desc Name of the alternative background music. (Do not include file extension.)
*
* @param map_mode
* @text Affected Maps
* @type select
* @option All Maps
* @option All Maps Except Selected Maps
* @option Only Selected Maps
* @default All Maps
* @desc Choose how this alternative background music will apply to maps.
*
* @param map_id
* @parent map_mode
* @text Selected Map IDs
* @type number[]
* @min 1
* @desc Selected Map ID to use in determining how to apply this alternative background music.
*/
(() => {
const pluginName = "Tyruswoo_MapProperties";
Tyruswoo.MapProperties.parameters = PluginManager.parameters(pluginName);
Tyruswoo.MapProperties.param = Tyruswoo.MapProperties.param || {};
Tyruswoo.MapProperties.parseRegionIds = function(json) {
if (!json) {
return [];
}
let inList = JSON.parse(json);
let outList = [];
for (const item of inList) {
let num = Number.parseInt(item);
// All region numbers in lists must be positive integers.
// Region 0 is the blank region and should have no special rules.
if (num <= 0 || Number.isNaN(num)) {
console.warn("Ignoring invalid region number: " + item);
} else {
outList.push(num);
}
}
return outList;
};
// User-Defined Plugin Parameters
Tyruswoo.MapProperties.param.parallaxSwitch = Tyruswoo.MapProperties.parameters['Parallax Switch'] ? JSON.parse(Tyruswoo.MapProperties.parameters['Parallax Switch']) : null;
if(Tyruswoo.MapProperties.param.parallaxSwitch) {
for(i = 0; i < Tyruswoo.MapProperties.param.parallaxSwitch.length; i++) {
Tyruswoo.MapProperties.param.parallaxSwitch[i] = Tyruswoo.MapProperties.param.parallaxSwitch[i] ? JSON.parse(Tyruswoo.MapProperties.param.parallaxSwitch[i]) : null;
if(Tyruswoo.MapProperties.param.parallaxSwitch[i]) {
Tyruswoo.MapProperties.param.parallaxSwitch[i].switch = Tyruswoo.MapProperties.param.parallaxSwitch[i].switch ? Number(Tyruswoo.MapProperties.param.parallaxSwitch[i].switch) : 0;
Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id = Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id ? JSON.parse(Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id) : null;
if(Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id && Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id.length) {
for(j = 0; j < Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id.length; j++) {
Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id[j] = Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id[j] ? Number(Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id[j]) : 0;
};
};
};
};
};
Tyruswoo.MapProperties.param.bgmSwitch = Tyruswoo.MapProperties.parameters['Background Music Switch'] ? JSON.parse(Tyruswoo.MapProperties.parameters['Background Music Switch']) : null;
if(Tyruswoo.MapProperties.param.bgmSwitch) {
for(i = 0; i < Tyruswoo.MapProperties.param.bgmSwitch.length; i++) {
Tyruswoo.MapProperties.param.bgmSwitch[i] = Tyruswoo.MapProperties.param.bgmSwitch[i] ? JSON.parse(Tyruswoo.MapProperties.param.bgmSwitch[i]) : null;
if(Tyruswoo.MapProperties.param.bgmSwitch[i]) {
Tyruswoo.MapProperties.param.bgmSwitch[i].switch = Tyruswoo.MapProperties.param.bgmSwitch[i].switch ? Number(Tyruswoo.MapProperties.param.bgmSwitch[i].switch) : 0;
Tyruswoo.MapProperties.param.bgmSwitch[i].map_id = Tyruswoo.MapProperties.param.bgmSwitch[i].map_id ? JSON.parse(Tyruswoo.MapProperties.param.bgmSwitch[i].map_id) : null;
if(Tyruswoo.MapProperties.param.bgmSwitch[i].map_id && Tyruswoo.MapProperties.param.bgmSwitch[i].map_id.length) {
for(j = 0; j < Tyruswoo.MapProperties.param.bgmSwitch[i].map_id.length; j++) {
Tyruswoo.MapProperties.param.bgmSwitch[i].map_id[j] = Tyruswoo.MapProperties.param.bgmSwitch[i].map_id[j] ? Number(Tyruswoo.MapProperties.param.bgmSwitch[i].map_id[j]) : 0;
};
};
};
};
};
Tyruswoo.MapProperties.param.regionRestrictAll = Tyruswoo.MapProperties.parseRegionIds(
Tyruswoo.MapProperties.parameters['Region Restrict All']);
Tyruswoo.MapProperties.param.regionRestrictPlayer = Tyruswoo.MapProperties.parseRegionIds(
Tyruswoo.MapProperties.parameters['Region Restrict Player']);
Tyruswoo.MapProperties.param.regionRestrictEvents = Tyruswoo.MapProperties.parseRegionIds(
Tyruswoo.MapProperties.parameters['Region Restrict Events']);
Tyruswoo.MapProperties.param.regionAllowAll = Tyruswoo.MapProperties.parseRegionIds(
Tyruswoo.MapProperties.parameters['Region Allow All']);
Tyruswoo.MapProperties.param.regionAllowPlayer = Tyruswoo.MapProperties.parseRegionIds(
Tyruswoo.MapProperties.parameters['Region Allow Player']);
Tyruswoo.MapProperties.param.regionAllowEvents = Tyruswoo.MapProperties.parseRegionIds(
Tyruswoo.MapProperties.parameters['Region Allow Events']);
// Variables
Tyruswoo.MapProperties._parallaxX = 0;
Tyruswoo.MapProperties._parallaxY = 0;
//=============================================================================
// PluginManager
//=============================================================================
// save_parallax_position
PluginManager.registerCommand(pluginName, "save_parallax_position", args => {
Tyruswoo.MapProperties._parallaxX = $gameMap._parallaxX;
Tyruswoo.MapProperties._parallaxY = $gameMap._parallaxY;
});
// load_parallax_position
PluginManager.registerCommand(pluginName, "load_parallax_position", args => {
$gameMap._parallaxX = Tyruswoo.MapProperties._parallaxX;
$gameMap._parallaxY = Tyruswoo.MapProperties._parallaxY;
});
//=============================================================================
// Game_Map
//=============================================================================
// Parallax
//-----------------------------------------------------------------------------
//Replacement method
Game_Map.prototype.setupParallax = function() {
this._parallaxName = $dataMap.parallaxName || "";
if(this._parallaxName && Tyruswoo.MapProperties.param.parallaxSwitch) {
var altParallaxName = this._parallaxName;
for(i = 0; i < Tyruswoo.MapProperties.param.parallaxSwitch.length; i++) {
if(Tyruswoo.MapProperties.param.parallaxSwitch[i].p == this._parallaxName) {
var mapQualifies = true;
switch(Tyruswoo.MapProperties.param.parallaxSwitch[i].map_mode) {
case "Only Selected Maps":
mapQualifies = false;
for(j = 0; j < Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id.length; j++) {
if(this.mapId() == Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id[j]) {mapQualifies = true;};
};
break;
case "All Maps Except Selected Maps":
for(j = 0; j < Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id.length; j++) {
if(this.mapId() == Tyruswoo.MapProperties.param.parallaxSwitch[i].map_id[j]) {mapQualifies = false;};
};
break;
};
if(mapQualifies) {
const switchId = Tyruswoo.MapProperties.param.parallaxSwitch[i].switch ? Tyruswoo.MapProperties.param.parallaxSwitch[i].switch : 0;
if(switchId && $gameSwitches.value(switchId) == true && Tyruswoo.MapProperties.param.parallaxSwitch[i].alt) {
altParallaxName = Tyruswoo.MapProperties.param.parallaxSwitch[i].alt;
};
};
}
};
this._parallaxName = altParallaxName;
};
this._parallaxZero = ImageManager.isZeroParallax(this._parallaxName);
this._parallaxLoopX = $dataMap.parallaxLoopX;
this._parallaxLoopY = $dataMap.parallaxLoopY;
this._parallaxSx = $dataMap.parallaxSx;
this._parallaxSy = $dataMap.parallaxSy;
this._parallaxX = 0;
this._parallaxY = 0;
};
//-----------------------------------------------------------------------------
// BGM
//-----------------------------------------------------------------------------
// Replacement method
Game_Map.prototype.autoplay = function() {
if ($dataMap.autoplayBgm) {
if ($gamePlayer.isInVehicle()) {
$gameSystem.saveWalkingBgm2();
} else {
var music = $dataMap.bgm;
if(music && music.name && Tyruswoo.MapProperties.param.bgmSwitch) {
var altMusicName = music.name;
for(i = 0; i < Tyruswoo.MapProperties.param.bgmSwitch.length; i++) {
if(Tyruswoo.MapProperties.param.bgmSwitch[i].m == music.name) {
var mapQualifies = true;
switch(Tyruswoo.MapProperties.param.bgmSwitch[i].map_mode) {
case "Only Selected Maps":
mapQualifies = false;
for(j = 0; j < Tyruswoo.MapProperties.param.bgmSwitch[i].map_id.length; j++) {
if(this.mapId() == Tyruswoo.MapProperties.param.bgmSwitch[i].map_id[j]) {mapQualifies = true;};
};
break;
case "All Maps Except Selected Maps":
for(j = 0; j < Tyruswoo.MapProperties.param.bgmSwitch[i].map_id.length; j++) {
if(this.mapId() == Tyruswoo.MapProperties.param.bgmSwitch[i].map_id[j]) {mapQualifies = false;};
};
break;
};
if(mapQualifies) {
const switchId = Tyruswoo.MapProperties.param.bgmSwitch[i].switch ? Tyruswoo.MapProperties.param.bgmSwitch[i].switch : 0;
if(switchId && $gameSwitches.value(switchId) == true && Tyruswoo.MapProperties.param.bgmSwitch[i].alt) {
altMusicName = Tyruswoo.MapProperties.param.bgmSwitch[i].alt;
};
};
}
};
music.name = altMusicName;
};
AudioManager.playBgm(music);
}
}
if ($dataMap.autoplayBgs) {
AudioManager.playBgs($dataMap.bgs);
}
};
//-----------------------------------------------------------------------------
// Region Passability Checks
//-----------------------------------------------------------------------------
Game_Map.prototype.isTilePassable = Game_Map.prototype.isPassable;
// Applies RegionRestrictAll and RegionAllowAll to ALL passability checks.
Game_Map.prototype.isPassable = function(x, y, d) {
const region = this.regionId(x, y);
if (Tyruswoo.MapProperties.param.regionRestrictAll.includes(region)) {
return false;
} else if (Tyruswoo.MapProperties.param.regionAllowAll.includes(region)) {
return true;
} else {
return this.isTilePassable(x, y, d);
}
};
// Call this wherever a map-based player passability check is needed.
Game_Map.prototype.isPlayerPassable = function(x, y, d) {
const region = this.regionId(x, y);
if (Tyruswoo.MapProperties.param.regionRestrictPlayer.includes(region)) {
return false;
} else if (Tyruswoo.MapProperties.param.regionAllowPlayer.includes(region)) {
return true;
} else {
return this.isPassable(x, y, d);
}
};
// Call this wherever a map-based event passability check is needed.
Game_Map.prototype.isEventPassable = function(x, y, d) {
const region = this.regionId(x, y);
if (Tyruswoo.MapProperties.param.regionRestrictEvents.includes(region)) {
return false;
} else if (Tyruswoo.MapProperties.param.regionAllowEvents.includes(region)) {
return true;
} else {
return this.isPassable(x, y, d);
}
};
//=============================================================================
// Game_CharacterBase and subclasses
//=============================================================================
// Region restrict / allow movement
//-----------------------------------------------------------------------------
// Alias method
Tyruswoo.MapProperties.Game_Player_isMapPassable =
Game_Player.prototype.isMapPassable;
Game_Player.prototype.isMapPassable = function(x, y, d) {
if (this.vehicle()) {
// Region restrict/allow doesn't affect players in vehicles.
return Tyruswoo.MapProperties.Game_Player_isMapPassable.call(
this, x, y, d);
}
const isNormallyPassable =
Tyruswoo.MapProperties.Game_Player_isMapPassable.call(this, x, y, d);
return this.isRegionPassable(x, y, d, isNormallyPassable);
};
// Alias method
Tyruswoo.MapProperties.Game_Event_isMapPassable =
Game_Event.prototype.isMapPassable;
Game_Event.prototype.isMapPassable = function(x, y, d) {
const isNormallyPassable =
Tyruswoo.MapProperties.Game_Event_isMapPassable.call(this, x, y, d);
return this.isRegionPassable(x, y, d, isNormallyPassable);
};
// New method
Game_CharacterBase.prototype.isRegionPassable =
function(x, y, d, isNormallyPassable) {
const x2 = $gameMap.roundXWithDirection(x, d);
const y2 = $gameMap.roundYWithDirection(y, d);
const nextRegion = $gameMap.regionId(x2, y2);
if (isNormallyPassable) {
// This passes unless it's region-blocked.
return !this.isBlockedByRegion(nextRegion);
} else {
// This isn't normally passable. Check if regions allow.
const myRegion = $gameMap.regionId(x, y);
const d2 = this.reverseDir(d);
const myTilePasses = this.passesThroughRegion(myRegion) ||
$gameMap.isPassable(x, y, d);
const nextRegionPasses = this.passesThroughRegion(nextRegion) ||
$gameMap.isPassable(x2, y2, d2);
return myTilePasses && nextRegionPasses;
}
};
// New method
Game_CharacterBase.prototype.passesThroughRegion = function(regionId) {
return Tyruswoo.MapProperties.param.regionAllowAll.includes(regionId);
};
// New method
Game_CharacterBase.prototype.isBlockedByRegion = function(regionId) {
return Tyruswoo.MapProperties.param.regionRestrictAll.includes(regionId);
};
// Override to new method
Game_Event.prototype.passesThroughRegion = function(regionId) {
return Game_Character.prototype.passesThroughRegion.call(this, regionId) ||
Tyruswoo.MapProperties.param.regionAllowEvents.includes(regionId);
};
// Override to new method
Game_Event.prototype.isBlockedByRegion = function(regionId) {
return Game_Character.prototype.isBlockedByRegion.call(this, regionId) ||
Tyruswoo.MapProperties.param.regionRestrictEvents.includes(regionId);
};
// Override to new method
Game_Player.prototype.passesThroughRegion = function(regionId) {
return Game_Character.prototype.passesThroughRegion.call(this, regionId) ||
Tyruswoo.MapProperties.param.regionAllowPlayer.includes(regionId);
};
// Override to new method
Game_Player.prototype.isBlockedByRegion = function(regionId) {
return Game_Character.prototype.isBlockedByRegion.call(this, regionId) ||
Tyruswoo.MapProperties.param.regionRestrictPlayer.includes(regionId);
};
})();