Skip to content

Commit

Permalink
Global Statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
ellieisjelly committed Jan 31, 2024
1 parent f0b0f2c commit 964c922
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.ellieis.Sabotage.Sabotage;
import me.ellieis.Sabotage.game.GameStates;
import me.ellieis.Sabotage.game.phase.SabotageActive;
import me.ellieis.Sabotage.game.statistics.GlobalPlayerStatistics;
import me.ellieis.Sabotage.game.statistics.SabotagePlayerStatistics;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
Expand All @@ -27,9 +28,8 @@
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import static me.ellieis.Sabotage.Sabotage.MOD_ID;
import static me.ellieis.Sabotage.game.custom.SabotageBlocks.SABOTAGE_CHEST_ENTITY;
import static java.util.Map.entry;
import static me.ellieis.Sabotage.game.custom.SabotageBlocks.SABOTAGE_CHEST_ENTITY;

public class SabotageChest extends ChestBlock implements BlockEntityProvider, PolymerBlock {
private final Block virtualBlock;
Expand Down Expand Up @@ -108,7 +108,8 @@ public ActionResult onUse(BlockState state, World woorld, BlockPos pos, PlayerEn
// couldn't insert stack, inventory is likely full
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), item));
}
game.gameSpace.getStatistics().bundle(MOD_ID).forPlayer((ServerPlayerEntity) plr).increment(SabotagePlayerStatistics.CHESTS_OPENED, 1);
game.stats.forPlayer((ServerPlayerEntity) plr).increment(SabotagePlayerStatistics.CHESTS_OPENED, 1);
game.stats.global().increment(GlobalPlayerStatistics.TOTAL_CHESTS_OPENED, 1);
world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
return ActionResult.FAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import xyz.nucleoid.plasmid.game.player.PlayerOfferResult;
import xyz.nucleoid.plasmid.game.player.PlayerSet;
import xyz.nucleoid.plasmid.game.rule.GameRuleType;
import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle;
import xyz.nucleoid.plasmid.util.PlayerRef;
import xyz.nucleoid.stimuli.event.block.BlockRandomTickEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;
Expand All @@ -61,6 +62,7 @@
import java.util.*;
import java.util.function.Consumer;

import static me.ellieis.Sabotage.Sabotage.MOD_ID;
import static me.ellieis.Sabotage.game.custom.SabotageItems.DETECTIVE_SHEARS;

public class SabotageActive {
Expand All @@ -76,6 +78,7 @@ public class SabotageActive {
// used in the game end message to list all saboteurs
private PlayerSet initialSaboteurs;
private final Map<ServerPlayerEntity, Team> playersOldTeams = new HashMap<>();
public final GameStatisticBundle stats;
private final KarmaManager karmaManager;
private final TaskScheduler taskScheduler;
private boolean isTesterOnCooldown = false;
Expand All @@ -99,7 +102,8 @@ public SabotageActive(SabotageConfig config, GameSpace gameSpace, SabotageMap ma
this.detectives = new MutablePlayerSet(gameSpace.getServer());
this.innocents = new MutablePlayerSet(gameSpace.getServer());
this.dead = new MutablePlayerSet(gameSpace.getServer());
this.karmaManager = new KarmaManager(gameSpace);
this.stats = gameSpace.getStatistics().bundle(MOD_ID);
this.karmaManager = new KarmaManager(stats);
this.taskScheduler = new TaskScheduler(gameSpace, world);
Sabotage.activeGames.add(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.ellieis.Sabotage.game.statistics;

import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.stats.StatisticKey;

import static me.ellieis.Sabotage.Sabotage.MOD_ID;

public class GlobalPlayerStatistics {
public static final StatisticKey<Integer> TOTAL_KARMA = StatisticKey.intKey(new Identifier(MOD_ID, "total_karma"));
public static final StatisticKey<Integer> TOTAL_CHESTS_OPENED = StatisticKey.intKey(new Identifier(MOD_ID, "total_chests_opened"));
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package me.ellieis.Sabotage.game.statistics;

import net.minecraft.server.network.ServerPlayerEntity;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle;

import static me.ellieis.Sabotage.Sabotage.MOD_ID;
import static me.ellieis.Sabotage.game.statistics.GlobalPlayerStatistics.TOTAL_KARMA;
import static me.ellieis.Sabotage.game.statistics.SabotagePlayerStatistics.KARMA;

public class KarmaManager {
private final GameStatisticBundle stats;
public KarmaManager(GameSpace gameSpace) {
stats = gameSpace.getStatistics().bundle(MOD_ID);
public KarmaManager(GameStatisticBundle stats) {
this.stats = stats;
}
public int getKarma(ServerPlayerEntity plr) {
return stats.forPlayer(plr).get(KARMA, 20);
Expand All @@ -24,6 +23,7 @@ public void setKarma(ServerPlayerEntity plr, int karma) {
}
public void incrementKarma(ServerPlayerEntity plr, int karma) {
setKarma(plr, getKarma(plr) + karma);
stats.global().increment(TOTAL_KARMA, karma);
}
public void decrementKarma(ServerPlayerEntity plr, int karma) {
setKarma(plr, getKarma(plr) - karma);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/data/sabotage/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"map.sabotage.skybound": "Skybound",

"statistic.bundle.sabotage": "Sabotage",
"statistic.sabotage.total_chests_opened": "Total Chests Opened",
"statistic.sabotage.total_karma": "Total Karma",
"statistic.sabotage.chests_opened": "Chests Opened",
"statistic.sabotage.karma": "Karma",

Expand Down

0 comments on commit 964c922

Please sign in to comment.