public static bool Patch_Pawn_PreApplyDamage_Prefix(
     ref Pawn __instance,
     ref DamageInfo dinfo,
     out bool absorbed)
 {
     if (((DamageInfo) ref dinfo).get_Def() != DamageDefOf.SurgicalCut && ((DamageInfo) ref dinfo).get_Def() != DamageDefOf.ExecutionCut && ((DamageInfo) ref dinfo).get_Def() != DamageDefOf.EMP && ((DamageInfo) ref dinfo).get_Def() != DamageDefOf.Stun && __instance.health != null && ((HediffSet)((Pawn_HealthTracker)__instance.health).hediffSet).HasHediff(MFHediffDefOf.MFBastionHigh, false) && ((HediffSet)((Pawn_HealthTracker)__instance.health).hediffSet).GetFirstHediffOfDef(MFHediffDefOf.MFBastionHigh, false) is ShieldHediff firstHediffOfDef)
     {
         if (firstHediffOfDef.broken)
         {
             firstHediffOfDef.ResetBrokenCooldown();
         }
         else if (firstHediffOfDef.AbsorbDamage(dinfo))
         {
             if (firstHediffOfDef.broken)
             {
                 SoundStarter.PlayOneShot((SoundDef)SoundDefOf.EnergyShield_Broken, SoundInfo.op_Implicit(new TargetInfo(((Thing)__instance).get_Position(), ((Thing)__instance).get_Map(), false)));
                 MoteMaker.MakeStaticMote(GenThing.TrueCenter((Thing)__instance), ((Thing)__instance).get_Map(), (ThingDef)ThingDefOf.Mote_ExplosionFlash, 12f);
             }
             else
             {
                 SoundStarter.PlayOneShot((SoundDef)SoundDefOf.EnergyShield_AbsorbDamage, SoundInfo.op_Implicit(new TargetInfo(((Thing)__instance).get_Position(), ((Thing)__instance).get_Map(), false)));
                 MoteMaker.MakeStaticMote(GenThing.TrueCenter((Thing)__instance), ((Thing)__instance).get_Map(), (ThingDef)ThingDefOf.Mote_ExplosionFlash, 6f);
             }
             if (!firstHediffOfDef.broken)
             {
                 firstHediffOfDef.ResetHitCooldown();
             }
             absorbed = true;
             return(false);
         }
     }
     absorbed = false;
     return(true);
 }
Example #2
0
        private void ProtectSquare(IntVec3 square, bool flag_direct, bool flag_indirect, bool IFFcheck)
        {
            if (!GenGrid.InBounds(square) || (!this.shieldBlockIndirect || !flag_indirect) && (!this.shieldBlockDirect || !flag_direct))
            {
                return;
            }
            List <Thing> thingList1 = Find.get_ThingGrid().ThingsListAt(square);
            List <Thing> thingList2 = new List <Thing>();
            int          index1     = 0;

            for (int index2 = ((IEnumerable <Thing>)thingList1).Count <Thing>(); index1 < index2; ++index1)
            {
                if (thingList1[index1] != null && thingList1[index1] is Projectile)
                {
                    Projectile projectile = (Projectile)thingList1[index1];
                    if (!((Thing)projectile).get_Destroyed() && (this.shieldBlockIndirect && flag_indirect && ((ProjectileProperties)((ThingDef)((Thing)projectile).def).projectile).flyOverhead != null || this.shieldBlockDirect && flag_direct && ((ProjectileProperties)((ThingDef)((Thing)projectile).def).projectile).flyOverhead == null))
                    {
                        bool flag = true;
                        if (IFFcheck)
                        {
                            Thing instanceField = ReflectionHelper.GetInstanceField(typeof(Projectile), (object)projectile, "launcher") as Thing;
                            if (instanceField != null && instanceField.get_Faction() != null && (instanceField.get_Faction().def != null && instanceField.get_Faction().def == FactionDefOf.Colony))
                            {
                                flag = false;
                            }
                        }
                        if (((ProjectileProperties)((ThingDef)((Thing)projectile).def).projectile).flyOverhead != null && !this.WillTargetLandInRange(projectile))
                        {
                            flag = false;
                        }
                        if (flag)
                        {
                            Quaternion exactRotation = projectile.get_ExactRotation();
                            Vector3    exactPosition = projectile.get_ExactPosition();
                            exactPosition.y = (__Null)0.0;
                            Vector3 vec = Vectors.IntVecToVec(this.position);
                            vec.y = (__Null)0.0;
                            Quaternion quaternion = Quaternion.LookRotation(Vector3.op_Subtraction(exactPosition, vec));
                            if ((double)Quaternion.Angle(exactRotation, quaternion) > 90.0 || IFFcheck)
                            {
                                MoteThrower.ThrowLightningGlow(projectile.get_ExactPosition(), 0.5f);
                                SoundStarter.PlayOneShot(ShieldField.HitSoundDef, SoundInfo.op_Implicit(((Thing)projectile).get_Position()));
                                this.ProcessDamage((int)((ProjectileProperties)((ThingDef)((Thing)projectile).def).projectile).damageAmountBase);
                                thingList2.Add((Thing)projectile);
                                if (!this.isOnline())
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            using (List <Thing> .Enumerator enumerator = thingList2.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    enumerator.Current.Destroy((DestroyMode)0);
                }
            }
        }