Skip to content

Commit

Permalink
Add use_purchase_limit field, so that some children might use the l…
Browse files Browse the repository at this point in the history
…imit while others don't.
  • Loading branch information
kw committed May 1, 2024
1 parent 652a2bb commit dd82ab5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = 'camp-engine'
version = '0.0.1'
authors = [{ name = "Ken Moriarty", email = "[email protected]" }]
authors = [{ name = "Ken Moriarty", email = "[email protected]" }]
description = "Rules engines for the Camp app"
readme = "README.md"
license = { file = "LICENSE" }
Expand All @@ -19,7 +19,7 @@ force_single_line = true
name = "camp-engine"
version = "0.1.0"
description = ""
authors = ["Ken Moriarty <[email protected]>"]
authors = ["Ken Moriarty <[email protected]>"]
readme = "README.md"
packages = [{ include = "camp", from = "src" }]

Expand Down
12 changes: 10 additions & 2 deletions src/camp/engine/rules/tempest/controllers/feature_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def child_purchase_limit(self) -> int | None:

@property
def child_purchase_count(self) -> int:
return sum(c.purchased_ranks for c in self.children)
return sum(c.purchased_ranks for c in self.children if c.purchase_limit_applies)

@property
def child_purchase_remaining(self) -> int | None:
Expand All @@ -600,6 +600,10 @@ def child_purchase_remaining(self) -> int | None:
def child_purchase_budget(self) -> int | None:
return None

@property
def purchase_limit_applies(self) -> bool:
return self.definition.use_purchase_limit

def can_increase(self, value: int = 1) -> Decision:
if value <= 0:
return _MUST_BE_POSITIVE
Expand All @@ -612,7 +616,11 @@ def can_increase(self, value: int = 1) -> Decision:
if purchaseable <= 0:
return Decision.NO
# If the parent feature has purchase limits for children, enforce it.
if self.parent and self.parent.supports_child_purchases:
if (
self.purchase_limit_applies
and self.parent
and self.parent.supports_child_purchases
):
if (remaining := self.parent.child_purchase_remaining) is not None:
if remaining < value:
return Decision(
Expand Down
1 change: 1 addition & 0 deletions src/camp/engine/rules/tempest/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class BaseFeatureDef(base_models.BaseFeatureDef, PowerCard):
choices: dict[str, ChoiceDef] | None = None
subcard: PowerCard | list[PowerCard] | None = None
child_purchase: ChildPurchaseDef | None = None
use_purchase_limit: bool = False

def post_validate(self, ruleset: base_models.BaseRuleset) -> None:
super().post_validate(ruleset)
Expand Down

0 comments on commit dd82ab5

Please sign in to comment.