Created
January 7, 2019 02:59
-
-
Save jbzdarkid/440ef052bfed0c6b0145f1717cf4cb1f to your computer and use it in GitHub Desktop.
Mardek Random Encounter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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