2018-07-22 20:30:17 +00:00
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
2018-08-10 06:58:26 +00:00
|
|
|
{-# LANGUAGE TypeSynonymInstances #-}
|
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
2018-07-22 20:30:17 +00:00
|
|
|
module Object where
|
|
|
|
|
2018-08-10 20:45:32 +00:00
|
|
|
import Affection as A
|
2018-07-22 20:30:17 +00:00
|
|
|
|
2018-08-10 06:58:26 +00:00
|
|
|
import Control.Monad (when)
|
|
|
|
|
2018-07-22 20:30:17 +00:00
|
|
|
import Data.Ecstasy
|
|
|
|
|
|
|
|
import Types
|
|
|
|
|
2018-08-10 06:58:26 +00:00
|
|
|
instance ObjectAction ObjType ObjState where
|
|
|
|
objectAction dt t@ObjCopier s@"copying" ent = do
|
|
|
|
emap (anEnt ent) $ do
|
|
|
|
mtime <- queryMaybe objStateTime
|
|
|
|
case mtime of
|
|
|
|
Nothing -> do
|
|
|
|
liftIO $ logIO Debug ("Copier " ++ show ent ++ ": copying!")
|
|
|
|
return unchanged
|
|
|
|
{ objStateTime = Set (actionTime t s)
|
|
|
|
, objState = Set "copying"
|
|
|
|
}
|
|
|
|
Just ttl -> do
|
|
|
|
return unchanged
|
|
|
|
{ objStateTime = Set (ttl - dt)
|
|
|
|
}
|
|
|
|
[trans] <- efor (anEnt ent) $ do
|
|
|
|
mttl <- queryMaybe objStateTime
|
|
|
|
case mttl of
|
|
|
|
Nothing -> return False
|
|
|
|
Just ttl -> return (ttl < 0)
|
2018-08-10 09:35:08 +00:00
|
|
|
when trans (setEntity ent =<< objectTransition t s False ent)
|
2018-08-10 06:58:26 +00:00
|
|
|
|
|
|
|
objectAction _ _ _ _ = return ()
|
|
|
|
|
2018-08-10 09:35:08 +00:00
|
|
|
objectTransition ObjCopier "idle" playerActivated ent = do
|
2018-08-10 06:58:26 +00:00
|
|
|
[e] <- efor (anEnt ent) $ do
|
2018-07-22 20:30:17 +00:00
|
|
|
let nstat = AnimState
|
|
|
|
(AnimId "copier" "copy" N)
|
|
|
|
0
|
|
|
|
0
|
|
|
|
return unchanged
|
2018-08-10 09:35:08 +00:00
|
|
|
{ objState = Set "copying"
|
|
|
|
, objPlayerActivated = Set playerActivated
|
|
|
|
, anim = Set nstat
|
2018-08-10 06:58:26 +00:00
|
|
|
}
|
|
|
|
return e
|
|
|
|
|
2018-08-10 09:35:08 +00:00
|
|
|
objectTransition ObjCopier "copying" _ ent = do
|
2018-08-10 06:58:26 +00:00
|
|
|
[e] <- efor (anEnt ent) $ do
|
|
|
|
let nstat = AnimState
|
|
|
|
(AnimId "copier" "open" N)
|
|
|
|
0
|
|
|
|
0
|
|
|
|
return unchanged
|
2018-08-10 09:35:08 +00:00
|
|
|
{ anim = Set nstat
|
|
|
|
, objState = Set "idle"
|
|
|
|
, objStateTime = Unset
|
|
|
|
, objPlayerActivated = Unset
|
2018-07-22 20:30:17 +00:00
|
|
|
}
|
2018-08-10 06:58:26 +00:00
|
|
|
return e
|
|
|
|
|
2018-08-10 09:35:08 +00:00
|
|
|
objectTransition _ _ _ _ = return unchanged
|
2018-08-10 06:58:26 +00:00
|
|
|
|
|
|
|
instance ActionTime ObjType ObjState where
|
|
|
|
actionTime ObjCopier "copying" = 5
|
2018-07-30 13:34:45 +00:00
|
|
|
|
2018-08-10 20:45:32 +00:00
|
|
|
actionTime o s = A.log Error (show o ++ ": " ++ s ++ ": has not time") 0
|