prison-brave/js/plugins/IM_TorigoyaMZ_EnemyTpBar_Plus.js
2025-08-28 10:38:20 -05:00

113 lines
4.8 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.

/*=============================================================================
* IM_TorigoyaMZ_EnemyTpBar_Plus.js
* - TorigoyaMZ_EnemyHpBar 用 TP 追加パッチ
*----------------------------------------------------------------------------
* 2025/06/27
* Immoralist
*----------------------------------------------------------------------------
* このプラグインは「敵 HP バー表示プラグイン (TorigoyaMZ_EnemyHpBar)」の
* クラスを流用し、HP バー直下に TP ゲージを描画します。
* 本プラグイン単体では動作しません。必ず TorigoyaMZ_EnemyHpBar.js を
* 先に導入してください。
*============================================================================*/
/*:ja
* @target MZ
* @plugindesc 敵 TP ゲージを HP バーの下に追加します。
* @author ChatGPT
*
* @param offsetY
* @text TPバーの縦オフセット
* @type number
* @min -100
* @max 100
* @default 2
*
* @help
* ■使い方
* このファイルを TorigoyaMZ_EnemyHpBar.js より後に読み込むだけで OK です。
*
* ■仕様
* - HP バーと同じ表示条件/非表示条件で TP ゲージも表示・非表示されます。
* - ゲージ幅・高さ・ラベル表示 ON/OFF 等の設定は HP バーの設定をそのまま
* 共有します。
* - 表示位置は「HP バーの高さ + オフセット(p offsetY)」だけ下に描画されます。
*----------------------------------------------------------------------------*/
(() => {
'use strict';
// 元プラグインが無い場合は警告して終了
if (!window.Torigoya || !Torigoya.EnemyHpBar) {
console.error('TorigoyaMZ_EnemyTpBar: TorigoyaMZ_EnemyHpBar が読み込まれていません。');
return;
}
//-------------------------------------------------------------------------
// 設定
//-------------------------------------------------------------------------
const PLUGIN_NAME = 'TorigoyaMZ_EnemyTpBar';
const parameters = PluginManager.parameters(PLUGIN_NAME);
const TP_BAR_OFFSET_Y = Number(parameters.offsetY || 2);
const EnemyHpBar = Torigoya.EnemyHpBar;
//-------------------------------------------------------------------------
// TP ゲージスプライト
// HP 用クラスを継承して drawValue を上書きするだけ
//-------------------------------------------------------------------------
class Sprite_EnemyTpGauge extends EnemyHpBar.Sprite_EnemyHpGauge {
/** TP は常に数値表示HP 用のマスク処理は無効化) */
drawValue() {
if (!EnemyHpBar.parameter.customizeDrawLabel) return;
super.drawValue();
}
}
// 名前空間に登録
const EnemyTpBar = (Torigoya.EnemyTpBar = {
name: PLUGIN_NAME,
parameter: { offsetY: TP_BAR_OFFSET_Y },
Sprite_EnemyTpGauge
});
//-------------------------------------------------------------------------
// Sprite_Enemy へのパッチ
//-------------------------------------------------------------------------
// HP バー生成後に TP バー生成
const _Sprite_Enemy_initMembers = Sprite_Enemy.prototype.initMembers;
Sprite_Enemy.prototype.initMembers = function () {
_Sprite_Enemy_initMembers.apply(this, arguments);
this._createTorigoyaEnemyTpBarSprite();
};
Sprite_Enemy.prototype._createTorigoyaEnemyTpBarSprite = function () {
this._torigoyaEnemyTpBar_gaugeSprite = new EnemyTpBar.Sprite_EnemyTpGauge();
this._torigoyaEnemyTpBar_gaugeSprite.anchor.x = 0.5;
this._torigoyaEnemyTpBar_gaugeSprite.opacity = 0;
this.addChild(this._torigoyaEnemyTpBar_gaugeSprite);
};
// バトラー設定
const _Sprite_Enemy_setBattler = Sprite_Enemy.prototype.setBattler;
Sprite_Enemy.prototype.setBattler = function (battler) {
_Sprite_Enemy_setBattler.apply(this, arguments);
this._torigoyaEnemyTpBar_gaugeSprite.setup(battler, 'tp');
};
// 座標・透明度更新
const _Sprite_Enemy_update = Sprite_Enemy.prototype.update;
Sprite_Enemy.prototype.update = function () {
_Sprite_Enemy_update.apply(this, arguments);
if (this._enemy) this._updateTorigoyaEnemyTpBarSprite();
};
Sprite_Enemy.prototype._updateTorigoyaEnemyTpBarSprite = function () {
const sprite = this._torigoyaEnemyTpBar_gaugeSprite;
sprite.x = this._torigoyaEnemyHpBar_gaugeSprite.x; // X 位置は HP と同じ
sprite.y =
this._torigoyaEnemyHpBar_gaugeSprite.y +
this._torigoyaEnemyHpBar_gaugeSprite.textHeight() +
EnemyTpBar.parameter.offsetY; // HP の下にオフセット
sprite.opacity += sprite.shouldShow() ? 48 : -48;
};
})();