Skip to content

Commit

Permalink
Effects+Logging: Overload format for discounting effects
Browse files Browse the repository at this point in the history
  • Loading branch information
loftyinclination committed Aug 26, 2023
1 parent 512ff03 commit 3186353
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions buisness_logic/effects/purchase_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(
"""
if decrease_by is None:
raise ValueError("Amount to decrease by cannot be null.")
self._decreaseBy: Dict[ResourceTypeEnum] = decrease_by
self._decrease_by: Dict[ResourceTypeEnum] = decrease_by
BaseTilePurchaseEffect.__init__(self, True)

def invoke(
Expand All @@ -53,14 +53,29 @@ def invoke(

new_price: Dict[ResourceTypeEnum, int] = dict(current_price)

for resource in self._decreaseBy:
for resource in self._decrease_by:
current_price_for_resource = new_price.get(resource, 0)
current_price_for_resource -= self._decreaseBy[resource]
current_price_for_resource -= self._decrease_by[resource]

new_price[resource] = current_price_for_resource

return new_price

def __str__(self) -> str:
return self.__format__(" ")

def __format__(self, format_spec):
text = [("", "Decrease cost of any purchase by ")]
for (i, (resource, amount)) in enumerate(self._decrease_by.items()):
text.append(("class:count", str(amount)))
text.append(("", " "))
text.append(("class:resource", resource.name))
if i != len(self._decrease_by) - 1:
text.append(("", ", "))
if format_spec == "pp":
return text
return "".join(e[1] for e in text)


class AllowSubstitutionForPurchaseEffect(BaseTilePurchaseEffect):
def __init__(
Expand Down Expand Up @@ -183,3 +198,18 @@ def invoke(
new_price[resource] = current_price_for_resource

return new_price

def __str__(self) -> str:
return self.__format__(" ")

def __format__(self, format_spec):
text = [("", "Decrease cost of weapon purchase by ")]
for (i, (resource, amount)) in enumerate(self._decrease_by.items()):
text.append(("class:count", str(amount)))
text.append(("", " "))
text.append(("class:resource", resource.name))
if i != len(self._decrease_by) - 1:
text.append(("", ", "))
if format_spec == "pp":
return text
return "".join(e[1] for e in text)

0 comments on commit 3186353

Please sign in to comment.