From 304726302d68a2cb0615f7b678b769c8b0a8f3a6 Mon Sep 17 00:00:00 2001 From: Cheri Dawn Date: Fri, 23 Aug 2024 12:18:57 +0300 Subject: [PATCH] add basic combine --- README.md | 4 +++- docs.toml | 6 ++++++ setage.py | 19 +++++++++++++++++++ test-game/manifest.setage | 11 +++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5287b99..45a75bd 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,6 @@ see test-game/manifest.setage * [x] `exact input` provides exact input checking * [x] `item check`, `item take` provides item checking * [ ] combining items and other item interactions -* [ ] + * [ ] multiple outputs + * [ ] reusable items ? + * [ ] lockable diff --git a/docs.toml b/docs.toml index 88c7f07..8c9e3cc 100644 --- a/docs.toml +++ b/docs.toml @@ -30,6 +30,12 @@ item.examine = "message when the `item` is examined" # `item` can be any item id item.hidden = false # optional, default. +[recipes.itemid] # Optional +ingredients = ["itemid1", "itemid2", ...] # Required +result_text = "shorttext of the result item" # Required +text = "message when items get combined with this recipe" # Optional; default = "> You combined items." + + [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" diff --git a/setage.py b/setage.py index 9a2cd8b..a135450 100755 --- a/setage.py +++ b/setage.py @@ -484,6 +484,25 @@ 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("> Can't combine this amount of items...") + return + for item in items: + if item not in inventory: + print(f"> {item} not in inventory...") + return + for recipe in recipes.items(): + if set(items) == set(recipe[1]["ingredients"]): + print(recipe[1]["text"]) + for item in items: + inventory.pop(item) + inventory[recipe[0]] = recipe[1]["result_text"] + return + def do_credits(self, arg): """Print credits.""" if "credits" not in metadata: diff --git a/test-game/manifest.setage b/test-game/manifest.setage index 1acded8..ee14cd2 100644 --- a/test-game/manifest.setage +++ b/test-game/manifest.setage @@ -29,6 +29,15 @@ 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" + + +[recipes.weapon] +ingredients = ["stone", "stick"] +text = "ooja booja" +result_text = "a weapon" [rooms.1] @@ -37,6 +46,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"