示例#1
0
    private void OnTouch(object sender, PointerEventArgs e)
    {
        // Only when selling
        if (!selling)
        {
            return;
        }

        for (int i = 0; i < e.Pointers.Count; i++)
        {
            // Tell if we touched a card
            if (e.Pointers[i].GetPressData().Target != null && e.Pointers[i].GetPressData().Target.tag == "Card")
            {
                // Store in var for easier handling
                Transform lastTouchedCard = e.Pointers[i].GetPressData().Target;

                int lastTouchedCardIndex = int.Parse(lastTouchedCard.name);

                // Check if we own this card
                if (Game.Instance.CurrentPlayer.propertiesOwned.Contains(lastTouchedCardIndex))
                {
                    // Get houses manager
                    HouseManager manager = Game.Instance.board.boardCardHouses[lastTouchedCardIndex];

                    // Check if it has houses or hotels
                    if (manager.currHouses > 0 && !manager.cantClickBuy)
                    {
                        // Take off house
                        manager.TakeOffHouses();

                        // Get paid
                        Game.Instance.CurrentPlayer.AddCurrency(manager.housePrice);

                        // Refresh Info
                        Game.Instance.CurrentPlayer.RefreshPlayerInfo();
                    }
                    // Else we sell the property
                    else
                    {
                        if (!manager.OthersHaveHouses(lastTouchedCardIndex))
                        {
                            // Remove from owned cards
                            Game.Instance.CurrentPlayer.propertiesOwned.Remove(lastTouchedCardIndex);

                            // Give player money back
                            Game.Instance.CurrentPlayer.AddCurrency(Game.Instance.board.cardsPrice[lastTouchedCardIndex].price);

                            // Hide ownership
                            Game.Instance.board.boardOwnershipRender[lastTouchedCardIndex].enabled = false;

                            // Make it available again
                            Game.Instance.properties.availableCards.Add(lastTouchedCardIndex);

                            // Refresh Info
                            Game.Instance.CurrentPlayer.RefreshPlayerInfo();

                            // Check if we can sell more
                            CheckOnSellButton();

                            // If we sell a property might be posible not to build
                            Game.Instance.actions.build.CheckOnBuildButton();
                        }
                        else
                        {
                            Debug.Log("Other properties have houses, sell them first");
                        }
                    }
                    Game.Instance.actions.payment.CheckIfIStillNeedToPay();
                }
            }
        }
    }