Beispiel #1
0
        protected override void Impact(Thing hitThing)
        {
            if (this.def.projectile.explosionDelay == 0)
            {
                this.Explode();
                return;
            }
            if (hitThing != null)
            {
                foreach (IntVec3 current in hitThing.CellsAdjacent8WayAndInside())
                {
                    Log.Message("4 MoteMaker");

                    MoteMaker.ThrowDustPuff(current, this.Map, 2f);
                    var t = GenClosest.ClosestThingReachable(hitThing.Position, hitThing.Map,
                                                             ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.ClosestTouch,
                                                             TraverseParms.For((Pawn)hitThing, Danger.Deadly, TraverseMode.ByPawn),
                                                             9999, new Predicate <Thing>(this.IsValidTarget), null, 0, -1, false,
                                                             RegionType.Set_Passable, false);
                    var pawn = t as Pawn;
                    pawn?.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Wander_Psychotic, null,
                                                                           false, false, null, false);
                }
            }
            this.landed            = true;
            this.ticksToDetonation = this.def.projectile.explosionDelay;
            GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
        }
Beispiel #2
0
        private void DropBomb()
        {
            for (int i = 0; i < (bombType == BombingType.precise ? this.precisionBombingNumBombs : 1); ++i)
            {
                if (innerContainer.Any(x => ((ActiveDropPod)x)?.Contents.innerContainer.Any(y => SRTSMod.mod.settings.allowedBombs.Contains(y.def.defName)) ?? false))
                {
                    ActiveDropPod srts = (ActiveDropPod)innerContainer.First();

                    Thing thing = srts?.Contents.innerContainer.FirstOrDefault(y => SRTSMod.mod.settings.allowedBombs.Contains(y.def.defName));
                    if (thing is null)
                    {
                        return;
                    }

                    Thing thing2 = srts?.Contents.innerContainer.Take(thing, 1);

                    IntVec3 bombPos = bombCells[0];
                    if (bombType == BombingType.carpet)
                    {
                        bombCells.RemoveAt(0);
                    }
                    int timerTickExplode = 20 + Rand.Range(0, 5); //Change later to allow release timer
                    if (SRTSHelper.CEModLoaded)
                    {
                        goto Block_CEPatched;
                    }
                    FallingBomb bombThing = new FallingBomb(thing2, thing2.TryGetComp <CompExplosive>(), this.Map, this.def.skyfaller.shadow);
                    bombThing.HitPoints      = int.MaxValue;
                    bombThing.ticksRemaining = timerTickExplode;

                    IntVec3 c = (from x in GenRadial.RadialCellsAround(bombPos, GetCurrentTargetingRadius(), true)
                                 where x.InBounds(this.Map)
                                 select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(this.Position) / GetCurrentTargetingRadius(), 1f) + 0.05f);
                    bombThing.angle = this.angle + (SPTrig.LeftRightOfLine(this.DrawPosCell, this.Position, c) * -10);
                    bombThing.speed = (float)SPExtra.Distance(this.DrawPosCell, c) / bombThing.ticksRemaining;
                    Thing t = GenSpawn.Spawn(bombThing, c, this.Map);
                    GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(t, thing2.TryGetComp <CompExplosive>().Props.explosiveDamageType, null);
                    continue;

                    Block_CEPatched :;
                    ThingComp     CEComp      = (thing2 as ThingWithComps)?.AllComps.Find(x => x.GetType().Name == "CompExplosiveCE");
                    FallingBombCE CEbombThing = new FallingBombCE(thing2, CEComp.props, CEComp, this.Map, this.def.skyfaller.shadow);
                    CEbombThing.HitPoints      = int.MaxValue;
                    CEbombThing.ticksRemaining = timerTickExplode;
                    IntVec3 c2 = (from x in GenRadial.RadialCellsAround(bombPos, GetCurrentTargetingRadius(), true)
                                  where x.InBounds(this.Map)
                                  select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(this.Position) / GetCurrentTargetingRadius(), 1f) + 0.05f);
                    CEbombThing.angle = this.angle + (SPTrig.LeftRightOfLine(this.DrawPosCell, this.Position, c2) * -10);
                    CEbombThing.speed = (float)SPExtra.Distance(this.DrawPosCell, c2) / CEbombThing.ticksRemaining;
                    Thing CEt = GenSpawn.Spawn(CEbombThing, c2, this.Map);
                    //GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(CEt, DamageDefOf., null); /*Is GenExplosion CE compatible?*/
                }
            }
            if (bombType == BombingType.precise && bombCells.Any())
            {
                bombCells.Clear();
            }
        }
 public void StartWick(Thing instigator = null)
 {
     if (!this.wickStarted && !(this.ExplosiveRadius() <= 0.0))
     {
         this.instigator    = instigator;
         this.wickStarted   = true;
         this.wickTicksLeft = this.Props.wickTicks.RandomInRange;
         this.StartWickSustainer();
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(base.parent, this.Props.explosiveDamageType, null);
     }
 }
 protected override void Impact(Thing hitThing)
 {
     if (this.def.projectile.explosionDelay == 0)
     {
         this.Explode();
         return;
     }
     this.landed            = true;
     this.ticksToDetonation = this.def.projectile.explosionDelay;
     GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
 }
