mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-07-07 01:04:25 +03:00
Taking things (issue #4)
This commit is contained in:
parent
9c40443c8f
commit
373d703fe0
|
@ -11,6 +11,7 @@ salet = Salet({
|
||||||
})
|
})
|
||||||
$(document).ready(() ->
|
$(document).ready(() ->
|
||||||
salet.beginGame()
|
salet.beginGame()
|
||||||
|
salet.character.bought_lamp = false
|
||||||
)
|
)
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
|
@ -69,7 +69,7 @@ room "lair", salet,
|
||||||
dsc: "You see a particularly beautiful slimy {{bugg.}}"
|
dsc: "You see a particularly beautiful slimy {{bugg.}}"
|
||||||
takeable: false
|
takeable: false
|
||||||
act: (salet) =>
|
act: (salet) =>
|
||||||
salet.rooms[salet.current].drop(@name)
|
salet.rooms[salet.current].drop("bugg")
|
||||||
return "You eat the bugg mass. Delicious and raw. Perhaps it's a good lair to live in."
|
return "You eat the bugg mass. Delicious and raw. Perhaps it's a good lair to live in."
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -79,6 +79,21 @@ phrase "Yes", salet, "merchant", """
|
||||||
dialogue "No", salet, "merchant", "merchant", """
|
dialogue "No", salet, "merchant", "merchant", """
|
||||||
No.
|
No.
|
||||||
"""
|
"""
|
||||||
|
room "sell-lamp", salet,
|
||||||
|
ways: ["shop"]
|
||||||
|
tags: ["merchant"]
|
||||||
|
choices: ["#merchant"]
|
||||||
|
optionText: "May I buy this lamp?"
|
||||||
|
title: "Talking with merchant"
|
||||||
|
canView: (salet) ->
|
||||||
|
return salet.character.has("lamp") and salet.character.bought_lamp == false
|
||||||
|
enter: (salet) ->
|
||||||
|
salet.character.bought_lamp = true
|
||||||
|
dsc: """
|
||||||
|
"That'll be 30 pieces of your time."
|
||||||
|
|
||||||
|
You quickly pay the price and take the lamp as a rightful owner.
|
||||||
|
"""
|
||||||
|
|
||||||
room "shop-inside", salet,
|
room "shop-inside", salet,
|
||||||
ways: ["shop"]
|
ways: ["shop"]
|
||||||
|
|
|
@ -10,6 +10,12 @@ class Character
|
||||||
index = @objects.indexOf(thing)
|
index = @objects.indexOf(thing)
|
||||||
@inventory.splice(index, 1)
|
@inventory.splice(index, 1)
|
||||||
|
|
||||||
|
@has = (thing) =>
|
||||||
|
for i in @inventory
|
||||||
|
if i.name == thing
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
for index, value of spec
|
for index, value of spec
|
||||||
this[index] = value
|
this[index] = value
|
||||||
return this
|
return this
|
||||||
|
|
|
@ -147,8 +147,8 @@ class SaletRoom
|
||||||
@drop = (name) =>
|
@drop = (name) =>
|
||||||
for thing in @objects
|
for thing in @objects
|
||||||
if thing.name == name
|
if thing.name == name
|
||||||
index = @objects.indexOf(thing)
|
@objects.splice(@objects.indexOf(thing), 1)
|
||||||
@objects.splice(index, 1)
|
return @objects
|
||||||
|
|
||||||
###
|
###
|
||||||
Object action. A function or a string which comes when you click on the object link.
|
Object action. A function or a string which comes when you click on the object link.
|
||||||
|
@ -163,11 +163,9 @@ class SaletRoom
|
||||||
# If not, we check the "act" function.
|
# If not, we check the "act" function.
|
||||||
if thing.takeable
|
if thing.takeable
|
||||||
system.character.take(thing)
|
system.character.take(thing)
|
||||||
@drop name
|
@drop link[2]
|
||||||
system.view.clearContent()
|
|
||||||
@entering.fcall(this, system, @name)
|
|
||||||
return system.view.write(thing.take.fcall(thing, system).toString())
|
return system.view.write(thing.take.fcall(thing, system).toString())
|
||||||
if thing.act?
|
else if thing.act?
|
||||||
return system.view.write thing.act.fcall(thing, system)
|
return system.view.write thing.act.fcall(thing, system)
|
||||||
|
|
||||||
# the loop is done but no return came - match not found
|
# the loop is done but no return came - match not found
|
||||||
|
|
|
@ -275,14 +275,18 @@ class Salet
|
||||||
# Carry out the action
|
# Carry out the action
|
||||||
if (action)
|
if (action)
|
||||||
room = @getCurrentRoom()
|
room = @getCurrentRoom()
|
||||||
if (room and @beforeAction)
|
if room
|
||||||
|
consumed = false
|
||||||
|
|
||||||
|
if @beforeAction
|
||||||
# Try the global act handler
|
# Try the global act handler
|
||||||
consumed = @beforeAction(room, action)
|
consumed = @beforeAction(room, action)
|
||||||
if (consumed != true)
|
|
||||||
|
if consumed != true
|
||||||
room.act(this, action)
|
room.act(this, action)
|
||||||
|
|
||||||
if (@afterAction)
|
if @afterAction
|
||||||
@afterAction(this, room, action)
|
@afterAction(room, action)
|
||||||
|
|
||||||
# This gets called when the user clicks a link to carry out an action.
|
# This gets called when the user clicks a link to carry out an action.
|
||||||
@processClick = (code) =>
|
@processClick = (code) =>
|
||||||
|
|
|
@ -30,9 +30,9 @@ class SaletView
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
a = $(this)
|
a = $(this)
|
||||||
href = a.attr('href')
|
href = a.attr('href')
|
||||||
if (href.match(salet.linkRe))
|
if a.hasClass("once") || href.match(/[?&]once[=&]?/)
|
||||||
if (a.hasClass("once") || href.match(/[?&]once[=&]?/))
|
|
||||||
salet.view.clearLinks(href)
|
salet.view.clearLinks(href)
|
||||||
|
if href.match(salet.linkRe)
|
||||||
salet.processClick(href)
|
salet.processClick(href)
|
||||||
)
|
)
|
||||||
$("#inventory").on("click", "a", (event) ->
|
$("#inventory").on("click", "a", (event) ->
|
||||||
|
|
Loading…
Reference in a new issue