Skip to content

Commit

Permalink
Objective rando is functional, still need UI elements
Browse files Browse the repository at this point in the history
  • Loading branch information
zaktherobot committed Apr 7, 2024
1 parent 830703a commit a9b35c2
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 19 deletions.
4 changes: 4 additions & 0 deletions List/ItemList.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ def sharedMultiItem() -> KH2Item:
@staticmethod
def objectiveItem() -> KH2Item:
return KH2Item(misc.ObjectiveItem)

@staticmethod
def emblemItem() -> KH2Item:
return KH2Item(misc.ObjectiveItem)

@staticmethod
def weaponslot_id_to_keyblade_item(location_id: int) -> Optional[Keyblade]:
Expand Down
11 changes: 5 additions & 6 deletions List/ObjectiveList.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from dataclasses import dataclass
from enum import Enum

from List.location import (simulatedtwilighttown,twilighttown,hollowbastion,landofdragons,
beastscastle,disneycastle,portroyal,agrabah,halloweentown,
pridelands, spaceparanoids, worldthatneverwas, olympuscoliseum,
hundredacrewood, atlantica, formlevel,puzzlereward)

class ObjectiveType(str, Enum):
BOSS = "Boss"
WORLDPROGRESS = "WorldProgress"
Expand All @@ -27,6 +22,10 @@ class KH2Objective:
Difficulty: ObjectiveDifficulty = ObjectiveDifficulty.EARLY

