Skip to content

Commit

Permalink
fix messages and removing items from a dead hero's inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj committed Mar 31, 2011
1 parent e55bb95 commit a8a3c43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
8 changes: 6 additions & 2 deletions src/EffectAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import qualified Effect
-- | 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.
-- TODO: separately define messages for the case when source == target
-- and for the other case; then use the messages outside of effectToAction,
-- depending on the returned bool, perception and identity of the actors.
effectToAction :: Effect.Effect -> Actor -> Actor -> Int -> String ->
Action Bool
effectToAction Effect.NoEffect source target power msg = do
Expand All @@ -55,7 +58,8 @@ effectToAction Effect.Heal source target power msg = do
let upd m = m { mhp = min (nhpMax (mkind m)) (mhp m + power) }
updateAnyActor target upd
pl <- gets splayer
when (target == pl) $ messageAdd "You feel better." -- TODO: use msg, if perceived, etc. Eliminate "you" in singular, but keep it in plural.
when (target == pl) $
messageAdd $ subjectMovableVerb (mkind m) "feel" ++ " better."
return True
effectToAction (Effect.Wound nDm) source target power msg = do
n <- liftIO $ rndToIO $ rollDice nDm
Expand All @@ -74,7 +78,7 @@ effectToAction (Effect.Wound nDm) source target power msg = do
then return () -- Unseen monster quaffs a potion of wounding.
else messageAdd $
if source == target && target == pl
then "You feel wounded."
then subjectMovableVerb (mkind tm) "feel" ++ " wounded."
else if not tvis
then "You hear some noises."
else if source == target || not svis
Expand Down
2 changes: 1 addition & 1 deletion src/Grammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ subjectVerbMObject m v o add =
objectMovable (mkind o) ++ add ++ "."

subjCompoundVerbIObj :: State -> Movable -> String -> String ->
Item -> String -> String
Item -> String -> String
subjCompoundVerbIObj state m v p o add =
subjectMovable (mkind m) ++ " " ++
compoundVerbMovable (mkind m) v p ++ " " ++
Expand Down
29 changes: 16 additions & 13 deletions src/ItemAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ inventory :: Action a
inventory = do
items <- gets (mitems . getPlayerBody)
if L.null items
then abortWith "You are not carrying anything."
then abortWith "Not carrying anything."
else do
displayItems "This is what you are carrying:" True items
displayItems "Carrying:" True items
session getConfirm
abortWith ""

Expand All @@ -71,7 +71,7 @@ applyGroupItem groupName verb = do
pbody <- gets getPlayerBody
is <- gets (mitems . getPlayerBody)
iOpt <- getGroupItem is groupName
("What to " ++ verb ++ "?") "in your inventory"
("What to " ++ verb ++ "?") "in inventory"
case iOpt of
Just item@(Item { ikind = ik }) -> do
-- only one item consumed, even if several in inventory
Expand All @@ -82,7 +82,7 @@ applyGroupItem groupName verb = do
message (subjectVerbIObject state pbody v consumed "")
pl <- gets splayer
b <- itemEffectAction consumed pl pl
when b $ removeFromInventory consumed
when b $ removeFromInventory consumed (mloc pbody)
Nothing -> neverMind True
playerAdvanceTime

Expand All @@ -97,15 +97,15 @@ zapGroupItem groupName verb = do
target <- gets (mtarget . getPlayerBody)
pl <- gets splayer
iOpt <- getGroupItem is groupName
("What to " ++ verb ++ "?") "in your inventory"
("What to " ++ verb ++ "?") "in inventory"
case iOpt of
Just item@(Item { ikind = ik }) -> do
-- only one item consumed, even if several in inventory
let v = if ItemKind.jname (ItemKind.getIK ik) == groupName
then verb
else "furiously zap"
consumed = item { icount = 1 }
removeFromInventory consumed
removeFromInventory consumed (mloc pbody)
case targetToLoc (ptvisible per) state of
Nothing -> abortWith "target invalid"
Just loc ->
Expand Down Expand Up @@ -144,18 +144,21 @@ dropItem = do
iOpt <- getAnyItem "What to drop?" items "inventory"
case iOpt of
Just i -> do
removeFromInventory i
removeFromInventory i (mloc pbody)
message (subjectVerbIObject state pbody "drop" i "")
modify (updateLevel (dropItemsAt [i] ploc))
Nothing -> neverMind True
playerAdvanceTime

-- | Remove given item from the hero's inventory or floor.
-- TODO: this is subtly wrong: if identical items are on the floor and in
-- inventory, the floor one will be chosen, regardless of player intention..
removeFromInventory :: Item -> Action ()
removeFromInventory i = do
ploc <- gets (mloc . getPlayerBody)
-- inventory, the floor one will be chosen, regardless of player intention.
-- TODO: right now it ugly hacks (with the ploc) around removing items
-- of dead heros/monsters. The subtle incorrectness helps here a lot,
-- because itmes of dead heroes land on the floor, so we used them up
-- in inventory, but remove them after use from the floor.
removeFromInventory :: Item -> Loc -> Action ()
removeFromInventory i ploc = do
b <- removeFromLoc i ploc
when (not b) $
updatePlayerBody (\ p -> p { mitems = removeItemByLetter i (mitems p) })
Expand Down Expand Up @@ -200,7 +203,7 @@ actorPickupItem actor = do
-- add item to actor's inventory:
updateAnyActor actor $ \ m ->
m { mitems = nitems, mletter = maxLetter l (mletter body) }
Nothing -> abortIfWith isPlayer "you cannot carry any more"
Nothing -> abortIfWith isPlayer "cannot carry any more"
advanceTime actor

pickupItem :: Action ()
Expand Down Expand Up @@ -252,7 +255,7 @@ getItem prompt p ptext is0 isn = do
in "[" ++ r ++ ", ?, *," ++ floorMsg ++ " RET, ESC]"
interact = do
when (L.null is0 && L.null tis) $
abortWith "You are not carrying anything."
abortWith "Not carrying anything."
message (prompt ++ " " ++ choice)
display
session nextCommand >>= perform
Expand Down

0 comments on commit a8a3c43

Please sign in to comment.