Skip to content

Commit c49e551

Browse files
committed
オフラインのプレイヤーのデータを変更できるように
1 parent 9eae49a commit c49e551

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/main/java/com/github/elic0de/thejpspit/util/KillRatingHelper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static java.lang.Math.round;
44

5+
import com.github.elic0de.thejpspit.player.OfflinePitPlayer;
56
import com.github.elic0de.thejpspit.player.PitPlayer;
67

78
public class KillRatingHelper {
@@ -18,6 +19,10 @@ public void initRating(PitPlayer player) {
1819
player.setRating(calculateKillingRatio(player));
1920
}
2021

22+
public void initRating(OfflinePitPlayer player) {
23+
player.setRating(calculateKillingRatio(player));
24+
}
25+
2126
private double calculateKillingRatio(PitPlayer player) {
2227
long deaths = player.getDeaths();
2328
long kills = player.getKills();
@@ -28,4 +33,15 @@ private double calculateKillingRatio(PitPlayer player) {
2833
return defaultRating;
2934
}
3035
}
36+
37+
private double calculateKillingRatio(OfflinePitPlayer player) {
38+
long deaths = player.getDeaths();
39+
long kills = player.getKills();
40+
long total = deaths + kills;
41+
if (deaths >= 0 && kills >= 0 && total > 0) {
42+
return round((double) kills / deaths * roundingFactor) / roundingFactor;
43+
} else {
44+
return defaultRating;
45+
}
46+
}
3147
}

0 commit comments

Comments
 (0)