public static float getWeaponForbiddenRange(Weapon weapon)
        {
            if (CustomAmmoCategories.Settings.forbiddenRangeEnable == false)
            {
                return(0f);
            }
            ;
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);
            float        result    = 0f;

            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName))
            {
                string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                result += CustomAmmoCategories.findExtAmmo(ammoId).ForbiddenRange;
            }
            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName))
            {
                string modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
                if (extWeapon.Modes.ContainsKey(modeId))
                {
                    result += extWeapon.Modes[modeId].ForbiddenRange;
                }
            }
            return(result);
        }
        public static float getWeaponDistantVariance(Weapon weapon)
        {
            float result = 0;

            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
            {
                string           ammoId  = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId);
                result += extAmmo.DistantVariance;
            }
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            if (extWeapon.Modes.Count > 0)
            {
                string modeId = "";
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true)
                {
                    modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
                }
                else
                {
                    modeId = extWeapon.baseModeId;
                }
                if (extWeapon.Modes.ContainsKey(modeId))
                {
                    result += extWeapon.Modes[modeId].DistantVariance;
                }
            }
            return(result);
        }
Exemple #3
0
        public static HitGeneratorType getHitGenerator(Weapon weapon)
        {
            HitGeneratorType result = HitGeneratorType.NotSet;

            if (weapon.weaponDef.ComponentTags.Contains("wr-clustered_shots"))
            {
                result = HitGeneratorType.Individual;
            }
            if (result == HitGeneratorType.NotSet)
            {
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true)
                {
                    string       modeId    = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
                    ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);
                    if (extWeapon.Modes.ContainsKey(modeId))
                    {
                        result = extWeapon.Modes[modeId].HitGenerator;
                    }
                }
            }
            if (result == HitGeneratorType.NotSet)
            {
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
                {
                    string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                    result = CustomAmmoCategories.findExtAmmo(ammoId).HitGenerator;
                }
            }
            if (result == HitGeneratorType.NotSet)
            {
                switch (weapon.Type)
                {
                case WeaponType.Autocannon:
                case WeaponType.Gauss:
                case WeaponType.Laser:
                case WeaponType.PPC:
                case WeaponType.Flamer:
                case WeaponType.Melee:
                    result = HitGeneratorType.Individual;
                    break;

                case WeaponType.LRM:
                    result = HitGeneratorType.Cluster;
                    break;

                case WeaponType.SRM:
                    result = HitGeneratorType.Individual;
                    break;

                case WeaponType.MachineGun:
                    result = HitGeneratorType.Individual;
                    break;

                default:
                    result = HitGeneratorType.Individual;
                    break;
                }
            }
            return(result);
        }
        public static bool getWeaponDamageOnJamming(Weapon weapon)
        {
            TripleBoolean result    = TripleBoolean.NotSet;
            ExtWeaponDef  extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            if (extWeapon.Modes.Count > 0)
            {
                string modeId = "";
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true)
                {
                    modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
                }
                else
                {
                    modeId = extWeapon.baseModeId;
                }
                if (extWeapon.Modes.ContainsKey(modeId))
                {
                    result = extWeapon.Modes[modeId].DamageOnJamming;
                }
            }
            if (result == TripleBoolean.NotSet)
            {
                result = extWeapon.DamageOnJamming;
            }
            return(result == TripleBoolean.True);
        }
Exemple #5
0
        public static bool getWeaponAlwaysIndirectVisuals(Weapon weapon)
        {
            bool result = false;

            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
            {
                string           CurrentAmmoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                ExtAmmunitionDef extAmmoDef    = CustomAmmoCategories.findExtAmmo(CurrentAmmoId);
                if (extAmmoDef.AlwaysIndirectVisuals != TripleBoolean.NotSet)
                {
                    result = (extAmmoDef.AlwaysIndirectVisuals == TripleBoolean.True);
                }
            }
            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true)
            {
                ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);
                string       modeId    = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
                if (extWeapon.Modes.ContainsKey(modeId))
                {
                    WeaponMode mode = extWeapon.Modes[modeId];
                    if (mode.AlwaysIndirectVisuals != TripleBoolean.NotSet)
                    {
                        result = (mode.AlwaysIndirectVisuals == TripleBoolean.True);
                    }
                }
            }
            return(result);
        }
        public static void applyWeaponAmmoMode(Weapon weapon, string modeId, string ammoId)
        {
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            CustomAmmoCategoriesLog.Log.LogWrite("applyWeaponAmmoMode(" + weapon.defId + "," + modeId + "," + ammoId + ")\n");
            if (extWeapon.Modes.ContainsKey(modeId))
            {
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == false)
                {
                    weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.WeaponModeStatisticName, modeId);
                }
                else
                {
                    weapon.StatCollection.Set <string>(CustomAmmoCategories.WeaponModeStatisticName, modeId);
                }
            }
            else
            {
                CustomAmmoCategoriesLog.Log.LogWrite("WARNING! " + weapon.defId + " has no mode " + modeId + "\n", true);
            }
            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false)
            {
                weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.AmmoIdStatName, ammoId);
            }
            else
            {
                weapon.StatCollection.Set <string>(CustomAmmoCategories.AmmoIdStatName, ammoId);
            }
        }
        public static bool getWeaponDistantVarianceReversed(Weapon weapon)
        {
            TripleBoolean result    = TripleBoolean.NotSet;
            ExtWeaponDef  extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            if (extWeapon.Modes.Count > 0)
            {
                string modeId = "";
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true)
                {
                    modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
                }
                else
                {
                    modeId = extWeapon.baseModeId;
                }
                if (extWeapon.Modes.ContainsKey(modeId))
                {
                    result = extWeapon.Modes[modeId].DistantVarianceReversed;
                }
            }
            if (result == TripleBoolean.NotSet)
            {
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
                {
                    string           ammoId  = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                    ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId);
                    result = extAmmo.DistantVarianceReversed;
                }
            }
            return(result == TripleBoolean.True);
        }
