Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*:
- * @plugindesc Creates an invisible savegame before every fight and optionally reloads it after a defeat.
- * <Iavra Battle Retry>
- * @author Iavra
- *
- * @param Label Retry
- * @desc Label to be used for the "retry" option of the command window. Default: Retry
- * @default Retry
- *
- * @param Label Title
- * @desc Label to be used for the "title" option of the command window. Default: To Title
- * @default To Title
- *
- * @param Window Position
- * @desc Y coordinate of the command window, that gets displayed during the gameover scene after a battle. Default: 400
- * @default 400
- *
- * @param Disable Switch
- * @desc Id of an optional switch, that can be set ON to (temporarily) disable battle retry. Default: 0
- * @default 0
- *
- * @help
- * Note: Please place this below every other plugin, that deals with the battle system.
- *
- * If the plugin is active and the switch defined under "Disable Switch" is set to OFF, every lost fight (that will
- * redirect to the gameover screen) offers the option to retry the battle.
- */
- var Imported = Imported || {};
- Imported.iavra_quickselect = true;
- //=============================================================================
- // namespace IAVRA
- //=============================================================================
- var IAVRA = IAVRA || {};
- (function() {
- "use strict";
- /**
- * Retrieve plugin parameters independant from the plugin's actual filename.
- */
- var _params = $plugins.filter(function(p) { return p.description.contains('<Iavra Battle Retry>'); })[0].parameters;
- var _param_labelRetry = _params['Label Retry'];
- var _param_labelTitle = _params['Label Title'];
- var _param_position = parseInt(_params['Window Position']) || 0;
- var _param_disableSwitch = parseInt(_params['Disable Switch']) || 0;
- /**
- * Contains the saved data.
- */
- var _data;
- /**
- * Creates a new save, which is stored in a variable, instead of being written to a file.
- */
- var _save = function() {
- var contents = DataManager.makeSaveContents();
- contents.troop = $gameTroop;
- _data = JsonEx.stringify(contents);
- }
- /**
- * Loads the current save from the variable.
- */
- var _load = function() {
- var contents = JsonEx.parse(_data)
- DataManager.extractSaveContents(contents);
- $gameTroop = contents.troop;
- };
- //=============================================================================
- // module IAVRA.BATTLERETRY
- //=============================================================================
- IAVRA.BATTLERETRY = {
- Scene_Gameover: function() { this.initialize.apply(this, arguments); },
- Window_Command: function() { this.initialize.apply(this, arguments); }
- };
- //=============================================================================
- // class IAVRA.BATTLERETRY.Scene_Gameover
- //=============================================================================
- (function($) {
- ($.prototype = Object.create(Scene_Gameover.prototype)).constructor = $;
- /**
- * Unlike the normal gameover scene, we display a command window, that can be used to retry the battle.
- */
- $.prototype.create = function() {
- Scene_Gameover.prototype.create.call(this);
- this.createCommandWindow();
- };
- /**
- * On start, open the command window for a small visual touch.
- */
- $.prototype.start = function() {
- Scene_Gameover.prototype.start.call(this);
- this._commandWindow.open();
- }
- /**
- * Add 2 command handler to either redirect to the title screen or back to the battle.
- */
- $.prototype.createCommandWindow = function() {
- this.addChild(this._commandWindow = new IAVRA.BATTLERETRY.Window_Command());
- this._commandWindow.setHandler('retry', this.retryBattle.bind(this));
- this._commandWindow.setHandler('title', this.gotoTitle.bind(this));
- };
- /**
- * On retry, load the stored savegame and go to the battle scene.
- */
- $.prototype.retryBattle = function() {
- _load();
- SceneManager.goto(Scene_Battle);
- };
- /**
- * We have a window, so we override the default behaviour of Scene_Gameover, that redirects to the title scene,
- * when the "ok" button is pressed.
- */
- $.prototype.isTriggered = function() { return false; }
- })(IAVRA.BATTLERETRY.Scene_Gameover);
- //=============================================================================
- // class IAVRA.BATTLEENTRY.Window_Retry
- //=============================================================================
- (function($) {
- ($.prototype = Object.create(Window_Command.prototype)).constructor = $;
- /**
- * Horizontally center the window and start closed, to it can be opened by the scene, when it starts.
- */
- $.prototype.initialize = function() {
- Window_Command.prototype.initialize.call(this, 0, _param_position);
- this.x = (Graphics.boxWidth - this.width) / 2;
- this.openness = 0;
- };
- /**
- * Add 2 commands, to either retry the battle or to go to the title screen (normal gameover behaviour).
- */
- $.prototype.makeCommandList = function() {
- this.addCommand(_param_labelRetry, 'retry', true);
- this.addCommand(_param_labelTitle, 'title', true);
- };
- })(IAVRA.BATTLERETRY.Window_Command);
- //=============================================================================
- // module BattleManager
- //=============================================================================
- (function($) {
- /**
- * On battle start, store the current game state.
- */
- var alias_startBattle = $.startBattle;
- $.startBattle = function() {
- _save();
- alias_startBattle.call(this);
- };
- /**
- * Redirect to our own gameover scene if:
- * - this is not a battle test.
- * - the whole party is dead (aka defeat).
- * - the battle would actually redirect to the gameover screen afterwards (isn't meant to be lost).
- * - the disable switch isn't set to ON.
- */
- var alias_updateBattleEnd = $.updateBattleEnd;
- $.updateBattleEnd = function() {
- if(!this.isBattleTest() && $gameParty.isAllDead() &&
- !this._canLose && !$gameSwitches.value(_param_disableSwitch)) {
- SceneManager.goto(IAVRA.BATTLERETRY.Scene_Gameover);
- } else { alias_updateBattleEnd.call(this); }
- };
- })(BattleManager);
- })();
Add Comment
Please, Sign In to add comment