Skip to content

Commit

Permalink
feat(game-options): cupid must win with lovers game option (#779)
Browse files Browse the repository at this point in the history
Closes #749
  • Loading branch information
antoinezanardi committed Dec 25, 2023
1 parent f2ffed4 commit ddf59bc
Show file tree
Hide file tree
Showing 53 changed files with 36,218 additions and 33,986 deletions.
2 changes: 1 addition & 1 deletion .run/Accursed Wolf-Father Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@accursed-wolf-father-role&quot;" />
<arguments value="--tags &quot;@accursed-wolf-father-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Actor Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@actor-role&quot;" />
<arguments value="--tags &quot;@actor-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Angel Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@angel-role&quot;" />
<arguments value="--tags &quot;@angel-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Bear Tamer Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@bear-tamer-role&quot;" />
<arguments value="--tags &quot;@bear-tamer-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Big Bad Wolf Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@big-bad-wolf-role&quot;" />
<arguments value="--tags &quot;@big-bad-wolf-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Cupid Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@cupid-role&quot;" />
<arguments value="--tags &quot;@cupid-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Defender Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@defender-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 .run/Devoted Servant Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@devoted-servant-role&quot;" />
<arguments value="--tags &quot;@devoted-servant-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Elder Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@elder-role&quot;" />
<arguments value="--tags &quot;@elder-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Fox Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@fox-role&quot;" />
<arguments value="--tags &quot;@fox-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Game Creation.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@game-creation&quot;" />
<arguments value="--tags &quot;@game-creation&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Game History.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@game-history&quot;" />
<arguments value="--tags &quot;@game-history&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Game Victory.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@game-victory&quot;" />
<arguments value="--tags &quot;@game-victory&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Idiot Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@idiot-role&quot;" />
<arguments value="--tags &quot;@idiot-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Little Girl Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@little-girl-role&quot;" />
<arguments value="--tags &quot;@little-girl-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Pied Piper Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@pied-piper-role&quot;" />
<arguments value="--tags &quot;@pied-piper-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Prejudiced Manipulator Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@prejudiced-manipulator-role&quot;" />
<arguments value="--tags &quot;@prejudiced-manipulator-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@role&quot;" />
<arguments value="--tags &quot;@role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Rusty Sword Knight Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@rusty-sword-knight-role&quot;" />
<arguments value="--tags &quot;@rusty-sword-knight-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Scandalmonger Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@scandalmonger-role&quot;" />
<arguments value="--tags &quot;@scandalmonger-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Scapegoat Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@scapegoat-role&quot;" />
<arguments value="--tags &quot;@scapegoat-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Sheriff Player Attribute.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@sheriff-player-attribute&quot;" />
<arguments value="--tags &quot;@sheriff-player-attribute&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Stuttering Judge Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@stuttering-judge-role&quot;" />
<arguments value="--tags &quot;@stuttering-judge-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Thief Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@thief-role&quot;" />
<arguments value="--tags &quot;@thief-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Three Brothers Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@three-brothers-role&quot;" />
<arguments value="--tags &quot;@three-brothers-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Two Sisters Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@two-sisters-role&quot;" />
<arguments value="--tags &quot;@two-sisters-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Villager-Villager Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@villager-villager-role&quot;" />
<arguments value="--tags &quot;@villager-villager-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Vote Game Play.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@vote-game-play&quot;" />
<arguments value="--tags &quot;@vote-game-play&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Werewolf Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@werewolf-role&quot;" />
<arguments value="--tags &quot;@werewolf-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/White Werewolf Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@white-werewolf-role&quot;" />
<arguments value="--tags &quot;@white-werewolf-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Wild Child Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@wild-child-role&quot;" />
<arguments value="--tags &quot;@wild-child-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Witch Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@witch-role&quot;" />
<arguments value="--tags &quot;@witch-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Wolf-Hound Role.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="test:cucumber" />
</scripts>
<arguments value="-- --tags &quot;@wolf-hound-role&quot;" />
<arguments value="--tags &quot;@wolf-hound-role&quot;" />
<node-interpreter value="project" />
<envs />
<method v="2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const DEFAULT_GAME_OPTIONS: ReadonlyDeep<GameOptions> = {
isTalkative: true,
canSeeRoles: true,
},
cupid: { lovers: { doRevealRoleToEachOther: false } },
cupid: {
lovers: { doRevealRoleToEachOther: false },
mustWinWithLovers: false,
},
littleGirl: { isProtectedByDefender: false },
defender: { canProtectTwice: false },
elder: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsOptional, ValidateNested } from "class-validator";
import { IsBoolean, IsOptional, ValidateNested } from "class-validator";

import { DEFAULT_GAME_OPTIONS } from "@/modules/game/constants/game-options/game-options.constant";
import { CreateCupidLoversGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-cupid-game-options/create-cupid-lovers-game-options.dto";
import { CUPID_GAME_OPTIONS_API_PROPERTIES } from "@/modules/game/schemas/game-options/roles-game-options/cupid-game-options/cupid-game-options.schema.constant";

Expand All @@ -15,6 +16,14 @@ class CreateCupidGameOptionsDto {
@Type(() => CreateCupidLoversGameOptionsDto)
@ValidateNested()
public lovers: CreateCupidLoversGameOptionsDto = new CreateCupidLoversGameOptionsDto();

@ApiProperty({
...CUPID_GAME_OPTIONS_API_PROPERTIES.mustWinWithLovers,
required: false,
} as ApiPropertyOptions)
@IsOptional()
@IsBoolean()
public mustWinWithLovers: boolean = DEFAULT_GAME_OPTIONS.roles.cupid.mustWinWithLovers;
}

export { CreateCupidGameOptionsDto };
10 changes: 7 additions & 3 deletions src/modules/game/helpers/game-victory/game-victory.factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { plainToInstance } from "class-transformer";

import { doesPlayerHaveActiveAttributeWithName } from "@/modules/game/helpers/player/player-attribute/player-attribute.helper";
import { PlayerAttributeNames } from "@/modules/game/enums/player.enum";
import { getPlayersWithActiveAttributeName, getPlayersWithCurrentSide, getPlayerWithCurrentRole } from "@/modules/game/helpers/game.helper";
import { getPlayersWithCurrentSide, getPlayerWithCurrentRole } from "@/modules/game/helpers/game.helper";
import type { Game } from "@/modules/game/schemas/game.schema";
import { RoleNames, RoleSides } from "@/modules/role/enums/role.enum";
import { GameVictoryTypes } from "@/modules/game/enums/game-victory.enum";
Expand All @@ -27,10 +28,13 @@ function createAngelGameVictory(game: Game, gameVictory: Partial<GameVictory> =
}

function createLoversGameVictory(game: Game, gameVictory: Partial<GameVictory> = {}): GameVictory {
const inLovePlayers = getPlayersWithActiveAttributeName(game, PlayerAttributeNames.IN_LOVE);
const { mustWinWithLovers: mustCupidWinWithLovers } = game.options.roles.cupid;
const winners = game.players.filter(player =>
doesPlayerHaveActiveAttributeWithName(player, PlayerAttributeNames.IN_LOVE, game) ||
player.role.current === RoleNames.CUPID && mustCupidWinWithLovers);
return createGameVictory({
type: GameVictoryTypes.LOVERS,
winners: inLovePlayers,
winners,
...gameVictory,
});
}
Expand Down

0 comments on commit ddf59bc

Please sign in to comment.