-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_TurnActorEnemy.js
321 lines (293 loc) · 10.8 KB
/
RS_TurnActorEnemy.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
//================================================================
// RS_TurnActorEnemy.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2019 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @plugindesc <RS_TurnActorEnemy>
* @author biud436
* @help
* In the battle event condition,
* This plugin allows you to set the enemy's turn and the actor's turn count values.
*
* In the condition window of the troop tab,
* You must set the following note tags to the switch's name.
*
* <TURN_ACTOR : actor_id turn_a turn_b>
* <TURN_ENEMY : enemy_index turn_a turn_b>
*
* Suppose you set the switch name as follows:
*
* <TURN_ACTOR : 2 0 1>
*
* The turn calculates using formulas such as 'turn_a + (turn_b * X)',
* So the battle event is executed whenever actor2's turn is returned.
*
* ==================================================
* Version Log
* ==================================================
* 2019.06.29 (v1.0.0) - First Release.
* 2019.06.30 (v1.0.1) :
* - Added the new feature that checks whether the actor's id or enemy's index is correct.
* - Now it starts the battle event together when enemy or actor gets a turn.
* - It is now compatible with YEP_BattleEngineCore.
*/
/*:ko
* @plugindesc RM2K3의 전투 이벤트 시작 조건처럼 몬스터의 턴, 액터의 턴을 설정합니다. <RS_TurnActorEnemy>
* @author biud436
* @help
*
* 사용법은 다음과 같습니다.
*
* 적 그룹의 전투 이벤트 설정으로 가면 조건 창이 있습니다.
* 조건 창에 노트 태그 란이 없기 때문에 스위치 체크 박스를 활성화하고,
* 한 스위치를 선택하여 이름 부분에 다음과 같은 노트 태그를 설정하세요.
*
* <TURN_ACTOR : actor_id turn_a turn_b>
* <TURN_ENEMY : enemy_index turn_a turn_b>
*
* 조건 -스위치 이름을 다음과 같이 설정했다고 가정해봅시다.
*
* <TURN_ACTOR : 2 0 1>
*
* 턴은 turn_a + (turn_b * X)로 계산되며 1X로 환산됩니다.
* 따라서 전투 이벤트는 2번 액터의 턴이 돌아올 때마다 실행됩니다.
*
* ==================================================
* Version Log
* ==================================================
* 2019.06.29 (v1.0.0) - First Release.
* 2019.06.30 (v1.0.2) :
* - actorId 및 enemyIndex를 체크하는 기능 추가
* - 배틀러의 턴이 시작될 때, 전투 이벤트도 같이 시작됩니다.
* - YEP_BattleEngineCore 관련 기능 추가
*/
var Imported = Imported || {};
Imported.RS_TurnActorEnemy = true;
var RS = RS || {};
RS.TurnActorEnemy = RS.TurnActorEnemy || {};
(function($) {
var parameters = $plugins.filter(function (i) {
return i.description.contains('<RS_TurnActorEnemy>');
});
parameters = (parameters.length > 0) && parameters[0].parameters;
$.Params = {};
$.Params.isDatabaseLoaded = false;
//====================
// DataManager
//====================
var alias_DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function() {
if(!alias_DataManager_isDatabaseLoaded.call(this)) return false;
if($.Params.isDatabaseLoaded) return true;
for(var i = 1; i < $dataTroops.length; i++) {
var pages = $dataTroops[i].pages;
for(var j = 0; j < pages.length; j++) {
var page = pages[j];
var c = page.conditions;
var switchId = c.switchId;
if(c.switchValid) {
var note = $dataSystem.switches[switchId];
if(/\<(?:TURN_ENEMY)[ ]:[ ](\d+)[ ](\d+)[ ](\d+)\>/.exec(note)) {
var enemyIndex = parseInt(RegExp.$1);
var turnA = parseInt(RegExp.$2);
var turnB = parseInt(RegExp.$3);
c.turnEnemyValid = true;
c.turnEnemyIndex = enemyIndex;
c.turnEnemyA = turnA;
c.turnEnemyB = turnB;
} else if(/\<(?:TURN_ACTOR)[ ]:[ ](\d+)[ ](\d+)[ ](\d+)\>/.exec(note)) {
var actorId = parseInt(RegExp.$1);
var turnA = parseInt(RegExp.$2);
var turnB = parseInt(RegExp.$3);
c.turnActorValid = true;
c.turnActorId = actorId;
c.turnActorA = turnA;
c.turnActorB = turnB;
}
}
}
}
$.Params.isDatabaseLoaded = true;
return true;
};
//====================
// Game_Troop
//====================
var alias_Game_Troop_clear = Game_Troop.prototype.clear;
Game_Troop.prototype.clear = function() {
alias_Game_Troop_clear.call(this);
this._turnFlags = {};
};
Game_Troop.prototype.setup2K3BattleEvent = function(index) {
if (!this._interpreter.isRunning()) {
if (this._interpreter.setupReservedCommonEvent()) {
return;
}
var pages = this.troop().pages;
for (var i = 0; i < pages.length; i++) {
var page = pages[i];
if (this.meetsConditions2(page, index) && !this._turnFlags[i]) {
this._interpreter.setup(page.list);
if (page.span <= 1) {
this._turnFlags[index] = true;
}
break;
}
}
}
};
Game_Troop.prototype.onTurnFlags = function(index) {
var pages = this.troop().pages;
for (var i = 0; i < pages.length; i++) {
var page = pages[i];
if (page.span === 1) {
this._turnFlags[index] = false;
}
}
};
Game_Troop.prototype.meetsConditions2 = function(page, index) {
var c = page.conditions;
if (!c.turnEnding && !c.turnValid && !c.enemyValid &&
!c.actorValid && !c.turnActorValid && !c.turnEnemyValid && !c.switchValid) {
return false; // Conditions not set
}
if (c.turnEnding) {
if (!BattleManager.isTurnEnd()) {
return false;
}
}
if (c.turnValid) {
var n = this._turnCount;
var a = c.turnA;
var b = c.turnB;
if ((b === 0 && n !== a)) {
return false;
}
if ((b > 0 && (n < 1 || n < a || n % b !== a % b))) {
return false;
}
}
if (c.enemyValid) {
var enemy = $gameTroop.members()[c.enemyIndex];
if (!enemy || enemy.hpRate() * 100 > c.enemyHp) {
return false;
}
}
if (c.actorValid) {
var actor = $gameActors.actor(c.actorId);
if (!actor || actor.hpRate() * 100 > c.actorHp) {
return false;
}
}
if (c.turnActorValid) {
var actor = $gameActors.actor(c.turnActorId);
if(!actor) {
return false;
}
var n = actor.turnCount();
var a = c.turnActorA;
var b = c.turnActorB;
var id = index.split("_");
if(id[0] !== "actor") {
return false;
}
if(parseInt(id[1]) !== c.turnActorId) {
return false;
}
if ((b === 0 && n !== a)) {
return false;
}
if ((b > 0 && (n < 1 || n < a || n % b !== a % b))) {
return false;
}
} else if (c.turnEnemyValid) {
var enemy = $gameTroop.members()[c.turnEnemyIndex];
if(!enemy) {
return false;
}
var n = enemy.turnCount();
var a = c.turnEnemyA;
var b = c.turnEnemyB;
var id = index.split("_");
if(id[0] !== "enemy") {
return false;
}
if(parseInt(id[1]) !== c.turnEnemyIndex) {
return false;
}
if ((b === 0 && n !== a)) {
return false;
}
if ((b > 0 && (n < 1 || n < a || n % b !== a % b))) {
return false;
}
} else if (c.switchValid) {
if (!$gameSwitches.value(c.switchId)) {
return false;
}
}
return true;
};
//====================
// Game_Battler
//====================
$.isBattleEngineCore = function() {
if(!Imported.YEP_BattleEngineCore) return false;
if(!BattleManager.isTickBased()) return false;
if(!Yanfly.Param.BECAISelfTurn) return false;
return true;
};
var alias_Game_Battler_initMembers = Game_Battler.prototype.initMembers;
Game_Battler.prototype.initMembers = function() {
alias_Game_Battler_initMembers.call(this);
if(!$.isBattleEngineCore()) this._turnCount = 0;
};
Game_Battler.prototype.clearTurn = function() {
if($.isBattleEngineCore()) return;
this._turnCount = 0;
};
Game_Battler.prototype.increaseTurn = function(index) {
if($.isBattleEngineCore()) {
this.increaseSelfTurnCount();
return;
}
this._turnCount++;
};
var alias_Game_Battler_turnCount = Game_Battler.prototype.turnCount;
Game_Battler.prototype.turnCount = function() {
if($.isBattleEngineCore()) {
return alias_Game_Battler_turnCount.call(this);
}
return this._turnCount;
};
var alias_Game_Battler_onBattleStart = Game_Battler.prototype.onBattleStart;
Game_Battler.prototype.onBattleStart = function() {
alias_Game_Battler_onBattleStart.call(this);
this.clearTurn();
};
//====================
// BattleManager
//====================
var alias_BattleManager_startAction = BattleManager.startAction;
BattleManager.startAction = function() {
alias_BattleManager_startAction.call(this);
var subject = this._subject;
if(subject) {
var index = "";
if(subject.isEnemy()) {
index += "enemy_";
index += subject.index();
} else if(subject.isActor()) {
index += "actor_";
index += subject.actorId();
}
subject.increaseTurn(index);
$gameTroop.setup2K3BattleEvent(index);
$gameTroop.onTurnFlags(index);
}
};
})(RS.TurnActorEnemy);