pure-full-lily/js/plugins/NRP_VictoryRewards_PreLevelUpCE.js
2025-09-16 10:12:44 -05:00

99 lines
4.7 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 [v1.2.0] Victory Rewards拡張: レベルアップ文言表示タイミングでコモンイベント実行NRP_VictoryRewards_Custom検知
* @author IvI
*
* @param LevelUpCommmonEvent
* @text レベルアップ前コモンイベント
* @type common_event
* @desc レベルアップメッセージ(\LVUPSE付き行が表示される瞬間に同期実行するコモンイベントID。
*
* @help
* ------------------------------------------------------------------
* ■概要
* NRP_VictoryRewards_Custom.js がレベルアップメッセージ冒頭に挿入する
* 制御文字「\LVUPSE」を検知し、その直後描画直前にコモンイベントを
* 同期実行します。これにより「リザルト開始時」ではなく
* 「レベルアップ文言が出た瞬間」に演出を差し込めます。
*
* 戦闘勝利時のレベルアップはもちろん、パラメータ
* 「非戦闘時にも反映」をONにして経験値獲得→レベルアップしたケース
* にも対応します。
*
* ------------------------------------------------------------------
* ■使い方
* 1. 本プラグインを NRP_VictoryRewards_Custom.js より下に配置。
* 2. パラメータ「レベルアップ前コモンイベント」に任意のコモンイベントID。
*
* ※複数アクターが同時にレベルアップした場合、アクターごとに
* \LVUPSE が含まれるメッセージ行が生成されます。よって
* コモンイベントはアクター数ぶん繰り返し実行されます。
*
* ------------------------------------------------------------------
* ■注意
* - コモンイベント内でメッセージ表示を行うと表示順が前後することがあります。
* 必要ならウェイトやピクチャ演出など短い処理に留めるのが安全です。
* - 長尺イベントを挟むとレベルアップメッセージ表示が大幅に遅延します。
*
* ------------------------------------------------------------------
* ■更新履歴
* v1.2.0 NRP_VictoryRewards_Custom の \LVUPSE 制御文字をフックする方式に変更。
* v1.1.0 Window_Message.startMessage フック版(非推奨)。
* v1.0.0 Game_Actor.displayLevelUp フック初版。
*
* ------------------------------------------------------------------
* ■ライセンス : MIT / クレジット任意
* © 2025 IvI
*/
(() => {
"use strict";
const PN = "NRP_VictoryRewards_PreLevelUpCE";
const param = PluginManager.parameters(PN);
// 旧綴り互換Commmon→Common: どちらでも拾う
const levelUpCE = Number(param["LevelUpCommmonEvent"] || param["LevelUpCommonEvent"] || 0);
if (!levelUpCE) return; // 未設定なら何もしない
// 実行済みガード(同じメッセージ行内で二重発火しない)
let _lvupCeFiredFrame = -1;
//--------------------------------------------------
// Window_Base.processEscapeCharacter フック
// NRP_VictoryRewards_Custom が \LVUPSE を使うのでそこを検知)
//--------------------------------------------------
const _Window_Base_processEscapeCharacter = Window_Base.prototype.processEscapeCharacter;
Window_Base.prototype.processEscapeCharacter = function(code, textState) {
_Window_Base_processEscapeCharacter.call(this, code, textState);
if (code && code.toUpperCase && code.toUpperCase() === "LVUPSE") {
// 同一フレーム多重防止複数ウィンドウで処理されても1回
const frameCount = Graphics.frameCount;
if (_lvupCeFiredFrame !== frameCount) {
_lvupCeFiredFrame = frameCount;
runPreLvCommonEvent();
}
}
};
//--------------------------------------------------
// コモンイベント同期実行
//--------------------------------------------------
function runPreLvCommonEvent() {
$gameTemp.reserveCommonEvent(levelUpCE);
if ($gameParty.inBattle()) {
const itp = $gameTroop._interpreter;
itp.setupReservedCommonEvent();
// 完全同期:終わるまで回す
while (itp.isRunning()) itp.update();
} else {
// マップ側
let safety = 0;
const max = 999; // 無限ループ安全策
do {
$gameMap.setupStartingEvent();
$gameMap.update(false);
safety++;
} while (($gameMap._interpreter && $gameMap._interpreter.isRunning()) && safety < max);
}
}
})();