Skip to content

Commit

Permalink
Add deaths statistic and leaderboard to Dodgeball
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Nov 14, 2024
1 parent 607e1d5 commit faae345
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.lovetropics.minigames.common.core.game.behavior.instances.action.GiveEffectAction;
import com.lovetropics.minigames.common.core.game.behavior.instances.action.GiveLootAction;
import com.lovetropics.minigames.common.core.game.behavior.instances.action.GiveRewardAction;
import com.lovetropics.minigames.common.core.game.behavior.instances.action.IncrementStatisticAction;
import com.lovetropics.minigames.common.core.game.behavior.instances.action.NotificationToastAction;
import com.lovetropics.minigames.common.core.game.behavior.instances.action.PlaySoundAction;
import com.lovetropics.minigames.common.core.game.behavior.instances.action.RemoveCollidersAction;
Expand Down Expand Up @@ -279,6 +280,7 @@ public class GameBehaviorTypes {
public static final GameBehaviorEntry<CancelPlayerAttacksBehavior> CANCEL_PLAYER_ATTACKS = register("cancel_player_attacks", CancelPlayerAttacksBehavior.CODEC);
public static final GameBehaviorEntry<AddCollidersAction> ADD_COLLIDERS = register("add_colliders", AddCollidersAction.CODEC);
public static final GameBehaviorEntry<RemoveCollidersAction> REMOVE_COLLIDERS = register("remove_colliders", RemoveCollidersAction.CODEC);
public static final GameBehaviorEntry<IncrementStatisticAction> INCREMENT_STATISTIC = register("increment_statistic", IncrementStatisticAction.CODEC);

public static final GameBehaviorEntry<SetupIntegrationsBehavior> SETUP_INTEGRATIONS = register("setup_integrations", SetupIntegrationsBehavior.CODEC);
public static final GameBehaviorEntry<AssignPlayerRolesBehavior> ASSIGN_PLAYER_ROLES = register("assign_player_roles", AssignPlayerRolesBehavior.CODEC);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.lovetropics.minigames.common.core.game.behavior.instances.action;

import com.lovetropics.minigames.common.core.game.IGamePhase;
import com.lovetropics.minigames.common.core.game.behavior.GameBehaviorType;
import com.lovetropics.minigames.common.core.game.behavior.GameBehaviorTypes;
import com.lovetropics.minigames.common.core.game.behavior.IGameBehavior;
import com.lovetropics.minigames.common.core.game.behavior.event.EventRegistrar;
import com.lovetropics.minigames.common.core.game.behavior.event.GameActionEvents;
import com.lovetropics.minigames.common.core.game.state.statistics.StatisticKey;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import java.util.function.Supplier;

public record IncrementStatisticAction(StatisticKey<Integer> statistic, int amount) implements IGameBehavior {
public static final MapCodec<IncrementStatisticAction> CODEC = RecordCodecBuilder.mapCodec(i -> i.group(
StatisticKey.typedCodec(Integer.class).fieldOf("statistic").forGetter(IncrementStatisticAction::statistic),
Codec.INT.optionalFieldOf("amount", 1).forGetter(IncrementStatisticAction::amount)
).apply(i, IncrementStatisticAction::new));

@Override
public void register(IGamePhase game, EventRegistrar events) {
events.listen(GameActionEvents.APPLY, context -> {
game.statistics().global().incrementInt(statistic, amount);
return true;
});
events.listen(GameActionEvents.APPLY_TO_PLAYER, (context, target) -> {
game.statistics().forPlayer(target).incrementInt(statistic, amount);
return true;
});
}

@Override
public Supplier<? extends GameBehaviorType<?>> behaviorType() {
return GameBehaviorTypes.INCREMENT_STATISTIC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static <T> Codec<StatisticKey<T>> typedCodec(final Class<T> type) {
public static final StatisticKey<Float> DAMAGE_TAKEN = ofFloat("damage_taken").displays(unit("damage"));
public static final StatisticKey<Float> DAMAGE_DEALT = ofFloat("damage_dealt").displays(unit("damage"));

public static final StatisticKey<Integer> DEATHS = ofInt("deaths").displays(unit("deaths"));
public static final StatisticKey<Boolean> DEAD = ofBool("dead");

// Generic - Global
Expand Down

0 comments on commit faae345

Please sign in to comment.