Skip to content

Commit 3f6908a

Browse files
authored
Merge pull request #113 from iqnite/iqnite/issue100
Add Alter the Future NOW
2 parents 0cd1e74 + e93a974 commit 3f6908a

File tree

5 files changed

+39
-35
lines changed

5 files changed

+39
-35
lines changed

eggsplode/cards/future.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ async def show_next_cards(
2323
amount: int = 3,
2424
):
2525
next_cards = "\n".join(
26-
format_message(
27-
"list_item_1", tooltip(card)
28-
)
26+
format_message("list_item_1", tooltip(card))
2927
for card in deck[-1 : -amount - 1 : -1]
3028
)
3129
await interaction.respond(
@@ -37,7 +35,7 @@ async def show_next_cards(
3735

3836

3937
async def alter_future_finish(game: "Game", _):
40-
await game.send(view=TextView("altered_future", game.current_player_id))
38+
await game.send(view=TextView("altered_future", game.action_player_id))
4139
await game.events.action_end()
4240

4341

@@ -54,33 +52,30 @@ def __init__(
5452
self.callback_action = callback_action
5553
self.selects: list[discord.ui.Select] = []
5654
self.add_item(self.confirm_button)
55+
self.add_item(discord.ui.TextDisplay(format_message("next_cards")))
5756
self.create_selections()
5857

5958
def create_selections(self):
60-
card_options = [
61-
discord.SelectOption(
62-
value=f"{i}:{card}",
63-
label=CARDS[card]["title"],
64-
description=CARDS[card]["description"][:99],
65-
emoji=replace_emojis(CARDS[card]["emoji"]),
66-
)
67-
for i, card in enumerate(
68-
self.game.deck[-1 : -self.amount_of_cards - 1 : -1]
69-
)
70-
]
7159
for select in self.selects:
7260
self.remove_item(select)
7361
self.selects = []
7462
for i in range(self.amount_of_cards):
63+
card_options = [
64+
discord.SelectOption(
65+
value=f"{j}:{card}",
66+
label=CARDS[card]["title"],
67+
description=CARDS[card]["description"][:99],
68+
emoji=replace_emojis(CARDS[card]["emoji"]),
69+
default=j == i,
70+
)
71+
for j, card in enumerate(
72+
self.game.deck[-1 : -self.amount_of_cards - 1 : -1]
73+
)
74+
]
7575
select = discord.ui.Select(
76-
placeholder=format_message(
77-
"alter_future_placeholder",
78-
i + 1,
79-
CARDS[self.game.deck[-i - 1]]["title"],
80-
),
76+
options=card_options,
8177
min_values=1,
8278
max_values=1,
83-
options=card_options,
8479
)
8580
select.callback = self.selection_callback
8681
self.selects.append(select)

eggsplode/core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ async def draw(
257257
async def action_check(self, interaction: discord.Interaction) -> bool:
258258
if not interaction.user:
259259
raise TypeError("interaction.user is None")
260-
if interaction.user.id != self.current_player_id:
260+
if interaction.user.id != self.action_player_id:
261261
await interaction.respond(
262262
view=TextView("not_your_turn"), ephemeral=True, delete_after=5
263263
)
@@ -285,9 +285,13 @@ async def show_hand(self, interaction: discord.Interaction):
285285
await self.events.turn_reset()
286286

287287
async def play_callback(self, interaction: discord.Interaction, card: str):
288+
if not interaction.user:
289+
return
290+
if CARDS[card].get("now"):
291+
self.action_player_id = interaction.user.id
288292
if not await self.action_check(interaction):
289293
return
290-
self.current_player_hand.remove(card)
294+
self.action_player_hand.remove(card)
291295
await self.events.action_start()
292296
if CARDS[card].get("explicit", False):
293297
await self.play(interaction, card)
@@ -298,7 +302,7 @@ async def play_callback(self, interaction: discord.Interaction, card: str):
298302
message=format_message(
299303
"play_card",
300304
CARDS[card]["emoji"],
301-
self.current_player_id,
305+
self.action_player_id,
302306
tooltip(card, emoji=False),
303307
),
304308
)

eggsplode/ui/play.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ def update_sections(self):
5050
return
5151
for card, count in user_cards.items():
5252
card_playable = (
53-
self.playable
53+
not self.game.paused
5454
and CARDS[card].get("usable", False)
5555
and (CARDS[card].get("combo", 0) == 0 or count > 1)
56+
and (
57+
CARDS[card].get("now", False)
58+
or self.game.current_player_id == self.user_id
59+
)
5660
)
5761
section = discord.ui.Section(
5862
discord.ui.TextDisplay(
@@ -115,13 +119,11 @@ async def button_callback(interaction: discord.Interaction):
115119
return button
116120

117121
async def play_card(self, card: str, interaction: discord.Interaction):
118-
if not self.playable:
122+
if self.game.paused:
119123
await interaction.edit(view=TextView("not_your_turn"), delete_after=5)
120124
return
121125
if self.action_id != self.game.action_id:
122-
await interaction.edit(
123-
view=TextView(format_message("invalid_turn")), delete_after=10
124-
)
126+
await interaction.edit(view=TextView("invalid_turn"), delete_after=10)
125127
return
126128
self.game.action_id += 1
127129
self.action_id = self.game.action_id

resources/cards.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@
115115
"usable": true
116116
},
117117
"alter_future_now": {
118-
"title": "Alter the future",
119-
"description": "Look at the next 3 cards on the deck and rearrange them how you want.",
118+
"title": "Alter the future NOW⚡",
119+
"description": "Look at the next 3 cards on the deck and rearrange them how you want. Can be played anytime.",
120120
"emoji": "🪄",
121-
"usable": true
121+
"usable": true,
122+
"now": true
122123
},
123-
124124
"reverse": {
125125
"title": "Reverse",
126126
"description": "End your turn without drawing and reverse the order of play.",

resources/recipes.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@
8282
"bury": 2,
8383
"self_attegg": 4,
8484
"share_future": 2,
85+
"alter_future_now": 2,
8586
"super_skip": 1,
8687
"dig_deeper": 4
8788
}
8889
},
8990
"all_cards": {
90-
"name": "(Almost) all cards",
91+
"name": "All cards",
9192
"description": "The classic game + the Radioeggtive and Eggsperiment expansions",
9293
"emoji": "💯",
9394
"cards": {
@@ -129,8 +130,10 @@
129130
"bury": 2,
130131
"self_attegg": 4,
131132
"share_future": 2,
133+
"alter_future_now": 2,
132134
"super_skip": 1,
133-
"dig_deeper": 4
135+
"dig_deeper": 4,
136+
"swap_top_bottom": 4
134137
}
135138
},
136139
"mind_games": {

0 commit comments

Comments
 (0)