Beispiel #1
0
        /// <summary>
        /// Override to the normal config parser, so we can load the resources
        /// </summary>
        /// <param name="cfgNode"></param>
        /// <returns></returns>
        internal override KKFacility ParseConfig(ConfigNode cfgNode)
        {
            base.ParseConfig(cfgNode);
            tradedResources = new HashSet <TradedResource>();

            string resourceName = null;
            PartResourceDefinition foundResource  = null;
            TradedResource         tradedResource = null;


            foreach (ConfigNode resourceNode in cfgNode.GetNodes("TradedResource"))
            {
                resourceName  = resourceNode.GetValue("ResourceName");
                foundResource = PartResourceLibrary.Instance.GetDefinition(resourceName);
                if (foundResource == null)
                {
                    Log.UserWarning("Resource not found: " + resourceName);
                }
                else
                {
                    tradedResource = new TradedResource()
                    {
                        resource       = foundResource,
                        multiplierBuy  = float.Parse(resourceNode.GetValue("MultiplierBuy")),
                        multiplierSell = float.Parse(resourceNode.GetValue("MultiplierSell")),
                        canBeBought    = bool.Parse(resourceNode.GetValue("CanBeBought")),
                        canBeSold      = bool.Parse(resourceNode.GetValue("CanBeSold"))
                    };
                    tradedResources.Add(tradedResource);
                }
            }
            return(this);
        }
Beispiel #2
0
        /// <summary>
        /// Override to the normal config parser, so we can load the resources
        /// </summary>
        /// <param name="cfgNode"></param>
        /// <returns></returns>
        internal override KKFacility ParseConfig(ConfigNode cfgNode)
        {
            base.ParseConfig(cfgNode);
            tradedResByID   = new Dictionary <int, TradedResource>();
            tradedResources = new Dictionary <string, TradedResource>();

            string resourceName = null;
            PartResourceDefinition foundResource  = null;
            TradedResource         tradedResource = null;


            foreach (ConfigNode resourceNode in cfgNode.GetNodes("TradedResource"))
            {
                resourceName  = resourceNode.GetValue("ResourceName");
                foundResource = PartResourceLibrary.Instance.GetDefinition(resourceName);
                if (foundResource == null)
                {
                    Log.UserWarning("Resource not found: " + resourceName);
                }
                else
                {
                    double multiplierBuy;
                    double multiplierSell;
                    bool   canBeBought;
                    bool   canBeSold;

                    double.TryParse(resourceNode.GetValue("MultiplierBuy"), out multiplierBuy);
                    double.TryParse(resourceNode.GetValue("MultiplierSell"), out multiplierSell);
                    bool.TryParse(resourceNode.GetValue("CanBeBought"), out canBeBought);
                    bool.TryParse(resourceNode.GetValue("CanBeSold"), out canBeSold);
                    tradedResource = new TradedResource()
                    {
                        resource       = foundResource,
                        multiplierBuy  = multiplierSell,
                        multiplierSell = multiplierSell,
                        canBeBought    = canBeBought,
                        canBeSold      = canBeSold
                    };
                    AddResource(tradedResource);
                }
            }
            return(this);
        }
Beispiel #3
0
 public void RemoveResource(TradedResource resource)
 {
     tradedResByID.Remove(resource.resource.id);
     tradedResources.Remove(resource.resource.name);
 }
Beispiel #4
0
 public void AddResource(TradedResource resource)
 {
     tradedResByID[resource.resource.id]     = resource;
     tradedResources[resource.resource.name] = resource;
 }