Skip to content

Game class reference

iqnite edited this page Jun 29, 2025 · 1 revision

Caution

This article is still under construction and incomplete.

eggsplode/core.py contains the main classes and methods that are responsible the game's flow control. It automates a lot of complex flow control actions, allowing you to focus on your card mechanics!

The Game class represents an Eggsplode game. It is initialized automatically at game start.

Attributes and properties

  • app (EggsplodeApp): The Discord app the game runs on.
  • config (dict): The configuration generated from the game settings.
  • players (list[int]): Contains the user IDs of the players that are still alive.
  • hands (dict[int, list[str]]): Contains the cards of the players that are still alive, matched to their user IDs.
  • deck (list[str]): The deck players draw from.
  • current_player (int): The list index of the player who has to draw or play next. Not to be confused with current_player_id.
  • current_player_id (get/set int): The Discord user ID of the current player.
  • current_player_hand (list[str]): The cards of the current player.
  • next_player (int): The list index of the player who will have to play after the current player, regardless of Atteggs. Not to be confused with next_player_id.
  • next_player_id (get int): The Discord user ID of the next player.
  • next_turn_player_id (get int): The Discord user ID of the player that will have to play after the current turn finishes. This considers Atteggs.
  • action_id (int): A number that is increased after every action, to ensure no "stale" actions are performed.
  • remaining_turns (int): The number of turns the current player has to perform before it is the next player's turn. Especially useful to handle Atteggs.
  • events (EventSet): A fixed set of events the game can notify and listen to.
  • last_activity (datetime): The time of the last user activity.
  • running (bool): Whether the game is still running or has ended.
  • paused (bool): Whether the turn timer is paused or should count down. No cards can be played (except for special ones such as Nope) while this is True. Useful when there is an active view with its own on_timeout function.
  • inactivity_count (int): The number of turns that have passed since the last activity.
  • anchor_interaction (discord.Interaction | None): The last valid public interaction, used to send follow-up messages on timeout.
  • play_actions (dict[str, Callable[[Game, discord.Interaction], Coroutine]]): The play actions from the expansions that have been loaded into the game.
  • draw_actions (dict[str, Callable[[Game, discord.Interaction, bool | None], Coroutine]]): The draw actions from the expansions that have been loaded into the game.
  • turn_warnings (list[Callable[[Game], str]]): The turn warnings from the expansions that have been loaded into the game.
  • setup_actions (list[Callable[[Game], None]]): The setup actions from the expansions that have been loaded into the game.
  • turn_prompt (get str): The message displayed above the Play a card and Draw buttons, telling who's turn it is.
  • warnings (get str): The message displayed below the Play a card and Draw buttons, set in the turn warnings list.

Methods

  • setup: Prepares the deck and player hands, and calls the setup actions.
  • start (async): Calls the setup method and begins the first turn.
    • Arguments: interaction (Interaction)
  • trim_deck: Removes a random number (from min_part to max_part) of cards from the deck. Unused since v1.4.
    • Arguments: min_part (int), max_part (int)
  • shuffle_deck: Shuffles the deck.
  • expand_deck: Increases the number of cards for every 5 players.
  • load_cards: Loads expansions from the configuration.
  • next_turn (async): Starts the next turn, considering remaining turns from Atteggs.
  • group_hand: Returns the cards of a certain player.
    • Arguments:
      • user_id (int): The Discord user ID of the player.
      • usable_only (bool): Whether only cards that can be played normally from the card selection should be included. Defaults to False.
    • Returns dict:
      • str: The name of the card.
      • int: How many of that card the player has.
  • play (async): Calls the play action for the specified card.
    • Arguments: interaction (Interaction), card (str)
  • draw (async): If present, calls the draw action for the specified card, else adds the card to the current player's hand.
    • Arguments:
      • interaction (Interaction): The Discord interaction that should be used to handle the action.
      • card (str): The drawn card.
      • timed_out (bool): Whether the card was drawn after turn timeout. Defaults to False.
    • Returns tuple:
      • str: The drawn card.
      • bool: False if the card had a draw action, True if it did not.
  • action_check (async): Checks if an interaction is legitimate, and shows an error message if it is not.
    • Arguments: Interaction
    • Returns bool: Whether the action is valid and should be continued.

Clone this wiki locally