restructuring and preparing for actual client work

This commit is contained in:
nek0 2023-12-11 11:54:17 +01:00
parent 2019fafdc5
commit c1717bc7d1
5 changed files with 114 additions and 54 deletions

View file

@ -21,14 +21,37 @@ main = do
putStrLn "connected" putStrLn "connected"
sendMessage (IdRequest) sock sendMessage (IdRequest) sock
threadDelay $ 5 * 10 ^ 6 threadDelay $ 5 * 10 ^ 6
clientId <- receiveMessage sock clientIdMsg <- receiveMessage sock
putStrLn $ "received client UUID: " <> show (acClientUUID clientId) let clientId = acClientUUID clientIdMsg
putStrLn $ "received client UUID: " <> show clientId
threadDelay $ 5 * 10 ^ 6 threadDelay $ 5 * 10 ^ 6
putStrLn welcomeText
threadDelay $ 15 * 10 ^ 6
sendMessage (ClientMessage clientId ClientRequestWizard) sock
playerWizard <- receiveMessage sock
let initRead = ReaderContainer sock clientId
initState = StateContainer (initWizard playerWizard)
putStrLn "sending quit message" putStrLn "sending quit message"
sendMessage (ClientMessage (acClientUUID clientId) ClientQuit) sock sendMessage (ClientMessage clientId ClientQuit) sock
where where
opts = info (options <**> helper) opts = info (options <**> helper)
( fullDesc ( fullDesc
<> progDesc "Run the \"wizard-wipeout\" Server." <> progDesc "Run the \"wizard-wipeout\" Server."
<> header "wizard-wipeout - Last Mage standing" <> header "wizard-wipeout - Last Mage standing"
) )
welcomeText :: String
welcomeText = mconcat $ map (<> "\n")
[ "Welcome to the arena, wizards."
, ""
, "Let the toughest and bravest of you survive"
, ""
, "Some last hints before you enter the fighting grounds:"
, ""
, "press [SpACE] to fire your wand"
, "press [1] through [9] to change wands, if you have collected more wands"
, "press [ESC] to leave"
, ""
, "Good Luck!"
]

View file

@ -1,33 +1,13 @@
module Library.Types module Library.Types
( module T ( module T
, module Library.Types , module Library.Types
) where ) where
import Data.Matrix import Data.Matrix
import Graphics.Vty import Graphics.Vty
import Linear
import Library.Types.Communication as T import Library.Types.Communication as T
import Library.Types.Player as T
-- | Just a type synonym for any kind of position. Translates to a 2D vector
type Position = V2 Float
-- | Data object for storing player state
data Wizard = Wizard
{ wizardPos :: Position
-- ^ Player's position
, wizardRot :: Float
-- ^ Player's view direction
, wizardHealth :: Int
-- ^ Player's hit points
, wizardMana :: Int
-- ^ Player's Mana (magic fuel)
, wizardWands :: [Wand]
-- ^ Player's wands (read: weapons)
, wizardEffects :: [Effect]
-- ^ 'Effect's affecting the player
}
deriving (Show, Eq)
-- | Data object for storing the client's state -- | Data object for storing the client's state
data ClientState = ClientState data ClientState = ClientState
@ -62,36 +42,7 @@ data Spawner = Spawner
} }
deriving (Show, Eq) deriving (Show, Eq)
-- List of all available Wands
data Wand
= HealthUp -- ^ Instant Health boost
| ManaUp -- ^ Instant Mana boost
| Shield -- ^ Magical shield protecting the player
| BigWand -- ^ Stronger Zap spell
| FireWand -- ^ Spell for causing fire damage
| IceWand -- ^ Spell for causing ice damage
| BlinkWand -- ^ Spell for random teleport
deriving (Show, Eq, Enum, Bounded)
data SpawnerState data SpawnerState
= SpawnerFull = SpawnerFull
| SpawnerEmpty | SpawnerEmpty
deriving (Eq, Show) deriving (Eq, Show)
data Effect = Effect
{ effectType :: Affliction -- ^ What is happening
, effectTTL :: Float -- ^ remaining time
}
deriving (Show, Eq)
data Affliction
= Burning -- ^ Damage over time
| Frozen -- ^ Unable to perform any action
| Shielded -- ^ invulnerable until next hit or time runs out.
deriving (Show, Eq)
harmingAfflictions :: [ Affliction ]
harmingAfflictions =
[ Burning
, Frozen
]

View file

@ -7,11 +7,18 @@ import Data.UUID
import GHC.Generics import GHC.Generics
-- internal imports
import Library.Types.Player
data ServerMessage data ServerMessage
= ServerQuit = ServerQuit
| AcceptClient | AcceptClient
{ acClientUUID :: UUID { acClientUUID :: UUID
} }
| ProvideInitialWizard
{ initWizard :: Wizard
}
deriving (Eq, Show, Generic) deriving (Eq, Show, Generic)
instance FromJSON ServerMessage instance FromJSON ServerMessage
@ -20,6 +27,7 @@ instance ToJSON ServerMessage
data ClientMessagePayload data ClientMessagePayload
= ClientQuit = ClientQuit
| ClientRequestWizard
deriving (Eq, Show, Generic) deriving (Eq, Show, Generic)
data ClientMessage data ClientMessage

View file

@ -0,0 +1,77 @@
{-# LANGUAGE DeriveGeneric #-}
module Library.Types.Player where
import Data.Aeson
import GHC.Generics (Generic)
import Linear
-- | Data object for storing player state
data Wizard = Wizard
{ wizardPos :: Position
-- ^ Player's position
, wizardRot :: Float
-- ^ Player's view direction
, wizardHealth :: Int
-- ^ Player's hit points
, wizardMana :: Int
-- ^ Player's Mana (magic fuel)
, wizardWands :: [Wand]
-- ^ Player's wands (read: weapons)
, wizardEffects :: [Effect]
-- ^ 'Effect's affecting the player
}
deriving (Show, Eq, Generic)
instance FromJSON Wizard
instance ToJSON Wizard
-- | Just a type synonym for any kind of position. Translates to a 2D vector
type Position = V2 Float
instance FromJSON Position
instance ToJSON Position
-- List of all available Wands
data Wand
= HealthUp -- ^ Instant Health boost
| ManaUp -- ^ Instant Mana boost
| Shield -- ^ Magical shield protecting the player
| BigWand -- ^ Stronger Zap spell
| FireWand -- ^ Spell for causing fire damage
| IceWand -- ^ Spell for causing ice damage
| BlinkWand -- ^ Spell for random teleport
deriving (Show, Eq, Enum, Bounded, Generic)
instance FromJSON Wand
instance ToJSON Wand
data Effect = Effect
{ effectType :: Affliction -- ^ What is happening
, effectTTL :: Float -- ^ remaining time
}
deriving (Show, Eq, Generic)
instance FromJSON Effect
instance ToJSON Effect
data Affliction
= Burning -- ^ Damage over time
| Frozen -- ^ Unable to perform any action
| Shielded -- ^ invulnerable until next hit or time runs out.
deriving (Show, Eq, Generic)
instance FromJSON Affliction
instance ToJSON Affliction
harmingAfflictions :: [ Affliction ]
harmingAfflictions =
[ Burning
, Frozen
]

View file

@ -20,6 +20,7 @@ library
import: warnings import: warnings
exposed-modules: Library.Types exposed-modules: Library.Types
Library.Types.Communication Library.Types.Communication
Library.Types.Player
build-depends: base ^>=4.17.2.1 build-depends: base ^>=4.17.2.1
, aeson , aeson
, linear , linear