-
Notifications
You must be signed in to change notification settings - Fork 25
/
GabeMZ_FollowersInteraction.js
160 lines (139 loc) · 5.95 KB
/
GabeMZ_FollowersInteraction.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
//============================================================================
// Gabe MZ - Followers Interaction
//----------------------------------------------------------------------------
// 08/09/20 | Version: 1.0.0 | Released
//----------------------------------------------------------------------------
// This plugin is released under the zlib License.
//============================================================================
/*:
* @target MZ
* @plugindesc [v1.0.0] Allows to interact with followers, calling Common Events that can be freely configured.
* @author Gabe (Gabriel Nascimento)
* @url http://patreon.com/gabriel_nfd
* @base GabeMZ_SmartFollowers
* @orderAfter GabeMZ_SmartFollowers
*
* @help Gabe MZ - Followers Interaction
* - This plugin is released under the zlib License.
*
* To setup interactions with followers, just set in the plugin parameters the
* Common Event ID that each actor will call. After that edit the Common Events
* with your like. The Common Events that each actor calls can be changed
* throughout the game via Plugin Commands.
*
* Plugin Commands:
* Change Common Event
* | This command allows to change the ID of the Common Event called when
* | player interact with the defined actor.
*
* For support and new plugins join our Discord server:
* https://discord.gg/GG85QRz
*
* @param keyCode
* @text Key Code
* @desc Set the Key Code used to player turn to the direction when pressed.
* @type number
* @default 17
*
* @param commonEventList
* @text Common Event List
* @desc Set the default Common Event called when player interact with the followers.
* @type struct<commonEventStruct>[]
*
* @command changeCommonEvent
* @text Change Common Event
* @desc Change the Common Event called when player interact with the followers.
*
* @arg commonEventList
* @text Common Event List
* @desc Change the Common Event called when player interact with the followers.
* @type struct<commonEventStruct>[]
*/
/*~struct~commonEventStruct:
* @param actorId
* @text Actor ID
* @desc Set the Actor ID.
* @type actor
*
* @param commonEventId
* @text Common Event ID
* @desc Set the Common Event ID that will be called when the player interacts with the defined actor.
* @type common_event
*/
var Imported = Imported || {};
Imported.GMZ_FollowersInteraction = true;
var GabeMZ = GabeMZ || {};
GabeMZ.FollowersInteraction = GabeMZ.FollowersInteraction || {};
GabeMZ.FollowersInteraction.VERSION = [1, 0, 0];
if (!GabeMZ.SmartFollowers) throw new Error("Gabe MZ - Followers Interaction plugin needs the Gabe MZ - Smart Followers base.");
(() => {
const pluginName = "GabeMZ_FollowersInteraction";
const params = PluginManager.parameters(pluginName);
GabeMZ.FollowersInteraction.keyCode = parseInt(params.keyCode);
GabeMZ.FollowersInteraction.defaultCommonEvents = JSON.parse(params.commonEventList);
GabeMZ.FollowersInteraction.commnEvents = {}
GabeMZ.FollowersInteraction.defaultCommonEvents.forEach(arg => {
arg = JSON.parse(arg);
GabeMZ.FollowersInteraction.commnEvents[arg.actorId] = parseInt(arg.commonEventId);
});
Input.keyMapper[GabeMZ.FollowersInteraction.keyCode] = 'playerTurnDirection';
//-----------------------------------------------------------------------------
// PluginManager
//
// The static class that manages the plugins.
PluginManager.registerCommand(pluginName, "changeCommonEvent", args => {
const commonEventList = JSON.parse(args.commonEventList);
commonEventList.forEach(arg => {
arg = JSON.parse(arg);
GabeMZ.FollowersInteraction.commnEvents[arg.actorId] = parseInt(arg.commonEventId);
$gameActors.actor(arg.actorId).changeCommonEventId(arg.commonEventId);
})
});
//-----------------------------------------------------------------------------
// Game_Actor
//
// The game object class for an actor.
const _Game_Actor_setup = Game_Actor.prototype.setup;
Game_Actor.prototype.setup = function(actorId) {
_Game_Actor_setup.call(this, actorId);
this._commonEventId = GabeMZ.FollowersInteraction.commnEvents[actorId] ?
GabeMZ.FollowersInteraction.commnEvents[actorId] : 0;
};
Game_Actor.prototype.commonEventId = function() {
return this._commonEventId;
};
Game_Actor.prototype.changeCommonEventId = function(id) {
this._commonEventId = id;
};
//-----------------------------------------------------------------------------
// Game_Player
//
// The game object class for the player. It contains event starting
// determinants and map scrolling functions.
const _Game_Player_getInputDirection = Game_Player.prototype.getInputDirection;
Game_Player.prototype.getInputDirection = function() {
if (Input.isPressed("playerTurnDirection")) {
this.setDirection(Input.dir4);
return 0;
} else {
return _Game_Player_getInputDirection.call(this);
}
};
const _Game_Player_update = Game_Player.prototype.update;
Game_Player.prototype.update = function(sceneActive) {
_Game_Player_update.call(this, sceneActive);
if (Input.isTriggered("ok")) this.updateFollowersInteraction();
};
Game_Player.prototype.updateFollowersInteraction = function() {
const follower = this.checkFollowerTriggerFront(this.direction());
if (!follower[0]) return;
if (!follower[0].actor() || $gameMap.isEventRunning() || this.isMoving()) return;
follower[0].turnTowardPlayer();
$gameMap._interpreter.setup($dataCommonEvents[follower[0].actor().commonEventId()].list);
};
Game_Player.prototype.checkFollowerTriggerFront = function(d) {
const x2 = $gameMap.roundXWithDirection(this._x, d);
const y2 = $gameMap.roundYWithDirection(this._y, d);
return this._followers.data().filter(follower => follower.pos(x2, y2));
};
})();