diff --git a/javelin/controller/action/ai/Flee.java b/javelin/controller/action/ai/Flee.java index 60265f948..cd88380e6 100644 --- a/javelin/controller/action/ai/Flee.java +++ b/javelin/controller/action/ai/Flee.java @@ -50,11 +50,27 @@ public static boolean flee(Combatant active, BattleState s) { if (!ALLOWFLEE || !Javelin.app.fight.canflee || s.isengaged(active)) { return false; } - final int eldifference = CrCalculator.calculateel( - s.redTeam) - CrCalculator.calculateel(s.blueTeam); + if (s.blueTeam.isEmpty() || s.redTeam.isEmpty()) { + return false; + } + final int eldifference = calculateel(s.redTeam) + - calculateel(s.blueTeam); return eldifference <= FLEEAT && s.redTeam.contains(s.next); } + private static int calculateel(ArrayList team) { + float totalcr = 0; + float highestcr = -Integer.MAX_VALUE; + for (Combatant c : team) { + Float cr = c.source.challengerating * c.hp / c.maxhp; + totalcr += cr; + if (cr > highestcr) { + highestcr = cr; + } + } + return CrCalculator.calculatel(totalcr, highestcr, team.size()); + } + @Override public List> getoutcomes(Combatant active, BattleState s) { ArrayList> outcomes = new ArrayList>(); diff --git a/javelin/controller/challenge/CrCalculator.java b/javelin/controller/challenge/CrCalculator.java index c287f59cd..cdfffd686 100644 --- a/javelin/controller/challenge/CrCalculator.java +++ b/javelin/controller/challenge/CrCalculator.java @@ -234,9 +234,12 @@ static int calculateel(final List group, final boolean check) } } } - final int groupCr = crtoel(sum) - + multipleOpponentsElModifier(group.size()); - final int highestCrEl = crtoel(highestCr); + return calculatel(sum, highestCr, group.size()); + } + + public static int calculatel(float totalcr, float highestcr, int size) { + final int groupCr = crtoel(totalcr) + multipleOpponentsElModifier(size); + final int highestCrEl = crtoel(highestcr); return Math.max(highestCrEl, groupCr); } @@ -774,8 +777,8 @@ public static float ratespelllikeability(int spelllevel) { } /** - * Same as {@link CrCalculator#ratespelllikeability(int)} but - * to be used in case a touch spell is being used as a ray spell instead. + * Same as {@link CrCalculator#ratespelllikeability(int)} but to be used in + * case a touch spell is being used as a ray spell instead. */ public static float ratetouchspellconvertedtoray(int spelllevel) { return .4f * spelllevel;