Skip to content

Commit

Permalink
feat: Cost.decrease_cost
Browse files Browse the repository at this point in the history
  • Loading branch information
zyr17 committed Sep 2, 2023
1 parent e85026a commit b900a97
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
18 changes: 7 additions & 11 deletions server/card/equipment/artifact/element_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from .base import ArtifactBase
from ....struct import Cost
from ....modifiable_values import CostValue
from ....consts import ElementType, ObjectPositionType, CostLabels
from ....consts import (
ELEMENT_TO_DIE_COLOR, ElementType, ObjectPositionType, CostLabels
)
from ....event import RoundPrepareEventArguments
from ....action import Actions

Expand Down Expand Up @@ -117,16 +119,10 @@ def value_modifier_COST(
# talent card not for this charactor
return value
# can decrease cost
used = 0
if (value.cost.elemental_dice_color == self.element
and value.cost.elemental_dice_number > 0):
value.cost.elemental_dice_number -= 1
used += 1
elif value.cost.any_dice_number > 0:
value.cost.any_dice_number -= 1
used += 1
if mode == 'REAL':
self.usage -= used
if value.cost.decrease_cost(ELEMENT_TO_DIE_COLOR[self.element]):
# decrease cost success
if mode == 'REAL':
self.usage -= 1
return value


Expand Down
12 changes: 5 additions & 7 deletions server/status/team_status/event_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ def value_modifier_COST(
if not (value.cost.label & CostLabels.SWITCH_CHARACTOR.value):
# not switch charactor, do nothing
return value
if value.cost.any_dice_number <= 0:
# no need dice, do nothing
return value
# self switch charactor, reduce cost by 1
value.cost.any_dice_number -= 1
if mode == 'REAL':
self.usage -= 1
# decrease 1 any cost
if value.cost.decrease_cost(None):
# decrease success
if mode == 'REAL':
self.usage -= 1
return value

def event_handler_SWITCH_CHARACTOR(
Expand Down
33 changes: 33 additions & 0 deletions server/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,39 @@ def total_dice_cost(self) -> int:
+ self.any_dice_number + self.omni_dice_number
)

def decrease_cost(self, dice_color: DieColor | None) -> bool:
"""
Decrease the cost by 1 dice of the given color in-place.
Return True if decrease successfully, False if not.
Args:
dice_color (DieColor | None): The dice color to be decreased.
If None, decrease same or any dice; Otherwise, decrease
elemental or any dice.
"""
assert dice_color != DieColor.OMNI, 'Omni dice is not supported yet.'
if dice_color is None:
# decrease same or any dice
if self.same_dice_number > 0:
self.same_dice_number -= 1
return True
if self.any_dice_number > 0:
self.any_dice_number -= 1
return True
return False
# decrease elemental or any dice
if (
self.elemental_dice_color == dice_color
and self.elemental_dice_number > 0
):
self.elemental_dice_number -= 1
return True
if self.any_dice_number > 0:
self.any_dice_number -= 1
return True
return False

def is_valid(self, dice_colors: List[DieColor], charge: int,
arcane_legend: bool, strict = True) -> bool:
"""
Expand Down

0 comments on commit b900a97

Please sign in to comment.