Permalink
Browse files

potions now work via effects

  • Loading branch information...
Mikolaj committed Mar 27, 2011
1 parent 7be79d7 commit 20a075226997883ad5be5c5409820b272e1fb3a5
Showing with 43 additions and 22 deletions.
  1. +37 −7 src/Actions.hs
  2. +2 −0 src/Effect.hs
  3. +3 −4 src/Grammar.hs
  4. +1 −11 src/ItemKind.hs
View
@@ -624,6 +624,7 @@ drinkPotion =
pbody <- gets getPlayerBody
ploc <- gets (mloc . getPlayerBody)
items <- gets (mitems . getPlayerBody)
+ pl <- gets splayer
if L.null items
then abortWith "You are not carrying anything."
else do
@@ -638,13 +639,7 @@ drinkPotion =
removeFromInventory consumed
message (subjectVerbIObject state pbody "drink" consumed "")
-- the potion is identified after drinking
- discover i'
- case ItemKind.jeffect (ItemKind.getIK (ikind i')) of -- TODO: redo
- (Effect.AffectHP n) -> do
- messageAdd "You feel better."
- let php p = min (nhpMax (mkind p)) (mhp p + n)
- updatePlayerBody (\ p -> p { mhp = php p })
- _ -> messageAdd "Tastes like water."
+ itemEffectAction i' pl pl
Just _ -> abortWith "you cannot drink that"
Nothing -> neverMind True
playerAdvanceTime
@@ -994,3 +989,38 @@ regenerateLevelHP =
-- via sending one hero to a safe level and waiting there.
modify (updateLevel (updateHeroes (IM.map upd)))
modify (updateLevel (updateMonsters (IM.map upd)))
+
+-- | The source actor affects the target actor, with a given effect and power.
+-- Both actors are on the current level and can be the same actor.
+-- The bool result indicates if the actors identify the effect.
+effectToAction :: Effect.Effect -> Actor -> Actor -> Int -> Action Bool
+effectToAction Effect.NoEffect source target power = return False
+effectToAction (Effect.AffectHP n) source target power
+ | n > 0 = do
+ m <- gets (getActor target)
+ if mhp m >= nhpMax (mkind m)
+ then return False
+ else do
+ let upd m = m { mhp = min (nhpMax (mkind m)) (mhp m + n + power) }
+ modify (updateAnyActorBody target upd)
+ pl <- gets splayer
+ when (target == pl) $ messageAdd "You feel better." -- TODO: msg, if perceived, etc.
+ return True
+ | n < 0 = return False -- TODO
+ | otherwise = return False -- TODO
+effectToAction Effect.Dominate source target power = return False -- TODO
+effectToAction Effect.SummonFriend source target power = return False -- TODO
+effectToAction Effect.SummonEnemy source target power = return False -- TODO
+effectToAction Effect.ApplyWater _ target _ =
+ if isAHero target -- Monsters ignore water splashed on them.
+ then messageAdd "Tastes like water." >> return True
+ else return False
+
+-- | The source actor affects the target actor, with a given item.
+-- If either actor is a hero, the item may get identified (domination ignored).
+itemEffectAction :: Item -> Actor -> Actor -> Action ()
+itemEffectAction item source target = do
+ let effect = ItemKind.jeffect $ ItemKind.getIK $ ikind item
+ b <- effectToAction effect source target (ipower item)
+ -- If something happens, the item gets identified.
+ when (b && (isAHero source || isAHero target)) $ discover item
View
@@ -6,6 +6,7 @@ data Effect =
| Dominate
| SummonFriend
| SummonEnemy
+ | ApplyWater
deriving (Show, Eq, Ord)
effectToName :: Effect -> String
@@ -17,3 +18,4 @@ effectToName (AffectHP n)
effectToName Dominate = "of domination"
effectToName SummonFriend = "of aid calling"
effectToName SummonEnemy = "of summoning"
+effectToName ApplyWater = "of water"
View
@@ -63,12 +63,11 @@ objectItem state o =
kind = ItemKind.getIK ik
identified = L.length (jflavour kind) == 1 ||
ik `S.member` sdiscoveries state
+ addSpace s = if s == "" then "" else " " ++ s
eff = effectToName (jeffect kind)
- pwr = if ipower o == 0 then "" else " (+" ++ show (ipower o) ++ ")"
+ pwr = if ipower o == 0 then "" else "(+" ++ show (ipower o) ++ ")"
adj name = if identified
- then name ++ if jsecret kind == ""
- then if eff == "" then pwr else " " ++ eff ++ pwr
- else " " ++ jsecret kind ++ pwr
+ then name ++ addSpace eff ++ addSpace pwr
else let flavour = getFlavour (sassocs state) ik
in flavourToName flavour ++ " " ++ name
in makeObject (icount o) adj (jname kind)
View
@@ -11,7 +11,6 @@ data ItemKind = ItemKind
{ jsymbol :: !Char
, jflavour :: [Flavour]
, jname :: String
- , jsecret :: String
, jeffect :: Effect
, jquant :: Roll
, jfreq :: !Int
@@ -59,7 +58,6 @@ amulet = ItemKind
{ jsymbol = '"'
, jflavour = [(BrWhite, True)]
, jname = "amulet"
- , jsecret = ""
, jeffect = NoEffect
, jquant = rollOne
, jfreq = 10
@@ -68,7 +66,6 @@ dart = ItemKind
{ jsymbol = ')'
, jflavour = [(Yellow, False)]
, jname = "dart"
- , jsecret = ""
, jeffect = AffectHP (-1)
, jquant = (3, 0, 6, 0)
, jfreq = 40
@@ -77,7 +74,6 @@ gem = ItemKind
{ jsymbol = '*'
, jflavour = zipPlain brightCol -- natural, so not fancy
, jname = "gem"
- , jsecret = ""
, jeffect = NoEffect
, jquant = rollOne
, jfreq = 5 -- x4, below
@@ -89,7 +85,6 @@ gold = ItemKind
{ jsymbol = '$'
, jflavour = [(BrYellow, False)]
, jname = "gold piece"
- , jsecret = ""
, jeffect = NoEffect
, jquant = (0, 3, 0, 10)
, jfreq = 80
@@ -98,13 +93,12 @@ potion = ItemKind
{ jsymbol = '!'
, jflavour = zipFancy stdCol
, jname = "potion"
- , jsecret = ""
, jeffect = NoEffect
, jquant = rollOne
, jfreq = 20
}
potion_water = potion
- { jsecret = "of water"
+ { jeffect = ApplyWater
}
potion_healing = potion
{ jeffect = AffectHP 20
@@ -113,7 +107,6 @@ ring = ItemKind
{ jsymbol = '='
, jflavour = [(BrWhite, False)]
, jname = "ring"
- , jsecret = ""
, jeffect = NoEffect
, jquant = rollOne
, jfreq = 10
@@ -122,7 +115,6 @@ scroll = ItemKind
{ jsymbol = '?'
, jflavour = zipFancy darkCol -- arcane and old
, jname = "scroll"
- , jsecret = ""
, jeffect = NoEffect
, jquant = rollOne
, jfreq = 10
@@ -131,7 +123,6 @@ sword = ItemKind
{ jsymbol = ')'
, jflavour = [(BrCyan, False)]
, jname = "sword"
- , jsecret = ""
, jeffect = AffectHP (-3)
, jquant = rollOne
, jfreq = 70
@@ -141,7 +132,6 @@ wand = ItemKind
, jflavour = [(BrRed, True)]
, jname = "wand"
, jeffect = NoEffect
- , jsecret = ""
, jquant = rollOne
, jfreq = 30
}

0 comments on commit 20a0752

Please sign in to comment.