From 304726302d68a2cb0615f7b678b769c8b0a8f3a6 Mon Sep 17 00:00:00 2001 From: Cheri Dawn Date: Fri, 23 Aug 2024 12:18:57 +0300 Subject: [PATCH 1/3] 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" From f9f172b5c5b59d8dd6b129b1d550f2ba4608fe48 Mon Sep 17 00:00:00 2001 From: Cheri Dawn Date: Mon, 26 Aug 2024 16:49:11 +0300 Subject: [PATCH 2/3] add multiple outputs option --- README.md | 6 +++++- docs.toml | 8 +++++++- setage.py | 14 ++++++++++---- test-game/manifest.setage | 8 +++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 45a75bd..e8084e3 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ 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 + * [x] basic + * [x] multiple outputs * [ ] reusable items ? * [ ] lockable + * [ ] "item" = examine an item + * [ ] "room" = enter a room + * [ ] "interactable" = use an interactable diff --git a/docs.toml b/docs.toml index 8c9e3cc..214cef5 100644 --- a/docs.toml +++ b/docs.toml @@ -30,9 +30,15 @@ item.examine = "message when the `item` is examined" # `item` can be any item id item.hidden = false # optional, default. -[recipes.itemid] # Optional +[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." diff --git a/setage.py b/setage.py index a135450..3a309c4 100755 --- a/setage.py +++ b/setage.py @@ -489,18 +489,24 @@ class SetageShell(Cmd): recipes = manifest["recipes"] items = [a.strip() for a in arg.split(",")] if len(items) < 2: - print("> Can't combine this amount of items...") + 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(): - if set(items) == set(recipe[1]["ingredients"]): - print(recipe[1]["text"]) + rec = recipe[1] + # FIXME: multiple recipes with same ingredients??? + if set(items) == set(rec["ingredients"]): + print(rec["text"]) for item in items: inventory.pop(item) - inventory[recipe[0]] = recipe[1]["result_text"] + 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 def do_credits(self, arg): diff --git a/test-game/manifest.setage b/test-game/manifest.setage index ee14cd2..9a9f771 100644 --- a/test-game/manifest.setage +++ b/test-game/manifest.setage @@ -32,12 +32,14 @@ note.examine = "The note reads: there is a [shiny] hidden in one of the rooms of stone.examine = "Ston. Rok." stick.examine = "stiC" weapon.examine = "wpn" +trash.examine = "trasshhhhhhhhhhhhh" [recipes.weapon] -ingredients = ["stone", "stick"] text = "ooja booja" -result_text = "a weapon" +ingredients = ["stone", "stick"] +result_ids = ["weapon", "trash"] +result_texts = ["a weapon", "trsh"] [rooms.1] @@ -106,4 +108,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" \ No newline at end of file +up = "1" From 2a8e02287839e79bfccec9e00a6a67edcbf320d1 Mon Sep 17 00:00:00 2001 From: Cheri Dawn Date: Sun, 1 Sep 2024 05:48:34 +0300 Subject: [PATCH 3/3] implement locking of recipes --- README.md | 11 +++++------ docs.toml | 2 ++ setage.py | 41 +++++++++++++++++++++++++++++---------- test-game/manifest.setage | 2 ++ 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e8084e3..5f18265 100644 --- a/README.md +++ b/README.md @@ -16,11 +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 - * [ ] reusable items ? - * [ ] lockable - * [ ] "item" = examine an item - * [ ] "room" = enter a room - * [ ] "interactable" = use an interactable + * [x] lockable + * [x] "item" = examine an item + * [x] "room" = enter a room + * [x] "interactable" = use an interactable diff --git a/docs.toml b/docs.toml index 214cef5..8e2b11f 100644 --- a/docs.toml +++ b/docs.toml @@ -40,6 +40,8 @@ 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. diff --git a/setage.py b/setage.py index 3a309c4..14b095e 100755 --- a/setage.py +++ b/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: @@ -431,6 +434,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() @@ -497,17 +501,34 @@ class SetageShell(Cmd): return for recipe in recipes.items(): rec = recipe[1] - # 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] + 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: - inventory[rec["result_id"]] = rec["result_text"] - return + 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.""" diff --git a/test-game/manifest.setage b/test-game/manifest.setage index 9a9f771..d68450d 100644 --- a/test-game/manifest.setage +++ b/test-game/manifest.setage @@ -37,6 +37,8 @@ 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"]