Add one kind of trap
authorJordan Rose <jrose@belkadan.com>
Mon, 31 Mar 2025 00:03:17 +0000 (17:03 -0700)
committerJordan Rose <jrose@belkadan.com>
Mon, 31 Mar 2025 00:03:17 +0000 (17:03 -0700)
apworld/sicp/__init__.py
apworld/sicp/client.py
apworld/sicp/items.yml
game.py

index 9d0fa5fe8a8892334b2402424cf469ce2045d926..0d2c1b69459398b896dc432c5ede76d839efcbd1 100644 (file)
@@ -36,6 +36,8 @@ class ItemData:
             return ItemClassification.useful
         if kind == 'progression_skip_balancing':
             return ItemClassification.progression_skip_balancing
+        if kind == 'trap':
+            return ItemClassification.trap
         return ItemClassification.filler
 
 with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'items.yml'), 'r') as input:
@@ -80,14 +82,6 @@ class SicpWorld(World):
             else:
                 self.multiworld.itempool.append(item)
 
-        # FIXME: need six traps later
-        self.multiworld.itempool.append(self.create_item("junk"))
-        self.multiworld.itempool.append(self.create_item("junk"))
-        self.multiworld.itempool.append(self.create_item("junk"))
-        self.multiworld.itempool.append(self.create_item("junk"))
-        self.multiworld.itempool.append(self.create_item("junk"))
-        self.multiworld.itempool.append(self.create_item("junk"))
-
         all_macguffins = [str(x) for x in all_items.values() if x.id() < 32]
         self.multiworld.completion_condition[self.player] = lambda state: state.has_all(all_macguffins, self.player)
 
index 302da86748c1ae3d8cad45dcedad37b631cf9d8b..a08d00a80468817dc2243d9a58900a496686e949 100644 (file)
@@ -22,9 +22,10 @@ import Utils
 if __name__ == "__main__":
     Utils.init_logging("SICPelago", exception_logger="Client")
 
-from NetUtils import ClientStatus
+from BaseClasses import ItemClassification
 from CommonClient import CommonContext, logger, get_base_parser, ClientCommandProcessor, server_loop
 from MultiServer import mark_raw
+from NetUtils import ClientStatus
 
 from . import all_items
 from .game import game
@@ -32,6 +33,7 @@ from .game.scheme import buffer_input, scheme_read, scheme_eval, scheme_format,
 
 items_by_id = {v.id(): v for v in all_items.values()}
 macguffins = [game.MacGuffin(x) for x in game.MacGuffins]
+traps_seen = set()
 
 async def send_locations(ctx: Context, problem: game.Problem):
     def id(problem):
@@ -72,6 +74,11 @@ async def game_loop(ctx: Context):
                             continue
                         macguffins[item.id() - 1] = None
                         game.receive_reward(next_mg)
+                    elif item.kind() == ItemClassification.trap:
+                        if item.id() in traps_seen:
+                            continue
+                        traps_seen.add(item.id())
+                        game.receive_reward(game.Trap())
                     elif not game.receive_reward(str(item)):
                         continue
                 ctx.watcher_event.clear()
index b9bd1f70499fe043ddef96e0210f76997af254c0..ac622317e4ff83bdc3de2099ffe762394862967c 100644 (file)
   id: 0x7
   kind: progression_skip_balancing
 
+- name: Trap 1
+  id: 0x100
+  kind: trap
+- name: Trap 2
+  id: 0x200
+  kind: trap
+- name: Trap 3
+  id: 0x300
+  kind: trap
+- name: Trap 4
+  id: 0x400
+  kind: trap
+- name: Trap 5
+  id: 0x500
+  kind: trap
+- name: Trap 6
+  id: 0x600
+  kind: trap
+
 - name: "*"
   id: 0x2a
   kind: useful_progression
diff --git a/game.py b/game.py
index 17eb1f1deccfea2f743e51cf5436301c200834f8..a9178143f7ec052aa45f3a9dabc9786ee6fb3fdb 100644 (file)
--- a/game.py
+++ b/game.py
@@ -123,6 +123,9 @@ def receive_reward(reward):
         if macguffinsCollected == len(MacGuffins):
             victory()
         return reward
+    if isinstance(reward, Trap):
+        print("\033[7mYou've activated my trap card!")
+        return reward
 
 problem_solved_hook = lambda problem: False
 
@@ -178,6 +181,12 @@ MacGuffins = [
 
 macguffinsCollected = 0
 
+class Trap:
+    def __str__(self):
+        return "Trap"
+    def __repr__(self):
+        return "Trap()"
+
 class Problem:
     def __init__(self, data: dict[str, Any]):
         self.data = data
@@ -212,7 +221,7 @@ def generate_problem_rewards_except(problems: Iterable[str], frame_of_locks: Fra
     for reward in MacGuffins:
         rewards[next(positions)].append(MacGuffin(reward))
 
-    for name in frame_of_locks.bindings:
+    for name in itertools.chain(frame_of_locks.bindings, itertools.repeat(Trap(), 6)):
         if name not in exceptions:
             rewards[next(positions)].insert(0, name)
 
@@ -250,6 +259,8 @@ def run_game(*argv: str):
         for reward in itertools.chain.from_iterable(ProblemRewards.values()):
             if isinstance(reward, MacGuffin):
                 item_id = MacGuffins.index(reward.name) + 1
+            elif isinstance(reward, Trap):
+                item_id = 0
             else:
                 # The last six characters of our operations happen to be unique
                 # and 48 bits is within the allowed ID range for Archipelago.