2025-11-13 21:12:43 -07:00
|
|
|
import math
|
2025-07-28 00:53:04 -04:00
|
|
|
from BaseClasses import Region, Item, ItemClassification
|
2025-09-26 18:09:18 -04:00
|
|
|
from .Locations import grinch_locations_to_id, grinch_locations, GrinchLocation, get_location_names_per_category
|
2025-11-13 21:12:43 -07:00
|
|
|
from .Items import (
|
|
|
|
|
grinch_items_to_id,
|
|
|
|
|
GrinchItem,
|
|
|
|
|
ALL_ITEMS_TABLE,
|
|
|
|
|
MISC_ITEMS_TABLE,
|
|
|
|
|
get_item_names_per_category,
|
|
|
|
|
TRAPS_TABLE,
|
|
|
|
|
)
|
2025-07-28 00:53:04 -04:00
|
|
|
from .Regions import connect_regions
|
2025-08-30 16:32:56 -04:00
|
|
|
from .Rules import set_location_rules
|
2025-07-26 20:51:05 -04:00
|
|
|
|
2025-08-06 23:34:52 -04:00
|
|
|
from .Client import *
|
2025-08-25 19:48:45 -04:00
|
|
|
from typing import ClassVar
|
2025-07-25 19:33:51 -04:00
|
|
|
|
|
|
|
|
from worlds.AutoWorld import World
|
2025-10-03 16:40:20 -04:00
|
|
|
from Options import OptionError
|
2025-07-25 19:33:51 -04:00
|
|
|
|
2025-09-09 00:23:36 -04:00
|
|
|
from .Options import GrinchOptions
|
2025-07-28 00:53:04 -04:00
|
|
|
from .Rules import access_rules_dict
|
|
|
|
|
|
2025-07-25 19:33:51 -04:00
|
|
|
|
|
|
|
|
class GrinchWorld(World):
|
|
|
|
|
game: ClassVar[str] = "The Grinch"
|
|
|
|
|
options_dataclass = Options.GrinchOptions
|
2025-09-06 16:50:38 -04:00
|
|
|
options: Options.GrinchOptions
|
2025-11-13 21:12:43 -07:00
|
|
|
topology_present = True # not an open world game, very linear
|
|
|
|
|
item_name_to_id: ClassVar[dict[str, int]] = grinch_items_to_id()
|
|
|
|
|
location_name_to_id: ClassVar[dict[str, int]] = grinch_locations_to_id()
|
2025-08-11 20:47:38 -04:00
|
|
|
required_client_version = (0, 6, 3)
|
2025-09-26 18:05:20 -04:00
|
|
|
item_name_groups = get_item_names_per_category()
|
2025-09-26 18:09:18 -04:00
|
|
|
location_name_groups = get_location_names_per_category()
|
2025-07-28 00:53:04 -04:00
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
def __init__(self, *args, **kwargs): # Pulls __init__ function and takes control from there in BaseClasses.py
|
2025-07-28 00:53:04 -04:00
|
|
|
self.origin_region_name: str = "Mount Crumpit"
|
|
|
|
|
super(GrinchWorld, self).__init__(*args, **kwargs)
|
|
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
def generate_early(self) -> None: # Special conditions changed before generation occurs
|
2025-09-09 00:04:09 -04:00
|
|
|
if self.options.ring_link == 1 and self.options.unlimited_eggs == 1:
|
2025-11-13 21:12:43 -07:00
|
|
|
raise OptionError(
|
|
|
|
|
"Cannot enable both unlimited rotten eggs and ring links. You can only enable one of these at a time."
|
|
|
|
|
+ f"The following player's YAML needs to be fixed: {self.player_name}"
|
|
|
|
|
)
|
2025-09-09 00:04:09 -04:00
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
def create_regions(self): # Generates all regions for the multiworld
|
2025-07-28 00:53:04 -04:00
|
|
|
for region_name in access_rules_dict.keys():
|
|
|
|
|
self.multiworld.regions.append(Region(region_name, self.player, self.multiworld))
|
|
|
|
|
self.multiworld.regions.append(Region("Mount Crumpit", self.player, self.multiworld))
|
|
|
|
|
for location, data in grinch_locations.items():
|
|
|
|
|
region = self.get_region(data.region)
|
|
|
|
|
entry = GrinchLocation(self.player, location, region, data)
|
2025-09-20 21:41:40 -04:00
|
|
|
if location == "MC - Sleigh Ride - Neutralizing Santa":
|
2025-09-26 21:40:52 -04:00
|
|
|
entry.place_locked_item(Item("Goal", ItemClassification.progression, None, self.player))
|
2025-07-28 00:53:04 -04:00
|
|
|
region.locations.append(entry)
|
|
|
|
|
connect_regions(self)
|
|
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
def create_item(self, item: str) -> GrinchItem: # Creates specific items on demand
|
2025-07-28 00:53:04 -04:00
|
|
|
if item in ALL_ITEMS_TABLE.keys():
|
|
|
|
|
return GrinchItem(item, self.player, ALL_ITEMS_TABLE[item])
|
|
|
|
|
raise Exception(f"Invalid item name: {item}")
|
|
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
def create_items(self): # Generates all items for the multiworld
|
2025-07-28 00:53:04 -04:00
|
|
|
self_itempool: list[GrinchItem] = []
|
|
|
|
|
for item, data in ALL_ITEMS_TABLE.items():
|
|
|
|
|
self_itempool.append(self.create_item(item))
|
|
|
|
|
if item == "Heart of Stone":
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
self_itempool.append(self.create_item(item))
|
2025-07-28 23:12:47 -04:00
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
# Get number of current unfilled locations
|
|
|
|
|
unfilled_locations: int = (
|
|
|
|
|
len(self.multiworld.get_unfilled_locations(self.player)) - len(ALL_ITEMS_TABLE.keys()) - 3
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
filler_locations: int = math.floor(unfilled_locations * (1 - (self.options.trap_percentage / 100)))
|
|
|
|
|
trap_locations: int = math.floor(unfilled_locations * (self.options.trap_percentage / 100))
|
|
|
|
|
|
|
|
|
|
# This catches the extra 1 or 2 unfilled_locations that come up from the math.floor()
|
|
|
|
|
extra_locations = unfilled_locations - (filler_locations + trap_locations)
|
|
|
|
|
filler_locations != extra_locations
|
2025-07-28 23:12:47 -04:00
|
|
|
|
2025-11-05 19:45:50 -05:00
|
|
|
# Total available weight sum
|
|
|
|
|
total_fillerweights = sum(self.options.filler_weight[filler] for filler in MISC_ITEMS_TABLE)
|
|
|
|
|
|
2025-11-13 21:55:44 -07:00
|
|
|
filler_total_count = 0
|
|
|
|
|
highest_filler = None
|
|
|
|
|
highest_filler_ratio = 0
|
|
|
|
|
|
2025-11-05 19:45:50 -05:00
|
|
|
# Fill remaining locations according to weight ratio
|
|
|
|
|
for filler in MISC_ITEMS_TABLE:
|
2025-11-13 21:12:43 -07:00
|
|
|
# This ratio is a decimal between 0 and 1, and when multiplied by 100 is the % of that filler
|
|
|
|
|
# item in the available unfilled locations
|
2025-11-05 20:17:13 -05:00
|
|
|
filler_weight_ratio = self.options.filler_weight[filler] / total_fillerweights
|
2025-11-13 21:55:44 -07:00
|
|
|
|
|
|
|
|
if filler_weight_ratio > highest_filler_ratio:
|
|
|
|
|
highest_filler_ratio = filler_weight_ratio
|
|
|
|
|
highest_filler = filler
|
|
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
filler_count = round(filler_locations * filler_weight_ratio)
|
|
|
|
|
|
2025-11-13 21:55:44 -07:00
|
|
|
filler_total_count += filler_count
|
|
|
|
|
|
2025-11-05 19:45:50 -05:00
|
|
|
for _ in range(filler_count):
|
|
|
|
|
self_itempool.append(self.create_item(filler))
|
|
|
|
|
|
2025-11-13 21:55:44 -07:00
|
|
|
# Back-filling empty locations with 20 Rotten Eggs
|
|
|
|
|
if filler_total_count < filler_locations:
|
|
|
|
|
for _ in filler_locations - filler_total_count:
|
|
|
|
|
self_itempool.append(self.create_item(highest_filler))
|
|
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
# # Make sure we don't underfill (in case of rounding losses)
|
|
|
|
|
# while len(self_itempool) < unfilled_locations:
|
|
|
|
|
# self_itempool.append(self.create_item(self.get_other_filler_item(list(MISC_ITEMS_TABLE.keys()))))
|
2025-11-05 19:45:50 -05:00
|
|
|
|
2025-11-13 21:55:44 -07:00
|
|
|
trap_total_count = 0
|
|
|
|
|
highest_trap = None
|
|
|
|
|
highest_trap_ratio = 0
|
|
|
|
|
|
2025-11-05 20:17:13 -05:00
|
|
|
# Total available weight sum
|
|
|
|
|
if self.options.trap_percentage > 0:
|
|
|
|
|
total_trapweights = sum(self.options.trap_weight[trap] for trap in TRAPS_TABLE)
|
|
|
|
|
|
2025-11-13 21:55:44 -07:00
|
|
|
if total_trapweights <= 0:
|
2025-11-05 20:17:13 -05:00
|
|
|
raise Exception("ERROR: Traps are enabled, but all trap weights are zero or undefined")
|
|
|
|
|
|
|
|
|
|
for trap in TRAPS_TABLE:
|
|
|
|
|
trap_weight_ratio = self.options.trap_weight[trap] / total_trapweights
|
2025-11-13 21:55:44 -07:00
|
|
|
|
|
|
|
|
if trap_weight_ratio > highest_trap_ratio:
|
|
|
|
|
highest_trap_ratio = trap_weight_ratio
|
|
|
|
|
highest_trap = trap
|
|
|
|
|
|
2025-11-13 21:12:43 -07:00
|
|
|
trap_count = round(trap_locations * trap_weight_ratio)
|
2025-11-13 21:55:44 -07:00
|
|
|
|
|
|
|
|
trap_total_count += trap_count
|
|
|
|
|
|
2025-11-05 20:17:13 -05:00
|
|
|
for _ in range(trap_count):
|
|
|
|
|
self_itempool.append(self.create_item(trap))
|
|
|
|
|
|
2025-11-13 21:55:44 -07:00
|
|
|
# Back-filling empty locations with 20 Rotten Eggs
|
|
|
|
|
if trap_total_count < trap_locations:
|
|
|
|
|
for _ in trap_locations - trap_total_count:
|
|
|
|
|
self_itempool.append(self.create_item(highest_trap))
|
|
|
|
|
|
2025-11-05 20:17:13 -05:00
|
|
|
self.multiworld.itempool += self_itempool
|
|
|
|
|
|
2025-07-28 00:53:04 -04:00
|
|
|
def set_rules(self):
|
2025-09-26 21:40:52 -04:00
|
|
|
self.multiworld.completion_condition[self.player] = lambda state: state.has("Goal", self.player)
|
2025-08-30 16:32:56 -04:00
|
|
|
set_location_rules(self)
|
2025-07-28 23:12:47 -04:00
|
|
|
|
|
|
|
|
def get_other_filler_item(self, other_filler: list[str]) -> str:
|
2025-08-14 00:23:40 -04:00
|
|
|
return self.random.choices(other_filler)[0]
|
|
|
|
|
|
|
|
|
|
def fill_slot_data(self):
|
|
|
|
|
return {
|
|
|
|
|
"give_unlimited_eggs": self.options.unlimited_eggs.value,
|
2025-09-08 22:48:43 -04:00
|
|
|
"ring_link": self.options.ring_link.value,
|
2025-08-16 02:26:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def generate_output(self, output_directory: str) -> None:
|
|
|
|
|
# print("")
|
2025-11-13 21:12:43 -07:00
|
|
|
pass
|