wizard-wipeout/src-server/Server/Util.hs

51 lines
960 B
Haskell
Raw Normal View History

2023-12-09 12:58:59 +00:00
module Server.Util where
import Control.Exception
import qualified Data.Matrix as M
import Linear
2023-12-09 12:58:59 +00:00
import System.Directory
import System.IO.Error
import System.Random
import Library.Types
2023-12-09 13:18:10 +00:00
-- | Remove a file if it exists
removeIfExists
:: FilePath -- File to remove
-> IO ()
2023-12-09 12:58:59 +00:00
removeIfExists fileName = removeFile fileName `catch` handleExists
where handleExists e
| isDoesNotExistError e = return ()
| otherwise = throwIO e
newWizard
:: Position
2024-11-25 02:58:31 +00:00
-> Float
-> Wizard
2024-11-25 02:58:31 +00:00
newWizard pos rot =
Wizard
{ wizardWands = []
2024-12-17 11:00:51 +00:00
, wizardRot = 0
, wizardPos = pos
, wizardMana = 100
, wizardHealth = 100
, wizardEffects = []
}
rollInitPosition
:: ServerMap
-> IO Position
rollInitPosition arena = do
r <- randomRIO (1, M.nrows arena)
c <- randomRIO (1, M.ncols arena)
if arena M.! (r, c) == Air
then
pure $ (fromIntegral <$> V2 r c) + V2 0.5 0.5
else
rollInitPosition arena