Beispiel #5
0
 public void StartWick(Thing instigator = null)
 {
     if (!wickStarted && !(ExplosiveRadius() <= 0f))
     {
         this.instigator = instigator;
         wickStarted     = true;
         wickTicksLeft   = Props.wickTicks.RandomInRange;
         StartWickSustainer();
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(parent, Props.explosiveDamageType);
     }
 }
Beispiel #6
0
 public void StartWick(Thing instigator = null)
 {
     if (this.wickStarted)
     {
         return;
     }
     this.instigator    = instigator;
     this.wickStarted   = true;
     this.wickTicksLeft = this.Props.wickTicks.RandomInRange;
     this.StartWickSustainer();
     GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this.parent, this.Props.explosiveDamageType, null);
 }
 protected virtual void ImpactExplode(Thing hitThing)
 {
     if (base.def.projectile.explosionDelay == 0)
     {
         this.Explode();
     }
     else
     {
         base.landed            = true;
         this.ticksToDetonation = base.def.projectile.explosionDelay;
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, base.def.projectile.damageDef, base.launcher.Faction);
     }
 }
 protected override void Impact(Thing hitThing)
 {
     if (def.projectile.explosionDelay == 0)
     {
         Explode();
     }
     else
     {
         landed            = true;
         ticksToDetonation = def.projectile.explosionDelay;
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, def.projectile.damageDef, launcher.Faction);
     }
 }
        public static bool Impact(Projectile_Explosive __instance, Thing hitThing)
        {
            if (__instance.def.projectile.explosionDelay == 0)
            {
                Explode(__instance);
                return(false);
            }

            Projectile_Patch.landed(__instance) = true;
            ticksToDetonation(__instance)       = __instance.def.projectile.explosionDelay;
            GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(__instance, __instance.def.projectile.damageDef, Projectile_Patch.launcher(__instance).Faction);
            return(false);
        }
        //public static void NotifyNearbyPawnsOfDangerousExplosive(Thing exploder, DamageDef damage, Faction onlyFaction = null)
        public static void NOFACTIONNotifyNearbyPawnsOfDangerousExplosive(Thing exploder, DamageDef damage, Faction onlyFaction = null, Thing launcher = null)
        {
            Faction actualFaction = onlyFaction;

            if (Mod.settings.dodgeGrenadeEnemy && onlyFaction != Faction.OfPlayer)
            {
                actualFaction = null;
            }
            if (Mod.settings.dodgeGrenadeNPC && onlyFaction == Faction.OfPlayer)
            {
                actualFaction = null;
            }
            GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(exploder, damage, actualFaction, launcher);
        }
 public new void StartWick(Thing instigator = null)
 {
     if (this.wickStarted)
     {
         return;
     }
     if (this.ExplosiveRadius() <= 0f)
     {
         return;
     }
     this.wickStarted   = true;
     this.wickTicksLeft = this.Props.wickTicks.RandomInRange;
     GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this.parent, this.Props.explosiveDamageType, null);
 }
