Skip to content

Instantly share code, notes, and snippets.

@jbzdarkid
Created January 7, 2019 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbzdarkid/440ef052bfed0c6b0145f1717cf4cb1f to your computer and use it in GitHub Desktop.
Save jbzdarkid/440ef052bfed0c6b0145f1717cf4cb1f to your computer and use it in GitHub Desktop.
Mardek Random Encounter
function TryRandomBattle() {
if (_root.noBattles || !IsPC() || actions.length > 0 || _root.freeze || _root.conv._visible || CheatVars.BATOG) {
return undefined;
}
tile = getTile(_parent._x, _parent._y);
var chance = Math.random() * (150 - risk);
if (chance <= _root.btlChance && _root.btlChance != 0 && GameData.steps >= 30 || _root.forceBattle) {
if (_root.forceBattle) {
_root.forceBattle = false;
}
GameData.steps = 0;
risk = 0;
_root.FOE_LEVELS = [];
_root.FOE_SEL = _root.foes[random(_root.foes.length)];
var partyLevel = 0;
var enemyLevel = 0;
var counts = {P:0, E:0};
for (var i=0; i<4; i++) {
if (_root.levelrange[0] == _root.levelrange[1]) {
_root.FOE_LEVELS[i] = _root.levelrange[1];
} else {
_root.FOE_LEVELS[i] = random(_root.levelrange[1] - _root.levelrange[0] + 1) + _root.levelrange[0]
}
if (_root.FOE_SEL[i] != null) {
counts.E++;
enemyLevel += _root.FOE_LEVELS[i];
}
if (_root.PCstats[i].level != null) {
counts.P++;
partyLevel += _root.PCstats[i].level;
}
}
AlertBalloon(int(partyLevel / counts.P > enemyLevel / counts.E + 2), true).onEnd = function() {
this._parent.DoBattle();
};
trace(partyLevel / counts.P + ">" + (enemyLevel / counts.E + 2));
} else {
risk++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment