1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-04 07:45:03 +03:00

Taking things (issue #4)

This commit is contained in:
Alexander Yakovlev 2016-03-20 19:41:47 +07:00
parent 9c40443c8f
commit 373d703fe0
6 changed files with 44 additions and 20 deletions

View file

@ -11,6 +11,7 @@ salet = Salet({
}) })
$(document).ready(() -> $(document).ready(() ->
salet.beginGame() salet.beginGame()
salet.character.bought_lamp = false
) )
### ###

View file

@ -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"]

View file

@ -9,7 +9,13 @@ class Character
if i.name == thing if i.name == thing
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

View file

@ -43,7 +43,7 @@ class SaletRoom
### ###
@exit = (system, to) => @exit = (system, to) =>
return true return true
### ###
I call SaletRoom.enter every time the player enters this room but before the section is opened. 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. Unlike @before this gets called before the current section is opened.
@ -98,7 +98,7 @@ class SaletRoom
if @choices if @choices
system.view.writeChoices(system, system.getSituationIdChoices(@choices, @maxChoices)) system.view.writeChoices(system, system.getSituationIdChoices(@choices, @maxChoices))
if @afterChoices? if @afterChoices?
@afterChoices.fcall(this, system, f) @afterChoices.fcall(this, system, f)
@ -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
@ -241,7 +239,7 @@ class SaletRoom
for index, value of spec for index, value of spec
this[index] = value this[index] = value
return this return this
room = (name, salet, spec) -> room = (name, salet, spec) ->
spec ?= {} spec ?= {}
spec.name = name spec.name = name

View file

@ -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
# Try the global act handler consumed = false
consumed = @beforeAction(room, action)
if (consumed != true) if @beforeAction
# Try the global act handler
consumed = @beforeAction(room, action)
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) =>

View file

@ -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) ->