|
|
|
@@ -50,17 +50,14 @@ def use_item(item: WorldItem, nickname: str, _clock_formatter: Callable[[dict],
|
|
|
|
discard_pile = []
|
|
|
|
discard_pile = []
|
|
|
|
if not isinstance(hands, dict):
|
|
|
|
if not isinstance(hands, dict):
|
|
|
|
hands = {}
|
|
|
|
hands = {}
|
|
|
|
hand = hands.get(nickname, [])
|
|
|
|
|
|
|
|
if not isinstance(hand, list):
|
|
|
|
|
|
|
|
hand = []
|
|
|
|
|
|
|
|
draw_count = len(draw_pile)
|
|
|
|
draw_count = len(draw_pile)
|
|
|
|
discard_count = len(discard_pile)
|
|
|
|
discard_count = len(discard_pile)
|
|
|
|
hand_count = len(hand)
|
|
|
|
dealt_count = sum(len(v) for v in hands.values() if isinstance(v, list))
|
|
|
|
|
|
|
|
|
|
|
|
return ItemUseResult(
|
|
|
|
return ItemUseResult(
|
|
|
|
self_message=(
|
|
|
|
self_message=(
|
|
|
|
f"{item.title}: {draw_count} in draw pile, "
|
|
|
|
f"{item.title}: {draw_count} in draw pile, "
|
|
|
|
f"{discard_count} in discard, {hand_count} in your hand."
|
|
|
|
f"{discard_count} in discard, {dealt_count} dealt out."
|
|
|
|
),
|
|
|
|
),
|
|
|
|
others_message="",
|
|
|
|
others_message="",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@@ -88,6 +85,7 @@ def interact_item(
|
|
|
|
item: WorldItem,
|
|
|
|
item: WorldItem,
|
|
|
|
action: str,
|
|
|
|
action: str,
|
|
|
|
params: dict | None,
|
|
|
|
params: dict | None,
|
|
|
|
|
|
|
|
actor_id: str,
|
|
|
|
nickname: str,
|
|
|
|
nickname: str,
|
|
|
|
) -> ItemUseResult:
|
|
|
|
) -> ItemUseResult:
|
|
|
|
"""Handle a card table interact action on behalf of any user."""
|
|
|
|
"""Handle a card table interact action on behalf of any user."""
|
|
|
|
@@ -103,9 +101,9 @@ def interact_item(
|
|
|
|
if not draw_pile:
|
|
|
|
if not draw_pile:
|
|
|
|
raise ValueError("Draw pile is empty.")
|
|
|
|
raise ValueError("Draw pile is empty.")
|
|
|
|
card = draw_pile.pop(0)
|
|
|
|
card = draw_pile.pop(0)
|
|
|
|
hand = list(hands.get(nickname, []))
|
|
|
|
hand = list(hands.get(actor_id, []))
|
|
|
|
hand.append(card)
|
|
|
|
hand.append(card)
|
|
|
|
hands[nickname] = hand
|
|
|
|
hands[actor_id] = hand
|
|
|
|
return ItemUseResult(
|
|
|
|
return ItemUseResult(
|
|
|
|
self_message=f"You drew {_card_name(card)}. {len(draw_pile)} remaining in draw pile.",
|
|
|
|
self_message=f"You drew {_card_name(card)}. {len(draw_pile)} remaining in draw pile.",
|
|
|
|
others_message=f"{nickname} draws a card.",
|
|
|
|
others_message=f"{nickname} draws a card.",
|
|
|
|
@@ -121,9 +119,9 @@ def interact_item(
|
|
|
|
if not isinstance(card_index, int) or card_index < 0 or card_index >= len(discard_pile):
|
|
|
|
if not isinstance(card_index, int) or card_index < 0 or card_index >= len(discard_pile):
|
|
|
|
raise ValueError("Invalid card_index.")
|
|
|
|
raise ValueError("Invalid card_index.")
|
|
|
|
card = discard_pile.pop(card_index)
|
|
|
|
card = discard_pile.pop(card_index)
|
|
|
|
hand = list(hands.get(nickname, []))
|
|
|
|
hand = list(hands.get(actor_id, []))
|
|
|
|
hand.append(card)
|
|
|
|
hand.append(card)
|
|
|
|
hands[nickname] = hand
|
|
|
|
hands[actor_id] = hand
|
|
|
|
return ItemUseResult(
|
|
|
|
return ItemUseResult(
|
|
|
|
self_message=f"You took {_card_name(card)} from the discard pile.",
|
|
|
|
self_message=f"You took {_card_name(card)} from the discard pile.",
|
|
|
|
others_message=f"{nickname} takes a card from the discard pile.",
|
|
|
|
others_message=f"{nickname} takes a card from the discard pile.",
|
|
|
|
@@ -133,13 +131,13 @@ def interact_item(
|
|
|
|
if action == "discard":
|
|
|
|
if action == "discard":
|
|
|
|
if not params or "card_index" not in params:
|
|
|
|
if not params or "card_index" not in params:
|
|
|
|
raise ValueError("discard requires params.card_index.")
|
|
|
|
raise ValueError("discard requires params.card_index.")
|
|
|
|
hand = list(hands.get(nickname, []))
|
|
|
|
hand = list(hands.get(actor_id, []))
|
|
|
|
card_index = params["card_index"]
|
|
|
|
card_index = params["card_index"]
|
|
|
|
if not isinstance(card_index, int) or card_index < 0 or card_index >= len(hand):
|
|
|
|
if not isinstance(card_index, int) or card_index < 0 or card_index >= len(hand):
|
|
|
|
raise ValueError("Invalid card_index.")
|
|
|
|
raise ValueError("Invalid card_index.")
|
|
|
|
card = hand.pop(card_index)
|
|
|
|
card = hand.pop(card_index)
|
|
|
|
discard_pile.insert(0, card)
|
|
|
|
discard_pile.insert(0, card)
|
|
|
|
hands[nickname] = hand
|
|
|
|
hands[actor_id] = hand
|
|
|
|
return ItemUseResult(
|
|
|
|
return ItemUseResult(
|
|
|
|
self_message=f"You discarded {_card_name(card)}.",
|
|
|
|
self_message=f"You discarded {_card_name(card)}.",
|
|
|
|
others_message=f"{nickname} discards a card.",
|
|
|
|
others_message=f"{nickname} discards a card.",
|
|
|
|
@@ -149,13 +147,13 @@ def interact_item(
|
|
|
|
if action == "return_to_pile":
|
|
|
|
if action == "return_to_pile":
|
|
|
|
if not params or "card_index" not in params:
|
|
|
|
if not params or "card_index" not in params:
|
|
|
|
raise ValueError("return_to_pile requires params.card_index.")
|
|
|
|
raise ValueError("return_to_pile requires params.card_index.")
|
|
|
|
hand = list(hands.get(nickname, []))
|
|
|
|
hand = list(hands.get(actor_id, []))
|
|
|
|
card_index = params["card_index"]
|
|
|
|
card_index = params["card_index"]
|
|
|
|
if not isinstance(card_index, int) or card_index < 0 or card_index >= len(hand):
|
|
|
|
if not isinstance(card_index, int) or card_index < 0 or card_index >= len(hand):
|
|
|
|
raise ValueError("Invalid card_index.")
|
|
|
|
raise ValueError("Invalid card_index.")
|
|
|
|
card = hand.pop(card_index)
|
|
|
|
card = hand.pop(card_index)
|
|
|
|
draw_pile.append(card)
|
|
|
|
draw_pile.append(card)
|
|
|
|
hands[nickname] = hand
|
|
|
|
hands[actor_id] = hand
|
|
|
|
return ItemUseResult(
|
|
|
|
return ItemUseResult(
|
|
|
|
self_message=f"You returned {_card_name(card)} to the draw pile.",
|
|
|
|
self_message=f"You returned {_card_name(card)} to the draw pile.",
|
|
|
|
others_message=f"{nickname} returns a card to the draw pile.",
|
|
|
|
others_message=f"{nickname} returns a card to the draw pile.",
|
|
|
|
|