Stardew Valley: Refactor Animals to use Content Packs (#4320)

This commit is contained in:
Jérémie Bolduc
2025-04-20 10:17:22 -04:00
committed by GitHub
parent 33dc845de8
commit 22941168cd
15 changed files with 229 additions and 85 deletions

View File

@@ -1,25 +1,15 @@
from typing import Union
import typing
from .base_logic import BaseLogicMixin, BaseLogic
from .building_logic import BuildingLogicMixin
from .has_logic import HasLogicMixin
from .money_logic import MoneyLogicMixin
from ..stardew_rule import StardewRule, true_
from ..strings.animal_names import Animal, coop_animals, barn_animals
from ..stardew_rule import StardewRule
from ..strings.building_names import Building
from ..strings.forageable_names import Forageable
from ..strings.generic_names import Generic
from ..strings.region_names import Region
from ..strings.machine_names import Machine
cost_and_building_by_animal = {
Animal.chicken: (800, Building.coop),
Animal.cow: (1500, Building.barn),
Animal.goat: (4000, Building.big_barn),
Animal.duck: (1200, Building.big_coop),
Animal.sheep: (8000, Building.deluxe_barn),
Animal.rabbit: (8000, Building.deluxe_coop),
Animal.pig: (16000, Building.deluxe_barn)
}
if typing.TYPE_CHECKING:
from .logic import StardewLogic
else:
StardewLogic = object
class AnimalLogicMixin(BaseLogicMixin):
@@ -28,32 +18,19 @@ class AnimalLogicMixin(BaseLogicMixin):
self.animal = AnimalLogic(*args, **kwargs)
class AnimalLogic(BaseLogic[Union[HasLogicMixin, MoneyLogicMixin, BuildingLogicMixin]]):
class AnimalLogic(BaseLogic[StardewLogic]):
def can_buy_animal(self, animal: str) -> StardewRule:
try:
price, building = cost_and_building_by_animal[animal]
except KeyError:
return true_
return self.logic.money.can_spend_at(Region.ranch, price) & self.logic.building.has_building(building)
def can_incubate(self, egg_item: str) -> StardewRule:
return self.logic.building.has_building(Building.coop) & self.logic.has(egg_item)
def has_animal(self, animal: str) -> StardewRule:
if animal == Generic.any:
return self.has_any_animal()
elif animal == Building.coop:
return self.has_any_coop_animal()
elif animal == Building.barn:
return self.has_any_barn_animal()
return self.logic.has(animal)
def can_ostrich_incubate(self, egg_item: str) -> StardewRule:
return self.logic.building.has_building(Building.barn) & self.logic.has(Machine.ostrich_incubator) & self.logic.has(egg_item)
def has_happy_animal(self, animal: str) -> StardewRule:
return self.has_animal(animal) & self.logic.has(Forageable.hay)
def has_animal(self, animal_name: str) -> StardewRule:
animal = self.content.animals.get(animal_name)
assert animal is not None, f"Animal {animal_name} not found."
def has_any_animal(self) -> StardewRule:
return self.has_any_coop_animal() | self.has_any_barn_animal()
return self.logic.source.has_access_to_any(animal.sources) & self.logic.building.has_building(animal.required_building)
def has_any_coop_animal(self) -> StardewRule:
return self.logic.has_any(*coop_animals)
def has_any_barn_animal(self) -> StardewRule:
return self.logic.has_any(*barn_animals)
def has_happy_animal(self, animal_name: str) -> StardewRule:
return self.logic.animal.has_animal(animal_name) & self.logic.has(Forageable.hay)