Skip to content

Commit

Permalink
add one-way energy link by hitting the mushroom with the hammer
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrochu committed Nov 29, 2024
1 parent baf60cf commit 620bfbc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
18 changes: 18 additions & 0 deletions worlds/zork_grand_inquisitor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ async def controller(self):
}
])

# Handle Energy Link
while len(self.game_controller.energy_link_queue) > 0:
energy_to_add: int = self.game_controller.energy_link_queue.popleft()

await self.send_msgs([
{
"cmd": "Set",
"key": f"EnergyLink{self.team}",
"slot": self.slot,
"operations":
[
{"operation": "add", "value": energy_to_add},
],
},
])

CommonClient.logger.info(f"Added {energy_to_add} J to the Energy Link pool")

# Handle Death Link
await self.update_death_link(self.death_link_status)

Expand Down
42 changes: 42 additions & 0 deletions worlds/zork_grand_inquisitor/game_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class GameController:
active_trap: Optional[ZorkGrandInquisitorItems]
active_trap_until: Optional[datetime.datetime]

energy_link_queue: collections.deque
pause_energy_link_monitoring: bool

pending_death_link: Tuple[bool, Optional[str], Optional[str]]
outgoing_death_link: Tuple[bool, Optional[str]]
pause_death_monitoring: bool
Expand Down Expand Up @@ -171,6 +174,9 @@ def __init__(self, logger=None) -> None:
self.active_trap = None
self.active_trap_until = None

self.energy_link_queue = collections.deque()
self.pause_energy_link_monitoring = False

self.pending_death_link = (False, None, None)
self.outgoing_death_link = (False, None)
self.pause_death_monitoring = False
Expand Down Expand Up @@ -422,6 +428,9 @@ def update(self) -> None:
if self.option_trap_percentage:
self._manage_traps()

if self._player_is_at("dg3e"):
self._manage_energy_link()

if self.option_death_link:
self._handle_death_link()

Expand Down Expand Up @@ -472,6 +481,9 @@ def reset(self) -> None:
self.active_trap = None
self.active_trap_until = None

self.energy_link_queue = collections.deque()
self.pause_energy_link_monitoring = False

self.pending_death_link = (False, None, None)
self.outgoing_death_link = (False, None)
self.pause_death_monitoring = False
Expand Down Expand Up @@ -1485,6 +1497,36 @@ def _activate_trap_zvision(self) -> None:
def _deactivate_trap_zvision(self) -> None:
self.game_state_manager.set_zvision(False)

def _manage_energy_link(self) -> None:
mushroom_hammered: bool = self._read_game_state_value_for(4217) == 1
mushroom_hammered_throck: bool = self._read_game_state_value_for(4219) == 1
mushroom_hammered_snapdragon: bool = self._read_game_state_value_for(4220) == 1
mushroom_hammered_snapdragon_throck: bool = self._read_game_state_value_for(4222) == 1

any_mushroom_hammered: bool = (
mushroom_hammered
or mushroom_hammered_throck
or mushroom_hammered_snapdragon
or mushroom_hammered_snapdragon_throck
)

# Pause Monitoring Flag
if self.pause_energy_link_monitoring and not any_mushroom_hammered:
self.pause_energy_link_monitoring = False

if not self.pause_energy_link_monitoring and any_mushroom_hammered:
# Contribute Energy
if mushroom_hammered:
self.energy_link_queue.append(750)
elif mushroom_hammered_throck:
self.energy_link_queue.append(1500)
elif mushroom_hammered_snapdragon:
self.energy_link_queue.append(750)
elif mushroom_hammered_snapdragon_throck:
self.energy_link_queue.append(1500)

self.pause_energy_link_monitoring = True

def _handle_death_link(self) -> None:
# Pause Monitoring Flag
if self.pause_death_monitoring and not self._player_is_at("gjde"):
Expand Down

0 comments on commit 620bfbc

Please sign in to comment.