Beispiel #12
0
 static bool Prefix(ref Projectile_Explosive __instance, Thing hitThing, ref bool ___landed, ref int ___ticksToDetonation, ref Projectile ___launcher)
 {
     if (__instance.def.projectile.explosionDelay == 0)
     {
         Explode(__instance);
     }
     else
     {
         ___landed            = true;
         ___ticksToDetonation = __instance.def.projectile.explosionDelay / RefcellRespeedConfig.currentTimeMultiplier;
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive((Thing)__instance,
                                                            __instance.def.projectile.damageDef, ___launcher.Faction);
     }
     return(false);
 }
Beispiel #13
0
 public void StartWick(bool silent)
 {
     if (wickStarted && !silent)
     {
         wickIsSilent = false;
     }
     if (wickStarted)
     {
         return;
     }
     wickIsSilent   = silent;
     wickStarted    = true;
     wickTotalTicks = wickTicksLeft = ExplosiveProps.wickTicks.RandomInRange;
     if (ExplosiveProps.explosiveDamageType != null)
     {
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(parent, ExplosiveProps.explosiveDamageType);
     }
 }
 protected override void Impact(Thing hitThing)
 {
     // Snap to target so we hit multi-tile pawns with our explosion
     if (hitThing is Pawn)
     {
         var newPos = hitThing.DrawPos;
         newPos.y      = ExactPosition.y;
         ExactPosition = newPos;
         Position      = ExactPosition.ToIntVec3();
     }
     if (def.projectile.explosionDelay == 0)
     {
         Explode();
         return;
     }
     landed            = true;
     ticksToDetonation = def.projectile.explosionDelay;
     GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher?.Faction);
 }
Beispiel #15
0
        public override void Impact()
        {
            if (Payload != null)
            {
                if (Payload.projectile.explosionDelay == 0)
                {
                    this.Explode();
                    return;
                }
                this.landed            = true;
                this.ticksToDetonation = Payload.projectile.explosionDelay;
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, Payload.projectile.damageDef, this.launcher.Faction);
            }
            else
            if (this.def.skyfaller.CausesExplosion)
            {
                //	Log.Message("CausesExplosion");
                GenExplosion.DoExplosion(base.Position, base.Map, this.def.skyfaller.explosionRadius, this.def.skyfaller.explosionDamage, null, GenMath.RoundRandom((float)this.def.skyfaller.explosionDamage.defaultDamage * this.def.skyfaller.explosionDamageFactor), -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false, null, (!this.def.skyfaller.damageSpawnedThings) ? this.innerContainer.ToList <Thing>() : null);
            }
            //	this.SpawnThings();
            this.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish);
            CellRect cellRect = this.OccupiedRect();

            for (int i = 0; i < cellRect.Area * this.def.skyfaller.motesPerCell; i++)
            {
                AdeptusMoteMaker.ThrowDustPuff(cellRect.RandomVector3, base.Map, 2f);
            }
            if (this.def.skyfaller.MakesShrapnel)
            {
                SkyfallerShrapnelUtility.MakeShrapnel(base.Position, base.Map, this.shrapnelDirection, this.def.skyfaller.shrapnelDistanceFactor, this.def.skyfaller.metalShrapnelCountRange.RandomInRange, this.def.skyfaller.rubbleShrapnelCountRange.RandomInRange, true);
            }
            if (this.def.skyfaller.cameraShake > 0f && base.Map == Find.CurrentMap)
            {
                Find.CameraDriver.shaker.DoShake(this.def.skyfaller.cameraShake);
            }
            if (this.def.skyfaller.impactSound != null)
            {
                this.def.skyfaller.impactSound.PlayOneShot(SoundInfo.InMap(new TargetInfo(base.Position, base.Map, false), MaintenanceType.None));
            }
            this.Destroy(DestroyMode.Vanish);
        }
        protected override void Impact(Thing hitThing)
        {
            base.Impact(hitThing);
            ThingDef def = this.def;

            if (!this.initialized)
            {
                caster = this.launcher as Pawn;
                CompAbilityUserMight comp = caster.GetComp <CompAbilityUserMight>();
                verVal = TM_Calc.GetMightSkillLevel(caster, comp.MightData.MightPowerSkill_ShotgunSpec, "TM_ShotgunSpec", "_ver", true);
                this.explosionCount = 5;
                if (verVal >= 3)
                {
                    this.explosionCount++;
                }
                this.initialized = true;
            }

            landed            = true;
            ticksToDetonation = def.projectile.explosionDelay;
            GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, def.projectile.damageDef, launcher.Faction);
        }
