draw accumulation

This commit is contained in:
JerryXiao 2023-10-04 15:34:37 +08:00
parent fc51c39101
commit b9fd7efbcb
Signed by: Jerry
GPG Key ID: 22618F758B5BE2E5
3 changed files with 27 additions and 4 deletions

View File

@ -155,11 +155,15 @@ def do_call_bluff(bot, player):
chat = game.chat
if player.prev.bluffing:
draw_prev = 4
draw_next = game.draw_counter - draw_prev
draw_next_text = ". " + __("Giving {count} cards to {name}").format(count=draw_next, name=player.user.first_name) if draw_next > 0 else ""
send_async(bot, chat.id,
text=__("Bluff called! Giving 4 cards to {name}",
text=__("Bluff called! Giving {count} cards to {name}" + draw_next_text,
multi=game.translate)
.format(name=player.prev.user.first_name))
.format(name=player.prev.user.first_name, count=draw_prev))
game.draw_counter = draw_prev
try:
player.prev.draw()
except DeckEmptyError:
@ -167,12 +171,21 @@ def do_call_bluff(bot, player):
text=__("There are no more cards in the deck.",
multi=game.translate))
game.draw_counter = draw_next
try:
player.draw()
except DeckEmptyError:
send_async(bot, player.game.chat.id,
text=__("There are no more cards in the deck.",
multi=game.translate))
else:
game.draw_counter += 2
send_async(bot, chat.id,
text=__("{name1} didn't bluff! Giving 6 cards to {name2}",
text=__("{name1} didn't bluff! Giving {count} cards to {name2}",
multi=game.translate)
.format(name1=player.prev.user.first_name,
count=game.draw_counter,
name2=player.user.first_name))
try:
player.draw()

8
bot.py
View File

@ -701,6 +701,14 @@ def process_result(update: Update, context: CallbackContext):
game.choose_color(result_id)
else:
reset_waiting_time(context.bot, player)
if game.mode == "text":
sticker_id = c.STICKERS.get(result_id)
if sticker_id:
context.bot.sendSticker(chat.id,
sticker=sticker_id,
timeout=TIMEOUT)
else:
logger.warning(f"no sticker found for {result_id=}")
do_play_card(context.bot, player, result_id)
if game_is_running(game):

View File

@ -149,7 +149,7 @@ class Player(object):
self.logger.debug("Matching!")
playable.append(card)
self.bluffing = (self.bluffing or card.color == last.color)
self.bluffing = (self.bluffing or (not card.special and (card.color == last.color or card.value == last.value)))
# You may not play a chooser or +4 as your last card
if len(self.cards) == 1 and self.cards[0].special:
@ -168,6 +168,8 @@ class Player(object):
not card.special):
self.logger.debug("Card's color or value doesn't match")
is_playable = False
elif (last.value == c.DRAW_TWO or last.special == c.DRAW_FOUR) and card.special == c.DRAW_FOUR:
self.logger.debug("Allow draw_four over draw_two or draw_four")
elif last.value == c.DRAW_TWO and not \
card.value == c.DRAW_TWO and self.game.draw_counter:
self.logger.debug("Player has to draw and can't counter")