/*:
* @target MZ
* @plugindesc Cae_Tweaks D12 - setSurprise() & setPreemptive() script calls.
* @author Caethyril
* @url https://forums.rpgmakerweb.com/threads/156047/
* @help Adds the following global functions, for use in Script commands:
* setSurprise(); // force enemy advantage for next battle
* setPreemptive(); // force party advantage for next battle
* These effects are temporary! They will reset:
* - On New/Load game;
* - On ending the play session;
* - After applying to the next battle.
* Intended for use with the Battle Processing command.
*
* ----------------------------------------------------------------------------
* Terms of use:
* MIT License: https://opensource.org/licenses/mit-license.html
*
* [[ BEGIN LICENSE TEXT ]]
*
* Copyright © 2023 Caethyril
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* [[ END LICENSE TEXT ]]
*/
// D12) setSurprise() and setPreemptive() fcts for next battle.
;void (() => {
'use strict';
/** Non-conflicting identifier for new "force surprise/preemptive" flag on `Game_Temp`. */
const SYM = Symbol();
/** @enum {number} enumerates flag values. */
const ENUM = Object.freeze({
DFAULT: 0,
PREEMPTIVE: 1,
SURPRISE: 2
});
/**
* Sets flag to `value`.
* @param {ENUM} [value] input value; omit to reset to default.
*/
const setFlag = function(value = ENUM.DFAULT) {
$gameTemp[SYM] = value;
};
/** @returns {ENUM} stored value. */
const getFlag = function() {
return $gameTemp[SYM] ?? ENUM.DFAULT;
};
/**
* Updates preemptive/surprise flags for upcoming battle.
* @returns {boolean} `true` iff a battle flag was set.
*/
const updateFlags = function() {
const f = getFlag();
setFlag();
switch (f) {
case ENUM.PREEMPTIVE:
return BattleManager._preemptive = true;
case ENUM.SURPRISE:
return BattleManager._surprise = true;
}
return false;
};
/** Forces next battle to be preemptive (favours party). */
globalThis.setPreemptive = function() {
setFlag(ENUM.PREEMPTIVE);
};
/** Forces next battle to be surprise (favours troop). */
globalThis.setSurprise = function() {
setFlag(ENUM.SURPRISE);
};
// Update surprise/preemptive flags after battle setup. Notes:
// - no script commands process between .setup() and .startBattle();
// - this feature's flag is stored on $gameTemp, which is not saved;
// - applies to all battles but is only designed for Battle Processing command;
// - random encounters still check ratePreemptive/rateSurprise as usual.
void (alias => {
BattleManager.setup = function(troopId, canEscape, canLose) {
alias.apply(this, arguments);
updateFlags();
};
})(BattleManager.setup);
})();