Exemplo n.º 1
0
    private void TradingDecision(bool aiIsTrader)
    {
        //goes back if AI has made enough offers this turn
        if (aiIsTrader && offers >= MAX_OFFERS_PER_TURN)
        {
            Click(TradingSystem.Back);
        }

        //AI will accept the trade if it gains more than it loses
        uint aiVal    = TradingVal(aiIsTrader);
        uint otherVal = TradingVal(!aiIsTrader);

        if (otherVal > aiVal)
        {
            Click(TradingSystem.Accept);
            return;
        }
        //add other's properties to increase value gained by AI
        foreach (Property property in NotOffered(!aiIsTrader))
        {
            TradingSystem.ToggleCardInOffer(property);
            otherVal = TradingSystem.GetTradingValue(Offered(!aiIsTrader));
            if (otherVal >= aiVal)
            {
                Click(TradingSystem.Offer);
                offers++;
                return;
            }
        }

        //get ai cards currently on offer - we will modify the list in trading system while looping through it so
        //we need a clone
        List <Property> aiOfferClone = new List <Property>();

        foreach (Property property in Offered(aiIsTrader))
        {
            aiOfferClone.Add(property);
        }

        //if AI still does not gain enough it removes its properties from trade until it gains enough
        if (aiVal >= otherVal)
        {
            foreach (Property property in aiOfferClone)
            {
                TradingSystem.ToggleCardInOffer(property);
                aiVal = TradingSystem.GetTradingValue(Offered(aiIsTrader));
                if (aiVal <= otherVal)
                {
                    Click(TradingSystem.Offer);
                    offers++;
                    return;
                }
            }
        }
    }
Exemplo n.º 2
0
    //mortgage
    public override void ClickUI()
    {
        base.ClickUI();

        if (!MenuManager.TradingMode)
        {
            Street street = property.GetComponent <Street>();
            if (!MenuManager.BuildHouseMode)
            {
                if (property.CanMortagage())
                {
                    property.Mortgage();
                }
                else if (street != null && street.CanSellHouse())
                {
                    street.SellHouse();
                }
                //can only unmortgage if player does not need to pay anything
                else if (property.Mortgaged && MenuManager.PaymentOptions.enabled == false)
                {
                    property.UnMortgage();
                }
            }
            else if (MenuManager.BuildHouseMode)
            {
                if (street != null)
                {
                    street.BuildHouse();
                }
            }
            return;
        }

        //check if AI is currently trading, and disable clicking if it is
        if ((TradingSystem.CounterOfferInProgress && TradingSystem.Tradee.gameObject.GetComponent <AI>() != null) ||
            (!TradingSystem.CounterOfferInProgress && GameManager.CurrentPlayer.gameObject.GetComponent <AI>() != null))
        {
            return;
        }

        TradingSystem.ToggleCardInOffer(property);
    }