Add options to allow silent failed plando placements.
This commit is contained in:
		
							parent
							
								
									2891d575f0
								
							
						
					
					
						commit
						8ef78cc32a
					
				|  | @ -1477,7 +1477,19 @@ class PlandoItem(NamedTuple): | ||||||
|     location: str |     location: str | ||||||
|     world: Union[bool, str] = False  # False -> own world, True -> not own world |     world: Union[bool, str] = False  # False -> own world, True -> not own world | ||||||
|     from_pool: bool = True  # if item should be removed from item pool |     from_pool: bool = True  # if item should be removed from item pool | ||||||
|     force: bool = False  # False -> warns if item not successfully placed. True -> errors out on failure to place item. |     force: Union[bool, str] = 'silent'  # False -> warns if item not successfully placed. True -> errors out on failure to place item. | ||||||
|  | 
 | ||||||
|  |     def warn(self, warning: str): | ||||||
|  |         if str(self.force).lower() in ['true', 'fail', 'failure', 'none', 'false', 'warn', 'warning']: | ||||||
|  |             logging.warning(f'{warning}') | ||||||
|  |         else: | ||||||
|  |             logging.debug(f'{warning}') | ||||||
|  | 
 | ||||||
|  |     def failed(self, warning: str, exception=Exception): | ||||||
|  |         if str(self.force).lower() in ['true', 'fail', 'failure']: | ||||||
|  |             raise exception(warning) | ||||||
|  |         else: | ||||||
|  |             self.warn(warning) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class PlandoConnection(NamedTuple): | class PlandoConnection(NamedTuple): | ||||||
|  |  | ||||||
							
								
								
									
										41
									
								
								Fill.py
								
								
								
								
							
							
						
						
									
										41
									
								
								Fill.py
								
								
								
								
							|  | @ -359,11 +359,8 @@ def distribute_planned(world): | ||||||
|                     set(world.player_ids) - {player}) if location.item_rule(item) |                     set(world.player_ids) - {player}) if location.item_rule(item) | ||||||
|                                 ) |                                 ) | ||||||
|                 if not unfilled: |                 if not unfilled: | ||||||
|                     if placement.force: |                     placement.failed(f"Could not find a world with an unfilled location {placement.location}", FillError) | ||||||
|                         raise FillError(f"Could not find a world with an unfilled location {placement.location}") |                     continue | ||||||
|                     else: |  | ||||||
|                         logging.warning(f"Could not find a world with an unfilled location {placement.location}, skipping.") |  | ||||||
|                         continue |  | ||||||
| 
 | 
 | ||||||
|                 target_world = world.random.choice(unfilled).player |                 target_world = world.random.choice(unfilled).player | ||||||
| 
 | 
 | ||||||
|  | @ -373,32 +370,25 @@ def distribute_planned(world): | ||||||
|                     set(world.player_ids)) if location.item_rule(item) |                     set(world.player_ids)) if location.item_rule(item) | ||||||
|                                 ) |                                 ) | ||||||
|                 if not unfilled: |                 if not unfilled: | ||||||
|                     if placement.force: |                     placement.failed(f"Could not find a world with an unfilled location {placement.location}", FillError) | ||||||
|                         raise FillError(f"Could not find a world with an unfilled location {placement.location}") |                     continue | ||||||
|                     else: |  | ||||||
|                         logging.warning(f"Could not find a world with an unfilled location {placement.location}, skipping.") |  | ||||||
|                         continue |  | ||||||
| 
 | 
 | ||||||
|                 target_world = world.random.choice(unfilled).player |                 target_world = world.random.choice(unfilled).player | ||||||
| 
 | 
 | ||||||
|             elif type(target_world) == int:  # target world by player id |             elif type(target_world) == int:  # target world by player id | ||||||
|                 pass |                 if target_world not in range(1, world.players + 1): | ||||||
|  |                     placement.failed(f"Cannot place item in world {target_world} as it is not in range of (1, {world.players})", ValueError) | ||||||
|  |                     continue | ||||||
|             else:  # find world by name |             else:  # find world by name | ||||||
|                 if target_world not in world_name_lookup: |                 if target_world not in world_name_lookup: | ||||||
|                     if placement.force: |                     placement.failed(f"Cannot place item to {target_world}'s world as that world does not exist.", ValueError) | ||||||
|                         raise Exception(f"Cannot place item to {target_world}'s world as that world does not exist.") |                     continue | ||||||
|                     else: |  | ||||||
|                         logging.warning(f"Cannot place item to {target_world}'s world as that world does not exist. Skipping.") |  | ||||||
|                         continue |  | ||||||
|                 target_world = world_name_lookup[target_world] |                 target_world = world_name_lookup[target_world] | ||||||
| 
 | 
 | ||||||
|             location = world.get_location(placement.location, target_world) |             location = world.get_location(placement.location, target_world) | ||||||
|             if location.item: |             if location.item: | ||||||
|                 if placement.force: |                 placement.failed(f"Cannot place item into already filled location {location}.") | ||||||
|                     raise Exception(f"Cannot place item into already filled location {location}.") |                 continue | ||||||
|                 else: |  | ||||||
|                     logging.warning(f"Cannot place item into already filled location {location}. Skipping.") |  | ||||||
|                     continue |  | ||||||
| 
 | 
 | ||||||
|             if location.can_fill(world.state, item, False): |             if location.can_fill(world.state, item, False): | ||||||
|                 world.push_item(location, item, collect=False) |                 world.push_item(location, item, collect=False) | ||||||
|  | @ -406,14 +396,11 @@ def distribute_planned(world): | ||||||
|                 location.locked = True |                 location.locked = True | ||||||
|                 logging.debug(f"Plando placed {item} at {location}") |                 logging.debug(f"Plando placed {item} at {location}") | ||||||
|             else: |             else: | ||||||
|                 if placement.force: |                 placement.failed(f"Can't place {item} at {location} due to fill condition not met.") | ||||||
|                     raise Exception(f"Can't place {item} at {location} due to fill condition not met.") |                 continue | ||||||
|                 else: |  | ||||||
|                     logging.warning(f"Can't place {item} at {location} due to fill condition not met. Skipping.") |  | ||||||
|                     continue |  | ||||||
| 
 | 
 | ||||||
|             if placement.from_pool:  # Should happen AFTER the item is placed, in case it was allowed to skip failed placement. |             if placement.from_pool:  # Should happen AFTER the item is placed, in case it was allowed to skip failed placement. | ||||||
|                 try: |                 try: | ||||||
|                     world.itempool.remove(item) |                     world.itempool.remove(item) | ||||||
|                 except ValueError: |                 except ValueError: | ||||||
|                     logging.warning(f"Could not remove {item} from pool as it's already missing from it.") |                     placement.warn(f"Could not remove {item} from pool as it's already missing from it.") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue