Skip to content

Commit

Permalink
Preliminary Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Exempt-Medic committed Oct 15, 2024
1 parent 37c869f commit bc8448c
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 71 deletions.
14 changes: 7 additions & 7 deletions worlds/civ_6/Civ6Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
import traceback
from typing import Dict, List
from typing import Dict, List, Optional
import zipfile

from CommonClient import ClientCommandProcessor, CommonContext, get_base_parser, logger, server_loop, gui_enabled
Expand All @@ -13,7 +13,7 @@
from .CivVIInterface import CivVIInterface, ConnectionState
from .Enum import CivVICheckType
from .Items import CivVIItemData, generate_item_table, get_item_by_civ_name
from .Locations import generate_era_location_table
from .Locations import CivVILocationData, generate_era_location_table
from .TunerClient import TunerErrorException, TunerTimeoutException


Expand Down Expand Up @@ -51,8 +51,8 @@ class CivVIContext(CommonContext):
items_handling = 0b111
tuner_sync_task = None
game_interface: CivVIInterface
location_name_to_civ_location = {}
location_name_to_id = {}
location_name_to_civ_location: Dict[str, CivVILocationData] = {}
location_name_to_id: Dict[str, int] = {}
item_id_to_civ_item: Dict[int, CivVIItemData] = {}
item_table: Dict[str, CivVIItemData] = {}
processing_multiple_items = False
Expand Down Expand Up @@ -118,7 +118,7 @@ class CivVIManager(GameManager):
logging_pairs = [
("Client", "Archipelago")
]
base_title = "Archipelago Civlization VI Client"
base_title = "Archipelago Civilization VI Client"

self.ui = CivVIManager(self)
self.ui_task = asyncio.create_task(self.ui.async_run(), name="UI")
Expand Down Expand Up @@ -153,7 +153,7 @@ async def tuner_sync_task(ctx: CivVIContext):
continue
else:
try:
if ctx.processing_multiple_items == True:
if ctx.processing_multiple_items:
await asyncio.sleep(3)
else:
state = await ctx.game_interface.is_in_game()
Expand Down Expand Up @@ -201,7 +201,7 @@ async def handle_checked_location(ctx: CivVIContext):
await ctx.send_msgs([{"cmd": "LocationChecks", "locations": checked_location_ids}])


async def handle_receive_items(ctx: CivVIContext, last_received_index_override: int = None):
async def handle_receive_items(ctx: CivVIContext, last_received_index_override: Optional[int] = None):
try:
last_received_index = last_received_index_override or await ctx.game_interface.get_last_received_index()
if len(ctx.items_received) - last_received_index > 1:
Expand Down
4 changes: 2 additions & 2 deletions worlds/civ_6/CivVIInterface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
from logging import Logger
from typing import List
from typing import List, Optional

from .Items import CivVIItemData
from .TunerClient import TunerClient, TunerConnectionException, TunerTimeoutException
Expand All @@ -15,7 +15,7 @@ class ConnectionState(Enum):
class CivVIInterface:
logger: Logger
tuner: TunerClient
last_error: str = None
last_error: Optional[str] = None

def __init__(self, logger: Logger):
self.logger = logger
Expand Down
3 changes: 1 addition & 2 deletions worlds/civ_6/Container.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def generate_new_items(world: 'CivVIWorld') -> str:
"""
Generates the XML for the new techs/civics as well as the blockers used to prevent players from researching their own items
"""
locations: List[CivVILocation] = world.multiworld.get_locations(
world.player)
locations: List[CivVILocation] = world.multiworld.get_filled_locations(world.player)
techs = [location for location in locations if location.location_type ==
CivVICheckType.TECH]
civics = [location for location in locations if location.location_type ==
Expand Down
6 changes: 3 additions & 3 deletions worlds/civ_6/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import os
import pkgutil
from typing import List
from typing import Dict, List


_cache = {}
Expand All @@ -18,7 +18,7 @@ def _get_data(key: str):


@dataclass
class CivVIBoostData():
class CivVIBoostData:
Type: str
EraType: str
Prereq: List[str]
Expand All @@ -41,7 +41,7 @@ def get_boosts_data() -> List[CivVIBoostData]:
return boosts


def get_era_required_items_data() -> List[str]:
def get_era_required_items_data() -> Dict[str, List[str]]:
return _get_data("era_required_items")


Expand Down
2 changes: 1 addition & 1 deletion worlds/civ_6/DeathLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def handle_check_deathlink(ctx: CommonContext):
f"was tired of sitting in BK and decided to fight a {result} instead",
f"purposely lost to a {result} as a cry for help",
f"is wanting to remind everyone that they are here to have fun and not to win",
f"is reconisdering their pursuit of a domination victory",
f"is reconsidering their pursuit of a domination victory",
f"had their plans toppled by a {result}",
]
player = ctx.player_names[ctx.slot]
Expand Down
3 changes: 3 additions & 0 deletions worlds/civ_6/Enum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from enum import Enum


