Skip to content

Commit

Permalink
feat: implement toss-up
Browse files Browse the repository at this point in the history
  • Loading branch information
zyr17 committed Aug 31, 2023
1 parent 6af6f20 commit 745d83d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 29 deletions.
11 changes: 11 additions & 0 deletions server/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ActionTypes(str, Enum):

# generate request actions
GENERATE_CHOOSE_CHARACTOR = 'GENERATE_CHOOSE_CHARACTOR'
GENERATE_REROLL_DICE = 'GENERATE_REROLL_DICE'


class ActionBase(BaseModel):
Expand Down Expand Up @@ -325,6 +326,16 @@ class GenerateChooseCharactorRequestAction(ActionBase):
player_idx: int


class GenerateRerollDiceRequestAction(ActionBase):
"""
Action for generating reroll dice request.
"""
type: Literal[ActionTypes.GENERATE_REROLL_DICE] = \
ActionTypes.GENERATE_REROLL_DICE
player_idx: int
reroll_times: int


Actions = (
ActionBase | DrawCardAction | RestoreCardAction | RemoveCardAction
| ChooseCharactorAction | CreateDiceAction | RemoveDiceAction
Expand Down
81 changes: 53 additions & 28 deletions server/card/event/others.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,13 @@
from ...consts import DieColor, ObjectPositionType

from ...object_base import CardBase
from ...action import CreateDiceAction, CreateObjectAction, DrawCardAction
from ...action import (
CreateDiceAction, CreateObjectAction, DrawCardAction,
GenerateRerollDiceRequestAction
)
from ...struct import Cost, ObjectPosition


class Strategize(CardBase):
name: Literal['Strategize']
desc: str = '''Draw 2 cards.'''
version: Literal['3.3'] = '3.3'
cost: Cost = Cost(
same_dice_number = 1
)

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

def get_actions(
self, target: ObjectPosition | None, match: Any
) -> list[DrawCardAction]:
"""
Act the card. Draw two cards.
"""
assert target is None # no targets
return [DrawCardAction(
player_idx = self.position.player_idx,
number = 2,
draw_if_filtered_not_enough = True
)]


class TheBestestTravelCompanion(CardBase):
name: Literal['The Bestest Travel Companion!']
desc: str = '''Convert the Elemental Dice spent to Omni Element x2.'''
Expand Down Expand Up @@ -94,4 +71,52 @@ def get_actions(
)]


OtherEventCards = Strategize | TheBestestTravelCompanion | ChangingShifts
class TossUp(CardBase):
name: Literal['Toss-Up'] = 'Toss-Up'
desc: str = '''Select any Elemental Dice to reroll. Can reroll 2 times.'''
version: Literal['3.3'] = '3.3'
cost: Cost = Cost()

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

def get_actions(
self, target: ObjectPosition | None, match: Any
) -> list[GenerateRerollDiceRequestAction]:
assert target is None
return [GenerateRerollDiceRequestAction(
player_idx = self.position.player_idx,
reroll_times = 2,
)]


class Strategize(CardBase):
name: Literal['Strategize']
desc: str = '''Draw 2 cards.'''
version: Literal['3.3'] = '3.3'
cost: Cost = Cost(
same_dice_number = 1
)

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

def get_actions(
self, target: ObjectPosition | None, match: Any
) -> list[DrawCardAction]:
"""
Act the card. Draw two cards.
"""
assert target is None # no targets
return [DrawCardAction(
player_idx = self.position.player_idx,
number = 2,
draw_if_filtered_not_enough = True
)]


OtherEventCards = (
TheBestestTravelCompanion | ChangingShifts | TossUp | Strategize
)
10 changes: 9 additions & 1 deletion server/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
MoveObjectAction,
CharactorDefeatedAction,
GenerateChooseCharactorRequestAction,
GenerateRerollDiceRequestAction,
)
from .interaction import (
Requests, Responses,
Expand Down Expand Up @@ -1137,7 +1138,6 @@ def _respond_reroll_dice(self, response: RerollDiceResponse):
if isinstance(req, RerollDiceRequest):
if req.player_idx == response.player_idx:
if req.reroll_times > 1:
raise NotImplementedError('Not tested part')
req.reroll_times -= 1
else:
self.requests.pop(num)
Expand Down Expand Up @@ -1383,6 +1383,8 @@ def _act(self, action: ActionBase) -> List[EventArguments]:
return list(self._action_consume_arcane_legend(action))
elif isinstance(action, GenerateChooseCharactorRequestAction):
return list(self._action_generate_choose_charactor_request(action))
elif isinstance(action, GenerateRerollDiceRequestAction):
return list(self._action_generate_reroll_dice_request(action))
else:
self._set_match_state(MatchState.ERROR) # pragma no cover
raise AssertionError(f'Unknown action {action}.')
Expand Down Expand Up @@ -2273,3 +2275,9 @@ def _action_generate_choose_charactor_request(
) -> List[EventArgumentsBase]:
self._request_choose_charactor(action.player_idx)
return []

def _action_generate_reroll_dice_request(
self, action: GenerateRerollDiceRequestAction
) -> List[EventArgumentsBase]:
self._request_reroll_dice(action.player_idx, action.reroll_times)
return []

0 comments on commit 745d83d

Please sign in to comment.