moon-red-goddess-cornelia/js/plugins/ReduceCost.js
2025-10-06 13:25:53 -05:00

82 lines
3.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*:
* @target MZ
* @plugindesc 装備メモ欄で指定スキルの消費MPを±調整-1で+1増加
* @author
*
* @help
* ■使い方(メモ欄)
* ▼1行まとめ
* <ReduceMpSkills: 1201:-1,1205:1,1207:-2>
* - スキル1201 → 消費MPを+1増やす-1
* - スキル1205 → 消費MPを-1減らす 1
* - スキル1207 → 消費MPを+2増やす-2
*
* ▼行分け複数行OK、;区切りも可)
* <ReduceMpSkill: 1201,-1; 1205,1>
* <ReduceMpSkill: 1207,-2>
*
* ■仕様
* - 値は「符号付き整数」。正なら減少、負なら増加。
* - 複数装備で同じスキルを指定した場合は“合算”されます。
* - 最終的な消費MPは下限0で丸めます負にはなりません
* - デフォルトでは武器/防具すべての装備を参照します。
* 防具のみに限定したい場合は、コード内の
* `const equips = this.equips();` を `this.armors();` に変更してください。
*
* ■競合
* - Game_BattlerBase.prototype.skillMpCost をエイリアスしています。
* 同メソッドを「上書き」しているプラグインがあると競合の可能性あり。
* (エイリアス同士なら概ね共存可能)
*
* ■補足
* - 割合系(半減など)と併用時は「基礎→他プラグイン処理→本プラグインの±固定値」
* の順で適用されます。
*/
(() => {
const _skillMpCost = Game_BattlerBase.prototype.skillMpCost;
Game_BattlerBase.prototype.skillMpCost = function(skill) {
let cost = _skillMpCost.call(this, skill);
if (!this.isActor()) return cost;
// ★防具限定にしたい場合は this.armors() に変更
const equips = this.equips();
let deltaSum = 0; // 正: 減る / 負: 増える(最後に cost - deltaSum を適用)
for (const equip of equips) {
if (!equip || !equip.meta) continue;
// ① 個別指定:<ReduceMpSkill: id,delta> ;区切り対応)
if (equip.meta.ReduceMpSkill) {
const chunks = String(equip.meta.ReduceMpSkill).split(";");
for (const chunk of chunks) {
const pair = chunk.split(",").map(s => s.trim());
if (pair.length >= 2) {
const id = Number(pair[0]);
const val = Number.parseInt(pair[1], 10); // 符号付き
if (skill.id === id && Number.isFinite(val)) {
deltaSum += val;
}
}
}
}
// ② まとめ指定:<ReduceMpSkills: id:delta, id:delta, ...>
if (equip.meta.ReduceMpSkills) {
const entries = String(equip.meta.ReduceMpSkills).split(",");
for (const e of entries) {
const [idStr, valStr] = e.split(":").map(s => s.trim());
const id = Number(idStr);
const val = Number.parseInt(valStr, 10); // 符号付き
if (skill.id === id && Number.isFinite(val)) {
deltaSum += val;
}
}
}
}
// deltaSum が負なら「増加」になるcost - (-1) = cost +1
return Math.max(0, cost - deltaSum);
};
})();