Beispiel #17
0
 public override void Impact(Thing hitThing)
 {
     if (this.def.projectile.explosionRadius > 0)
     {
         if (this.def.projectile.explosionDelay == 0)
         {
             this.Explode(hitThing);
             base.Impact(hitThing);
             return;
         }
         this.landed            = true;
         this.ticksToDetonation = this.def.projectile.explosionDelay;
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
     }
     else
     if (this.def.projectile.explosionEffect != null)
     {
         Effecter effecter = this.def.projectile.explosionEffect.Spawn();
         effecter.Trigger(new TargetInfo(base.Position, this.Map, false), new TargetInfo(base.Position, Map, false));
         effecter.Cleanup();
     }
     base.Impact(hitThing);
 }
Beispiel #18
0
 // Token: 0x060052C8 RID: 21192 RVA: 0x002628C0 File Offset: 0x00260CC0
 public override void Impact(Thing hitThing)
 {
     if (hitThing is Pawn)
     {
         Vector3 drawPos = hitThing.DrawPos;
         drawPos.y          = this.ExactPosition.y;
         this.ExactPosition = drawPos;
         base.Position      = this.ExactPosition.ToIntVec3();
     }
     if (this.def.projectile.explosionDelay == 0)
     {
         base.Impact(hitThing);
         return;
     }
     else
     {
         this.landed            = true;
         this.ticksToDetonation = this.def.projectile.explosionDelay;
         DamageDef damageDef = this.def.projectile.damageDef;
         Thing     launcher  = this.launcher;
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, damageDef, (launcher != null) ? launcher.Faction : null);
     }
     base.Impact(hitThing);
 }
