Example #1
0
        public static bool Prefix(ref Verb_Shoot __instance)
        {
            //    Log.Warning("TryCastShot");
            IAdvancedVerb entry = __instance.SpecialRules();

            if (entry == null)
            {
                //    Log.Message("no SpecialRules detected");
                return(true);
            }
            bool          UserEffect      = entry.EffectsUser;
            HediffDef     UserHediff      = entry.UserEffect;
            float         AddHediffChance = entry.EffectsUserChance;
            List <string> Immunitylist    = entry.UserEffectImmuneList;
            string        msg             = string.Format("");
            float         failChance      = entry.FailChance(__instance.EquipmentSource, out string reliabilityString);

            bool failed = false;

            if (failChance > 0f)
            {
                if (entry.Debug)
                {
                    Log.Message("failChance: " + failChance);
                }
                Rand.PushState();
                failed = Rand.Chance(failChance);
                Rand.PopState();
                if (entry.Debug)
                {
                    Log.Message((entry.GetsHot ? "Overheat" : "Jam") + " Chance: " + failChance + "% Result: " + (failed ? (entry.GetsHot ? "Overheated" : "Jamed") : "Passed"));
                }
                //    Log.Message("failed: "+failed);
            }
            if (failed)
            {
                bool           stillFire         = true;
                bool           canDamageWeapon   = entry.HotDamageWeapon || entry.JamsDamageWeapon;
                MessageTypeDef msgDef            = entry.GetsHot ? MessageTypeDefOf.NegativeHealthEvent : MessageTypeDefOf.SilentInput;
                float          extraWeaponDamage = entry.HotDamageWeapon ? entry.HotDamage : entry.JamDamage;
                if (entry.GetsHot)
                {
                    string    overheat     = "overheated";
                    string    causing      = "causing";
                    DamageDef damageDef    = __instance.Projectile.projectile.damageDef;
                    HediffDef HediffToAdd  = damageDef.hediff;
                    Pawn      launcherPawn = __instance.caster as Pawn;
                    Rand.PushState();
                    bool crit = Rand.Chance(entry.GetsHotCritChance);
                    Rand.PopState();
                    bool critExplode = false;
                    if (crit)
                    {
                        overheat = "critically overheated";
                        if (entry.GetsHotCritExplosion)
                        {
                            critExplode = Rand.Chance(entry.GetsHotCritExplosionChance);
                            if (critExplode)
                            {
                                causing = "causing an explosion";
                                CriticalOverheatExplosion(__instance);
                            }
                        }
                    }
                    float ArmorPenetration = __instance.Projectile.projectile.GetArmorPenetration(__instance.EquipmentSource, null) * (crit ? 1f : 0.25f);
                    float DamageAmount     = __instance.Projectile.projectile.GetDamageAmount(__instance.EquipmentSource, null) * (crit ? 1f : 0.25f);
                    msg = string.Format("{0}'s {1} " + overheat + ". ({2} chance) " + causing + " {3} damage", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent(), DamageAmount);
                    float damageLeft = DamageAmount;
                    List <BodyPartTagDef> tagDefs = new List <BodyPartTagDef>()
                    {
                        BodyPartTagDefOf.ManipulationLimbDigit, BodyPartTagDefOf.ManipulationLimbSegment
                    };
                    List <BodyPartRecord> list = launcherPawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Outside, tagDefs).ToList <BodyPartRecord>();
                    if (list.NullOrEmpty())
                    {
                        list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.defName.Contains("Arm") || x.parent.def.defName.Contains("Arm")).ToList <BodyPartRecord>();
                    }
                    if (list.NullOrEmpty())
                    {
                        list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbCore) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbSegment) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbDigit)).ToList <BodyPartRecord>();
                    }
                    if (!list.NullOrEmpty())
                    {
                        while (damageLeft > 0f && !list.NullOrEmpty())
                        {
                            Rand.PushState();
                            BodyPartRecord part = list.RandomElement();
                            list.Remove(part);
                            float maxPartDamage = Math.Min(damageLeft, launcherPawn.health.hediffSet.GetPartHealth(part));
                            float amount        = Rand.Range(1f, Math.Min(damageLeft, maxPartDamage));
                            Rand.PopState();
                            if (amount > 0)
                            {
                                /*
                                 * Hediff hediff = HediffMaker.MakeHediff(HediffToAdd, launcherPawn, part);
                                 * hediff.Severity = severity;
                                 * launcherPawn.health.AddHediff(hediff, part, null);
                                 */
                                DamageInfo info = new DamageInfo(damageDef, amount, ArmorPenetration, -1, __instance.EquipmentSource, part, __instance.EquipmentSource.def, DamageInfo.SourceCategory.ThingOrUnknown, __instance.CurrentTarget.Thing ?? null);
                                launcherPawn.TakeDamage(info);
                                damageLeft -= amount;
                            }
                        }
                    }
                    else
                    {
                    }
                    Messages.Message(msg, MessageTypeDefOf.NegativeHealthEvent);
                }
                if (entry.Jams)
                {
                    if (!__instance.GetsHot())
                    {
                        msg = string.Format("{0}'s {1} had a weapon jam. ({2} chance)", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent());
                        Messages.Message(msg, MessageTypeDefOf.SilentInput);
                    }
                    float defaultCooldownTime = __instance.verbProps.defaultCooldownTime * 2;
                    __instance.verbProps.defaultCooldownTime = defaultCooldownTime;
                    if (canDamageWeapon)
                    {
                        if (extraWeaponDamage != 0f)
                        {
                            if (__instance.EquipmentSource != null)
                            {
                                if (__instance.EquipmentSource.HitPoints - (int)extraWeaponDamage >= 0)
                                {
                                    __instance.EquipmentSource.HitPoints = __instance.EquipmentSource.HitPoints - (int)extraWeaponDamage;
                                }
                                else if (__instance.EquipmentSource.HitPoints - (int)extraWeaponDamage < 0)
                                {
                                    __instance.EquipmentSource.HitPoints = 0;
                                    __instance.EquipmentSource.Destroy();
                                }
                            }
                            if (__instance.HediffCompSource != null)
                            {
                                /*
                                 * if (__instance.HediffCompSource.parent.Part.HitPoints - (int)extraWeaponDamage >= 0)
                                 * {
                                 *  __instance.HediffCompSource.HitPoints = __instance.HediffCompSource.HitPoints - (int)extraWeaponDamage;
                                 * }
                                 * else if (__instance.HediffCompSource.HitPoints - (int)extraWeaponDamage < 0)
                                 * {
                                 *  __instance.HediffCompSource.HitPoints = 0;
                                 *  __instance.HediffCompSource.Destroy();
                                 * }
                                 */
                            }
                        }
                        else
                        {
                            if (__instance.EquipmentSource != null)
                            {
                                if (__instance.EquipmentSource.HitPoints > 0)
                                {
                                    __instance.EquipmentSource.HitPoints--;
                                }
                            }
                        }
                    }
                    if (__instance.EquipmentSource != null)
                    {
                        SpinningLaserGun spinner = __instance.EquipmentSource as SpinningLaserGun;
                        if (spinner != null)
                        {
                            spinner.state = SpinningLaserGunBase.State.Idle;
                            spinner.ReachRotationSpeed(0, 0);
                        }
                    }
                    return(false);
                }
            }
            if (__instance.UserEffect(out float Chance, out HediffDef Effect, out StatDef ResistStat, out List <string> ImmuneList))
            {
                bool Immunityflag = false;
                Pawn launcherPawn = __instance.caster as Pawn;
                if (!Immunitylist.NullOrEmpty())
                {
                    foreach (var item in Immunitylist)
                    {
                        Immunityflag = launcherPawn.def.defName.Contains(item);
                        if (Immunityflag)
                        {
                            //    Log.Message(string.Format("{0} is immune to their {1}'s UseEffect", launcherPawn.LabelShortCap, __instance.EquipmentSource.LabelShortCap));
                        }
                    }

                    /*
                     * List<string> list = GunExt.UserEffectImmuneList.Where(x => DefDatabase<ThingDef>.GetNamedSilentFail(x) != null).ToList();
                     * bool Immunityflag = list.Contains(launcherPawn.def.defName);
                     * if (Immunityflag)
                     * {
                     *  return;
                     * }
                     */
                }
                if (!Immunityflag)
                {
                    Rand.PushState();
                    var rand = Rand.Value; // This is a random percentage between 0% and 100%
                    Rand.PopState();
                    //    Log.Message(string.Format("GunExt.EffectsUser Effect: {0}, Chance: {1}, Roll: {2}, Result: {3}" + GunExt.ResistEffectStat != null ? ", Resist Stat: "+GunExt.ResistEffectStat.LabelCap+", Resist Amount"+ __instance.caster.GetStatValue(GunExt.ResistEffectStat, true) : null, GunExt.UserEffect.LabelCap, AddHediffChance, rand, rand <= AddHediffChance));
                    if (rand <= AddHediffChance) // If the percentage falls under the chance, success!
                    {
                        Rand.PushState();
                        var randomSeverity = Rand.Range(0.05f, 0.15f);
                        Rand.PopState();
                        var effectOnPawn = launcherPawn?.health?.hediffSet?.GetFirstHediffOfDef(UserHediff);
                        if (effectOnPawn != null)
                        {
                            effectOnPawn.Severity += randomSeverity;
                        }
                        else
                        {
                            Hediff hediff = HediffMaker.MakeHediff(UserHediff, launcherPawn, null);
                            hediff.Severity = randomSeverity;
                            launcherPawn.health.AddHediff(hediff, null, null);
                        }
                    }
                }
            }
            return(true);
        }
        public static bool Prefix(ref AbilitesExtended.Verb_EquipmentLaunchProjectile __instance)
        {
            //    Log.Warning("TryCastShot");
            bool          GetsHot                    = __instance.verbProperties.GetsHot;
            bool          Jams                       = __instance.verbProperties.Jams;
            bool          GetsHotCrit                = __instance.verbProperties.GetsHotCrit;
            float         GetsHotCritChance          = __instance.verbProperties.GetsHotCritChance;
            bool          GetsHotCritExplosion       = __instance.verbProperties.GetsHotCritExplosion;
            float         GetsHotCritExplosionChance = __instance.verbProperties.GetsHotCritExplosionChance;
            bool          canDamageWeapon            = __instance.verbProperties.HotDamageWeapon || __instance.verbProperties.JamsDamageWeapon;
            float         extraWeaponDamage          = (Jams && __instance.verbProperties.JamsDamageWeapon) ? __instance.verbProperties.JamDamage : (GetsHot && __instance.verbProperties.HotDamageWeapon) ? __instance.verbProperties.HotDamage : 0f;
            bool          TwinLinked                 = __instance.verbProperties.TwinLinked;
            bool          Multishot                  = __instance.verbProperties.Multishot;
            int           ScattershotCount           = __instance.verbProperties.ScattershotCount;
            bool          UserEffect                 = __instance.verbProperties.EffectsUser;
            HediffDef     UserHediff                 = __instance.verbProperties.UserEffect;
            float         AddHediffChance            = __instance.verbProperties.EffectsUserChance;
            List <string> Immunitylist               = __instance.verbProperties.UserEffectImmuneList;

            if ((GetsHot && AMSettings.Instance.AllowGetsHot) || (Jams && AMSettings.Instance.AllowJams))
            {
                string msg = string.Format("");
                string reliabilityString;
                float  failChance;
                AbilitesExtended.StatPart_Reliability.GetReliability(__instance.verbProperties, out reliabilityString, out failChance);
                failChance = GetsHot ? (failChance / 10) : (failChance / 100);
                Rand.PushState();
                bool fails = Rand.Chance(failChance);
                Rand.PopState();
                if (fails)
                {
                    if (GetsHot)
                    {
                        DamageDef damageDef        = __instance.Projectile.projectile.damageDef;
                        HediffDef HediffToAdd      = damageDef.hediff;
                        float     ArmorPenetration = __instance.Projectile.projectile.GetArmorPenetration(__instance.EquipmentSource, null);
                        float     DamageAmount     = 0;
                        Pawn      launcherPawn     = __instance.caster as Pawn;
                        Rand.PushState();
                        bool getshotcrit = Rand.Chance(GetsHotCritChance);
                        Rand.PopState();
                        if (getshotcrit)
                        {
                            DamageAmount = __instance.Projectile.projectile.GetDamageAmount(__instance.EquipmentSource, null);
                            msg          = string.Format("{0}'s {1} critically overheated. ({2} chance) causing {3} damage", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent(), DamageAmount);
                            Rand.PushState();
                            if (GetsHotCritExplosion && Rand.Chance(GetsHotCritExplosionChance))
                            {
                                CriticalOverheatExplosion(ref __instance);
                            }
                            Rand.PopState();
                        }
                        else
                        {
                            DamageAmount = __instance.Projectile.projectile.GetDamageAmount(__instance.EquipmentSource, null);
                            msg          = string.Format("{0}'s {1} overheated. ({2} chance) causing {3} damage", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent(), DamageAmount);
                        }
                        float maxburndmg = DamageAmount / 10;
                        while (DamageAmount > 0f)
                        {
                            List <BodyPartRecord> list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.defName.Contains("Finger") || x.def.defName.Contains("Hand")).ToList <BodyPartRecord>();
                            if (list.NullOrEmpty())
                            {
                                list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.defName.Contains("Arm") || x.def.defName.Contains("Shoulder")).ToList <BodyPartRecord>();
                            }
                            if (list.NullOrEmpty())
                            {
                                list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbCore) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbSegment) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbDigit)).ToList <BodyPartRecord>();
                            }
                            if (list.NullOrEmpty())
                            {
                                break;
                            }
                            else
                            {
                                BodyPartRecord part = list.RandomElement();
                                Hediff         hediff;
                                Rand.PushState();
                                float severity = Rand.Range(Math.Min(0.1f, DamageAmount), Math.Min(DamageAmount, maxburndmg));
                                Rand.PopState();
                                hediff          = HediffMaker.MakeHediff(HediffToAdd, launcherPawn, null);
                                hediff.Severity = severity;
                                launcherPawn.health.AddHediff(hediff, part, null);
                                DamageAmount -= severity;
                            }
                        }
                        Messages.Message(msg, MessageTypeDefOf.NegativeHealthEvent);
                    }
                    else
                    {
                        msg = string.Format("{0}'s {1} had a weapon jam. ({2} chance)", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent());
                        Messages.Message(msg, MessageTypeDefOf.SilentInput);
                    }
                    float defaultCooldownTime = __instance.verbProps.defaultCooldownTime * 2;
                    __instance.verbProps.defaultCooldownTime = defaultCooldownTime;
                    if (canDamageWeapon)
                    {
                        if (extraWeaponDamage != 0f)
                        {
                            if (__instance.EquipmentSource != null)
                            {
                                if (__instance.EquipmentSource.HitPoints - (int)extraWeaponDamage >= 0)
                                {
                                    __instance.EquipmentSource.HitPoints = __instance.EquipmentSource.HitPoints - (int)extraWeaponDamage;
                                }
                                else if (__instance.EquipmentSource.HitPoints - (int)extraWeaponDamage < 0)
                                {
                                    __instance.EquipmentSource.HitPoints = 0;
                                    __instance.EquipmentSource.Destroy();
                                }
                            }
                            if (__instance.HediffCompSource != null)
                            {
                                /*
                                 * if (__instance.HediffCompSource.parent.Part..HitPoints - (int)extraWeaponDamage >= 0)
                                 * {
                                 *  __instance.HediffCompSource.HitPoints = __instance.HediffCompSource.HitPoints - (int)extraWeaponDamage;
                                 * }
                                 * else if (__instance.HediffCompSource.HitPoints - (int)extraWeaponDamage < 0)
                                 * {
                                 *  __instance.HediffCompSource.HitPoints = 0;
                                 *  __instance.HediffCompSource.Destroy();
                                 * }
                                 */
                            }
                        }
                        else
                        {
                            if (__instance.EquipmentSource != null)
                            {
                                if (__instance.EquipmentSource.HitPoints > 0)
                                {
                                    __instance.EquipmentSource.HitPoints--;
                                }
                            }
                        }
                    }
                    if (Jams)
                    {
                        if (__instance.EquipmentSource != null)
                        {
                            SpinningLaserGun spinner = (SpinningLaserGun)__instance.EquipmentSource;
                            if (spinner != null)
                            {
                                spinner.state = SpinningLaserGunBase.State.Idle;
                                spinner.ReachRotationSpeed(0, 0);
                            }
                        }
                        return(false);
                    }
                }
            }

            if (ScattershotCount > 0 && Multishot && AMSettings.Instance.AllowMultiShot || TwinLinked)
            {
                Traverse        traverse                = Traverse.Create(__instance);
                LocalTargetInfo currentTarget           = (LocalTargetInfo)Verb_Shoot_TryCastShot_WeaponSpecialRules_Patch.currentTarget.GetValue(__instance);
                bool            canHitNonTargetPawnsNow = (bool)Verb_Shoot_TryCastShot_WeaponSpecialRules_Patch.canHitNonTargetPawnsNow.GetValue(__instance);
                //    Log.Message(string.Format("AllowMultiShot: {0} Projectile Count: {1}", AMASettings.Instance.AllowMultiShot && Multishot, ScattershotCount));
                if (TwinLinked)
                {
                    TryCastExtraShot(ref __instance, currentTarget, canHitNonTargetPawnsNow);
                }
                else
                {
                    for (int i = 0; i < ScattershotCount; i++)
                    {
                        TryCastExtraShot(ref __instance, currentTarget, canHitNonTargetPawnsNow);
                    }
                }
            }

            if (UserEffect && AMSettings.Instance.AllowUserEffects)
            {
                if (__instance.caster.def.category == ThingCategory.Pawn)
                {
                    bool Immunityflag = false;
                    Pawn launcherPawn = __instance.caster as Pawn;
                    if (!Immunitylist.NullOrEmpty())
                    {
                        foreach (var item in Immunitylist)
                        {
                            Immunityflag = launcherPawn.def.defName.Contains(item);
                            if (Immunityflag)
                            {
                                //    Log.Message(string.Format("{0} is immune to their {1}'s UseEffect", launcherPawn.LabelShortCap, __instance.EquipmentSource.LabelShortCap));
                            }
                        }

                        /*
                         * List<string> list = GunExt.UserEffectImmuneList.Where(x => DefDatabase<ThingDef>.GetNamedSilentFail(x) != null).ToList();
                         * bool Immunityflag = list.Contains(launcherPawn.def.defName);
                         * if (Immunityflag)
                         * {
                         *  return;
                         * }
                         */
                    }
                    if (!Immunityflag)
                    {
                        Rand.PushState();
                        var rand = Rand.Value; // This is a random percentage between 0% and 100%
                        Rand.PopState();
                        //    Log.Message(string.Format("GunExt.EffectsUser Effect: {0}, Chance: {1}, Roll: {2}, Result: {3}" + GunExt.ResistEffectStat != null ? ", Resist Stat: "+GunExt.ResistEffectStat.LabelCap+", Resist Amount"+ __instance.caster.GetStatValue(GunExt.ResistEffectStat, true) : null, GunExt.UserEffect.LabelCap, AddHediffChance, rand, rand <= AddHediffChance));
                        if (rand <= AddHediffChance) // If the percentage falls under the chance, success!
                        {
                            Rand.PushState();
                            var randomSeverity = Rand.Range(0.05f, 0.15f);
                            Rand.PopState();
                            var effectOnPawn = launcherPawn?.health?.hediffSet?.GetFirstHediffOfDef(UserHediff);
                            if (effectOnPawn != null)
                            {
                                effectOnPawn.Severity += randomSeverity;
                            }
                            else
                            {
                                Hediff hediff = HediffMaker.MakeHediff(UserHediff, launcherPawn, null);
                                hediff.Severity = randomSeverity;
                                launcherPawn.health.AddHediff(hediff, null, null);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Example #3
0
        public static bool Prefix(ref Verb_ShootCE __instance)
        {
            //    Log.Warning("CE_TryCastShot_WeaponSpecialRules_Patch WarmupComplete ");
            IAdvancedVerb entry = __instance.SpecialRules();

            if (entry == null)
            {
                //    Log.Message("no SpecialRules detected");
                return(true);
            }
            bool          canDamageWeapon;
            float         extraWeaponDamage;
            bool          TwinLinked       = entry.TwinLinked;
            bool          Multishot        = entry.Multishot;
            int           ScattershotCount = entry.ScattershotCount;
            bool          UserEffect       = entry.EffectsUser;
            HediffDef     UserHediff       = entry.UserEffect;
            float         AddHediffChance  = entry.EffectsUserChance;
            List <string> Immunitylist     = entry.UserEffectImmuneList;
            string        msg = string.Format("");
            string        reliabilityString;
            float         failChance;

            StatPart_Reliability.GetReliability(entry, __instance.EquipmentSource, out reliabilityString, out failChance);
            failChance = (__instance.GetsHot()) ? (failChance / 10) : (failChance / 100);
            bool failed = false;

            if (__instance.GetsHot() || __instance.Jams())
            {
                //    Log.Message("failChance: "+failChance);
                Rand.PushState();
                failed = Rand.Chance(failChance);
                Rand.PopState();
                //    Log.Message("failed: "+failed);
            }
            if (__instance.GetsHot(out bool GetsHotCrit, out float GetsHotCritChance, out bool GetsHotCritExplosion, out float GetsHotCritExplosionChance, out canDamageWeapon, out extraWeaponDamage))
            {
                if (failed)
                {
                    DamageDef damageDef        = __instance.Projectile.projectile.damageDef;
                    HediffDef HediffToAdd      = damageDef.hediff;
                    float     ArmorPenetration = __instance.Projectile.projectile.GetArmorPenetration(__instance.EquipmentSource, null);
                    float     DamageAmount     = 0;
                    Pawn      launcherPawn     = __instance.caster as Pawn;
                    Rand.PushState();
                    if (Rand.Chance(GetsHotCritChance))
                    {
                        DamageAmount = __instance.Projectile.projectile.GetDamageAmount(__instance.EquipmentSource, null);
                        msg          = string.Format("{0}'s {1} critically overheated. ({2} chance) causing {3} damage", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent(), DamageAmount);
                        if (GetsHotCritExplosion && Rand.Chance(GetsHotCritExplosionChance))
                        {
                            CriticalOverheatExplosion(ref __instance);
                        }
                    }
                    else
                    {
                        DamageAmount = __instance.Projectile.projectile.GetDamageAmount(__instance.EquipmentSource, null);
                        msg          = string.Format("{0}'s {1} overheated. ({2} chance) causing {3} damage", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent(), DamageAmount);
                    }
                    Rand.PopState();
                    float maxburndmg = DamageAmount / 10;
                    while (DamageAmount > 0f)
                    {
                        List <BodyPartRecord> list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.defName.Contains("Finger") || x.def.defName.Contains("Hand")).ToList <BodyPartRecord>();
                        if (list.NullOrEmpty())
                        {
                            list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.defName.Contains("Arm") || x.parent.def.defName.Contains("Arm")).ToList <BodyPartRecord>();
                        }
                        if (list.NullOrEmpty())
                        {
                            list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbCore) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbSegment) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbDigit)).ToList <BodyPartRecord>();
                        }
                        if (list.NullOrEmpty())
                        {
                            break;
                        }
                        else
                        {
                            BodyPartRecord part = list.RandomElement();
                            Hediff         hediff;
                            Rand.PushState();
                            float severity = Rand.Range(Math.Min(0.1f, DamageAmount), Math.Min(DamageAmount, maxburndmg));
                            Rand.PopState();
                            hediff          = HediffMaker.MakeHediff(HediffToAdd, launcherPawn, part);
                            hediff.Severity = severity;
                            launcherPawn.health.AddHediff(hediff, part, null);
                            DamageAmount -= severity;
                        }
                    }
                    Messages.Message(msg, MessageTypeDefOf.NegativeHealthEvent);
                }
            }
            if (__instance.Jams(out canDamageWeapon, out extraWeaponDamage))
            {
                if (failed)
                {
                    if (!__instance.GetsHot())
                    {
                        msg = string.Format("{0}'s {1} had a weapon jam. ({2} chance)", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent());
                        Messages.Message(msg, MessageTypeDefOf.SilentInput);
                    }
                    float defaultCooldownTime = __instance.verbProps.defaultCooldownTime * 2;
                    __instance.verbProps.defaultCooldownTime = defaultCooldownTime;
                    if (canDamageWeapon)
                    {
                        if (extraWeaponDamage != 0f)
                        {
                            if (__instance.EquipmentSource != null)
                            {
                                if (__instance.EquipmentSource.HitPoints - (int)extraWeaponDamage >= 0)
                                {
                                    __instance.EquipmentSource.HitPoints = __instance.EquipmentSource.HitPoints - (int)extraWeaponDamage;
                                }
                                else if (__instance.EquipmentSource.HitPoints - (int)extraWeaponDamage < 0)
                                {
                                    __instance.EquipmentSource.HitPoints = 0;
                                    __instance.EquipmentSource.Destroy();
                                }
                            }
                            if (__instance.HediffCompSource != null)
                            {
                                /*
                                 * if (__instance.HediffCompSource.parent.Part..HitPoints - (int)extraWeaponDamage >= 0)
                                 * {
                                 *  __instance.HediffCompSource.HitPoints = __instance.HediffCompSource.HitPoints - (int)extraWeaponDamage;
                                 * }
                                 * else if (__instance.HediffCompSource.HitPoints - (int)extraWeaponDamage < 0)
                                 * {
                                 *  __instance.HediffCompSource.HitPoints = 0;
                                 *  __instance.HediffCompSource.Destroy();
                                 * }
                                 */
                            }
                        }
                        else
                        {
                            if (__instance.EquipmentSource != null)
                            {
                                if (__instance.EquipmentSource.HitPoints > 0)
                                {
                                    __instance.EquipmentSource.HitPoints--;
                                }
                            }
                        }
                    }
                    if (__instance.EquipmentSource != null)
                    {
                        SpinningLaserGun spinner = (SpinningLaserGun)__instance.EquipmentSource;
                        if (spinner != null)
                        {
                            spinner.state = SpinningLaserGunBase.State.Idle;
                            spinner.ReachRotationSpeed(0, 0);
                        }
                    }
                    return(false);
                }
            }

            if (__instance.MultiShot() || __instance.TwinLinked())
            {
                if (__instance.TwinLinked())
                {
                }
                else
                {
                }
            }

            if (__instance.UserEffect(out float Chance, out HediffDef Effect, out StatDef ResistStat, out List <string> ImmuneList))
            {
                bool Immunityflag = false;
                Pawn launcherPawn = __instance.caster as Pawn;
                if (!Immunitylist.NullOrEmpty())
                {
                    foreach (var item in Immunitylist)
                    {
                        Immunityflag = launcherPawn.def.defName.Contains(item);
                        if (Immunityflag)
                        {
                            //    Log.Message(string.Format("{0} is immune to their {1}'s UseEffect", launcherPawn.LabelShortCap, __instance.EquipmentSource.LabelShortCap));
                        }
                    }

                    /*
                     * List<string> list = GunExt.UserEffectImmuneList.Where(x => DefDatabase<ThingDef>.GetNamedSilentFail(x) != null).ToList();
                     * bool Immunityflag = list.Contains(launcherPawn.def.defName);
                     * if (Immunityflag)
                     * {
                     *  return;
                     * }
                     */
                }
                if (!Immunityflag)
                {
                    Rand.PushState();
                    var rand = Rand.Value; // This is a random percentage between 0% and 100%
                    Rand.PopState();
                    //    Log.Message(string.Format("GunExt.EffectsUser Effect: {0}, Chance: {1}, Roll: {2}, Result: {3}" + GunExt.ResistEffectStat != null ? ", Resist Stat: "+GunExt.ResistEffectStat.LabelCap+", Resist Amount"+ __instance.caster.GetStatValue(GunExt.ResistEffectStat, true) : null, GunExt.UserEffect.LabelCap, AddHediffChance, rand, rand <= AddHediffChance));
                    if (rand <= AddHediffChance) // If the percentage falls under the chance, success!
                    {
                        Rand.PushState();
                        var randomSeverity = Rand.Range(0.05f, 0.15f);
                        Rand.PopState();
                        var effectOnPawn = launcherPawn?.health?.hediffSet?.GetFirstHediffOfDef(UserHediff);
                        if (effectOnPawn != null)
                        {
                            effectOnPawn.Severity += randomSeverity;
                        }
                        else
                        {
                            Hediff hediff = HediffMaker.MakeHediff(UserHediff, launcherPawn, null);
                            hediff.Severity = randomSeverity;
                            launcherPawn.health.AddHediff(hediff, null, null);
                        }
                    }
                }
            }
            return(true);
        }