File size: 4,086 Bytes
bb3fbf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import numpy as np
from pytest_bdd import given, parsers, scenarios, then, when

from engine.game.game_state import MemberCard
from engine.models.ability import Ability, Effect, EffectType, TriggerType

scenarios("../features/complex.feature")


@given(parsers.parse('a player has a "Complex Member" with ability "Order -> Tap -> Draw"'))
def setup_complex_member(context, game_state):
    p = game_state.players[0]
    mid = 888

    complex_ability = Ability(
        raw_text="Test Ability",
        trigger=TriggerType.ACTIVATED,
        effects=[
            Effect(EffectType.ORDER_DECK, 2, params={"position": "bottom", "shuffle": True}),
            Effect(EffectType.TAP_OPPONENT, 1),
            Effect(EffectType.DRAW, 1),
        ],
        costs=[],
    )

    m = MemberCard(
        card_id=mid,
        card_no="TEST-888",
        name="Complex Test Card",
        cost=1,
        groups=[],
        hearts=np.zeros(6),
        blade_hearts=np.zeros(7),
        blades=1,
        abilities=[complex_ability],
    )
    game_state.member_db[mid] = m
    p.stage[0] = mid
    return m


@given("the opponent has a member on stage at slot 0")
def setup_opponent_member(context, game_state):
    opp = game_state.players[1]
    mid = 999
    # Ensure in DB
    if mid not in game_state.member_db:
        game_state.member_db[mid] = MemberCard(
            card_id=mid,
            card_no="OPP-01",
            name="Opponent",
            cost=1,
            groups=[],
            hearts=np.zeros(6),
            blade_hearts=np.zeros(7),
            blades=1,
        )

    opp.stage[0] = mid
    opp.tapped_members[0] = False


@given("the player's deck has 5 cards")
def setup_deck_5(context, game_state):
    p = game_state.players[0]
    p.main_deck = [10, 20, 30, 40, 50]


@when('the player activates the ability of "Complex Member"')
def activate_complex(context, game_state):
    # Action 200 = Activate Slot 0
    game_state = game_state.step(200)
    context["game_state"] = game_state


@then("the player should be prompted to select an opponent member")
def check_prompt_opponent(context, game_state):
    current_state = context["game_state"]
    assert len(current_state.pending_choices) > 0
    assert current_state.pending_choices[0][0] == "TARGET_OPPONENT_MEMBER"


@then(parsers.parse('the pending effects should contain "{effect_name}"'))
def check_pending_effect_contain(context, game_state, effect_name):
    current_state = context["game_state"]
    # effect types are enums. name property gives string.
    names = [e.effect_type.name for e in current_state.pending_effects]
    assert effect_name in names


@when("the player selects the opponent member at slot 0")
def select_opponent(context, game_state):
    # Action 600 = Target Opponent Slot 0
    current_state = context["game_state"]
    current_state = current_state.step(600)
    context["game_state"] = current_state


@then("the opponent member at slot 0 should be tapped")
def check_opponent_tapped(context, game_state):
    current_state = context["game_state"]
    opp = current_state.players[1]
    assert opp.tapped_members[0]  # Boolean truthiness check is safer for numpy


@then("the player should draw 1 card")
def check_draw_1(context, game_state):
    # Check hand size increased by 1 from initial?
    # Initial hand size was?
    # generic setup usually clears hand unless specified.
    # We didn't set hand size explicitly, so it's empty (generic `player_with_deck` not used here, we manually set main_deck).
    # Hand is empty by default in GameState? No, `init_game` sets it?
    # `GameState()` constructor initializes empty hand.
    # So expected 1.
    current_state = context["game_state"]
    p = current_state.players[0]
    assert len(p.hand) == 1


@then("the pending effects should be empty")
def check_pending_empty(context, game_state):
    current_state = context["game_state"]
    assert len(current_state.pending_effects) == 0