Beispiel #19
0
        protected override void Impact(Thing hitThing)
        {
            this.hitThing = hitThing;
            bool shielded = hitThing.IsShielded() && def.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = (destination - origin).normalized;

            dir.y = 0;

            Vector3 a = origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength);
            Vector3 b;

            if (hitThing == null)
            {
                b = destination;
            }
            else if (shielded)
            {
                b = hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f;
            }
            else if ((destination - hitThing.TrueCenter()).magnitude < 1)
            {
                b = destination;
            }
            else
            {
                b    = hitThing.TrueCenter();
                b.x += Rand.Range(-0.5f, 0.5f);
                b.z += Rand.Range(-0.5f, 0.5f);
            }

            a.y = b.y = def.Altitude;

            //    SpawnBeam(a, b);

            if (this.def.projectile.explosionRadius > 0f)
            {
                this.Explode(hitThing, false);
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
            }

            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }
            if (weapon == null)
            {
                Building_LaserGun turret = launcher as Building_LaserGun;
                if (turret != null)
                {
                    weapon = turret.gun as IDrawnWeaponWithRotation;
                }
            }
            if (weapon != null)
            {
                float angle = (b - a).AngleFlat() - (intendedTarget.CenterVector3 - a).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }

            if (hitThing == null)
            {
                Rand.PushState();
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                Rand.PopState();
                if (flag2)
                {
                    FireUtility.TryStartFireIn(b.ToIntVec3(), pawn.Map, 0.01f);
                }
            }
            else
            {
                if (hitThing is Pawn && shielded)
                {
                    weaponDamageMultiplier *= def.shieldDamageMultiplier;

                    SpawnBeamReflections(a, b, 5);
                }

                Rand.PushState();
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                Rand.PopState();
                if (flag2)
                {
                    hitThing.TryAttachFire(0.01f);
                }
                AddeEffects(hitThing);
            }
            //    TriggerEffect(def.explosionEffect, b, hitThing);
            Map     map      = base.Map;
            IntVec3 position = base.Position;

            GenClamor.DoClamor(this, 2.1f, ClamorDefOf.Impact);
            this.Destroy(DestroyMode.Vanish);
            BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, this.equipmentDef, this.def, this.targetCoverDef);

            Find.BattleLog.Add(battleLogEntry_RangedImpact);
            this.NotifyImpact(hitThing, map, position);
            if (hitThing != null)
            {
                DamageInfo dinfo = new DamageInfo(this.def.projectile.damageDef, (float)this.DamageAmount, this.ArmorPenetration, this.ExactRotation.eulerAngles.y, this.launcher, null, this.equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                if (pawn != null && pawn.stances != null && pawn.BodySize <= this.def.projectile.StoppingPower + 0.001f)
                {
                    pawn.stances.StaggerFor(95);
                }
                if (this.def.projectile.extraDamages == null)
                {
                    return;
                }
                using (List <ExtraDamage> .Enumerator enumerator = this.def.projectile.extraDamages.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ExtraDamage extraDamage = enumerator.Current;
                        if (Rand.Chance(extraDamage.chance))
                        {
                            DamageInfo dinfo2 = new DamageInfo(extraDamage.def, extraDamage.amount, extraDamage.AdjustedArmorPenetration(), this.ExactRotation.eulerAngles.y, this.launcher, null, this.equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                            hitThing.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_RangedImpact);
                        }
                    }
                    return;
                }
            }
            SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
            if (base.Position.GetTerrain(map).takeSplashes)
            {
                MoteMaker.MakeWaterSplash(this.ExactPosition, map, Mathf.Sqrt((float)base.DamageAmount) * 1f, 4f);
                return;
            }
            //    MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
        }
        protected override void Impact(Thing hitThing)
        {
            Pawn pawn = hitThing as Pawn;

            if (hitThing != null)
            {
                Map map = base.Map;
                BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, this.equipmentDef, this.def, this.targetCoverDef);
                Find.BattleLog.Add(battleLogEntry_RangedImpact);
                float  explodeRoll   = Rand.Range(0, 100);
                float  explodeChance = Def.DetonationChance;
                string logroll       = string.Format("rolled {0} needs less than {1} to detonate", explodeRoll, explodeChance);
                //    Log.Message(logroll);
                if (explodeRoll < explodeChance && hitThing == this.intendedTarget.Thing & hitThing.def.category == ThingCategory.Pawn && hitThing.Spawned && hitThing != null)
                {
                    if (this.def.projectile.explosionDelay == 0)
                    {
                        this.Destroy(DestroyMode.Vanish);
                        if (this.def.projectile.explosionEffect != null)
                        {
                            Effecter effecter = this.def.projectile.explosionEffect.Spawn();
                            effecter.Trigger(new TargetInfo(base.Position, map, false), new TargetInfo(base.Position, map, false));
                            effecter.Cleanup();
                        }
                        IntVec3   position         = base.Position;
                        Map       map2             = map;
                        float     explosionRadius  = Def.blastRadius;
                        DamageDef damageDef        = Def.blastdamageDef;
                        Thing     launcher         = this.launcher;
                        int       damageAmount     = Def.blastdamageAmount;
                        float     hitdmg           = (float)base.DamageAmount * Def.blastdamageAmount;
                        float     armorPenetration = Def.blastarmorPenetration;
                        SoundDef  soundExplode     = Def.blastsoundExplode;
                        ThingDef  equipmentDef     = this.equipmentDef;
                        ThingDef  def   = this.def;
                        Thing     thing = this.intendedTarget.Thing;
                        float     y     = this.ExactRotation.eulerAngles.y;
                        ThingDef  postExplosionSpawnThingDef   = this.def.projectile.postExplosionSpawnThingDef;
                        float     postExplosionSpawnChance     = this.def.projectile.postExplosionSpawnChance;
                        int       postExplosionSpawnThingCount = this.def.projectile.postExplosionSpawnThingCount;
                        ThingDef  preExplosionSpawnThingDef    = this.def.projectile.preExplosionSpawnThingDef;
                        GenExplosion.DoExplosion(position, map2, explosionRadius, damageDef, launcher, damageAmount, armorPenetration, soundExplode, equipmentDef, def, thing, postExplosionSpawnThingDef, postExplosionSpawnChance, postExplosionSpawnThingCount, this.def.projectile.applyDamageToExplosionCellsNeighbors, preExplosionSpawnThingDef, this.def.projectile.preExplosionSpawnChance, this.def.projectile.preExplosionSpawnThingCount, this.def.projectile.explosionChanceToStartFire, this.def.projectile.explosionDamageFalloff);
                        DamageInfo dinfo = new DamageInfo(damageDef, hitdmg, base.ArmorPenetration, y, launcher, null, equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                        hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                        string msg = string.Format("{0} was lost to the warp", hitThing.LabelCap);
                        if (pawn.Dead)
                        {
                            pawn.Kill(dinfo);
                        }
                        if (hitThing.Faction == Faction.OfPlayer)
                        {
                            Messages.Message(msg, MessageTypeDefOf.PawnDeath);
                        }
                        if (hitThing.Spawned == true)
                        {
                            if (((hitThing as Corpse)?.InnerPawn ?? hitThing) is Pawn hitPawn)
                            {
                                hitPawn.Corpse.Destroy(DestroyMode.KillFinalize);
                            }
                        }
                        ///this.intendedTarget.Thing.Destroy(DestroyMode.KillFinalize);
                    }
                    this.landed            = true;
                    this.ticksToDetonation = this.def.projectile.explosionDelay;
                    GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
                }
                else
                {
                    if (hitThing != null)
                    {
                        this.Destroy(DestroyMode.Vanish);
                        DamageDef  damageDef        = this.def.projectile.damageDef;
                        float      amount           = (float)base.DamageAmount;
                        float      armorPenetration = base.ArmorPenetration;
                        float      y            = this.ExactRotation.eulerAngles.y;
                        Thing      launcher     = this.launcher;
                        ThingDef   equipmentDef = this.equipmentDef;
                        DamageInfo dinfo        = new DamageInfo(damageDef, amount, armorPenetration, y, launcher, null, equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                        hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                    }
                    else
                    {
                        this.Destroy(DestroyMode.Vanish);
                        SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
                        MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
                    }
                }
            }
        }
        private void DropBomb()
        {
            for (int i = 0; i < (bombType == BombingType.precise ? this.precisionBombingNumBombs : 1); ++i)
            {
                if (innerContainer.Any(x => ((ActiveDropPod)x)?.Contents.innerContainer.Any(y => SRTSMod.mod.settings.allowedBombs.Contains(y.def.defName)) ?? false))
                {
                    ActiveDropPod srts = (ActiveDropPod)innerContainer.First();

                    Thing thing = srts?.Contents.innerContainer.FirstOrDefault(y => SRTSMod.mod.settings.allowedBombs.Contains(y.def.defName));
                    if (thing is null)
                    {
                        return;
                    }

                    Thing thing2 = srts?.Contents.innerContainer.Take(thing, 1);

                    IntVec3 bombPos = bombCells[0];
                    if (bombType == BombingType.carpet)
                    {
                        bombCells.RemoveAt(0);
                    }
                    int timerTickExplode = 20 + Rand.Range(0, 5); //Change later to allow release timer
                    if (SRTSHelper.CEModLoaded)
                    {
                        goto Block_CEPatched;
                    }
                    FallingBomb bombThing = new FallingBomb(thing2, thing2.TryGetComp <CompExplosive>(), this.Map, this.def.skyfaller.shadow);
                    bombThing.HitPoints      = int.MaxValue;
                    bombThing.ticksRemaining = timerTickExplode;

                    IntVec3 c = (from x in GenRadial.RadialCellsAround(bombPos, GetCurrentTargetingRadius(), true)
                                 where x.InBounds(this.Map)
                                 select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(this.Position) / GetCurrentTargetingRadius(), 1f) + 0.05f);
                    bombThing.angle = this.angle + (SPTrig.LeftRightOfLine(this.DrawPosCell, this.Position, c) * -10);
                    bombThing.speed = (float)SPExtra.Distance(this.DrawPosCell, c) / bombThing.ticksRemaining;
                    Thing t = GenSpawn.Spawn(bombThing, c, this.Map);
                    GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(t, thing2.TryGetComp <CompExplosive>().Props.explosiveDamageType, null);
                    continue;

                    Block_CEPatched :;
                    // Replaced referencing the projectile trough the detonateProjectile property of the item's def with referencing trough AmmoSetDef. The reason is taht not all mortar shells had detonateProjectile. Don't ask how I came up with this.
                    ProjectileCE_Explosive bombCE = (ProjectileCE_Explosive)ThingMaker.MakeThing((thing2.def as AmmoDef).AmmoSetDefs.Find(set => set.ammoTypes.Any()).ammoTypes.Find(link => link.ammo == (thing2.def as AmmoDef)).projectile, null);
                    //ProjectileCE_Explosive bombCE = (ProjectileCE_Explosive)ThingMaker.MakeThing((AccessTools.Field(thing2.def.GetType(), "detonateProjectile").GetValue(thing2.def) as ThingDef), null);

                    /*ThingComp CEComp = (thing2 as ThingWithComps)?.AllComps.Find(x => x.GetType().Name == "CompExplosiveCE");
                     * FallingBombCE CEbombThing = new FallingBombCE(thing2, CEComp.props, CEComp, this.Map, this.def.skyfaller.shadow);
                     * CEbombThing.HitPoints = int.MaxValue;
                     * CEbombThing.ticksRemaining = timerTickExplode;*/
                    IntVec3 c2 = (from x in GenRadial.RadialCellsAround(bombPos, GetCurrentTargetingRadius(), true)
                                  where x.InBounds(this.Map)
                                  select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(this.Position) / GetCurrentTargetingRadius(), 1f) + 0.05f);

                    /*CEbombThing.angle = this.angle + (SPTrig.LeftRightOfLine(this.DrawPosCell, this.Position, c2) * -10);
                     * CEbombThing.speed = (float)SPExtra.Distance(this.DrawPosCell, c2) / CEbombThing.ticksRemaining;
                     * Thing CEt = GenSpawn.Spawn(CEbombThing, c2, this.Map);*/
                    //Basically Im stea- "borrrowing" code from Verb_LaunchProjectileCE.
                    GenSpawn.Spawn(bombCE, this.DrawPosCell, this.Map);
                    bombCE.canTargetSelf        = false;
                    bombCE.minCollisionDistance = 1;
                    bombCE.intendedTarget       = null;
                    bombCE.AccuracyFactor       = 1f;
                    bombCE.Launch(this,
                                  this.DrawPosCell.ToIntVec2.ToVector2(),
                                  0f,
                                  this.angle + UnityEngine.Random.Range(-60f, 60f),
                                  5f,
                                  (float)SPExtra.Distance(this.DrawPosCell, c2),
                                  this);
                    //GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(CEt, DamageDefOf., null); /*Is GenExplosion CE compatible?*/
                }
            }
            if (bombType == BombingType.precise && bombCells.Any())
            {
                bombCells.Clear();
            }
        }
