-
Notifications
You must be signed in to change notification settings - Fork 0
/
NRP_ForgetLowerSkill.js
278 lines (256 loc) · 10.1 KB
/
NRP_ForgetLowerSkill.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
//=============================================================================
// NRP_ForgetLowerSkill.js
//=============================================================================
/*:
* @target MV MZ
* @plugindesc v1.01 Forget lower level skills when learning higher level skills.
* @author Takeshi Sunagawa (http://newrpg.seesaa.net/)
* @orderAfter NRP_AdditionalClasses
* @url http://newrpg.seesaa.net/article/483693029.html
*
* @help Forget lower level skills when learning higher level skills.
* Also, the message when learning a skill will be changed.
* This will make it act like a skill that ranks up.
*
* -------------------------------------------------------------------
* [Usage]
* -------------------------------------------------------------------
* In the note field of the skill to be treated
* as a higher-level skill, specify the following.
* When a skill is learned, the skill of the ID specified
* in ? will be automatically deleted.
*
* <ForgetSkill:?>
*
* Also, the message at the time of learning will be changed.
*
* -------------------------------------------------------------------
* [Extra Feature]
* -------------------------------------------------------------------
* After applying this plugin, you will be able to use icons
* in the skill acquisition text in the database terms.
* %2 will be the icon number。
*
* "%1 learns \i[%2]%2!"
*
* Specify as above.
*
* The same applies to rank-up messages.
* "\i[%3]%1 has been enhanced to \i[%4]%2!"
* Specify as above.
*
* -------------------------------------------------------------------
* [Terms]
* -------------------------------------------------------------------
* There are no restrictions.
* Modification, redistribution freedom, commercial availability,
* and rights indication are also optional.
* The author is not responsible,
* but will deal with defects to the extent possible.
*
* @-----------------------------------------------------
* @ [Plugin Parameters]
* @-----------------------------------------------------
*
* @param RankUpMessage
* @type string
* @default %1 has been enhanced to %2!
* @desc This is the message when you rank up a skill. %1: Forget Skill, %2: Learn SKill, %3: Icon No(F), %3: Icon No(L)
*/
/*:ja
* @target MV MZ
* @plugindesc v1.01 上位スキル習得時に下位スキルを消去。
* @author 砂川赳(http://newrpg.seesaa.net/)
* @orderAfter NRP_AdditionalClasses
* @url http://newrpg.seesaa.net/article/483693029.html
*
* @help 上位スキル習得時に下位スキルを消去します。
* また、スキル習得時のメッセージを変更することで、
* ランクアップするスキルのような演出が可能です。
* スキルの数を無闇に増やしたくない――なんて場合に便利です。
*
* -------------------------------------------------------------------
* ■使用方法
* -------------------------------------------------------------------
* 上位スキルとして扱うスキルのメモ欄に、以下を指定してください。
* スキルの習得時、?に指定したIDのスキルを自動で削除します。
*
* <ForgetSkill:?>
*
* また、習得時のメッセージも変更されます。
*
* -------------------------------------------------------------------
* ■おまけ機能
* -------------------------------------------------------------------
* 当プラグインを適用すると、データベースの用語にある
* スキル習得のテキストにアイコンを使用できるようになります。
* %2がアイコン番号となります。
*
* 「\i[%2]%1を覚えた!」
*
* というように指定してください。
*
* ランクアップメッセージについても同様です。
* 「\i[%3]%1が\i[%4]%2へと強化された!」
* というようになります。
*
* -------------------------------------------------------------------
* ■利用規約
* -------------------------------------------------------------------
* 特に制約はありません。
* 改変、再配布自由、商用可、権利表示も任意です。
* 作者は責任を負いませんが、不具合については可能な範囲で対応します。
*
* @-----------------------------------------------------
* @ プラグインパラメータ
* @-----------------------------------------------------
*
* @param RankUpMessage
* @text ランクアップメッセージ
* @type string
* @default %1が%2へと強化された!
* @desc ランクアップ時のメッセージです。%1:忘れるスキル, %2:覚えるスキル, %3:アイコンNo(忘), %4:アイコンNo(覚)
*/
(function() {
"use strict";
function toBoolean(val, def) {
// 空白なら初期値を返す
if (val === "" || val === undefined) {
return def;
// 既にboolean型なら、そのまま返す
} else if (typeof val === "boolean") {
return val;
}
// 文字列ならboolean型に変換して返す
return val.toLowerCase() == "true";
}
function toNumber(str, def) {
return isNaN(str) ? def : +(str || def);
}
function setDefault(str, def) {
return str ? str : def;
}
const PLUGIN_NAME = "NRP_ForgetLowerSkill";
const parameters = PluginManager.parameters(PLUGIN_NAME);
const pRankUpMessage = parameters["RankUpMessage"];
// スキルの配列
let mlastSkills = [];
/**
* ●経験値の増減
*/
const _Game_Actor_changeExp = Game_Actor.prototype.changeExp;
Game_Actor.prototype.changeExp = function(exp, show) {
mlastSkills = this.skills();
_Game_Actor_changeExp.apply(this, arguments);
};
/**
* ●スキルの習得
*/
const _Game_Actor_learnSkill = Game_Actor.prototype.learnSkill;
Game_Actor.prototype.learnSkill = function(skillId) {
// 忘却指定のあるスキルを取得
const forgetSkillId = toNumber($dataSkills[skillId].meta.ForgetSkill);
// 既に習得済みのスキルの場合、忘却処理を行う。
if (forgetSkillId && this.isLearnedSkill(forgetSkillId)) {
this.forgetSkill(forgetSkillId);
}
_Game_Actor_learnSkill.apply(this, arguments);
};
/**
* ●レベルアップの表示
*/
const _Game_Actor_displayLevelUp = Game_Actor.prototype.displayLevelUp;
Game_Actor.prototype.displayLevelUp = function(newSkills) {
// メッセージが存在しない場合は元のまま
if (!pRankUpMessage) {
_Game_Actor_displayLevelUp.apply(this, arguments);
return;
}
// 一旦、newSkillsを空にしてメッセージを作成
_Game_Actor_displayLevelUp.call(this, []);
// スキル習得メッセージの表示
displayObtainSkills(this, newSkills);
};
/**
* ●忘却したスキルIDの配列を取得する。
*/
function findForgotSkillIds(actor, lastSkills) {
// 元の配列を壊さないようディープコピー
// const forgetSkills = [...lastSkills];
// 以前のスキルの配列から、新しいスキルの配列を除去する。
const newSkills = actor.skills();
for (const newSkill of newSkills) {
lastSkills.remove(newSkill);
}
return lastSkills.map(skill => skill.id);
};
/**
* ●スキル習得メッセージの表示
*/
function displayObtainSkills(actor, newSkills) {
// 新スキルの習得メッセージを再作成
const forgetSkillIds = findForgotSkillIds(actor, mlastSkills);
for (const skill of newSkills) {
// 忘却指定のあるスキルを取得
const forgetSkillId = toNumber(skill.meta.ForgetSkill);
// 忘れたスキルが一致した場合、ランクアップメッセージを表示
if (forgetSkillId && forgetSkillIds.includes(forgetSkillId)) {
const forgetSkill = $dataSkills[forgetSkillId];
// %1:忘れるスキル, %2:覚えるスキル, %3:忘れるスキルのアイコン番号, %4:覚えるスキルのアイコン番号
$gameMessage.add(pRankUpMessage.format(forgetSkill.name, skill.name, forgetSkill.iconIndex ,skill.iconIndex));
continue;
}
// 通常のメッセージ(おまけ機能で%2にアイコン番号を追加)
$gameMessage.add(TextManager.obtainSkill.format(skill.name, skill.iconIndex));
}
}
//----------------------------------------
// 多重職業プラグインへも対応
//----------------------------------------
/**
* NRP_AdditionalClasses.jsが登録されている場合
*/
const hasAdditionalClasses = PluginManager._scripts.some(function(scriptName) {
return scriptName == "NRP_AdditionalClasses";
});
if (hasAdditionalClasses) {
/**
* ●経験値の増減
*/
const _AdditionalClass_changeExp = AdditionalClass.prototype.changeExp;
AdditionalClass.prototype.changeExp = function(exp, show) {
mlastSkills = this.actor().skills();
_AdditionalClass_changeExp.apply(this, arguments);
};
/**
* ●レベルアップメッセージの表示
*/
const _AdditionalClass_displayLevelUp = AdditionalClass.prototype.displayLevelUp;
AdditionalClass.prototype.displayLevelUp = function(newSkills) {
// メッセージが存在しない場合は元のまま
if (!pRankUpMessage) {
_AdditionalClass_displayLevelUp.apply(this, arguments);
return;
}
// 一旦、newSkillsを空にしてメッセージを作成
_AdditionalClass_displayLevelUp.call(this, []);
// スキル習得メッセージの表示
displayObtainSkills(this.actor(), newSkills);
};
}
/**
* 【MV対応】MZにしか存在しない関数なので追加
*/
if (!Array.prototype.remove) {
Array.prototype.remove = function(element) {
for (;;) {
const index = this.indexOf(element);
if (index >= 0) {
this.splice(index, 1);
} else {
return this;
}
}
};
}
})();