Skip to content

Commit

Permalink
Take current HP into consideration when deciding to Flee
Browse files Browse the repository at this point in the history
  • Loading branch information
tukkek committed Sep 21, 2017
1 parent 90da075 commit 6be7694
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
20 changes: 18 additions & 2 deletions javelin/controller/action/ai/Flee.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Combatant> 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<List<ChanceNode>> getoutcomes(Combatant active, BattleState s) {
ArrayList<List<ChanceNode>> outcomes = new ArrayList<List<ChanceNode>>();
Expand Down
13 changes: 8 additions & 5 deletions javelin/controller/challenge/CrCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,12 @@ static int calculateel(final List<Combatant> 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);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6be7694

Please sign in to comment.