Cleanup bosses.py
This commit is contained in:
parent
ebd6a9e3cf
commit
49189bec02
140
Bosses.py
140
Bosses.py
|
@ -1,19 +1,22 @@
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from BaseClasses import Boss
|
from BaseClasses import Boss
|
||||||
from Fill import FillError
|
from Fill import FillError
|
||||||
|
|
||||||
def BossFactory(boss, player):
|
|
||||||
|
def BossFactory(boss: str, player: int) -> Optional[Boss]:
|
||||||
if boss is None:
|
if boss is None:
|
||||||
return None
|
return None
|
||||||
if boss in boss_table:
|
if boss in boss_table:
|
||||||
enemizer_name, defeat_rule = boss_table[boss]
|
enemizer_name, defeat_rule = boss_table[boss]
|
||||||
return Boss(boss, enemizer_name, defeat_rule, player)
|
return Boss(boss, enemizer_name, defeat_rule, player)
|
||||||
|
|
||||||
logging.getLogger('').error('Unknown Boss: %s', boss)
|
logging.error('Unknown Boss: %s', boss)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def ArmosKnightsDefeatRule(state, player):
|
|
||||||
|
def ArmosKnightsDefeatRule(state, player: int):
|
||||||
# Magic amounts are probably a bit overkill
|
# Magic amounts are probably a bit overkill
|
||||||
return (
|
return (
|
||||||
state.has_melee_weapon(player) or
|
state.has_melee_weapon(player) or
|
||||||
|
@ -25,7 +28,8 @@ def ArmosKnightsDefeatRule(state, player):
|
||||||
state.has('Blue Boomerang', player) or
|
state.has('Blue Boomerang', player) or
|
||||||
state.has('Red Boomerang', player))
|
state.has('Red Boomerang', player))
|
||||||
|
|
||||||
def LanmolasDefeatRule(state, player):
|
|
||||||
|
def LanmolasDefeatRule(state, player: int):
|
||||||
return (
|
return (
|
||||||
state.has_melee_weapon(player) or
|
state.has_melee_weapon(player) or
|
||||||
state.has('Fire Rod', player) or
|
state.has('Fire Rod', player) or
|
||||||
|
@ -34,14 +38,17 @@ def LanmolasDefeatRule(state, player):
|
||||||
state.has('Cane of Byrna', player) or
|
state.has('Cane of Byrna', player) or
|
||||||
state.can_shoot_arrows(player))
|
state.can_shoot_arrows(player))
|
||||||
|
|
||||||
def MoldormDefeatRule(state, player):
|
|
||||||
|
def MoldormDefeatRule(state, player: int):
|
||||||
return state.has_melee_weapon(player)
|
return state.has_melee_weapon(player)
|
||||||
|
|
||||||
def HelmasaurKingDefeatRule(state, player):
|
|
||||||
|
def HelmasaurKingDefeatRule(state, player: int):
|
||||||
# TODO: technically possible with the hammer
|
# TODO: technically possible with the hammer
|
||||||
return state.has_sword(player) or state.can_shoot_arrows(player)
|
return state.has_sword(player) or state.can_shoot_arrows(player)
|
||||||
|
|
||||||
def ArrghusDefeatRule(state, player):
|
|
||||||
|
def ArrghusDefeatRule(state, player: int):
|
||||||
if not state.has('Hookshot', player):
|
if not state.has('Hookshot', player):
|
||||||
return False
|
return False
|
||||||
# TODO: ideally we would have a check for bow and silvers, which combined with the
|
# TODO: ideally we would have a check for bow and silvers, which combined with the
|
||||||
|
@ -50,11 +57,12 @@ def ArrghusDefeatRule(state, player):
|
||||||
if state.has_melee_weapon(player):
|
if state.has_melee_weapon(player):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return ((state.has('Fire Rod', player) and (state.can_shoot_arrows(player) or state.can_extend_magic(player, 12))) or #assuming mostly gitting two puff with one shot
|
return ((state.has('Fire Rod', player) and (state.can_shoot_arrows(player) or state.can_extend_magic(player,
|
||||||
|
12))) or # assuming mostly gitting two puff with one shot
|
||||||
(state.has('Ice Rod', player) and (state.can_shoot_arrows(player) or state.can_extend_magic(player, 16))))
|
(state.has('Ice Rod', player) and (state.can_shoot_arrows(player) or state.can_extend_magic(player, 16))))
|
||||||
|
|
||||||
|
|
||||||
def MothulaDefeatRule(state, player):
|
def MothulaDefeatRule(state, player: int):
|
||||||
return (
|
return (
|
||||||
state.has_melee_weapon(player) or
|
state.has_melee_weapon(player) or
|
||||||
(state.has('Fire Rod', player) and state.can_extend_magic(player, 10)) or
|
(state.has('Fire Rod', player) and state.can_extend_magic(player, 10)) or
|
||||||
|
@ -65,19 +73,21 @@ def MothulaDefeatRule(state, player):
|
||||||
state.can_get_good_bee(player)
|
state.can_get_good_bee(player)
|
||||||
)
|
)
|
||||||
|
|
||||||
def BlindDefeatRule(state, player):
|
|
||||||
|
def BlindDefeatRule(state, player: int):
|
||||||
return state.has_melee_weapon(player) or state.has('Cane of Somaria', player) or state.has('Cane of Byrna', player)
|
return state.has_melee_weapon(player) or state.has('Cane of Somaria', player) or state.has('Cane of Byrna', player)
|
||||||
|
|
||||||
def KholdstareDefeatRule(state, player):
|
|
||||||
|
def KholdstareDefeatRule(state, player: int):
|
||||||
return (
|
return (
|
||||||
(
|
(
|
||||||
state.has('Fire Rod', player) or
|
state.has('Fire Rod', player) or
|
||||||
(
|
(
|
||||||
state.has('Bombos', player) and
|
state.has('Bombos', player) and
|
||||||
# FIXME: the following only actually works for the vanilla location for swordless
|
# FIXME: the following only actually works for the vanilla location for swordless
|
||||||
(state.has_sword(player) or state.world.swords[player] == 'swordless')
|
(state.has_sword(player) or state.world.swords[player] == 'swordless')
|
||||||
)
|
)
|
||||||
) and
|
) and
|
||||||
(
|
(
|
||||||
state.has_melee_weapon(player) or
|
state.has_melee_weapon(player) or
|
||||||
(state.has('Fire Rod', player) and state.can_extend_magic(player, 20)) or
|
(state.has('Fire Rod', player) and state.can_extend_magic(player, 20)) or
|
||||||
|
@ -91,19 +101,23 @@ def KholdstareDefeatRule(state, player):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def VitreousDefeatRule(state, player):
|
|
||||||
|
def VitreousDefeatRule(state, player: int):
|
||||||
return state.can_shoot_arrows(player) or state.has_melee_weapon(player)
|
return state.can_shoot_arrows(player) or state.has_melee_weapon(player)
|
||||||
|
|
||||||
def TrinexxDefeatRule(state, player):
|
|
||||||
|
def TrinexxDefeatRule(state, player: int):
|
||||||
if not (state.has('Fire Rod', player) and state.has('Ice Rod', player)):
|
if not (state.has('Fire Rod', player) and state.has('Ice Rod', player)):
|
||||||
return False
|
return False
|
||||||
return state.has('Hammer', player) or state.has('Tempered Sword', player) or state.has('Golden Sword', player) or \
|
return state.has('Hammer', player) or state.has('Tempered Sword', player) or state.has('Golden Sword', player) or \
|
||||||
(state.has('Master Sword', player) and state.can_extend_magic(player, 16)) or \
|
(state.has('Master Sword', player) and state.can_extend_magic(player, 16)) or \
|
||||||
(state.has_sword(player) and state.can_extend_magic(player, 32))
|
(state.has_sword(player) and state.can_extend_magic(player, 32))
|
||||||
|
|
||||||
def AgahnimDefeatRule(state, player):
|
|
||||||
|
def AgahnimDefeatRule(state, player: int):
|
||||||
return state.has_sword(player) or state.has('Hammer', player) or state.has('Bug Catching Net', player)
|
return state.has_sword(player) or state.has('Hammer', player) or state.has('Bug Catching Net', player)
|
||||||
|
|
||||||
|
|
||||||
boss_table = {
|
boss_table = {
|
||||||
'Armos Knights': ('Armos', ArmosKnightsDefeatRule),
|
'Armos Knights': ('Armos', ArmosKnightsDefeatRule),
|
||||||
'Lanmolas': ('Lanmola', LanmolasDefeatRule),
|
'Lanmolas': ('Lanmola', LanmolasDefeatRule),
|
||||||
|
@ -119,31 +133,36 @@ boss_table = {
|
||||||
'Agahnim2': ('Agahnim2', AgahnimDefeatRule)
|
'Agahnim2': ('Agahnim2', AgahnimDefeatRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
anywhere_bosses = ["Moldorm", "Helmasaur King", "Mothula", "Vitreous"]
|
|
||||||
|
|
||||||
def can_place_boss(world, player, boss, dungeon_name, level=None):
|
def can_place_boss(world, player: int, boss: str, dungeon_name: str, level: Optional[str] = None) -> bool:
|
||||||
if world.swords[player] in ['swordless'] and boss == 'Kholdstare' and dungeon_name != 'Ice Palace':
|
if world.swords[player] in ['swordless'] and boss == 'Kholdstare' and dungeon_name != 'Ice Palace':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if dungeon_name in ['Ganons Tower', 'Inverted Ganons Tower'] and level == 'top':
|
if dungeon_name in ['Ganons Tower', 'Inverted Ganons Tower'] and level == 'top':
|
||||||
if boss in ["Armos Knights", "Arrghus", "Blind", "Trinexx", "Lanmolas"]:
|
if boss in ["Armos Knights", "Arrghus", "Blind", "Trinexx", "Lanmolas"]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if dungeon_name in ['Ganons Tower', 'Inverted Ganons Tower'] and level == 'middle':
|
if dungeon_name in ['Ganons Tower', 'Inverted Ganons Tower'] and level == 'middle':
|
||||||
if boss in ["Blind"]:
|
if boss in ["Blind"]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if dungeon_name == 'Tower of Hera' and boss in ["Armos Knights", "Arrghus", "Blind", "Trinexx", "Lanmolas"]:
|
if dungeon_name == 'Tower of Hera' and boss in ["Armos Knights", "Arrghus", "Blind", "Trinexx", "Lanmolas"]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if dungeon_name == 'Skull Woods' and boss in ["Trinexx"]:
|
if dungeon_name == 'Skull Woods' and boss in ["Trinexx"]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if boss in ["Agahnim", "Agahnim2", "Ganon"]:
|
if boss in ["Agahnim", "Agahnim2", "Ganon"]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def place_bosses(world, player):
|
|
||||||
|
def place_boss(world, player: int, boss: str, location: str, level: Optional[str]):
|
||||||
|
logging.debug('Placing boss %s at %s', boss, location + (' (' + level + ')' if level else ''))
|
||||||
|
world.get_dungeon(location, player).bosses[level] = BossFactory(boss, player)
|
||||||
|
|
||||||
|
|
||||||
|
def place_bosses(world, player: int):
|
||||||
if world.boss_shuffle[player] == 'none':
|
if world.boss_shuffle[player] == 'none':
|
||||||
return
|
return
|
||||||
# Most to least restrictive order
|
# Most to least restrictive order
|
||||||
|
@ -180,63 +199,64 @@ def place_bosses(world, player):
|
||||||
['Inverted Ganons Tower', 'bottom'],
|
['Inverted Ganons Tower', 'bottom'],
|
||||||
]
|
]
|
||||||
|
|
||||||
all_bosses = sorted(boss_table.keys()) #sorted to be deterministic on older pythons
|
all_bosses = sorted(boss_table.keys()) # sorted to be deterministic on older pythons
|
||||||
placeable_bosses = [boss for boss in all_bosses if boss not in ['Agahnim', 'Agahnim2', 'Ganon']]
|
placeable_bosses = [boss for boss in all_bosses if boss not in ['Agahnim', 'Agahnim2', 'Ganon']]
|
||||||
|
anywhere_bosses = [boss for boss in placeable_bosses if all(
|
||||||
|
can_place_boss(world, player, boss, loc, level) for loc, level in boss_locations)]
|
||||||
if world.boss_shuffle[player] in ["basic", "normal"]:
|
if world.boss_shuffle[player] in ["basic", "normal"]:
|
||||||
# temporary hack for swordless kholdstare:
|
# temporary hack for swordless kholdstare:
|
||||||
if world.swords[player] == 'swordless':
|
if world.swords[player] == 'swordless':
|
||||||
world.get_dungeon('Ice Palace', player).boss = BossFactory('Kholdstare', player)
|
place_boss(world, player, 'Kholdstare', 'Ice Palace', None)
|
||||||
logging.getLogger('').debug('Placing boss Kholdstare at Ice Palace')
|
|
||||||
boss_locations.remove(['Ice Palace', None])
|
boss_locations.remove(['Ice Palace', None])
|
||||||
placeable_bosses.remove('Kholdstare')
|
placeable_bosses.remove('Kholdstare')
|
||||||
|
|
||||||
if world.boss_shuffle[player] == "basic": # vanilla bosses shuffled
|
if world.boss_shuffle[player] == "basic": # vanilla bosses shuffled
|
||||||
bosses = placeable_bosses + ['Armos Knights', 'Lanmolas', 'Moldorm']
|
bosses = placeable_bosses + ['Armos Knights', 'Lanmolas', 'Moldorm']
|
||||||
else: # all bosses present, the three duplicates chosen at random
|
else: # all bosses present, the three duplicates chosen at random
|
||||||
bosses = all_bosses + [world.random.choice(placeable_bosses) for _ in range(3)]
|
bosses = all_bosses + [world.random.choice(placeable_bosses) for _ in range(3)]
|
||||||
|
|
||||||
logging.debug('Bosses chosen %s', bosses)
|
logging.debug('Bosses chosen %s', bosses)
|
||||||
|
|
||||||
world.random.shuffle(bosses)
|
world.random.shuffle(bosses)
|
||||||
for [loc, level] in boss_locations:
|
for [loc, level] in boss_locations:
|
||||||
loc_text = loc + (' ('+level+')' if level else '')
|
|
||||||
boss = next((b for b in bosses if can_place_boss(world, player, b, loc, level)), None)
|
boss = next((b for b in bosses if can_place_boss(world, player, b, loc, level)), None)
|
||||||
if not boss:
|
if not boss:
|
||||||
|
loc_text = loc + (' (' + level + ')' if level else '')
|
||||||
raise FillError('Could not place boss for location %s' % loc_text)
|
raise FillError('Could not place boss for location %s' % loc_text)
|
||||||
bosses.remove(boss)
|
bosses.remove(boss)
|
||||||
|
place_boss(world, player, boss, loc, level)
|
||||||
|
|
||||||
logging.debug('Placing boss %s at %s', boss, loc_text)
|
elif world.boss_shuffle[player] == "chaos": # all bosses chosen at random
|
||||||
world.get_dungeon(loc, player).bosses[level] = BossFactory(boss, player)
|
|
||||||
elif world.boss_shuffle[player] == "chaos": #all bosses chosen at random
|
|
||||||
for [loc, level] in boss_locations:
|
for [loc, level] in boss_locations:
|
||||||
loc_text = loc + (' ('+level+')' if level else '')
|
|
||||||
try:
|
try:
|
||||||
boss = world.random.choice(
|
boss = world.random.choice(
|
||||||
[b for b in placeable_bosses if can_place_boss(world, player, b, loc, level)])
|
[b for b in placeable_bosses if can_place_boss(world, player, b, loc, level)])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
loc_text = loc + (' (' + level + ')' if level else '')
|
||||||
raise FillError('Could not place boss for location %s' % loc_text)
|
raise FillError('Could not place boss for location %s' % loc_text)
|
||||||
|
else:
|
||||||
|
place_boss(world, player, boss, loc, level)
|
||||||
|
|
||||||
logging.debug('Placing boss %s at %s', boss, loc_text)
|
|
||||||
world.get_dungeon(loc, player).bosses[level] = BossFactory(boss, player)
|
|
||||||
elif world.boss_shuffle[player] == "singularity":
|
elif world.boss_shuffle[player] == "singularity":
|
||||||
if world.swords[player] == 'swordless':
|
boss = world.random.choice(anywhere_bosses)
|
||||||
boss = world.random.choice(anywhere_bosses)
|
for loc, level in boss_locations:
|
||||||
else:
|
place_boss(world, player, boss, loc, level)
|
||||||
boss = world.random.choice(anywhere_bosses + ["Kholdstare"])
|
|
||||||
for [loc, level] in boss_locations:
|
|
||||||
logging.debug('Placing boss %s at %s', boss, loc + (' ('+level+')' if level else ''))
|
|
||||||
world.get_dungeon(loc, player).bosses[level] = BossFactory(boss, player)
|
|
||||||
elif world.boss_shuffle[player] == "duality":
|
elif world.boss_shuffle[player] == "duality":
|
||||||
if world.swords[player] == 'swordless':
|
# pick a boss that can only appear in some places
|
||||||
used_anywhere_bosses = anywhere_bosses
|
limited_boss = world.random.choice([boss for boss in placeable_bosses if boss not in anywhere_bosses])
|
||||||
else:
|
|
||||||
used_anywhere_bosses = anywhere_bosses + ["Kholdstare"]
|
|
||||||
|
|
||||||
limited_boss = world.random.choice([boss for boss in placeable_bosses if boss not in used_anywhere_bosses])
|
remaining_boss_locations = []
|
||||||
anywhere_boss = world.random.choice(used_anywhere_bosses)
|
for loc, level in boss_locations:
|
||||||
|
#place that boss where it can go
|
||||||
for [loc, level] in boss_locations:
|
if can_place_boss(world, player, limited_boss, loc, level):
|
||||||
boss = limited_boss if can_place_boss(world, player, limited_boss, loc, level) else anywhere_boss
|
place_boss(world, player, limited_boss, loc, level)
|
||||||
logging.debug('Placing boss %s at %s', boss, loc + (' ('+level+')' if level else ''))
|
else:
|
||||||
world.get_dungeon(loc, player).bosses[level] = BossFactory(boss, player)
|
remaining_boss_locations.append((loc, level))
|
||||||
|
#pick a boss to go into the remaining locations
|
||||||
|
remaining_boss = world.random.choice([boss for boss in placeable_bosses if all(
|
||||||
|
can_place_boss(world, player, boss, loc, level) for loc, level in remaining_boss_locations)])
|
||||||
|
logging.info([boss for boss in placeable_bosses if all(
|
||||||
|
can_place_boss(world, player, boss, loc, level) for loc, level in remaining_boss_locations)])
|
||||||
|
for loc, level in remaining_boss_locations:
|
||||||
|
place_boss(world, player, remaining_boss, loc, level)
|
||||||
|
|
Loading…
Reference in New Issue