mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-06-01 07:48:20 +03:00
Taking things (issue #4)
This commit is contained in:
parent
9c40443c8f
commit
373d703fe0
|
@ -11,6 +11,7 @@ salet = Salet({
|
|||
})
|
||||
$(document).ready(() ->
|
||||
salet.beginGame()
|
||||
salet.character.bought_lamp = false
|
||||
)
|
||||
|
||||
###
|
||||
|
|
|
@ -69,7 +69,7 @@ room "lair", salet,
|
|||
dsc: "You see a particularly beautiful slimy {{bugg.}}"
|
||||
takeable: false
|
||||
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."
|
||||
]
|
||||
|
||||
|
@ -79,6 +79,21 @@ phrase "Yes", salet, "merchant", """
|
|||
dialogue "No", salet, "merchant", "merchant", """
|
||||
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,
|
||||
ways: ["shop"]
|
||||
|
|
|
@ -9,7 +9,13 @@ class Character
|
|||
if i.name == thing
|
||||
index = @objects.indexOf(thing)
|
||||
@inventory.splice(index, 1)
|
||||
|
||||
|
||||
@has = (thing) =>
|
||||
for i in @inventory
|
||||
if i.name == thing
|
||||
return true
|
||||
return false
|
||||
|
||||
for index, value of spec
|
||||
this[index] = value
|
||||
return this
|
||||
|
|
|
@ -43,7 +43,7 @@ class SaletRoom
|
|||
###
|
||||
@exit = (system, to) =>
|
||||
return true
|
||||
|
||||
|
||||
###
|
||||
I call SaletRoom.enter every time the player enters this room but before the section is opened.
|
||||
Unlike @before this gets called before the current section is opened.
|
||||
|
@ -98,7 +98,7 @@ class SaletRoom
|
|||
|
||||
if @choices
|
||||
system.view.writeChoices(system, system.getSituationIdChoices(@choices, @maxChoices))
|
||||
|
||||
|
||||
if @afterChoices?
|
||||
@afterChoices.fcall(this, system, f)
|
||||
|
||||
|
@ -147,8 +147,8 @@ class SaletRoom
|
|||
@drop = (name) =>
|
||||
for thing in @objects
|
||||
if thing.name == name
|
||||
index = @objects.indexOf(thing)
|
||||
@objects.splice(index, 1)
|
||||
@objects.splice(@objects.indexOf(thing), 1)
|
||||
return @objects
|
||||
|
||||
###
|
||||
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 thing.takeable
|
||||
system.character.take(thing)
|
||||
@drop name
|
||||
system.view.clearContent()
|
||||
@entering.fcall(this, system, @name)
|
||||
@drop link[2]
|
||||
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)
|
||||
|
||||
# the loop is done but no return came - match not found
|
||||
|
@ -241,7 +239,7 @@ class SaletRoom
|
|||
for index, value of spec
|
||||
this[index] = value
|
||||
return this
|
||||
|
||||
|
||||
room = (name, salet, spec) ->
|
||||
spec ?= {}
|
||||
spec.name = name
|
||||
|
|
|
@ -275,14 +275,18 @@ class Salet
|
|||
# Carry out the action
|
||||
if (action)
|
||||
room = @getCurrentRoom()
|
||||
if (room and @beforeAction)
|
||||
# Try the global act handler
|
||||
consumed = @beforeAction(room, action)
|
||||
if (consumed != true)
|
||||
if room
|
||||
consumed = false
|
||||
|
||||
if @beforeAction
|
||||
# Try the global act handler
|
||||
consumed = @beforeAction(room, action)
|
||||
|
||||
if consumed != true
|
||||
room.act(this, action)
|
||||
|
||||
if (@afterAction)
|
||||
@afterAction(this, room, action)
|
||||
if @afterAction
|
||||
@afterAction(room, action)
|
||||
|
||||
# This gets called when the user clicks a link to carry out an action.
|
||||
@processClick = (code) =>
|
||||
|
|
|
@ -30,9 +30,9 @@ class SaletView
|
|||
event.preventDefault()
|
||||
a = $(this)
|
||||
href = a.attr('href')
|
||||
if (href.match(salet.linkRe))
|
||||
if (a.hasClass("once") || href.match(/[?&]once[=&]?/))
|
||||
salet.view.clearLinks(href)
|
||||
if a.hasClass("once") || href.match(/[?&]once[=&]?/)
|
||||
salet.view.clearLinks(href)
|
||||
if href.match(salet.linkRe)
|
||||
salet.processClick(href)
|
||||
)
|
||||
$("#inventory").on("click", "a", (event) ->
|
||||
|
|
Loading…
Reference in a new issue