// // yanaオートバトル MZ自己改造 // // ------------------------------------------------------ // Copyright (c) 2016 Yana // Released under the MIT license // http://opensource.org/licenses/mit-license.php // ------------------------------------------------------ // // author Yana + hamachi_ya // /*: * @target MZ * @plugindesc 戦闘中にキー入力でオートバトルを開始できるようにします。また、オートバトル中は高速化します。 * @author Yana * * @param autoBattleSwitch * @type switch * @desc オートバトルを無効化するためのスイッチです。 * @default 11 * * @param showX * @type number * @desc AutoBattleWindowの表示位置X座標です。(幅は320固定) * @default 496 * * @param showY * @type number * @desc AutoBattleWindowの表示位置Y座標です。(高さは49固定) * @default 395 * * @param autoBattleSpeed * @type number * @min 1 * @max 4 * @desc オートバトル時の戦闘速度です。1=通常、4=最速 * @default 4 * * @param showWindow * @type boolean * @desc AutoBattleWindowを表示するか。falseなら黒帯のみ。 * @default true * * @param autoBattleUseSkill * @type boolean * @desc trueなら通常の自動戦闘と同じ行動。falseなら通常攻撃のみ。 * @default false * * @param windowHideSwitch * @type switch * @desc AutoBattleWindowを隠すスイッチ。イベント中などで利用。 * @default 12 * * @param autoBattleKey * @type select * @option shift * @option control * @option tab * @option pageup * @option pagedown * @option menu * @desc オートバトルの開始に使用するキー。 * @default shift * * @param autoBattleUsableMessage * @type string * @desc オートバトル中に表示するテキスト。_keyがキー名に変換されます。 * @default _keyで解除 * * @param autoBattleMessage * @type string * @desc 非オートバトル時に表示するテキスト。_keyがキー名に変換されます。 * @default _key:オート * * @help------------------------------------------------------ * このプラグインにはプラグインコマンドはありません。 * ------------------------------------------------------ * 仕様と解説 * ------------------------------------------------------ * ・AutoBattleWindowをクリックすることでもオートバトルの開始/停止が可能です。 * ・Auto Battle Keyで使用可能なキーの一覧は以下の通りです。 * pageup : Qキー、pageupキー、LBボタン * pagedown : Wキー、pagedownキー、RBボタン * shift : shiftキー、Xボタン * control : ctrlキー、altキー * tab : tabキー * menu : Yボタン * ・Auto Battle Use Skillがfalseの場合、通常攻撃のみを行います。 * ・イベントが開始しても自動でウィンドウは消えません。これはコモンイベントなどで開いたり閉じたりするのを防ぐ目的があります。 * ------------------------------------------------------ * 利用規約 * ------------------------------------------------------ * 当プラグインはMITライセンスで公開されています。 * 使用に制限はありません。商用、アダルト、いずれにも使用できます。 * 二次配布も制限はしませんが、サポートは行いません。 * 著作表示は任意です。行わなくても利用できます。 * 要するに、特に規約はありません。 * バグ報告や使用方法等のお問合せはネ実ツクールスレ、または、Twitterにお願いします。 * https://twitter.com/yanatsuki_ * 素材利用は自己責任でお願いします。 * ------------------------------------------------------ * 更新履歴: * ver1.03: * スキルウィンドウとアイテムウィンドウが開いたとき、オートバトルウィンドウが閉じるように修正。 * ver1.02: * startMoveでcallが抜けていたバグを修正 * ver1.01: * startTurnが2回実行される可能性のあるバグを修正 * ver1.00: * 公開 */ (function(){ 'use strict'; const pluginName = 'AutoBattle'; const parameters = PluginManager.parameters(pluginName); console.log(parameters); var invalidateAutoBattleSwitch = Number(parameters['autoBattleSwitch'] || 11); var showX = Number(parameters['showX'] || 496); var showY = Number(parameters['showY'] || 395); var autoBattleSpeed = Number(parameters['autoBattleSpeed'] || 4); var showWindow = String(parameters['showWindow'] || 'true') === 'true'; var windowHideSwitch = Number(parameters['windowHideSwitch'] || 12); var autoBattleKey = String(parameters['autoBattleKey'] || 'shift'); var autoBattleUsableMessage = String(parameters['autoBattleUsableMessage'] || 'Shiftで解除'); var autoBattleMessage = String(parameters['autoBattleMessage'] || 'Shift: オート'); BattleManager.isAutoBattle = function(){ return this._autoBattle && !this.isAutoBattleInvalid(); }; BattleManager.autoBattleActivate = function(){ this._autoBattle = true; }; BattleManager.autoBattleDeactivate = function(){ this._autoBattle = false; }; BattleManager.isAutoBattleInvalid = function(){ return $gameSwitches.value(invalidateAutoBattleSwitch); }; BattleManager.startAutoBattle = function(){ $gameParty.members().forEach(member => { if (!this.isTpb()) { member.makeAutoBattleActions(); } else { member.setAutoBattleUntilEnd(); } }); if (BattleManager.isInputting()){ this.startTurn() } }; var _aB_BManager_startInput = BattleManager.startInput; BattleManager.startInput = function(){ _aB_BManager_startInput.call(this); if (this.isAutoBattle()){ this.startAutoBattle() } }; var _aB_BManager_startTurn = BattleManager.startTurn; BattleManager.startTurn = function() { if (!this.isAutoBattle()){ SceneManager._scene._autoBattleWindow.close() } _aB_BManager_startTurn.call(this); }; function Window_AutoBattle() { this.initialize.apply(this, arguments); }; Window_AutoBattle.prototype = Object.create(Window_Base.prototype); Window_AutoBattle.prototype.constructor = Window_AutoBattle; Window_AutoBattle.prototype.initialize = function() { Window_Base.prototype.initialize.call(this,new Rectangle(showX, showY, 240, 54)); if (!showWindow){ this.opacity = 0 } this.refresh(); }; Window_AutoBattle.prototype.standardPadding = function(){ return 6; }; Window_AutoBattle.prototype.refresh = function(){ this.contents.clear(); this.contents.fontSize = 18; var b1 = 'rgba(0,0,0,0)'; var b2 = 'rgba(0,0,0,0.5)'; if (!showWindow){ var w = this.contentsWidth()/4; this.contents.gradientFillRect(0,0,w,32,b1,b2); this.contents.fillRect(w,0,w*2,32,b2); this.contents.gradientFillRect(w*3,0,w,32,b2,b1); } var text = BattleManager.isAutoBattle() ? autoBattleUsableMessage : autoBattleMessage; text = text.replace(/_key/,autoBattleKey); this.drawText(text,0,0,this.contentsWidth(),'center'); }; /////////////////////////////////////////////////////////////////////////////////// var _aB_SBattle_createAllWindows = Scene_Battle.prototype.createAllWindows; Scene_Battle.prototype.createAllWindows = function(){ _aB_SBattle_createAllWindows.call(this); this.createAutoBattleWindow(); }; Scene_Battle.prototype.createAutoBattleWindow = function(){ this._autoBattleWindow = new Window_AutoBattle(); this._autoBattleWindow.hide(); this._autoBattleWindow.close(); this.addWindow(this._autoBattleWindow); }; var _aB_SBattle_updateTurn = Scene_Battle.prototype.update; Scene_Battle.prototype.update = function() { _aB_SBattle_updateTurn.call(this); if (this._autoBattleWindow.isOpen() && (Input.isTriggered(autoBattleKey) || this.onTouchCallAutoBattle())){ if (BattleManager.isAutoBattle()){ this.deactivateAutoBattle(); SoundManager.playCancel(); } else if (!BattleManager.isInTurn() && !BattleManager.isAutoBattleInvalid() && (this._partyCommandWindow.active || this._actorCommandWindow.active)){ this.activateAutoBattle(); SoundManager.playOk(); this._partyCommandWindow.close(); this._actorCommandWindow.close(); BattleManager.startAutoBattle(); } } else if (this._autoBattleWindow.isOpen() && (this.isHideAutoBattleWindow() || BattleManager.isAutoBattleInvalid())){ this.deactivateAutoBattle(); } this.endHideAutoBattleWindow(); }; Scene_Battle.prototype.onTouchCallAutoBattle = function(){ if (TouchInput.isTriggered()){ var x = TouchInput.x; var y = TouchInput.y; var ax = this._autoBattleWindow.x; var xw = ax + this._autoBattleWindow.width; var ay = this._autoBattleWindow.y; var yh = ay + this._autoBattleWindow.height; return x >= ax && x <= xw && y >= ay && y <= yh; } return false; }; Scene_Battle.prototype.canAuto = function(){ return !(BattleManager.isAutoBattleInvalid() || this.isHideAutoBattleWindow()); }; var _aB_SBattle_startPartyCommandSelection = Scene_Battle.prototype.startPartyCommandSelection; Scene_Battle.prototype.startPartyCommandSelection = function() { if (this.canAuto()){ this._autoBattleWindow.show(); this._autoBattleWindow.open(); } _aB_SBattle_startPartyCommandSelection.call(this); }; var _aB_SBattle_startActorCommandSelection = Scene_Battle.prototype.startActorCommandSelection; Scene_Battle.prototype.startActorCommandSelection = function(){ _aB_SBattle_startActorCommandSelection.call(this); if (this.canAuto()){ this._autoBattleWindow.open() } }; var _aB_SBattle_commandSkill = Scene_Battle.prototype.commandSkill; Scene_Battle.prototype.commandSkill = function(){ _aB_SBattle_commandSkill.call(this); this._autoBattleWindow.close(); }; var _aB_SBattle_commandItem = Scene_Battle.prototype.commandItem; Scene_Battle.prototype.commandItem = function(){ _aB_SBattle_commandItem.call(this); this._autoBattleWindow.close(); }; var _aB_SBattle_onSkillCancel = Scene_Battle.prototype.onSkillCancel; Scene_Battle.prototype.onSkillCancel = function(){ _aB_SBattle_onSkillCancel.call(this); if (this.canAuto()){ this._autoBattleWindow.open() } }; var _aB_SBattle_onItemCancel = Scene_Battle.prototype.onItemCancel; Scene_Battle.prototype.onItemCancel = function(){ _aB_SBattle_onItemCancel.call(this); if (this.canAuto()){ this._autoBattleWindow.open() } }; var _aB_SBattle_commandEscape = Scene_Battle.prototype.commandEscape; Scene_Battle.prototype.commandEscape = function(){ if (!BattleManager.isAutoBattle()){ this._autoBattleWindow.close() } this.deactivateAutoBattle(); _aB_SBattle_commandEscape.call(this); }; Scene_Battle.prototype.isHideAutoBattleWindow = function(){ return $gameSwitches.value(windowHideSwitch); }; Scene_Battle.prototype.endHideAutoBattleWindow = function(){ if (BattleManager.isAborting() || $gameParty.members().length === 0 || $gameParty.isAllDead() || $gameTroop.isAllDead()){ this.deactivateAutoBattle(); } }; Scene_Battle.prototype.deactivateAutoBattle = function(){ BattleManager.autoBattleDeactivate(); this._autoBattleWindow.refresh(); if (this._autoBattleWindow.isOpen()){ this._autoBattleWindow.close() } }; Scene_Battle.prototype.activateAutoBattle = function(){ BattleManager.autoBattleActivate(); this._autoBattleWindow.refresh(); if (!this._autoBattleWindow.isOpen()){ this._autoBattleWindow.open() } Input.update(); TouchInput.update(); }; // オートバトル中、メッセージ速度を変更 var _aB_WBLog_messageSpeed = Window_BattleLog.prototype.messageSpeed; Window_BattleLog.prototype.messageSpeed = function() { if (BattleManager.isAutoBattle()){ return _aB_WBLog_messageSpeed.call(this) / autoBattleSpeed; }else{ return _aB_WBLog_messageSpeed.call(this); } }; // オートバトル中、rateを高速化 var _aB_SAnimation_setupRate = Sprite_AnimationMV.prototype.setupRate; Sprite_AnimationMV.prototype.setupRate = function() { if (BattleManager.isAutoBattle()){ this._rate = 4 / autoBattleSpeed; }else{ _aB_SAnimation_setupRate.call(this); } }; // アニメーション速度(MZ処理追加) const _Sprite_Animation_updateEffectGeometry = Sprite_Animation.prototype.updateEffectGeometry; Sprite_Animation.prototype.updateEffectGeometry = function() { _Sprite_Animation_updateEffectGeometry.apply(this); if (!BattleManager.isAutoBattle()) { return; } // パーティクル速度を変更 if (autoBattleSpeed != 1) { this._handle.setSpeed(autoBattleSpeed); } }; // モーション速度(MZ処理追加) const _Sprite_Actor_motionSpeed = Sprite_Actor.prototype.motionSpeed; Sprite_Actor.prototype.motionSpeed = function() { let result = _Sprite_Actor_motionSpeed.apply(this); if (!BattleManager.isAutoBattle()) { return result; } // 速度変更 if (autoBattleSpeed != 1) { result = Math.round(result /autoBattleSpeed); } return result; }; // オートバトル中、アクターのアクション待ちを短縮 var _aB_SBattler_startMove = Sprite_Battler.prototype.startMove; Sprite_Battler.prototype.startMove = function(x, y, duration) { if (BattleManager.isAutoBattle()){ duration /= autoBattleSpeed; } _aB_SBattler_startMove.call(this,x,y,duration); }; // 次のアニメーションのディレイ(MZ処理追加) const _Sprite_Base_animationNextDelay = Spriteset_Base.prototype.animationNextDelay; Spriteset_Base.prototype.animationNextDelay = function() { let result = _Sprite_Base_animationNextDelay.apply(this); if (BattleManager.isAutoBattle()) { result /= autoBattleSpeed; } return result; }; Spriteset_Battle.prototype.animationBaseDelay = function() { return $gameSystem.isSideView() ? Spriteset_Base.prototype.animationBaseDelay.call(this) : 0; }; const _Spriteset_Battle_isEffecting = Spriteset_Battle.prototype.isEffecting; Spriteset_Battle.prototype.isEffecting = function() { return BattleManager.isAutoBattle() ? false : _Spriteset_Battle_isEffecting.call(this); }; const _Spriteset_Battle_isAnyoneMoving = Spriteset_Battle.prototype.isAnyoneMoving; Spriteset_Battle.prototype.isAnyoneMoving = function() { return BattleManager.isAutoBattle() ? false : _Spriteset_Battle_isAnyoneMoving.call(this); }; Spriteset_Battle.prototype.isBusy = function() { return BattleManager.isAutoBattle() ? false : this.isAnimationPlaying(); }; }());