class EraType(Enum):
ERA_ANCIENT = "ERA_ANCIENT"
ERA_CLASSICAL = "ERA_CLASSICAL"
Expand All @@ -10,6 +12,7 @@ class EraType(Enum):
ERA_INFORMATION = "ERA_INFORMATION"
ERA_FUTURE = "ERA_FUTURE"


class CivVICheckType(Enum):
TECH = "TECH"
CIVIC = "CIVIC"
Expand Down
20 changes: 10 additions & 10 deletions worlds/civ_6/Items.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FillerItemRarity(Enum):

FILLER_DISTRIBUTION: Dict[FillerItemRarity, float] = {
FillerItemRarity.RARE: 0.025,
FillerItemRarity.UNCOMMON: .2,
FillerItemRarity.UNCOMMON: 0.2,
FillerItemRarity.COMMON: 0.775,
}

Expand Down Expand Up @@ -113,7 +113,7 @@ class CivVIItem(Item):
civ_vi_id: int
item_type: CivVICheckType

def __init__(self, item: CivVIItemData, player: int, classification: ItemClassification = None):
def __init__(self, item: CivVIItemData, player: int, classification: Optional[ItemClassification] = None):
super().__init__(item.name, classification or item.classification, item.code, player)
self.civ_vi_id = item.civ_vi_id
self.item_type = item.item_type
Expand Down Expand Up @@ -271,21 +271,21 @@ def generate_item_table() -> Dict[str, CivVIItemData]:

progressive_items = get_flat_progressive_districts()

item_table = {}
item_table: Dict[str, CivVIItemData] = {}

def get_id_base():
return len(item_table.keys())

item_table = {**item_table, **_generate_tech_items(get_id_base(), required_items, progressive_items)}
item_table = {**item_table, **_generate_civics_items(get_id_base(), required_items, progressive_items)}
item_table = {**item_table, **_generate_progressive_district_items(get_id_base())}
item_table = {**item_table, **_generate_progressive_era_items(get_id_base())}
item_table = {**item_table, **_generate_goody_hut_items(get_id_base())}
item_table.update(**_generate_tech_items(get_id_base(), required_items, progressive_items))
item_table.update(**_generate_civics_items(get_id_base(), required_items, progressive_items))
item_table.update(**_generate_progressive_district_items(get_id_base()))
item_table.update(**_generate_progressive_era_items(get_id_base()))
item_table.update(**_generate_goody_hut_items(get_id_base()))

return item_table


