Skip to content

Commit

Permalink
test(acceptance): acceptance tests for vile father of wolves (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Sep 28, 2023
1 parent f1d8bdc commit f8e9520
Show file tree
Hide file tree
Showing 7 changed files with 17,312 additions and 17,113 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sample } from "lodash";

import type { MakeGamePlayWithRelationsDto } from "@/modules/game/dto/make-game-play/make-game-play-with-relations.dto";
import { GamePlayActions, GamePlayCauses, WitchPotions } from "@/modules/game/enums/game-play.enum";
import { PlayerAttributeNames, PlayerDeathCauses, PlayerGroups } from "@/modules/game/enums/player.enum";
import { PlayerAttributeNames, PlayerGroups } from "@/modules/game/enums/player.enum";
import { createGamePlaySurvivorsVote, createGamePlaySheriffSettlesVotes, createGamePlaySurvivorsElectSheriff } from "@/modules/game/helpers/game-play/game-play.factory";
import { createGame } from "@/modules/game/helpers/game.factory";
import { getFoxSniffedPlayers, getPlayerWithActiveAttributeName, getPlayerWithCurrentRole } from "@/modules/game/helpers/game.helper";
Expand Down Expand Up @@ -351,8 +351,8 @@ export class GamePlayMakerService {
}
const { player: targetedPlayer, isInfected: isTargetInfected } = targets[0];
const eatenByWerewolvesPlayerAttribute = createEatenByWerewolvesPlayerAttribute();
const isAncientKillable = await this.playerKillerService.isAncientKillable(clonedGame, targetedPlayer, PlayerDeathCauses.EATEN);
if (isTargetInfected === true && (targetedPlayer.role.current !== RoleNames.ANCIENT || isAncientKillable)) {
const ancientLivesCount = await this.playerKillerService.getAncientLivesCountAgainstWerewolves(clonedGame, targetedPlayer);
if (isTargetInfected === true && (targetedPlayer.role.current !== RoleNames.ANCIENT || ancientLivesCount <= 1)) {
const playerDataToUpdate: Partial<Player> = { side: { ...targetedPlayer.side, current: RoleSides.WEREWOLVES } };
return updatePlayerInGame(targetedPlayer._id, playerDataToUpdate, clonedGame);
}
Expand Down
30 changes: 15 additions & 15 deletions src/modules/game/providers/services/player/player-killer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ export class PlayerKillerService {
return ancientLivesCountAgainstWerewolves <= 0;
}

public async getAncientLivesCountAgainstWerewolves(game: Game, ancientPlayer: Player): Promise<number> {
const { livesCountAgainstWerewolves } = game.options.roles.ancient;
const werewolvesEatAncientRecords = await this.gameHistoryRecordService.getGameHistoryWerewolvesEatAncientRecords(game._id);
const werewolvesEatAncientOnPreviousTurnsRecords = werewolvesEatAncientRecords.filter(({ turn }) => turn < game.turn);
const ancientProtectedFromWerewolvesRecords = await this.gameHistoryRecordService.getGameHistoryAncientProtectedFromWerewolvesRecords(game._id);
const doesAncientLooseALifeOnCurrentTurn = doesPlayerHaveActiveAttributeWithName(ancientPlayer, PlayerAttributeNames.EATEN, game) && this.canPlayerBeEaten(ancientPlayer, game);
return werewolvesEatAncientOnPreviousTurnsRecords.reduce((acc, werewolvesEatAncientRecord) => {
const wasAncientProtectedFromWerewolves = !!ancientProtectedFromWerewolvesRecords.find(({ turn }) => turn === werewolvesEatAncientRecord.turn);
if (!wasAncientProtectedFromWerewolves) {
return acc - 1;
}
return acc;
}, doesAncientLooseALifeOnCurrentTurn ? livesCountAgainstWerewolves - 1 : livesCountAgainstWerewolves);
}

private applyPlayerRoleRevelationOutcomes(revealedPlayer: Player, game: Game): Game {
const clonedGame = createGame(game);
if (revealedPlayer.role.current === RoleNames.IDIOT) {
Expand Down Expand Up @@ -75,21 +90,6 @@ export class PlayerKillerService {
return clonedPlayer;
}

private async getAncientLivesCountAgainstWerewolves(game: Game, ancientPlayer: Player): Promise<number> {
const { livesCountAgainstWerewolves } = game.options.roles.ancient;
const werewolvesEatAncientRecords = await this.gameHistoryRecordService.getGameHistoryWerewolvesEatAncientRecords(game._id);
const werewolvesEatAncientOnPreviousTurnsRecords = werewolvesEatAncientRecords.filter(({ turn }) => turn < game.turn);
const ancientProtectedFromWerewolvesRecords = await this.gameHistoryRecordService.getGameHistoryAncientProtectedFromWerewolvesRecords(game._id);
const doesAncientLooseALifeOnCurrentTurn = doesPlayerHaveActiveAttributeWithName(ancientPlayer, PlayerAttributeNames.EATEN, game) && this.canPlayerBeEaten(ancientPlayer, game);
return werewolvesEatAncientOnPreviousTurnsRecords.reduce((acc, werewolvesEatAncientRecord) => {
const wasAncientProtectedFromWerewolves = !!ancientProtectedFromWerewolvesRecords.find(({ turn }) => turn === werewolvesEatAncientRecord.turn);
if (!wasAncientProtectedFromWerewolves) {
return acc - 1;
}
return acc;
}, doesAncientLooseALifeOnCurrentTurn ? livesCountAgainstWerewolves - 1 : livesCountAgainstWerewolves);
}

private isIdiotKillable(idiotPlayer: Player, cause: PlayerDeathCauses, game: Game): boolean {
const isIdiotPowerless = !isPlayerPowerful(idiotPlayer, game);
return idiotPlayer.role.isRevealed || cause !== PlayerDeathCauses.VOTE || isIdiotPowerless;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@vile-father-of-wolves-role

Feature: 🐺 Vile Father of Wolves role

Scenario: 🐺 Vile Father of Wolves infects a player instead of eating it
Given a created game with options described in files no-sheriff-option.json and with the following players
| name | role |
| Antoine | vile-father-of-wolves |
| Olivia | seer |
| JB | villager |
| Thomas | villager |
Then the game's current play should be seer to look

When the seer looks at the player named Antoine
Then the game's current play should be werewolves to eat

When the vile father of wolves infects the player named Olivia
Then the player named Olivia should be on werewolves current side and originally be on villagers side
And the player named Olivia should be alive
And the game's current play should be survivors to vote

When the player or group skips his turn
Then the game's current play should be seer to look

Scenario: 🐺 Vile Father of Wolves doesn't infect the ancient if he still have lives
Given a created game with options described in files no-sheriff-option.json and with the following players
| name | role |
| Antoine | vile-father-of-wolves |
| Olivia | ancient |
| JB | villager |
| Thomas | villager |
Then the game's current play should be werewolves to eat

When the vile father of wolves infects the player named Olivia
Then the player named Olivia should be on villagers current side and originally be on villagers side
And the player named Olivia should be alive

Scenario: 🐺 Vile Father of Wolves infects the ancient if he only has one life left
Given a created game with options described in files no-sheriff-option.json, ancient-one-life-against-werewolves-option.json and with the following players
| name | role |
| Antoine | vile-father-of-wolves |
| Olivia | ancient |
| JB | villager |
| Thomas | villager |
Then the game's current play should be werewolves to eat

When the vile father of wolves infects the player named Olivia
Then the player named Olivia should be on werewolves current side and originally be on villagers side
And the player named Olivia should be alive

0 comments on commit f8e9520

Please sign in to comment.