use of me.shadorc.shadbot.command.game.roulette.RouletteCmd.Place in project Shadbot by Shadorc.
the class RouletteManager method stop.
@Override
public void stop() {
this.cancelScheduledTask();
int winningPlace = ThreadLocalRandom.current().nextInt(1, 37);
List<String> list = new ArrayList<>();
for (IUser user : playersPlace.keySet()) {
int gains = playersPlace.get(user).getFirst();
String place = playersPlace.get(user).getSecond();
Place placeEnum = Utils.getValueOrNull(Place.class, place);
Map<Place, Boolean> testsMap = new HashMap<>();
testsMap.put(Place.RED, RED_NUMS.contains(winningPlace));
testsMap.put(Place.BLACK, !RED_NUMS.contains(winningPlace));
testsMap.put(Place.LOW, Utils.isInRange(winningPlace, 1, 19));
testsMap.put(Place.HIGH, Utils.isInRange(winningPlace, 19, 37));
testsMap.put(Place.EVEN, winningPlace % 2 == 0);
testsMap.put(Place.ODD, winningPlace % 2 != 0);
int multiplier = 0;
if (place.equals(Integer.toString(winningPlace))) {
multiplier = 36;
} else if (placeEnum != null && testsMap.get(placeEnum)) {
multiplier = 2;
} else {
multiplier = -1;
}
testsMap.clear();
gains *= multiplier;
if (gains > 0) {
list.add(0, String.format("**%s** (Gains: **%s**)", user.getName(), FormatUtils.formatCoins(gains)));
MoneyStatsManager.log(MoneyEnum.MONEY_GAINED, this.getCmdName(), gains);
} else {
list.add(String.format("**%s** (Losses: **%s**)", user.getName(), FormatUtils.formatCoins(Math.abs(gains))));
MoneyStatsManager.log(MoneyEnum.MONEY_LOST, this.getCmdName(), Math.abs(gains));
}
Database.getDBUser(this.getGuild(), user).addCoins(gains);
}
BotUtils.sendMessage(String.format(Emoji.DICE + " No more bets. *The wheel is spinning...* **%d (%s)** !", winningPlace, RED_NUMS.contains(winningPlace) ? "Red" : "Black"), this.getChannel()).get();
this.results = FormatUtils.format(list, Object::toString, ", ");
this.show();
playersPlace.clear();
RouletteCmd.MANAGERS.remove(this.getChannel().getLongID());
}
Aggregations