Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Score Minimum Value #1046

Merged
merged 13 commits into from
Nov 4, 2022
Merged
11 changes: 8 additions & 3 deletions core/src/main/java/tc/oc/pgm/score/MercyRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ public class MercyRule {
private final ScoreMatchModule scoreMatchModule;
private final int scoreLimit;
private final int mercyLimit;
private final int mercyLimitMin;

private Map.Entry<Competitor, Double> leader;
private Map.Entry<Competitor, Double> trailer;

public MercyRule(ScoreMatchModule scoreMatchModule, int scoreLimit, int mercyLimit) {
public MercyRule(
ScoreMatchModule scoreMatchModule, int scoreLimit, int mercyLimit, int mercyLimitMin) {
this.scoreMatchModule = scoreMatchModule;
this.scoreLimit = scoreLimit;
this.mercyLimit = mercyLimit;
this.mercyLimitMin = mercyLimitMin;

calculateLeaders();
}
Expand Down Expand Up @@ -49,11 +52,13 @@ private boolean isTrailer(Competitor competitor) {
public int getScoreLimit() {
int scoreBaseline = (int) getTrailerScore();

int mercyBaseline = Math.max(scoreBaseline + mercyLimit, mercyLimitMin);

if (scoreLimit < 0) {
return scoreBaseline + mercyLimit;
return mercyBaseline;
}

return Math.min(scoreBaseline + mercyLimit, scoreLimit);
return Math.min(mercyBaseline, scoreLimit);
}

public void handleEvent(CompetitorScoreChangeEvent event) {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/tc/oc/pgm/score/ScoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class ScoreConfig {
public int deathScore;
public int killScore;
public int mercyLimit;
public int mercyLimitMin;
}
3 changes: 2 additions & 1 deletion core/src/main/java/tc/oc/pgm/score/ScoreMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public ScoreMatchModule(Match match, ScoreConfig config, Set<ScoreBox> scoreBoxe
this.match.getCompetitors().forEach(competitor -> this.scores.put(competitor, 0.0));

if (this.config.mercyLimit > 0) {
this.mercyRule = new MercyRule(this, config.scoreLimit, config.mercyLimit);
this.mercyRule =
new MercyRule(this, config.scoreLimit, config.mercyLimit, config.mercyLimitMin);
}
}

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/tc/oc/pgm/score/ScoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public ScoreModule parse(MapFactory factory, Logger logger, Document doc)
config.scoreLimit = XMLUtils.parseNumber(scoreEl.getChild("limit"), Integer.class, -1);
config.mercyLimit = XMLUtils.parseNumber(scoreEl.getChild("mercy"), Integer.class, -1);

Element mercyElement = XMLUtils.getUniqueChild(scoreEl, "mercy");
config.mercyLimitMin =
XMLUtils.parseNumber(Node.fromAttr(mercyElement, "min"), Integer.class, -1);

// For backwards compatibility, default kill/death points to 1 if proto is old and <king/>
// tag
// is not present
Expand Down