împlement optional hint system (defaults to off)

This commit is contained in:
Fabian Dill
2020-02-09 05:28:48 +01:00
parent 7c57a7337c
commit 14e24037a5
5 changed files with 160 additions and 85 deletions

View File

@@ -1,5 +1,5 @@
__author__ = "Berserker55" # you can find me on the ALTTP Randomizer Discord
__version__ = 1.5
__version__ = 1.6
"""
This script launches a Multiplayer "Multiworld" Mystery Game
@@ -10,42 +10,9 @@ After generation the server is automatically launched.
It is still up to the host to forward the correct port (38281 by default) and distribute the roms to the players.
Regular Mystery has to work for this first, such as a ALTTP Base ROM and Enemizer Setup.
A guide can be found here: https://docs.google.com/document/d/19FoqUkuyStMqhOq8uGiocskMo1KMjOW4nEeG81xrKoI/edit
This script itself should be placed within the Bonta Multiworld folder, that you download in step 1
Configuration can be found in host.yaml
"""
####config####
#location of your Enemizer CLI, available here: https://github.com/Bonta0/Enemizer/releases
enemizer_location:str = "EnemizerCLI/EnemizerCLI.Core.exe"
#Where to place the resulting files
outputpath:str = "MultiMystery"
#automatically launches {player_name}.yaml's ROM file using the OS's default program once generation completes. (likely your emulator)
#does nothing if the name is not found
#example: player_name = "Berserker"
player_name:str = ""
#Zip the resulting roms
#0 -> Don't
#1 -> Create a zip
#2 -> Create a zip and delete the ROMs that will be in it, except the hosts (requires player_name to be set correctly)
zip_roms:int = 1
#create a spoiler file
create_spoiler:bool = True
#create roms as race coms
race:bool= False
#folder from which the player yaml files are pulled from
player_files_folder:str = "Players"
#Version of python to use for Bonta Multiworld. Probably leave this as is, if you don't know what this does.
#can be tagged for bitness, for example "3.8-32" would be latest installed 3.8 on 32 bits
#special case: None -> use the python which was used to launch this file.
py_version:str = None
####end of config####
import os
import subprocess
import sys
@@ -57,31 +24,43 @@ def feedback(text:str):
if __name__ == "__main__":
try:
if not py_version:
py_version = f"{sys.version_info.major}.{sys.version_info.minor}"
print(f"{__author__}'s MultiMystery Launcher V{__version__}")
import ModuleUpdate
ModuleUpdate.update()
print(f"{__author__}'s MultiMystery Launcher V{__version__}")
if not os.path.exists(enemizer_location):
feedback(f"Enemizer not found at {enemizer_location}, please adjust the path in MultiMystery.py's config or put Enemizer in the default location.")
from Utils import parse_yaml
multi_mystery_options = parse_yaml(open("host.yaml").read())["multi_mystery_options"]
output_path = multi_mystery_options["output_path"]
enemizer_path = multi_mystery_options["enemizer_path"]
player_files_path = multi_mystery_options["player_files_path"]
race = multi_mystery_options["race"]
create_spoiler = multi_mystery_options["create_spoiler"]
zip_roms = multi_mystery_options["zip_roms"]
player_name = multi_mystery_options["player_name"]
py_version = f"{sys.version_info.major}.{sys.version_info.minor}"
if not os.path.exists(enemizer_path):
feedback(f"Enemizer not found at {enemizer_path}, please adjust the path in MultiMystery.py's config or put Enemizer in the default location.")
if not os.path.exists("Zelda no Densetsu - Kamigami no Triforce (Japan).sfc"):
feedback("Base rom is expected as Zelda no Densetsu - Kamigami no Triforce (Japan).sfc in the Multiworld root folder please place/rename it there.")
player_files = []
os.makedirs(player_files_folder, exist_ok=True)
for file in os.listdir(player_files_folder):
os.makedirs(player_files_path, exist_ok=True)
for file in os.listdir(player_files_path):
if file.lower().endswith(".yaml"):
player_files.append(file)
print(f"Player {file[:-5]} found.")
player_count = len(player_files)
if player_count == 0:
feedback(f"No player files found. Please put them in a {player_files_folder} folder.")
feedback(f"No player files found. Please put them in a {player_files_path} folder.")
else:
print(player_count, "Players found.")
player_string = ""
for i,file in enumerate(player_files):
player_string += f"--p{i+1} {os.path.join(player_files_folder, file)} "
player_string += f"--p{i+1} {os.path.join(player_files_path, file)} "
player_names = list(file[:-5] for file in player_files)
@@ -93,8 +72,8 @@ if __name__ == "__main__":
basemysterycommand = f"py -{py_version} Mystery.py" #source
command = f"{basemysterycommand} --multi {len(player_files)} {player_string} " \
f"--names {','.join(player_names)} --enemizercli {enemizer_location} " \
f"--outputpath {outputpath}" + " --create_spoiler" if create_spoiler else "" + " --race" if race else ""
f"--names {','.join(player_names)} --enemizercli {enemizer_path} " \
f"--outputpath {output_path}" + " --create_spoiler" if create_spoiler else "" + " --race" if race else ""
print(command)
import time
start = time.perf_counter()
@@ -116,20 +95,20 @@ if __name__ == "__main__":
except IndexError:
print(f"Could not find Player {player_name}")
else:
romfilename = os.path.join(outputpath, f"ER_{seedname}_P{index+1}_{player_name}.sfc")
romfilename = os.path.join(output_path, f"ER_{seedname}_P{index+1}_{player_name}.sfc")
import webbrowser
if os.path.exists(romfilename):
print(f"Launching ROM file {romfilename}")
webbrowser.open(romfilename)
if zip_roms:
zipname = os.path.join(outputpath, f"ER_{seedname}.zip")
zipname = os.path.join(output_path, f"ER_{seedname}.zip")
print(f"Creating zipfile {zipname}")
import zipfile
with zipfile.ZipFile(zipname, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
for file in os.listdir(outputpath):
for file in os.listdir(output_path):
if file.endswith(".sfc") and seedname in file:
zf.write(os.path.join(outputpath, file), file)
zf.write(os.path.join(output_path, file), file)
print(f"Packed {file} into zipfile {zipname}")
if zip_roms == 2 and player_name.lower() not in file.lower():
os.remove(file)
@@ -143,7 +122,7 @@ if __name__ == "__main__":
baseservercommand = f"py -{py_version} MultiServer.py" # source
#don't have a mac to test that. If you try to run compiled on mac, good luck.
subprocess.call(f"{baseservercommand} --multidata {os.path.join(outputpath, multidataname)}")
subprocess.call(f"{baseservercommand} --multidata {os.path.join(output_path, multidataname)}")
except:
import traceback
traceback.print_exc()