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 void AddJam(AbstractActor actor, Weapon weapon)
 {
     if (CustomAmmoCategories.getWeaponDamageOnJamming(weapon) == false)
     {
         if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.JammedWeaponStatisticName) == false)
         {
             weapon.StatCollection.AddStatistic <bool>(CustomAmmoCategories.JammedWeaponStatisticName, false);
         }
         weapon.StatCollection.Set <bool>(CustomAmmoCategories.JammedWeaponStatisticName, true);
         weapon.StatCollection.Set <bool>(CustomAmmoCategories.TemporarilyDisabledStatisticName, true);
         actor.Combat.MessageCenter.PublishMessage(
             new AddSequenceToStackMessage(
                 new ShowActorInfoSequence(actor, $"{weapon.Name} Jammed!", FloatieMessage.MessageNature.Debuff,
                                           true)));
     }
     else
     {
         var isDestroying = weapon.DamageLevel != ComponentDamageLevel.Functional;
         var damageLevel  = isDestroying ? ComponentDamageLevel.Destroyed : ComponentDamageLevel.Penalized;
         var fakeHit      = new WeaponHitInfo(-1, -1, -1, -1, string.Empty, string.Empty, -1, null, null, null, null, null, null, null, AttackDirection.None, Vector2.zero, null);
         weapon.DamageComponent(fakeHit, damageLevel, true);
         var message = isDestroying
     ? $"{weapon.Name} misfire: Destroyed!"
     : $"{weapon.Name} misfire: Damaged!";
         actor.Combat.MessageCenter.PublishMessage(
             new AddSequenceToStackMessage(
                 new ShowActorInfoSequence(actor, message, FloatieMessage.MessageNature.Debuff, true)));
     }
 }
Beispiel #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);
        }
Beispiel #4
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 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);
        }
        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 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);
        }
        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);
        }
        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 void SetWeaponAmmo(Weapon weapon, string ammoId)
 {
     if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false)
     {
         weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.AmmoIdStatName, ammoId);
     }
     else
     {
         weapon.StatCollection.Set <string>(CustomAmmoCategories.AmmoIdStatName, ammoId);
     }
 }
Beispiel #11
0
        public static int getWeaponAttackRecoil(Weapon weapon)
        {
            CustomAmmoCategoriesLog.Log.LogWrite("getWeaponAttackRecoil " + weapon.UIName + "\n");
            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false)
            {
                CustomAmmoCategoriesLog.Log.LogWrite("  weapon has no ammo\n");
                return(weapon.weaponDef.AttackRecoil);
            }
            string           ammoId  = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
            ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId);

            CustomAmmoCategoriesLog.Log.LogWrite("  modified AttackRecoil\n");
            return(weapon.weaponDef.AttackRecoil + extAmmo.AttackRecoil);
        }
Beispiel #12
0
 public static void AddCooldown(AbstractActor actor, Weapon weapon)
 {
     if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.CooldownWeaponStatisticName) == false)
     {
         weapon.StatCollection.AddStatistic <int>(CustomAmmoCategories.CooldownWeaponStatisticName, 0);
     }
     if (CustomAmmoCategories.getWeaponCooldown(weapon) > 0)
     {
         weapon.StatCollection.Set <int>(CustomAmmoCategories.CooldownWeaponStatisticName, CustomAmmoCategories.getWeaponCooldown(weapon));
         weapon.StatCollection.Set <bool>(CustomAmmoCategories.TemporarilyDisabledStatisticName, true);
         actor.Combat.MessageCenter.PublishMessage(
             new AddSequenceToStackMessage(
                 new ShowActorInfoSequence(actor, $"{weapon.Name} Cooldown!", FloatieMessage.MessageNature.Debuff,
                                           true)));
     }
 }
        public static void switchToMostClusterAmmo(Weapon weapon)
        {
            if (weapon.ammoBoxes.Count == 0)
            {
                return;
            }
            int    ClusterShot = 0;
            string ammoId      = "";

            for (int index = 0; index < weapon.ammoBoxes.Count; ++index)
            {
                if (weapon.ammoBoxes[index].CurrentAmmo <= 0)
                {
                    continue;
                }
                if (weapon.ammoBoxes[index].IsFunctional == false)
                {
                    continue;
                }
                ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(weapon.ammoBoxes[index].ammoDef.Description.Id);
                int ammoShots            = (weapon.weaponDef.ShotsWhenFired + extAmmo.ShotsWhenFired) * (weapon.weaponDef.ProjectilesPerShot + extAmmo.ProjectilesPerShot);
                if (string.IsNullOrEmpty(ammoId))
                {
                    ammoId      = weapon.ammoBoxes[index].ammoDef.Description.Id;
                    ClusterShot = ammoShots;
                    continue;
                }
                ;
                if (ClusterShot < ammoShots)
                {
                    ammoId      = weapon.ammoBoxes[index].ammoDef.Description.Id;
                    ClusterShot = ammoShots;
                }
            }
            if (string.IsNullOrEmpty(ammoId) == false)
            {
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false)
                {
                    weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.AmmoIdStatName, ammoId);
                }
                else
                {
                    weapon.StatCollection.Set <string>(CustomAmmoCategories.AmmoIdStatName, ammoId);
                }
            }
        }