Beispiel #22
0
        protected override void Impact(Thing hitThing)
        {
            bool shielded = hitThing.IsShielded() && def.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = (destination - origin).normalized;

            dir.y = 0;

            Vector3 a = origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength);
            Vector3 b = shielded ? hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f : destination;

            a.y = b.y = def.Altitude;

            SpawnBeam(a, b);
            bool createsExplosion = this.def.projectile.explosionRadius > 0f;

            if (createsExplosion)
            {
                this.Explode(hitThing, false);
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
            }
            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }
            if (weapon == null)
            {
                Building_LaserGun turret = launcher as Building_LaserGun;
                if (turret != null)
                {
                    weapon = turret.gun as IDrawnWeaponWithRotation;
                }
            }
            if (weapon != null)
            {
                float angle = (b - a).AngleFlat() - (intendedTarget.CenterVector3 - a).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }

            if (hitThing == null)
            {
                TriggerEffect(def.explosionEffect, destination);
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                if (flag2)
                {
                    FireUtility.TryStartFireIn(destination.ToIntVec3(), pawn.Map, 0.05f);
                }
            }
            else
            {
                if (hitThing is Pawn)
                {
                    Pawn hitPawn = hitThing as Pawn;
                    if (shielded)
                    {
                        weaponDamageMultiplier *= def.shieldDamageMultiplier;

                        SpawnBeamReflections(a, b, 5);
                    }
                }

                bool flag2 = this.def.causefireChance > 0f && Rand.Range(0f, 1f) > this.def.causefireChance;
                if (flag2)
                {
                    hitThing.TryAttachFire(0.05f);
                }
                TriggerEffect(def.explosionEffect, ExactPosition);
            }
            if (def.HediffToAdd != null)
            {
                AddedEffect(hitThing);
            }
            Map map = base.Map;

            base.Impact(hitThing);
            BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, this.equipmentDef, this.def, this.targetCoverDef);

            Find.BattleLog.Add(battleLogEntry_RangedImpact);
            if (hitThing != null)
            {
                DamageDef  damageDef        = this.def.projectile.damageDef;
                float      amount           = DamageAmount;
                float      armorPenetration = ArmorPenetration;
                float      y            = this.ExactRotation.eulerAngles.y;
                Thing      launcher     = this.launcher;
                ThingDef   equipmentDef = this.equipmentDef;
                DamageInfo dinfo        = new DamageInfo(damageDef, amount, armorPenetration, y, launcher, null, equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                Pawn hitPawn = hitThing as Pawn;
                if (hitPawn != null && hitPawn.stances != null && hitPawn.BodySize <= this.def.projectile.StoppingPower + 0.001f)
                {
                    hitPawn.stances.StaggerFor(95);
                }
            }
            else
            {
                SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
                MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
                if (base.Position.GetTerrain(map).takeSplashes)
                {
                    MoteMaker.MakeWaterSplash(this.ExactPosition, map, Mathf.Sqrt((float)base.DamageAmount) * 1f, 4f);
                }
            }
        }
