Allow for rom options in linked/triggered options without needing to...
...overwrite the entire rom tree.
This commit is contained in:
parent
5e619dec60
commit
44f4f7f20c
32
Mystery.py
32
Mystery.py
|
@ -291,6 +291,17 @@ def roll_percentage(percentage: typing.Union[int, float]) -> bool:
|
||||||
percentage is expected to be in range [0, 100]"""
|
percentage is expected to be in range [0, 100]"""
|
||||||
return random.random() < (float(percentage) / 100)
|
return random.random() < (float(percentage) / 100)
|
||||||
|
|
||||||
|
def update_weights(weights: dict, new_weights: dict, type: str, name: str) -> dict:
|
||||||
|
logging.debug(f'Applying {new_weights}')
|
||||||
|
new_options = set(new_weights) - set(weights)
|
||||||
|
weights.update(new_weights)
|
||||||
|
if new_options:
|
||||||
|
for new_option in new_options:
|
||||||
|
logging.warning(f'{type} Suboption "{new_option}" of "{name}" did not '
|
||||||
|
f'overwrite a root option. '
|
||||||
|
f'This is probably in error.')
|
||||||
|
return weights
|
||||||
|
|
||||||
def roll_linked_options(weights: dict) -> dict:
|
def roll_linked_options(weights: dict) -> dict:
|
||||||
weights = weights.copy() # make sure we don't write back to other weights sets in same_settings
|
weights = weights.copy() # make sure we don't write back to other weights sets in same_settings
|
||||||
for option_set in weights["linked_options"]:
|
for option_set in weights["linked_options"]:
|
||||||
|
@ -299,14 +310,12 @@ def roll_linked_options(weights: dict) -> dict:
|
||||||
try:
|
try:
|
||||||
if roll_percentage(option_set["percentage"]):
|
if roll_percentage(option_set["percentage"]):
|
||||||
logging.debug(f"Linked option {option_set['name']} triggered.")
|
logging.debug(f"Linked option {option_set['name']} triggered.")
|
||||||
logging.debug(f'Applying {option_set["options"]}')
|
if "options" in option_set:
|
||||||
new_options = set(option_set["options"]) - set(weights)
|
weights = update_weights(weights, option_set["options"], "Linked", option_set["name"])
|
||||||
weights.update(option_set["options"])
|
if "rom_options" in option_set:
|
||||||
if new_options:
|
rom_weights = weights.get("rom", dict())
|
||||||
for new_option in new_options:
|
rom_weights = update_weights(rom_weights, option_set["rom_options"], "Linked Rom", option_set["name"])
|
||||||
logging.warning(f'Linked Suboption "{new_option}" of "{option_set["name"]}" did not '
|
weights["rom"] = rom_weights
|
||||||
f'overwrite a root option. '
|
|
||||||
f"This is probably in error.")
|
|
||||||
else:
|
else:
|
||||||
logging.debug(f"linked option {option_set['name']} skipped.")
|
logging.debug(f"linked option {option_set['name']} skipped.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -322,7 +331,12 @@ def roll_triggers(weights: dict) -> dict:
|
||||||
trigger_result = get_choice("option_result", option_set)
|
trigger_result = get_choice("option_result", option_set)
|
||||||
result = get_choice(key, weights)
|
result = get_choice(key, weights)
|
||||||
if result == trigger_result and roll_percentage(get_choice("percentage", option_set, 100)):
|
if result == trigger_result and roll_percentage(get_choice("percentage", option_set, 100)):
|
||||||
weights.update(option_set["options"])
|
if "options" in option_set:
|
||||||
|
weights = update_weights(weights, option_set["options"], "Triggered", option_set["option_name"])
|
||||||
|
if "rom_options" in option_set:
|
||||||
|
rom_weights = weights.get("rom", dict())
|
||||||
|
rom_weights = update_weights(rom_weights, option_set["rom_options"], "Triggered Rom", option_set["option_name"])
|
||||||
|
weights["rom"] = rom_weights
|
||||||
weights[key] = result
|
weights[key] = result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(f"A trigger is destroyed. "
|
raise ValueError(f"A trigger is destroyed. "
|
||||||
|
|
Loading…
Reference in New Issue