//------------------
    // affecting players
    //------------------

    public bool CanHenchmanAttackTargetPlayer(BoardSpaceEnum henchmanSpace, PlayerManager target)
    {
        HenchmanCard henchman = board[henchmanSpace];

        if (henchman != null)
        {
            if (!henchman.HasActedThisTurn())
            {
                if (henchman.GetController() != target)
                {
                    return(true);
                }
                else
                {
                    Debug.Log("Henchman can't attack a player because the player is its controller...");
                }
            }
            else
            {
                Debug.Log("Henchman can't attack a player because it already acted this turn...");
            }
        }
        else
        {
            Debug.Log("Henchman can't attack a player because it doesn't exist...");
        }
        return(false);
    }
    private void VisuallyPutHenchmanAtSpace(HenchmanCard henchman, BoardSpaceEnum space)
    {
        RectTransform henchmanTransform = henchman.GetComponent <RectTransform>();

        henchmanTransform.SetParent(visualBoardSpaces[space].transform);
        henchmanTransform.anchorMin     = new Vector2(0.5f, 0.5f);
        henchmanTransform.anchorMax     = new Vector2(0.5f, 0.5f);
        henchmanTransform.localScale    = new Vector3(1f, 1f, 1f);
        henchmanTransform.localPosition = new Vector3(0f, 0f, 0f);
    }
 /*
  * This method is called whenever the player clicks a henchman in play. It will cause the
  * RoTStateMachine to move to the AttackingWithHenchmanState as long as the henchman is
  * controlled by the active player and can still attack this turn.
  *
  * NOTE: Any behaviors related to clicking a henchman that has attacked or a henchman
  *       controlled by the opponent should be implemented in this method.
  */
 private void HandleHenchmanInPlaySelected(HenchmanCard henchman)
 {
     if (henchman.GetController() == rsm.GetActivePlayer())
     {
         if (!henchman.HasActedThisTurn())
         {
             rsm.SetAttackingHenchman(henchman);
             rsm.ChangeState <AttackingWithHenchmanState>();
         }
     }
 }