Exemple #8
0
        public static List <CustomAmmoCategory> getWeaponAmmoCategories(Weapon weapon)
        {
            List <CustomAmmoCategory> result = new List <CustomAmmoCategory>();
            ExtWeaponDef extWeapon           = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            if (weapon.AmmoCategory != AmmoCategory.NotSet)
            {
                if (extWeapon.AmmoCategory.BaseCategory == weapon.AmmoCategory)
                {
                    result.Add(extWeapon.AmmoCategory);
                }
                else
                {
                    result.Add(CustomAmmoCategories.find(weapon.AmmoCategory.ToString()));
                }
            }
            foreach (var mode in extWeapon.Modes)
            {
                if (mode.Value.AmmoCategory == null)
                {
                    continue;
                }
                ;
                if (mode.Value.AmmoCategory.BaseCategory != AmmoCategory.NotSet)
                {
                    result.Add(mode.Value.AmmoCategory);
                }
                ;
            }
            return(result);
        }
Exemple #9
0
        public static bool isWeaponCanShootNoAmmo(WeaponDef weaponDef)
        {
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weaponDef.Description.Id);

            if (weaponDef.AmmoCategory == AmmoCategory.NotSet)
            {
                return(true);
            }
            ;
            if (extWeapon.Modes.Count <= 0)
            {
                return(false);
            }
            ;
            foreach (var mode in extWeapon.Modes)
            {
                if (mode.Value.AmmoCategory == null)
                {
                    continue;
                }
                ;
                if (mode.Value.AmmoCategory.BaseCategory == AmmoCategory.NotSet)
                {
                    return(true);
                }
                ;
            }
            return(false);
        }
        public static float getWeaponFlatJammingChance(Weapon weapon)
        {
            float result  = 0;
            float mult    = 0;
            float baseval = 0f;

            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
            {
                string           ammoId  = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId);
                result += extAmmo.FlatJammingChance;
                mult   += extAmmo.GunneryJammingMult;
                if (extAmmo.GunneryJammingBase > 0)
                {
                    baseval = extAmmo.GunneryJammingBase;
                }
                ;
            }
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            result += extWeapon.FlatJammingChance;
            mult   += extWeapon.GunneryJammingMult;
            if ((extWeapon.GunneryJammingBase > 0) && (baseval == 0f))
            {
                baseval = extWeapon.GunneryJammingBase;
            }
            ;
            if (extWeapon.Modes.Count > 0)
            {
                string modeId = "";
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true)
                {
                    modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
                }
                else
                {
                    modeId = extWeapon.baseModeId;
                }
                if (extWeapon.Modes.ContainsKey(modeId))
                {
                    result += extWeapon.Modes[modeId].FlatJammingChance;
                    mult   += extWeapon.Modes[modeId].GunneryJammingMult;
                    if ((extWeapon.Modes[modeId].GunneryJammingBase > 0) && (baseval == 0f))
                    {
                        baseval = extWeapon.Modes[modeId].GunneryJammingBase;
                    }
                    ;
                }
            }
            if (weapon.parent != null)
            {
                if (baseval == 0f)
                {
                    baseval = 5f;
                }
                result += ((baseval - weapon.parent.SkillGunnery) * mult);
            }
            return(result);
        }
        public static HashSet <string> getWeaponAvaibleAmmoForMode(Weapon weapon, string modeId)
        {
            HashSet <string>   result       = new HashSet <string>();
            CustomAmmoCategory ammoCategory = CustomAmmoCategories.find(weapon.AmmoCategory.ToString());
            ExtWeaponDef       extWeapon    = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            if (extWeapon.AmmoCategory.BaseCategory == weapon.AmmoCategory)
            {
                ammoCategory = extWeapon.AmmoCategory;
            }
            if (extWeapon.Modes.Count < 1)
            {
                CustomAmmoCategoriesLog.Log.LogWrite("WARNING! " + weapon.defId + " has no modes. Even base mode. This means something is very very wrong\n", true);
                return(result);
            }
            if (extWeapon.Modes.ContainsKey(modeId) == false)
            {
                CustomAmmoCategoriesLog.Log.LogWrite("WARNING! " + weapon.defId + " has no mode " + modeId + ".\n", true);
                return(result);
            }
            WeaponMode weaponMode = extWeapon.Modes[modeId];

            if (weaponMode.AmmoCategory.Index != ammoCategory.Index)
            {
                ammoCategory = weaponMode.AmmoCategory;
            }
            ;
            if (ammoCategory.Index == CustomAmmoCategories.NotSetCustomAmmoCategoty.Index)
            {
                result.Add(""); return(result);
            }
            ;
            foreach (AmmunitionBox box in weapon.ammoBoxes)
            {
                if (box.IsFunctional == false)
                {
                    continue;
                }
                if (box.CurrentAmmo <= 0)
                {
                    continue;
                }
                CustomAmmoCategory boxAmmoCategory = CustomAmmoCategories.getAmmoAmmoCategory(box.ammoDef);
                if (boxAmmoCategory.Index == ammoCategory.Index)
                {
                    if (result.Contains(box.ammoDef.Description.Id) == false)
                    {
                        result.Add(box.ammoDef.Description.Id);
                    }
                }
            }
            return(result);
        }
