示例#1
0
        public static bool ExplosionAffectCell(DamageWorker __instance, Explosion explosion, IntVec3 c, List <Thing> damagedThings, List <Thing> ignoredThings, bool canThrowMotes)
        {
            if (__instance.def.explosionCellMote != null && canThrowMotes)
            {
                Mote mote = c.GetFirstThing(explosion.Map, __instance.def.explosionCellMote) as Mote;
                if (mote != null)
                {
                    mote.spawnTick = Find.TickManager.TicksGame;
                }
                else
                {
                    float t     = Mathf.Clamp01((explosion.Position - c).LengthHorizontal / explosion.radius);
                    Color color = Color.Lerp(__instance.def.explosionColorCenter, __instance.def.explosionColorEdge, t);
                    MoteMaker.ThrowExplosionCell(c, explosion.Map, __instance.def.explosionCellMote, color);
                }
            }

            //thingsToAffect.Clear();
            List <Thing> thingsToAffect = new List <Thing>();
            float        num            = float.MinValue;
            bool         flag           = false;
            List <Thing> list           = explosion.Map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.category != ThingCategory.Mote && thing.def.category != ThingCategory.Ethereal)
                {
                    thingsToAffect.Add(thing);
                    if (thing.def.Fillage == FillCategory.Full && thing.def.Altitude > num)
                    {
                        flag = true;
                        num  = thing.def.Altitude;
                    }
                }
            }

            for (int j = 0; j < thingsToAffect.Count; j++)
            {
                if (thingsToAffect[j].def.Altitude >= num) //Null Reference Exception
                {
                    ExplosionDamageThing(__instance, explosion, thingsToAffect[j], damagedThings, ignoredThings, c);
                }
            }

            if (!flag)
            {
                ExplosionDamageTerrain(__instance, explosion, c);
            }

            if (__instance.def.explosionSnowMeltAmount > 0.0001f)
            {
                float lengthHorizontal = (c - explosion.Position).LengthHorizontal;
                float num2             = 1f - lengthHorizontal / explosion.radius;
                if (num2 > 0f)
                {
                    explosion.Map.snowGrid.AddDepth(c, (0f - num2) * __instance.def.explosionSnowMeltAmount);
                }
            }

            if (__instance.def != DamageDefOf.Bomb && __instance.def != DamageDefOf.Flame)
            {
                return(false);
            }

            List <Thing> list2 = explosion.Map.listerThings.ThingsOfDef(ThingDefOf.RectTrigger);

            for (int k = 0; k < list2.Count; k++)
            {
                RectTrigger rectTrigger = (RectTrigger)list2[k];
                if (rectTrigger.activateOnExplosion && rectTrigger.Rect.Contains(c))
                {
                    rectTrigger.ActivatedBy(null);
                }
            }
            return(false);
        }
        public override void ExplosionAffectCell(Explosion explosion, IntVec3 c, List <Thing> damagedThings, List <Thing> ignoredThings, bool canThrowMotes)
        {
            if (this.def.explosionCellMote != null && canThrowMotes)
            {
                Mote mote = c.GetFirstThing(explosion.Map, this.def.explosionCellMote) as Mote;
                if (mote != null)
                {
                    mote.spawnTick = Find.TickManager.TicksGame;
                }
                else
                {
                    float t     = Mathf.Clamp01((explosion.Position - c).LengthHorizontal / explosion.radius);
                    Color color = Color.Lerp(this.def.explosionColorCenter, this.def.explosionColorEdge, t);
                    PurpleIvyMoteMaker.ThrowExplosionCell(c, explosion.Map, this.def.explosionCellMote, color);
                }
            }
            DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Clear();
            float        num  = float.MinValue;
            bool         flag = false;
            List <Thing> list = explosion.Map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.category != ThingCategory.Mote && thing.def.category != ThingCategory.Ethereal)
                {
                    if (thing.Faction != PurpleIvyData.AlienFaction)
                    {
                        DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Add(thing);
                        if (thing.def.Fillage == FillCategory.Full && thing.def.Altitude > num)
                        {
                            flag = true;
                            num  = thing.def.Altitude;
                        }
                    }
                }
            }
            for (int j = 0; j < DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Count; j++)
            {
                if (DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j].def.Altitude >= num)
                {
                    if (DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j] is Pawn)
                    {
                        Pawn pawn = (Pawn)DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j];
                        if (Rand.Chance(0.3f))
                        {
                            pawn.stances.stunner.StunFor(Rand.RangeInclusive(100, 200), explosion.instigator);
                        }
                    }
                    this.ExplosionDamageThing(explosion, DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j], damagedThings, ignoredThings, c);
                }
            }
            if (!flag)
            {
                this.ExplosionDamageTerrain(explosion, c);
            }
            if (this.def.explosionSnowMeltAmount > 0.0001f)
            {
                float lengthHorizontal = (c - explosion.Position).LengthHorizontal;
                float num2             = 1f - lengthHorizontal / explosion.radius;
                if (num2 > 0f)
                {
                    explosion.Map.snowGrid.AddDepth(c, -num2 * this.def.explosionSnowMeltAmount);
                }
            }
            if (this.def == DamageDefOf.Bomb || this.def == DamageDefOf.Flame)
            {
                List <Thing> list2 = explosion.Map.listerThings.ThingsOfDef(ThingDefOf.RectTrigger);
                for (int k = 0; k < list2.Count; k++)
                {
                    RectTrigger rectTrigger = (RectTrigger)list2[k];
                    if (rectTrigger.activateOnExplosion && rectTrigger.Rect.Contains(c))
                    {
                        rectTrigger.ActivatedBy(null);
                    }
                }
            }
        }