Exemplo n.º 1
0
        public VendorLogic GetOrCreateVendor(string worldId, int npcType)
        {
            var vendors = this.GetOrCreateWorldVendors(worldId);

            if (!vendors.Keys.Contains(npcType))
            {
                vendors[npcType] = VendorLogic.Create(npcType);
            }
            return(vendors[npcType]);
        }
Exemplo n.º 2
0
        public void SaveVendorsForCurrentPlayer(TagCompound tags)
        {
            foreach (var worldVendors in this.VendorWorlds)
            {
                string worldId = worldVendors.Key;
                IDictionary <int, VendorLogic> vendors = worldVendors.Value;

                tags.Set(worldId + "_vendor_count", vendors.Count);
                //if( (DebugHelper.DEBUGMODE & 1) > 0 ) {
                //	ErrorLogger.Log( "  save " + world_id + "_vendor_count: " + vendors.Count );
                //}

                int i = 0;
                foreach (var kv in vendors)
                {
                    if (kv.Key <= 0)
                    {
                        continue;
                    }
                    if (kv.Value == null)
                    {
                        continue;
                    }

                    int         npcType = kv.Key;
                    VendorLogic vendor  = kv.Value;
                    int[]       totalPurchaseTypes, totalSpendingsTypes;
                    float[]     totalPurchases, totalSpendings;

                    vendor.SaveTotalSpendings(out totalPurchaseTypes, out totalSpendingsTypes, out totalPurchases, out totalSpendings);
                    string jsonTotalPurchases = JsonConvert.SerializeObject(totalPurchases);
                    string jsonTotalSpendings = JsonConvert.SerializeObject(totalSpendings);

                    tags.Set(worldId + "_vendor_npc_types_" + i, npcType);
                    tags.Set(worldId + "_vendor_total_purchase_types_" + i, totalPurchaseTypes);
                    tags.Set(worldId + "_vendor_total_spendings_types_" + i, totalSpendingsTypes);
                    tags.Set(worldId + "_vendor_total_purchases_str_" + i, jsonTotalPurchases);
                    tags.Set(worldId + "_vendor_total_spendings_str_" + i, jsonTotalSpendings);

                    //if( (DebugHelper.DEBUGMODE & 1) > 0 ) {
                    //	ErrorLogger.Log( "    save " + world_id + "_vendor_npc_types_" + i + ": " + (int)npc_type );
                    //	ErrorLogger.Log( "    save " + world_id + "_vendor_total_purchase_types_" + i + ": " + String.Join( ",", total_purchase_types ) );
                    //	ErrorLogger.Log( "    save " + world_id + "_vendor_total_spendings_types_" + i + ": " + String.Join( ",", total_spendings_types ) );
                    //	ErrorLogger.Log( "    save " + world_id + "_vendor_total_purchases_" + i + ": " + json_total_purchases );
                    //	ErrorLogger.Log( "    save " + world_id + "_vendor_total_spendings_" + i + ": " + json_total_spendings );
                    //}
                    i++;
                }
            }
        }
Exemplo n.º 3
0
        ////////////////

        public void LoadVendorsForCurrentPlayer(CapitalismMod mymod, TagCompound tags, string worldId)
        {
            try {
                int vendorCount = tags.GetInt(worldId + "_vendor_count");

                IDictionary <int, VendorLogic> vendors;
                if (this.VendorWorlds.Keys.Contains(worldId) && this.VendorWorlds[worldId] != null)
                {
                    vendors = this.VendorWorlds[worldId];
                }
                else
                {
                    vendors = this.VendorWorlds[worldId] = new Dictionary <int, VendorLogic>(vendorCount);
                }

                for (int i = 0; i < vendorCount; i++)
                {
                    if (!tags.ContainsKey(worldId + "_vendor_npc_types_" + i))
                    {
                        continue;
                    }

                    int    npcType             = tags.GetInt(worldId + "_vendor_npc_types_" + i);
                    int[]  totalPurchaseTypes  = tags.GetIntArray(worldId + "_vendor_total_purchase_types_" + i);
                    int[]  totalSpendingsTypes = tags.GetIntArray(worldId + "_vendor_total_spendings_types_" + i);
                    string jsonTotalPurchases  = tags.GetString(worldId + "_vendor_total_purchases_str_" + i);
                    string jsonTotalSpendings  = tags.GetString(worldId + "_vendor_total_spendings_str_" + i);

                    float[] totalPurchases = JsonConvert.DeserializeObject <float[]>(jsonTotalPurchases);
                    float[] totalSpendings = JsonConvert.DeserializeObject <float[]>(jsonTotalSpendings);

                    //if( (DebugHelper.DEBUGMODE & 1) > 0 ) {
                    //	ErrorLogger.Log( "    load " + world_id + "_vendor_npc_types_" + i + ": " + npc_type );
                    //	ErrorLogger.Log( "    load " + world_id + "_vendor_total_purchase_types_" + i + ": " + string.Join( ",", total_purchase_types ) );
                    //	ErrorLogger.Log( "    load " + world_id + "_vendor_total_spendings_types_" + i + ": " + string.Join( ",", total_spendings_types ) );
                    //	ErrorLogger.Log( "    load " + world_id + "_vendor_total_purchases_str_" + i + ": " + json_total_purchases );
                    //	ErrorLogger.Log( "    load " + world_id + "_vendor_total_spendings_str_" + i + ": " + json_total_spendings );
                    //}

                    vendors[npcType] = VendorLogic.Create(npcType);
                    if (vendors[npcType] != null)
                    {
                        vendors[npcType].LoadTotalPurchases(totalPurchaseTypes, totalSpendingsTypes, totalPurchases, totalSpendings);
                    }
                }
            } catch (Exception e) {
                LogHelpers.Warn(e.ToString());
                this.VendorWorlds = new Dictionary <string, IDictionary <int, VendorLogic> >();
            }
        }
Exemplo n.º 4
0
        ////////////////

        public float GetPriceOf(int itemType)
        {
            // Register the initial base price of an item once and for all
            if (!this.BasePrices.Keys.Contains(itemType))
            {
                Item item = new Item();
                item.SetDefaults(itemType);
                this.BasePrices[itemType] = item.value;
            }
            if (!this.TotalSpendings.Keys.Contains(itemType))
            {
                this.TotalPurchases[itemType] = 0;
                this.TotalSpendings[itemType] = 0;
            }

            long  basePrice      = this.BasePrices[itemType];
            float totalPurchases = this.TotalPurchases[itemType];
            float totalSpendings = this.TotalSpendings[itemType];

            return(VendorLogic.ComputePrice((float)basePrice, totalPurchases, totalSpendings));
        }