Allow items to veto being taken.

This commit is contained in:
Andrew Miner
2018-05-28 15:31:56 -06:00
parent 56daf2ef62
commit 2e7772b488
2 changed files with 24 additions and 13 deletions
+19 -11
View File
@@ -8,10 +8,13 @@ class GameLog
@content += "<br>&gt; " + text + "<br>"
@onChange(this)
writeln: (text="")->
@content += text.replace(/\n/g, "<br>") + "<br>"
write: (text="")->
@content += text.replace(/\n/g, "<br>")
@onChange(this)
writeln: (text="")->
@write(text + "\n")
########################################################################################################################
@@ -63,10 +66,16 @@ class Item
@description = "non-descript item"
@fixed = options.fixed
@story = null
# Public Methods ###############################################################################
attemptTake: ->
take: ->
if @fixed
@story.log.writeln("You cannot take the #{@name}.")
return false
else
@story.log.writeln("Taken.")
return true
describe: ->
@@ -320,23 +329,21 @@ class Player
take: (item)->
localItems = @story.currentLocation.inventory
if not item
tookSomething = false
foundTakeableItem = false
localItems.eachItem (item)=>
if not item.fixed
@story.log.write("#{item}: ")
foundTakeableItem = true
@take(item)
tookSomething = true
if not tookSomething then @story.log.writeln("There's nothing here you can take.")
if not foundTakeableItem then @story.log.writeln("There's nothing here you can take.")
else if localItems.has(item)
console.log(item)
if not item.fixed
if item.take()
localItems.remove(item)
@inventory.add(item)
@story.log.writeln("Took the #{item.name}.")
else
@story.log.writeln("You can't take the #{item.name}.")
else
throw new ParseError("You can't take #{item} because there isn't one here.")
throw new ParseError("There isn't a #{item} here.")
########################################################################################################################
@@ -407,6 +414,7 @@ class Story
addItem: (name, options={})->
item = new Item(name, options)
item.story = this
@items.push(item)
return item
+4 -1
View File
@@ -2,10 +2,13 @@ window.STORY = s = new Story("A Walk Through My House")
# Items ################################################################################################################
boxOfTile = s.addItem("box of tiles", fixed: true)
boxOfTile = s.addItem("box of tiles")
boxOfTile.description =
"This appears to be a box of flooring tiles. The tiles appear to be a very light color of natural stone. It is
quite heavy."
boxOfTile.take = ->
s.log.writeln("Oof! It's too heavy.")
return false
hose = s.addItem("garden hose")
hose.description = "It's a pretty ordinary garden hose about 20' long."