Skip to content

Commit

Permalink
make sure traps are activated in received order + trap client messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrochu committed Nov 30, 2024
1 parent 26aaf89 commit eb295ed
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 48 deletions.
8 changes: 3 additions & 5 deletions worlds/zork_grand_inquisitor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ async def controller(self):
# Enqueue Received Item Delta
goal_item_count: int = 0

trap_item_counts: Dict[ZorkGrandInquisitorItems, int] = {
item: 0 for item in self.game_controller.all_trap_items
}
received_traps: List[ZorkGrandInquisitorItems] = list()

network_item: NetUtils.NetworkItem
for network_item in self.items_received:
Expand All @@ -223,7 +221,7 @@ async def controller(self):
goal_item_count += 1
continue
elif item in self.game_controller.all_trap_items:
trap_item_counts[item] += 1
received_traps.append(item)
continue
elif item not in self.game_controller.received_items:
if item not in self.game_controller.received_items_queue:
Expand All @@ -233,7 +231,7 @@ async def controller(self):
self.game_controller.goal_item_count = goal_item_count
self.game_controller.output_goal_item_update()

self.game_controller.trap_counters = trap_item_counts
self.game_controller.received_traps = received_traps

# Game Controller Update
if self.game_controller.is_process_running():
Expand Down
7 changes: 0 additions & 7 deletions worlds/zork_grand_inquisitor/data/mapping_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,13 +757,6 @@
ZorkGrandInquisitorStartingLocations.MONASTERY_EXHIBIT: ZorkGrandInquisitorRegions.MONASTERY_EXHIBIT,
}

traps_to_game_state_key: Dict[ZorkGrandInquisitorItems, int] = {
ZorkGrandInquisitorItems.TRAP_INFINITE_CORRIDOR: 19990,
ZorkGrandInquisitorItems.TRAP_REVERSE_CONTROLS: 19991,
ZorkGrandInquisitorItems.TRAP_TELEPORT: 19992,
ZorkGrandInquisitorItems.TRAP_ZVISION: 19993,
}

voxam_cast_game_locations: Dict[
ZorkGrandInquisitorStartingLocations,
Tuple[Tuple[str, int], ...]
Expand Down
88 changes: 52 additions & 36 deletions worlds/zork_grand_inquisitor/game_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
death_cause_labels,
hotspots_for_regional_hotspot,
labels_for_enum_items,
traps_to_game_state_key,
voxam_cast_game_locations,
)

Expand Down Expand Up @@ -87,7 +86,7 @@ class GameController:
starter_kit: Optional[List[str]]
initial_totemizer_destination: Optional[ZorkGrandInquisitorItems]

trap_counters: Dict[ZorkGrandInquisitorItems, int]
received_traps: List[ZorkGrandInquisitorItems]

active_trap: Optional[ZorkGrandInquisitorItems]
active_trap_until: Optional[datetime.datetime]
Expand Down Expand Up @@ -164,12 +163,7 @@ def __init__(self, logger=None) -> None:
self.starter_kit = None
self.initial_totemizer_destination = None

self.trap_counters = {
ZorkGrandInquisitorItems.TRAP_INFINITE_CORRIDOR: 0,
ZorkGrandInquisitorItems.TRAP_REVERSE_CONTROLS: 0,
ZorkGrandInquisitorItems.TRAP_TELEPORT: 0,
ZorkGrandInquisitorItems.TRAP_ZVISION: 0,
}
self.received_traps = list()

self.active_trap = None
self.active_trap_until = None
Expand Down Expand Up @@ -471,12 +465,7 @@ def reset(self) -> None:
self.starter_kit = None
self.initial_totemizer_destination = None

self.trap_counters = {
ZorkGrandInquisitorItems.TRAP_INFINITE_CORRIDOR: 0,
ZorkGrandInquisitorItems.TRAP_REVERSE_CONTROLS: 0,
ZorkGrandInquisitorItems.TRAP_TELEPORT: 0,
ZorkGrandInquisitorItems.TRAP_ZVISION: 0,
}
self.received_traps = list()

