コード例 #1
0
ファイル: House.cs プロジェクト: chaojikugua/CapitalCity
    public override void ReceiveItem(ItemOrder io)
    {
        if (io.type == ItemType.Meal)
        {
            Hunger         -= io.amount;
            FoodQualCurrent = ResourcesDatabase.GetQuality(io.GetItemName());
        }

        else if (io.type == ItemType.Good)
        {
            Goods[io.item] += io.amount;
        }
    }
コード例 #2
0
ファイル: House.cs プロジェクト: chaojikugua/CapitalCity
    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);
    }