Skip to content

Commit

Permalink
Added start of room hints logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiryn committed Dec 15, 2024
1 parent b43b6e6 commit e25a086
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
47 changes: 41 additions & 6 deletions MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class Context:
def __init__(self, host: str, port: int, server_password: str, password: str, location_check_points: int,
hint_cost: int, item_cheat: bool, release_mode: str = "disabled", collect_mode="disabled",
remaining_mode: str = "disabled", auto_shutdown: typing.SupportsFloat = 0, compatibility: int = 2,
log_network: bool = False, logger: logging.Logger = logging.getLogger()):
log_network: bool = False, logger: logging.Logger = logging.getLogger(), use_room_hints: bool = False):
self.logger = logger
super(Context, self).__init__()
self.slot_info = {}
Expand Down Expand Up @@ -283,7 +283,7 @@ def __init__(self, host: str, port: int, server_password: str, password: str, lo
self._load_game_data()

# Ashipelago customization
self.dynx = Ashipelago(self)
self.dynx = Ashipelago(self, use_room_hints)

# Data package retrieval
def _load_game_data(self):
Expand Down Expand Up @@ -599,6 +599,7 @@ def get_save(self) -> dict:
"received_items": self.received_items,
"hints_used": dict(self.hints_used),
"hints": dict(self.hints),
"room_hints": int,
"location_checks": dict(self.location_checks),
"name_aliases": self.name_aliases,
"client_game_state": dict(self.client_game_state),
Expand All @@ -613,7 +614,8 @@ def get_save(self) -> dict:
"server_password": self.server_password, "password": self.password,
"release_mode": self.release_mode,
"remaining_mode": self.remaining_mode, "collect_mode": self.collect_mode,
"item_cheat": self.item_cheat, "compatibility": self.compatibility}
"item_cheat": self.item_cheat, "compatibility": self.compatibility,
"room_hints": self.dynx.use_room_hints}

}

Expand All @@ -627,6 +629,7 @@ def set_save(self, savedata: dict):
self.received_items = savedata["received_items"]
self.hints_used.update(savedata["hints_used"])
self.hints.update(savedata["hints"])
self.dynx.room_hints_used = savedata["room_hints"]

self.name_aliases.update(savedata["name_aliases"])
self.client_game_state.update(savedata["client_game_state"])
Expand All @@ -649,6 +652,7 @@ def set_save(self, savedata: dict):
self.collect_mode = savedata["game_options"]["collect_mode"]
self.item_cheat = savedata["game_options"]["item_cheat"]
self.compatibility = savedata["game_options"]["compatibility"]
self.dynx.use_room_hints = savedata["game_options"]["room_hints"]

if "group_collected" in savedata:
self.group_collected = savedata["group_collected"]
Expand Down Expand Up @@ -832,6 +836,8 @@ class Ashipelago:
admin_password: str
ctx: Context
webhook_thread: WebhookThread
use_room_hints: bool
room_hints_used: int

def __init__(self, ctx: Context):
self.ctx = ctx
Expand Down Expand Up @@ -1052,6 +1058,25 @@ def _push_game_item_information(self):
}
self._push_to_webhook(information)

def get_room_points(self, team) -> int:
result = 0
locations = 0
for slot, connected_clients in self.ctx.clients[team].items():
result = result + (self.ctx.location_check_points * len(self.ctx.location_checks[team, slot]))
locations = locations + len(self.ctx.locations[slot])

hint_cost = max(1, int(self.ctx.hint_cost * 0.01 * locations))
return result - hint_cost * self.room_hints_used

def get_room_hint_cost(self, team) -> int:
if self.ctx.hint_cost:
locations = 0
for slot, connected_clients in self.ctx.clients[team].items():
locations = locations + len(self.ctx.locations[slot])
return max(1, int(self.ctx.hint_cost * 0.01 * locations / len(self.ctx.clients[team])))

return 0

# Webhook class used to multithread the webhook messages so that the main thread is not stalled
class WebhookThread(threading.Thread):
ctx: Context
Expand Down Expand Up @@ -1868,8 +1893,14 @@ def _cmd_getitem(self, item_name: str) -> bool:
return False

def get_hints(self, input_text: str, for_location: bool = False) -> bool:
points_available = get_client_points(self.ctx, self.client)
cost = self.ctx.get_hint_cost(self.client.slot)
# Ashipelago customization
if self.ctx.dynx.use_room_hints:
points_available = self.ctx.dynx.get_room_points(self.client.team)
cost = self.ctx.dynx.get_room_hint_cost(self.client.team)
else:
points_available = get_client_points(self.ctx, self.client)
cost = self.ctx.get_hint_cost(self.client.slot)

auto_status = HintStatus.HINT_UNSPECIFIED if for_location else HintStatus.HINT_PRIORITY
if not input_text:
hints = {hint.re_check(self.ctx, self.client.team) for hint in
Expand Down Expand Up @@ -1963,7 +1994,11 @@ def get_hints(self, input_text: str, for_location: bool = False) -> bool:
hint = not_found_hints.pop()
hints.append(hint)
can_pay -= 1
self.ctx.hints_used[self.client.team, self.client.slot] += 1
# Ashipelago customization
if self.ctx.dynx.use_room_hints:
self.ctx.dynx.room_hints_used += 1
else:
self.ctx.hints_used[self.client.team, self.client.slot] += 1

self.ctx.notify_hints(self.client.team, hints)
if not_found_hints:
Expand Down
1 change: 1 addition & 0 deletions WebHostLib/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_meta(options_source: dict, race: bool = False) -> Dict[str, Union[List[s
"item_cheat": bool(int(options_source.get("item_cheat", not ServerOptions.disable_item_cheat))),
"server_password": options_source.get("server_password", None),
"track_in_discord": bool(int(options_source.get("track_in_discord", ServerOptions.track_in_discord))),
"use_room_hints": bool(int(options_source.get("use_room_hints", ServerOptions.use_room_hints))),
}
generator_options = {
"spoiler": int(options_source.get("spoiler", GeneratorOptions.spoiler)),
Expand Down
15 changes: 15 additions & 0 deletions WebHostLib/templates/generate.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ <h1>Generate Game{% if race %} (Race Mode){% endif %}</h1>
</select>
</td>
</tr>
<tr>
<td>
<label for="use_room_hints">Use shared room hints
<span class="interactive" data-tooltip="Allows for the players in a room to pool their hints into a global hint pool for the room.">
(?)
</span>
</label>
</td>
<td>
<select name="use_room_hints" id="use_room_hints">
<option value="0">Disabled</option>
<option value="1">Enabled</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="server_password">Server Password:
Expand Down
1 change: 1 addition & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ class LogNetwork(IntEnum):
disable_item_cheat: Union[DisableItemCheat, bool] = False
location_check_points: LocationCheckPoints = LocationCheckPoints(1)
hint_cost: HintCost = HintCost(10)
use_room_hints: bool = False
track_in_discord: bool = False
release_mode: ReleaseMode = ReleaseMode("auto")
collect_mode: CollectMode = CollectMode("auto")
Expand Down

0 comments on commit e25a086

Please sign in to comment.