Skip to content

Commit

Permalink
re-order pre_fill to properly handle animal fill
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvris committed Aug 26, 2023
1 parent 0e1e051 commit b81d1c3
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions worlds/kdl3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ def get_trap_item_name(self) -> str:
self.multiworld.ability_trap_weight[self.player]])[0]

def pre_fill(self) -> None:
if self.multiworld.copy_ability_randomization[self.player]:
# randomize copy abilities
valid_abilities = list(copy_ability_access_table.keys())
enemies_to_set = list(self.copy_abilities.keys())
# now for the edge cases
for abilities, enemies in enemy_restrictive:
available_enemies = list()
for enemy in enemies:
if enemy not in enemies_to_set:
if self.copy_abilities[enemy] in abilities:
break
else:
available_enemies.append(enemy)
else:
chosen_enemy = self.random.choice(available_enemies)
chosen_ability = self.random.choice(tuple(abilities))
self.copy_abilities[chosen_enemy] = chosen_ability
enemies_to_set.remove(chosen_enemy)
# place remaining
for enemy in enemies_to_set:
self.copy_abilities[enemy] = self.random \
.choice(valid_abilities)

for enemy in enemy_mapping:
self.multiworld.get_location(enemy, self.player) \
.place_locked_item(self.create_item(self.copy_abilities[enemy_mapping[enemy]]))
# fill animals
if self.multiworld.animal_randomization[self.player] != 0:
spawns = [animal for animal in animal_friend_spawns.keys() if
Expand Down Expand Up @@ -146,32 +172,7 @@ def pre_fill(self) -> None:
self.multiworld.get_location(animal, self.player) \
.place_locked_item(self.create_item(animal_friends[animal]))

if self.multiworld.copy_ability_randomization[self.player]:
# randomize copy abilities
valid_abilities = list(copy_ability_access_table.keys())
enemies_to_set = list(self.copy_abilities.keys())
# now for the edge cases
for abilities, enemies in enemy_restrictive:
available_enemies = list()
for enemy in enemies:
if enemy not in enemies_to_set:
if self.copy_abilities[enemy] in abilities:
break
else:
available_enemies.append(enemy)
else:
chosen_enemy = self.random.choice(available_enemies)
chosen_ability = self.random.choice(tuple(abilities))
self.copy_abilities[chosen_enemy] = chosen_ability
enemies_to_set.remove(chosen_enemy)
# place remaining
for enemy in enemies_to_set:
self.copy_abilities[enemy] = self.random \
.choice(valid_abilities)

for enemy in enemy_mapping:
self.multiworld.get_location(enemy, self.player) \
.place_locked_item(self.create_item(self.copy_abilities[enemy_mapping[enemy]]))

def create_items(self) -> None:
itempool = []
Expand Down

0 comments on commit b81d1c3

Please sign in to comment.