module Game.LambdaHack.Common.Effect
( Effect(..), Aspect(..), ThrowMod(..), Feature(..), EqpSlot(..)
, effectTrav, aspectTrav
) where
import qualified Control.Monad.State as St
import Data.Binary
import Data.Hashable (Hashable)
import Data.Text (Text)
import GHC.Generics (Generic)
import qualified Game.LambdaHack.Common.Ability as Ability
import qualified Game.LambdaHack.Common.Dice as Dice
import Game.LambdaHack.Common.Misc
import Game.LambdaHack.Content.ModeKind
data Effect a =
NoEffect !Text
| Hurt !Dice.Dice
| Burn !Int
| Explode !GroupName
| RefillHP !Int
| RefillCalm !Int
| Dominate
| Impress
| CallFriend !a
| Summon !Freqs !a
| CreateItem !a
| Ascend !Int
| Escape !Int
| Paralyze !a
| InsertMove !a
| Teleport !a
| PolyItem !CStore
| Identify !CStore
| SendFlying !ThrowMod
| PushActor !ThrowMod
| PullActor !ThrowMod
| DropBestWeapon
| DropEqp !Char !Bool
| ActivateInv !Char
| ApplyPerfume
| OneOf ![Effect a]
| OnSmash !(Effect a)
| TimedAspect !Int !(Aspect a)
deriving (Show, Read, Eq, Ord, Generic, Functor)
data Aspect a =
Periodic !a
| AddHurtMelee !a
| AddArmorMelee !a
| AddHurtRanged !a
| AddArmorRanged !a
| AddMaxHP !a
| AddMaxCalm !a
| AddSpeed !a
| AddSkills !Ability.Skills
| AddSight !a
| AddSmell !a
| AddLight !a
deriving (Show, Read, Eq, Ord, Generic, Functor)
data ThrowMod = ThrowMod
{ throwVelocity :: !Int
, throwLinger :: !Int
}
deriving (Show, Read, Eq, Ord, Generic)
data Feature =
ChangeTo !GroupName
| Fragile
| Durable
| ToThrow !ThrowMod
| Identified
| Applicable
| EqpSlot !EqpSlot !Text
| Precious
| Tactic !Tactic
deriving (Show, Eq, Ord, Generic)
data EqpSlot =
EqpSlotPeriodic
| EqpSlotAddHurtMelee
| EqpSlotAddArmorMelee
| EqpSlotAddHurtRanged
| EqpSlotAddArmorRanged
| EqpSlotAddMaxHP
| EqpSlotAddMaxCalm
| EqpSlotAddSpeed
| EqpSlotAddSkills
| EqpSlotAddSight
| EqpSlotAddSmell
| EqpSlotAddLight
| EqpSlotWeapon
deriving (Show, Eq, Ord, Generic)
instance Hashable a => Hashable (Effect a)
instance Hashable a => Hashable (Aspect a)
instance Hashable ThrowMod
instance Hashable Feature
instance Hashable EqpSlot
instance Binary a => Binary (Effect a)
instance Binary a => Binary (Aspect a)
instance Binary ThrowMod
instance Binary Feature
instance Binary EqpSlot
effectTrav :: Effect a -> (a -> St.State s b) -> St.State s (Effect b)
effectTrav (NoEffect t) _ = return $! NoEffect t
effectTrav (RefillHP p) _ = return $! RefillHP p
effectTrav (Hurt dice) _ = return $! Hurt dice
effectTrav (RefillCalm p) _ = return $! RefillCalm p
effectTrav Dominate _ = return Dominate
effectTrav Impress _ = return Impress
effectTrav (CallFriend a) f = do
b <- f a
return $! CallFriend b
effectTrav (Summon freqs a) f = do
b <- f a
return $! Summon freqs b
effectTrav (CreateItem a) f = do
b <- f a
return $! CreateItem b
effectTrav ApplyPerfume _ = return ApplyPerfume
effectTrav (Burn p) _ = return $! Burn p
effectTrav (Ascend p) _ = return $! Ascend p
effectTrav (Escape p) _ = return $! Escape p
effectTrav (Paralyze a) f = do
b <- f a
return $! Paralyze b
effectTrav (InsertMove a) f = do
b <- f a
return $! InsertMove b
effectTrav DropBestWeapon _ = return DropBestWeapon
effectTrav (DropEqp symbol hit) _ = return $! DropEqp symbol hit
effectTrav (SendFlying tmod) _ = return $! SendFlying tmod
effectTrav (PushActor tmod) _ = return $! PushActor tmod
effectTrav (PullActor tmod) _ = return $! PullActor tmod
effectTrav (Teleport a) f = do
b <- f a
return $! Teleport b
effectTrav (PolyItem cstore) _ = return $! PolyItem cstore
effectTrav (Identify cstore) _ = return $! Identify cstore
effectTrav (ActivateInv symbol) _ = return $! ActivateInv symbol
effectTrav (OneOf la) f = do
lb <- mapM (\a -> effectTrav a f) la
return $! OneOf lb
effectTrav (OnSmash effa) f = do
effb <- effectTrav effa f
return $! OnSmash effb
effectTrav (Explode t) _ = return $! Explode t
effectTrav (TimedAspect k asp) f = do
asp2 <- aspectTrav asp f
return $! TimedAspect k asp2
aspectTrav :: Aspect a -> (a -> St.State s b) -> St.State s (Aspect b)
aspectTrav (Periodic a) f = do
b <- f a
return $! Periodic b
aspectTrav (AddMaxHP a) f = do
b <- f a
return $! AddMaxHP b
aspectTrav (AddMaxCalm a) f = do
b <- f a
return $! AddMaxCalm b
aspectTrav (AddSpeed a) f = do
b <- f a
return $! AddSpeed b
aspectTrav (AddSkills as) _ = return $! AddSkills as
aspectTrav (AddHurtMelee a) f = do
b <- f a
return $! AddHurtMelee b
aspectTrav (AddHurtRanged a) f = do
b <- f a
return $! AddHurtRanged b
aspectTrav (AddArmorMelee a) f = do
b <- f a
return $! AddArmorMelee b
aspectTrav (AddArmorRanged a) f = do
b <- f a
return $! AddArmorRanged b
aspectTrav (AddSight a) f = do
b <- f a
return $! AddSight b
aspectTrav (AddSmell a) f = do
b <- f a
return $! AddSmell b
aspectTrav (AddLight a) f = do
b <- f a
return $! AddLight b