Files
Bryce Wilson 6f2464d4ad Pokemon Emerald: Rework tags/dynamically create item and location groups (#3263)
* Pokemon Emerald: Rework location tags to categories

* Pokemon Emerald: Rework item tags, automatically create item/location groups

* Pokemon Emerald: Move item and location groups to data.py, add some regional location groups

* Map Regions

* Pokemon Emerald: Fix up location groups

* Pokemon Emerald: Move groups to their own file

* Pokemon Emerald: Add meta groups for location groups

* Pokemon Emerald: Fix has_group using updated item group name

* Pokemon Emerald: Add sanity check for maps in location groups

* Pokemon Emerald: Remove missed use of location.tags

* Pokemon Emerald: Reclassify white and black flutes

* Pokemon Emerald: Update changelog

* Pokemon Emerald: Adjust changelog

---------

Co-authored-by: Tsukino <16899482+Tsukino-uwu@users.noreply.github.com>
2024-11-29 09:24:24 +01:00

54 lines
1.5 KiB
Python

"""
Classes and functions related to AP items for Pokemon Emerald
"""
from typing import Dict, FrozenSet, Set, Optional
from BaseClasses import Item, ItemClassification
from .data import BASE_OFFSET, data
class PokemonEmeraldItem(Item):
game: str = "Pokemon Emerald"
tags: FrozenSet[str]
def __init__(self, name: str, classification: ItemClassification, code: Optional[int], player: int) -> None:
super().__init__(name, classification, code, player)
if code is None:
self.tags = frozenset(["Event"])
else:
self.tags = data.items[reverse_offset_item_value(code)].tags
def offset_item_value(item_value: int) -> int:
"""
Returns the AP item id (code) for a given item value
"""
return item_value + BASE_OFFSET
def reverse_offset_item_value(item_id: int) -> int:
"""
Returns the item value for a given AP item id (code)
"""
return item_id - BASE_OFFSET
def create_item_label_to_code_map() -> Dict[str, int]:
"""
Creates a map from item labels to their AP item id (code)
"""
label_to_code_map: Dict[str, int] = {}
for item_value, attributes in data.items.items():
label_to_code_map[attributes.label] = offset_item_value(item_value)
return label_to_code_map
def get_item_classification(item_code: int) -> ItemClassification:
"""
Returns the item classification for a given AP item id (code)
"""
return data.items[reverse_offset_item_value(item_code)].classification