@@ -175,8 +175,11 @@ class Context:
175
175
all_item_and_group_names : typing .Dict [str , typing .Set [str ]]
176
176
all_location_and_group_names : typing .Dict [str , typing .Set [str ]]
177
177
non_hintable_names : typing .Dict [str , typing .Set [str ]]
178
+ spheres : typing .List [typing .Dict [int , typing .Set [int ]]]
179
+ """ each sphere is { player: { location_id, ... } } """
178
180
logger : logging .Logger
179
181
182
+
180
183
def __init__ (self , host : str , port : int , server_password : str , password : str , location_check_points : int ,
181
184
hint_cost : int , item_cheat : bool , release_mode : str = "disabled" , collect_mode = "disabled" ,
182
185
remaining_mode : str = "disabled" , auto_shutdown : typing .SupportsFloat = 0 , compatibility : int = 2 ,
@@ -238,6 +241,7 @@ def __init__(self, host: str, port: int, server_password: str, password: str, lo
238
241
self .stored_data = {}
239
242
self .stored_data_notification_clients = collections .defaultdict (weakref .WeakSet )
240
243
self .read_data = {}
244
+ self .spheres = []
241
245
242
246
# init empty to satisfy linter, I suppose
243
247
self .gamespackage = {}
@@ -466,6 +470,9 @@ def _load(self, decoded_obj: dict, game_data_packages: typing.Dict[str, typing.A
466
470
for game_name , data in self .location_name_groups .items ():
467
471
self .read_data [f"location_name_groups_{ game_name } " ] = lambda lgame = game_name : self .location_name_groups [lgame ]
468
472
473
+ # sorted access spheres
474
+ self .spheres = decoded_obj .get ("spheres" , [])
475
+
469
476
# saving
470
477
471
478
def save (self , now = False ) -> bool :
@@ -624,6 +631,16 @@ def get_rechecked_hints(self, team: int, slot: int):
624
631
self .recheck_hints (team , slot )
625
632
return self .hints [team , slot ]
626
633
634
+ def get_sphere (self , player : int , location_id : int ) -> int :
635
+ """Get sphere of a location, -1 if spheres are not available."""
636
+ if self .spheres :
637
+ for i , sphere in enumerate (self .spheres ):
638
+ if location_id in sphere .get (player , set ()):
639
+ return i
640
+ raise KeyError (f"No Sphere found for location ID { location_id } belonging to player { player } . "
641
+ f"Location or player may not exist." )
642
+ return - 1
643
+
627
644
def get_players_package (self ):
628
645
return [NetworkPlayer (t , p , self .get_aliased_name (t , p ), n ) for (t , p ), n in self .player_names .items ()]
629
646
@@ -1549,6 +1566,9 @@ def get_hints(self, input_text: str, for_location: bool = False) -> bool:
1549
1566
self .ctx .random .shuffle (not_found_hints )
1550
1567
# By popular vote, make hints prefer non-local placements
1551
1568
not_found_hints .sort (key = lambda hint : int (hint .receiving_player != hint .finding_player ))
1569
+ # By another popular vote, prefer early sphere
1570
+ not_found_hints .sort (key = lambda hint : self .ctx .get_sphere (hint .finding_player , hint .location ),
1571
+ reverse = True )
1552
1572
1553
1573
hints = found_hints + old_hints
1554
1574
while can_pay > 0 :
@@ -1558,10 +1578,10 @@ def get_hints(self, input_text: str, for_location: bool = False) -> bool:
1558
1578
hints .append (hint )
1559
1579
can_pay -= 1
1560
1580
self .ctx .hints_used [self .client .team , self .client .slot ] += 1
1561
- points_available = get_client_points (self .ctx , self .client )
1562
1581
1563
1582
self .ctx .notify_hints (self .client .team , hints )
1564
1583
if not_found_hints :
1584
+ points_available = get_client_points (self .ctx , self .client )
1565
1585
if hints and cost and int ((points_available // cost ) == 0 ):
1566
1586
self .output (
1567
1587
f"There may be more hintables, however, you cannot afford to pay for any more. "
0 commit comments