fsharp(ygosim): refactor: refactored some of the tribute summoning code
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
ab4bd21306
commit
377dd0430a
|
@ -277,17 +277,16 @@ module Summon =
|
||||||
let (_monster, _id) = target
|
let (_monster, _id) = target
|
||||||
|
|
||||||
// Find what monsters to tribute
|
// Find what monsters to tribute
|
||||||
let tributteCount = numberOfTributes _monster
|
|
||||||
let possibleTributes = board ^. Board.currentPlayerMonsters |>> ((=<<) monster) |> choose id
|
let possibleTributes = board ^. Board.currentPlayerMonsters |>> ((=<<) monster) |> choose id
|
||||||
let tributes = chooseTributes client possibleTributes tributteCount []
|
let tributes = chooseTributes client possibleTributes <| numberOfTributes _monster <| []
|
||||||
|
|
||||||
// helpers to remove the tributes from the board
|
// helpers to remove the tributes from the board
|
||||||
let replaceInstance instance =
|
let replaceInstance instance = List.tryFind (view _2 >> (=) instance.id) tributes |>> toCardInstance
|
||||||
let isInstance = List.tryFind (view _2 >> (=) instance.id) tributes |> Option.isSome
|
|
||||||
if isInstance then None
|
|
||||||
else Some instance
|
|
||||||
|
|
||||||
let replaceTributes = map <| Option.bind replaceInstance
|
let replaceTributes =
|
||||||
|
replaceInstance
|
||||||
|
|> Option.bind
|
||||||
|
|> map
|
||||||
|
|
||||||
// Tribute monsters
|
// Tribute monsters
|
||||||
let boardWithoutTributes =
|
let boardWithoutTributes =
|
||||||
|
@ -295,10 +294,12 @@ module Summon =
|
||||||
|> over Board.currentPlayerMonsters replaceTributes
|
|> over Board.currentPlayerMonsters replaceTributes
|
||||||
|> over Board.currentPlayer (tributes |>> toCardInstance |> toGraveyard)
|
|> over Board.currentPlayer (tributes |>> toCardInstance |> toGraveyard)
|
||||||
|
|
||||||
let free = freeMonsterZones <| boardWithoutTributes ^. Board.currentPlayer
|
|
||||||
|
|
||||||
// Choose a zone to summon the monster
|
// Choose a zone to summon the monster
|
||||||
let zone = chooseZone client free
|
let zone =
|
||||||
|
boardWithoutTributes ^. Board.currentPlayer
|
||||||
|
|> freeMonsterZones
|
||||||
|
|> chooseZone client
|
||||||
|
|
||||||
let turn = boardWithoutTributes ^. Board.turn
|
let turn = boardWithoutTributes ^. Board.turn
|
||||||
|
|
||||||
// Instance to actually summon
|
// Instance to actually summon
|
||||||
|
@ -311,7 +312,9 @@ module Summon =
|
||||||
let removeTarget = List.filter (fun card -> card.id <> _id)
|
let removeTarget = List.filter (fun card -> card.id <> _id)
|
||||||
|
|
||||||
// Notify the client a new monster was summoned
|
// Notify the client a new monster was summoned
|
||||||
client <| MonsterSummoned(target ^. _1, zone) |> ignore
|
MonsterSummoned(target ^. _1, zone)
|
||||||
|
|> client
|
||||||
|
|> ignore
|
||||||
|
|
||||||
// Update the board
|
// Update the board
|
||||||
boardWithoutTributes
|
boardWithoutTributes
|
||||||
|
@ -328,9 +331,6 @@ module Game =
|
||||||
|
|
||||||
let isCurrentPlayer (board: Board) (player: Player) = (board ^. Board.currentPlayerId) = player.id
|
let isCurrentPlayer (board: Board) (player: Player) = (board ^. Board.currentPlayerId) = player.id
|
||||||
|
|
||||||
let canDrawCard (board: Board) (player: Player) =
|
|
||||||
isCurrentPlayer board player && board ^. Board.phase = Draw && board ^. Board.turn <> 0
|
|
||||||
|
|
||||||
let draw (board: Board) =
|
let draw (board: Board) =
|
||||||
match board ^. Board.currentPlayerDeck with
|
match board ^. Board.currentPlayerDeck with
|
||||||
| [] -> board |> Board.currentPlayerState .-> Lost "deckout"
|
| [] -> board |> Board.currentPlayerState .-> Lost "deckout"
|
||||||
|
@ -347,9 +347,7 @@ module Game =
|
||||||
|
|
||||||
let processPhase client board =
|
let processPhase client board =
|
||||||
match board ^. Board.phase with
|
match board ^. Board.phase with
|
||||||
| Draw ->
|
| Draw -> draw board
|
||||||
if canDrawCard board <| board ^. Board.currentPlayer then draw board
|
|
||||||
else board
|
|
||||||
| Main1 -> handleMainPhase client board
|
| Main1 -> handleMainPhase client board
|
||||||
| Main2 -> handleMainPhase client board
|
| Main2 -> handleMainPhase client board
|
||||||
| _ -> board
|
| _ -> board
|
||||||
|
|
Loading…
Reference in a new issue