Skip to content

Commit

Permalink
refactor: lotus crisp as DefendCharactorStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
zyr17 committed Sep 2, 2023
1 parent 36288cb commit e85026a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 29 deletions.
70 changes: 68 additions & 2 deletions server/status/charactor_status/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Any, Literal, List

from ...modifiable_values import DamageDecreaseValue
from ...consts import ObjectType
from ..base import StatusBase
from ...action import RemoveObjectAction, Actions
Expand All @@ -10,6 +12,11 @@ class CharactorStatusBase(StatusBase):
Base class of charactor status.
"""
type: Literal[ObjectType.CHARACTOR_STATUS] = ObjectType.CHARACTOR_STATUS
name: str
desc: str
version: str
usage: int
max_usage: int


class UsageCharactorStatus(CharactorStatusBase):
Expand All @@ -26,7 +33,11 @@ class UsageCharactorStatus(CharactorStatusBase):
If it is not a damage related status, check_remove_triggered should be
called manually.
"""
name: Literal['UsageCharactorStatus'] = 'UsageCharactorStatus'
name: str
desc: str
version: str
usage: int
max_usage: int

def check_should_remove(self) -> List[Actions]:
"""
Expand Down Expand Up @@ -55,8 +66,11 @@ class RoundCharactorStatus(CharactorStatusBase):
event trigger on ROUND_PREPARE to check if run out of usages; when run out
of usages, it will remove itself.
"""
name: Literal['RoundCharactorStatus'] = 'RoundCharactorStatus'
name: str
desc: str
version: str
usage: int
max_usage: int

def check_should_remove(self) -> List[RemoveObjectAction]:
"""
Expand All @@ -79,3 +93,55 @@ def event_handler_ROUND_PREPARE(
"""
self.usage -= 1
return list(self.check_should_remove())


class DefendCharactorStatus(UsageCharactorStatus):
"""
Base class of defend status (purple shield), decrease damage with its rule
when receive damage, and decrease usage by 1.
"""
name: str
desc: str
version: str
usage: int
max_usage: int
min_damage_to_trigger: int
max_in_one_time: int
decrease_usage_by_damage: bool = False

def value_modifier_DAMAGE_DECREASE(
self, value: DamageDecreaseValue, match: Any,
mode: Literal['TEST', 'REAL']) -> DamageDecreaseValue:
"""
Decrease damage with its rule, and decrease 1 usage.
"""
if not value.is_corresponding_charactor_receive_damage(
self.position, match,
):
# not this charactor receive damage, not modify
return value
assert self.usage > 0
new_usage = value.apply_shield(
self.usage, self.min_damage_to_trigger,
self.max_in_one_time, self.decrease_usage_by_damage,
)
assert mode == 'REAL'
self.usage = new_usage
return value


class ShieldCharactorStatus(DefendCharactorStatus):
"""
Base class of shield status (yellow shield), decrease damage by its usage
and decrease corresponding usage.
"""
name: str
desc: str
version: str
usage: int
max_usage: int

# papams passing to apply_shield is fixed
min_damage_to_trigger: int = 0
max_in_one_time: int = 0
decrease_usage_by_damage: bool = True
32 changes: 5 additions & 27 deletions server/status/charactor_status/foods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from ...consts import SkillType

from ...modifiable_values import DamageDecreaseValue, DamageIncreaseValue
from ...modifiable_values import DamageIncreaseValue

from ...action import RemoveObjectAction

from ...event import MakeDamageEventArguments
from .base import RoundCharactorStatus
from .base import DefendCharactorStatus, RoundCharactorStatus


class Satiated(RoundCharactorStatus):
Expand Down Expand Up @@ -59,38 +59,16 @@ def event_handler_MAKE_DAMAGE(
return self.check_should_remove()


class LotusFlowerCrisp(RoundCharactorStatus):
class LotusFlowerCrisp(RoundCharactorStatus, DefendCharactorStatus):
name: Literal['Lotus Flower Crisp']
desc: str = (
"During this Round, the target character takes -3 DMG the next time."
)
version: Literal['3.3'] = '3.3'
usage: int = 1
max_usage: int = 1

def value_modifier_DAMAGE_DECREASE(
self, value: DamageDecreaseValue, match: Any,
mode: Literal['TEST', 'REAL']) -> DamageDecreaseValue:
assert mode == 'REAL'
if not value.is_corresponding_charactor_receive_damage(
self.position, match
):
# not this charactor receive damage, not modify
return value
if value.damage == 0:
# no damage, not modify
return value
assert self.usage > 0
decrease = min(3, value.damage)
value.damage -= decrease
assert mode == 'REAL'
self.usage -= 1
return value

def event_handler_MAKE_DAMAGE(
self, event: MakeDamageEventArguments, match: Any
) -> List[RemoveObjectAction]:
return self.check_should_remove()
min_damage_to_trigger: int = 1
max_in_one_time: int = 3


class TandooriRoastChicken(RoundCharactorStatus):
Expand Down

0 comments on commit e85026a

Please sign in to comment.