Zillion: remove old option access from item link validation (#2673)

* Zillion: remove old option access from item link validation
and a little bit a cleaning in other stuff nearby

* one option access missed
This commit is contained in:
Doug Hoskisson 2024-01-14 06:48:30 -08:00 committed by GitHub
parent 6904bd5885
commit ed6b7b2670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 30 deletions

View File

@ -4,7 +4,7 @@ import functools
import settings import settings
import threading import threading
import typing import typing
from typing import Any, Dict, List, Literal, Set, Tuple, Optional, cast from typing import Any, Dict, List, Set, Tuple, Optional, cast
import os import os
import logging import logging
@ -12,7 +12,7 @@ from BaseClasses import ItemClassification, LocationProgressType, \
MultiWorld, Item, CollectionState, Entrance, Tutorial MultiWorld, Item, CollectionState, Entrance, Tutorial
from .logic import cs_to_zz_locs from .logic import cs_to_zz_locs
from .region import ZillionLocation, ZillionRegion from .region import ZillionLocation, ZillionRegion
from .options import ZillionOptions, ZillionStartChar, validate from .options import ZillionOptions, validate
from .id_maps import item_name_to_id as _item_name_to_id, \ from .id_maps import item_name_to_id as _item_name_to_id, \
loc_name_to_id as _loc_name_to_id, make_id_to_others, \ loc_name_to_id as _loc_name_to_id, make_id_to_others, \
zz_reg_name_to_reg_name, base_id zz_reg_name_to_reg_name, base_id
@ -225,7 +225,7 @@ class ZillionWorld(World):
loc.access_rule = access_rule loc.access_rule = access_rule
if not (limited_skill >= zz_loc.req): if not (limited_skill >= zz_loc.req):
loc.progress_type = LocationProgressType.EXCLUDED loc.progress_type = LocationProgressType.EXCLUDED
self.multiworld.exclude_locations[p].value.add(loc.name) self.options.exclude_locations.value.add(loc.name)
here.locations.append(loc) here.locations.append(loc)
self.my_locations.append(loc) self.my_locations.append(loc)
@ -288,15 +288,15 @@ class ZillionWorld(World):
if group["game"] == "Zillion": if group["game"] == "Zillion":
assert "item_pool" in group assert "item_pool" in group
item_pool = group["item_pool"] item_pool = group["item_pool"]
to_stay: Literal['Apple', 'Champ', 'JJ'] = "JJ" to_stay: Chars = "JJ"
if "JJ" in item_pool: if "JJ" in item_pool:
assert "players" in group assert "players" in group
group_players = group["players"] group_players = group["players"]
start_chars = cast(Dict[int, ZillionStartChar], getattr(multiworld, "start_char")) players_start_chars: List[Tuple[int, Chars]] = []
players_start_chars = [ for player in group_players:
(player, start_chars[player].current_option_name) z_world = multiworld.worlds[player]
for player in group_players assert isinstance(z_world, ZillionWorld)
] players_start_chars.append((player, z_world.options.start_char.get_char()))
start_char_counts = Counter(sc for _, sc in players_start_chars) start_char_counts = Counter(sc for _, sc in players_start_chars)
# majority rules # majority rules
if start_char_counts["Apple"] > start_char_counts["Champ"]: if start_char_counts["Apple"] > start_char_counts["Champ"]:
@ -304,7 +304,7 @@ class ZillionWorld(World):
elif start_char_counts["Champ"] > start_char_counts["Apple"]: elif start_char_counts["Champ"] > start_char_counts["Apple"]:
to_stay = "Champ" to_stay = "Champ"
else: # equal else: # equal
choices: Tuple[Literal['Apple', 'Champ', 'JJ'], ...] = ("Apple", "Champ") choices: Tuple[Chars, ...] = ("Apple", "Champ")
to_stay = multiworld.random.choice(choices) to_stay = multiworld.random.choice(choices)
for p, sc in players_start_chars: for p, sc in players_start_chars:

View File

@ -1,9 +1,11 @@
from typing import Dict, FrozenSet, Tuple, cast, List, Counter as _Counter from typing import Dict, FrozenSet, Tuple, List, Counter as _Counter
from BaseClasses import CollectionState from BaseClasses import CollectionState
from zilliandomizer.logic_components.items import Item, items
from zilliandomizer.logic_components.locations import Location from zilliandomizer.logic_components.locations import Location
from zilliandomizer.randomizer import Randomizer from zilliandomizer.randomizer import Randomizer
from zilliandomizer.logic_components.items import Item, items
from .region import ZillionLocation
from .item import ZillionItem from .item import ZillionItem
from .id_maps import item_name_to_id from .id_maps import item_name_to_id
@ -18,11 +20,12 @@ def set_randomizer_locs(cs: CollectionState, p: int, zz_r: Randomizer) -> int:
returns a hash of the player and of the set locations with their items returns a hash of the player and of the set locations with their items
""" """
from . import ZillionWorld
z_world = cs.multiworld.worlds[p] z_world = cs.multiworld.worlds[p]
my_locations = cast(List[ZillionLocation], getattr(z_world, "my_locations")) assert isinstance(z_world, ZillionWorld)
_hash = p _hash = p
for z_loc in my_locations: for z_loc in z_world.my_locations:
zz_name = z_loc.zz_loc.name zz_name = z_loc.zz_loc.name
zz_item = z_loc.item.zz_item \ zz_item = z_loc.item.zz_item \
if isinstance(z_loc.item, ZillionItem) and z_loc.item.player == p \ if isinstance(z_loc.item, ZillionItem) and z_loc.item.player == p \

View File

@ -1,13 +1,14 @@
from collections import Counter from collections import Counter
from dataclasses import dataclass from dataclasses import dataclass
from typing import Dict, Tuple from typing import ClassVar, Dict, Tuple
from typing_extensions import TypeGuard # remove when Python >= 3.10 from typing_extensions import TypeGuard # remove when Python >= 3.10
from Options import DefaultOnToggle, NamedRange, PerGameCommonOptions, Range, Toggle, Choice from Options import DefaultOnToggle, NamedRange, PerGameCommonOptions, Range, Toggle, Choice
from zilliandomizer.options import \ from zilliandomizer.options import (
Options as ZzOptions, char_to_gun, char_to_jump, ID, \ Options as ZzOptions, char_to_gun, char_to_jump, ID,
VBLR as ZzVBLR, chars, Chars, ItemCounts as ZzItemCounts VBLR as ZzVBLR, Chars, ItemCounts as ZzItemCounts
)
from zilliandomizer.options.parsing import validate as zz_validate from zilliandomizer.options.parsing import validate as zz_validate
@ -107,6 +108,15 @@ class ZillionStartChar(Choice):
display_name = "start character" display_name = "start character"
default = "random" default = "random"
_name_capitalization: ClassVar[Dict[int, Chars]] = {
option_jj: "JJ",
option_apple: "Apple",
option_champ: "Champ",
}
def get_char(self) -> Chars:
return ZillionStartChar._name_capitalization[self.value]
class ZillionIDCardCount(Range): class ZillionIDCardCount(Range):
""" """
@ -348,16 +358,6 @@ def validate(options: ZillionOptions) -> "Tuple[ZzOptions, Counter[str]]":
# that should be all of the level requirements met # that should be all of the level requirements met
name_capitalization: Dict[str, Chars] = {
"jj": "JJ",
"apple": "Apple",
"champ": "Champ",
}
start_char = options.start_char
start_char_name = name_capitalization[start_char.current_key]
assert start_char_name in chars
starting_cards = options.starting_cards starting_cards = options.starting_cards
room_gen = options.room_gen room_gen = options.room_gen
@ -371,7 +371,7 @@ def validate(options: ZillionOptions) -> "Tuple[ZzOptions, Counter[str]]":
max_level.value, max_level.value,
False, # tutorial False, # tutorial
skill, skill,
start_char_name, options.start_char.get_char(),
floppy_req.value, floppy_req.value,
options.continues.value, options.continues.value,
bool(options.randomize_alarms.value), bool(options.randomize_alarms.value),