Exemple #12
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);
        }
Exemple #13
0
        public static CustomAmmoCategory getWeaponCustomAmmoCategory(Weapon weapon)
        {
            WeaponMode mode = CustomAmmoCategories.getWeaponMode(weapon);

            if (mode.AmmoCategory == null)
            {
                ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);
                if (extWeapon.AmmoCategory.BaseCategory != weapon.AmmoCategory)
                {
                    return(CustomAmmoCategories.find(weapon.AmmoCategory.ToString()));
                }
                return(extWeapon.AmmoCategory);
            }
            return(mode.AmmoCategory);
        }
        public static float getDirectFireModifier(Weapon weapon)
        {
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.weaponDef.Description.Id);
            float        result    = extWeapon.DirectFireModifier;

            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName))
            {
                string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                result += CustomAmmoCategories.findExtAmmo(ammoId).DirectFireModifier;
            }
            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName))
            {
                string modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
                if (extWeapon.Modes.ContainsKey(modeId))
                {
                    result += extWeapon.Modes[modeId].DirectFireModifier;
                }
            }
            return(result);
        }
Exemple #15
0
        public static WeaponCategory isWeaponUseInMelee(Weapon weapon)
        {
            if (weapon.Category != WeaponCategory.AntiPersonnel)
            {
                return(weapon.Category);
            }
            ;
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            if (extWeapon.NotUseInMelee != TripleBoolean.True)
            {
                return(weapon.Category);
            }
            ;
            switch (weapon.Type)
            {
            case WeaponType.AMS: return(WeaponCategory.AMS);

            case WeaponType.Autocannon: return(WeaponCategory.Ballistic);

            case WeaponType.Flamer: return(WeaponCategory.Energy);

            case WeaponType.Gauss: return(WeaponCategory.Ballistic);

            case WeaponType.Laser: return(WeaponCategory.Energy);

            case WeaponType.LRM: return(WeaponCategory.Missile);

            case WeaponType.MachineGun: return(WeaponCategory.Ballistic);

            case WeaponType.Melee: return(WeaponCategory.Melee);

            case WeaponType.NotSet: return(WeaponCategory.NotSet);

            case WeaponType.PPC: return(WeaponCategory.Energy);

            case WeaponType.SRM: return(WeaponCategory.Missile);

            default: return(WeaponCategory.NotSet);
            }
        }
        public static List <DamagePredictRecord> getWeaponDamagePredict(AbstractActor unit, ICombatant target, Weapon weapon)
        {
            List <DamagePredictRecord> result = new List <DamagePredictRecord>();
            ExtWeaponDef extWeapon            = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            if (extWeapon.Modes.Count < 1)
            {
                CustomAmmoCategoriesLog.Log.LogWrite("WARNING! " + weapon.defId + " has no modes. Even base mode. This means something is very very wrong\n", true);
                return(result);
            }
            string currentMode = extWeapon.baseModeId;

            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true)
            {
                currentMode = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>();
            }
            string currentAmmo = "";

            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
            {
                currentAmmo = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
            }
            foreach (var mode in extWeapon.Modes)
            {
                HashSet <string> ammos        = CustomAmmoCategories.getWeaponAvaibleAmmoForMode(weapon, mode.Value.Id);
                List <int>       hitLocations = null;
                float            AverageArmor = float.NaN;
                foreach (var ammo in ammos)
                {
                    DamagePredictRecord record = new DamagePredictRecord(ammo, mode.Value.Id);
                    CustomAmmoCategories.fillWeaponPredictRecord(ref record, unit, target, weapon, ref hitLocations, ref AverageArmor);
                    result.Add(record);
                }
            }
            CustomAmmoCategories.applyWeaponAmmoMode(weapon, currentMode, currentAmmo);
            return(result);
        }
        public static bool getWeaponDisabledClustering(Weapon weapon)
        {
            ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId);

            return(extWeapon.DisableClustering == TripleBoolean.True);
        }