Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFMQ: Efficiency Improvement and Use New Options Methods #2767

Merged
merged 10 commits into from
Jul 24, 2024
2 changes: 1 addition & 1 deletion worlds/ffmq/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def game_watcher(self, ctx):
received = await snes_read(ctx, RECEIVED_DATA[0], RECEIVED_DATA[1])
data = await snes_read(ctx, READ_DATA_START, READ_DATA_END - READ_DATA_START)
check_2 = await snes_read(ctx, 0xF53749, 1)
if check_1 in (b'\x00', b'\x55') or check_2 in (b'\x00', b'\x55'):
if check_1 != b'01' or check_2 != b'01':
Alchav marked this conversation as resolved.
Show resolved Hide resolved
return

def get_range(data_range):
Expand Down
20 changes: 10 additions & 10 deletions worlds/ffmq/Items.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,39 +222,39 @@ def yaml_item(text):

def create_items(self) -> None:
items = []
starting_weapon = self.multiworld.starting_weapon[self.player].current_key.title().replace("_", " ")
starting_weapon = self.options.starting_weapon.current_key.title().replace("_", " ")
self.multiworld.push_precollected(self.create_item(starting_weapon))
self.multiworld.push_precollected(self.create_item("Steel Armor"))
if self.multiworld.sky_coin_mode[self.player] == "start_with":
if self.options.sky_coin_mode == "start_with":
self.multiworld.push_precollected(self.create_item("Sky Coin"))

precollected_item_names = {item.name for item in self.multiworld.precollected_items[self.player]}

