Skip to content

Commit

Permalink
feat: implement wind and freedom
Browse files Browse the repository at this point in the history
also fix bug in charactor defeated.
  • Loading branch information
zyr17 committed Aug 31, 2023
1 parent fa71364 commit 1020927
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server/card/event/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .others import OtherEventCards
from .arcane_legend import ArcaneLegendCards
from .resonance import NationResonanceCards


EventCards = OtherEventCards | ArcaneLegendCards
EventCards = OtherEventCards | ArcaneLegendCards | NationResonanceCards
53 changes: 53 additions & 0 deletions server/card/event/resonance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@


from typing import Any, List, Literal
from server.action import CreateObjectAction
from ...consts import ObjectPositionType

from server.struct import ObjectPosition
from ...object_base import CardBase
from ...struct import Cost


class ElementalResonanceCardBase(CardBase):
... # pragma: no cover


class NationResonanceCardBase(CardBase):
pass


class WindAndFreedom(NationResonanceCardBase):
name: Literal['Wind and Freedom']
desc: str = (
'In this Round, when an opposing character is defeated during your '
'Action, you can continue to act again when that Action ends. '
'Usage(s): 1 '
'(You must have at least 2 Mondstadt characters in your deck to add '
'this card to your deck.)'
)
version: Literal['3.7'] = '3.7'
cost: Cost = Cost(same_dice_number = 1)

def get_targets(self, match: Any) -> List[ObjectPosition]:
return []

def get_actions(
self, target: ObjectPosition | None, match: Any
) -> List[CreateObjectAction]:
"""
Create Wind and Freedom team status.
"""
assert target is None
return [CreateObjectAction(
object_name = 'Wind and Freedom',
object_position = ObjectPosition(
player_idx = self.position.player_idx,
area = ObjectPositionType.TEAM_STATUS,
id = -1,
),
object_arguments = {},
)]


NationResonanceCards = WindAndFreedom | WindAndFreedom
1 change: 1 addition & 0 deletions server/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,7 @@ def _action_charactor_defeated(self, action: CharactorDefeatedAction) \
charactor.status = []
charactor.element_application = []
charactor.is_alive = False
charactor.charge = 0
need_switch = False
if table.active_charactor_idx == charactor_idx:
table.active_charactor_idx = -1 # reset active charactor
Expand Down
4 changes: 2 additions & 2 deletions server/object_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import random
from utils import BaseModel
from typing import List, Literal, Any
from .action import ActionBase, ActionTypes
from .action import Actions, ActionTypes
from .consts import ObjectType, WeaponType, ObjectPositionType, CostLabels
from .modifiable_values import ModifiableValueTypes
from .struct import (
Expand Down Expand Up @@ -104,7 +104,7 @@ def get_targets(self, match: Any) -> List[ObjectPosition]:

def get_actions(
self, target: ObjectPosition | None, match: Any
) -> List[ActionBase]:
) -> List[Actions]:
"""
Act the card. It will return a list of actions.
Expand Down
2 changes: 2 additions & 0 deletions server/status/team_status/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from .system import SystemTeamStatus
from .hydro_charactors import HydroCharactorTeamStatus
from .dendro_charactors import DendroTeamStatus
from .event_cards import EventCardTeamStatus

from .old_version import OldVersionTeamStatus


TeamStatus = (
SystemTeamStatus | HydroCharactorTeamStatus | DendroTeamStatus
| EventCardTeamStatus
# finally, old version status
| OldVersionTeamStatus
)
70 changes: 70 additions & 0 deletions server/status/team_status/event_cards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@


from typing import Any, Literal, List

from ...action import Actions, RemoveObjectAction

from ...event import (
CharactorDefeatedEventArguments, CombatActionEventArguments
)

from ...modifiable_values import CombatActionValue
from .base import RoundTeamStatus


class WindAndFreedom(RoundTeamStatus):
name: Literal['Wind and Freedom'] = 'Wind and Freedom'
desc: str = (
'In this Round, when an opposing character is defeated during your '
'Action, you can continue to act again when that Action ends. '
'Usage(s): 1 '
)
version: Literal['3.7'] = '3.7'
usage: int = 1
max_usage: int = 1
activated: bool = False

def event_handler_CHARACTOR_DEFEATED(
self, event: CharactorDefeatedEventArguments, match: Any
) -> List[Actions]:
"""
When an enemy charactor is defeated, mark activated.
"""
if (self.position.player_idx != event.action.player_idx):
# enemy defeated, mark activated.
self.activated = True
return []

def value_modifier_COMBAT_ACTION(
self, value: CombatActionValue, match: Any,
mode: Literal['TEST', 'REAL']
) -> CombatActionValue:
"""
When enemy charactor defeated,
"""
if not self.activated:
# not activated, do nothing
return value
assert self.usage > 0
assert self.position.check_position_valid(
value.position, match, player_idx_same = True,
)
# combat action end from self, if combat action, change to quick.
if value.do_combat_action:
value.do_combat_action = False
self.usage -= 1
else:
# Mona + Kaeya may trigger
raise NotImplementedError('Not tested part')
return value

def event_handler_COMBAT_ACTION(
self, event: CombatActionEventArguments, match: Any
) -> List[RemoveObjectAction]:
"""
When combat action end, check whether to remove.
"""
return self.check_should_remove()


EventCardTeamStatus = WindAndFreedom | WindAndFreedom

0 comments on commit 1020927

Please sign in to comment.