Beispiel #23
0
        protected override void Impact(Thing hitThing)
        {
            bool shielded = hitThing.IsShielded() && def.IsWeakToShields;

            LaserGunDef defWeapon = equipmentDef as LaserGunDef;
            Vector3     dir       = (destination - origin).normalized;

            dir.y = 0;

            Vector3 a = origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength);
            Vector3 b = shielded ? hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f : destination;

            a.y = b.y = def.Altitude;

            SpawnBeam(a, b);
            bool createsExplosion = this.def.canExplode && this.def.projectile.explosionRadius > 0f;

            if (createsExplosion)
            {
                this.Explode(hitThing, false);
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction);
            }
            Pawn pawn = launcher as Pawn;
            IDrawnWeaponWithRotation weapon = null;

            if (pawn != null && pawn.equipment != null)
            {
                weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation;
            }

            /* if (weapon == null) {
             *   Building_LaserGun turret = launcher as Building_LaserGun;
             *   if (turret != null) {
             *       weapon = turret.gun as IDrawnWeaponWithRotation;
             *   }
             * }
             */
            if (weapon != null)
            {
                float angle = (b - a).AngleFlat() - (intendedTarget.CenterVector3 - a).AngleFlat();
                weapon.RotationOffset = (angle + 180) % 360 - 180;
            }

            if (hitThing == null)
            {
                TriggerEffect(def.explosionEffect, destination);
                bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance);
                if (flag2)
                {
                    FireUtility.TryStartFireIn(destination.ToIntVec3(), pawn.Map, 0.05f);
                }
            }
            else
            {
                if (hitThing is Pawn)
                {
                    Pawn hitPawn = hitThing as Pawn;
                    if (shielded)
                    {
                        weaponDamageMultiplier *= def.shieldDamageMultiplier;

                        SpawnBeamReflections(a, b, 5);
                    }
                }

                bool flag2 = this.def.causefireChance > 0f && Rand.Range(0f, 1f) > this.def.causefireChance;
                if (flag2)
                {
                    hitThing.TryAttachFire(0.05f);
                }
                TriggerEffect(def.explosionEffect, ExactPosition);
            }
            base.Impact(hitThing);
        }