예제 #1
0
    public override void EnterUI()
    {
        base.EnterUI();

        MenuManager.UpdateCardInfo(property);

        if (!MenuManager.TradingMode)
        {
            Street street = property.GetComponent <Street>();
            if (MenuManager.BuildHouseMode)
            {
                if (street == null)
                {
                    toolTip.text = "Cannot build house on this type of property";
                }
                else if (!street.CanBuildHouse())
                {
                    toolTip.text = "House requirements not met";
                }
                else
                {
                    toolTip.text = "Build house for $" + street.HousePrice;
                }
            }
            else if (property.CanMortagage())
            {
                toolTip.text = "Click to mortgage";
            }
            else if (street != null && street.CanSellHouse())
            {
                toolTip.text = "Click to sell house for $" + street.SellHousePrice;
            }
            else if (property.Mortgaged && MenuManager.PaymentOptions.enabled == false)
            {
                toolTip.text = "Click to unmortgage";
            }
            else if (MenuManager.PaymentOptions.enabled == true)
            {
                toolTip.text = "Cannot unmortgage as a payment is due";
            }
            else
            {
                toolTip.text = "House selling requirements not met";
            }

            //change camera to property
            CameraFollow.target = property.transform;
            return;
        }

        //set tool tip based on whether property offered/who is offering
        Player owner = property.Owner;

        if (owner == GameManager.CurrentPlayer)
        {
            if (!TradingSystem.CurrentPlayerOffer.Contains(property))
            {
                toolTip.text = !TradingSystem.CounterOfferInProgress ? "Add to offer" : "Add to demand";
                return;
            }
            toolTip.text = !TradingSystem.CounterOfferInProgress ? "Remove from offer" : "Remove from demand";
            return;
        }
        if (!TradingSystem.TradeeOffer.Contains(property))
        {
            toolTip.text = !TradingSystem.CounterOfferInProgress ? "Add to demand" : "Add to offer";
            return;
        }
        toolTip.text = !TradingSystem.CounterOfferInProgress ? "Remove from demand" : "Remove from offer";
    }
예제 #2
0
    //Add AI pays when a collect from everyone card is picked up

    void Update()
    {
        if (timer == 0)
        {
            Player playerComp = gameObject.GetComponent <Player>();
            if (GameManager.CurrentPlayer == playerComp ||
                CardCollect.currentPayee == playerComp ||
                TradingSystem.Tradee == playerComp)
            {
                if (MenuManager.TurnOptions.enabled == true)
                {
                    if (!MenuManager.BuildHouseMode)
                    {
                        //check if a player has anything to trade
                        bool tradingPartnerExists = false;
                        foreach (Player player in GameManager.Players)
                        {
                            if (player != playerComp && player.PropertiesOwned.Count > 0)
                            {
                                tradingPartnerExists = true;
                                break;
                            }
                        }

                        //has % chance to intitate trading if amount of offers this turn have not been exceded
                        if (tradingPartnerExists && offers < MAX_OFFERS_PER_TURN && UnityEngine.Random.Range(0f, 1f) < CHANCE_OF_TRADING_BEFORE_ROLL)
                        {
                            Click(MenuManager.Trade);
                        }
                        else
                        {
                            //Build house if possible - update this for different AI modes
                            bool canBuildHouse = false;
                            foreach (Property property in GameManager.CurrentPlayer.PropertiesOwned)
                            {
                                if (property.GetComponent <Street>() != null && property.GetComponent <Street>().CanBuildHouse())
                                {
                                    canBuildHouse = true;
                                    break;
                                }
                            }

                            if (canBuildHouse)
                            {
                                Click(MenuManager.BuildHouse);
                            }
                            else
                            {
                                Click(MenuManager.Roll);
                            }
                        }
                    }
                    else
                    {
                        //Build house on heighest value streets - update this for different AI modes
                        bool houseBuilt = false;
                        for (byte i = (byte)(GameManager.CurrentPlayer.PropertiesOwned.Count - 1); i >= 0; i--)
                        {
                            foreach (Property property in GameManager.CurrentPlayer.PropertiesOwned)
                            {
                                Street street = property.GetComponent <Street>();
                                if (street != null && street.CanBuildHouse())
                                {
                                    street.BuildHouse();
                                    houseBuilt = true;
                                    break;
                                }
                            }
                            if (houseBuilt)
                            {
                                Click(MenuManager.BuildHouse);
                                break;
                            }
                        }
                    }
                }
                else if (MenuManager.EndOfTurnOptions.enabled == true)
                {
                    if (!Click(MenuManager.Buy))
                    {
                        if (!Click(MenuManager.Auction))
                        {
                            //reset number of trade offers AI has attempted
                            offers = 0;
                            Click(MenuManager.NextTurn);
                        }
                    }
                }
                else if (MenuManager.PaymentOptions.enabled == true)
                {
                    if (!(GameManager.ActiveCard is CardCollect) || CardCollect.currentPayee == GameManager.CurrentPlayer)
                    {
                        if (!Click(MenuManager.Pay))
                        {
                            Mortgage();
                        }
                    }
                }
                else if (MenuManager.PaymentTileOptions.enabled == true)
                {
                    int potentialFunds = GameManager.CurrentPlayer.GetTotalPotentialBalance() + GameManager.CurrentPlayer.GetBalance() / 10;
                    if (potentialFunds > 200)                                               //may need to change the 200 for super tax tile
                    {
                        Click(MenuManager.PayFixed);
                    }
                    else
                    {
                        Click(MenuManager.PayPercentage);
                    }
                }
                else if (MenuManager.CardOptions.enabled == true)
                {
                    Click(MenuManager.AcknowledgeCard);
                }
                else if (MenuManager.LoseOptions.enabled == true)
                {
                    Click(MenuManager.Bankrupt);
                }
                else if (TradingSystem.TradingSetup.enabled == true)
                {
                    //goes back if AI has made enough offers this turn
                    if (offers >= MAX_OFFERS_PER_TURN)
                    {
                        Click(TradingSystem.Back);
                    }
                    else
                    {
                        uint   highestVal   = 0;
                        Button playerButton = null;

                        //finds player who can trade the most total value                        //change this for different personalitites
                        foreach (Button button in TradingSystem.TradingPartnerOptions)
                        {
                            if (button.interactable == true)
                            {
                                uint val = 0;
                                foreach (Player player in GameManager.Players)
                                {
                                    if (player.gameObject.name == button.GetComponentInChildren <Text>().text)
                                    {
                                        val = TradingSystem.GetTradingValue(player.PropertiesOwned);
                                        break;
                                    }
                                }
                                if (val >= highestVal)
                                {
                                    highestVal   = val;
                                    playerButton = button;
                                }
                            }
                        }
                        Click(playerButton);
                    }
                }
                else if (TradingSystem.TradingOptions.enabled == true)
                {
                    //if AI is the tradee
                    if (TradingSystem.Tradee == playerComp && TradingSystem.CounterOfferInProgress)                          //set it up so AI does not repeat offers
                    {
                        TradingDecision(false);
                    }
                    //if AI is the trader
                    else if (GameManager.CurrentPlayer == playerComp && !TradingSystem.CounterOfferInProgress)
                    {
                        TradingDecision(true);
                    }
                }
            }
        }
        timer = timer == 0 ? TIME_BETWEEN_CLICKS + 1 : timer;
        timer--;
    }