def get_items_by_type(item_type: CivVICheckType, item_table: Dict[str, CivVIItemData]) -> Dict[str, CivVIItemData]:
def get_items_by_type(item_type: CivVICheckType, item_table: Dict[str, CivVIItemData]) -> List[CivVIItemData]:
"""
Returns a list of items that match the given item type
"""
Expand All @@ -297,4 +297,4 @@ def get_random_filler_by_rarity(world: 'CivVIWorld', rarity: FillerItemRarity) -
Returns a random filler item by rarity
"""
items = [item for item in get_filler_item_data().values() if item.rarity == rarity]
return items[world.random.randint(0, len(items) - 1)]
return world.random.choice(items)
6 changes: 3 additions & 3 deletions worlds/civ_6/Locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Locs that should have progression items (keypoint techs/civics, ~1 per era)
PRIORITY_LOCATIONS = [
"TECH_ANCEINT_09",
"TECH_ANCIENT_09",
"TECH_CLASSICAL_15",
"TECH_MEDIEVAL_20",
"TECH_RENAISSANCE_33",
Expand Down Expand Up @@ -52,7 +52,7 @@
]


class CivVILocationData():
class CivVILocationData:
game: str = "Civilization VI"
name: str
cost: int
Expand All @@ -61,7 +61,7 @@ class CivVILocationData():
code: int
era_type: EraType
location_type: CivVICheckType
pre_reqs: List[str]
pre_reqs: Optional[List[str]]

def __init__(self, name: str, cost: int, uiTreeRow: int, id: int, era_type: EraType, location_type: CivVICheckType, pre_reqs: Optional[List[str]] = None):
self.name = name
Expand Down
18 changes: 9 additions & 9 deletions worlds/civ_6/Options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from Options import Choice, DeathLink, DefaultOnToggle, PerGameCommonOptions, Range, StartInventory, StartInventoryPool, Toggle
from Options import Choice, DeathLink, DefaultOnToggle, PerGameCommonOptions, Range, StartInventoryPool, Toggle


class ProgressionStyle(Choice):
Expand All @@ -18,12 +18,12 @@ class ProgressionStyle(Choice):


class ShuffleGoodyHuts(DefaultOnToggle):
"""Shuffles the goody hut rewards. Goody huts will only contain junk items and location checks are received sequentially (GOODY_HUT_1, GOODY_HUT_2, etc)."""
"""Shuffles the goody hut rewards. Goody huts will only contain junk items and location checks are received sequentially (GOODY_HUT_1, GOODY_HUT_2, etc.)."""
display_name = "Shuffle Goody Hut Rewards"


class BoostSanity(Toggle):
"""Boosts for Civics/Techs are location checks. Boosts can now be triggered even if the item has already been researched. If it is dependent upon a unit that is now obsolete, you can click toggle on/off the relevant tech in the tech tree."""
"""Boosts for Civics/Techs are location checks. Boosts can now be triggered even if the item has already been researched. If it is dependent upon a unit that is now obsolete, you can click to toggle on/off the relevant tech in the tech tree."""
display_name = "Boostsanity"


Expand All @@ -33,7 +33,7 @@ class ExcludeMissableBoosts(Toggle):


class ResearchCostMultiplier(Choice):
"""Multiplier for research cost of techs and civics, higher values make research more expensive. Cheap = 0.5x, Expensive = 1.5x. Default is 1. """
"""Multiplier for research cost of techs and civics, higher values make research more expensive. Cheap = 0.5x, Expensive = 1.5x."""
display_name = "Tech/Civic Cost Multiplier"
option_cheap = 0.5
option_default = 1
Expand All @@ -43,9 +43,9 @@ class ResearchCostMultiplier(Choice):

class PreHintItems(Choice):
"""Controls if/what items in the tech/civics trees are pre-hinted for the multiworld.
All : All items in the tech & civics trees are pre-hinted.
All: All items in the tech & civics trees are pre-hinted.
Progression items: Only locations in the trees containing progression items are pre-hinted.
No Junk: pre-hint the progression and useful items.
No Junk: Pre-hint the progression and useful items.
None: No items are pre-hinted.
"""
display_name = "Tech/Civic Tree pre-hinted Items"
Expand All @@ -62,12 +62,12 @@ class HideItemNames(Toggle):


class InGameFlagProgressionItems(DefaultOnToggle):
"""If enabled, an advisor icon will be added to any location that contains a progression item"""
"""If enabled, an advisor icon will be added to any location that contains a progression item."""
display_name = "Advisor Indicates Progression Items"


class DeathLinkEffect(Choice):
"""What happens when a unit dies. Default is Unit Killed.
"""What happens when a unit dies.
Faith, and Gold will be decreased by the amount specified in 'Death Link Effect Percent'.
Era score is decreased by 1.
Any will select any of these options any time a death link is received."""
Expand All @@ -82,7 +82,7 @@ class DeathLinkEffect(Choice):


