Пример #1
0
 public static void Load()
 {
     try
     {
         bullets = new BulletInfos();
         UrlDir.UrlConfig[] nodes = GameDatabase.Instance.GetConfigs("BULLET");
         for (int i = 0; i < nodes.Length; i++)
         {
             ConfigNode node = nodes[i].config;
             bullets.Add(
                 new BulletInfo(
                     node.GetValue("name"),
                     float.Parse(node.GetValue("caliber")),
                     float.Parse(node.GetValue("bulletVelocity")),
                     float.Parse(node.GetValue("bulletMass")),
                     Convert.ToBoolean(node.GetValue("explosive")),
                     float.Parse(node.GetValue("tntMass")),
                     float.Parse(node.GetValue("blastPower")),
                     float.Parse(node.GetValue("blastHeat")),
                     float.Parse(node.GetValue("blastRadius")),
                     float.Parse(node.GetValue("apBulletMod")),
                     node.GetValue("bulletDragTypeName")
                     )
                 );
         }
     }
     catch (Exception e)
     {
         Debug.Log("[BDArmory]: Error Loading Bullet Config | " + e.ToString());
     }
 }
Пример #2
0
        public static void Load()
        {
            if (bullets != null)
            {
                return;                  // Only load the bullet defs once on startup.
            }
            bullets = new BulletInfos();
            if (bulletNames == null)
            {
                bulletNames = new HashSet <string>();
            }
            UrlDir.UrlConfig[] nodes = GameDatabase.Instance.GetConfigs("BULLET");
            ConfigNode         node;

            // First locate BDA's default bullet definition so we can fill in missing fields.
            if (defaultBullet == null)
            {
                for (int i = 0; i < nodes.Length; ++i)
                {
                    if (nodes[i].parent.name != "BD_Bullets")
                    {
                        continue;                                       // Ignore other config files.
                    }
                    node = nodes[i].config;
                    if (!node.HasValue("name") || (string)ParseField(nodes[i].config, "name", typeof(string)) != "def")
                    {
                        continue;                                                                                                 // Ignore other configs.
                    }
                    Debug.Log("[BDArmory]: Parsing default bullet definition from " + nodes[i].parent.name);
                    defaultBullet = new BulletInfo(
                        "def",
                        (float)ParseField(node, "caliber", typeof(float)),
                        (float)ParseField(node, "bulletVelocity", typeof(float)),
                        (float)ParseField(node, "bulletMass", typeof(float)),
                        (bool)ParseField(node, "explosive", typeof(bool)),
                        (float)ParseField(node, "tntMass", typeof(float)),
                        (string)ParseField(node, "fuzeType", typeof(string)),
                        (float)ParseField(node, "apBulletMod", typeof(float)),
                        (int)ParseField(node, "subProjectileCount", typeof(int)),
                        (string)ParseField(node, "bulletDragTypeName", typeof(string)),
                        (string)ParseField(node, "projectileColor", typeof(string)),
                        (string)ParseField(node, "startColor", typeof(string)),
                        (bool)ParseField(node, "fadeColor", typeof(bool))
                        );
                    bullets.Add(defaultBullet);
                    bulletNames.Add("def");
                    break;
                }
            }
            if (defaultBullet == null)
            {
                throw new ArgumentException("Failed to find BDArmory's default bullet definition.", "defaultBullet");
            }

            // Now add in the rest of the bullets.
            for (int i = 0; i < nodes.Length; i++)
            {
                string name_ = "";
                try
                {
                    node  = nodes[i].config;
                    name_ = (string)ParseField(node, "name", typeof(string));
                    if (bulletNames.Contains(name_))                                // Avoid duplicates.
                    {
                        if (nodes[i].parent.name != "BD_Bullets" || name_ != "def") // Don't report the default bullet definition as a duplicate.
                        {
                            Debug.LogError("[BDArmory]: Bullet definition " + name_ + " from " + nodes[i].parent.name + " already exists, skipping.");
                        }
                        continue;
                    }
                    Debug.Log("[BDArmory]: Parsing definition of bullet " + name_ + " from " + nodes[i].parent.name);
                    bullets.Add(
                        new BulletInfo(
                            name_,
                            (float)ParseField(node, "caliber", typeof(float)),
                            (float)ParseField(node, "bulletVelocity", typeof(float)),
                            (float)ParseField(node, "bulletMass", typeof(float)),
                            (bool)ParseField(node, "explosive", typeof(bool)),
                            (float)ParseField(node, "tntMass", typeof(float)),
                            (string)ParseField(node, "fuzeType", typeof(string)),
                            (float)ParseField(node, "apBulletMod", typeof(float)),
                            (int)ParseField(node, "subProjectileCount", typeof(int)),
                            (string)ParseField(node, "bulletDragTypeName", typeof(string)),
                            (string)ParseField(node, "projectileColor", typeof(string)),
                            (string)ParseField(node, "startColor", typeof(string)),
                            (bool)ParseField(node, "fadeColor", typeof(bool))
                            )
                        );
                    bulletNames.Add(name_);
                }
                catch (Exception e)
                {
                    Debug.LogError("[BDArmory]: Error Loading Bullet Config '" + name_ + "' | " + e.ToString());
                }
            }
        }