Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom cards and bots simultaneously #550

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 33 additions & 49 deletions client/src/elm/MassiveDecks/Pages/Lobby/Configure.elm
Original file line number Diff line number Diff line change
Expand Up @@ -455,21 +455,43 @@ startGameProblems shared wrap wrapLobby users model remote =
Nothing ->
summaries .responses

-- Catch the case where "only blank white cards" is enabled.
numberOfNonBlankResponses =
case hr.comedyWriter of
Just { exclusive } ->
if exclusive then
0

else
summaries .responses

Nothing ->
summaries .responses

Comment on lines +458 to +470
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need some feedback on this. Is this reasonable?

humanPlayerCount =
users
|> Dict.values
|> List.filter (\u -> u.role == User.Player && u.presence == User.Joined && u.control == User.Human)
|> List.length

computerPlayers =
computerPlayerCount =
config.rules.houseRules.rando |> Maybe.map .number |> Maybe.withDefault 0

playerCount =
humanPlayerCount + computerPlayers
humanPlayerCount + computerPlayerCount

-- 5 is arbitrary, but we have to deal with an additional cards for each slot.
requiredResponses =
playerCount * 5 + playerCount * rules.handSize
requiredHumanResponses =
humanPlayerCount * 5 + humanPlayerCount * rules.handSize

-- We need enough non-blank responses for every player to have a full hand
-- otherwise there is a chance humans will hog all the non-blank responses.
requiredComputerResponses =
if computerPlayerCount > 0 then
playerCount * 5 + playerCount * rules.handSize

else
0

deckIssues =
if noDecks then
Expand All @@ -489,7 +511,7 @@ startGameProblems shared wrap wrapLobby users model remote =
else
let
diff =
requiredResponses - numberOfResponses
requiredHumanResponses - numberOfResponses

old =
config.rules.houseRules.comedyWriter |> Maybe.map .number |> Maybe.withDefault 0
Expand All @@ -515,9 +537,12 @@ startGameProblems shared wrap wrapLobby users model remote =
|> Message.error
|> Maybe.justIf (summaries .calls < 1)
, Message.errorWithFix
(Strings.NotEnoughCardsOfType { cardType = Strings.Response, needed = requiredResponses, have = numberOfResponses })
(Strings.NotEnoughCardsOfType { cardType = Strings.Response, needed = requiredHumanResponses, have = numberOfResponses })
[ Message.Fix (Strings.AddBlankCards { amount = diff }) Icon.add fixMsg ]
|> Maybe.justIf (numberOfResponses < requiredResponses)
|> Maybe.justIf (numberOfResponses < requiredHumanResponses)
, Message.error
(Strings.NotEnoughNonBlankCardsOfType { cardType = Strings.Response, needed = requiredComputerResponses, have = numberOfNonBlankResponses })
|> Maybe.justIf (numberOfResponses >= requiredHumanResponses && numberOfNonBlankResponses < requiredComputerResponses)
]

rando =
Expand Down Expand Up @@ -560,47 +585,6 @@ startGameProblems shared wrap wrapLobby users model remote =
|> Maybe.justIf (humanPlayerCount < 1)
]

disableRandoConfig =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I should bring this back but check for "blank white cards only" instead to fix the above comment? And then I guess I'd need to hide the above error message I added in that case too...

{ config | rules = { rules | houseRules = { houseRules | rando = Nothing } } }

disableRandoFixMsg =
ApplyChange
(Rando.Enabled
|> HouseRules.RandoId
|> Rules.HouseRulesId
|> RulesId
)
disableRandoConfig
|> wrap

disableComedyWriterConfig =
{ config | rules = { rules | houseRules = { houseRules | comedyWriter = Nothing } } }

disableComedyWriterFixMsg =
ApplyChange
(ComedyWriter.Enabled
|> HouseRules.ComedyWriterId
|> Rules.HouseRulesId
|> RulesId
)
disableComedyWriterConfig
|> wrap

aisNoWriteGoodIssues =
[ Message.errorWithFix
Strings.RandoCantWrite
[ { description = Strings.DisableRando
, icon = Icon.disableAi
, action = disableRandoFixMsg
}
, { description = Strings.DisableComedyWriter
, icon = Icon.disableEdit
, action = disableComedyWriterFixMsg
}
]
|> Maybe.justIf (hr.rando /= Nothing && hr.comedyWriter /= Nothing)
]

