Skip to content

Commit

Permalink
refactor(defender): rename guard to defender according to official ru…
Browse files Browse the repository at this point in the history
…lebook (#693)

Closes #681
  • Loading branch information
antoinezanardi committed Nov 29, 2023
1 parent 9ee3d99 commit 244e260
Show file tree
Hide file tree
Showing 58 changed files with 27,816 additions and 27,819 deletions.
4 changes: 2 additions & 2 deletions .run/Guard Role.run.xml → .run/Defender Role.run.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Guard Role" type="js.build_tools.npm" folderName="Cucumber Tags">
<configuration default="false" name="Defender Role" type="js.build_tools.npm" folderName="Cucumber Tags">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@guard-role&quot;" />
<arguments value="-- --tags &quot;@defender-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ This is the **next** version of the current **[Werewolves Assistant API](https:/
| <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/werewolf/werewolf-small.jpeg?raw=true" width="40"/><br/>**Werewolf** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/big-bad-wolf/big-bad-wolf-small.jpeg?raw=true" width="40"/><br/>**Big Bad Wolf** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/vile-father-of-wolves/vile-father-of-wolves-small.jpeg?raw=true" width="40"/><br/>**Vile Father Of Wolves** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/white-werewolf/white-werewolf-small.jpeg?raw=true" width="40"/><br/>**White Werewolf** |
|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/villager/villager-small.jpeg?raw=true" width="40"/><br/>**Villager** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/villager/villager-small.jpeg?raw=true" width="40"/><br/> **Villager-Villager** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/seer/seer-small.jpeg?raw=true" width="40"/><br/>**Seer** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/cupid/cupid-small.jpeg?raw=true" width="40"/><br/>**Cupid** |
| <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/witch/witch-small.jpeg?raw=true" width="40"/><br/>**Witch** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/hunter/hunter-small.jpeg?raw=true" width="40"/><br/>**Hunter** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/little-girl/little-girl-small.jpeg?raw=true" width="40"/><br/>**Little Girl** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/guard/guard-small.jpeg?raw=true" width="40"/><br/>**Guard** |
| <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/witch/witch-small.jpeg?raw=true" width="40"/><br/>**Witch** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/hunter/hunter-small.jpeg?raw=true" width="40"/><br/>**Hunter** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/little-girl/little-girl-small.jpeg?raw=true" width="40"/><br/>**Little Girl** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/defender/defender-small.jpeg?raw=true" width="40"/><br/>**Defender** |
| <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/elder/elder-small.jpeg?raw=true" width="40"/><br/>**Elder** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/scapegoat/scapegoat-small.jpeg?raw=true" width="40"/><br/>**Scapegoat** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/idiot/idiot-small.jpeg?raw=true" width="40"/><br/>**Idiot** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/two-sisters/two-sisters-small.jpeg?raw=true" width="40"/><br/>**Two Sisters** |
| <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/three-brothers/three-brothers-small.jpeg?raw=true" width="40"/><br/>**Three Brothers** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/fox/fox-small.jpeg?raw=true" width="40"/><br/>**Fox** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/bear-tamer/bear-tamer-small.jpeg?raw=true" width="40"/><br/>**Bear Tamer** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/stuttering-judge/stuttering-judge-small.jpeg?raw=true" width="40"/><br/>**Stuttering Judge** |
| <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/rusty-sword-knight/rusty-sword-knight-small.jpeg?raw=true" width="40"/><br/>**Rusty Sword Knight** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/wild-child/wild-child-small.jpeg?raw=true" width="40"/><br/>**Wild Child** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/dog-wolf/dog-wolf-small.jpeg?raw=true" width="40"/><br/>**Dog-Wolf** | <img src="https://github.com/antoinezanardi/werewolves-assistant-api-next/blob/main/public/assets/images/roles/thief/thief-small.jpeg?raw=true" width="40"/><br/>**Thief** |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const DEFAULT_GAME_OPTIONS: ReadonlyDeep<GameOptions> = {
isTalkative: true,
canSeeRoles: true,
},
littleGirl: { isProtectedByGuard: false },
guard: { canProtectTwice: false },
littleGirl: { isProtectedByDefender: false },
defender: { canProtectTwice: false },
elder: {
livesCountAgainstWerewolves: 2,
doesTakeHisRevenge: true,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/game/constants/game-play/game-play.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const GAME_PLAY_SOURCE_NAMES = [
RoleNames.CUPID,
RoleNames.DOG_WOLF,
RoleNames.FOX,
RoleNames.GUARD,
RoleNames.DEFENDER,
RoleNames.HUNTER,
RoleNames.PIED_PIPER,
RoleNames.RAVEN,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/game/constants/game.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const GAME_PLAYS_PRIORITY_LIST: ReadonlyDeep<GamePlay[]> = [
occurrence: GamePlayOccurrences.ON_NIGHTS,
},
{
source: { name: RoleNames.GUARD },
source: { name: RoleNames.DEFENDER },
action: GamePlayActions.PROTECT,
occurrence: GamePlayOccurrences.ON_NIGHTS,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { ApiProperty } from "@nestjs/swagger";
import { IsBoolean, IsOptional } from "class-validator";

import { DEFENDER_GAME_OPTIONS_API_PROPERTIES, DEFENDER_GAME_OPTIONS_FIELDS_SPECS } from "@/modules/game/schemas/game-options/roles-game-options/defender-game-options/defender-game-options.schema.constant";

class CreateDefenderGameOptionsDto {
@ApiProperty({
...DEFENDER_GAME_OPTIONS_API_PROPERTIES.canProtectTwice,
required: false,
} as ApiPropertyOptions)
@IsOptional()
@IsBoolean()
public canProtectTwice: boolean = DEFENDER_GAME_OPTIONS_FIELDS_SPECS.canProtectTwice.default;
}

export { CreateDefenderGameOptionsDto };

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { LITTLE_GIRL_GAME_OPTIONS_API_PROPERTIES, LITTLE_GIRL_GAME_OPTIONS_SPECS

class CreateLittleGirlGameOptionsDto {
@ApiProperty({
...LITTLE_GIRL_GAME_OPTIONS_API_PROPERTIES.isProtectedByGuard,
...LITTLE_GIRL_GAME_OPTIONS_API_PROPERTIES.isProtectedByDefender,
required: false,
} as ApiPropertyOptions)
@IsOptional()
@IsBoolean()
public isProtectedByGuard: boolean = LITTLE_GIRL_GAME_OPTIONS_SPECS_FIELDS.isProtectedByGuard.default;
public isProtectedByDefender: boolean = LITTLE_GIRL_GAME_OPTIONS_SPECS_FIELDS.isProtectedByDefender.default;
}

export { CreateLittleGirlGameOptionsDto };
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CreateBearTamerGameOptionsDto } from "@/modules/game/dto/create-game/cr
import { CreateBigBadWolfGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-big-bad-wolf-game-options.dto";
import { CreateDogWolfGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-dog-wolf-game-options.dto";
import { CreateFoxGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-fox-game-options.dto";
import { CreateGuardGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-guard-game-options.dto";
import { CreateDefenderGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-defender-game-options.dto";
import { CreateIdiotGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-idiot-game-options.dto";
import { CreateLittleGirlGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-little-girl-game-options.dto";
import { CreatePiedPiperGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-pied-piper-game-options.dto";
Expand Down Expand Up @@ -87,13 +87,13 @@ class CreateRolesGameOptionsDto {
public littleGirl: CreateLittleGirlGameOptionsDto = new CreateLittleGirlGameOptionsDto();

@ApiProperty({
...ROLES_GAME_OPTIONS_API_PROPERTIES.guard,
...ROLES_GAME_OPTIONS_API_PROPERTIES.defender,
required: false,
} as ApiPropertyOptions)
@IsOptional()
@Type(() => CreateGuardGameOptionsDto)
@Type(() => CreateDefenderGameOptionsDto)
@ValidateNested()
public guard: CreateGuardGameOptionsDto = new CreateGuardGameOptionsDto();
public defender: CreateDefenderGameOptionsDto = new CreateDefenderGameOptionsDto();

@ApiProperty({
...ROLES_GAME_OPTIONS_API_PROPERTIES.elder,
Expand Down
6 changes: 3 additions & 3 deletions src/modules/game/helpers/game-play/game-play.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ function createGamePlayRavenMarks(gamePlay: Partial<GamePlay> = {}): GamePlay {
});
}

function createGamePlayGuardProtects(gamePlay: Partial<GamePlay> = {}): GamePlay {
function createGamePlayDefenderProtects(gamePlay: Partial<GamePlay> = {}): GamePlay {
return createGamePlay({
source: createGamePlaySource({ name: RoleNames.GUARD }),
source: createGamePlaySource({ name: RoleNames.DEFENDER }),
action: GamePlayActions.PROTECT,
occurrence: GamePlayOccurrences.ON_NIGHTS,
...gamePlay,
Expand Down Expand Up @@ -264,7 +264,7 @@ export {
createGamePlayThreeBrothersMeetEachOther,
createGamePlayTwoSistersMeetEachOther,
createGamePlayRavenMarks,
createGamePlayGuardProtects,
createGamePlayDefenderProtects,
createGamePlayHunterShoots,
createGamePlayWitchUsesPotions,
createGamePlayPiedPiperCharms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ function createRavenMarkByRavenPlayerAttribute(playerAttribute: Partial<PlayerAt
});
}

function createProtectedByGuardPlayerAttribute(playerAttribute: Partial<PlayerAttribute> = {}): PlayerAttribute {
function createProtectedByDefenderPlayerAttribute(playerAttribute: Partial<PlayerAttribute> = {}): PlayerAttribute {
return createPlayerAttribute({
name: PlayerAttributeNames.PROTECTED,
source: RoleNames.GUARD,
source: RoleNames.DEFENDER,
remainingPhases: 1,
...playerAttribute,
});
Expand Down Expand Up @@ -195,7 +195,7 @@ export {
createWorshipedByWildChildPlayerAttribute,
createInLoveByCupidPlayerAttribute,
createRavenMarkByRavenPlayerAttribute,
createProtectedByGuardPlayerAttribute,
createProtectedByDefenderPlayerAttribute,
createDrankDeathPotionByWitchPlayerAttribute,
createDrankLifePotionByWitchPlayerAttribute,
createEatenByBigBadWolfPlayerAttribute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class GameHistoryRecordRepository {
return this.gameHistoryRecordModel.create(gameHistoryRecord);
}

public async getLastGameHistoryGuardProtectsRecord(gameId: Types.ObjectId): Promise<GameHistoryRecord | null> {
public async getLastGameHistoryDefenderProtectsRecord(gameId: Types.ObjectId): Promise<GameHistoryRecord | null> {
const filter: FilterQuery<GameHistoryRecord> = {
gameId,
"play.action": GamePlayActions.PROTECT,
"play.source.name": RoleNames.GUARD,
"play.source.name": RoleNames.DEFENDER,
};
return this.gameHistoryRecordModel.findOne(filter, undefined, { sort: { createdAt: -1 } });
}
Expand Down Expand Up @@ -93,7 +93,7 @@ export class GameHistoryRecordRepository {
gameId,
$or: [
{
"play.source.name": RoleNames.GUARD,
"play.source.name": RoleNames.DEFENDER,
"play.action": GamePlayActions.PROTECT,
"play.targets.player.role.current": RoleNames.ELDER,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class GameHistoryRecordService {
return this.gameHistoryRecordRepository.create(gameHistoryRecordToInsert);
}

public async getLastGameHistoryGuardProtectsRecord(gameId: Types.ObjectId): Promise<GameHistoryRecord | null> {
return this.gameHistoryRecordRepository.getLastGameHistoryGuardProtectsRecord(gameId);
public async getLastGameHistoryDefenderProtectsRecord(gameId: Types.ObjectId): Promise<GameHistoryRecord | null> {
return this.gameHistoryRecordRepository.getLastGameHistoryDefenderProtectsRecord(gameId);
}

public async getLastGameHistoryTieInVotesRecord(gameId: Types.ObjectId, action: GamePlayActions): Promise<GameHistoryRecord | null> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class GamePlayAugmenterService {
[RoleNames.BIG_BAD_WOLF]: game => this.getBigBadWolfGamePlayEligibleTargets(game),
[RoleNames.CUPID]: game => this.getCupidGamePlayEligibleTargets(game),
[RoleNames.FOX]: game => this.getFoxGamePlayEligibleTargets(game),
[RoleNames.GUARD]: async game => this.getGuardGamePlayEligibleTargets(game),
[RoleNames.DEFENDER]: async game => this.getDefenderGamePlayEligibleTargets(game),
[RoleNames.HUNTER]: game => this.getHunterGamePlayEligibleTargets(game),
[RoleNames.PIED_PIPER]: game => this.getPiedPiperGamePlayEligibleTargets(game),
[RoleNames.RAVEN]: game => this.getRavenGamePlayEligibleTargets(game),
Expand Down Expand Up @@ -190,14 +190,14 @@ export class GamePlayAugmenterService {
return createGamePlayEligibleTargets({ interactablePlayers, boundaries });
}

private async getGuardGamePlayEligibleTargets(game: Game): Promise<GamePlayEligibleTargets> {
const { canProtectTwice } = game.options.roles.guard;
private async getDefenderGamePlayEligibleTargets(game: Game): Promise<GamePlayEligibleTargets> {
const { canProtectTwice } = game.options.roles.defender;
const alivePlayers = getAlivePlayers(game);
const lastGuardProtectRecord = await this.gameHistoryRecordService.getLastGameHistoryGuardProtectsRecord(game._id);
const lastProtectedPlayer = lastGuardProtectRecord?.play.targets?.[0].player;
const interactions: PlayerInteraction[] = [{ type: PlayerInteractionTypes.PROTECT, source: RoleNames.GUARD }];
const possibleGuardTargets = canProtectTwice || !lastProtectedPlayer ? alivePlayers : alivePlayers.filter(player => !player._id.equals(lastProtectedPlayer._id));
const interactablePlayers: InteractablePlayer[] = possibleGuardTargets.map(player => ({ player, interactions }));
const lastDefenderProtectRecord = await this.gameHistoryRecordService.getLastGameHistoryDefenderProtectsRecord(game._id);
const lastProtectedPlayer = lastDefenderProtectRecord?.play.targets?.[0].player;
const interactions: PlayerInteraction[] = [{ type: PlayerInteractionTypes.PROTECT, source: RoleNames.DEFENDER }];
const possibleDefenderTargets = canProtectTwice || !lastProtectedPlayer ? alivePlayers : alivePlayers.filter(player => !player._id.equals(lastProtectedPlayer._id));
const interactablePlayers: InteractablePlayer[] = possibleDefenderTargets.map(player => ({ player, interactions }));
const boundaries: GamePlayEligibleTargetsBoundaries = { min: 1, max: 1 };
return createGamePlayEligibleTargets({ interactablePlayers, boundaries });
}
Expand Down

0 comments on commit 244e260

Please sign in to comment.