Skip to content

Commit

Permalink
feat(pied-piper): add powerless by accursed wolf-father when infected (
Browse files Browse the repository at this point in the history
…#711)

Closes #701
  • Loading branch information
antoinezanardi committed Dec 3, 2023
1 parent 7b284d9 commit 1d8a37f
Show file tree
Hide file tree
Showing 8 changed files with 28,141 additions and 28,098 deletions.
6 changes: 0 additions & 6 deletions src/modules/game/helpers/player/player.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import type { Game } from "@/modules/game/schemas/game.schema";
import type { Player } from "@/modules/game/schemas/player/player.schema";
import { RoleSides } from "@/modules/role/enums/role.enum";

function canPiedPiperCharm(piedPiperPlayer: Player, game: Game): boolean {
const { isPowerlessIfInfected } = game.options.roles.piedPiper;
return isPlayerAliveAndPowerful(piedPiperPlayer, game) && (!isPowerlessIfInfected || piedPiperPlayer.side.current === RoleSides.VILLAGERS);
}

function isPlayerPowerful(player: Player, game: Game): boolean {
return !doesPlayerHaveActiveAttributeWithName(player, PlayerAttributeNames.POWERLESS, game);
}
Expand All @@ -26,7 +21,6 @@ function isPlayerOnVillagersSide(player: Player): boolean {
}

export {
canPiedPiperCharm,
isPlayerPowerful,
isPlayerAliveAndPowerful,
isPlayerOnWerewolvesSide,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ export class GamePlayMakerService {

private accursedWolfFatherInfects(targetedPlayer: Player, game: GameWithCurrentPlay): Game {
let clonedGame = createGame(game);
const { roles } = game.options;
const playerDataToUpdate: Partial<Player> = { side: { ...targetedPlayer.side, current: RoleSides.WEREWOLVES } };
if (targetedPlayer.role.current === RoleNames.PREJUDICED_MANIPULATOR) {
if (targetedPlayer.role.current === RoleNames.PREJUDICED_MANIPULATOR ||
targetedPlayer.role.current === RoleNames.PIED_PIPER && roles.piedPiper.isPowerlessIfInfected) {
clonedGame = addPlayerAttributeInGame(targetedPlayer._id, clonedGame, createPowerlessByAccursedWolfFatherPlayerAttribute());
}
return updatePlayerInGame(targetedPlayer._id, playerDataToUpdate, clonedGame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createGamePlay, createGamePlaySurvivorsElectSheriff, createGamePlaySurv
import { areGamePlaysEqual, canSurvivorsVote, findPlayPriorityIndex } from "@/modules/game/helpers/game-play/game-play.helper";
import { createGame, createGameWithCurrentGamePlay } from "@/modules/game/helpers/game.factory";
import { getGroupOfPlayers, getLeftToEatByWerewolvesPlayers, getLeftToEatByWhiteWerewolfPlayers, getPlayerDtoWithRole, getPlayersWithActiveAttributeName, getPlayersWithCurrentRole, getPlayerWithActiveAttributeName, getPlayerWithCurrentRole, isGameSourceGroup, isGameSourceRole } from "@/modules/game/helpers/game.helper";
import { canPiedPiperCharm, isPlayerAliveAndPowerful, isPlayerPowerful } from "@/modules/game/helpers/player/player.helper";
import { isPlayerAliveAndPowerful, isPlayerPowerful } from "@/modules/game/helpers/player/player.helper";
import { GameHistoryRecordService } from "@/modules/game/providers/services/game-history/game-history-record.service";
import type { GameHistoryRecord } from "@/modules/game/schemas/game-history-record/game-history-record.schema";
import type { SheriffGameOptions } from "@/modules/game/schemas/game-options/roles-game-options/sheriff-game-options/sheriff-game-options.schema";
Expand Down Expand Up @@ -204,7 +204,7 @@ export class GamePlayService {
return !!getPlayerDtoWithRole(game, RoleNames.PIED_PIPER);
}
const piedPiperPlayer = getPlayerWithCurrentRole(game, RoleNames.PIED_PIPER);
return !!piedPiperPlayer && canPiedPiperCharm(piedPiperPlayer, game);
return !!piedPiperPlayer && isPlayerAliveAndPowerful(piedPiperPlayer, game);
}

private isBigBadWolfGamePlaySuitableForCurrentPhase(game: CreateGameDto | Game): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Feature: 🪈 Pied Piper role

When the accursed wolf-father infects the player named Antoine
Then the player named Antoine should be on werewolves current side and originally be on villagers side
And the player named Antoine should have the active powerless from accursed-wolf-father attribute
And the game's current play should be survivors to vote

When the survivors vote with the following votes
Expand Down Expand Up @@ -329,6 +330,7 @@ Feature: 🪈 Pied Piper role

When the accursed wolf-father infects the player named Antoine
Then the player named Antoine should be on werewolves current side and originally be on villagers side
And the player named Antoine should not have the active powerless from accursed-wolf-father attribute
And the game's current play should be pied-piper to charm
And the game's current play should be played by the following players
| name |
Expand Down

0 comments on commit 1d8a37f

Please sign in to comment.