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