Example #1
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            var projectileProps = ShellDef.projectile;

            ShieldGeneratorUtility.CheckIntercept(this, map, projectileProps.GetDamageAmount(1), projectileProps.damageDef, () => this.OccupiedRect().Cells,
                                                  postIntercept: s =>
            {
                if (s.Energy > 0)
                {
                    Destroy();
                }
            });
        }
Example #2
0
            public static bool Prefix(Explosion explosion, IntVec3 c)
            {
                bool executeOriginal = true;

                ShieldGeneratorUtility.CheckIntercept(explosion, explosion.Map, explosion.damAmount, explosion.damType, () => new List <IntVec3>()
                {
                    c
                }, () => explosion.damType.AffectsShields(),
                                                      s =>
                {
                    executeOriginal = s.WithinBoundary(explosion.Position, c);
                    return(!s.affectedThings.ContainsKey(explosion));
                },
                                                      s =>
                {
                    var cellsToAffect = (List <IntVec3>)NonPublicFields.Explosion_cellsToAffect.GetValue(explosion);
                    int cacheDuration = cellsToAffect.Select(eC => NonPublicMethods.Explosion_GetCellAffectTick(explosion, eC)).Max();
                    s.affectedThings.Add(explosion, cacheDuration);
                });
                return(executeOriginal);
            }
Example #3
0
            public static void Prefix(Skyfaller __instance) //patch the tick, not the creation - means shields can turn on in time to do something
            {
                if (__instance.Map != null && __instance.ticksToImpact <= 20)
                {
                    var thingDefExtension = __instance.def.GetModExtension <ThingDefExtension>() ?? ThingDefExtension.defaultValues;
                    ShieldGeneratorUtility.CheckIntercept(__instance, __instance.Map, thingDefExtension.shieldDamageIntercepted, DamageDefOf.Blunt, () => __instance.OccupiedRect().Cells, () => thingDefExtension.shieldDamageIntercepted > -1,
                                                          postIntercept: s =>
                    {
                        if (s.Energy > 0)
                        {
                            switch (__instance)
                            {
                            case DropPodIncoming dropPod:
                                if (ShieldGeneratorUtility.CheckPodHostility(dropPod))
                                {
                                    var innerContainer = dropPod.Contents.innerContainer;
                                    for (int i = 0; i < innerContainer.Count; i++)
                                    {
                                        var thing = innerContainer[i];
                                        if (thing is Pawn pawn)
                                        {
                                            ShieldGeneratorUtility.KillPawn(pawn, dropPod.Position, dropPod.Map);
                                        }
                                    }
                                    dropPod.Destroy();
                                    return;
                                }
                                return;

                            case DropPodLeaving _:
                                return;

                            default:
                                __instance.Destroy();
                                return;
                            }
                        }
                    });
                }
            }