Allow items to veto being taken.
This commit is contained in:
+19
-11
@@ -8,10 +8,13 @@ class GameLog
|
|||||||
@content += "<br>> " + text + "<br>"
|
@content += "<br>> " + text + "<br>"
|
||||||
@onChange(this)
|
@onChange(this)
|
||||||
|
|
||||||
writeln: (text="")->
|
write: (text="")->
|
||||||
@content += text.replace(/\n/g, "<br>") + "<br>"
|
@content += text.replace(/\n/g, "<br>")
|
||||||
@onChange(this)
|
@onChange(this)
|
||||||
|
|
||||||
|
writeln: (text="")->
|
||||||
|
@write(text + "\n")
|
||||||
|
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@@ -63,10 +66,16 @@ class Item
|
|||||||
|
|
||||||
@description = "non-descript item"
|
@description = "non-descript item"
|
||||||
@fixed = options.fixed
|
@fixed = options.fixed
|
||||||
|
@story = null
|
||||||
|
|
||||||
# Public Methods ###############################################################################
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
attemptTake: ->
|
take: ->
|
||||||
|
if @fixed
|
||||||
|
@story.log.writeln("You cannot take the #{@name}.")
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
@story.log.writeln("Taken.")
|
||||||
return true
|
return true
|
||||||
|
|
||||||
describe: ->
|
describe: ->
|
||||||
@@ -320,23 +329,21 @@ class Player
|
|||||||
take: (item)->
|
take: (item)->
|
||||||
localItems = @story.currentLocation.inventory
|
localItems = @story.currentLocation.inventory
|
||||||
if not item
|
if not item
|
||||||
tookSomething = false
|
foundTakeableItem = false
|
||||||
localItems.eachItem (item)=>
|
localItems.eachItem (item)=>
|
||||||
if not item.fixed
|
if not item.fixed
|
||||||
|
@story.log.write("#{item}: ")
|
||||||
|
foundTakeableItem = true
|
||||||
@take(item)
|
@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)
|
else if localItems.has(item)
|
||||||
console.log(item)
|
console.log(item)
|
||||||
if not item.fixed
|
if item.take()
|
||||||
localItems.remove(item)
|
localItems.remove(item)
|
||||||
@inventory.add(item)
|
@inventory.add(item)
|
||||||
@story.log.writeln("Took the #{item.name}.")
|
|
||||||
else
|
else
|
||||||
@story.log.writeln("You can't take the #{item.name}.")
|
throw new ParseError("There isn't a #{item} here.")
|
||||||
else
|
|
||||||
throw new ParseError("You can't take #{item} because there isn't one here.")
|
|
||||||
|
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
@@ -407,6 +414,7 @@ class Story
|
|||||||
|
|
||||||
addItem: (name, options={})->
|
addItem: (name, options={})->
|
||||||
item = new Item(name, options)
|
item = new Item(name, options)
|
||||||
|
item.story = this
|
||||||
@items.push(item)
|
@items.push(item)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -2,10 +2,13 @@ window.STORY = s = new Story("A Walk Through My House")
|
|||||||
|
|
||||||
# Items ################################################################################################################
|
# Items ################################################################################################################
|
||||||
|
|
||||||
boxOfTile = s.addItem("box of tiles", fixed: true)
|
boxOfTile = s.addItem("box of tiles")
|
||||||
boxOfTile.description =
|
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
|
"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."
|
quite heavy."
|
||||||
|
boxOfTile.take = ->
|
||||||
|
s.log.writeln("Oof! It's too heavy.")
|
||||||
|
return false
|
||||||
|
|
||||||
hose = s.addItem("garden hose")
|
hose = s.addItem("garden hose")
|
||||||
hose.description = "It's a pretty ordinary garden hose about 20' long."
|
hose.description = "It's a pretty ordinary garden hose about 20' long."
|
||||||
|
|||||||
Reference in New Issue
Block a user