Ejemplo 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]);
        }
Ejemplo n.º 2
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> >();
            }
        }