Merge branch 'feature/item-combining'
This commit is contained in:
commit
08d58a0f01
4 changed files with 83 additions and 3 deletions
|
@ -16,5 +16,10 @@ see test-game/manifest.setage
|
|||
* [x] `input` provides case insensitive input checking
|
||||
* [x] `exact input` provides exact input checking
|
||||
* [x] `item check`, `item take` provides item checking
|
||||
* [ ] combining items and other item interactions
|
||||
* [ ]
|
||||
* [x] combining items and other item interactions
|
||||
* [x] basic
|
||||
* [x] multiple outputs
|
||||
* [x] lockable
|
||||
* [x] "item" = examine an item
|
||||
* [x] "room" = enter a room
|
||||
* [x] "interactable" = use an interactable
|
||||
|
|
14
docs.toml
14
docs.toml
|
@ -30,6 +30,20 @@ item.examine = "message when the `item` is examined" # `item` can be any item id
|
|||
item.hidden = false # optional, default.
|
||||
|
||||
|
||||
[recipes.recipeid] # Optional
|
||||
ingredients = ["itemid1", "itemid2", ...] # Required
|
||||
# --
|
||||
result_id = "itemid" # Required
|
||||
result_text = "shorttext of the result item" # Required
|
||||
# OR
|
||||
result_ids = ["id1", "id2", ...] # Required
|
||||
result_texts = ["text1", "text2", ...] # Required; short texts of the items
|
||||
# --
|
||||
text = "message when items get combined with this recipe" # Optional; default = "> You combined items."
|
||||
lock = "" # Optional; one of: item, room, interactable
|
||||
lock_target = "id" # Optional; of the lock above
|
||||
|
||||
|
||||
[rooms.id] # Required, id can be any other room id.
|
||||
description = "description of the room as it appears in the listing of exits from other rooms"
|
||||
examine = "description of the room when you examine it"
|
||||
|
|
46
setage.py
46
setage.py
|
@ -88,6 +88,8 @@ class SetageShell(Cmd):
|
|||
intro = ""
|
||||
prompt = "> "
|
||||
ruler = "~"
|
||||
interacted_with = set()
|
||||
rooms_been_in = set()
|
||||
|
||||
def cmdloop(self, intro=None):
|
||||
print(self.intro)
|
||||
|
@ -273,6 +275,7 @@ class SetageShell(Cmd):
|
|||
f"invalid `type` '{inter["type"]}' "
|
||||
f"in interactable '{arg}'")
|
||||
if can_activate:
|
||||
self.interacted_with.add(arg)
|
||||
if "target_room" not in inter:
|
||||
target_room = current_room_id
|
||||
else:
|
||||
|
@ -434,6 +437,7 @@ class SetageShell(Cmd):
|
|||
print(rooms[current_room_id]["go"])
|
||||
else:
|
||||
print(f"You went {arg}.")
|
||||
self.rooms_been_in.add(current_room_id)
|
||||
else:
|
||||
print("> I can't go there...")
|
||||
return self.check_win()
|
||||
|
@ -501,6 +505,48 @@ class SetageShell(Cmd):
|
|||
"""Check your inventory."""
|
||||
self.do_inventory(arg)
|
||||
|
||||
def do_combine(self, arg):
|
||||
"""Combine items: combine item1,item2"""
|
||||
recipes = manifest["recipes"]
|
||||
items = [a.strip() for a in arg.split(",")]
|
||||
if len(items) < 2:
|
||||
print("> Not enough items to combine...")
|
||||
return
|
||||
for item in items:
|
||||
if item not in inventory:
|
||||
print(f"> {item} not in inventory...")
|
||||
return
|
||||
for recipe in recipes.items():
|
||||
rec = recipe[1]
|
||||
can = True
|
||||
if rec["lock"]:
|
||||
can = False
|
||||
if rec["lock"] == "item":
|
||||
if rec["lock_target"] in inventory:
|
||||
can = True
|
||||
elif rec["lock"] == "interactable":
|
||||
if rec["lock_target"] in self.interacted_with:
|
||||
can = True
|
||||
elif rec["lock"] == "room":
|
||||
if rec["lock_target"] in self.rooms_been_in:
|
||||
can = True
|
||||
else:
|
||||
print(f"ERROR: Invalid lock type for recipe `{recipe[0]}`")
|
||||
return True
|
||||
if can:
|
||||
# FIXME: multiple recipes with same ingredients???
|
||||
if set(items) == set(rec["ingredients"]):
|
||||
print(rec["text"])
|
||||
for item in items:
|
||||
inventory.pop(item)
|
||||
if "result_ids" in rec:
|
||||
for idx, _id in enumerate(rec["result_ids"]):
|
||||
inventory[_id] = rec["result_texts"][idx]
|
||||
else:
|
||||
inventory[rec["result_id"]] = rec["result_text"]
|
||||
return self.check_win()
|
||||
print("> I can't combine these...")
|
||||
|
||||
def do_credits(self, arg):
|
||||
"""Print credits."""
|
||||
if "credits" not in metadata:
|
||||
|
|
|
@ -29,6 +29,19 @@ detergent.examine = "A bottle of detergent. Half-filled. Stinks."
|
|||
shiny.examine = "A heart-shaped shiny locket with a picture of a horse inside."
|
||||
shiny.hidden = true
|
||||
note.examine = "The note reads: there is a [shiny] hidden in one of the rooms of this house."
|
||||
stone.examine = "Ston. Rok."
|
||||
stick.examine = "stiC"
|
||||
weapon.examine = "wpn"
|
||||
trash.examine = "trasshhhhhhhhhhhhh"
|
||||
|
||||
|
||||
[recipes.weapon]
|
||||
text = "ooja booja"
|
||||
lock = "item"
|
||||
lock_target = "note"
|
||||
ingredients = ["stone", "stick"]
|
||||
result_ids = ["weapon", "trash"]
|
||||
result_texts = ["a weapon", "trsh"]
|
||||
|
||||
|
||||
[rooms.1]
|
||||
|
@ -37,6 +50,8 @@ go = "You walk into a room full of trash, garbage and other junk."
|
|||
examine = "This room doesn't have much to it, just a lot of dust, old wood trash and a couple torn paintings. This room stinks!"
|
||||
|
||||
[rooms.1.items]
|
||||
stone = "Ston. RoK."
|
||||
stick = "stiC"
|
||||
|
||||
[rooms.1.interactables.lever]
|
||||
name = "a rustic lever"
|
||||
|
@ -95,4 +110,4 @@ examine = "The room has yellowed wallpapers. They stink of old age. There's a fa
|
|||
note = "a torn, yellowed note"
|
||||
|
||||
[rooms.4.exits]
|
||||
up = "1"
|
||||
up = "1"
|
||||
|
|
Loading…
Reference in a new issue