module Game.Werewolf.Command.Protector (
protectCommand,
) where
import Control.Lens
import Control.Monad.Except
import Control.Monad.Extra
import Control.Monad.State hiding (state)
import Data.Text (Text)
import Game.Werewolf
import Game.Werewolf.Messages
import Game.Werewolf.Util
protectCommand :: Text -> Text -> Command
protectCommand callerName targetName = Command $ do
validatePlayer callerName callerName
unlessM (isPlayerProtector callerName) $ throwError [playerCannotDoThatMessage callerName]
unlessM isProtectorsTurn $ throwError [playerCannotDoThatRightNowMessage callerName]
validatePlayer callerName targetName
whenM (has (priorProtect . traverse . only targetName) <$> get) $ throwError [playerCannotProtectSamePlayerTwiceInARowMessage callerName]
priorProtect .= Just targetName
protect .= Just targetName