Add option to hard require plando item placement.

This commit is contained in:
CaitSith2 2021-01-04 13:50:27 -08:00
parent e03841794b
commit a6d53aafb0
3 changed files with 35 additions and 11 deletions

View File

@ -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):

42
Fill.py
View File

@ -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.")

View File

@ -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: