Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add 2 scrolls

  • Loading branch information...
commit 2ace9a437d4c56ea724a44e071fbe2a0b7c260db 1 parent c26a3d8
@Mikolaj Mikolaj authored
View
50 src/Actions.hs
@@ -621,9 +621,7 @@ drinkPotion :: Action ()
drinkPotion =
do
state <- get
- lmap <- gets (lmap . slevel)
pbody <- gets getPlayerBody
- ploc <- gets (mloc . getPlayerBody)
items <- gets (mitems . getPlayerBody)
pl <- gets splayer
if L.null items
@@ -639,12 +637,36 @@ drinkPotion =
let consumed = i' { icount = 1 }
removeFromInventory consumed
message (subjectVerbIObject state pbody "drink" consumed "")
- -- the potion is identified after drinking
itemEffectAction i' pl pl
Just _ -> abortWith "you cannot drink that"
Nothing -> neverMind True
playerAdvanceTime
+readScroll :: Action ()
+readScroll =
+ do
+ state <- get
+ pbody <- gets getPlayerBody
+ items <- gets (mitems . getPlayerBody)
+ pl <- gets splayer
+ if L.null items
+ then abortWith "You are not carrying anything."
+ else do
+ i <- getScroll "What to read?" items "inventory"
+ case i of
+ Just i'@(Item { ikind = ik })
+ | ItemKind.jname (ItemKind.getIK ik) == "scroll" ->
+ do
+ -- only one scroll is consumed even if several
+ -- are joined in the inventory
+ let consumed = i' { icount = 1 }
+ removeFromInventory consumed
+ message (subjectVerbIObject state pbody "read" consumed "")
+ itemEffectAction i' pl pl
+ Just _ -> abortWith "you cannot read that"
+ Nothing -> neverMind True
+ playerAdvanceTime
+
fireItem :: Action ()
fireItem = do
state <- get
@@ -667,16 +689,16 @@ fireItem = do
Nothing -> abortWith "nothing to fire"
playerAdvanceTime
-applyItem :: Action ()
-applyItem = do
+zapItem :: Action ()
+zapItem = do
pl <- gets splayer
state <- get
per <- currentPerception
pitems <- gets (mitems . getPlayerBody)
case findItem (\ i -> ItemKind.jname (ItemKind.getIK (ikind i)) == "wand") pitems of
Just (wand, _) -> do
- let applied = wand { icount = 1 }
- removeFromInventory applied
+ let zapped = wand { icount = 1 }
+ removeFromInventory zapped
case targetToLoc (ptvisible per) state of
Nothing -> abortWith "target invalid"
Just loc ->
@@ -685,7 +707,7 @@ applyItem = do
Just ta -> itemEffectAction wand pl ta
Nothing -> abortWith "no living target to affect"
else abortWith "target not reachable"
- Nothing -> abortWith "nothing to apply"
+ Nothing -> abortWith "nothing to zap"
playerAdvanceTime
dropItem :: Action ()
@@ -724,7 +746,8 @@ removeFromLoc i loc =
adj = M.adjust (\ (t, rt) -> (remove t, rt)) loc
remove t = t { titems = removeItemByKind i (titems t) }
--- | Let the player choose any potion. Note that this does not guarantee a potion to be chosen,
+-- | Let the player choose any potion.
+-- Note that this does not guarantee a potion to be chosen,
-- as the player can override the choice.
getPotion :: String -> -- prompt
[Item] -> -- all objects in question
@@ -735,6 +758,15 @@ getPotion prompt is isn =
let choice i = ItemKind.jname (ItemKind.getIK (ikind i)) == "potion"
in getItem prompt choice "Potions" is isn
+getScroll :: String -> -- prompt
+ [Item] -> -- all objects in question
+ String -> -- how to refer to the collection of objects,
+ -- e.g., "in your inventory"
+ Action (Maybe Item)
+getScroll prompt is isn =
+ let choice i = ItemKind.jname (ItemKind.getIK (ikind i)) == "scroll"
+ in getItem prompt choice "Scrolls" is isn
+
actorPickupItem :: Actor -> Action ()
actorPickupItem actor =
do
View
3  src/Command.hs
@@ -22,8 +22,9 @@ descendCommand = Described "descend a level" (lvlchange Down)
floorCommand = Described "target location" targetFloor
monsterCommand = Described "target monster" (checkCursor targetMonster)
drinkCommand = Described "quaff a potion" drinkPotion
+readCommand = Described "read a scroll" readScroll
fireCommand = Described "fire an item" (checkCursor fireItem)
-applyCommand = Described "aim a wand " (checkCursor applyItem) -- TODO: change descriptions as soon as the command generalized and requires specifying an item
+zapCommand = Described "zap an item" (checkCursor zapItem)
waitCommand = Described "wait" playerAdvanceTime
saveCommand = Described "save and quit the game" saveGame
quitCommand = Described "quit without saving" quitGame
View
9 src/Item.hs
@@ -162,12 +162,15 @@ removeItemBy eq i = concatMap $ \ x ->
else [x]
equalItemKindAndPower :: Item -> Item -> Bool
-equalItemKindAndPower i1 i2 = equalItemKind i1 i2 && ipower i1 == ipower i2
+equalItemKindAndPower i1 i2 = equalItemKind i1 i2 && equalItemPower i1 i2
+
+equalItemPower :: Item -> Item -> Bool
+equalItemPower = (==) `on` ipower
equalItemKind :: Item -> Item -> Bool
-equalItemKind = (==) `on` (jname . getIK . ikind)
+equalItemKind = (==) `on` ikind
-removeItemByKind = removeItemBy equalItemKind
+removeItemByKind = removeItemBy equalItemKind
equalItemLetter :: Item -> Item -> Bool
equalItemLetter = (==) `on` iletter
View
25 src/ItemKind.hs
@@ -45,14 +45,19 @@ getIK ik = dungeonLoot IM.! ik
loot :: [ItemKind]
loot =
- [amulet, dart, gem, gem1, gem2, gem3, gold,
+ [amulet,
+ dart,
+ gem, gem1, gem2, gem3,
+ gold,
potion_water, potion_healing,
- ring, scroll, sword,
+ ring,
+ scroll1, scroll2,
+ sword,
wand_domination]
amulet, dart, gem, gem1, gem2, gem3, gold :: ItemKind
potion, potion_water, potion_healing :: ItemKind
-ring, scroll, sword :: ItemKind
+ring, scroll, scroll1, scroll2, sword :: ItemKind
wand, wand_domination :: ItemKind
amulet = ItemKind
{ jsymbol = '"'
@@ -68,7 +73,7 @@ dart = ItemKind
, jname = "dart"
, jeffect = Wound 1
, jquant = (3, 0, 6, 0)
- , jfreq = 40
+ , jfreq = 30
}
gem = ItemKind
{ jsymbol = '*'
@@ -95,7 +100,7 @@ potion = ItemKind
, jname = "potion"
, jeffect = NoEffect
, jquant = rollOne
- , jfreq = 20
+ , jfreq = 20 -- x2
}
potion_water = potion
{ jeffect = ApplyWater
@@ -117,7 +122,13 @@ scroll = ItemKind
, jname = "scroll"
, jeffect = NoEffect
, jquant = rollOne
- , jfreq = 10
+ , jfreq = 10 -- x2
+ }
+scroll1 = scroll
+ { jeffect = SummonFriend
+ }
+scroll2 = scroll
+ { jeffect = SummonEnemy
}
sword = ItemKind
{ jsymbol = ')'
@@ -125,7 +136,7 @@ sword = ItemKind
, jname = "sword"
, jeffect = Wound 3
, jquant = rollOne
- , jfreq = 70
+ , jfreq = 60
}
wand = ItemKind
{ jsymbol = '/'
View
3  src/Turn.hs
@@ -245,8 +245,9 @@ stdKeybindings = Keybindings
(K.Char 'd', dropCommand),
(K.Char 'i', inventoryCommand),
(K.Char 'q', drinkCommand),
+ (K.Char 'r', readCommand),
(K.Char 'f', fireCommand),
- (K.Char 'a', applyCommand),
+ (K.Char 'z', zapCommand),
-- wait
-- (K.Char ' ', waitCommand),
Please sign in to comment.
Something went wrong with that request. Please try again.