def get_full_objective_list():
from List.location import (simulatedtwilighttown,twilighttown,hollowbastion,landofdragons,
beastscastle,disneycastle,portroyal,agrabah,halloweentown,
pridelands, spaceparanoids, worldthatneverwas, olympuscoliseum,
hundredacrewood, atlantica, formlevel,puzzlereward)
return [
# STT
KH2Objective("Defeat Twilight Thorn",simulatedtwilighttown.CheckLocation.TwilightThorn,ObjectiveType.BOSS),
Expand Down Expand Up @@ -148,7 +147,7 @@ def get_full_objective_list():
KH2Objective("Defeat Data Xaldin",beastscastle.CheckLocation.DataXaldin,ObjectiveType.BOSS,ObjectiveDifficulty.LATEST),
KH2Objective("Defeat Data Luxord",portroyal.CheckLocation.DataLuxordApBoost,ObjectiveType.BOSS,ObjectiveDifficulty.LATEST),
KH2Objective("Defeat Data Xemnas",worldthatneverwas.CheckLocation.DataXemnas,ObjectiveType.BOSS,ObjectiveDifficulty.LATEST),
KH2Objective("Defeat Data Zexion",olympuscoliseum.CheckLocation.ZexionBonus,ObjectiveType.BOSS,ObjectiveDifficulty.LATEST),
KH2Objective("Defeat Data Zexion",olympuscoliseum.CheckLocation.DataZexionLostIllusion,ObjectiveType.BOSS,ObjectiveDifficulty.LATEST),
KH2Objective("Defeat Data Vexen",halloweentown.CheckLocation.DataVexen,ObjectiveType.BOSS,ObjectiveDifficulty.LATEST),
KH2Objective("Defeat Data Larxene",spaceparanoids.CheckLocation.DataLarxeneLostIllusion,ObjectiveType.BOSS,ObjectiveDifficulty.LATEST),
KH2Objective("Defeat Data Lexaeus",agrabah.CheckLocation.DataLexaeus,ObjectiveType.BOSS,ObjectiveDifficulty.LATEST),
Expand Down
2 changes: 2 additions & 0 deletions Module/Hints/HintUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Class.itemClass import KH2Item
from Class.newLocationClass import KH2Location
from List.LvupStats import DreamWeaponOffsets
from List.ObjectiveList import KH2Objective
from List.configDict import HintType, SoraLevelOption, itemType, locationCategory, locationType
from List.inventory import ability, form, magic, misc, storyunlock, summon
from List.inventory.item import InventoryItem
Expand All @@ -28,6 +29,7 @@ def __init__(self, settings: RandomizerSettings):
)
self.important_check_list = settings.important_checks
self.spoiler_reveal_list = settings.spoiler_reveal_checks
self.objective_mode = settings.objective_rando
# remove any items that aren't enabled by settings
if settings.promiseCharm:
tracker_includes.append("PromiseCharm")
Expand Down
19 changes: 12 additions & 7 deletions Module/RandomizerSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from Class import settingkey
from Class.exceptions import SettingsException
from Class.seedSettings import SeedSettings, makeKHBRSettings
from List import experienceValues
from List import experienceValues, ObjectiveList
from List.configDict import (
locationType,
itemType,
Expand Down Expand Up @@ -409,12 +409,6 @@ def __init__(
self.statSanity: bool = ui_settings.get(settingkey.STATSANITY)
self.yeetTheBear: bool = ui_settings.get(settingkey.YEET_THE_BEAR)
self.chainLogic: bool = ui_settings.get(settingkey.CHAIN_LOGIC)
# self.chainLogicIncludeTerra: bool = ui_settings.get(
# settingkey.CHAIN_LOGIC_TERRA
# )
# self.chainLogicTerraLate: bool = ui_settings.get(
# settingkey.CHAIN_LOGIC_MIN_TERRA
# )
self.chainLogicMinLength: int = ui_settings.get(settingkey.CHAIN_LOGIC_LENGTH)
self.chainLogicMaxLength: int = ui_settings.get(settingkey.MAX_CHAIN_LOGIC_LENGTH)

Expand Down Expand Up @@ -541,9 +535,13 @@ def __init__(
self.revealComplete: bool = ui_settings.get(settingkey.REVEAL_COMPLETE)
self.revealMode: str = ui_settings.get(settingkey.REPORTS_REVEAL)
self.journal_hints: str = ui_settings.get(settingkey.JOURNAL_HINTS_ABILITIES)
self.emblems = False
self.num_emblems_needed = 7
self.max_emblems_available = 13
self.objective_rando = False
self.num_objectives_needed = 7
self.max_objectives_available = 13
self.available_objectives = ObjectiveList.get_full_objective_list()

self.hintable_check_types: list[str] = [
item_type for item_type in ui_settings.get(settingkey.HINTABLE_CHECKS)
Expand Down Expand Up @@ -574,6 +572,9 @@ def __init__(
self.hiscore_mode: bool = ui_settings.get(settingkey.SCORE_MODE)

self.tracker_includes: list[str] = []

if self.objective_rando:
self.tracker_includes.append("objectives")
if self.progression_hints:
self.tracker_includes.append("ProgressionHints")
if self.vanilla_level_one:
Expand Down Expand Up @@ -724,6 +725,10 @@ def validateSettings(self):
raise SettingsException(
"Can't use chain logic and objective rando at the same time"
)
if self.emblems:
raise SettingsException(
"Can't use chain logic and emblems at the same time"
)

if (
self.ability_pool_option != AbilityPoolOption.DEFAULT
Expand Down
2 changes: 2 additions & 0 deletions Module/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,8 @@ def generate_hints_v2(randomizer: Randomizer, settings: RandomizerSettings) -> H
]
hint_data = common_tracker_data.to_dict()
hint_data["level_data"] = world_items.level_checks
if settings.objective_rando:
hint_data["objective_list"] = [o.Name for o in randomizer.objectives]
if settings.hintsType == HintType.SHANANAS:
hint_data["world"] = world_items.world_to_item_ids()
elif settings.hintsType == HintType.JSMARTEE:
Expand Down
27 changes: 25 additions & 2 deletions Module/newRandomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from Class.itemClass import KH2Item
from Class.newLocationClass import KH2Location
from Class.randomUtils import weighted_sample_without_replacement
from List.ObjectiveList import KH2Objective
from List.ItemList import Items
from List.NewLocationList import Locations
from List.configDict import (
Expand Down Expand Up @@ -186,6 +187,7 @@ def __init__(self, settings: RandomizerSettings, progress_bar_vis: bool = False)
self.form_level_exp: list[FormExp] = []
self.synthesis_recipes: list[SynthesisRecipe] = []
self.shop_items: list[KH2Item] = []
self.objectives: list[KH2Objective] = []
self.assign_sora_items(settings)
if progress_bar_vis:
return
Expand Down Expand Up @@ -603,7 +605,9 @@ def assign_sora_items(self, settings: RandomizerSettings):
)
self.num_available_items = (
len(ability_pool)
+ len(item_pool)
+ len(item_pool)
+ (settings.max_objectives_available if settings.objective_rando else 0)
+ (settings.max_emblems_available if settings.emblems else 0)
- (sum([len(l.VanillaItems) for l in locations_with_vanilla_items]))
)

Expand Down Expand Up @@ -665,11 +669,30 @@ def assign_sora_items(self, settings: RandomizerSettings):
# check for objective rando
if settings.objective_rando:
# get the objective pool
objective_pool = settings.available_objectives
# filter down the pool based on what valid locations there are
valid_location_descriptions = [v.Description for v in valid_locations]
objective_pool = [o for o in objective_pool if o.Location in valid_location_descriptions]
# remove proof of nonexistence
item_pool = [i for i in item_pool if i.Id != proof.ProofOfNonexistence.id]
# remove duplicates for AS/Data split
if locationType.AS in settings.enabledLocations and locationType.DataOrg in settings.enabledLocations:
if settings.as_data_split:
# remove duplicates for ASs
objective_pool = [o for o in objective_pool if "Defeat AS" not in o.Name]
else:
# remove duplicates for Datas
objective_pool = [o for o in objective_pool if not any(t in o.Name for t in ["Data Vexen","Data Zexion","Data Larxene","Data Lexaeus","Data Marluxia"])]
# pick a number of objectives
self.objectives = random.sample(objective_pool,k=settings.max_objectives_available)
picked_objectives_location_names = [o.Location for o in self.objectives]
# plando completion marks onto the selected objectives
pass
objective_locations = [v for v in valid_locations if v.Description in picked_objectives_location_names]
for o in objective_locations:
locations_to_remove = self.randomly_assign_single_item(Items.objectiveItem(),[o])
for l in locations_to_remove:
valid_locations.remove(l)


if settings.chainLogic:
self.assign_chain_logic(settings, item_pool, valid_locations)
Expand Down
6 changes: 3 additions & 3 deletions Module/spoilerLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def item_spoiler_dictionary(
location_spheres=None
) -> dict[locationType, list[tuple[str, KH2Item]]]:
# (depth for sort purposes, location id for sort purposes, sphere, spoiler log string, item)
out_dict: dict[locationType, list[tuple[int, int, int, str, KH2Item]]] = {}
out_dict: dict[locationType, list[tuple[int, int, str, str, KH2Item]]] = {}

item_lookup = Items.sora_lookup_table()
if starting_inventory_ids is not None:
Expand Down Expand Up @@ -52,12 +52,12 @@ def item_spoiler_dictionary(
else:
added_string = ""

sphere = 0
sphere = "N/A"
if location_spheres and location not in location_spheres:
prepend_string = "Unreachable "
elif location_spheres and location in location_spheres:
prepend_string = ""
sphere = location_spheres[location]
sphere = str(location_spheres[location])
else:
prepend_string = ""

Expand Down
2 changes: 1 addition & 1 deletion Module/zipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def create_drop_rate_assets(self, mod: SeedModBuilder):
)

def create_objective_rando_assets(self, mod: SeedModBuilder, num_objectives_needed: int):
mod.add_objective_randomization_mods(True,num_objectives_needed)
mod.add_objective_randomization_mods(num_objectives_needed)
mod.items.add_item(
item_id=363,
item_type="Recipe",
Expand Down

0 comments on commit a9b35c2

Please sign in to comment.