protected void SellStock(RestockSettings restockSettings)
    {
        float totalCost        = GetTotalCost();
        float percentToRestock = restockSettings.percent.Random() / 100f;
        float restockAmount    = totalCost * percentToRestock;
        bool  nothingSold      = false;

        while (restockAmount > 0)
        {
            int origSellIndex    = Random.Range(0, specificItems.Length);
            int currentSellIndex = origSellIndex;
            do
            {
                if (specificItems[currentSellIndex].cost < restockAmount)
                {
                    restockAmount -= specificItems[currentSellIndex].cost;
                    RemoveAt(currentSellIndex);
                    break;
                }
                currentSellIndex = (currentSellIndex + 1) % specificItems.Length;

                if (currentSellIndex == origSellIndex)
                {
                    nothingSold = true;
                }
            }while (currentSellIndex != origSellIndex);

            if (nothingSold)
            {
                break;
            }
        }
    }
    protected override void SetupFromSplitJsonString(string[] splitJsonString)
    {
        name            = splitJsonString[0];
        notes           = splitJsonString[1];
        size            = EnumValue.CreateFromJsonString(splitJsonString[2]);
        restockSettings = RestockSettings.CreateFromJsonString(splitJsonString[3]);

        m_AvailabilityPerShopSizePerStockType  = AvailabilityPerStockTypePerShopSize.Load(splitJsonString[4]);
        m_RestockFrequencyModifiersPerShopSize = RestockFrequencyModifiersPerShopSize.Load(splitJsonString[5]);
        m_ReadyCashPerShopSize = ReadyCashPerShopSize.Load(splitJsonString[6]);
        m_RarityPerCharacterClassPerSpellContainer = RarityPerCharacterClassPerSpellContainer.Load(splitJsonString[7]);
        m_BudgetRangePerPowerLevelPerStockType     = FloatRangePerPowerLevelPerStockType.Load(splitJsonString[8]);
        m_ArmourCollection               = ArmourCollection.Load(splitJsonString[9]);
        m_SpellCollection                = SpellCollection.Load(splitJsonString[10]);
        m_WeaponCollection               = WeaponCollection.Load(splitJsonString[11]);
        m_RingCollection                 = RingCollection.Load(splitJsonString[12]);
        m_RodCollection                  = RodCollection.Load(splitJsonString[13]);
        m_StaffCollection                = StaffCollection.Load(splitJsonString[14]);
        m_WondrousCollection             = WondrousCollection.Load(splitJsonString[15]);
        m_ArmourQualityCollection        = ArmourQualityCollection.Load(splitJsonString[16]);
        m_WeaponQualityCollection        = WeaponQualityCollection.Load(splitJsonString[17]);
        m_WeaponQualityConstraintsMatrix = WeaponQualityConstraintsMatrix.Load(splitJsonString[18]);
        m_ArmourQualityConstraintsMatrix = ArmourQualityConstraintsMatrix.Load(splitJsonString[19]);

        shops = new Shop[splitJsonString.Length - 20];
        for (int i = 0; i < shops.Length; i++)
        {
            shops[i] = Shop.CreateFromJsonString(splitJsonString[i + 20]);
        }
    }
    protected override string ConvertToJsonString(string[] jsonSplitter)
    {
        string jsonString = "";

        jsonString += name + jsonSplitter[0];
        jsonString += notes + jsonSplitter[0];
        jsonString += EnumValue.GetJsonString(size) + jsonSplitter[0];
        jsonString += RestockSettings.GetJsonString(restockSettings) + jsonSplitter[0];

        jsonString += m_AvailabilityPerShopSizePerStockType.name + jsonSplitter[0];
        jsonString += m_RestockFrequencyModifiersPerShopSize.name + jsonSplitter[0];
        jsonString += m_ReadyCashPerShopSize.name + jsonSplitter[0];
        jsonString += m_RarityPerCharacterClassPerSpellContainer.name + jsonSplitter[0];
        jsonString += m_BudgetRangePerPowerLevelPerStockType.name + jsonSplitter[0];
        jsonString += m_ArmourCollection.name + jsonSplitter[0];
        jsonString += m_SpellCollection.name + jsonSplitter[0];
        jsonString += m_WeaponCollection.name + jsonSplitter[0];
        jsonString += m_RingCollection.name + jsonSplitter[0];
        jsonString += m_RodCollection.name + jsonSplitter[0];
        jsonString += m_StaffCollection.name + jsonSplitter[0];
        jsonString += m_WondrousCollection.name + jsonSplitter[0];
        jsonString += m_ArmourQualityCollection.name + jsonSplitter[0];
        jsonString += m_WeaponQualityCollection.name + jsonSplitter[0];
        jsonString += m_WeaponQualityConstraintsMatrix.name + jsonSplitter[0];
        jsonString += m_ArmourQualityConstraintsMatrix.name + jsonSplitter[0];


        for (int i = 0; i < shops.Length; i++)
        {
            jsonString += Shop.GetJsonString(shops[i]) + jsonSplitter[0];
        }

        return(jsonString);
    }
Beispiel #4
0
    public void PassTime(int daysPassed, Settlement settlement)
    {
        int             totalDaysSinceLastRestock = daysPassed + daysSinceLastRestock;
        RestockSettings restockSettings           = settlement.restockSettings;

        int daysUntilRestock = Mathf.FloorToInt(restockSettings.days.Random() * settlement.RestockFrequencyModifiersPerShopSize[size]);

        while (totalDaysSinceLastRestock - daysUntilRestock > 0)
        {
            Restock(restockSettings);
            totalDaysSinceLastRestock -= daysUntilRestock;
            daysUntilRestock           = Mathf.FloorToInt(restockSettings.days.Random() * settlement.RestockFrequencyModifiersPerShopSize[size]);
        }

        daysSinceLastRestock = totalDaysSinceLastRestock;

        totalCash = GetMaxPossibleStockValue() - GetTotalStockValue() + readyCash;
    }
Beispiel #5
0
 protected void Restock(RestockSettings restockSettings)
 {
     if (stockTypes["Armour"])
     {
         specificArmourCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Armour"]);
     }
     if (stockTypes["Potion"])
     {
         specificPotionCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Potion"]);
     }
     if (stockTypes["Ring"])
     {
         specificRingCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Ring"]);
     }
     if (stockTypes["Rod"])
     {
         specificRodCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Rod"]);
     }
     if (stockTypes["Scroll"])
     {
         specificScrollCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Scroll"]);
     }
     if (stockTypes["Staff"])
     {
         specificStaffCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Staff"]);
     }
     if (stockTypes["Wand"])
     {
         specificWandCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Wand"]);
     }
     if (stockTypes["Weapon"])
     {
         specificWeaponCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Weapon"]);
     }
     if (stockTypes["Wondrous"])
     {
         specificWondrousCollection.Restock(restockSettings, m_BudgetRangePerPowerLevelPerStockType["Wondrous"]);
     }
 }
    public void Restock(RestockSettings restockSettings, FloatRangePerPowerLevel perPowerLevelItemBudgetRange)
    {
        SellStock(restockSettings);

        BuyStock(perPowerLevelItemBudgetRange);
    }