-
Notifications
You must be signed in to change notification settings - Fork 41
/
OrangeRegionCollisions.js
177 lines (148 loc) · 6.18 KB
/
OrangeRegionCollisions.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
/*=============================================================================
* Orange - Region Collisions
* By Hudell - www.hudell.com
* OrangeRegionCollisions.js
* Version: 1.2
* Free for commercial and non commercial use.
*=============================================================================*/
/*:
* @plugindesc Allows the usage of regions to overwrite the passability configuration of tiles
* @author Hudell
*
* @param BlockRegionId
* @desc The ID of the region that should be used to block passage on a tile
* @default 0
*
* @param UnblockRegionId
* @desc The ID of the region that should be used to unblock passage on a tile
* @default 0
*
* @param BlockPlayerRegionId
* @desc The ID of the region that should be used to block passage of the player on a tile
* @default 0
*
* @param UnblockPlayerRegionId
* @desc The ID of the region that should be used to unblock passage of the player on a tile
* @default 0
*
* @param BlockEventRegionId
* @desc The ID of the region that should be used to block passage of events on a tile
* @default 0
*
* @param UnblockEventRegionId
* @desc The ID of the region that should be used to unblock passage of events on a tile
* @default 0
*
* @help
* ============================================================================
* Latest Version
* ============================================================================
*
* Get the latest version of this script on
* http://download.hudell.com/OrangeRegionCollisions.js
*
*=============================================================================*/
var Imported = Imported || {};
var OrangeRegionCollisions = OrangeRegionCollisions || {};
(function($) {
"use strict";
$.Parameters = PluginManager.parameters('OrangeRegionCollisions');
$.Param = $.Param || {};
$.Param.BlockRegionId = Number($.Parameters.BlockRegionId || 0);
$.Param.UnblockRegionId = Number($.Parameters.UnblockRegionId || 0);
$.Param.BlockPlayerRegionId = Number($.Parameters.BlockPlayerRegionId || 0);
$.Param.UnblockPlayerRegionId = Number($.Parameters.UnblockPlayerRegionId || 0);
$.Param.BlockEventRegionId = Number($.Parameters.BlockEventRegionId || 0);
$.Param.UnblockEventRegionId = Number($.Parameters.UnblockEventRegionId || 0);
var oldGame_Map_checkPassage = Game_Map.prototype.checkPassage;
Game_Map.prototype.checkPassage = function(x, y, bit) {
if ($.Param.BlockRegionId > 0 || $.Param.UnblockRegionId > 0) {
var regionId = this.regionId(x, y);
if (regionId > 0) {
if ($.Param.BlockRegionId > 0 && regionId == $.Param.BlockRegionId) {
return false;
}
if ($.Param.UnblockRegionId > 0 && regionId == $.Param.UnblockRegionId) {
return true;
}
}
}
return oldGame_Map_checkPassage.call(this, x, y, bit);
};
var oldGameEvent_isMapPassable = Game_Event.prototype.isMapPassable;
Game_Event.prototype.isMapPassable = function(x, y, d) {
if ($.Param.BlockEventRegionId > 0 || $.Param.UnblockRegionId > 0) {
var new_x = $gameMap.roundXWithDirection(x, d);
var new_y = $gameMap.roundYWithDirection(y, d);
var regionId = $gameMap.regionId(new_x, new_y);
if (regionId > 0) {
if ($.Param.BlockEventRegionId > 0 && regionId == $.Param.BlockEventRegionId) {
return false;
}
if ($.Param.UnblockRegionId > 0 && regionId == $.Param.UnblockRegionId) {
return true;
}
}
}
return oldGameEvent_isMapPassable.call(this, x, y, d);
};
var oldGamePlayer_isMapPassable = Game_Player.prototype.isMapPassable;
if (Imported.SuperOrangeMovement !== undefined || Imported.SuperOrangeMovementEx !== undefined) {
var insignificantValue = 0.000001;
$.runForAllPositions = function(x, y, callback) {
var first_x = (x + this.hitboxXSize).floor();
var last_x = (x + this.hitboxXSize + this.hitboxWidthSize - insignificantValue).floor();
var first_y = (y + this.hitboxYSize).floor();
var last_y = (y + this.hitboxYSize + this.hitboxHeightSize - insignificantValue).floor();
for (var new_x = first_x; new_x <= last_x; new_x++) {
for (var new_y = first_y; new_y <= last_y; new_y++) {
var result = callback.call(this, new_x, new_y);
if (result === true) return true;
if (result === false) return false;
}
}
return null;
};
$.checkPlayerRegionCollision = function(x, y) {
var regionId = $gameMap.regionId(x, y);
if (regionId > 0) {
if ($.Param.BlockPlayerRegionId > 0 && regionId == $.Param.BlockPlayerRegionId) {
return false;
}
if ($.Param.UnblockRegionId > 0 && regionId == $.Param.UnblockRegionId) {
return true;
}
}
return null;
};
Game_Player.prototype.isMapPassable = function(x, y, d) {
if ($.Param.BlockPlayerRegionId > 0 || $.Param.UnblockRegionId > 0) {
var new_x = $gameMap.roundFractionXWithDirection(x, d);
var new_y = $gameMap.roundFractionYWithDirection(y, d);
var result = $.runForAllPositions.call(this, new_x, new_y, $.checkPlayerRegionCollision);
if (result === true) return true;
if (result === false) return false;
}
return oldGamePlayer_isMapPassable.call(this, x, y, d);
};
}
else {
Game_Player.prototype.isMapPassable = function(x, y, d) {
if ($.Param.BlockPlayerRegionId > 0 || $.Param.UnblockRegionId > 0) {
var new_x = $gameMap.roundXWithDirection(x, d);
var new_y = $gameMap.roundYWithDirection(y, d);
var regionId = $gameMap.regionId(new_x, new_y);
if (regionId > 0) {
if ($.Param.BlockPlayerRegionId > 0 && regionId == $.Param.BlockPlayerRegionId) {
return false;
}
if ($.Param.UnblockRegionId > 0 && regionId == $.Param.UnblockRegionId) {
return true;
}
}
}
return oldGamePlayer_isMapPassable.call(this, x, y, d);
};
}
})(OrangeRegionCollisions);
Imported.OrangeRegionCollisions = 1.2;