-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMano_PartyCommandEvent.js
More file actions
310 lines (286 loc) · 9.39 KB
/
Mano_PartyCommandEvent.js
File metadata and controls
310 lines (286 loc) · 9.39 KB
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
//@ts-check
//=============================================================================
// Mano_InputConfig.js
// ----------------------------------------------------------------------------
// Copyright (c) 2017-2021 Sigureya
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
// ----------------------------------------------------------------------------
// Version
// ver 1.1.0 2022/04/11
// ----------------------------------------------------------------------------
// [Twitter]: https://twitter.com/Sigureya/
//=============================================================================
/*:
* @plugindesc バトル中のパーティコマンドに任意の要素を追加します。
* @author しぐれん
* @url https://raw.githubusercontent.com/Sigureya/RPGmakerMZ/master/Mano_PartyCommandEvent.js
*
* @target MZ
*
* @param commandList
* @type struct<PartyCommand>[]
* @default []
*
* @help
* 戦闘中のパーティコマンドからコモンイベントを呼び出します。
* シーン遷移系のコマンドを呼び出すと不具合が発生する可能性があります。
*
* Call a common event from a party command in battle.
* If you call a scene transition command, a problem may occur.
*
* ■更新履歴/UpdateLogs
* 2022/04/11 ver1.1.0 Added English commentary
* 2022/03/02 ver1.0 公開
*
*/
/*~struct~PartyCommand:
* @param name
* @text コマンド名/CommandName
* @type string
* @default コマンド
*
* @param eventId
* @text 呼び出すイベント/event
* @type common_event
* @default 0
*
* @param enableSwtich
* @text 有効化スイッチ/EnableSwitch
* @desc 指定されたスイッチがONの場合のみ選択可能。
* Selectable only when the specified switch is ON.
* @type switch
* @default 0
*
* @param addSwtich
* @text 表示スイッチ/ShowSwitch
* @desc 指定されたスイッチがONの場合のみ表示。
* Displayed only when the specified switch is ON.
* @type switch
* @default 0
*
* @param helpText
* @text ヘルプ文章/helpText
* @desc 画面上部に文章を表示します。
* The text is displayed at the top of the screen.
* @type string
* @default
*
* @param partyCommandVisible
* @desc イベント実行中のコマンドウィンドウ表示。
* Command window display during event execution.
* @type boolean
* @default true
*
* @param actorStatusVisible
* @desc イベント実行中のステータスウィンドウ表示。
* Status window display during event execution.
* @type boolean
* @default true
*
*/
(function(){
`use strict`;
/**
* @type {String}
*/
const PLUGIN_NAME= ('Mano_PartyCommandEvent');
function getParam(){ return PluginManager.parameters(PLUGIN_NAME); }
const SYMBOL_STRING="PTCMD";
class SwitchCasset{
/**
* @param {Number} switchId
*/
constructor(switchId){
this._switchId=switchId;
}
isEnabled(){
if(this._switchId >0){
return $gameSwitches.value(this._switchId);
}
return true;
}
}
class PartyCommand{
/**
* @param {String} name
* @param {Number} eventId
* @param {Number} addSwitch
* @param {Number} enableSwitch
* @param {Boolean} partyCommandWidnow
* @param {Boolean} actorStatusWinodw
* @param {String} helpText
*/
constructor(name,eventId,addSwitch,enableSwitch,partyCommandWidnow,actorStatusWinodw,helpText){
this._name =name;
this._eventId=eventId;
this._addSwtich= new SwitchCasset(addSwitch);
this._enableSwitch=new SwitchCasset(enableSwitch);
this._partyComamandVisible=partyCommandWidnow;
this._actorStatusWindow=actorStatusWinodw;
this._helpText=helpText;
}
/**
* @param {String} objText
* @returns
*/
static create(objText){
const obj=JSON.parse(objText);
const name =obj.name;
const eventId =Number(obj.eventId);
const addSwitch =Number(obj.addSwitch);
const enableSwitch=Number(obj.enableSwitch);
const partyCommandWidnow =(obj.partyCommandVisible==="true");
const actorStatusWinodw =(obj.actorStatusVisible==="true");
const helpText = String(obj.helpText||"");
return new PartyCommand(name,eventId,addSwitch,enableSwitch,partyCommandWidnow,actorStatusWinodw,helpText);
}
partyCommandVisible(){
return this._partyComamandVisible;
}
actorStatusVisible(){
return this._actorStatusWindow;
}
eventId(){
return this._eventId;
}
name(){
return this._name;
}
//TODO:コマンド用画像設定を作った時に何かする
symbol(){
return `${this._eventId}:${SYMBOL_STRING}`;
}
helpText(){
return this._helpText;
}
isEnabled(){
if(this._enableSwitch){
return this._enableSwitch.isEnabled();
}
return true;
}
canAdd(){
if(this._addSwtich){
return this._addSwtich.isEnabled();
}
return true;
}
}
class PartyCommandManager_T{
/**
*
* @param {Number} eventId
*/
find(eventId) {
return this._list.get(eventId);
}
/**
* @param {Map<Number,PartyCommand>} partyCommandList
*/
constructor(partyCommandList){
this._list=partyCommandList;
this._inter=null;
}
commandList(){
return this._list.values();
}
/**
* @param {Number} eventId
* @param {()=>void} onEndEvent
*/
startEvent(eventId,onEndEvent){
const eventCode =$dataCommonEvents[eventId];
if(eventCode){
//実行用のインタプリタを作成
this._inter = new Game_Interpreter(0);
this._inter.setup(eventCode.list,0);
//デストラクタ用の処理を設定
this._endEventFunction=onEndEvent;
}
}
update(){
if(this._inter){
this._inter.update();
if(!this._inter.isRunning()){
this.onEndEvent();
this._inter=null;
}
}
}
onEndEvent(){
if(this._endEventFunction){
this._endEventFunction();
}
this._endEventFunction=null;
}
}
const PartyCommandManager = (()=>{
const param =getParam();
/**
* @type {String[]}
*/
const commandListText =JSON.parse(param.commandList);
/**
* @type {Map<Number,PartyCommand>}
*/
const table =new Map();
for (const iterator of commandListText) {
const cmd = PartyCommand.create(iterator);
table.set(cmd.eventId(),cmd);
}
const manager= new PartyCommandManager_T(
table
);
return manager;
})();
const Window_PartyCommand_addCommand=Window_PartyCommand.prototype.addCommand;
Window_PartyCommand.prototype.addCommand =function(name,symbol,enabled,ext){
if(symbol==="escape"){
for (const iterator of PartyCommandManager.commandList()) {
if(iterator.canAdd()){
this.addCommand(iterator.name(),SYMBOL_STRING,iterator.isEnabled(),iterator.eventId());
}
}
}
Window_PartyCommand_addCommand.apply(this,arguments);
}
const Scene_Battle_createPartyCommandWindow=Scene_Battle.prototype.createPartyCommandWindow;
Scene_Battle.prototype.createPartyCommandWindow =function(){
Scene_Battle_createPartyCommandWindow.call(this);
//@ts-ignore
this._partyCommandWindow.setHandler(SYMBOL_STRING,this.onExtraPartyCommandOk.bind(this));
};
const Scene_Battle_update=Scene_Battle.prototype.update;
Scene_Battle.prototype.update =function(){
PartyCommandManager.update();
Scene_Battle_update.call(this);
};
//@ts-ignore
Scene_Battle.prototype.onExtraPartyCommandOk =function(){
/**
* @type {Number}
*/
const eventId = this._partyCommandWindow.currentExt();
const cmd = PartyCommandManager.find(eventId);
if(!cmd){
this._partyCommandWindow.activate();
return;
}
const help=cmd.helpText();
if(help){
this._helpWindow.setText(help);
this._helpWindow.visible = true;
}
this._partyCommandWindow.visible = cmd.partyCommandVisible();
this._statusWindow.visible = cmd.actorStatusVisible();
PartyCommandManager.startEvent(eventId,()=>{
this._helpWindow.clear();
this._helpWindow.visible = false;
this._statusWindow.visible = true;
this._partyCommandWindow.visible = true;
this._partyCommandWindow.activate();
this._partyCommandWindow.open();
});
};
}())