From 1a24a73ccd98fafddcb70725228c7bd68bb229ca Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Fri, 1 Apr 2022 04:14:51 +0200 Subject: [PATCH] add forgotten file (#378) --- worlds/hk/templates/RulesTemplate.pyt | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 worlds/hk/templates/RulesTemplate.pyt diff --git a/worlds/hk/templates/RulesTemplate.pyt b/worlds/hk/templates/RulesTemplate.pyt new file mode 100644 index 00000000..bf02942e --- /dev/null +++ b/worlds/hk/templates/RulesTemplate.pyt @@ -0,0 +1,57 @@ +from ..generic.Rules import set_rule, add_rule + +units = { + "egg": "RANCIDEGGS", + "grub": "GRUBS", + "essence": "ESSENCE", + "charm": "CHARMS", +} + + +def hk_set_rule(hk_world, location: str, rule): + count = hk_world.created_multi_locations[location] + if count: + locations = [f"{location}_{x}" for x in range(1, count+1)] + elif (location, hk_world.player) in hk_world.world._location_cache: + locations = [location] + else: + return + for location in locations: + set_rule(hk_world.world.get_location(location, hk_world.player), rule) + + +def set_shop_prices(hk_world): + player = hk_world.player + for shop, unit in hk_world.shops.items(): + for i in range(1, 1 + hk_world.created_multi_locations[shop]): + loc = hk_world.world.get_location(f"{shop}_{i}", hk_world.player) + add_rule(loc, lambda state, unit=units[unit], cost=loc.cost: state.count(unit, player) > cost) + + +def set_rules(hk_world): + player = hk_world.player + world = hk_world.world + + # Events + {% for location, rule_text in event_rules.items() %} + hk_set_rule(hk_world, "{{location}}", lambda state: {{rule_text}}) + {%- endfor %} + + # Locations + {% for location, rule_text in location_rules.items() %} + hk_set_rule(hk_world, "{{location}}", lambda state: {{rule_text}}) + {%- endfor %} + + # Shop prices + set_shop_prices(hk_world) + + # Connectors + {% for entrance, rule_text in connectors_rules.items() %} + rule = lambda state: {{rule_text}} + entrance = world.get_entrance("{{entrance}}", player) + entrance.access_rule = rule + {%- if entrance not in one_ways %} + world.get_entrance("{{entrance}}_R", player).access_rule = lambda state, entrance= entrance: \ + rule(state) and entrance.can_reach(state) + {%- endif %} + {% endfor %} \ No newline at end of file