2024-03-15 15:05:14 +03:00
|
|
|
from .base_logic import BaseLogic
|
2025-03-22 15:29:16 -04:00
|
|
|
from ..stardew_rule import StardewRule, And, Or, Has, Count, true_, false_, HasProgressionPercent
|
2024-03-15 15:05:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
class HasLogicMixin(BaseLogic[None]):
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
true_ = true_
|
|
|
|
false_ = false_
|
|
|
|
|
2024-03-15 15:05:14 +03:00
|
|
|
# Should be cached
|
|
|
|
def has(self, item: str) -> StardewRule:
|
|
|
|
return Has(item, self.registry.item_rules)
|
|
|
|
|
|
|
|
def has_all(self, *items: str):
|
|
|
|
assert items, "Can't have all of no items."
|
|
|
|
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
return self.logic.and_(*(self.has(item) for item in items))
|
2024-03-15 15:05:14 +03:00
|
|
|
|
|
|
|
def has_any(self, *items: str):
|
|
|
|
assert items, "Can't have any of no items."
|
|
|
|
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
return self.logic.or_(*(self.has(item) for item in items))
|
2024-03-15 15:05:14 +03:00
|
|
|
|
|
|
|
def has_n(self, *items: str, count: int):
|
|
|
|
return self.count(count, *(self.has(item) for item in items))
|
|
|
|
|
2025-03-22 15:29:16 -04:00
|
|
|
def has_progress_percent(self, percent: int):
|
|
|
|
assert percent >= 0, "Can't have a negative progress percent"
|
|
|
|
assert percent <= 100, "Can't have a progress percent over 100"
|
|
|
|
|
|
|
|
return HasProgressionPercent(self.player, percent)
|
|
|
|
|
2024-03-15 15:05:14 +03:00
|
|
|
@staticmethod
|
|
|
|
def count(count: int, *rules: StardewRule) -> StardewRule:
|
|
|
|
assert rules, "Can't create a Count conditions without rules"
|
|
|
|
assert len(rules) >= count, "Count need at least as many rules as the count"
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
assert count > 0, "Count can't be negative"
|
|
|
|
|
|
|
|
count -= sum(r is true_ for r in rules)
|
|
|
|
rules = list(r for r in rules if r is not true_)
|
|
|
|
|
|
|
|
if count <= 0:
|
|
|
|
return true_
|
|
|
|
|
|
|
|
if len(rules) == 1:
|
|
|
|
return rules[0]
|
2024-03-15 15:05:14 +03:00
|
|
|
|
|
|
|
if count == 1:
|
|
|
|
return Or(*rules)
|
|
|
|
|
|
|
|
if count == len(rules):
|
|
|
|
return And(*rules)
|
|
|
|
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
return Count(rules, count)
|
|
|
|
|
|
|
|
@staticmethod
|
2025-03-22 15:29:16 -04:00
|
|
|
def and_(*rules: StardewRule, allow_empty: bool = False) -> StardewRule:
|
|
|
|
"""
|
|
|
|
:param rules: The rules to combine
|
|
|
|
:param allow_empty: If True, return true_ when no rules are given. Otherwise, raise an error.
|
|
|
|
"""
|
|
|
|
if not rules:
|
|
|
|
assert allow_empty, "Can't create a And conditions without rules"
|
|
|
|
return true_
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
|
|
|
|
if len(rules) == 1:
|
|
|
|
return rules[0]
|
|
|
|
|
|
|
|
return And(*rules)
|
|
|
|
|
|
|
|
@staticmethod
|
2025-03-22 15:29:16 -04:00
|
|
|
def or_(*rules: StardewRule, allow_empty: bool = False) -> StardewRule:
|
|
|
|
"""
|
|
|
|
:param rules: The rules to combine
|
|
|
|
:param allow_empty: If True, return false_ when no rules are given. Otherwise, raise an error.
|
|
|
|
"""
|
|
|
|
if not rules:
|
|
|
|
assert allow_empty, "Can't create a Or conditions without rules"
|
|
|
|
return false_
|
Stardew Valley 6.x.x: The Content Update (#3478)
Focus of the Update: Compatibility with Stardew Valley 1.6 Released on March 19th 2024
This includes randomization for pretty much all of the new content, including but not limited to
- Raccoon Bundles
- Booksanity
- Skill Masteries
- New Recipes, Craftables, Fish, Maps, Farm Type, Festivals and Quests
This also includes a significant reorganisation of the code into "Content Packs", to allow for easier modularity of various game mechanics between the settings and the supported mods. This improves maintainability quite a bit.
In addition to that, a few **very** requested new features have been introduced, although they weren't the focus of this update
- Walnutsanity
- Player Buffs
- More customizability in settings, such as shorter special orders, ER without farmhouse
- New Remixed Bundles
2024-07-07 16:04:25 +03:00
|
|
|
|
|
|
|
if len(rules) == 1:
|
|
|
|
return rules[0]
|
|
|
|
|
|
|
|
return Or(*rules)
|