Skip to content

Commit

Permalink
address more review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrochu committed Mar 11, 2024
1 parent 5661d25 commit d658100
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 35 deletions.
17 changes: 12 additions & 5 deletions worlds/zork_grand_inquisitor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,22 @@ class ZorkGrandInquisitorContext(CommonClient.CommonContext):
id_to_items: Dict[int, ZorkGrandInquisitorItems] = id_to_items()
id_to_locations: Dict[int, ZorkGrandInquisitorLocations] = id_to_locations()

game_controller: GameController

controller_task: Optional[asyncio.Task]

process_attached_at_least_once: bool
can_display_process_message: bool

def __init__(self, server_address: Optional[str], password: Optional[str]) -> None:
super().__init__(server_address, password)

self.game_controller: GameController = GameController(logger=CommonClient.logger)
self.game_controller = GameController(logger=CommonClient.logger)

self.controller_task: Optional[asyncio.Task] = None
self.controller_task = None

self.process_attached_at_least_once: bool = False
self.can_display_process_message: bool = True
self.process_attached_at_least_once = False
self.can_display_process_message = True

def run_gui(self) -> None:
from kvui import GameManager
Expand All @@ -83,7 +90,7 @@ def on_package(self, cmd: str, _args: Any) -> None:
if cmd == "Connected":
self.game = self.slot_info[self.slot].game

CommonClient.async_start(process_package(self, cmd, _args))
Utils.async_start(process_package(self, cmd, _args))

