Skip to content

Commit

Permalink
fix: use long for user's coins
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Sep 28, 2024
1 parent 04a3480 commit 07576b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.jetbrains.annotations.NotNull;
import pink.zak.minestom.towerdefence.model.user.GameUser;

public record PlayerCoinChangeEvent(@NotNull GameUser user, int coins) implements Event {
public record PlayerCoinChangeEvent(@NotNull GameUser user, long coins) implements Event {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@

import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

public final class GameUser {
public static final int DEFAULT_COINS = 2_000;
public static final int DEFAULT_COINS = 2_000_000_000;
public static final int DEFAULT_INCOME_RATE = 50;

private final @NotNull TDPlayer player; // todo in the future we should allow re-joining a game so this will not be final.
private final @NotNull Team team;
private final @NotNull MobQueue queue;
private final @NotNull UpgradeHandler upgradeHandler;

private final @NotNull AtomicInteger coins = new AtomicInteger(DEFAULT_COINS);
private final @NotNull AtomicLong coins = new AtomicLong(DEFAULT_COINS);

// incomeRate is the amount of coins the player gets per 10 seconds.
private final @NotNull AtomicInteger incomeRate = new AtomicInteger(DEFAULT_INCOME_RATE);
Expand All @@ -44,16 +46,16 @@ public GameUser(@NotNull TDPlayer player, @NotNull Set<EnemyMob> defaultUnlocks,
return this.team;
}

public int getCoins() {
public long getCoins() {
return this.coins.get();
}

public @NotNull UpgradeHandler getUpgradeHandler() {
return this.upgradeHandler;
}

public int updateCoins(@NotNull IntUnaryOperator intOperator) {
int newCoins = this.coins.updateAndGet(intOperator);
public long updateCoins(@NotNull LongUnaryOperator intOperator) {
long newCoins = this.coins.updateAndGet(intOperator);
MinecraftServer.getGlobalEventHandler().call(new PlayerCoinChangeEvent(this, newCoins));
return newCoins;
}
Expand Down

0 comments on commit 07576b4

Please sign in to comment.