Files
Grinch-AP/worlds/stardew_valley/logic/building_logic.py
Jérémie Bolduc 9ac921380f Stardew Valley: Refactor buildings to use content packs (#4239)
* create building data object and rename ItemSource to Source to be more generic

# Conflicts:
#	worlds/stardew_valley/content/game_content.py

# Conflicts:
#	worlds/stardew_valley/data/artisan.py
#	worlds/stardew_valley/data/game_item.py
#	worlds/stardew_valley/data/harvest.py
#	worlds/stardew_valley/data/shop.py

* remove compound sources, replace by other requirements which already handle this usecase

* add coops to content packs

* add building progression in game features

* add shippping bin to starting building; remove has_house

* replace config check with feature

* add other buildings in content packs

* not passing

* tests passes, unbelievable

* use newly create methods more

* use new assets to ease readability

* self review

* fix flake8 maybe

* properly split rule for mapping cave systems

* fix tractor garage name

* self review

* add upgrade_from to farm house buldings

* don't override building name variable in logic

* remove has_group from buildings

* mark some items easy in grinding logic so blueprints buildings can be in more early spheres

* move stuff around to maybe avoid future conflicts cuz I have like 10 PRs opened right now

* remove price_multiplier, turns out it's unused during generation

* disable shop source for mapping cave systems

* bunch of code review changes

* add petbowl and farmhouse to autobuilding

* set min easy items to 300

* fix farm type
2025-04-08 12:37:45 -04:00

63 lines
2.4 KiB
Python

import typing
from functools import cached_property
from typing import Union
from Utils import cache_self1
from .base_logic import BaseLogic, BaseLogicMixin
from .has_logic import HasLogicMixin
from .received_logic import ReceivedLogicMixin
from .region_logic import RegionLogicMixin
from ..stardew_rule import StardewRule, true_
from ..strings.building_names import Building
from ..strings.region_names import Region
if typing.TYPE_CHECKING:
from .source_logic import SourceLogicMixin
else:
SourceLogicMixin = object
AUTO_BUILDING_BUILDINGS = {Building.shipping_bin, Building.pet_bowl, Building.farm_house}
class BuildingLogicMixin(BaseLogicMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.building = BuildingLogic(*args, **kwargs)
class BuildingLogic(BaseLogic[Union[BuildingLogicMixin, RegionLogicMixin, ReceivedLogicMixin, HasLogicMixin, SourceLogicMixin]]):
@cache_self1
def can_build(self, building_name: str) -> StardewRule:
building = self.content.farm_buildings.get(building_name)
assert building is not None, f"Building {building_name} not found."
source_rule = self.logic.source.has_access_to_any(building.sources)
if not building.is_upgrade:
return source_rule
upgrade_rule = self.logic.building.has_building(building.upgrade_from)
return self.logic.and_(upgrade_rule, source_rule)
@cache_self1
def has_building(self, building_name: str) -> StardewRule:
building_progression = self.content.features.building_progression
if building_name in building_progression.starting_buildings:
return true_
if not building_progression.is_progressive:
return self.logic.building.can_build(building_name)
# Those buildings are special. The mod auto-builds them when received, no need to go to Robin.
if building_name in AUTO_BUILDING_BUILDINGS:
return self.logic.received(Building.shipping_bin)
carpenter_rule = self.logic.building.can_construct_buildings
item, count = building_progression.to_progressive_item(building_name)
return self.logic.received(item, count) & carpenter_rule
@cached_property
def can_construct_buildings(self) -> StardewRule:
return self.logic.region.can_reach(Region.carpenter)