Beispiel #4
0
    /*
     * This method is called whenever the player clicks a henchman in play. If that
     * henchman is controlled by the non-active player, the attacking henchman will
     * attack it, if it can (based on Ellusive), then move the RoTStateMachine back
     * to the MainPhaseState. If that henchman is controlled by the active player,
     * the MainPhaseState will also be re-entered.
     */
    private void HandleHenchmanInPlaySelected(HenchmanCard henchman)
    {
        //CanHenchmenFight() will make sure the henchmen are on opposing sides of the board
        BoardSpaceEnum attackingLocation = rsm.GetAttackingHenchman().GetLocation();
        BoardSpaceEnum targetLocation    = henchman.GetLocation();

        if (rsm.GetBoard().CanHenchmenFight(attackingLocation, targetLocation))
        {
            rsm.GetBoard().HaveHenchmenFight(attackingLocation, targetLocation);
        }
        rsm.ChangeState <MainPhaseState>();
    }
    public override void Enter()
    {
        base.Enter();
        Debug.Log("Entering PlayingHenchmanState");

        //the card being played must be owned by the active player
        Debug.Assert(rsm.GetCardToBePlayed().GetController() == rsm.GetActivePlayer());

        //the card being played must be a henchman
        Debug.Assert(rsm.GetCardToBePlayed().GetType() == typeof(HenchmanCard));
        henchmanToBePlayed = (HenchmanCard)rsm.GetCardToBePlayed();
    }
    //should only be called if CanHenchmanAttackTargetPlayer() returns true
    public void HaveHenchmanAttackTargetPlayer(BoardSpaceEnum henchmanSpace, PlayerManager target, uint damageReduction = 0)
    {
        HenchmanCard henchman = board[henchmanSpace];

        if (henchman.GetAttack() > 0)
        {
            target.ApplyDamage(henchman.GetAttack() - damageReduction);
        }
        //trigger rush for combat damage
        henchman.RushEvent.Invoke();
        henchman.ActionTaken();
    }
 //returns true if successful
 public bool TryPutHenchmanOnOpponentSide(HenchmanCard henchman)
 {
     for (int i = (int)BoardSpaceEnum.O1; i <= (int)BoardSpaceEnum.O5; i++)
     {
         BoardSpaceEnum currSpace = (BoardSpaceEnum)i;
         if (CanPutHenchmanAtSpace(henchman, currSpace))
         {
             PutHenchmanAtSpace(henchman, currSpace);
             return(true);
         }
     }
     return(false);
 }
    //this method assumes the new henchman hasn't yet been added to henchmenOrder
    private void TriggerAttentionSeekerEvents()
    {
        //invoke attention-seeker events on all henchman, in the order they came into play
        RemoveQueue <BoardSpaceEnum> newOrder = new RemoveQueue <BoardSpaceEnum>();

        while (!henchmenOrder.IsEmpty())
        {
            BoardSpaceEnum henchmanSpace = henchmenOrder.Dequeue();
            HenchmanCard   henchman      = board[henchmanSpace];
            henchman.AttentionSeekerEvent.Invoke();
            newOrder.Enqueue(henchmanSpace);
        }
        henchmenOrder = newOrder;
    }
    //NOTE: Should be called before switching the active player!
    public void HandleEndOfTurn(PlayerManager activePlayer)
    {
        //call HandleEndOfTurn() on all HenchmanCards in play, in the order they came into play
        RemoveQueue <BoardSpaceEnum> newOrder = new RemoveQueue <BoardSpaceEnum>();

        while (!henchmenOrder.IsEmpty())
        {
            BoardSpaceEnum henchmanSpace = henchmenOrder.Dequeue();
            HenchmanCard   henchman      = board[henchmanSpace];
            if (henchman.GetController() == activePlayer)
            {
                henchman.HandleEndOfTurn();
            }
            newOrder.Enqueue(henchmanSpace);
        }
        henchmenOrder = newOrder;
    }
    public bool CanHenchmenFight(BoardSpaceEnum playerSpace, BoardSpaceEnum opponentSpace)
    {
        bool onOpposingSides = OnOpposingSides(playerSpace, opponentSpace);

        if ((board[playerSpace] != null) && (board[opponentSpace] != null) && onOpposingSides)
        {
            //if both spaces are occupied by henchman and they're on opposing sides of the board, they could be able to fight
            HenchmanCard playerHenchman   = board[playerSpace];
            HenchmanCard opponentHenchman = board[opponentSpace];
            if (!playerHenchman.HasActedThisTurn())
            {
                //if the henchman hasn't already acted this turn, the henchmen could fight
                if (playerHenchman.IsEllusive() || (!playerHenchman.IsEllusive() && !opponentHenchman.IsEllusive()))
                {
                    //if the attacking henchman is ellusive or neither henchman is ellusive, they can fight
                    return(true);
                }
                else
                {
                    Debug.Log("Henchmen wouldn've been able to fight, except one was ellusive and the other wasn't...");
                    return(false);
                }
            }
            else
            {
                Debug.Log("The henchman at playerSpace already moved this turn...");
                return(false);
            }
        }
        else
        {
            if (board[playerSpace] == null)
            {
                Debug.Log("playerSpace passed to TryHaveHenchmanFight() didn't have a henchman in it...");
            }
            if (board[opponentSpace] == null)
            {
                Debug.Log("opponentSpace passed to TryHaveHenchmanFight() didn't have a henchman in it...");
            }
            if (!onOpposingSides)
            {
                Debug.Log("The two henchman trying to fight in TryHaveHenchmanFight() weren't on opposite sides of the board...");
            }
            return(false);
        }
    }
    //---------------------
    // responding to events
    //---------------------

    private void TriggerVengeanceEvents(PlayerManager prizeCardRecipient)
    {
        //invoke vengeance events on relevant henchman, in the order they came into play
        RemoveQueue <BoardSpaceEnum> newOrder = new RemoveQueue <BoardSpaceEnum>();

        while (!henchmenOrder.IsEmpty())
        {
            BoardSpaceEnum henchmanSpace = henchmenOrder.Dequeue();
            HenchmanCard   henchman      = board[henchmanSpace];
            if (henchman.GetController() != prizeCardRecipient)
            {
                //only invoke the event if the recipient of the prize card was not the henchman's controller
                henchman.VengeanceEvent.Invoke();
            }
            newOrder.Enqueue(henchmanSpace);
        }
        henchmenOrder = newOrder;
    }
    //should only be called if CanPutHenchmanAtSpace() returns true
    public void PutHenchmanAtSpace(HenchmanCard henchman, BoardSpaceEnum space)
    {
        //put it on the board
        board[space] = henchman;
        henchman.SetPlayState(PlayStateEnum.BOARD);
        henchman.SetLocation(space);

        //move the henchman visually
        VisuallyPutHenchmanAtSpace(henchman, space);

        //invoke its flashy event
        henchman.FlashyEvent.Invoke();
        //invoke all other henchmen's attention-seeker events
        TriggerAttentionSeekerEvents();

        //add it to the order
        henchmenOrder.Enqueue(space);
    }
    //should only be called if CanRemoveHenchmanFromBoard() returns true
    public void RemoveHenchmanFromBoard(BoardSpaceEnum space)
    {
        HenchmanCard henchman = board[space];

        //remove it from the board
        board[space] = null;
        henchman.SetPlayState(PlayStateEnum.DONE);
        henchman.SetLocation(BoardSpaceEnum.NONE);

        //remove it from the order
        henchmenOrder.RemoveArbitrary(space);

        //remove the henchman visually
        henchman.gameObject.SetActive(false);

        //set up the henchman to be destroyed
        henchman.GetController().GetDeck().DestroyCard(henchman);

        //invoke its closing-act event
        henchman.ClosingActEvent.Invoke();
    }
    //should only be called if CanHenchmanFight() returns true
    public void HaveHenchmenFight(BoardSpaceEnum playerSpace, BoardSpaceEnum opponentSpace)
    {
        HenchmanCard playerHenchman   = board[playerSpace];
        HenchmanCard opponentHenchman = board[opponentSpace];

        //check if any damage needs to trample over
        int excess = (int)playerHenchman.GetAttack() - opponentHenchman.GetHealth();

        if ((excess > 0) && playerHenchman.IsOverAchiever())
        {
            Debug.Log("ROLLING DAMAGE OVER");
            uint reduction = playerHenchman.GetAttack() - (uint)excess;
            HaveHenchmanAttackTargetPlayer(playerSpace, opponentHenchman.GetController(), damageReduction: reduction);
        }

        //apply damage to the henchmen after applying trample damage to prevent issues arising from the
        //trampler dying after taking damage from the other henchman, then not being at playerSpace anymore
        //FIXME: find a more elegant solution, since this could cause some unintuitive interactions with
        //       triggered effects on the other henchman, since it technically won't "die" until after
        //       damage has trampled over
        playerHenchman.ApplyDamage((int)opponentHenchman.GetAttack());
        opponentHenchman.ApplyDamage((int)playerHenchman.GetAttack());
        playerHenchman.ActionTaken();
    }
    //------------------------
    // affecting cards in play
    //------------------------

    public bool CanPutHenchmanAtSpace(HenchmanCard henchman, BoardSpaceEnum space)
    {
        //henchman can be placed if the space is on it's controller's side
        bool onControllersSide = false;

        if (henchman.GetController() == player)
        {
            if ((space == BoardSpaceEnum.P1) || (space == BoardSpaceEnum.P2) || (space == BoardSpaceEnum.P3) ||
                (space == BoardSpaceEnum.P4) || (space == BoardSpaceEnum.P5))
            {
                onControllersSide = true;
            }
        }
        else if (henchman.GetController() == opponent)
        {
            if ((space == BoardSpaceEnum.O1) || (space == BoardSpaceEnum.O2) || (space == BoardSpaceEnum.O3) ||
                (space == BoardSpaceEnum.O4) || (space == BoardSpaceEnum.O5))
            {
                onControllersSide = true;
            }
        }
        else
        {
            Debug.Log("The henchman trying to be placed has a controller that's neither the player nor the opponent...");
        }

        if (onControllersSide)
        {
            //the space must also be empty
            return(board[space] == null);
        }
        else
        {
            return(false);
        }
    }
 public void SetAttackingHenchman(HenchmanCard henchman)
 {
     attackingHenchman = henchman;
 }
 /*
  * This method is used to clear out any temporary variables stored in the RoTStateMachine
  * that are used only by particular states, so there is never incorrect information being
  * used by those states.
  */
 public void ResetTemporaryVariables()
 {
     cardToBePlayed        = null;
     attackingHenchman     = null;
     shouldDrawOnTurnStart = true;
 }