Ejemplo n.º 1
0
 public static string getOriginal(this AmmunitionDef def)
 {
     if (originals.TryGetValue(def.GetType(), out Dictionary <string, string> origs) == false)
     {
         return(def.ToJSON());
     }
     if (origs.TryGetValue(def.Description.Id, out string result) == false)
     {
         return(def.ToJSON());
     }
     return(result);
 }
Ejemplo n.º 2
0
        public static bool isWeaponCanUseAmmo(WeaponDef weaponDef, AmmunitionDef ammoDef)
        {
            ExtAmmunitionDef   extAmmo      = CustomAmmoCategories.findExtAmmo(ammoDef.Description.Id);
            CustomAmmoCategory ammoCategory = extAmmo.AmmoCategory;

            if (ammoCategory.BaseCategory == AmmoCategory.NotSet)
            {
                ammoCategory = CustomAmmoCategories.find(ammoDef.Category.ToString());
            }
            ;
            if (ammoCategory.BaseCategory == AmmoCategory.NotSet)
            {
                return(false);
            }
            ;
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weaponDef.Description.Id);

            if (extWeapon.AmmoCategory.BaseCategory != AmmoCategory.NotSet)
            {
                if (extWeapon.AmmoCategory.Index == ammoCategory.Index)
                {
                    return(true);
                }
                ;
            }
            else
            if (weaponDef.AmmoCategory != AmmoCategory.NotSet)
            {
                CustomAmmoCategory weaponAmmoCategory = CustomAmmoCategories.find(weaponDef.AmmoCategory.ToString());
                if ((weaponAmmoCategory.BaseCategory != AmmoCategory.NotSet) && (weaponAmmoCategory.Index == ammoCategory.Index))
                {
                    return(true);
                }
            }
            foreach (var mode in extWeapon.Modes)
            {
                if (mode.Value.AmmoCategory == null)
                {
                    continue;
                }
                ;
                if ((mode.Value.AmmoCategory.BaseCategory != AmmoCategory.NotSet) && (mode.Value.AmmoCategory.Index == ammoCategory.Index))
                {
                    return(true);
                }
                ;
            }
            return(false);
        }
Ejemplo n.º 3
0
 public static void setOriginal(this AmmunitionDef def, string json)
 {
     if (originals.TryGetValue(def.GetType(), out Dictionary <string, string> origs) == false)
     {
         origs = new Dictionary <string, string>();
         originals.Add(def.GetType(), origs);
     }
     if (origs.ContainsKey(def.Description.Id))
     {
         origs[def.Description.Id] = json;
     }
     else
     {
         origs.Add(def.Description.Id, json);
     }
 }
Ejemplo n.º 4
0
        public static void Postfix(AmmunitionDef __instance)
        {
            EffectData[]      effects = CustomAmmoCategories.findExtAmmo(__instance.Description.Id).statusEffects;
            List <EffectData> tmpList = new List <EffectData>();

            CustomAmmoCategoriesLog.Log.LogWrite("Checking on null status effects " + __instance.Description.Id + " " + effects.Length + ".\n");
            foreach (EffectData effect in effects)
            {
                if ((effect.Description != null))
                {
                    if ((effect.Description.Id != null) && (effect.Description.Name != null))
                    {
                        tmpList.Add(effect);
                        continue;
                    }
                    else
                    {
                        if (effect.Description.Id == null)
                        {
                            CustomAmmoCategoriesLog.Log.LogWrite("!Warning! effect id is null " + __instance.Description.Id + ".\n");
                        }
                        if (effect.Description.Name == null)
                        {
                            CustomAmmoCategoriesLog.Log.LogWrite("!Warning! effect name is null " + __instance.Description.Id + ".\n");
                        }
                    }
                }
                else
                {
                    CustomAmmoCategoriesLog.Log.LogWrite("!Warning! effect description is null " + __instance.Description.Id + ".\n");
                }
                CustomAmmoCategoriesLog.Log.LogWrite("!Warning! null status effect detected at ammo " + __instance.Description.Id + ".\n");
            }
            if (tmpList.Count != effects.Length)
            {
                CustomAmmoCategoriesLog.Log.LogWrite("!Warning! null (" + (effects.Length - tmpList.Count) + "/" + effects.Length + ") status effects detected at ammo " + __instance.Description.Id + ".Removing\n");
                CustomAmmoCategories.findExtAmmo(__instance.Description.Id).statusEffects = tmpList.ToArray();
            }
        }