self.active_trap = None
self.active_trap_until = None
Expand Down Expand Up @@ -1447,29 +1436,56 @@ def _manage_traps(self) -> None:

return None

processed_trap_counters: Dict[ZorkGrandInquisitorItems, int] = {
ZorkGrandInquisitorItems.TRAP_INFINITE_CORRIDOR: self._read_game_state_value_for(19990),
ZorkGrandInquisitorItems.TRAP_REVERSE_CONTROLS: self._read_game_state_value_for(19991),
ZorkGrandInquisitorItems.TRAP_TELEPORT: self._read_game_state_value_for(19992),
ZorkGrandInquisitorItems.TRAP_ZVISION: self._read_game_state_value_for(19993),
}

traps_remaining: int = len(self.received_traps) - sum(processed_trap_counters.values()) - 1
traps_remaining_message: str = f"Traps remaining: {traps_remaining}" if traps_remaining else ""

trap: ZorkGrandInquisitorItems
count: int
for trap, count in self.trap_counters.items():
game_count: int = self._read_game_state_value_for(traps_to_game_state_key[trap])

if game_count < count:
if trap == ZorkGrandInquisitorItems.TRAP_INFINITE_CORRIDOR:
self._activate_trap_infinite_corridor()
elif trap == ZorkGrandInquisitorItems.TRAP_REVERSE_CONTROLS:
self.active_trap = ZorkGrandInquisitorItems.TRAP_REVERSE_CONTROLS
self.active_trap_until = datetime.datetime.now() + datetime.timedelta(seconds=30)

self._activate_trap_reverse_controls()
elif trap == ZorkGrandInquisitorItems.TRAP_TELEPORT:
self._activate_trap_teleport()
elif trap == ZorkGrandInquisitorItems.TRAP_ZVISION:
self.active_trap = ZorkGrandInquisitorItems.TRAP_ZVISION
self.active_trap_until = datetime.datetime.now() + datetime.timedelta(seconds=30)

self._activate_trap_zvision()

self._write_game_state_value_for(traps_to_game_state_key[trap], game_count + 1)
break
for trap in self.received_traps:
if processed_trap_counters[trap]:
processed_trap_counters[trap] -= 1
continue

game_state_key: int = -1
if trap == ZorkGrandInquisitorItems.TRAP_INFINITE_CORRIDOR:
game_state_key = 19990
self._activate_trap_infinite_corridor()

self.log(f"Infinite Corridor Trap! {traps_remaining_message}")
elif trap == ZorkGrandInquisitorItems.TRAP_REVERSE_CONTROLS:
game_state_key = 19991

self.active_trap = ZorkGrandInquisitorItems.TRAP_REVERSE_CONTROLS
self.active_trap_until = datetime.datetime.now() + datetime.timedelta(seconds=30)

self._activate_trap_reverse_controls()

self.log(f"Reverse Controls Trap for 30 seconds! {traps_remaining_message}")
elif trap == ZorkGrandInquisitorItems.TRAP_TELEPORT:
game_state_key = 19992
self._activate_trap_teleport()

self.log(f"Teleport Trap! {traps_remaining_message}")
elif trap == ZorkGrandInquisitorItems.TRAP_ZVISION:
game_state_key = 19993

self.active_trap = ZorkGrandInquisitorItems.TRAP_ZVISION
self.active_trap_until = datetime.datetime.now() + datetime.timedelta(seconds=30)

self._activate_trap_zvision()

self.log(f"ZVision Trap for 30 seconds! {traps_remaining_message}")

current_count: int = self._read_game_state_value_for(game_state_key)
self._write_game_state_value_for(game_state_key, current_count + 1)

break

def _activate_trap_infinite_corridor(self) -> None:
depth = random.randint(10, 20)
Expand Down

0 comments on commit eb295ed

Please sign in to comment.