示例#1
0
    // Buy/Sell
    public bool makeOperation(CMarketBehaviour.EMarketOperations operation, CResourceBehaviour.EResources resource, double amount)
    {
        bool returnStatus = false;

        switch (operation)
        {
        case CMarketBehaviour.EMarketOperations.Buy:
            if (m_Credits - m_MarketController.GetMarketBehaviour().TryBuy(resource, amount) >= 0)
            {
                m_Credits -= m_MarketController.GetMarketBehaviour().Buy(resource, amount);
                m_EntityInventory[resource] += amount;
                returnStatus = true;
            }
            break;

        case CMarketBehaviour.EMarketOperations.Sell:
            if (m_EntityInventory[resource] - amount >= 0)
            {
                m_Credits += m_MarketController.GetMarketBehaviour().Sell(resource, amount);
                m_EntityInventory[resource] -= amount;
                returnStatus = true;
            }
            break;
        }

        return(returnStatus);
    }
示例#2
0
    Sell(CResourceBehaviour.EResources resource, double amount)
    {
        double sellValue = m_ResourcePrices[resource] * amount;

        UpdatePrice(resource, EMarketOperations.Sell, amount);

        return(sellValue);
    }
示例#3
0
    Buy(CResourceBehaviour.EResources resource, double amount)
    {
        double costValue = m_ResourcePrices[resource] * amount;

        UpdatePrice(resource, EMarketOperations.Buy, amount);

        return(costValue);
    }
示例#4
0
    CreateBuiding(CResourceBehaviour.EResources resourceType)
    {
        // Choose resource type
        m_ResourceType = resourceType;

        // Sets the sprite of parent to be the correct one.
        SpriteRenderer parentSpriteRenderer = GetComponentsInParent <SpriteRenderer>()[0];

        parentSpriteRenderer.sprite = m_Sprites[(int)m_ResourceType];
    }
示例#5
0
 UpdatePrice(CResourceBehaviour.EResources resource, EMarketOperations operation, double amount)
 {
     // If demand goes up the price goes up
     if (operation == EMarketOperations.Buy)
     {
         m_ResourcePrices[resource] += 1.1 * amount;
     }
     // If supply increases the price decreases
     else if (operation == EMarketOperations.Sell)
     {
         m_ResourcePrices[resource] -= 0.9 * amount;
     }
 }
示例#6
0
 // Adds amount to inventory
 public void AddToInventory(CResourceBehaviour.EResources resource, double amount)
 {
     m_EntityInventory[resource] += amount;
 }
示例#7
0
    GetResourceInfo(out CResourceBehaviour.EResources resourceType)
    {
        resourceType = m_ResourceType;

        return(true);
    }
示例#8
0
    TrySell(CResourceBehaviour.EResources resource, double amount)
    {
        double sellValue = m_ResourcePrices[resource] * amount;

        return(sellValue);
    }
示例#9
0
    TryBuy(CResourceBehaviour.EResources resource, double amount)
    {
        double costValue = m_ResourcePrices[resource] * amount;

        return(costValue);
    }