【解決済み】Scene_Base を継承した独自の戦闘シーンでのコモンイベント呼び出し
Posted: 2025年6月12日(木) 10:37
はじめてこちらに質問させていただきます。
https://raw.githubusercontent.com/munok ... ns/master/
上記のMV用プラグインに関する質問です。
MZで使えるようにこちらで修正し、正常に稼働しておりますが、
戦闘中にコモンイベントを挟みたいと思い、様々試したものの実現できませんでした。
基本的にコモンイベントは、 Scene_Map か Scene_Battle が動いている時だけ
$gameMap.update() や BattleManager.update() 内で Interpreter が実行されるため
Scene_Base を継承しているScene_CardBattleでは、マップ用のInterpreter が更新されないかと思います。
Scene_CardBattle にインタプリタを持たせればよいと思い、以下のように定義しました。
しかしコモンイベントは戦闘終了後にしか起爆せず、予約止まりとなります。
以下のように、一旦戦闘処理を止めて実行しようとしましたが、
処理が止まったまま、コモンイベントも実行されませんでした。
実行したい箇所は以下の部分です。
ツクールMZの処理構造にお詳しい方のご助言をいただけますと幸いです。
https://raw.githubusercontent.com/munok ... ns/master/
上記のMV用プラグインに関する質問です。
MZで使えるようにこちらで修正し、正常に稼働しておりますが、
戦闘中にコモンイベントを挟みたいと思い、様々試したものの実現できませんでした。
基本的にコモンイベントは、 Scene_Map か Scene_Battle が動いている時だけ
$gameMap.update() や BattleManager.update() 内で Interpreter が実行されるため
Scene_Base を継承しているScene_CardBattleでは、マップ用のInterpreter が更新されないかと思います。
Scene_CardBattle にインタプリタを持たせればよいと思い、以下のように定義しました。
コード: 全て選択
Scene_CardBattle.prototype.create = function() {
Scene_Base.prototype.create.call(this);
this.createWindowLayer();
if (typeof this.createDisplayObjects === "function") {
this.createDisplayObjects();
} else {
if (typeof this.createCardField === "function") this.createCardField();
if (typeof this.createWindow === "function") this.createWindow();
}
this._ceInterpreter = new Game_Interpreter();
this.createMessageWindow();
};
Scene_CardBattle.prototype.update = function() {
this.updateMain();
// ↓ここで毎フレーム interpreter を動かす
if (this._ceInterpreter) {
if (this._ceInterpreter.isRunning()) {
this._ceInterpreter.update();
} else if ($gameTemp.isCommonEventReserved()) {
const ev = $gameTemp.retrieveCommonEvent();
if (ev && ev.list) this._ceInterpreter.setup(ev.list);
}
}
Scene_Base.prototype.update.call(this);
};
Scene_CardBattle.prototype.updateMain = function() {
var active = this.isActive();
$gameCardBattle.update(active);
};
以下のように、一旦戦闘処理を止めて実行しようとしましたが、
処理が止まったまま、コモンイベントも実行されませんでした。
コード: 全て選択
Scene_CardBattle.prototype.update = function() {
// ① Interpreter が動いているなら それだけ更新して return
if (this._ceInterpreter.isRunning()) {
this._ceInterpreter.update(); // 共通イベントを 1 フレーム処理
Scene_Base.prototype.update.call(this); // 画面描画だけ
return; // ★ バトル更新はスキップ
}
// ② 新しく予約が入っていたらセットアップして return
if ($gameTemp.isCommonEventReserved()) {
const ev = $gameTemp.retrieveCommonEvent();
if (ev && ev.list) this._ceInterpreter.setup(ev.list);
Scene_Base.prototype.update.call(this);
return; // ★ ここもスキップ
}
// ③ 何も無いときだけ通常のバトル進行
this.updateMain();
Scene_Base.prototype.update.call(this);
};
実行したい箇所は以下の部分です。
コード: 全て選択
Game_CardBattle.prototype.updateAttackPhase = function() {
var attacker = this.attackerDeck();
var target = this.targetDeck();
var animationId = attacker.card().attackAnimation();
target.gainHp(-this._damage);
if (this._turn) {
$gameTemp.reserveCommonEvent(1); //ここ
this.addMessage(2, animationId || TMPlugin.Card.AnimationAttack);
} else {
$gameTemp.reserveCommonEvent(2); //ここ
this.addMessage(1, animationId || TMPlugin.Card.AnimationEnemyAttack);
}
this.addMessage(0, target.card().name() + ' に ' + this._damage + ' ダメージ');
this.addMessage(4, 0);
for (;;) {
var attackerLastHp = attacker.hp;
var targetLastHp = target.hp;
this.checkSkill(attacker, target, true);
this.checkSkill(target, attacker, false);
if (attackerLastHp === attacker.hp && targetLastHp === target.hp) break;
}
this.addMessage(4, 0);
this._phase += 1;
};
ツクールMZの処理構造にお詳しい方のご助言をいただけますと幸いです。