// 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); }
Sell(CResourceBehaviour.EResources resource, double amount) { double sellValue = m_ResourcePrices[resource] * amount; UpdatePrice(resource, EMarketOperations.Sell, amount); return(sellValue); }
Buy(CResourceBehaviour.EResources resource, double amount) { double costValue = m_ResourcePrices[resource] * amount; UpdatePrice(resource, EMarketOperations.Buy, amount); return(costValue); }
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]; }
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; } }
// Adds amount to inventory public void AddToInventory(CResourceBehaviour.EResources resource, double amount) { m_EntityInventory[resource] += amount; }
GetResourceInfo(out CResourceBehaviour.EResources resourceType) { resourceType = m_ResourceType; return(true); }
TrySell(CResourceBehaviour.EResources resource, double amount) { double sellValue = m_ResourcePrices[resource] * amount; return(sellValue); }
TryBuy(CResourceBehaviour.EResources resource, double amount) { double costValue = m_ResourcePrices[resource] * amount; return(costValue); }