Allow items to veto being taken.
This commit is contained in:
+19
-11
@@ -8,10 +8,13 @@ class GameLog
|
||||
@content += "<br>> " + 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
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user