Beispiel #14
0
 public static string getWeaponAmmoId(Weapon weapon)
 {
     if (CustomAmmoCategories.getWeaponCustomAmmoCategory(weapon) == CustomAmmoCategories.NotSetCustomAmmoCategoty)
     {
         return("");
     }
     if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
     {
         return(weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>());
     }
     if (weapon.ammoBoxes.Count == 0)
     {
         return("");
     }
     ;
     return(weapon.ammoBoxes[0].ammoDef.Description.Id);
 }
        public static void switchToMostHeatAmmo(Weapon weapon)
        {
            if (weapon.ammoBoxes.Count == 0)
            {
                return;
            }
            float  HeatPerShot = 0;
            string ammoId      = "";

            for (int index = 0; index < weapon.ammoBoxes.Count; ++index)
            {
                if (weapon.ammoBoxes[index].CurrentAmmo <= 0)
                {
                    continue;
                }
                if (weapon.ammoBoxes[index].IsFunctional == false)
                {
                    continue;
                }
                ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(weapon.ammoBoxes[index].ammoDef.Description.Id);
                if (string.IsNullOrEmpty(ammoId))
                {
                    ammoId      = weapon.ammoBoxes[index].ammoDef.Description.Id;
                    HeatPerShot = extAmmo.HeatDamagePerShot;
                    continue;
                }
                ;
                if (HeatPerShot < extAmmo.HeatDamagePerShot)
                {
                    ammoId      = weapon.ammoBoxes[index].ammoDef.Description.Id;
                    HeatPerShot = extAmmo.HeatDamagePerShot;
                }
            }
            if (string.IsNullOrEmpty(ammoId) == false)
            {
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false)
                {
                    weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.AmmoIdStatName, ammoId);
                }
                else
                {
                    weapon.StatCollection.Set <string>(CustomAmmoCategories.AmmoIdStatName, ammoId);
                }
            }
        }
