Category talk

Mulligan

From Shadow Era Wiki

Revision as of 00:15, 3 October 2024 by Blopi (Talk | contribs)

  • Explanation of `case GameStateType.mulliganDraw:`

In card games, a "mulligan" is a mechanism that allows players to redraw their initial cards before the game begins. This gives them the chance to improve their hand by exchanging unwanted cards or all cards in hand.
`GameStateType` is an enumeration (enum) that defines different states of the game. Each state represents a specific moment or phase in the course of the game.
`mulliganDraw` is one of these states, indicating that the player is in the mulligan phase, where they the game choose for the player to redraw certain cards.

The logic within this case is responsible for managing the actions that need to occur when the game is in the mulligan state.
This may include operations such as:
Shuffling the deck: Before allowing the game to redraw, the game ensures that the deck is shuffled correctly to guarantee the randomness of the new cards.
Modifying the state of cards: Ensuring that the cards being redrawn are handled correctly within the system.
This does not include:
Updating the user interface: Indicating to the player if they can declare "Mulligan" after the shuffle and allowing the selection of all or some cards to redraw.


Code Summary and Detailed Code

FILE REFERENCES IN THE GAME
TERMS TO LOCATE MULLIGAN REFERENCE
  • AIController.cs: Manages AI player logic, including conditions for entering the `mulligan` state and invoking the `DoMulligan()` method to handle AI-specific mulligan actions.
  • PlayerController.cs: Contains player interaction logic, with specific handling for the `mulligan` state, allowing players to initiate and execute a mulligan through the `Mulligan()` method.
  • ReplayController.cs: Manages game replays, with logic to activate the `mulligan` state when processing replay commands.
  • GameController.cs: Implements the `Mulligan(ShadowEraCard card)` method to manage the process of performing a mulligan, including logging and transitioning to the `mulliganDraw` state.
  • GameOptions.cs: Contains the `mulligans` boolean option, allowing players to enable or disable the mulligan feature when setting up game options.
  • GameManager.cs: Defines an enumeration for move types that includes `mulligan`, indicating that this action is tracked as part of game moves.
  • Gameplay.cs: Supervises the game logic and checks for the `mulligan` state during game updates, enabling specific actions when in this state.
  • GameState.cs: Defines game states including `mulligan` and `mulliganDraw`, providing a framework for managing the transitions related to the mulligan mechanism.
  • Lobby.cs: Manages game lobby interactions, with options related to the `mulligans` toggle when creating or joining games.
  • Mulligan
SUMMARY OF THE MULLIGAN PROCESS:
  1. `GameManager.RecordMove(MoveTypeEnum.mulligan, null)` :
    Records the action of performing a mulligan in the game history.
  2. `PlayerController.Mulligan(null)` :
    Called when the player initiates a mulligan. It can either skip the mulligan or proceed based on the game state.
  3. `GameModel.GameStateActivate(GameState.GameStateType.mulligan)` :
    Activates the `mulligan` game state, allowing the game to enter the mulligan phase.
  4. `GameController.Mulligan(ShadowEraCard card)` :
    Handles the actual logic of the mulligan process. It checks the card being returned and manages the transition to drawing new cards.
  5. `GameModel.HandCount()` :
    Used within the `Mulligan` function to determine how many cards the player currently has in hand. It helps in deciding how many cards to draw back.
  6. `GameModel.DiscardCard(ShadowEraCard card)` :
    Called within the `Mulligan` function to discard a card selected for the mulligan.
  7. `GameModel.ShuffleDeck()` :
    Shuffles the deck after cards have been discarded as part of the mulligan process, ensuring the draw is random.
  8. `GameModel.GameStateActivate(GameState.GameStateType.mulliganDraw)` :
    Activates the `mulliganDraw` state, transitioning the game into the phase where new cards are drawn for the player.
  9. `GameModel.Draw(int side)` :
    Called during the `mulliganDraw` state to draw new cards for the specified player side. It handles the card drawing mechanics.
  10. `GameModel.CurSide()` :
    Retrieves the current player side, ensuring the appropriate player is drawing cards during the mulligan process.
DETAILED CODE
This code is a collection of all the functions involved in the shuffle mechanic, though it doesn't exist as a single block in any one file.
// GameManager.cs
public enum MoveTypeEnum
{
    mulligan,
    // other move types...
}
 
// PlayerController.cs
public void Mulligan()
{
    if (clickedCard == null && !GraveyardListDisplay.isShowingGraveYard && !DeckListDisplay.isShowingDeck)
    {
        GameManager.PressedGUIButton();
        GameManager.RecordMove(GameManager.MoveTypeEnum.mulligan, null);
        GameController.Mulligan(null);
        gameplay.ShowButton(gameplay.buttonBR2Red, "Mulligan");
 
        if (gameplay.button2Pressed)
        {
            GameManager.PressedGUIButton();
            GameManager.RecordMove(GameManager.MoveTypeEnum.mulligan, GameModel.GetHero());
            GameController.Mulligan(GameModel.GetHero());
        }
    }
}
 
// GameController.cs
public void Mulligan(ShadowEraCard card)
{
    if (card == null)
    {
        DebugLogger.Log("GameController Mulligan Skipped - curSide " + GameModel.CurSide() + " turnCounter " + GameModel.turnCounter);
        GameModel.SetCurSide(1 - GameModel.CurSide());
        GameModel.turnCounter++;
    }
    else
    {
        DebugLogger.Log("GameController Mulligan - curSide " + GameModel.CurSide() + " turnCounter " + GameModel.turnCounter);
        GameModel.DiscardCard(card); // Discard the selected card
        GameModel.ShuffleDeck(); // Shuffle the deck after discarding
        GameModel.GameStateActivate(GameState.GameStateType.mulliganDraw); // Transition to mulligan draw state
    }
}
 
// GameModel.cs
public int HandCount()
{
    // Returns the number of cards in the player's hand
}
 
public void DiscardCard(ShadowEraCard card)
{
    // Logic to remove the specified card from the player's hand
}
 
public void ShuffleDeck()
{
    // Logic to shuffle the player's deck
}
 
public void GameStateActivate(GameState.GameStateType newState)
{
    // Logic to change the game state
}
 
// Gameplay.cs
public void Update(float deltaTime)
{
    switch (GameModel.CurGameState())
    {
        case GameState.GameStateType.mulligan:
            // Handle actions specific to the mulligan state
            break;
        case GameState.GameStateType.mulliganDraw:
            if (stateTime == deltaTime)
            {
                for (int i = 0; i < 5; i++)
                {
                    GameModel.Draw(GameModel.CurSide()); // Draw new cards for the player
                }
            }
            break;
    }
}
 
// GameState.cs
public enum GameStateType
{
    pre,
    draw,
    mulligan,
    mulliganDraw,
    sacrifice,
    action,
    // other states...
}