From a6d53aafb073ceb435b24e518deefd48ad202b98 Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Mon, 4 Jan 2021 13:50:27 -0800 Subject: [PATCH] Add option to hard require plando item placement. --- BaseClasses.py | 1 + Fill.py | 42 ++++++++++++++++++++++++++++++++---------- Mystery.py | 3 ++- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index 4729e4fd..46f49521 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -1477,6 +1477,7 @@ class PlandoItem(NamedTuple): location: str world: Union[bool, str] = False # False -> own world, True -> not own world 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. class PlandoConnection(NamedTuple): diff --git a/Fill.py b/Fill.py index 0ad4332f..efa9c95e 100644 --- a/Fill.py +++ b/Fill.py @@ -359,7 +359,11 @@ def distribute_planned(world): set(world.player_ids) - {player}) if location.item_rule(item) ) if not unfilled: - raise FillError(f"Could not find a world with an unfilled location {placement.location}") + if placement.force: + raise FillError(f"Could not find a world with an unfilled location {placement.location}") + else: + logging.warning(f"Could not find a world with an unfilled location {placement.location}, skipping.") + continue target_world = world.random.choice(unfilled).player @@ -369,24 +373,32 @@ def distribute_planned(world): set(world.player_ids)) if location.item_rule(item) ) if not unfilled: - raise FillError(f"Could not find a world with an unfilled location {placement.location}") + if placement.force: + raise FillError(f"Could not find a world with an unfilled location {placement.location}") + else: + logging.warning(f"Could not find a world with an unfilled location {placement.location}, skipping.") + continue target_world = world.random.choice(unfilled).player elif type(target_world) == int: # target world by player id pass else: # find world by name + if target_world not in world_name_lookup: + if placement.force: + raise Exception(f"Cannot place item to {target_world}'s world as that world does not exist.") + 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] location = world.get_location(placement.location, target_world) if location.item: - raise Exception(f"Cannot place item into already filled location {location}.") - - if placement.from_pool: - try: - world.itempool.remove(item) - except ValueError: - logging.warning(f"Could not remove {item} from pool as it's already missing from it.") + if placement.force: + raise Exception(f"Cannot place item into already filled location {location}.") + else: + logging.warning(f"Cannot place item into already filled location {location}. Skipping.") + continue if location.can_fill(world.state, item, False): world.push_item(location, item, collect=False) @@ -394,4 +406,14 @@ def distribute_planned(world): location.locked = True logging.debug(f"Plando placed {item} at {location}") else: - raise Exception(f"Can't place {item} at {location} due to fill condition not met.") + if placement.force: + raise Exception(f"Can't place {item} at {location} due to fill condition not met.") + 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. + try: + world.itempool.remove(item) + except ValueError: + logging.warning(f"Could not remove {item} from pool as it's already missing from it.") diff --git a/Mystery.py b/Mystery.py index b11c789c..38507af9 100644 --- a/Mystery.py +++ b/Mystery.py @@ -568,7 +568,8 @@ def roll_settings(weights, plando_options: typing.Set[str] = frozenset(("bosses" raise Exception(f"Could not plando item {item} at location {location} as the location was not recognized") from_pool = get_choice("from_pool", placement, True) location_world = get_choice("world", placement, False) - ret.plando_items.append(PlandoItem(item, location, location_world, from_pool)) + force = get_choice("force", placement, False) + ret.plando_items.append(PlandoItem(item, location, location_world, from_pool, force)) ret.plando_texts = {} if "texts" in plando_options: