Skip to content

Commit

Permalink
Add support for rewards in CookieClicker
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Feb 9, 2021
1 parent faf8413 commit f9aae36
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 3.2.0
- extend GameRuleMultiRewards to support CookieClicker rewards

## 3.1.2
- support MC 1.16.4

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>gamebox</artifactId>
<name>GameBox</name>
<packaging>jar</packaging>
<version>3.1.2</version>
<version>3.2.0</version>
<description>Collection of inventory games</description>
<url>https://gamebox.nikl.me</url>

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/me/nikl/gamebox/game/rules/GameRuleMultiRewards.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ public double getMoneyToWin(double score) {
return money;
}

public double currentScoreMoneyKey(double score) {
double moneyKey = saveType.isHigherScore() ? 0 : Double.MAX_VALUE;
List<Double> sortedScoreKeys = new ArrayList<>(moneyToWin.keySet());
Collections.sort(sortedScoreKeys);
for (double key : sortedScoreKeys) {
if (scoreIsBetterThen(key, score)) continue;
if (scoreIsBetterThen(moneyKey, score)) continue;
moneyKey = key;
}
return moneyKey;
}

public double currentScoreTokenKey(double score) {
double tokenKey = saveType.isHigherScore() ? 0 : Double.MAX_VALUE;
List<Double> sortedScoreKeys = new ArrayList<>(tokenToWin.keySet());
Collections.sort(sortedScoreKeys);
for (double key : sortedScoreKeys) {
if (scoreIsBetterThen(key, score)) continue;
if (scoreIsBetterThen(tokenKey, score)) continue;
tokenKey = key;
}
return tokenKey;
}

private boolean scoreIsBetterThen(double score, double compare) {
return ((saveType.isHigherScore() && compare < score)
|| (!saveType.isHigherScore() && compare > score));
Expand Down

0 comments on commit f9aae36

Please sign in to comment.