mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00

* first working (most of the time) progression generation for SM using VariaRandomizer's rules, items, locations and accessPoint (as regions) * first working single-world randomized SM rom patches * - SM now displays message when getting an item outside for someone else (fills ROM item table) This is dependant on modifications done to sm_randomizer_rom project * First working MultiWorld SM * some missing things: - player name inject in ROM and get in client - end game get from ROM in client - send self item to server - add player names table in ROM * replaced CollectionState inheritance from SMBoolManager with a composition of an array of it (required to generation more than one SM world, which is still fails but is better) * - reenabled balancing * post rebase fixes * updated SmClient.py * + added VariaRandomizer LICENSE * + added sm_randomizer_rom project (which builds sm.ips) * Moved VariaRandomizer and sm_randomizer_rom projects inside worlds/sm and done some cleaning * properly revert change made to CollectionState and more cleaning * Fixed multiworld support patch not working with VariaRandomizer's * missing file commit * Fixed syntax error in unused code to satisfy Linter * Revert "Fixed multiworld support patch not working with VariaRandomizer's" This reverts commit fb3ca18528bb331995e3d3051648c8f84d04c08b. * many fixes and improovement - fixed seeded generation - fixed broken logic when more than one SM world - added missing rules for inter-area transitions - added basic patch presence for logic - added DoorManager init call to reflect present patches for logic - moved CollectionState addition out of BaseClasses into SM world - added condition to apply progitempool presorting only if SM world is present - set Bosses item id to None to prevent them going into multidata - now use get_game_players * first working (most of the time) progression generation for SM using VariaRandomizer's rules, items, locations and accessPoint (as regions) * first working single-world randomized SM rom patches * - SM now displays message when getting an item outside for someone else (fills ROM item table) This is dependant on modifications done to sm_randomizer_rom project * First working MultiWorld SM * some missing things: - player name inject in ROM and get in client - end game get from ROM in client - send self item to server - add player names table in ROM * replaced CollectionState inheritance from SMBoolManager with a composition of an array of it (required to generation more than one SM world, which is still fails but is better) * - reenabled balancing * post rebase fixes * updated SmClient.py * + added VariaRandomizer LICENSE * + added sm_randomizer_rom project (which builds sm.ips) * Moved VariaRandomizer and sm_randomizer_rom projects inside worlds/sm and done some cleaning * properly revert change made to CollectionState and more cleaning * Fixed multiworld support patch not working with VariaRandomizer's * missing file commit * Fixed syntax error in unused code to satisfy Linter * Revert "Fixed multiworld support patch not working with VariaRandomizer's" This reverts commit fb3ca18528bb331995e3d3051648c8f84d04c08b. * many fixes and improovement - fixed seeded generation - fixed broken logic when more than one SM world - added missing rules for inter-area transitions - added basic patch presence for logic - added DoorManager init call to reflect present patches for logic - moved CollectionState addition out of BaseClasses into SM world - added condition to apply progitempool presorting only if SM world is present - set Bosses item id to None to prevent them going into multidata - now use get_game_players * Fixed multiworld support patch not working with VariaRandomizer's Added stage_fill_hook to set morph first in progitempool Added back VariaRandomizer's standard patches * + added missing files from variaRandomizer project * + added missing variaRandomizer files (custom sprites) + started integrating VariaRandomizer options (WIP) * Some fixes for player and server name display - fixed player name of 16 characters reading too far in SM client - fixed 12 bytes SM player name limit (now 16) - fixed server name not being displayed in SM when using server cheat ( now displays RECEIVED FROM ARCHIPELAGO) - request: temporarly changed default seed names displayed in SM main menu to OWTCH * Fixed Goal completion not triggering in smClient * integrated VariaRandomizer's options into AP (WIP) - startAP is working - door rando is working - skillset is working * - fixed itemsounds.ips crash by always including nofanfare.ips into multiworld.ips (itemsounds is now always applied and "itemsounds" preset must always be "off") * skillset are now instanced per player instead of being a singleton class * RomPatches are now instanced per player instead of being a singleton class * DoorManager is now instanced per player instead of being a singleton class * - fixed the last bugs that prevented generation of >1 SM world * fixed crash when no skillset preset is specified in randoPreset (default to "casual") * maxDifficulty support and itemsounds removal - added support for maxDifficulty - removed itemsounds patch as its always applied from multiworld patch for now * Fixed bad merge * Post merge adaptation * fixed player name length fix that got lost with the merge * fixed generation with other game type than SM * added default randoPreset json for SM in playerSettings.yaml * fixed broken SM client following merge * beautified json skillset presets * Fixed ArchipelagoSmClient not building * Fixed conflict between mutliworld patch and beam_doors_plms patch - doorsColorsRando now working * SM generation now outputs APBP - Fixed paths for patches and presets when frozen * added missing file and fixed multithreading issue * temporarily set data_version = 0 * more work - added support for AP starting items - fixed client crash with gamemode being None - patch.py "compatible_version" is now 3 * commited missing asm files fixed start item reserve breaking game (was using bad write offset when patching) * Nothing item are now handled game-side. the game will now skip displaying a message box for received Nothing item (but the client will still receive it). fixed crash in SMClient when loosing connection to SNI * fixed No Energy Item missing its ID fixed Plando * merge post fixes * fixed start item Grapple, XRay and Reserve HUD, as well as graphic beams (except ice palette color) * fixed freeze in blue brinstar caused by Varia's custom PLM not being filled with proper Multiworld PLM address (altLocsAddresses) * fixed start item x-ray HUD display * Fixed start items being sent by the server (is all handled in ROM) Start items are now not removed from itempool anymore Nothing Item is now local_items so no player will ever pickup Nothing. Doing so reduces contribution of this world to the Multiworld the more Nothing there is though. Fixed crash (and possibly passing but broken) at generation where the static list of IPSPatches used by all SM worlds was being modified * fixed settings that could be applied to any SM players * fixed auth to server only using player name (now does as ALTTP to authenticate) * - fixed End Credits broken text * added non SM item name display * added all supported SM options in playerSettings.yaml * fixed locations needing a list of parent regions (now generate a region for each location with one-way exits to each (previously) parent region did some cleaning (mainly reverts on unnecessary core classes * minor setting fixes and tweaks - merged Area and lightArea settings - made missileQty, superQty and powerBombQty use value from 10 to 90 and divide value by float(10) when generating - fixed inverted layoutPatch setting * added option start_inventory_removes_from_pool fixed option names formatting fixed lint errors small code and repo cleanup * Hopefully fixed ROR2 that could not send any items * - fixed missing required change to ROR2 * fixed 0 hp when respawning without having ever saved (start items were not updating the save checksum) * fixed typo with doors_colors_rando * fixed checksum * added custom sprites for off-world items (progression or not) the original AP sprite was made with PierRoulette's SM Item Sprite Utility by ijwu * - added missing change following upstream merge - changed patch filename extension from apbp to apm3 so patch can be used with the new client * added morph placement options: early means local and sphere 1 * fixed failing unit tests * - fixed broken custom_preset options * - big cleanup to remove unnecessary or unsupported features * - more cleanup * - moved sm_randomizer_rom and all always applied patches into an external project that outputs basepatch.ips - small cleanup * - added comment to refer to project for generating basepatch.ips (https://github.com/lordlou/SMBasepatch) * fixed g4_skip patch that can be not applied if hud is enabled * - fixed off world sprite that can have broken graphics (restricted to use only first 2 palette) * - updated basepatch to reflect g4_skip removal - moved more asm files to SMBasepatch project * - tourian grey doors at baby metroid are now always flashing (allowing to go back if needed) * fixed wrong path if using built as exe * - cleaned exposed maxDifficulty options - removed always enabled Knows * Merged LttPClient and SMClient into SNIClient * added varia_custom Preset Option that fetch a preset (read from a new varia_custom_preset Option) from varia's web service * small doc precision * - added death_link support - fixed broken Goal Completion - post merge fix * - removed now useless presets * - fixed bad internal mapping with maxDiff - increases maxDiff if only Bosses is preventing beating the game * - added support for lowercase custom preset sections (knows, settings and controller) - fixed controller settings not applying to ROM * - fixed death loop when dying with Door rando, bomb or speed booster as starting items - varia's backup save should now be usable (automatically enabled when doing door rando) * -added docstring for generated yaml * fixed bad merge * fixed broken infinity max difficulty * commented debug prints * adjusted credits to mark progression speed and difficulty as Non Available * added support for more than 255 players (will print Archipelago for higher player number) * fixed missing cleanup * added support for 65535 different player names in ROM * fixed generations failing when only bosses are unreachable * - replaced setting maxDiff to infinity with a bool only affecting boss logics if only bosses are left to finish * fixed failling generations when using 'fun' settings Accessibility checks are forced to 'items' if restricted locations are used by VARIA following usage of 'fun' settings * fixed debug logger * removed unsupported "suits_restriction" option * fixed generations failing when only bosses are unreachable (using a less intrusive approach for AP) * - fixed deathlink emptying reserves - added death_link_survive option that lets player survive when receiving a deathlink if the have non-empty reserves * - merged death_link and death_link_survive options * fixed death_link * added a fallback default starting location instead of failing generation if an invalid one was chosen * added Nothing and NoEnergy as hint blacklist added missing NoEnergy as local items and removed it from progression * fixed broken Item links * fixed failing generation that could happen with Disabled Tourian fixed shared Location list that could be modified for each world * added missing force disable of EscapeRando if an escape solution cant be found * fixed broken animal surprise patches * prevent receiving items when in the first room of Ceres (message box in mode7 is broken) * fixed generating with "activate chozo robots" Objective * added soft reset that saves to initial starting location reverted code change applied to fix softlocks from comeback checks reverted forcing all beam local when using door rando * replaced "save and reset" with "save and fast reload" (using same Start+Select+L+R) * added documentation about Save and Reload removed forgotten docstring about forcing beams as local items when using door rando * fixed frequent failing generation on WebHost (KeyError: 'Kraid') * added "objectiveRandom", "nbObjective", objectiveList and adapted Objective selection options to better reflect VARIA's. fixed "collect 100% items" not being excluded when objectiveRandom is used added Exception when VARIA initial layout fails * fixed broken non-AP items fixed determinism caused by the use of a set * fixed generation failing on Webhost with string as a OptionSet (replaced default with a list of string) cleaned doc and naming of Objective related Options
535 lines
20 KiB
Python
535 lines
20 KiB
Python
import io
|
|
import os, json, re, random
|
|
import pathlib
|
|
import sys
|
|
from typing import Any
|
|
import zipfile
|
|
|
|
from ..utils.parameters import Knows, Settings, Controller, isKnows, isSettings, isButton
|
|
from ..utils.parameters import easy, medium, hard, harder, hardcore, mania, text2diff
|
|
from ..logic.smbool import SMBool
|
|
|
|
|
|
# support for AP world
|
|
isAPWorld = ".apworld" in sys.modules[__name__].__file__
|
|
|
|
def getZipFile():
|
|
filename = sys.modules[__name__].__file__
|
|
apworldExt = ".apworld"
|
|
zipPath = pathlib.Path(filename[:filename.index(apworldExt) + len(apworldExt)])
|
|
return (zipfile.ZipFile(zipPath), zipPath.stem)
|
|
|
|
def openFile(resource: str, mode: str = "r", encoding: None = None):
|
|
if isAPWorld:
|
|
(zipFile, stem) = getZipFile()
|
|
with zipFile as zf:
|
|
zipFilePath = resource[resource.index(stem + "/"):]
|
|
if mode == 'rb':
|
|
return zf.open(zipFilePath, 'r')
|
|
else:
|
|
return io.TextIOWrapper(zf.open(zipFilePath, mode), encoding)
|
|
else:
|
|
return open(resource, mode)
|
|
|
|
def listDir(resource: str):
|
|
if isAPWorld:
|
|
(zipFile, stem) = getZipFile()
|
|
with zipFile as zf:
|
|
zipFilePath = resource[resource.index(stem + "/"):]
|
|
path = zipfile.Path(zf, zipFilePath + "/")
|
|
files = [f.at[len(zipFilePath)+1:] for f in path.iterdir()]
|
|
return files
|
|
else:
|
|
return os.listdir(resource)
|
|
|
|
def exists(resource: str):
|
|
if isAPWorld:
|
|
(zipFile, stem) = getZipFile()
|
|
with zipFile as zf:
|
|
if (stem in resource):
|
|
zipFilePath = resource[resource.index(stem + "/"):]
|
|
path = zipfile.Path(zf, zipFilePath)
|
|
return path.exists()
|
|
else:
|
|
return False
|
|
else:
|
|
return os.path.exists(resource)
|
|
|
|
def isStdPreset(preset):
|
|
return preset in ['newbie', 'casual', 'regular', 'veteran', 'expert', 'master', 'samus', 'solution', 'Season_Races', 'SMRAT2021', 'Torneio_SGPT3']
|
|
|
|
def getPresetDir(preset) -> str:
|
|
if isStdPreset(preset):
|
|
return 'worlds/sm/variaRandomizer/standard_presets'
|
|
else:
|
|
return 'worlds/sm/variaRandomizer/community_presets'
|
|
|
|
def removeChars(string, toRemove):
|
|
return re.sub('[{}]+'.format(toRemove), '', string)
|
|
|
|
def range_union(ranges):
|
|
ret = []
|
|
for rg in sorted([[r.start, r.stop] for r in ranges]):
|
|
begin, end = rg[0], rg[-1]
|
|
if ret and ret[-1][1] > begin:
|
|
ret[-1][1] = max(ret[-1][1], end)
|
|
else:
|
|
ret.append([begin, end])
|
|
return [range(r[0], r[1]) for r in ret]
|
|
|
|
# https://github.com/robotools/fontParts/commit/7cb561033929cfb4a723d274672e7257f5e68237
|
|
def normalizeRounding(n):
|
|
# Normalizes rounding as Python 2 and Python 3 handing the rounding of halves (0.5, 1.5, etc) differently.
|
|
# This normalizes rounding to be the same in both environments.
|
|
if round(0.5) != 1 and n % 1 == .5 and not int(n) % 2:
|
|
return int((round(n) + (abs(n) / n) * 1))
|
|
else:
|
|
return int(round(n))
|
|
|
|
# gauss random in [0, r] range
|
|
# the higher the slope, the less probable extreme values are.
|
|
def randGaussBounds(r, slope=5):
|
|
r = float(r)
|
|
n = normalizeRounding(random.gauss(r/2, r/slope))
|
|
if n < 0:
|
|
n = 0
|
|
if n > r:
|
|
n = int(r)
|
|
return n
|
|
|
|
# from a relative weight dictionary, gives a normalized range dictionary
|
|
# example :
|
|
# { 'a' : 10, 'b' : 17, 'c' : 3 } => {'c': 0.1, 'a':0.4333333, 'b':1 }
|
|
def getRangeDict(weightDict):
|
|
total = float(sum(weightDict.values()))
|
|
rangeDict = {}
|
|
current = 0.0
|
|
for k in sorted(weightDict, key=weightDict.get):
|
|
w = float(weightDict[k]) / total
|
|
current += w
|
|
rangeDict[k] = current
|
|
|
|
return rangeDict
|
|
|
|
def chooseFromRange(rangeDict):
|
|
r = random.random()
|
|
val = None
|
|
for v in sorted(rangeDict, key=rangeDict.get):
|
|
val = v
|
|
if r < rangeDict[v]:
|
|
return v
|
|
return val
|
|
|
|
class PresetLoader(object):
|
|
@staticmethod
|
|
def factory(params):
|
|
# can be a json, a python file or a dict with the parameters
|
|
if type(params) == str:
|
|
ext = os.path.splitext(params)
|
|
if ext[1].lower() == '.json':
|
|
return PresetLoaderJson(params)
|
|
else:
|
|
raise Exception("PresetLoader: wrong parameters file type: {}".format(ext[1]))
|
|
elif type(params) is dict:
|
|
return PresetLoaderDict(params)
|
|
else:
|
|
raise Exception("wrong parameters input, is neither a string nor a json file name: {}::{}".format(params, type(params)))
|
|
|
|
def __init__(self):
|
|
if 'Knows' not in self.params:
|
|
if 'knows' in self.params:
|
|
self.params['Knows'] = self.params['knows']
|
|
else:
|
|
self.params['Knows'] = {}
|
|
if 'Settings' not in self.params:
|
|
if 'settings' in self.params:
|
|
self.params['Settings'] = self.params['settings']
|
|
else:
|
|
self.params['Settings'] = {}
|
|
if 'Controller' not in self.params:
|
|
if 'controller' in self.params:
|
|
self.params['Controller'] = self.params['controller']
|
|
else:
|
|
self.params['Controller'] = {}
|
|
self.params['score'] = self.computeScore()
|
|
|
|
def load(self, player):
|
|
# update the parameters in the parameters classes: Knows, Settings
|
|
Knows.knowsDict[player] = Knows()
|
|
Settings.SettingsDict[player] = Settings()
|
|
Controller.ControllerDict[player] = Controller()
|
|
|
|
# Knows
|
|
for param in self.params['Knows']:
|
|
if isKnows(param) and hasattr(Knows, param):
|
|
setattr(Knows.knowsDict[player], param, SMBool( self.params['Knows'][param][0],
|
|
self.params['Knows'][param][1],
|
|
['{}'.format(param)]))
|
|
# Settings
|
|
## hard rooms
|
|
for hardRoom in ['X-Ray', 'Gauntlet']:
|
|
if hardRoom in self.params['Settings']:
|
|
Settings.SettingsDict[player].hardRooms[hardRoom] = Settings.hardRoomsPresets[hardRoom][self.params['Settings'][hardRoom]]
|
|
|
|
## bosses
|
|
for boss in ['Kraid', 'Phantoon', 'Draygon', 'Ridley', 'MotherBrain']:
|
|
if boss in self.params['Settings']:
|
|
Settings.SettingsDict[player].bossesDifficulty[boss] = Settings.bossesDifficultyPresets[boss][self.params['Settings'][boss]]
|
|
|
|
## hellruns
|
|
for hellRun in ['Ice', 'MainUpperNorfair', 'LowerNorfair']:
|
|
if hellRun in self.params['Settings']:
|
|
Settings.SettingsDict[player].hellRuns[hellRun] = Settings.hellRunPresets[hellRun][self.params['Settings'][hellRun]]
|
|
|
|
# Controller
|
|
for button in self.params['Controller']:
|
|
if isButton(button):
|
|
setattr(Controller.ControllerDict[player], button, self.params['Controller'][button])
|
|
|
|
def dump(self, fileName):
|
|
with open(fileName, 'w') as jsonFile:
|
|
json.dump(self.params, jsonFile)
|
|
|
|
def printToScreen(self):
|
|
print("self.params: {}".format(self.params))
|
|
|
|
print("loaded knows: ")
|
|
for knows in Knows.__dict__:
|
|
if isKnows(knows):
|
|
print("{}: {}".format(knows, Knows.__dict__[knows]))
|
|
print("loaded settings:")
|
|
for setting in Settings.__dict__:
|
|
if isSettings(setting):
|
|
print("{}: {}".format(setting, Settings.__dict__[setting]))
|
|
print("loaded controller:")
|
|
for button in Controller.__dict__:
|
|
if isButton(button):
|
|
print("{}: {}".format(button, Controller.__dict__[button]))
|
|
print("loaded score: {}".format(self.params['score']))
|
|
|
|
def computeScore(self):
|
|
# the more techniques you know and the smaller the difficulty of the techniques, the higher the score
|
|
diff2score = {
|
|
easy: 6,
|
|
medium: 5,
|
|
hard: 4,
|
|
harder: 3,
|
|
hardcore: 2,
|
|
mania: 1
|
|
}
|
|
|
|
boss2score = {
|
|
"He's annoying": 1,
|
|
'A lot of trouble': 1,
|
|
"I'm scared!": 1,
|
|
"It can get ugly": 1,
|
|
'Default': 2,
|
|
'Quick Kill': 3,
|
|
'Used to it': 3,
|
|
'Is this really the last boss?': 3,
|
|
'No problemo': 4,
|
|
'Piece of cake': 4,
|
|
'Nice cutscene bro': 4
|
|
}
|
|
|
|
hellrun2score = {
|
|
'No thanks': 0,
|
|
'Solution': 0,
|
|
'Gimme energy': 2,
|
|
'Default': 4,
|
|
'Bring the heat': 6,
|
|
'I run RBO': 8
|
|
}
|
|
|
|
hellrunLN2score = {
|
|
'Default': 0,
|
|
'Solution': 0,
|
|
'Bring the heat': 6,
|
|
'I run RBO': 12
|
|
}
|
|
|
|
xray2score = {
|
|
'Aarghh': 0,
|
|
'Solution': 0,
|
|
"I don't like spikes": 1,
|
|
'Default': 2,
|
|
"I don't mind spikes": 3,
|
|
'D-Boost master': 4
|
|
}
|
|
|
|
gauntlet2score = {
|
|
'Aarghh': 0,
|
|
"I don't like acid": 1,
|
|
'Default': 2
|
|
}
|
|
|
|
score = 0
|
|
|
|
# knows
|
|
for know in Knows.__dict__:
|
|
if isKnows(know):
|
|
if know in self.params['Knows']:
|
|
if self.params['Knows'][know][0] == True:
|
|
score += diff2score[self.params['Knows'][know][1]]
|
|
else:
|
|
# if old preset with not all the knows, use default values for the know
|
|
if Knows.__dict__[know].bool == True:
|
|
score += diff2score[Knows.__dict__[know].difficulty]
|
|
|
|
# hard rooms
|
|
hardRoom = 'X-Ray'
|
|
if hardRoom in self.params['Settings']:
|
|
score += xray2score[self.params['Settings'][hardRoom]]
|
|
|
|
hardRoom = 'Gauntlet'
|
|
if hardRoom in self.params['Settings']:
|
|
score += gauntlet2score[self.params['Settings'][hardRoom]]
|
|
|
|
# bosses
|
|
for boss in ['Kraid', 'Phantoon', 'Draygon', 'Ridley', 'MotherBrain']:
|
|
if boss in self.params['Settings']:
|
|
score += boss2score[self.params['Settings'][boss]]
|
|
|
|
# hellruns
|
|
for hellRun in ['Ice', 'MainUpperNorfair']:
|
|
if hellRun in self.params['Settings']:
|
|
score += hellrun2score[self.params['Settings'][hellRun]]
|
|
|
|
hellRun = 'LowerNorfair'
|
|
if hellRun in self.params['Settings']:
|
|
score += hellrunLN2score[self.params['Settings'][hellRun]]
|
|
|
|
return score
|
|
|
|
class PresetLoaderJson(PresetLoader):
|
|
# when called from the test suite
|
|
def __init__(self, jsonFileName):
|
|
with openFile(jsonFileName) as jsonFile:
|
|
self.params = json.load(jsonFile)
|
|
super(PresetLoaderJson, self).__init__()
|
|
|
|
class PresetLoaderDict(PresetLoader):
|
|
# when called from the website
|
|
def __init__(self, params):
|
|
self.params = params
|
|
super(PresetLoaderDict, self).__init__()
|
|
|
|
def getDefaultMultiValues():
|
|
from ..graph.graph_utils import GraphUtils
|
|
from ..utils.objectives import Objectives
|
|
defaultMultiValues = {
|
|
'startLocation': GraphUtils.getStartAccessPointNames(),
|
|
'majorsSplit': ['Full', 'FullWithHUD', 'Major', 'Chozo', 'Scavenger'],
|
|
'progressionSpeed': ['slowest', 'slow', 'medium', 'fast', 'fastest', 'basic', 'VARIAble', 'speedrun'],
|
|
'progressionDifficulty': ['easier', 'normal', 'harder'],
|
|
'morphPlacement': ['early', 'normal'], #['early', 'late', 'normal'],
|
|
'energyQty': ['ultra sparse', 'sparse', 'medium', 'vanilla'],
|
|
'gravityBehaviour': ['Vanilla', 'Balanced', 'Progressive'],
|
|
'areaRandomization': ['off', 'full', 'light'],
|
|
'objective': Objectives.getAllGoals(removeNothing=True),
|
|
'tourian': ['Vanilla', 'Fast', 'Disabled']
|
|
}
|
|
return defaultMultiValues
|
|
|
|
def getPresetValues():
|
|
return [
|
|
"newbie",
|
|
"casual",
|
|
"regular",
|
|
"veteran",
|
|
"expert",
|
|
"master",
|
|
"samus",
|
|
"Season_Races",
|
|
"SMRAT2021",
|
|
"solution",
|
|
"custom",
|
|
"varia_custom"
|
|
]
|
|
|
|
# from web to cli
|
|
def convertParam(randoParams, param, inverse=False):
|
|
value = randoParams.get(param, "off" if inverse == False else "on")
|
|
if value == "on":
|
|
return True if inverse == False else False
|
|
elif value == "off":
|
|
return False if inverse == False else True
|
|
elif value == "random":
|
|
return "random"
|
|
raise Exception("invalid value for parameter {}".format(param))
|
|
|
|
def loadRandoPreset(world, player, args):
|
|
defaultMultiValues = getDefaultMultiValues()
|
|
diffs = ["easy", "medium", "hard", "harder", "hardcore", "mania", "infinity"]
|
|
presetValues = getPresetValues()
|
|
|
|
args.animals = world.animals[player].value
|
|
args.noVariaTweaks = not world.varia_tweaks[player].value
|
|
args.maxDifficulty = diffs[world.max_difficulty[player].value]
|
|
#args.suitsRestriction = world.suits_restriction[player].value
|
|
args.hideItems = world.hide_items[player].value
|
|
args.strictMinors = world.strict_minors[player].value
|
|
args.noLayout = not world.layout_patches[player].value
|
|
args.gravityBehaviour = defaultMultiValues["gravityBehaviour"][world.gravity_behaviour[player].value]
|
|
args.nerfedCharge = world.nerfed_charge[player].value
|
|
args.area = world.area_randomization[player].current_key
|
|
if (args.area == "true"):
|
|
args.area = "full"
|
|
if args.area != "off":
|
|
args.areaLayoutBase = not world.area_layout[player].value
|
|
args.escapeRando = world.escape_rando[player].value
|
|
args.noRemoveEscapeEnemies = not world.remove_escape_enemies[player].value
|
|
args.doorsColorsRando = world.doors_colors_rando[player].value
|
|
args.allowGreyDoors = world.allow_grey_doors[player].value
|
|
args.bosses = world.boss_randomization[player].value
|
|
if world.fun_combat[player].value:
|
|
args.superFun.append("Combat")
|
|
if world.fun_movement[player].value:
|
|
args.superFun.append("Movement")
|
|
if world.fun_suits[player].value:
|
|
args.superFun.append("Suits")
|
|
|
|
ipsPatches = { "spin_jump_restart":"spinjumprestart",
|
|
"rando_speed":"rando_speed",
|
|
"elevators_speed":"elevators_speed",
|
|
"fast_doors":"fast_doors",
|
|
"refill_before_save":"refill_before_save",
|
|
"relaxed_round_robin_cf":"relaxed_round_robin_cf"}
|
|
for settingName, patchName in ipsPatches.items():
|
|
if hasattr(world, settingName) and getattr(world, settingName)[player].value:
|
|
args.patches.append(patchName + '.ips')
|
|
|
|
patches = {"no_music":"No_Music", "infinite_space_jump":"Infinite_Space_Jump"}
|
|
for settingName, patchName in patches.items():
|
|
if hasattr(world, settingName) and getattr(world, settingName)[player].value:
|
|
args.patches.append(patchName)
|
|
|
|
args.hud = world.hud[player].value
|
|
args.morphPlacement = defaultMultiValues["morphPlacement"][world.morph_placement[player].value]
|
|
#args.majorsSplit
|
|
#args.scavNumLocs
|
|
#args.scavRandomized
|
|
args.startLocation = defaultMultiValues["startLocation"][world.start_location[player].value]
|
|
#args.progressionDifficulty
|
|
#args.progressionSpeed
|
|
args.missileQty = world.missile_qty[player].value / float(10)
|
|
args.superQty = world.super_qty[player].value / float(10)
|
|
args.powerBombQty = world.power_bomb_qty[player].value / float(10)
|
|
args.minorQty = world.minor_qty[player].value
|
|
args.energyQty = defaultMultiValues["energyQty"][world.energy_qty[player].value]
|
|
args.objectiveRandom = world.custom_objective[player].value
|
|
args.objectiveList = list(world.custom_objective_list[player].value)
|
|
args.nbObjective = world.custom_objective_count[player].value
|
|
args.objective = list(world.objective[player].value)
|
|
args.tourian = defaultMultiValues["tourian"][world.tourian[player].value]
|
|
#args.minimizerN
|
|
#args.minimizerTourian
|
|
|
|
return presetValues[world.preset[player].value]
|
|
|
|
def getRandomizerDefaultParameters():
|
|
defaultParams = {}
|
|
defaultMultiValues = getDefaultMultiValues()
|
|
|
|
defaultParams['complexity'] = "simple"
|
|
defaultParams['preset'] = 'regular'
|
|
defaultParams['randoPreset'] = ""
|
|
defaultParams['raceMode'] = "off"
|
|
defaultParams['majorsSplit'] = "Full"
|
|
defaultParams['majorsSplitMultiSelect'] = defaultMultiValues['majorsSplit']
|
|
defaultParams['scavNumLocs'] = "10"
|
|
defaultParams['scavRandomized'] = "off"
|
|
defaultParams['startLocation'] = "Landing Site"
|
|
defaultParams['startLocationMultiSelect'] = defaultMultiValues['startLocation']
|
|
defaultParams['maxDifficulty'] = 'hardcore'
|
|
defaultParams['progressionSpeed'] = "medium"
|
|
defaultParams['progressionSpeedMultiSelect'] = defaultMultiValues['progressionSpeed']
|
|
defaultParams['progressionDifficulty'] = 'normal'
|
|
defaultParams['progressionDifficultyMultiSelect'] = defaultMultiValues['progressionDifficulty']
|
|
defaultParams['morphPlacement'] = "early"
|
|
defaultParams['morphPlacementMultiSelect'] = defaultMultiValues['morphPlacement']
|
|
defaultParams['suitsRestriction'] = "on"
|
|
defaultParams['hideItems'] = "off"
|
|
defaultParams['strictMinors'] = "off"
|
|
defaultParams['missileQty'] = "3"
|
|
defaultParams['superQty'] = "2"
|
|
defaultParams['powerBombQty'] = "1"
|
|
defaultParams['minorQty'] = "100"
|
|
defaultParams['energyQty'] = "vanilla"
|
|
defaultParams['energyQtyMultiSelect'] = defaultMultiValues['energyQty']
|
|
defaultParams['objectiveRandom'] = "off"
|
|
defaultParams['nbObjective'] = "4"
|
|
defaultParams['objective'] = ["kill all G4"]
|
|
defaultParams['objectiveMultiSelect'] = defaultMultiValues['objective']
|
|
defaultParams['tourian'] = "Vanilla"
|
|
defaultParams['areaRandomization'] = "off"
|
|
defaultParams['areaLayout'] = "off"
|
|
defaultParams['doorsColorsRando'] = "off"
|
|
defaultParams['allowGreyDoors'] = "off"
|
|
defaultParams['escapeRando'] = "off"
|
|
defaultParams['removeEscapeEnemies'] = "off"
|
|
defaultParams['bossRandomization'] = "off"
|
|
defaultParams['minimizer'] = "off"
|
|
defaultParams['minimizerQty'] = "45"
|
|
defaultParams['funCombat'] = "off"
|
|
defaultParams['funMovement'] = "off"
|
|
defaultParams['funSuits'] = "off"
|
|
defaultParams['layoutPatches'] = "on"
|
|
defaultParams['variaTweaks'] = "on"
|
|
defaultParams['gravityBehaviour'] = "Balanced"
|
|
defaultParams['gravityBehaviourMultiSelect'] = defaultMultiValues['gravityBehaviour']
|
|
defaultParams['nerfedCharge'] = "off"
|
|
defaultParams['relaxed_round_robin_cf'] = "off"
|
|
defaultParams['itemsounds'] = "on"
|
|
defaultParams['elevators_speed'] = "on"
|
|
defaultParams['fast_doors'] = "on"
|
|
defaultParams['spinjumprestart'] = "off"
|
|
defaultParams['rando_speed'] = "off"
|
|
defaultParams['Infinite_Space_Jump'] = "off"
|
|
defaultParams['refill_before_save'] = "off"
|
|
defaultParams['hud'] = "off"
|
|
defaultParams['animals'] = "off"
|
|
defaultParams['No_Music'] = "off"
|
|
defaultParams['random_music'] = "off"
|
|
|
|
return defaultParams
|
|
|
|
def fixEnergy(items):
|
|
# display number of energy used
|
|
energies = [i for i in items if i.find('ETank') != -1]
|
|
if len(energies) > 0:
|
|
(maxETank, maxReserve, maxEnergy) = (0, 0, 0)
|
|
for energy in energies:
|
|
nETank = int(energy[0:energy.find('-ETank')])
|
|
if energy.find('-Reserve') != -1:
|
|
nReserve = int(energy[energy.find(' - ')+len(' - '):energy.find('-Reserve')])
|
|
else:
|
|
nReserve = 0
|
|
nEnergy = nETank + nReserve
|
|
if nEnergy > maxEnergy:
|
|
maxEnergy = nEnergy
|
|
maxETank = nETank
|
|
maxReserve = nReserve
|
|
items.remove(energy)
|
|
items.append('{}-ETank'.format(maxETank))
|
|
if maxReserve > 0:
|
|
items.append('{}-Reserve'.format(maxReserve))
|
|
|
|
|
|
# keep biggest crystal flash
|
|
cfs = [i for i in items if i.find('CrystalFlash') != -1]
|
|
if len(cfs) > 1:
|
|
maxCf = 0
|
|
for cf in cfs:
|
|
nCf = int(cf[0:cf.find('-CrystalFlash')])
|
|
if nCf > maxCf:
|
|
maxCf = nCf
|
|
items.remove(cf)
|
|
items.append('{}-CrystalFlash'.format(maxCf))
|
|
return items
|
|
|
|
def dumpErrorMsg(outFileName, msg):
|
|
print("DIAG: " + msg)
|
|
if outFileName is not None:
|
|
with open(outFileName, 'w') as jsonFile:
|
|
json.dump({"errorMsg": msg}, jsonFile) |