slave-thistle/www/js/plugins/0_HalfMpSwitch.js
2025-05-26 09:44:24 -05:00

85 lines
3.4 KiB
JavaScript
Raw 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.

/*:
* @plugindesc 特定のスイッチがONのとき、スキルの消費MPを半減する端数切り上げ
* @author あなたの名前
*
* @param mpHalfSwitchId
* @text 消費MP半減スイッチID
* @desc ONのとき、スキルの消費MPが半減するスイッチのID
* @default 248
* @type number
*
* @help
* 【概要】
* 指定したスイッチがONのとき、スキルの消費MPを半減します。
* OFFの場合は通常のMP消費となります。
*
* 【使用方法】
* 1. プラグインパラメータで「消費MP半減スイッチID」を設定デフォルトは248
* 2. そのスイッチをONにすると、スキルのMP消費が半減
* 3. 戦闘時、メニュー画面のMP表示にも対応
* 4. スイッチをOFFにすると、通常の消費MPに戻る
*
* 【注意点】
* - **Yanflyの YEP_SkillCore** に対応。
* - MP消費率 (`mcr`) の影響を適正に計算し、二重適用を防ぐ。
* - **MP消費の端数は切り上げに変更。**
*/
(() => {
'use strict';
let pluginName = 'HalfMpSwitch';
let parameters = PluginManager.parameters(pluginName);
let mpHalfSwitchId = Number(parameters['mpHalfSwitchId']) || 248; // デフォルトはスイッチ248
// YEP_SkillCore が有効かどうか判定
let isYEP_SkillCoreEnabled = Imported.YEP_SkillCore;
// スキルの消費MPを取得戦闘時のMP消費に適用
let _Game_BattlerBase_skillMpCost = Game_BattlerBase.prototype.skillMpCost;
Game_BattlerBase.prototype.skillMpCost = function(skill) {
let cost = _Game_BattlerBase_skillMpCost.call(this, skill);
// YEP_SkillCore の影響を取り除くMP消費率 mcr を適用前に調整)
if (isYEP_SkillCoreEnabled) {
cost /= this.mcr; // MP消費率mcr適用前にリセット
}
// スイッチがONのとき MP消費を半減
if ($gameSwitches.value(mpHalfSwitchId)) {
cost *= 0.5;
}
// 最終的な MP 消費率 (mcr) を適用
if (isYEP_SkillCoreEnabled) {
cost *= this.mcr;
}
return Math.max(0, Math.ceil(cost)); // 切り上げに変更
};
// メニュー画面のスキル消費MP表示を変更
let _Window_SkillList_drawMpCost = Window_SkillList.prototype.drawMpCost;
Window_SkillList.prototype.drawMpCost = function(skill, x, y, width) {
if (this._actor) {
let cost = this._actor.skillMpCost(skill);
if (cost > 0) {
if (Yanfly.Icon.Mp > 0) {
let iw = x + width - Window_Base._iconWidth;
this.drawIcon(Yanfly.Icon.Mp, iw, y + 2);
width -= Window_Base._iconWidth + 2;
}
this.changeTextColor(this.textColor(Yanfly.Param.SCCMpTextColor));
let fmt = Yanfly.Param.SCCMpFormat;
let text = fmt.format(Yanfly.Util.toGroup(cost), TextManager.mpA);
this.contents.fontSize = Yanfly.Param.SCCMpFontSize;
this.drawText(text, x, y, width, 'right');
this.resetFontSettings();
return width - this.textWidth(text) - Yanfly.Param.SCCCostPadding;
}
}
return _Window_SkillList_drawMpCost.call(this, skill, x, y, width);
};
})();