Ejemplo n.º 5
0
        public static bool Prefix(AmmunitionDef __instance, ref string json)
        {
            CustomAmmoCategoriesLog.Log.LogWrite("AmmunitionDef fromJSON ");
            JObject defTemp = JObject.Parse(json);

            CustomAmmoCategoriesLog.Log.LogWrite(defTemp["Description"]["Id"] + "\n");
            CustomAmmoCategory custCat = CustomAmmoCategories.find((string)defTemp["Category"]);

            //CustomAmmoCategories.RegisterAmmunition((string)defTemp["Description"]["Id"], custCat);
            defTemp["Category"] = custCat.BaseCategory.ToString();
            ExtAmmunitionDef extAmmoDef = new ExtAmmunitionDef();

            extAmmoDef.AmmoCategory = custCat;
            if (defTemp["AccuracyModifier"] != null)
            {
                extAmmoDef.AccuracyModifier = (float)defTemp["AccuracyModifier"];
                defTemp.Remove("AccuracyModifier");
            }
            if (defTemp["DamagePerShot"] != null)
            {
                extAmmoDef.DamagePerShot = (float)defTemp["DamagePerShot"];
                defTemp.Remove("DamagePerShot");
            }
            if (defTemp["HeatDamagePerShot"] != null)
            {
                extAmmoDef.HeatDamagePerShot = (float)defTemp["HeatDamagePerShot"];
                defTemp.Remove("HeatDamagePerShot");
            }
            if (defTemp["ProjectilesPerShot"] != null)
            {
                extAmmoDef.ProjectilesPerShot = (int)defTemp["ProjectilesPerShot"];
                defTemp.Remove("ProjectilesPerShot");
            }
            if (defTemp["ShotsWhenFired"] != null)
            {
                extAmmoDef.ShotsWhenFired = (int)defTemp["ShotsWhenFired"];
                defTemp.Remove("ShotsWhenFired");
            }
            if (defTemp["CriticalChanceMultiplier"] != null)
            {
                extAmmoDef.CriticalChanceMultiplier = (float)defTemp["CriticalChanceMultiplier"];
                defTemp.Remove("CriticalChanceMultiplier");
            }
            if (defTemp["AIBattleValue"] != null)
            {
                extAmmoDef.AIBattleValue = (int)defTemp["AIBattleValue"];
                defTemp.Remove("AIBattleValue");
            }
            if (defTemp["MinRange"] != null)
            {
                extAmmoDef.MinRange = (float)defTemp["MinRange"];
                defTemp.Remove("MinRange");
            }
            if (defTemp["MaxRange"] != null)
            {
                extAmmoDef.MaxRange = (float)defTemp["MaxRange"];
                defTemp.Remove("MaxRange");
            }
            if (defTemp["ShortRange"] != null)
            {
                extAmmoDef.ShortRange = (float)defTemp["ShortRange"];
                defTemp.Remove("ShortRange");
            }
            if (defTemp["MediumRange"] != null)
            {
                extAmmoDef.MediumRange = (float)defTemp["MediumRange"];
                defTemp.Remove("MediumRange");
            }
            if (defTemp["LongRange"] != null)
            {
                extAmmoDef.LongRange = (float)defTemp["LongRange"];
                defTemp.Remove("LongRange");
            }
            if (defTemp["ForbiddenRange"] != null)
            {
                extAmmoDef.ForbiddenRange = (float)defTemp["ForbiddenRange"];
                defTemp.Remove("ForbiddenRange");
            }
            if (defTemp["RefireModifier"] != null)
            {
                extAmmoDef.RefireModifier = (int)defTemp["RefireModifier"];
                defTemp.Remove("RefireModifier");
            }
            if (defTemp["Instability"] != null)
            {
                extAmmoDef.Instability = (float)defTemp["Instability"];
                defTemp.Remove("Instability");
            }
            if (defTemp["AttackRecoil"] != null)
            {
                extAmmoDef.AttackRecoil = (int)defTemp["AttackRecoil"];
                defTemp.Remove("AttackRecoil");
            }
            if (defTemp["WeaponEffectID"] != null)
            {
                extAmmoDef.WeaponEffectID = (string)defTemp["WeaponEffectID"];
                defTemp.Remove("WeaponEffectID");
            }
            if (defTemp["EvasivePipsIgnored"] != null)
            {
                extAmmoDef.EvasivePipsIgnored = (float)defTemp["EvasivePipsIgnored"];
                defTemp.Remove("EvasivePipsIgnored");
            }
            if (defTemp["FlatJammingChance"] != null)
            {
                extAmmoDef.FlatJammingChance = (float)defTemp["FlatJammingChance"];
                defTemp.Remove("FlatJammingChance");
            }
            if (defTemp["GunneryJammingBase"] != null)
            {
                extAmmoDef.GunneryJammingBase = (float)defTemp["GunneryJammingBase"];
                defTemp.Remove("GunneryJammingBase");
            }
            if (defTemp["GunneryJammingMult"] != null)
            {
                extAmmoDef.GunneryJammingMult = (float)defTemp["GunneryJammingMult"];
                defTemp.Remove("GunneryJammingMult");
            }
            if (defTemp["IndirectFireCapable"] != null)
            {
                extAmmoDef.IndirectFireCapable = ((bool)defTemp["IndirectFireCapable"] == true) ? TripleBoolean.True : TripleBoolean.False;
                defTemp.Remove("IndirectFireCapable");
            }
            if (defTemp["DirectFireModifier"] != null)
            {
                extAmmoDef.DirectFireModifier = (float)defTemp["DirectFireModifier"];
                defTemp.Remove("DirectFireModifier");
            }
            if (defTemp["AOECapable"] != null)
            {
                extAmmoDef.AOECapable = ((bool)defTemp["AOECapable"] == true) ? TripleBoolean.True : TripleBoolean.False;
                defTemp.Remove("AOECapable");
            }
            if (defTemp["DistantVariance"] != null)
            {
                extAmmoDef.DistantVariance = (float)defTemp["DistantVariance"];
                defTemp.Remove("DistantVariance");
            }
            if (defTemp["AlwaysIndirectVisuals"] != null)
            {
                extAmmoDef.AlwaysIndirectVisuals = ((bool)defTemp["AlwaysIndirectVisuals"] == true) ? TripleBoolean.True : TripleBoolean.False;
                defTemp.Remove("AlwaysIndirectVisuals");
            }
            if (defTemp["DamageMultiplier"] != null)
            {
                extAmmoDef.DamageMultiplier = (float)defTemp["DamageMultiplier"];
                defTemp.Remove("DamageMultiplier");
            }
            if (defTemp["DistantVarianceReversed"] != null)
            {
                extAmmoDef.DistantVarianceReversed = ((bool)defTemp["DistantVarianceReversed"] == true) ? TripleBoolean.True : TripleBoolean.False;
                defTemp.Remove("DistantVarianceReversed");
            }
            if (defTemp["DamageVariance"] != null)
            {
                extAmmoDef.DamageVariance = (float)defTemp["DamageVariance"];
                defTemp.Remove("DamageVariance");
            }
            if (defTemp["HitGenerator"] != null)
            {
                try {
                    extAmmoDef.HitGenerator = (HitGeneratorType)Enum.Parse(typeof(HitGeneratorType), (string)defTemp["HitGenerator"], true);
                } catch (Exception e) {
                    extAmmoDef.HitGenerator = HitGeneratorType.NotSet;
                }
                defTemp.Remove("HitGenerator");
            }
            if (defTemp["statusEffects"] != null)
            {
                if (defTemp["statusEffects"].Type == JTokenType.Array)
                {
                    List <EffectData> tmpList       = new List <EffectData>();
                    JToken            statusEffects = defTemp["statusEffects"];
                    foreach (JObject statusEffect in statusEffects)
                    {
                        EffectData effect = new EffectData();
                        JSONSerializationUtility.FromJSON <EffectData>(effect, statusEffect.ToString());
                        tmpList.Add(effect);
                    }
                    extAmmoDef.statusEffects = tmpList.ToArray();
                }
                //extAmmoDef.statusEffects = JsonConvert.DeserializeObject<EffectData[]>(defTemp["statusEffects"].ToString());
                //JSONSerializationUtility.FromJSON<EffectData[]>(extAmmoDef.statusEffects, defTemp["statusEffects"].ToString());
                //CustomAmmoCategoriesLog.Log.LogWrite(JsonConvert.SerializeObject(extAmmoDef.statusEffects)+"\n");
                defTemp.Remove("statusEffects");
            }
            CustomAmmoCategories.RegisterExtAmmoDef((string)defTemp["Description"]["Id"], extAmmoDef);
            json = defTemp.ToString();
            return(true);
        }