forked from comuns-rpgmaker/GabeMZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGabeMZ_RegionPlus.js
253 lines (226 loc) · 8.37 KB
/
GabeMZ_RegionPlus.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
//============================================================================
// Gabe MZ - Region Plus
//----------------------------------------------------------------------------
// 27/02/21 | Version: 1.0,1 | Multiple effects bug fix
// 18/09/20 | Version: 1.0.0 | Released
//----------------------------------------------------------------------------
// This software is released under the zlib License.
//============================================================================
/*:
* @target MZ
* @plugindesc [v1.0.1] Adds improvements and new functions to the game regions.
* @author Gabe (Gabriel Nascimento)
* @url http://patreon.com/gabriel_nfd
*
* @help Gabe MZ - Region Plus
* - This plugin is released under the zlib License.
*
* This plugin adds improvements and new functions to the game regions.
*
* Plugin Parameters:
* Only Player Region
* | Set a region that will be passable only for the player.
*
* Only Event Region
* | Set a region that will be passable only for the events.
*
* Passable Region
* | Set a region that will always be passable.
*
* Impassable Region
* | Set a region that will always be impassable.
*
* Map Note Tag:
* <commonRegion regionId: commonEventId>
* | The defined region will trigger the common event of the defined
* | id when the note is inserted in the notes field of the map.
* Usage Example:
* <commonRegion 255: 1>
* | When stepping on a tile whose region id is 255 this'll trigger the
* | common event of id 1.
*
* Plugin Commands:
* Set Region Passability
* | This command allows to manually set the passability of
* | a specific region by id.
*
* @param passageSettings
* @text Passage Settings
* @desc Set the passability regions settings
*
* @param onlyPlayerRegion
* @text Only Player Region
* @type number
* @default 40
* @parent passageSettings
*
* @param onlyEventRegion
* @text Only Event Region
* @type number
* @default 41
* @parent passageSettings
*
* @param passableRegion
* @text Passable Region
* @type number
* @default 42
* @parent passageSettings
*
* @param impassableRegion
* @text Impassable Region
* @type number
* @default 43
* @parent passageSettings
*
* @command setRegionPassability
* @text Set Region Passability
* @desc Set the passability of the specified region.
*
* @arg regionId
* @text Region ID
* @desc The region id.
* @type number
* @default 0
*
* @arg passable
* @text Passable
* @desc ON: The region is passable.
* OFF: The region is impassable
* @type boolean
* @default true
*/
var Imported = Imported || {};
Imported.GMZ_RegionPlus = true;
var GabeMZ = GabeMZ || {};
GabeMZ.RegionPlus = GabeMZ.RegionPlus || {};
GabeMZ.RegionPlus.VERSION = [1, 0, 1];
(() => {
const pluginName = "GabeMZ_RegionPlus";
const params = PluginManager.parameters(pluginName);
GabeMZ.RegionPlus.onlyPlayerRegion = parseInt(params.onlyPlayerRegion);
GabeMZ.RegionPlus.onlyEventRegion = parseInt(params.onlyEventRegion);
GabeMZ.RegionPlus.impassableRegion = parseInt(params.impassableRegion);
GabeMZ.RegionPlus.passableRegion = parseInt(params.passableRegion);
//-----------------------------------------------------------------------------
// PluginManager
//
// The static class that manages the plugins.
PluginManager.registerCommand(pluginName, "setRegionPassability", args => {
const passable = JSON.parse(args.passable)
const regionId = parseInt(args.regionId);
if (passable) {
$gameSystem.setPassableRegion(regionId);
} else {
$gameSystem.setImpassableRegion(regionId);
}
});
//-----------------------------------------------------------------------------
// Game_Actor
//
// The game object class for an actor.
const _Game_Actor_checkFloorEffect = Game_Actor.prototype.checkFloorEffect;
Game_Actor.prototype.checkFloorEffect = function() {
_Game_Actor_checkFloorEffect.call(this);
if (this.actorId() != $gameParty.leader().actorId()) return;
const commonEventId = $gameMap.commonRegion($gamePlayer.regionId());
if (commonEventId) {
$gameTemp.reserveCommonEvent(commonEventId);
}
};
//-----------------------------------------------------------------------------
// Game_CharacterBase
//
// The superclass of Game_Character. It handles basic information, such as
// coordinates and images, shared by all characters.
const _Game_CharacterBase_canPass = Game_CharacterBase.prototype.canPass;
Game_CharacterBase.prototype.canPass = function(x, y, d) {
const x2 = $gameMap.roundXWithDirection(x, d);
const y2 = $gameMap.roundYWithDirection(y, d);
const regionId = $gameMap.regionId(x2,y2);
if ($gameSystem.isImpassableRegion(regionId)) return false;
switch (regionId) {
case GabeMZ.RegionPlus.impassableRegion:
return false;
case GabeMZ.RegionPlus.passableRegion:
return true;
default:
return _Game_CharacterBase_canPass.call(this, x, y, d);
}
}
//-----------------------------------------------------------------------------
// Game_Event
//
// The game object class for an event. It contains functionality for event page
// switching and running parallel process events.
const _Game_Event_canPass = Game_Event.prototype.canPass;
Game_Event.prototype.canPass = function(x, y, d) {
const x2 = $gameMap.roundXWithDirection(x, d);
const y2 = $gameMap.roundYWithDirection(y, d);
if (!$gameMap.isValid(x2, y2)) return false;
if (this.isThrough()) return true;
switch ($gameMap.regionId(x2,y2)) {
case GabeMZ.RegionPlus.onlyPlayerRegion:
return false;
case GabeMZ.RegionPlus.onlyEventRegion:
return true;
default:
return _Game_Event_canPass.call(this, x, y, d);
}
}
//-----------------------------------------------------------------------------
// Game_Player
//
// The game object class for the player. It contains event starting
// determinants and map scrolling functions.
const _Game_Player_canPass = Game_Player.prototype.canPass;
Game_Player.prototype.canPass = function(x, y, d) {
const x2 = $gameMap.roundXWithDirection(x, d);
const y2 = $gameMap.roundYWithDirection(y, d);
if (!$gameMap.isValid(x2, y2)) return false;
if (this.isThrough() || this.isDebugThrough()) return true;
switch ($gameMap.regionId(x2,y2)) {
case GabeMZ.RegionPlus.onlyEventRegion:
return false;
case GabeMZ.RegionPlus.onlyPlayerRegion:
return true;
default:
return _Game_Player_canPass.call(this, x, y, d);
}
}
//-----------------------------------------------------------------------------
// Game_Map
//
// The game object class for a map. It contains scrolling and passage
// determination functions.
const _Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
_Game_Map_setup.call(this, mapId);
this._commonRegions = [];
let reg = /<commonRegion\s*(\d+):\s*(\d+)>/g;
let match;
while (match = reg.exec($dataMap.note)) {
this._commonRegions[parseInt(match[1])] = parseInt(match[2]);
}
};
Game_Map.prototype.commonRegion = function(regionId) {
return this._commonRegions[regionId];
}
//-----------------------------------------------------------------------------
// Game_System
//
// The game object class for the system data.
const _Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_Game_System_initialize.call(this);
this._impassableRegions = [];
}
Game_System.prototype.setImpassableRegion = function(regionId) {
this._impassableRegions[regionId] = true;
}
Game_System.prototype.setPassableRegion = function(regionId) {
this._impassableRegions[regionId] = false;
}
Game_System.prototype.isImpassableRegion = function(regionId) {
return this._impassableRegions[regionId]
}
})();