Skip to content

Commit

Permalink
Add totem activation effects
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Jun 21, 2024
1 parent f380b1c commit 37857cb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ public void spawn(ServerWorld world, BlockBounds spawn) {
this.player.sendMessage(Text.translatable("text.totemhunt.role_spawn", this.role.getName()), true);
}

public void changeRole(Role role) {
public void changeRole(Role role, boolean notify) {
this.role.unapply(this);
role.apply(this);

this.role = role;
this.player.sendMessage(Text.translatable("text.totemhunt.role_change", this.role.getName()), true);

if (notify) {
this.player.sendMessage(Text.translatable("text.totemhunt.role_change", this.role.getName()), true);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.github.haykam821.totemhunt.game.role.Roles;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.entity.EntityStatuses;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -152,8 +153,12 @@ private Text getWinMessage(ServerPlayerEntity hunter, ServerPlayerEntity holder)
return Text.translatable("text.totemhunt.totem_found", hunterName, holderName, time).formatted(Formatting.RED);
}

public void endGame(ServerPlayerEntity hunter, ServerPlayerEntity holder) {
this.gameSpace.getPlayers().sendMessage(this.getWinMessage(hunter, holder));
public void endGame(PlayerEntry hunter, PlayerEntry holder) {
holder.changeRole(Roles.PLAYER.getRole(), false);

this.gameSpace.getPlayers().sendMessage(this.getWinMessage(hunter.getPlayer(), holder.getPlayer()));
this.world.sendEntityStatus(holder.getPlayer(), EntityStatuses.USE_TOTEM_OF_UNDYING);

this.ticksUntilClose = this.config.getTicksUntilClose().get(this.world.getRandom());
}

Expand Down Expand Up @@ -208,10 +213,10 @@ private void reassignRequiredRoles() {
for (PlayerEntry entry : this.players) {
if (needsHunter) {
needsHunter = false;
entry.changeRole(Roles.HUNTER.getRole());
entry.changeRole(Roles.HUNTER.getRole(), true);
} else if (needsHolder) {
needsHolder = false;
entry.changeRole(Roles.HUNTER.getRole());
entry.changeRole(Roles.HUNTER.getRole(), true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onGiveTotem(TotemHuntActivePhase phase, PlayerEntry from, PlayerEntr
return;
}

from.getPhase().endGame(from.getPlayer(), to.getPlayer());
from.getPhase().endGame(from, to);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public abstract class Role {
public abstract Text getName();

public void onGiveTotem(TotemHuntActivePhase phase, PlayerEntry from, PlayerEntry to) {
from.changeRole(Roles.PLAYER.getRole());
to.changeRole(Roles.HOLDER.getRole());
from.changeRole(Roles.PLAYER.getRole(), true);
to.changeRole(Roles.HOLDER.getRole(), true);
}

public boolean canTransferTo(Role role) {
Expand Down

0 comments on commit 37857cb

Please sign in to comment.