예제 #3
0
    public static void CreatePropertyCard(Transform parent, Property property, Vector2 localPosition, Vector2 sizeDelta)
    {
        Street street = property.GetComponent <Street>();

        GameObject cardObj = new GameObject("InventoryCard");
        Image      card    = cardObj.AddComponent <Image>();

        card.tag = "InventoryCard";
        card.transform.SetParent(parent);
        card.rectTransform.sizeDelta     = sizeDelta;
        card.rectTransform.localPosition = localPosition;

        cardObj.AddComponent <InventoryPropertyMouseInputUI>().property = property;

        Text title = new GameObject().AddComponent <Text>();

        title.text      = property.Title;
        title.fontSize  = 6;
        title.color     = Color.black;
        title.font      = Resources.GetBuiltinResource <Font>("Arial.ttf");
        title.alignment = TextAnchor.UpperCenter;
        title.transform.SetParent(card.transform);
        title.rectTransform.sizeDelta     = new Vector2(card.rectTransform.sizeDelta.x * 4 / 5, card.rectTransform.sizeDelta.y / 6);
        title.rectTransform.localPosition = new Vector2(0f, 35f);

        if (!property.Mortgaged)
        {
            Text price = new GameObject().AddComponent <Text>();
            price.text      = "$" + property.Price;
            price.fontSize  = 6;
            price.color     = Color.black;
            price.font      = Resources.GetBuiltinResource <Font>("Arial.ttf");
            price.alignment = TextAnchor.UpperCenter;
            price.transform.SetParent(card.transform);
            price.rectTransform.sizeDelta     = new Vector2(card.rectTransform.sizeDelta.x * 4 / 5, card.rectTransform.sizeDelta.y / 6);
            price.rectTransform.localPosition = new Vector2(0f, -40f);

            if (street != null)
            {
                Image streetColour = new GameObject("StreetColour").AddComponent <Image>();
                streetColour.transform.SetParent(card.transform);
                streetColour.rectTransform.sizeDelta     = new Vector2(card.rectTransform.sizeDelta.x, card.rectTransform.sizeDelta.y / 6);
                streetColour.rectTransform.localPosition = new Vector2(0f, card.rectTransform.sizeDelta.y / 2 - streetColour.rectTransform.sizeDelta.y / 2);
                streetColour.color = new Color(street.Colour.r, street.Colour.g, street.Colour.b, 1);

                title.rectTransform.localPosition = new Vector2(0f, 20f);

                //grays out street if not able to build house in house mode
                if (BuildHouseMode && !street.CanBuildHouse())
                {
                    DisableCard(cardObj);
                }
            }
            else if (property.GetComponent <Utility>() != null || property.GetComponent <RailwayStation>() != null)
            {
                Image icon = new GameObject("Icon").AddComponent <Image>();
                icon.sprite = property.GetComponent <Tile>().Icon;
                icon.rectTransform.SetParent(card.transform);
                icon.rectTransform.localPosition = Vector2.zero;
                icon.rectTransform.sizeDelta     = new Vector2(card.rectTransform.sizeDelta.x * 0.7f, card.rectTransform.sizeDelta.x * 0.7f);
            }
        }
        else
        {
            title.text = "MORTGAGED";
            title.rectTransform.localPosition = Vector3.zero;
        }

        //grays out non-street properties if in house mode or if cant sell house, or if in payment menu and property mortgaged, or can't pay unmortgage cost
        if ((!TradingMode &&
             ((BuildHouseMode && (street == null || street.Mortgaged)) ||
              (!BuildHouseMode && street != null && !street.CanMortagage() && !street.Mortgaged && !street.CanSellHouse()) ||
              (PaymentOptions.enabled == true && property.Mortgaged) ||
              (property.Mortgaged && property.Owner.GetBalance() < property.UnMortgageCost))) ||
            (TradingMode && street != null && street.Houses > 0))
        {
            DisableCard(cardObj);
        }
    }