Skip to content

Commit

Permalink
drop individual items instead of whole stacks
Browse files Browse the repository at this point in the history
TODO: dropping all or a given number of identical items would be nice, too.
  • Loading branch information
Mikolaj committed Apr 17, 2011
1 parent fc550fc commit e1d2492
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ItemAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ aimItem = playerZapGroupItem "wand"
throwItem :: Action ()
throwItem = playerZapGroupItem "dart"

-- | Drop a single item.
-- TODO: allow dropping a given number of identical items.
dropItem :: Action ()
dropItem = do
pl <- gets splayer
Expand All @@ -168,13 +170,20 @@ dropItem = do
items <- gets (mitems . getPlayerBody)
iOpt <- getAnyItem "What to drop?" items "inventory"
case iOpt of
Just i -> do
removeFromInventory pl i (mloc pbody)
Just stack -> do
let i = stack { icount = 1 }
removeOnlyFromInventory pl i (mloc pbody)
messageAdd (subjectVerbIObject state pbody "drop" i "")
modify (updateLevel (dropItemsAt [i] ploc))
Nothing -> neverMind True
playerAdvanceTime

-- TODO: this is a hack for dropItem, because removeFromInventory
-- makes it impossible to drop items if the floor not empty.
removeOnlyFromInventory :: Actor -> Item -> Loc -> Action ()
removeOnlyFromInventory actor i loc = do
updateAnyActor actor (\ m -> m { mitems = removeItemByLetter i (mitems m) })

-- | Remove given item from an actor'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.
Expand Down

0 comments on commit e1d2492

Please sign in to comment.