class DeathLinkEffectPercent(Range):
"""The percentage of the effect that will be applied. Only applicable for Gold and Faith effects. Default is 20%"""
"""The percentage of the effect that will be applied. Only applicable for Gold and Faith effects."""
display_name = "Death Link Effect Percent"
default = 20
range_start = 1
Expand Down
7 changes: 3 additions & 4 deletions worlds/civ_6/Regions.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from typing import TYPE_CHECKING, Dict, List
from typing import TYPE_CHECKING, Dict, List, Optional
from BaseClasses import CollectionState, LocationProgressType, Region
from .Data import get_era_required_items_data, get_progressive_districts_data
from .Items import format_item_name, get_item_by_civ_name
from .Items import CivVIItemData, format_item_name, get_item_by_civ_name
from .Enum import CivVICheckType, EraType
from .Locations import CivVILocation
from .ProgressiveDistricts import get_flat_progressive_districts
from .Options import CivVIOptions

if TYPE_CHECKING:
from . import CivVIWorld
from Items import CivVIItemData


def get_prereqs_for_era(end_era: EraType, exclude_progressive_items: bool = True, item_table: Dict[str, 'CivVIItemData'] = None) -> List['CivVIItemData']:
def get_prereqs_for_era(end_era: EraType, exclude_progressive_items: bool = True, item_table: Optional[Dict[str, CivVIItemData]] = None) -> List[CivVIItemData]:
"""Gets the specific techs/civics that are required for the specified era"""
era_required_items = get_era_required_items_data()[end_era.value].copy()

Expand Down
4 changes: 2 additions & 2 deletions worlds/civ_6/Rules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Callable, List, Dict
from typing import TYPE_CHECKING, List, Dict
from BaseClasses import CollectionState
from .Items import get_item_by_civ_name
from .Data import get_boosts_data
Expand All @@ -17,7 +17,7 @@ def create_boost_rules(world: 'CivVIWorld'):
boost_locations = [location for location in world.location_table.values() if location.location_type == CivVICheckType.BOOST]
for location in boost_locations:
boost_data = next((boost for boost in boost_data_list if boost.Type == location.name), None)
world_location = world.multiworld.get_location(location.name, world.player)
world_location = world.get_location(location.name)
forbid_item(world_location, "Progressive Era", world.player)
if not boost_data or boost_data.PrereqRequiredCount == 0:
continue
Expand Down
8 changes: 4 additions & 4 deletions worlds/civ_6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def create_items(self) -> None:
data = get_era_required_items_data()
early_items = data[EraType.ERA_ANCIENT.value]
early_locations = [location for location in self.location_table.values() if location.era_type == EraType.ERA_ANCIENT.value]
for item_name, data in self.item_table.items():
for item_name, item_data in self.item_table.items():
# These item types are handled individually
if data.item_type in [CivVICheckType.PROGRESSIVE_DISTRICT, CivVICheckType.ERA, CivVICheckType.GOODY]:
if item_data.item_type in [CivVICheckType.PROGRESSIVE_DISTRICT, CivVICheckType.ERA, CivVICheckType.GOODY]:
continue

# If we're using progressive districts, we need to check if we need to create a different item instead
Expand All @@ -118,7 +118,7 @@ def create_items(self) -> None:
for location in early_locations:
found_location = None
try:
found_location = self.multiworld.get_location(location.name, self.player)
found_location = self.get_location(location.name)
forbid_item(found_location, item_to_create, self.player)
except KeyError:
pass
Expand Down Expand Up @@ -167,7 +167,7 @@ def post_fill(self) -> None:
if location_data.location_type != CivVICheckType.CIVIC and location_data.location_type != CivVICheckType.TECH:
continue

location: CivVILocation = self.multiworld.get_location(location_name, self.player)
location: CivVILocation = self.get_location(location_name)

if not location.item or not show_flags.get(location.item.classification, False):
continue
Expand Down
Loading

0 comments on commit bc8448c

Please sign in to comment.