async def controller(self):
while not self.exit_event.is_set():
Expand Down
2 changes: 1 addition & 1 deletion worlds/zork_grand_inquisitor/data_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def locations_by_region(include_deathsanity: bool = False) -> Dict[
location: ZorkGrandInquisitorLocations
data: ZorkGrandInquisitorLocationData
for location, data in location_data.items():
if include_deathsanity is False and ZorkGrandInquisitorTags.DEATHSANITY in (
if not include_deathsanity and ZorkGrandInquisitorTags.DEATHSANITY in (
data.tags or tuple()
):
continue
Expand Down
56 changes: 40 additions & 16 deletions worlds/zork_grand_inquisitor/game_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,62 @@


class GameController:
logger: Optional[logging.Logger]

game_state_manager: GameStateManager

received_items: Set[ZorkGrandInquisitorItems]
completed_locations: Set[ZorkGrandInquisitorLocations]

completed_locations_queue: collections.deque
received_items_queue: collections.deque

all_hotspot_items: Set[ZorkGrandInquisitorItems]

game_id_to_items: Dict[int, ZorkGrandInquisitorItems]

possible_inventory_items: Set[ZorkGrandInquisitorItems]

available_inventory_slots: Set[int]

goal_completed: bool

option_goal: Optional[ZorkGrandInquisitorGoals]
option_deathsanity: Optional[bool]
option_grant_missable_location_checks: Optional[bool]

def __init__(self, logger=None) -> None:
self.logger: Optional[logging.Logger] = logger
self.logger = logger

self.game_state_manager: GameStateManager = GameStateManager()
self.game_state_manager = GameStateManager()

self.received_items: Set[ZorkGrandInquisitorItems] = set()
self.completed_locations: Set[ZorkGrandInquisitorLocations] = set()
self.received_items = set()
self.completed_locations = set()

self.completed_locations_queue: collections.deque = collections.deque()
self.received_items_queue: collections.deque = collections.deque()
self.completed_locations_queue = collections.deque()
self.received_items_queue = collections.deque()

self.all_hotspot_items: Set[ZorkGrandInquisitorItems] = (
self.all_hotspot_items = (
items_with_tag(ZorkGrandInquisitorTags.HOTSPOT)
| items_with_tag(ZorkGrandInquisitorTags.SUBWAY_DESTINATION)
| items_with_tag(ZorkGrandInquisitorTags.TOTEMIZER_DESTINATION)
)

self.game_id_to_items: Dict[int, ZorkGrandInquisitorItems] = game_id_to_items()
self.game_id_to_items = game_id_to_items()

self.possible_inventory_items: Set[ZorkGrandInquisitorItems] = (
self.possible_inventory_items = (
items_with_tag(ZorkGrandInquisitorTags.INVENTORY_ITEM)
| items_with_tag(ZorkGrandInquisitorTags.SPELL)
| items_with_tag(ZorkGrandInquisitorTags.TOTEM)
)

self.available_inventory_slots: Set[int] = set()
self.available_inventory_slots = set()

self.goal_completed: bool = False
self.goal_completed = False

self.option_goal: Optional[ZorkGrandInquisitorGoals] = None
self.option_deathsanity: Optional[bool] = None
self.option_grant_missable_location_checks: Optional[bool] = None
self.option_goal = None
self.option_deathsanity = None
self.option_grant_missable_location_checks = None

@functools.cached_property
def brog_items(self) -> Set[ZorkGrandInquisitorItems]:
Expand Down Expand Up @@ -176,7 +200,7 @@ def update(self) -> None:

self._check_for_completed_locations()

if self.option_grant_missable_location_checks is True:
if self.option_grant_missable_location_checks:
self._check_for_missable_locations_to_grant()

self._process_received_items()
Expand Down Expand Up @@ -368,7 +392,7 @@ def _check_for_missable_locations_to_grant(self) -> None:

data: ZorkGrandInquisitorLocationData = location_data[missable_location]

if ZorkGrandInquisitorTags.DEATHSANITY in data.tags and self.option_deathsanity is False:
if ZorkGrandInquisitorTags.DEATHSANITY in data.tags and not self.option_deathsanity:
continue

condition_data: ZorkGrandInquisitorMissableLocationGrantConditionsData = (
Expand Down
29 changes: 19 additions & 10 deletions worlds/zork_grand_inquisitor/game_state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
class GameStateManager:
process_name = "scummvm.exe"

process: Optional[Pymem]
is_process_running: bool

script_manager_struct_address: int
render_manager_struct_address: int

game_location: Optional[str]
game_location_offset: Optional[int]

def __init__(self) -> None:
self.process: Optional[Pymem] = None
self.is_process_running: bool = False
self.process = None
self.is_process_running = False

self.script_manager_struct_address: int = 0x0
self.render_manager_struct_address: int = 0x0
self.script_manager_struct_address = 0x0
self.render_manager_struct_address = 0x0

self.game_location: Optional[str] = None
self.game_location_offset: Optional[int] = None
self.game_location = None
self.game_location_offset = None

@property
def game_state_storage_pointer_address(self) -> int:
Expand Down Expand Up @@ -191,7 +200,7 @@ def write_statemap_value_for(self, key: int, value: int, scope: str = "game_stat
statemap_deleted_key_count: int = self.process.read_int(deleted_key_count_address)

if value == 0:
if is_existing_node is False:
if not is_existing_node:
return False

self.process.write_longlong(storage_address + offset, 1)
Expand Down Expand Up @@ -340,7 +349,7 @@ def _get_statemap_address_write_offset_for(self, key: int, scope: str = "game_st
if offset_value == 0: # Null Pointer
break
elif offset_value == 1: # Dummy Node
if dummy_node_found is False:
if not dummy_node_found:
dummy_node_offset = offset
dummy_node_found = True
elif offset_value > 1: # Existing Node
Expand All @@ -353,9 +362,9 @@ def _get_statemap_address_write_offset_for(self, key: int, scope: str = "game_st

perturb >>= perturb_shift

if node_found is False and dummy_node_found is True: # We should reuse the dummy node
if not node_found and dummy_node_found: # We should reuse the dummy node
return dummy_node_offset, False, True
elif node_found is False and dummy_node_found is False: # We should allocate a new node
elif not node_found and not dummy_node_found: # We should allocate a new node
return offset, False, False

return offset, True, False # We should update the existing node
4 changes: 1 addition & 3 deletions worlds/zork_grand_inquisitor/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class ZorkGrandInquisitorWorld(World):

game = "Zork Grand Inquisitor"

topology_present = False

item_name_to_id = item_names_to_id()
location_name_to_id = location_names_to_id()

Expand Down Expand Up @@ -169,7 +167,7 @@ def create_items(self) -> None:
self.multiworld.early_items[self.player][ZorkGrandInquisitorItems.ROPE.value] = 1
self.multiworld.early_items[self.player][ZorkGrandInquisitorItems.LANTERN.value] = 1

if start_with_hotspot_items is False:
if not start_with_hotspot_items:
self.multiworld.early_items[self.player][ZorkGrandInquisitorItems.HOTSPOT_WELL.value] = 1
self.multiworld.early_items[self.player][ZorkGrandInquisitorItems.HOTSPOT_JACKS_DOOR.value] = 1

Expand Down

0 comments on commit d658100

Please sign in to comment.