Skip to content

Commit

Permalink
(feat): Add game tracking finish data
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Dec 27, 2023
1 parent 9fbe39c commit 99f4a2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
implementation("dev.emortal.minestom:game-sdk:08edba4") {
exclude(group = "dev.emortal.api", module = "common-proto-sdk")
}
implementation("dev.emortal.api:common-proto-sdk:91d6f2e")
implementation("dev.emortal.api:common-proto-sdk:519634c")

implementation("dev.emortal:rayfast:e6ebf1f")
implementation("com.github.emortaldev:Particable:f7212f39fb")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.emortal.minestom.blocksumo.game;

import com.google.protobuf.Message;
import dev.emortal.api.model.gametracker.BlockSumoFinishData;
import dev.emortal.api.model.gametracker.BlockSumoScoreboard;
import dev.emortal.api.model.gametracker.BlockSumoUpdateData;
import dev.emortal.api.model.gametracker.CommonGameFinishWinnerData;
import dev.emortal.minestom.blocksumo.event.EventManager;
import dev.emortal.minestom.blocksumo.explosion.ExplosionManager;
import dev.emortal.minestom.blocksumo.map.LoadedMap;
Expand Down Expand Up @@ -44,6 +46,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;

Expand All @@ -65,6 +68,10 @@ public class BlockSumoGame extends Game {

private @Nullable Task countdownTask;

// end of game data used to pass to the game tracker
private Set<Player> winners;
private BlockSumoScoreboard endOfGameScoreboard;

public BlockSumoGame(@NotNull GameCreationInfo creationInfo, @NotNull LoadedMap map) {
super(creationInfo);
this.map = map;
Expand Down Expand Up @@ -186,6 +193,8 @@ public void cancelCountdown() {
public void victory(@NotNull Set<Player> winners) {
if (this.hasEnded()) return;
this.ended.set(true);
this.winners = winners;
this.endOfGameScoreboard = this.createScoreboard();

Sound victorySound = Sound.sound(SoundEvent.ENTITY_VILLAGER_CELEBRATE, Sound.Source.MASTER, 1f, 1f);
Sound victorySound2 = Sound.sound(SoundEvent.ENTITY_PLAYER_LEVELUP, Sound.Source.MASTER, 1f, 1f);
Expand Down Expand Up @@ -225,6 +234,18 @@ public void victory(@NotNull Set<Player> winners) {
);
}

@Override
public @NotNull List<? extends Message> createGameFinishExtraData() {
return List.of(
BlockSumoFinishData.newBuilder().setScoreboard(this.endOfGameScoreboard).build(),
CommonGameFinishWinnerData.newBuilder()
.addAllWinnerIds(this.winners.stream().map(Player::getUuid).map(UUID::toString).toList())
.addAllLoserIds(this.getPlayers().stream().filter(player -> !this.winners.contains(player))
.map(Player::getUuid).map(UUID::toString).toList())
.build()
);
}

private @NotNull BlockSumoScoreboard createScoreboard() {
List<BlockSumoScoreboard.Entry> entries = new ArrayList<>();
for (Player player : this.getPlayers()) {
Expand Down

0 comments on commit 99f4a2d

Please sign in to comment.