restructuring and preparing for actual client work
This commit is contained in:
parent
2019fafdc5
commit
c1717bc7d1
5 changed files with 114 additions and 54 deletions
|
@ -21,14 +21,37 @@ main = do
|
|||
putStrLn "connected"
|
||||
sendMessage (IdRequest) sock
|
||||
threadDelay $ 5 * 10 ^ 6
|
||||
clientId <- receiveMessage sock
|
||||
putStrLn $ "received client UUID: " <> show (acClientUUID clientId)
|
||||
clientIdMsg <- receiveMessage sock
|
||||
let clientId = acClientUUID clientIdMsg
|
||||
putStrLn $ "received client UUID: " <> show clientId
|
||||
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"
|
||||
sendMessage (ClientMessage (acClientUUID clientId) ClientQuit) sock
|
||||
sendMessage (ClientMessage clientId ClientQuit) sock
|
||||
where
|
||||
opts = info (options <**> helper)
|
||||
( fullDesc
|
||||
<> progDesc "Run the \"wizard-wipeout\" Server."
|
||||
<> 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!"
|
||||
]
|
||||
|
|
|
@ -1,33 +1,13 @@
|
|||
module Library.Types
|
||||
( module T
|
||||
, module Library.Types
|
||||
, module Library.Types
|
||||
) where
|
||||
|
||||
import Data.Matrix
|
||||
import Graphics.Vty
|
||||
import Linear
|
||||
|
||||
import Library.Types.Communication 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)
|
||||
import Library.Types.Player as T
|
||||
|
||||
-- | Data object for storing the client's state
|
||||
data ClientState = ClientState
|
||||
|
@ -62,36 +42,7 @@ data Spawner = Spawner
|
|||
}
|
||||
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
|
||||
= SpawnerFull
|
||||
| SpawnerEmpty
|
||||
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
|
||||
]
|
||||
|
|
|
@ -7,11 +7,18 @@ import Data.UUID
|
|||
|
||||
import GHC.Generics
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Library.Types.Player
|
||||
|
||||
data ServerMessage
|
||||
= ServerQuit
|
||||
| AcceptClient
|
||||
{ acClientUUID :: UUID
|
||||
}
|
||||
| ProvideInitialWizard
|
||||
{ initWizard :: Wizard
|
||||
}
|
||||
deriving (Eq, Show, Generic)
|
||||
|
||||
instance FromJSON ServerMessage
|
||||
|
@ -20,6 +27,7 @@ instance ToJSON ServerMessage
|
|||
|
||||
data ClientMessagePayload
|
||||
= ClientQuit
|
||||
| ClientRequestWizard
|
||||
deriving (Eq, Show, Generic)
|
||||
|
||||
data ClientMessage
|
||||
|
|
77
src-lib/Library/Types/Player.hs
Normal file
77
src-lib/Library/Types/Player.hs
Normal 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
|
||||
]
|
|
@ -20,6 +20,7 @@ library
|
|||
import: warnings
|
||||
exposed-modules: Library.Types
|
||||
Library.Types.Communication
|
||||
Library.Types.Player
|
||||
build-depends: base ^>=4.17.2.1
|
||||
, aeson
|
||||
, linear
|
||||
|
|
Loading…
Reference in a new issue