public override void Use()
 {
     //makes sure player is in jail before they can use card
     if (Jail.InJail())
     {
         Jail.LeaveJail();
         base.Use();
         GameManager.EndOfRollOptions();
     }
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        velocity = rb.velocity;             //Set the velocity of the dice.

        if (Rolling)
        {
            //if still rolling, the dice numbers are set to 0, and so returns from function
            byte diceTotal = 0;
            foreach (Die die in dice)
            {
                if (die.number == 0)
                {
                    return;
                }
                diceTotal += die.number;
            }

            //set total
            _diceTotal = diceTotal;
            _rolling   = false;

            //checks if player is in jail or not
            if (!Jail.InJail())
            {
                GameManager.CurrentPlayer.Move((sbyte)Result);
            }
            else if (dice[0].number == dice[1].number)
            {
                Jail.LeaveJail();
                GameManager.CurrentPlayer.Move((sbyte)Result);
            }
            else
            {
                MenuManager.SwitchToMenuWithInventory(MenuManager.EndOfTurnOptions);
            }

            //set the camera to track the current player and enable end of roll options
            CameraFollow.target = GameManager.CurrentPlayer.transform;
        }
    }
    //Funcitionality of all buttons relevant to an ongoing game. Their listeners are all placed
    //in this method as they can be called without pressing a button from the AI script.
    public static void CallIngameButtonListener(Button button)
    {
        Player player = GameManager.CurrentPlayer;

        if (player == null)
        {
            return;
        }

        bool ai = player.GetComponent <AI>();

        //Checks if ai called the listener or if the current player called it. This is needed
        //as if the player presses a button during the ai's turn, it needs to not do anything.
        if (button.interactable && ((!ai && ButtonClicked) || (ai && !ButtonClicked) ||
                                    /*only these buttons can be pressed by human when AI is active*/ button == Pay || button == TradingSystem.Offer || button == TradingSystem.Accept))
        {
            if (button == Roll)
            {
                Die.Roll();
            }
            else if (button == Buy)
            {
                GameManager.CurrentPlayer.Purchase();
                GameManager.UpdateBuyButtonInteractibility();
                GameManager.UpdateAuctionButtonInteractibility();
                GameManager.UpdateNextPlayerButtonInteractibility();
                UpdateInventoryData();
            }
            else if (button == PayFixed)
            {
                GameManager.PlayerMustPay(200);
            }
            else if (button == PayPercentage)
            {
                GameManager.PlayerMustPay((ushort)(0.1 * GameManager.CurrentPlayer.GetTotalPotentialBalance()));
            }
            else if (button == Pay)
            {
                Property    property    = GameManager.CurrentPlayer.Position.GetComponent <Property>();
                ChanceTile  chance      = GameManager.CurrentPlayer.Position.GetComponent <ChanceTile>();
                PaymentTile paymentTile = GameManager.CurrentPlayer.Position.GetComponent <PaymentTile>();
                if (property != null)
                {
                    ushort payment = property.PaymentPrice();
                    GameManager.CurrentPlayer.RemoveFunds(payment);
                    property.Owner.AddFunds(payment);
                    SwitchToMenuWithInventory(EndOfTurnOptions);
                }
                else if (chance != null)
                {
                    if (GameManager.ActiveCard is CardCollect)
                    {
                        ushort payment = 50;
                        CardCollect.currentPayee.RemoveFunds(payment);
                        GameManager.CurrentPlayer.AddFunds(payment);
                        CardCollect.currentPayee = GameManager.Players[(Array.IndexOf(GameManager.Players, CardCollect.currentPayee) + 1) % GameManager.Players.Length];

                        //switches payment to next player
                        if (CardCollect.currentPayee != GameManager.CurrentPlayer)
                        {
                            GameManager.PlayerMustPay(payment, CardCollect.currentPayee);
                        }
                        //if looped back around to current player, stop payment loop
                        else
                        {
                            SwitchToMenuWithInventory(EndOfTurnOptions);
                        }

                        //moves camera to whomever needs to pay
                        CameraFollow.target = CardCollect.currentPayee.transform;
                    }
                    else if (GameManager.ActiveCard is CardPay)
                    {
                        CardPay activeCard = (CardPay)GameManager.ActiveCard;
                        ushort  payment    = GameManager.PaymentNeeded;
                        GameManager.CurrentPlayer.RemoveFunds(payment);
                        CardPay cardPay = (CardPay)GameManager.ActiveCard;

                        //if statement to check player still exists
                        if (cardPay.Type == EnumsForCards.cardPay.payEachPlayer)
                        {
                            //Pays amount to each player
                            foreach (Player p in GameManager.Players)
                            {
                                if (p != GameManager.CurrentPlayer)
                                {
                                    p.AddFunds(activeCard.Amount);
                                }
                            }
                        }
                        SwitchToMenuWithInventory(EndOfTurnOptions);
                    }
                }
                else if (paymentTile != null)
                {
                    ushort payment = GameManager.PaymentNeeded;
                    GameManager.CurrentPlayer.RemoveFunds(payment);
                    SwitchToMenuWithInventory(EndOfTurnOptions);
                }
            }
            else if (button == AcknowledgeCard)
            {
                SwitchToMenuWithInventory(EndOfTurnOptions);
                if (!(GameManager.ActiveCard is CardGetOutOfJail || GameManager.ActiveCard is TileLink))
                {
                    GameManager.ActiveCard.Use();
                }
                UpdateInventoryData();
            }
            else if (button == Auction)
            {
                Auction.interactable = false;
                GameManager.UpdateBuyButtonInteractibility();
                GameManager.UpdateNextPlayerButtonInteractibility();                                                   //update this when Trading System is implemented
                AuctionSystem.StartAuction();
            }
            else if (button == NextTurn)
            {
                GameManager.NextPlayer();
            }
            else if (button == Bankrupt)
            {
                //remove all properties and cards from player
                Player lostPlayer = GameManager.CurrentPlayer;
                lostPlayer.Reset();
                GameManager.NextPlayer();
                GameManager.RemoveActivePlayer(lostPlayer);
            }
            else if (button == BuildHouse)
            {
                _houseMode = !_houseMode;
                if (_houseMode)
                {
                    Roll.interactable  = false;
                    Trade.interactable = false;
                    BuildHouse.GetComponentInChildren <Text>().text = "Back";
                }
                else
                {
                    Roll.interactable  = true;
                    Trade.interactable = true;
                    BuildHouse.GetComponentInChildren <Text>().text = "Build House";
                }
                UpdateInventoryData();
            }
            else if (button == BackToNormalCamera)
            {
                SwitchToMenuWithInventory(TurnOptions);
                SwitchToCamera(!GameManager.OnlyAIsInGame ? MainCamera : AmbientCamera);
            }
            else if (button == Trade)
            {
                TradingSystem.ShowTradingOptions();
            }
            //go to TradingSystem class if button is part of the trading system
            else if (Array.IndexOf(TradingSystem.Buttons, button) != -1)
            {
                TradingSystem.CallTradingButtonListener(button);
            }
            else if (button == PayToLeaveJail)
            {
                GameManager.PlayerMustPay(50);
                Jail.LeaveJail();
                SwitchToMenuWithInventory(EndOfTurnOptions);
            }
        }

        _buttonClicked = false;
    }