Beispiel #16
0
        public static float getWeaponEvasivePipsIgnored(Weapon weapon)
        {
            float result = weapon.weaponDef.EvasivePipsIgnored;

            //CustomAmmoCategoriesLog.Log.LogWrite("getWeaponEvasivePipsIgnored " + weapon.UIName + "\n");
            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
            {
                string           ammoId  = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId);
                result += extAmmo.EvasivePipsIgnored;
            }
            if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true)
            {
                result += CustomAmmoCategories.getWeaponMode(weapon).EvasivePipsIgnored;
            }
            //CustomAmmoCategoriesLog.Log.LogWrite("  modified EvasivePipsIgnored\n");
            return(result);
        }
        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);
        }
        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 int DecrementAmmo(Weapon instance, int stackItemUID, int StreakHitCount)
        {
            int shotsWhenFired = instance.ShotsWhenFired;

            if (StreakHitCount != 0)
            {
                if (instance.weaponDef.ComponentTags.Contains("wr-clustered_shots") || (CustomAmmoCategories.getWeaponDisabledClustering(instance) == false))
                {
                    shotsWhenFired = StreakHitCount / instance.ProjectilesPerShot;
                }
                else
                {
                    shotsWhenFired = StreakHitCount;
                }
            }
            bool streakEffect = CustomAmmoCategories.getExtWeaponDef(instance.weaponDef.Description.Id).StreakEffect;

            if ((streakEffect == false) && (StreakHitCount == 0))
            {
                StreakHitCount = shotsWhenFired;
            }
            CustomAmmoCategoriesLog.Log.LogWrite("Weapon.DecrementAmmo " + instance.UIName + " real fire count:" + StreakHitCount + "\n");
            int result = 0;

            if ((CustomAmmoCategories.getWeaponCustomAmmoCategory(instance).Index == CustomAmmoCategories.NotSetCustomAmmoCategoty.Index) || (instance.parent != null && instance.parent is Turret))
            {
                if (instance.weaponDef.ComponentTags.Contains("wr-clustered_shots") || CustomAmmoCategories.getWeaponDisabledClustering(instance))
                {
                    result = shotsWhenFired;
                }
                else
                {
                    result = shotsWhenFired * instance.ProjectilesPerShot;
                }
                CustomAmmoCategoriesLog.Log.LogWrite("  weapon has no ammo (energy or turret) " + instance.UIName + "\n");
                return(result);
            }
            int modValue;

            if (instance.InternalAmmo >= shotsWhenFired)
            {
                if (StreakHitCount != 0)
                {
                    instance.StatCollection.ModifyStat <int>(instance.uid, stackItemUID, "InternalAmmo", StatCollection.StatOperation.Int_Subtract, shotsWhenFired, -1, true);
                }
                modValue = 0;
            }
            else
            {
                modValue = shotsWhenFired - instance.InternalAmmo;
                if (StreakHitCount != 0)
                {
                    instance.StatCollection.ModifyStat <int>(instance.uid, stackItemUID, "InternalAmmo", StatCollection.StatOperation.Set, 0, -1, true);
                }
            }
            string CurrentAmmoId = "";

            if (CustomAmmoCategories.checkExistance(instance.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
            {
                CurrentAmmoId = instance.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
            }
            else
            {
                if (instance.ammoBoxes.Count > 0)
                {
                    CurrentAmmoId = instance.ammoBoxes[0].ammoDef.Description.Id;
                    CustomAmmoCategoriesLog.Log.LogWrite($"WARNING! strange behavior " + instance.UIName + " has no data in statistics. fallback to default ammo " + CurrentAmmoId + "\n");
                }
                else
                {
                    CustomAmmoCategoriesLog.Log.LogWrite($"WARNING! strange behavior " + instance.UIName + " not energy, parent no turret but no ammo boxes\n");
                    if (instance.weaponDef.ComponentTags.Contains("wr-clustered_shots") || CustomAmmoCategories.getWeaponDisabledClustering(instance))
                    {
                        result = shotsWhenFired;
                    }
                    else
                    {
                        result = shotsWhenFired * instance.ProjectilesPerShot;
                    }
                    return(result);
                }
            }
            //ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(CurrentAmmoId);
            //ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(__instance.weaponDef.Description.Id);
            if (modValue == 0)
            {
                if (instance.weaponDef.ComponentTags.Contains("wr-clustered_shots") || CustomAmmoCategories.getWeaponDisabledClustering(instance))
                {
                    result = shotsWhenFired;
                }
                else
                {
                    result = shotsWhenFired * instance.ProjectilesPerShot;
                }
                CustomAmmoCategoriesLog.Log.LogWrite("  fire internal ammo. projectiles:" + result + "\n");
                return(result);
            }
            for (int index = 0; index < instance.ammoBoxes.Count; ++index)
            {
                AmmunitionBox ammoBox = instance.ammoBoxes[index];
                if (ammoBox.IsFunctional == false)
                {
                    continue;
                }
                if (ammoBox.CurrentAmmo <= 0)
                {
                    continue;
                }
                if ((string.IsNullOrEmpty(CurrentAmmoId) == false) && (ammoBox.ammoDef.Description.Id != CurrentAmmoId))
                {
                    continue;
                }
                if (ammoBox.CurrentAmmo >= modValue)
                {
                    if (StreakHitCount != 0)
                    {
                        ammoBox.StatCollection.ModifyStat <int>(instance.uid, stackItemUID, "CurrentAmmo", StatCollection.StatOperation.Int_Subtract, modValue, -1, true);
                    }
                    modValue = 0;
                }
                else
                {
                    modValue -= ammoBox.CurrentAmmo;
                    if (StreakHitCount != 0)
                    {
                        ammoBox.StatCollection.ModifyStat <int>(instance.uid, stackItemUID, "CurrentAmmo", StatCollection.StatOperation.Set, 0, -1, true);
                    }
                }
            }
            if (instance.weaponDef.ComponentTags.Contains("wr-clustered_shots") || CustomAmmoCategories.getWeaponDisabledClustering(instance))
            {
                result = (instance.ShotsWhenFired - modValue);
            }
            else
            {
                result = (instance.ShotsWhenFired - modValue) * instance.ProjectilesPerShot;
            }
            CustomAmmoCategoriesLog.Log.LogWrite("  fire exteranl ammo. projectiles:" + result + "\n");
            return(result);
        }