def add_item(item_name):
if item_name in ["Steel Armor", "Sky Fragment"] or "Progressive" in item_name:
return
if item_name.lower().replace(" ", "_") == self.multiworld.starting_weapon[self.player].current_key:
if item_name.lower().replace(" ", "_") == self.options.starting_weapon.current_key:
return
if self.multiworld.progressive_gear[self.player]:
if self.options.progressive_gear:
for item_group in prog_map:
if item_name in self.item_name_groups[item_group]:
item_name = prog_map[item_group]
break
if item_name == "Sky Coin":
if self.multiworld.sky_coin_mode[self.player] == "shattered_sky_coin":
if self.options.sky_coin_mode == "shattered_sky_coin":
for _ in range(40):
items.append(self.create_item("Sky Fragment"))
return
elif self.multiworld.sky_coin_mode[self.player] == "save_the_crystals":
elif self.options.sky_coin_mode == "save_the_crystals":
items.append(self.create_filler())
return
if item_name in precollected_item_names:
items.append(self.create_filler())
return
i = self.create_item(item_name)
if self.multiworld.logic[self.player] != "friendly" and item_name in ("Magic Mirror", "Mask"):
if self.options.logic != "friendly" and item_name in ("Magic Mirror", "Mask"):
i.classification = ItemClassification.useful
if (self.multiworld.logic[self.player] == "expert" and self.multiworld.map_shuffle[self.player] == "none" and
if (self.options.logic == "expert" and self.options.map_shuffle == "none" and
item_name == "Exit Book"):
i.classification = ItemClassification.progression
items.append(i)
Expand All @@ -263,11 +263,11 @@ def add_item(item_name):
for item in self.item_name_groups[item_group]:
add_item(item)

if self.multiworld.brown_boxes[self.player] == "include":
if self.options.brown_boxes == "include":
filler_items = []
for item, count in fillers.items():
filler_items += [self.create_item(item) for _ in range(count)]
if self.multiworld.sky_coin_mode[self.player] == "shattered_sky_coin":
if self.options.sky_coin_mode == "shattered_sky_coin":
self.multiworld.random.shuffle(filler_items)
filler_items = filler_items[39:]
items += filler_items
Expand Down
69 changes: 35 additions & 34 deletions worlds/ffmq/Options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Options import Choice, FreeText, Toggle, Range
from Options import Choice, FreeText, Toggle, Range, PerGameCommonOptions
from dataclasses import dataclass


class Logic(Choice):
Expand Down Expand Up @@ -321,36 +322,36 @@ class KaelisMomFightsMinotaur(Toggle):
default = 0


option_definitions = {
"logic": Logic,
"brown_boxes": BrownBoxes,
"sky_coin_mode": SkyCoinMode,
"shattered_sky_coin_quantity": ShatteredSkyCoinQuantity,
"starting_weapon": StartingWeapon,
"progressive_gear": ProgressiveGear,
"leveling_curve": LevelingCurve,
"starting_companion": StartingCompanion,
"available_companions": AvailableCompanions,
"companions_locations": CompanionsLocations,
"kaelis_mom_fight_minotaur": KaelisMomFightsMinotaur,
"companion_leveling_type": CompanionLevelingType,
"companion_spellbook_type": CompanionSpellbookType,
"enemies_density": EnemiesDensity,
"enemies_scaling_lower": EnemiesScalingLower,
"enemies_scaling_upper": EnemiesScalingUpper,
"bosses_scaling_lower": BossesScalingLower,
"bosses_scaling_upper": BossesScalingUpper,
"enemizer_attacks": EnemizerAttacks,
"enemizer_groups": EnemizerGroups,
"shuffle_res_weak_types": ShuffleResWeakType,
"shuffle_enemies_position": ShuffleEnemiesPositions,
"progressive_formations": ProgressiveFormations,
"doom_castle_mode": DoomCastle,
"doom_castle_shortcut": DoomCastleShortcut,
"tweak_frustrating_dungeons": TweakFrustratingDungeons,
"map_shuffle": MapShuffle,
"crest_shuffle": CrestShuffle,
"shuffle_battlefield_rewards": ShuffleBattlefieldRewards,
"map_shuffle_seed": MapShuffleSeed,
"battlefields_battles_quantities": BattlefieldsBattlesQuantities,
}
@dataclass
class FFMQOptions(PerGameCommonOptions):
logic: Logic
brown_boxes: BrownBoxes
sky_coin_mode: SkyCoinMode
shattered_sky_coin_quantity: ShatteredSkyCoinQuantity
starting_weapon: StartingWeapon
progressive_gear: ProgressiveGear
leveling_curve: LevelingCurve
starting_companion: StartingCompanion
available_companions: AvailableCompanions
companions_locations: CompanionsLocations
kaelis_mom_fight_minotaur: KaelisMomFightsMinotaur
companion_leveling_type: CompanionLevelingType
companion_spellbook_type: CompanionSpellbookType
enemies_density: EnemiesDensity
enemies_scaling_lower: EnemiesScalingLower
enemies_scaling_upper: EnemiesScalingUpper
bosses_scaling_lower: BossesScalingLower
bosses_scaling_upper: BossesScalingUpper
enemizer_attacks: EnemizerAttacks
enemizer_groups: EnemizerGroups
shuffle_res_weak_types: ShuffleResWeakType
shuffle_enemies_position: ShuffleEnemiesPositions
progressive_formations: ProgressiveFormations
doom_castle_mode: DoomCastle
doom_castle_shortcut: DoomCastleShortcut
tweak_frustrating_dungeons: TweakFrustratingDungeons
map_shuffle: MapShuffle
crest_shuffle: CrestShuffle
shuffle_battlefield_rewards: ShuffleBattlefieldRewards
map_shuffle_seed: MapShuffleSeed
battlefields_battles_quantities: BattlefieldsBattlesQuantities
74 changes: 37 additions & 37 deletions worlds/ffmq/Output.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import yaml
import os
import zipfile
import Utils
from copy import deepcopy
from .Regions import object_id_table
from Utils import __version__
from worlds.Files import APPatch
import pkgutil

settings_template = yaml.load(pkgutil.get_data(__name__, "data/settings.yaml"), yaml.Loader)
settings_template = Utils.parse_yaml(pkgutil.get_data(__name__, "data/settings.yaml"))


def generate_output(self, output_directory):
Expand All @@ -21,7 +21,7 @@ def output_item_name(item):
item_name = "".join(item_name.split(" "))
else:
if item.advancement or item.useful or (item.trap and
self.multiworld.per_slot_randoms[self.player].randint(0, 1)):
self.random.randint(0, 1)):
item_name = "APItem"
else:
item_name = "APItemFiller"
Expand All @@ -46,60 +46,60 @@ def tf(option):
options = deepcopy(settings_template)
options["name"] = self.multiworld.player_name[self.player]
option_writes = {
"enemies_density": cc(self.multiworld.enemies_density[self.player]),
"enemies_density": cc(self.options.enemies_density),
"chests_shuffle": "Include",
"shuffle_boxes_content": self.multiworld.brown_boxes[self.player] == "shuffle",
"shuffle_boxes_content": self.options.brown_boxes == "shuffle",
"npcs_shuffle": "Include",
"battlefields_shuffle": "Include",
"logic_options": cc(self.multiworld.logic[self.player]),
"shuffle_enemies_position": tf(self.multiworld.shuffle_enemies_position[self.player]),
"enemies_scaling_lower": cc(self.multiworld.enemies_scaling_lower[self.player]),
"enemies_scaling_upper": cc(self.multiworld.enemies_scaling_upper[self.player]),
"bosses_scaling_lower": cc(self.multiworld.bosses_scaling_lower[self.player]),
"bosses_scaling_upper": cc(self.multiworld.bosses_scaling_upper[self.player]),
"enemizer_attacks": cc(self.multiworld.enemizer_attacks[self.player]),
"leveling_curve": cc(self.multiworld.leveling_curve[self.player]),
"battles_quantity": cc(self.multiworld.battlefields_battles_quantities[self.player]) if
self.multiworld.battlefields_battles_quantities[self.player].value < 5 else
"logic_options": cc(self.options.logic),
"shuffle_enemies_position": tf(self.options.shuffle_enemies_position),
"enemies_scaling_lower": cc(self.options.enemies_scaling_lower),
"enemies_scaling_upper": cc(self.options.enemies_scaling_upper),
"bosses_scaling_lower": cc(self.options.bosses_scaling_lower),
"bosses_scaling_upper": cc(self.options.bosses_scaling_upper),
"enemizer_attacks": cc(self.options.enemizer_attacks),
"leveling_curve": cc(self.options.leveling_curve),
"battles_quantity": cc(self.options.battlefields_battles_quantities) if
self.options.battlefields_battles_quantities.value < 5 else
"RandomLow" if
self.multiworld.battlefields_battles_quantities[self.player].value == 5 else
self.options.battlefields_battles_quantities.value == 5 else
"RandomHigh",
"shuffle_battlefield_rewards": tf(self.multiworld.shuffle_battlefield_rewards[self.player]),
"shuffle_battlefield_rewards": tf(self.options.shuffle_battlefield_rewards),
"random_starting_weapon": True,
"progressive_gear": tf(self.multiworld.progressive_gear[self.player]),
"tweaked_dungeons": tf(self.multiworld.tweak_frustrating_dungeons[self.player]),
"doom_castle_mode": cc(self.multiworld.doom_castle_mode[self.player]),
"doom_castle_shortcut": tf(self.multiworld.doom_castle_shortcut[self.player]),
"sky_coin_mode": cc(self.multiworld.sky_coin_mode[self.player]),
"sky_coin_fragments_qty": cc(self.multiworld.shattered_sky_coin_quantity[self.player]),
"progressive_gear": tf(self.options.progressive_gear),
"tweaked_dungeons": tf(self.options.tweak_frustrating_dungeons),
"doom_castle_mode": cc(self.options.doom_castle_mode),
"doom_castle_shortcut": tf(self.options.doom_castle_shortcut),
"sky_coin_mode": cc(self.options.sky_coin_mode),
"sky_coin_fragments_qty": cc(self.options.shattered_sky_coin_quantity),
"enable_spoilers": False,
"progressive_formations": cc(self.multiworld.progressive_formations[self.player]),
"map_shuffling": cc(self.multiworld.map_shuffle[self.player]),
"crest_shuffle": tf(self.multiworld.crest_shuffle[self.player]),
"enemizer_groups": cc(self.multiworld.enemizer_groups[self.player]),
"shuffle_res_weak_type": tf(self.multiworld.shuffle_res_weak_types[self.player]),
"companion_leveling_type": cc(self.multiworld.companion_leveling_type[self.player]),
"companion_spellbook_type": cc(self.multiworld.companion_spellbook_type[self.player]),
"starting_companion": cc(self.multiworld.starting_companion[self.player]),
"progressive_formations": cc(self.options.progressive_formations),
"map_shuffling": cc(self.options.map_shuffle),
"crest_shuffle": tf(self.options.crest_shuffle),
"enemizer_groups": cc(self.options.enemizer_groups),
"shuffle_res_weak_type": tf(self.options.shuffle_res_weak_types),
"companion_leveling_type": cc(self.options.companion_leveling_type),
"companion_spellbook_type": cc(self.options.companion_spellbook_type),
"starting_companion": cc(self.options.starting_companion),
"available_companions": ["Zero", "One", "Two",
"Three", "Four"][self.multiworld.available_companions[self.player].value],
"companions_locations": cc(self.multiworld.companions_locations[self.player]),
"kaelis_mom_fight_minotaur": tf(self.multiworld.kaelis_mom_fight_minotaur[self.player]),
"Three", "Four"][self.options.available_companions.value],
"companions_locations": cc(self.options.companions_locations),
"kaelis_mom_fight_minotaur": tf(self.options.kaelis_mom_fight_minotaur),
}

for option, data in option_writes.items():
options["Final Fantasy Mystic Quest"][option][data] = 1

rom_name = f'MQ{__version__.replace(".", "")[0:3]}_{self.player}_{self.multiworld.seed_name:11}'[:21]
rom_name = f'MQ{Utils.__version__.replace(".", "")[0:3]}_{self.player}_{self.multiworld.seed_name:11}'[:21]
self.rom_name = bytearray(rom_name,
'utf8')
self.rom_name_available_event.set()

setup = {"version": "1.5", "name": self.multiworld.player_name[self.player], "romname": rom_name, "seed":
hex(self.multiworld.per_slot_randoms[self.player].randint(0, 0xFFFFFFFF)).split("0x")[1].upper()}
hex(self.random.randint(0, 0xFFFFFFFF)).split("0x")[1].upper()}

starting_items = [output_item_name(item) for item in self.multiworld.precollected_items[self.player]]
if self.multiworld.sky_coin_mode[self.player] == "shattered_sky_coin":
if self.options.sky_coin_mode == "shattered_sky_coin":
starting_items.append("SkyCoin")

file_path = os.path.join(output_directory, f"{self.multiworld.get_out_file_name_base(self.player)}.apmq")
Expand Down
Loading
Loading