Pre-emptive and Surprise Attacks with On-touch Encounters

Hey everyone,

  • I don't feel like Yanfly's Event Chase Players will matter much hence why I am posting here.
  • I wonder if I can guarantee the likelihood of a pre-emptive or ambush depending on the direction either the foe or the target are facing on touch.
  • Will I be able to use $gameParty.Agility in a conditional branch to increase/decrease the likelihood of an ambush?
No answer on that subject ? 🙁  is it possible to even do a 

Pre-emptive and Surprise Attack in RPG Maker MV ? 
I don't know about the third, but the first two should be done by a plugin I mentioned here.
Thanks for sharing that, Marsigne.

It would be nice to do just a script call that sets the switch, or values, for preemptive or surprise encounters to 100% or true.

I too was poking around in rpg_managers.js and rpg_objects.js

I found a good number of references to "surprise" when I searched. Unfortunately I couldn't make heads or tails of it. I'll post them below in a spoiler below. Maybe what I found is enough for someone with programming knowledge to post a snippet that can be used with Script or Plugin Command.

What I found from rpg_managers.js (Note: I am not pasting the whole script... just open up your copy if you need the full thing. It's in the js folder)

Spoiler
function BattleManager() {

    throw new Error('This is a static class');

}

BattleManager.setup = function(troopId, canEscape, canLose) {

    this.initMembers();

    this._canEscape = canEscape;

    this._canLose = canLose;

    $gameTroop.setup(troopId);

    $gameScreen.onBattleStart();

    this.makeEscapeRatio();

};

BattleManager.initMembers = function() {

    this._phase = 'init';

    this._canEscape = false;

    this._canLose = false;

    this._battleTest = false;

    this._eventCallback = null;

    this._preemptive = false;

    this._surprise = false;

    this._actorIndex = -1;

    this._actionForcedBattler = null;

    this._mapBgm = null;

    this._mapBgs = null;

    this._actionBattlers = [];

    this._subject = null;

    this._action = null;

    this._targets = [];

    this._logWindow = null;

    this._statusWindow = null;

    this._spriteset = null;

    this._escapeRatio = 0;

    this._escaped = false;

    this._rewards = {};

};

BattleManager.onEncounter = function() {

    this._preemptive = (Math.random() < this.ratePreemptive());

    this._surprise = (Math.random() < this.rateSurprise() && !this._preemptive);

};

BattleManager.ratePreemptive = function() {

    return $gameParty.ratePreemptive($gameTroop.agility());

};

BattleManager.rateSurprise = function() {

    return $gameParty.rateSurprise($gameTroop.agility());

};

BattleManager.displayStartMessages = function() {

    $gameTroop.enemyNames().forEach(function(name) {

        $gameMessage.add(TextManager.emerge.format(name));

    });

    if (this._preemptive) {

        $gameMessage.add(TextManager.preemptive.format($gameParty.name()));

    } else if (this._surprise) {

        $gameMessage.add(TextManager.surprise.format($gameParty.name()));

    }

[SIZE=11pt]};[/SIZE]

BattleManager.startInput = function() {

    this._phase = 'input';

    $gameParty.makeActions();

    $gameTroop.makeActions();

    this.clearActor();

    if (this._surprise || !$gameParty.canInput()) {

        this.startTurn();

    }

[SIZE=11pt]};[/SIZE]

BattleManager.endTurn = function() {

    this._phase = 'turnEnd';

    this._preemptive = false;

    this._surprise = false;

    this.allBattleMembers().forEach(function(battler) {

        battler.onTurnEnd();

        this.refreshStatus();

        this._logWindow.displayAutoAffectedStatus(battler);

        this._logWindow.displayRegeneration(battler);

    }, this);

[SIZE=11pt]};[/SIZE]

What I found from rpg_objects.js (Note: I am not pasting the whole script... just open up your copy if you need the full thing. It's in the js folder)

Spoiler
function Game_Party() {

    this.initialize.apply(this, arguments);

}

Game_Party.prototype = Object.create(Game_Unit.prototype);

Game_Party.prototype.constructor = Game_Party;

Game_Party.ABILITY_ENCOUNTER_HALF    = 0;

Game_Party.ABILITY_ENCOUNTER_NONE    = 1;

Game_Party.ABILITY_CANCEL_SURPRISE   = 2;

Game_Party.ABILITY_RAISE_PREEMPTIVE  = 3;

Game_Party.ABILITY_GOLD_DOUBLE       = 4;

Game_Party.ABILITY_DROP_ITEM_DOUBLE  = 5;

Game_Party.prototype.initialize = function() {

    Game_Unit.prototype.initialize.call(this);

    this._gold = 0;

    this._steps = 0;

    this._lastItem = new Game_Item();

    this._menuActorId = 0;

    this._targetActorId = 0;

    this._actors = [];

    this.initAllItems();

};

Game_Party.prototype.hasCancelSurprise = function() {

    return this.partyAbility(Game_Party.ABILITY_CANCEL_SURPRISE);

};

Game_Party.prototype.hasRaisePreemptive = function() {

    return this.partyAbility(Game_Party.ABILITY_RAISE_PREEMPTIVE);

[SIZE=11pt]};[/SIZE]

Game_Party.prototype.ratePreemptive = function(troopAgi) {

    var rate = this.agility() >= troopAgi ? 0.05 : 0.03;

    if (this.hasRaisePreemptive()) {

        rate *= 4;

    }

    return rate;

};

Game_Party.prototype.rateSurprise = function(troopAgi) {

    var rate = this.agility() >= troopAgi ? 0.03 : 0.05;

    if (this.hasCancelSurprise()) {

        rate = 0;

    }

    return rate;

[SIZE=11pt]};[/SIZE]

 

 

I really don't understand/know programming. So, sorry in advance if I left anything out of those copy/pastes.
Bumping this to see if anyone has any suggestions.

Original thread: https://forums.rpgmakerweb.com/threads/pre-emptive-and-surprise-attacks-with-on-touch-encounters.50908/