magical-girls-runa-and-nanami/js/plugins/maus_battle.js
2026-02-28 12:33:13 -06:00

109 lines
3.2 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 [究極安定版] スイッチ113がONのときマウスオーバー選択左クリック決定(完全リセット対応)
* @author you
*
* @help
* ■ 概要
* バトル中のみ動作。
* スイッチ113がONの間、以下の挙動を行います。
*
* ・右半分x >= 641にマウスがある → 右キー入力中と同じ
* ・左半分x <= 640にマウスがある → 左キー入力中と同じ
* ・左クリック → 決定キー(OK)入力1フレームスイッチ113をOFF
*
* ■ 安定化仕様
* ・戦闘開始終了の両方で全Input状態をリセット左右残留防止
* ・スイッチOFF時は完全停止
* ・再ONで再動作可能
*/
(() => {
const SWITCH_ID = 113;
const CENTER_X = 640;
let okTriggered = false;
let processing = false;
// 入力を完全リセット(全状態と履歴)
function resetAllInput() {
Input._currentState = {};
Input._previousState = {};
Input._latestButton = null;
Input._pressedTime = 0;
if (Input.clear) Input.clear();
}
// スイッチONバトル中チェック
function isReady() {
return (
typeof $gameSwitches !== "undefined" &&
$gameSwitches &&
typeof $gameParty !== "undefined" &&
$gameParty &&
$gameParty.inBattle &&
$gameParty.inBattle() &&
$gameSwitches.value(SWITCH_ID)
);
}
// メイン更新
const _updateMain = SceneManager.updateMain;
SceneManager.updateMain = function() {
_updateMain.call(this);
if (!isReady()) {
processing = false;
return;
}
if (processing) return;
processing = true;
const x = TouchInput.x;
Input._currentState.left = false;
Input._currentState.right = false;
if (x >= CENTER_X + 1) {
Input._currentState.right = true;
} else if (x <= CENTER_X) {
Input._currentState.left = true;
}
if (TouchInput.isTriggered() && !TouchInput.isCancelled()) {
okTriggered = true;
}
};
// OK入力とOFF処理
const _Input_update = Input.update;
Input.update = function() {
_Input_update.call(this);
if (okTriggered) {
this._currentState.ok = true;
okTriggered = false;
setTimeout(() => {
this._currentState.ok = false;
if ($gameSwitches) $gameSwitches.setValue(SWITCH_ID, false);
processing = false;
}, 16);
}
};
// 🧩【追加】戦闘開始時にも全入力を初期化
const _BattleManager_setup = BattleManager.setup;
BattleManager.setup = function(troopId, canEscape, canLose) {
resetAllInput(); // ← 戦闘に入る瞬間にリセット
_BattleManager_setup.call(this, troopId, canEscape, canLose);
};
// 🧩【追加】戦闘終了時にも全入力を初期化
const _BattleManager_endBattle = BattleManager.endBattle;
BattleManager.endBattle = function(result) {
_BattleManager_endBattle.call(this, result);
setTimeout(() => {
resetAllInput(); // ← 1フレーム後に完全クリア
processing = false;
}, 16);
};
})();