configurationIssues =
[ Message.errorWithFix Strings.UnsavedChangesWarning
(List.filterMap identity
Expand All @@ -619,7 +603,7 @@ startGameProblems shared wrap wrapLobby users model remote =
|> Maybe.justIf (config /= remote)
]
in
[ deckIssues, playerIssues, aisNoWriteGoodIssues, configurationIssues ] |> List.concat |> List.filterMap identity
[ deckIssues, playerIssues, configurationIssues ] |> List.concat |> List.filterMap identity


tabs : List Tab
Expand Down
4 changes: 1 addition & 3 deletions client/src/elm/MassiveDecks/Strings.elm
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ type MdString
| WaitForDecks -- A hint that the user has to wait for decks to load before starting the game.
| MissingCardType { cardType : Noun } -- An error explaining that the user needs a deck with the given type of card (call/response).
| NotEnoughCardsOfType { cardType : Noun, needed : Int, have : Int } -- An error explaining that the user needs to add more cards of the given type for the number of players.
| NotEnoughNonBlankCardsOfType { cardType : Noun, needed : Int, have : Int } -- An error explaining that the user needs to add more non-blank white cards for the number of players.
| AddBlankCards { amount : Int } -- A description of the action of adding the given number of blank cards to the game.
| AddDeck -- A description of the action of adding a deck to the game configuration.
| RemoveDeck -- A description of the action of removing a deck from the game configuration.
Expand Down Expand Up @@ -281,9 +282,6 @@ type MdString
| NeedAtLeastOneDeck -- A description of the problem that the game needs at least one deck to start.
| NeedAtLeastThreePlayers -- A description of the problem that the game needs at least three players to start.
| NeedAtLeastOneHuman -- A description of the problem that the game needs at least one human player.
| RandoCantWrite -- A description of the problem that the AI players can't use blank cards.
| DisableRando -- A description of disabling the "Rando Cardrissian" house rule.
| DisableComedyWriter -- A description of disabling the "Comedy Writer" house rule.
| AddAnAiPlayer -- A description of adding an AI player to the game.
| PasswordShared -- A warning that game passwords are visible to anyone else in the game.
| PasswordNotSecured -- A warning that game passwords are not stored securely and should not be used elsewhere.
Expand Down
15 changes: 5 additions & 10 deletions client/src/elm/MassiveDecks/Strings/Languages/De.elm
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ translate _ mdString =
, Text "."
]

-- TODO: Translate
NotEnoughNonBlankCardsOfType _ ->
[ Missing ]

AddBlankCards { amount } ->
[ Text "Ergänze "
, amount |> String.fromInt |> Text
Expand Down Expand Up @@ -919,15 +923,6 @@ translate _ mdString =
, Text " (auch wenn nur ein einzelner menschlicher Spieler ein bisschen langweilig sein mag!)"
]

RandoCantWrite ->
[ Text "Computerspieler können ihre Karten nicht selbst schreiben." ]

DisableComedyWriter ->
[ Text "Deaktiviere ", ref HouseRuleComedyWriter ]

DisableRando ->
[ Text "Deaktiviere ", ref HouseRuleRandoCardrissian ]

AddAnAiPlayer ->
[ Text "Fügen Sie dem Spiel einen KI-Spieler hinzu." ]

Expand Down Expand Up @@ -1380,10 +1375,10 @@ translate _ mdString =
Spanish ->
[ Text "Spanisch" ]


Korean ->
[ Text "Koreanisch" ]


an : Maybe Int -> String
an amount =
case amount of
Expand Down
13 changes: 4 additions & 9 deletions client/src/elm/MassiveDecks/Strings/Languages/DeXInformal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,10 @@ translate _ mdString =
, Text "."
]

-- TODO: Translate
NotEnoughNonBlankCardsOfType _ ->
[ Missing ]

AddBlankCards { amount } ->
[ Text "Ergänze "
, amount |> String.fromInt |> Text
Expand Down Expand Up @@ -917,15 +921,6 @@ translate _ mdString =
, Text " (auch wenn nur ein einzelner menschlicher Spieler ein bisschen langweilig sein mag!)"
]

RandoCantWrite ->
[ Text "Computerspieler können ihre Karten nicht selbst schreiben." ]

DisableComedyWriter ->
[ Text "Deaktiviere ", ref HouseRuleComedyWriter ]

DisableRando ->
[ Text "Deaktiviere ", ref HouseRuleRandoCardrissian ]

AddAnAiPlayer ->
[ Text "Füge dem Spiel einen KI-Spieler hinzu." ]

Expand Down
21 changes: 11 additions & 10 deletions client/src/elm/MassiveDecks/Strings/Languages/En/Internal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ translate _ mdString =
]

NotEnoughCardsOfType { cardType, needed, have } ->
[ Text "For the number of players in the game, you need at least "
[ Text "For the number of humans in the game, you need at least "
, Text (needed |> String.fromInt)
, Text " "
, ref (noun cardType needed)
Expand All @@ -762,6 +762,16 @@ translate _ mdString =
, Text "."
]

NotEnoughNonBlankCardsOfType { cardType, needed, have } ->
[ Text "For the number of bots in the game, you need at least "
, Text (needed |> String.fromInt)
, Text " non-blank "
, ref (noun cardType needed)
, Text " but you only have "
, Text (have |> String.fromInt)
, Text "."
]

AddBlankCards { amount } ->
[ Text "Add "
, amount |> String.fromInt |> Text
Expand Down Expand Up @@ -866,15 +876,6 @@ translate _ mdString =
, Text " (Although only one human might be a bit boring!)"
]

RandoCantWrite ->
[ Text "Computer players can't write their own cards." ]

DisableComedyWriter ->
[ Text "Disable ", ref HouseRuleComedyWriter ]

DisableRando ->
[ Text "Disable ", ref HouseRuleRandoCardrissian ]

AddAnAiPlayer ->
[ Text "Add an AI player to the game." ]

Expand Down
14 changes: 5 additions & 9 deletions client/src/elm/MassiveDecks/Strings/Languages/Es.elm
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@ translate _ mdString =
, Text "."
]

