public void SellItem(House house, int item, ItemType type, int amountStored) { ItemOrder willBuy = house.WillBuy(item, type, amountStored); if (willBuy == null) { return; } //subtract from house's savings, earn revenue house.Savings -= willBuy.ExchangeValue(); money.GainFromLocalSales(willBuy.ExchangeValue(), willBuy.type); //add to house's inventory, subtract from market's inventory house.ReceiveItem(willBuy); Origin.RemoveItem(willBuy); }
public float ValueAddedToProduction(int stockpile) { int materialAmount = GetDeteriorationPerCycle(stockpile); int fuelAmount = (int)((float)stockpile * fuelPer100 / 100f); ItemOrder f = new ItemOrder(materialAmount, (int)material, ItemType.Resource); ItemOrder c = new ItemOrder(fuelAmount, (int)fuel, ItemType.Resource); Debug.Log(f.ExchangeValue() + " " + f); float value = f.ExchangeValue(); if (fuel != ResourceType.END) //only add value for fuel if it exists { value += c.ExchangeValue(); } return(value); }
private void Update() { float baseDays = ResourcesDatabase.GetBaseDays(ItemName); float localProductivity = ProductivityController.GetAverageProductivityHere(ItemName); float globalProductivity = ProductivityController.GetAverageProductivityEverywhere(ItemName); daysWorldWide.text = Mathf.RoundToInt(baseDays / globalProductivity) + " days"; daysLocal.text = localProductivity > 0 ? "(" + Mathf.RoundToInt(baseDays / localProductivity) + " days here)" : "(??? days here)"; ItemOrder io = new ItemOrder(100, ItemName); valueLabel.text = MoneyController.symbol + io.ExchangeValue().ToString("n2"); }
public ItemOrder WillBuyMeal(int item, int amountStored) { //if you don't want anything, stop if (foodQualWant == Quality.None) { return(null); } //if this food is not high enough quality and we're not desperate enough, don't buy if (!WillAcceptFoodTypes(ResourcesDatabase.GetQuality(Enums.GetItemName(item, ItemType.Meal)))) { return(null); } int delta = Hunger; //if we don't have that much food, sell as much as we can if (amountStored < delta) { delta = amountStored; } ItemOrder io = new ItemOrder(delta, item, ItemType.Meal); //if house cannot afford, find the largest amount it can buy for the smallest price if (io.ExchangeValue() > Savings) { float priceOfOne = ResourcesDatabase.GetBasePrice(new ItemOrder(1, item, ItemType.Meal)); int smallestAmount = (int)(Savings / priceOfOne); int smallestAmountWantToBuy = (int)(0.25f * delta); if (smallestAmount <= smallestAmountWantToBuy) { return(null); } io.amount = smallestAmount; } return(io); }
private void Start() { string itemName = order.GetItemDisplayName(); desc.text = order.amount + " " + itemName + " for " + MoneyController.symbol + order.ExchangeValue().ToString("n2"); Sprite spr = ResourcesDatabase.GetSprite(itemName); if (spr != null) { image.sprite = spr; } UpdateButton(trade.ContainsDeal(order)); }
public ItemOrder WillBuyGood(int item, int amountStored) { bool wantsToBuy = false; //check the wanted good first if there is one if (goodWanted != GoodType.END) { //only proceed if the good considered is the good that this house wants if ((int)goodWanted == item) { wantsToBuy = true; } } //now we're going to check the same for each good that we need if we don't want it to evolve // if we don't need this good, don't proceed if (!wantsToBuy) { foreach (GoodType good in goodsNeeded) { if ((int)good == item) { wantsToBuy = true; } } } //if we don't want this good, return null if (!wantsToBuy) { return(null); } //the smallest amount we want to buy is 1 unit, and the most we can have is 2 * houseSize // if the vendor has less goods than we want, match that int delta = GoodsMax - Goods[item]; if (amountStored < delta) { delta = amountStored; } ItemOrder io = new ItemOrder(delta, item, ItemType.Good); //if house cannot afford, find the largest amount it can buy for the smallest price if (io.ExchangeValue() > Savings) { float priceOfOne = ResourcesDatabase.GetBasePrice(new ItemOrder(1, item, ItemType.Good)); int smallestAmount = (int)(Savings / priceOfOne); int smallestAmountWantToBuy = (int)(0.25f * delta); if (smallestAmount <= smallestAmountWantToBuy) { return(null); } io.amount = smallestAmount; } return(io); }