-- TODO: Translate
NotEnoughNonBlankCardsOfType _ ->
[ Missing ]

AddBlankCards { amount } ->
[ Text "Añadir "
, amount |> String.fromInt |> Text
Expand Down Expand Up @@ -900,15 +904,6 @@ translate _ mdString =
, Text " (¡Aunque solo un humano puede ser un poco aburrido!)"
]

RandoCantWrite ->
[ Text "Los bots no pueden escribir sus propias cartas." ]

DisableComedyWriter ->
[ Text "Desactivar ", ref HouseRuleComedyWriter ]

DisableRando ->
[ Text "Desactivar ", ref HouseRuleRandoCardrissian ]

AddAnAiPlayer ->
[ Text "Añadir un bot a la partida." ]

Expand Down Expand Up @@ -1363,6 +1358,7 @@ translate _ mdString =
Korean ->
[ Text "Coreano" ]


raw : MdString -> Translation.Result never
raw =
Raw Nothing
Expand Down
13 changes: 4 additions & 9 deletions client/src/elm/MassiveDecks/Strings/Languages/Id.elm
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,10 @@ translate _ mdString =
, Text "."
]

-- TODO: Translate
NotEnoughNonBlankCardsOfType _ ->
[ Missing ]

AddBlankCards { amount } ->
[ Text "Tambahkan "
, amount |> String.fromInt |> Text
Expand Down Expand Up @@ -908,15 +912,6 @@ translate _ mdString =
, Text " (Meskipun hanya satu manusia yang mungkin sedikit membosankan!)"
]

RandoCantWrite ->
[ Text "Pemain komputer tidak bisa menulis kartunya sendiri." ]

DisableComedyWriter ->
[ Text "Nonaktifkan" ]

DisableRando ->
[ Text "Nonaktifkan ", ref HouseRuleRandoCardrissian ]

AddAnAiPlayer ->
[ Text "Tambahkan pemain AI ke dalam game." ]

Expand Down
13 changes: 4 additions & 9 deletions client/src/elm/MassiveDecks/Strings/Languages/It.elm
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,10 @@ translate _ mdString =
, Text "."
]

-- TODO: Translate
NotEnoughNonBlankCardsOfType _ ->
[ Missing ]

-- TODO: Translate
AddBlankCards { amount } ->
[ Missing ]
Expand Down Expand Up @@ -932,15 +936,6 @@ translate _ mdString =
, Text " (Anche se un solo giocatore umano potrebbe essere piuttosto noioso!)"
]

RandoCantWrite ->
[ Text "I giocatori computer non possono scrivere le loro carte." ]

DisableComedyWriter ->
[ Text "Disabilita ", ref HouseRuleComedyWriter ]

DisableRando ->
[ Text "Disabilita ", ref HouseRuleRandoCardrissian ]

AddAnAiPlayer ->
[ Text "Aggiungi un giocatore IA al gioco." ]

Expand Down
13 changes: 4 additions & 9 deletions client/src/elm/MassiveDecks/Strings/Languages/Ko.elm
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,10 @@ translate _ mdString =
, Text "장입니다."
]

-- TODO: Translate
NotEnoughNonBlankCardsOfType _ ->
[ Missing ]

AddBlankCards { amount } ->
[ amount |> String.fromInt |> Text
, Text "장의 공백 "
Expand Down Expand Up @@ -882,15 +886,6 @@ translate _ mdString =
, Text " (인간 1명은 좀 재미가 없을 것 같기도 하지만요!)"
]

RandoCantWrite ->
[ Text "컴퓨터 플레이어들은 자신의 커스텀 카드는 쓸 수 없습니다." ]

DisableComedyWriter ->
[ ref HouseRuleComedyWriter, Text " 비활성화" ]

DisableRando ->
[ ref HouseRuleRandoCardrissian, Text "비활성화" ]

AddAnAiPlayer ->
[ Text "게임에 AI 플레이어를 추가합니다." ]

Expand Down
13 changes: 4 additions & 9 deletions client/src/elm/MassiveDecks/Strings/Languages/Pl.elm
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,10 @@ translate maybeDeclCase mdString =
, Text "."
]

-- TODO: Translate
NotEnoughNonBlankCardsOfType _ ->
[ Missing ]

AddBlankCards { amount } ->
[ Text "Dodaj "
, Text (asWord amount Feminine Accusative)
Expand Down Expand Up @@ -1012,15 +1016,6 @@ translate maybeDeclCase mdString =
, Text " (Chociaż z tylko jednym człowiekiem może być nudno!)"
]

RandoCantWrite ->
[ Text "Boty nie mogą pisać własnych kart." ]

DisableComedyWriter ->
[ Text "Wyłącz Memiarza" ]

DisableRando ->
[ Text "Wyłącz Rando Cardrissiana" ]

AddAnAiPlayer ->
[ Text "Dodaj bota do gry." ]

Expand Down
Loading