Beispiel #1
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)      //Add mannableComp, ticksUntilAutoReload, register to GenClosestAmmo
        {
            base.SpawnSetup(map, respawningAfterLoad);
            dormantComp  = GetComp <CompCanBeDormant>();
            powerComp    = GetComp <CompPowerTrader>();
            mannableComp = GetComp <CompMannable>();
            if (!respawningAfterLoad)
            {
                CELogger.Message($"top is {top?.ToString() ?? "null"}");
                top.SetRotationFromOrientation();
                burstCooldownTicksLeft = def.building.turretInitialCooldownTime.SecondsToTicks();

                //Delay auto-reload for a few seconds after spawn, so player can operate the turret right after placing it, before other colonists start reserving it for reload jobs
                if (mannableComp != null)
                {
                    ticksUntilAutoReload = minTicksBeforeAutoReload;
                }
            }

            // if (CompAmmo == null || CompAmmo.Props == null || CompAmmo.Props.ammoSet == null || CompAmmo.Props.ammoSet.ammoTypes.NullOrEmpty())
            //     return;

            // //"Subscribe" turret to GenClosestAmmo
            // foreach (var ammo in CompAmmo.Props.ammoSet.ammoTypes.Select(x => x.ammo))
            // {
            //     if (!GenClosestAmmo.listeners.ContainsKey(ammo))
            //         GenClosestAmmo.listeners.Add(ammo, new List<Building_TurretGunCE>() { this });
            //     else
            //         GenClosestAmmo.listeners[ammo].Add(this);

            //     if (!GenClosestAmmo.latestAmmoUpdate.ContainsKey(ammo))
            //         GenClosestAmmo.latestAmmoUpdate.Add(ammo, 0);
            // }
        }
Beispiel #2
0
        public override void SpawnSetup(Map map)
        {
            base.SpawnSetup(map);
            this.powerComp    = base.GetComp <CompPowerTrader>();
            this.mannableComp = base.GetComp <CompMannable>();
            if (gun == null)
            {
                this.gun = ThingMaker.MakeThing(this.def.building.turretGunDef, null);
            }
            for (int i = 0; i < this.GunCompEq.AllVerbs.Count; i++)
            {
                Verb verb = this.GunCompEq.AllVerbs[i];
                verb.caster = this;
                verb.castCompleteCallback = new Action(this.BurstComplete);
            }
            this.top = new TurretTopCR(this);

            // Callback for ammo comp
            if (compAmmo != null)
            {
                compAmmo.turret = this;
                if (def.building.turretShellDef != null && def.building.turretShellDef is AmmoDef)
                {
                    compAmmo.selectedAmmo = (AmmoDef)def.building.turretShellDef;
                }
            }
        }
        public bool ThreatDisabled()
        {
            if (GetComp <CompExplosive>().wickStarted)
            {
                return(true);
            }

            if (!mountableComp.IsMounted)
            {
                return(true);
            }

            CompPowerTrader comp = GetComp <CompPowerTrader>();

            if (comp == null || !comp.PowerOn)
            {
                CompMannable comp2 = GetComp <CompMannable>();
                if (comp2 == null || !comp2.MannedNow)
                {
                    return(!mountableComp.IsMounted);

                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// This is called seperately when the Mod-Thread is done.
        /// It is needed to be seperately from SpawnSetup, so that the graphics can be found
        /// </summary>
        private void SpawnSetup_Part2()
        {
            powerComp    = base.GetComp <CompPowerTrader>();
            mannableComp = base.GetComp <CompMannable>();

            ReadXmlData();

            if (forceCreateGunAndTop)
            {
                CreateGunAndTop(gun);
            }
            else
            {
                gun = null;
                top = null;
            }

            // When not of colony, equip a Mortar Bomb as main weapon.
            if (Faction != Faction.OfPlayer)
            {
                def.building.turretGunDef = ThingDef.Named("Artillery_MortarBomb");
                this.gun = (Thing)ThingMaker.MakeThing(def.building.turretGunDef, null);

                List <Verb> allVerbs = this.GunCompEq.AllVerbs;

                for (int i = 0; i < allVerbs.Count; i++)
                {
                    Verb item = allVerbs[i];
                    item.caster = this;
                    item.castCompleteCallback = new Action(this.BurstComplete);
                }

                top = new TurretTop_TurretWeaponBase(this);
            }
        }
Beispiel #5
0
        /*[HarmonyPatch(typeof(Verb_LaunchProjectile), "HighlightFieldRadiusAroundTarget")]
         * static class Harmony_Verb_LaunchProjectile_HighlightFieldRadiusAroundTarget
         * {
         *  static bool Prefix(ref float __result, Verb_LaunchProjectile __instance, LocalTargetInfo ___currentTarget, out bool needLOSToCenter)
         *  {
         *      if (__instance.verbProps.forcedMissRadius < 0.5f || __instance.verbProps.requireLineOfSight)
         *      {
         *          // Assuming this is not a mortar-like thing
         *          // Perform vanilla logic
         *          needLOSToCenter = true;
         *          return true;
         *      }
         *      if (!Settings.showAccuracyRadius)
         *      {
         *          needLOSToCenter = true;
         *          return true;
         *      }
         *      else
         *      {
         *          needLOSToCenter = false;
         *
         *          float missRadius = GetAdjustedForcedMissRadius(__instance, ___currentTarget);
         *          if (missRadius < 1)
         *          {
         *              missRadius = 1f;
         *          }
         *          __result = missRadius;
         *
         *          // Skip normal execution, we will draw our own overlay
         *          return false;
         *      }
         *  }
         * }*/

        static float GetAdjustedForcedMissRadius(Verb_LaunchProjectile shootVerb, LocalTargetInfo ___currentTarget)
        {
            if (shootVerb.verbProps.forcedMissRadius < 0.5f || shootVerb.verbProps.requireLineOfSight)
            {
                return(0);
            }
            else
            {
                Pawn         shooterPawn  = null;
                CompMannable compMannable = shootVerb.caster.TryGetComp <CompMannable>();
                if (compMannable != null && compMannable.ManningPawn != null)
                {
                    shooterPawn = compMannable.ManningPawn;
                }
                else
                {
                    shooterPawn = shootVerb.CasterPawn;
                }
                // Grab default forced miss radius for this particular weapon
                float missRadiusForShot = shootVerb.verbProps.forcedMissRadius;
                float skillMultiplier   = 1f;
                // We want to multiply this forced miss radius by our pawn's skill modifier
                if (shooterPawn != null && shooterPawn.skills != null)
                {
                    int totalSkill    = 0;
                    int skillsTotaled = 0;
                    if (Settings.intellectualAffectsMortarAccuracy)
                    {
                        totalSkill += shooterPawn.skills.GetSkill(SkillDefOf.Intellectual).Level;
                        skillsTotaled++;
                    }
                    if (Settings.shootingAffectsMortarAccuracy)
                    {
                        totalSkill += shooterPawn.skills.GetSkill(SkillDefOf.Shooting).Level;
                        skillsTotaled++;
                    }

                    if (skillsTotaled > 0)
                    {
                        // get average skill
                        int averageSkill = (int)(((float)totalSkill) / skillsTotaled);
                        skillMultiplier = 1 - ((averageSkill - SkillRecord.MinLevel) * (Settings.maxSkillSpreadReduction - Settings.minSkillSpreadReduction) / (SkillRecord.MaxLevel - SkillRecord.MinLevel) + Settings.minSkillSpreadReduction);
                    }
                }
                // Weather should affect shot no matter what the skill is
                if (Settings.weatherAffectsMortarAccuracy)
                {
                    missRadiusForShot = (missRadiusForShot * skillMultiplier) + ((1 - shootVerb.caster.Map.weatherManager.CurWeatherAccuracyMultiplier) * missRadiusForShot);
                }
                else
                {
                    missRadiusForShot = (missRadiusForShot * skillMultiplier);
                }

                // TODO: this is wrong. __curentTarget.Cell is origin when we are hovering over it, preview is incorrect
                return(VerbUtility.CalculateAdjustedForcedMiss(missRadiusForShot, ___currentTarget.Cell - shootVerb.caster.Position));
            }
        }
Beispiel #6
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     this.powerComp              = this.GetComp <CompPowerTrader>();
     this.mannableComp           = this.GetComp <CompMannable>();
     this.currentTargetInt       = LocalTargetInfo.Invalid;
     this.burstWarmupTicksLeft   = 0;
     this.burstCooldownTicksLeft = 0;
 }
        // Token: 0x06002252 RID: 8786 RVA: 0x000D128C File Offset: 0x000CF48C
        protected override bool TryCastShot()
        {
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = this.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine shootLine;
            bool      flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLine);

            if (this.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (base.EquipmentSource != null)
            {
                CompChangeableProjectile comp = base.EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
            }
            Thing        launcher     = this.caster;
            Thing        equipment    = base.EquipmentSource;
            CompMannable compMannable = this.caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = this.caster;
            }
            Vector3            drawPos               = this.caster.DrawPos;
            Projectile         projectile2           = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, this.caster.Map, WipeMode.Vanish);
            ShotReport         shotReport            = ShotReport.HitReportFor(this.caster, this, this.currentTarget);
            Thing              randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef           targetCoverDef        = (randomCoverToMissInto != null) ? randomCoverToMissInto.def : null;
            ProjectileHitFlags projectileHitFlags4   = ProjectileHitFlags.IntendedTarget;

            this.ThrowDebugText("ToHit" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
            if (this.currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, this.currentTarget, this.currentTarget, projectileHitFlags4, false, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", this.currentTarget.Cell);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags4, false, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", shootLine.Dest);
            }
            return(true);
        }
        private bool ShouldApply(StatRequest req, out CompMannable mannableComp)
        {
            mannableComp = null;
            if (req.Thing is Building_Turret turret && TurretFrameworkExtension.Get(turret.def).useManningPawnShootingAccuracy)
            {
                mannableComp = turret.GetComp <CompMannable>();
            }

            return(mannableComp != null);
        }
Beispiel #9
0
 // Added CompAmmo setup
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     powerComp    = base.GetComp <CompPowerTrader>();
     mannableComp = base.GetComp <CompMannable>();
     if (mannableComp != null && !respawningAfterLoad)
     {
         //Delay auto-reload for a few seconds after spawn, so player can operate the turret right after placing it, before other colonists start reserving it for reload jobs
         ticksUntilAutoReload = minTicksBeforeAutoReload;
     }
 }
Beispiel #10
0
 /// <summary>
 /// Attempts to find a turret operator. Accepts any Thing as input and does a sanity check to make sure it is an actual turret.
 /// </summary>
 /// <param name="thing">The turret to check for an operator</param>
 /// <returns>Turret operator if one is found, null if not</returns>
 public static Pawn TryGetTurretOperator(Thing thing)
 {
     // Building_TurretGunCE DOES NOT inherit from Building_TurretGun!!!
     if (thing is Building_Turret)
     {
         CompMannable comp = thing.TryGetComp <CompMannable>();
         if (comp != null)
         {
             return(comp.ManningPawn);
         }
     }
     return(null);
 }
        float GetAdjustedForcedMissRadius()
        {
            if (base.verbProps.forcedMissRadius > 0.5f)
            {
                CompMannable compMannable = base.caster.TryGetComp <CompMannable>();
                // Grab default forced miss radius for this particular weapon
                float missRadiusForShot = base.verbProps.forcedMissRadius;
                float skillMultiplier   = 1f;
                // We want to multiply this forced miss radius by our pawn's skill modifier
                if (compMannable != null && compMannable.ManningPawn != null && compMannable.ManningPawn.skills != null)
                {
                    int totalSkill    = 0;
                    int skillsTotaled = 0;
                    if (Settings.intellectualAffectsMortarAccuracy)
                    {
                        totalSkill += compMannable.ManningPawn.skills.GetSkill(SkillDefOf.Intellectual).Level;
                        skillsTotaled++;
                    }
                    if (Settings.shootingAffectsMortarAccuracy)
                    {
                        totalSkill += compMannable.ManningPawn.skills.GetSkill(SkillDefOf.Shooting).Level;
                        skillsTotaled++;
                    }

                    if (skillsTotaled > 0)
                    {
                        // get average skill
                        int averageSkill = (int)(((float)totalSkill) / skillsTotaled);
                        skillMultiplier = 1 - ((averageSkill - SkillRecord.MinLevel) * (Settings.maxSkillSpreadReduction - Settings.minSkillSpreadReduction) / (SkillRecord.MaxLevel - SkillRecord.MinLevel) + Settings.minSkillSpreadReduction);
                    }
                }

                // Weather should affect shot no matter what the skill is
                if (Settings.weatherAffectsMortarAccuracy)
                {
                    missRadiusForShot = (missRadiusForShot * skillMultiplier) + ((1 - caster.Map.weatherManager.CurWeatherAccuracyMultiplier) * missRadiusForShot);
                }
                else
                {
                    missRadiusForShot = (missRadiusForShot * skillMultiplier);
                }

                return(VerbUtility.CalculateAdjustedForcedMiss(missRadiusForShot, base.currentTarget.Cell - base.caster.Position));
            }
            else
            {
                return(0);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Attempts to find a turret operator. Accepts any Thing as input and does a sanity check to make sure it is an actual turret.
        /// </summary>
        /// <param name="thing">The turret to check for an operator</param>
        /// <returns>Turret operator if one is found, null if not</returns>
        public static Pawn TryGetTurretOperator(Thing thing)
        {
            Pawn manningPawn          = null;
            Building_TurretGun turret = thing as Building_TurretGun;

            if (turret != null)
            {
                CompMannable comp = turret.TryGetComp <CompMannable>();
                if (comp != null && comp.MannedNow)
                {
                    manningPawn = comp.ManningPawn;
                }
            }
            return(manningPawn);
        }
        public static void Listener(Building_TurretGun __instance, ref bool __result)
        {
            CompRemotelyControlledTurret crt = __instance.TryGetComp <CompRemotelyControlledTurret>();

            //Si pas de controlleur alors on ne peut pas controller la tourelle
            if (crt == null || crt.controller == null)
            {
                return;
            }

            CompMannable mannable = (CompMannable)mannableComp.GetValue(__instance);

            // bool controlled = (bool)PlayerControlled.GetValue(__instance);
            __result = __result || mannable == null;
        }
Beispiel #14
0
        public bool ThreatDisabled()
        {
            CompPowerTrader comp = base.GetComp <CompPowerTrader>();

            if (comp == null || !comp.PowerOn)
            {
                CompRefuelable comp3 = base.GetComp <CompRefuelable>();
                if (comp3 != null || !comp3.HasFuel)
                {
                    CompMannable comp2 = base.GetComp <CompMannable>();
                    if (comp2 == null || !comp2.MannedNow)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            powerComp    = base.GetComp <CompPowerTrader>();
            mannableComp = base.GetComp <CompMannable>();

            // added
            defaultDelay = def.building.turretBurstCooldownTime;
            if (turretBurstCooldownTime > -1)
            {
                def.building.turretBurstCooldownTime = turretBurstCooldownTime;
            }
            else
            {
                turretBurstCooldownTime = defaultDelay;
            }
            // added
        }
        // TODO make vehicles break down & get repaired like buildings
        public override bool ClaimableBy(Faction faction)
        {
            if (!mountableComp.IsMounted)
            {
                return(true);
            }

            CompPowerTrader comp = GetComp <CompPowerTrader>();

            if (comp == null || !comp.PowerOn)
            {
                CompMannable comp2 = GetComp <CompMannable>();
                if (comp2 == null || !comp2.MannedNow)
                {
                    return(true);
                }
            }
            return(false);
        }
        public override void PostSpawnSetup(bool respawningAfterLoad)
        {
            base.PostSpawnSetup(respawningAfterLoad);

            RunningTrack_southSheet.Add(RunningTrack_south0);
            RunningTrack_southSheet.Add(RunningTrack_south1);
            RunningTrack_southSheet.Add(RunningTrack_south2);
            RunningTrack_southSheet.Add(RunningTrack_south3);
            RunningTrack_southSheet.Add(RunningTrack_south4);
            RunningTrack_southSheet.Add(RunningTrack_south5);
            RunningTrack_southSheet.Add(RunningTrack_south6);
            RunningTrack_southSheet.Add(RunningTrack_south7);
            RunningTrack_southSheet.Add(RunningTrack_south8);

            RunningTrack_northSheet.Add(RunningTrack_north0);
            RunningTrack_northSheet.Add(RunningTrack_north1);
            RunningTrack_northSheet.Add(RunningTrack_north2);
            RunningTrack_northSheet.Add(RunningTrack_north3);
            RunningTrack_northSheet.Add(RunningTrack_north4);
            RunningTrack_northSheet.Add(RunningTrack_north5);
            RunningTrack_northSheet.Add(RunningTrack_north6);
            RunningTrack_northSheet.Add(RunningTrack_north7);
            RunningTrack_northSheet.Add(RunningTrack_north8);

            RunningTrack_eastSheet.Add(RunningTrack_east0);
            RunningTrack_eastSheet.Add(RunningTrack_east1);
            RunningTrack_eastSheet.Add(RunningTrack_east2);
            RunningTrack_eastSheet.Add(RunningTrack_east3);
            RunningTrack_eastSheet.Add(RunningTrack_east4);
            RunningTrack_eastSheet.Add(RunningTrack_east5);
            RunningTrack_eastSheet.Add(RunningTrack_east6);
            RunningTrack_eastSheet.Add(RunningTrack_east7);
            RunningTrack_eastSheet.Add(RunningTrack_east8);

            compMannable = parent.TryGetComp <CompMannable>();
            if (base.Props.basePowerConsumption <= 0f && !parent.IsBrokenDown() && FlickUtility.WantsToBeOn(parent))
            {
                base.PowerOn = true;
            }

            //Log.Message("RunningTrack_southSheet frames count = " + RunningTrack_southSheet.Count);
        }
        // Token: 0x06004F1C RID: 20252 RVA: 0x001AB3BC File Offset: 0x001A95BC
        public bool ThreatDisabled(IAttackTargetSearcher disabledFor)
        {
            CompPowerTrader comp = base.GetComp <CompPowerTrader>();

            if (comp != null && !comp.PowerOn)
            {
                return(true);
            }
            CompMannable comp2 = base.GetComp <CompMannable>();

            if (comp2 != null && !comp2.MannedNow)
            {
                return(true);
            }
            CompCanBeDormant comp3 = base.GetComp <CompCanBeDormant>();

            if (comp3 != null && !comp3.Awake)
            {
                return(true);
            }
            CompInitiatable comp4 = base.GetComp <CompInitiatable>();

            return(comp4 != null && !comp4.Initiated);
        }
        public override void PostSpawnSetup(bool respawningAfterLoad)
        {
            base.PostSpawnSetup(respawningAfterLoad);

            setupDone = true;

            calculated     = false;
            lastPosition   = iv3Invalid;
            lastSightRange = -9999;
            lastIsPeeking  = false;

            viewMap1 = null;
            viewMap2 = null;

            viewRect = new CellRect(-1, -1, 0, 0);

            viewPositions = new IntVec3[5];

            compHiddenable    = mainComponent.compHiddenable;
            compGlower        = parent.GetComp <CompGlower>();
            compPowerTrader   = parent.GetComp <CompPowerTrader>();
            compRefuelable    = parent.GetComp <CompRefuelable>();
            compFlickable     = parent.GetComp <CompFlickable>();
            compMannable      = parent.GetComp <CompMannable>();
            compProvideVision = parent.GetComp <CompProvideVision>();

            pawn     = parent as Pawn;
            building = parent as Building;
            turret   = parent as Building_TurretGun;

            if (pawn != null)
            {
                raceProps  = pawn.RaceProps;
                hediffs    = pawn.health.hediffSet.hediffs;
                capacities = pawn.health.capacities;
            }

            initMap();

            def = parent.def;
            if (def.race != null)
            {
                isMechanoid = def.race.IsMechanoid;
            }
            else
            {
                isMechanoid = false;
            }

            if (!isMechanoid)
            {
                baseViewRange = NON_MECH_DEFAULT_RANGE;
            }
            else
            {
                baseViewRange = MECH_DEFAULT_RANGE;
            }

            disabled = false;

            lastMovementTick       = Find.TickManager.TicksGame;
            lastPositionUpdateTick = lastMovementTick;
            updateFoV();
        }
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     powerComp = base.GetComp<CompPowerTrader>();
     WhoIsManningMe = base.GetComp<CompMannable>();
 }
        // Token: 0x060064F4 RID: 25844 RVA: 0x001B8C14 File Offset: 0x001B7014
        protected override bool TryCastShot()
        {
            //    Log.Message(string.Format("{0}, {1}, {2}, {3}", CasterPawn.equipment.Primary != null , CasterPawn.equipment.Primary.def.IsRangedWeapon , CasterPawn.equipment.PrimaryEq.PrimaryVerb.HarmsHealth() , !CasterPawn.equipment.PrimaryEq.PrimaryVerb.UsesExplosiveProjectiles()));
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = this.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            bool flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out ShootLine shootLine);

            if (this.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (base.EquipmentSource != null)
            {
                CompChangeableProjectile comp = base.EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
            }
            Thing        launcher     = this.caster;
            Thing        equipment    = base.EquipmentSource;
            CompMannable compMannable = this.caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = this.caster;
            }
            Vector3 drawPos = this.caster.DrawPos;
            Stuffable_Projectile projectile2 = (Stuffable_Projectile)GenSpawn.Spawn(projectile, shootLine.Source, this.caster.Map, WipeMode.Vanish);

            if (this.verbProps.forcedMissRadius > 0.5f)
            {
                float num = VerbUtility.CalculateAdjustedForcedMiss(this.verbProps.forcedMissRadius, this.currentTarget.Cell - this.caster.Position);
                if (num > 0.5f)
                {
                    int max  = GenRadial.NumCellsInRadius(num);
                    int num2 = Rand.Range(0, max);
                    if (num2 > 0)
                    {
                        IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num2];
                        this.ThrowDebugText("ToRadius");
                        this.ThrowDebugText("Rad\nDest", c);
                        ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                        if (Rand.Chance(0.5f))
                        {
                            projectileHitFlags = ProjectileHitFlags.All;
                        }
                        if (!this.canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                        }
                        projectile2.Launch(launcher, drawPos, c, this.currentTarget, projectileHitFlags, equipment, null);
                        return(true);
                    }
                }
            }
            ShotReport shotReport            = ShotReport.HitReportFor(this.caster, this, this.currentTarget);
            Thing      randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef   targetCoverDef        = randomCoverToMissInto?.def;

            if (!Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture))
            {
                shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
                this.ThrowDebugText("ToWild" + ((!this.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp"));
                this.ThrowDebugText("Wild\nDest", shootLine.Dest);
                ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                if (Rand.Chance(0.5f) && this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
                }
                projectile2.Launch(launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags2, equipment, targetCoverDef);
                return(true);
            }
            if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance))
            {
                this.ThrowDebugText("ToCover" + ((!this.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp"));
                this.ThrowDebugText("Cover\nDest", randomCoverToMissInto.Position);
                ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
                if (this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
                }
                projectile2.Launch(launcher, drawPos, randomCoverToMissInto, this.currentTarget, projectileHitFlags3, equipment, targetCoverDef);
                return(true);
            }
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (this.canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            this.ThrowDebugText("ToHit" + ((!this.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp"));
            if (this.currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, this.currentTarget, this.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", this.currentTarget.Cell);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", shootLine.Dest);
            }
            return(true);
        }
Beispiel #22
0
        /// <summary>
        /// Tries the cast shot.
        /// </summary>
        /// <returns></returns>
        protected override bool TryCastShot()
        {
            if (currentTarget.HasThing && currentTarget.Thing.Map != caster.Map)
            {
                return(false);
            }
            ThingDef projectile = Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine resultingLine;
            bool      flag = TryFindShootLineFromTo(caster.Position, currentTarget, out resultingLine);

            if (verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (base.EquipmentSource != null)
            {
                base.EquipmentSource.GetComp <CompChangeableProjectile>()?.Notify_ProjectileLaunched();
            }
            Thing        launcher     = caster;
            Thing        equipment    = base.EquipmentSource;
            CompMannable compMannable = caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = caster;
            }
            Vector3    drawPos     = caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, resultingLine.Source, caster.Map);

            if (verbProps.forcedMissRadius > 0.5f)
            {
                float num = VerbUtility.CalculateAdjustedForcedMiss(verbProps.forcedMissRadius, currentTarget.Cell - caster.Position);
                if (num > 0.5f)
                {
                    int max  = GenRadial.NumCellsInRadius(num);
                    int num2 = Rand.Range(0, max);
                    if (num2 > 0)
                    {
                        IntVec3            c = currentTarget.Cell + GenRadial.RadialPattern[num2];
                        ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                        if (Rand.Chance(0.5f))
                        {
                            projectileHitFlags = ProjectileHitFlags.All;
                        }
                        if (!canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                        }
                        projectile2.Launch(launcher, drawPos, c, currentTarget, projectileHitFlags, equipment);
                        return(true);
                    }
                }
            }
            ShotReport shotReport            = ShotReport.HitReportFor(caster, this, currentTarget);
            Thing      randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef   targetCoverDef        = randomCoverToMissInto?.def;
            //never miss

            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, currentTarget, currentTarget, projectileHitFlags4, equipment, targetCoverDef);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, resultingLine.Dest, currentTarget, projectileHitFlags4, equipment, targetCoverDef);
            }
            return(true);
        }
        // Token: 0x0600651E RID: 25886 RVA: 0x001B8BC0 File Offset: 0x001B6FC0
        public static bool TryCastExtraShot(ref AbilitesExtended.Verb_EquipmentLaunchProjectile __instance, LocalTargetInfo currentTarget, bool canHitNonTargetPawnsNow)
        {
            if (currentTarget.HasThing && currentTarget.Thing.Map != __instance.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = __instance.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine shootLine;
            bool      flag = __instance.TryFindShootLineFromTo(__instance.caster.Position, currentTarget, out shootLine);

            if (__instance.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (__instance.EquipmentSource != null)
            {
                CompChangeableProjectile comp = __instance.EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
            }
            Thing        launcher     = __instance.caster;
            Thing        equipment    = __instance.EquipmentSource;
            CompMannable compMannable = __instance.caster.TryGetCompFast <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = __instance.caster;
            }
            Vector3    drawPos     = __instance.caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, __instance.caster.Map, WipeMode.Vanish);

            if (__instance.verbProps.forcedMissRadius > 0.5f)
            {
                float num = VerbUtility.CalculateAdjustedForcedMiss(__instance.verbProps.forcedMissRadius, currentTarget.Cell - __instance.caster.Position);
                if (num > 0.5f)
                {
                    int max = GenRadial.NumCellsInRadius(num);
                    Rand.PushState();
                    int num2 = Rand.Range(0, max);
                    Rand.PopState();
                    if (num2 > 0)
                    {
                        IntVec3 c = currentTarget.Cell + GenRadial.RadialPattern[num2];

                        ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                        Rand.PushState();
                        if (Rand.Chance(0.5f))
                        {
                            projectileHitFlags = ProjectileHitFlags.All;
                        }
                        Rand.PopState();
                        if (!canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                        }
                        projectile2.Launch(launcher, drawPos, c, currentTarget, projectileHitFlags, equipment, null);
                        return(true);
                    }
                }
            }
            ShotReport shotReport            = ShotReport.HitReportFor(__instance.caster, __instance, currentTarget);
            Thing      randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef   targetCoverDef        = randomCoverToMissInto?.def;

            Rand.PushState();
            bool f1 = !Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture);

            Rand.PopState();
            if (f1)
            {
                shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
                ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                Rand.PushState();
                if (Rand.Chance(0.5f) && canHitNonTargetPawnsNow)
                {
                    projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
                }
                Rand.PopState();
                projectile2.Launch(launcher, drawPos, shootLine.Dest, currentTarget, projectileHitFlags2, equipment, targetCoverDef);
                return(true);
            }
            Rand.PushState();
            bool f2 = !Rand.Chance(shotReport.PassCoverChance);

            Rand.PopState();
            if (currentTarget.Thing != null && currentTarget.Thing.def.category == ThingCategory.Pawn && f2)
            {
                ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
                if (canHitNonTargetPawnsNow)
                {
                    projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
                }
                projectile2.Launch(launcher, drawPos, randomCoverToMissInto, currentTarget, projectileHitFlags3, equipment, targetCoverDef);
                return(true);
            }
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!currentTarget.HasThing || currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            if (currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, currentTarget, currentTarget, projectileHitFlags4, equipment, targetCoverDef);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, shootLine.Dest, currentTarget, projectileHitFlags4, equipment, targetCoverDef);
            }
            return(true);
        }
 // Added CompAmmo setup
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     powerComp    = base.GetComp <CompPowerTrader>();
     mannableComp = base.GetComp <CompMannable>();
 }
Beispiel #25
0
        protected override bool TryCastShot()
        {
            if (currentTarget.HasThing && currentTarget.Thing.Map != caster.Map)
            {
                return(false);
            }
            ThingDef projectile = Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine resultingLine;
            bool      flag = TryFindShootLineFromTo(caster.Position, currentTarget, out resultingLine);

            if (verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (base.EquipmentSource != null)
            {
                base.EquipmentSource.GetComp <CompChangeableProjectile>()?.Notify_ProjectileLaunched();
                base.EquipmentSource.GetComp <CompReloadable>()?.UsedOnce();
            }
            Thing        launcher     = caster;
            Thing        equipment    = base.EquipmentSource;
            CompMannable compMannable = caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = caster;
            }
            Vector3    drawPos     = caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, resultingLine.Source, caster.Map);

            if (verbProps.forcedMissRadius > 0.5f)
            {
                float num = VerbUtility.CalculateAdjustedForcedMiss(verbProps.forcedMissRadius, currentTarget.Cell - caster.Position);
                if (num > 0.5f)
                {
                    int max  = GenRadial.NumCellsInRadius(num);
                    int num2 = Rand.Range(0, max);
                    if (num2 > 0)
                    {
                        IntVec3 c = currentTarget.Cell + GenRadial.RadialPattern[num2];
                        ThrowDebugText("ToRadius");
                        ThrowDebugText("Rad\nDest", c);
                        ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                        if (Rand.Chance(0.5f))
                        {
                            projectileHitFlags = ProjectileHitFlags.All;
                        }
                        if (!canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                        }
                        projectile2.Launch(launcher, drawPos, c, currentTarget, projectileHitFlags, equipment);
                        return(true);
                    }
                }
            }
            ShotReport shotReport            = ShotReport.HitReportFor(caster, this, currentTarget);
            Thing      randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef   targetCoverDef        = randomCoverToMissInto?.def;

            if (!Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture))
            {
                resultingLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
                ThrowDebugText("ToWild" + (canHitNonTargetPawnsNow ? "\nchntp" : ""));
                ThrowDebugText("Wild\nDest", resultingLine.Dest);
                ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                if (Rand.Chance(0.5f) && canHitNonTargetPawnsNow)
                {
                    projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
                }
                projectile2.Launch(launcher, drawPos, resultingLine.Dest, currentTarget, projectileHitFlags2, equipment, targetCoverDef);
                return(true);
            }
            if (currentTarget.Thing != null && currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance))
            {
                ThrowDebugText("ToCover" + (canHitNonTargetPawnsNow ? "\nchntp" : ""));
                ThrowDebugText("Cover\nDest", randomCoverToMissInto.Position);
                ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
                if (canHitNonTargetPawnsNow)
                {
                    projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
                }
                projectile2.Launch(launcher, drawPos, randomCoverToMissInto, currentTarget, projectileHitFlags3, equipment, targetCoverDef);
                return(true);
            }
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!currentTarget.HasThing || currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            ThrowDebugText("ToHit" + (canHitNonTargetPawnsNow ? "\nchntp" : ""));
            if (currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, currentTarget, currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                ThrowDebugText("Hit\nDest", currentTarget.Cell);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, resultingLine.Dest, currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                ThrowDebugText("Hit\nDest", resultingLine.Dest);
            }
            return(true);
        }
Beispiel #26
0
        protected override bool TryCastShot()
        {
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = this.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine shootLine;
            bool      flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLine);

            if (this.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (base.EquipmentSource != null)
            {
                CompChangeableProjectile comp = base.EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
            }
            Thing        launcher     = this.caster;
            Thing        equipment    = base.EquipmentSource;
            CompMannable compMannable = this.caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = this.caster;
            }

            /*
             * if (equipment == null)
             * {
             *  Log.Message("equipment==null");
             * }
             * else
             * {
             *  Log.Message(equipment.LabelShortCap);
             * }
             */
            Vector3    drawPos     = this.caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, this.caster.Map, WipeMode.Vanish);

            if (this.verbProps.forcedMissRadius > 0.5f)
            {
                float num = VerbUtility.CalculateAdjustedForcedMiss(this.verbProps.forcedMissRadius, this.currentTarget.Cell - this.caster.Position);
                if (num > 0.5f)
                {
                    int max = GenRadial.NumCellsInRadius(num);
                    Rand.PushState();
                    int num2 = Rand.Range(0, max);
                    Rand.PopState();
                    if (num2 > 0)
                    {
                        IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num2];
                        this.ThrowDebugText("ToRadius");
                        this.ThrowDebugText("Rad\nDest", c);
                        ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                        Rand.PushState();
                        if (Rand.Chance(0.5f))
                        {
                            projectileHitFlags = ProjectileHitFlags.All;
                        }
                        Rand.PopState();
                        if (!this.canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                        }
                        //    Log.Message("EquipmentAbility projectile2.Launch forcedMissRadius");
                        projectile2.Launch(launcher, drawPos, c, this.currentTarget, projectileHitFlags, equipment, null);
                        return(true);
                    }
                }
            }
            ShotReport shotReport            = ShotReport.HitReportFor(this.caster, this, this.currentTarget);
            Thing      randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef   targetCoverDef        = (randomCoverToMissInto != null) ? randomCoverToMissInto.def : null;

            Rand.PushState();
            bool AimOnTarget = Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture);

            Rand.PopState();
            if (!AimOnTarget)
            {
                shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
                this.ThrowDebugText("ToWild" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
                this.ThrowDebugText("Wild\nDest", shootLine.Dest);
                ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                Rand.PushState();
                if (Rand.Chance(0.5f) && this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
                }
                Rand.PopState();
                projectile2.Launch(launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags2, equipment, targetCoverDef);
                //    Log.Message("EquipmentAbility projectile2.Launch OffTarget");
                return(true);
            }
            Rand.PushState();
            bool PassCover = Rand.Chance(shotReport.PassCoverChance);

            Rand.PopState();
            if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn && !PassCover)
            {
                this.ThrowDebugText("ToCover" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
                this.ThrowDebugText("Cover\nDest", randomCoverToMissInto.Position);
                ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
                if (this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
                }
                projectile2.Launch(launcher, drawPos, randomCoverToMissInto, this.currentTarget, projectileHitFlags3, equipment, targetCoverDef);
                //    Log.Message("EquipmentAbility projectile2.Launch IntoCover");
                return(true);
            }
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (this.canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            this.ThrowDebugText("ToHit" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
            if (this.currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, this.currentTarget, this.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                //    Log.Message("EquipmentAbility projectile2.Launch NoThing");
                this.ThrowDebugText("Hit\nDest", this.currentTarget.Cell);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                //    Log.Message("EquipmentAbility projectile2.Launch AtThing");
                this.ThrowDebugText("Hit\nDest", shootLine.Dest);
            }
            return(true);
            //    return this.ability.Activate(this.currentTarget, this.currentDestination);
        }
        protected override (bool success, Vector3 launchPos, float angle) TryCastShotInternal()
        {
            IntVec3 exitTarget = caster.Position.CellFromDistAngle(Building_Artillery.MaxMapDistance, heading);

            if (!target.HasWorldObject && !target.HasThing)
            {
                return(false, Vector3.zero, 0);
            }
            ThingDef projectile = Projectile;

            if (projectile is null)
            {
                return(false, Vector3.zero, 0);
            }
            bool flag = TryFindShootLineFromTo(caster.Position, exitTarget, out ShootLine shootLine);

            if (verbProps.stopBurstWithoutLos && !flag)
            {
                return(false, Vector3.zero, 0);
            }
            if (EquipmentSource != null)
            {
                CompChangeableProjectile comp = EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
                CompReloadable comp2 = EquipmentSource.GetComp <CompReloadable>();
                if (comp2 != null)
                {
                    comp2.UsedOnce();
                }
            }
            Thing        launcher     = caster;
            Thing        equipment    = EquipmentSource;
            CompMannable compMannable = caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = caster;
            }
            Vector3    launchPos   = caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, caster.Position, caster.Map, WipeMode.Vanish);

            if (projectile2.AllComps.NullOrEmpty())
            {
                AccessTools.Field(typeof(ThingWithComps), "comps").SetValue(projectile2, new List <ThingComp>());
            }

            projectile2.AllComps.Add(new CompProjectileExitMap(CasterTWC)
            {
                airDefenseDef = AntiAircraftDefOf.FlakProjectile,
                target        = target.WorldObject as AerialVehicleInFlight,
                spawnPos      = Building_Artillery.RandomWorldPosition(caster.Map.Tile, 1).FirstOrDefault()
            });
            if (caster.def.GetModExtension <ProjectilePropertiesDefModExtension>() is ProjectilePropertiesDefModExtension projectileProps)
            {
                projectile2.AllComps.Add(new CompTurretProjectileProperties(CasterTWC)
                {
                    speed    = projectileProps.speed > 0 ? projectileProps.speed : projectile2.def.projectile.speed,
                    hitflag  = ProjectileHitFlags.IntendedTarget,
                    hitflags = null
                });
            }
            ThrowDebugText("ToHit" + (canHitNonTargetPawnsNow ? "\nchntp" : ""));
            launchPos += new Vector3(VerbProps.shootOffset.x, 0, VerbProps.shootOffset.y).RotatedBy(heading);
            projectile2.Launch(launcher, launchPos, exitTarget, exitTarget, ProjectileHitFlags.IntendedTarget, equipment);
            ThrowDebugText("Hit\nDest", shootLine.Dest);
            return(true, launchPos, heading);
        }
Beispiel #28
0
        // Token: 0x06002252 RID: 8786 RVA: 0x000D128C File Offset: 0x000CF48C
        protected bool base_TryCastShot()
        {
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = this.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine shootLine;
            bool      flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLine);

            if (this.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (base.EquipmentSource != null)
            {
                CompChangeableProjectile comp = base.EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
                //修改精度
                if (CompShootMode != null)
                {
                    CompShootMode.PostPreEachShoot(this);
                }
            }
            Thing        launcher     = this.caster;
            Thing        equipment    = base.EquipmentSource;
            CompMannable compMannable = this.caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = this.caster;
            }
            Vector3    drawPos     = this.caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, this.caster.Map, WipeMode.Vanish);

            //强制误差半径,无视技能等级(原版迫击炮)
            if (this.verbProps.forcedMissRadius > 0.5f)
            {
                float num = VerbUtility.CalculateAdjustedForcedMiss(this.verbProps.forcedMissRadius, this.currentTarget.Cell - this.caster.Position);
                if (num > 0.5f)
                {
                    int max  = GenRadial.NumCellsInRadius(num);
                    int num2 = Rand.Range(0, max);
                    if (num2 > 0)
                    {
                        IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num2];
                        this.ThrowDebugText("ToRadius");
                        this.ThrowDebugText("Rad\nDest", c);
                        ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                        if (Rand.Chance(0.5f))
                        {
                            projectileHitFlags = ProjectileHitFlags.All;
                        }
                        if (!this.canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                        }
                        LanuchWithDamageMultiplier(projectile2, launcher, drawPos, c, this.currentTarget, projectileHitFlags, equipment, null);

                        return(true);
                    }
                }
            }


            ShotReport shotReport            = ShotReport.HitReportFor(this.caster, this, this.currentTarget);
            Thing      randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef   targetCoverDef        = (randomCoverToMissInto != null) ? randomCoverToMissInto.def : null;

            if (!Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture))
            {
                shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
                this.ThrowDebugText("ToWild" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
                this.ThrowDebugText("Wild\nDest", shootLine.Dest);
                ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                if (Rand.Chance(0.5f) && this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
                }
                LanuchWithDamageMultiplier(projectile2, launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags2, equipment, targetCoverDef);
                return(true);
            }
            if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance))
            {
                this.ThrowDebugText("ToCover" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
                this.ThrowDebugText("Cover\nDest", randomCoverToMissInto.Position);
                ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
                if (this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
                }
                LanuchWithDamageMultiplier(projectile2, launcher, drawPos, randomCoverToMissInto, this.currentTarget, projectileHitFlags3, equipment, targetCoverDef);
                return(true);
            }
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (this.canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            this.ThrowDebugText("ToHit" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
            if (this.currentTarget.Thing != null)
            {
                LanuchWithDamageMultiplier(projectile2, launcher, drawPos, this.currentTarget, this.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", this.currentTarget.Cell);
            }
            else
            {
                LanuchWithDamageMultiplier(projectile2, launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", shootLine.Dest);
            }
            return(true);
        }
        protected override bool TryCastShot()
        {
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = this.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine shootLine;
            bool      flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLine);

            if (this.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (this.ownerEquipment != null)
            {
                CompChangeableProjectile comp = this.ownerEquipment.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
            }
            Thing        launcher     = this.caster;
            Thing        equipment    = this.ownerEquipment;
            CompMannable compMannable = this.caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = this.caster;
            }
            Vector3    drawPos     = this.caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, this.caster.Map);

            projectile2.FreeIntercept = (this.canFreeInterceptNow && !projectile2.def.projectile.flyOverhead);
            if (this.verbProps.forcedMissRadius > 0.5f)
            {
                float num = (float)(this.currentTarget.Cell - this.caster.Position).LengthHorizontalSquared;
                float num2;
                if (num < 9f)
                {
                    num2 = 0f;
                }
                else if (num < 25f)
                {
                    num2 = this.verbProps.forcedMissRadius * 0.5f;
                }
                else if (num < 49f)
                {
                    num2 = this.verbProps.forcedMissRadius * 0.8f;
                }
                else
                {
                    num2 = this.verbProps.forcedMissRadius * 1f;
                }
                if (num2 > 0.5f)
                {
                    int max  = GenRadial.NumCellsInRadius(this.verbProps.forcedMissRadius);
                    int num3 = Rand.Range(0, max);
                    if (num3 > 0)
                    {
                        if (DebugViewSettings.drawShooting)
                        {
                            MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToForRad", -1f);
                        }
                        IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num3];
                        if (this.currentTarget.HasThing)
                        {
                            projectile2.ThingToNeverIntercept = this.currentTarget.Thing;
                        }
                        if (!projectile2.def.projectile.flyOverhead)
                        {
                            projectile2.InterceptWalls = true;
                        }
                        projectile2.Launch(launcher, drawPos, c, equipment, this.currentTarget.Thing);
                        return(true);
                    }
                }
            }
            ShotReport shotReport = ShotReport.HitReportFor(this.caster, this, this.currentTarget);

            if (Rand.Value > shotReport.ChanceToNotGoWild_IgnoringPosture)
            {
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToWild", -1f);
                }
                shootLine.ChangeDestToMissWild();
                if (this.currentTarget.HasThing)
                {
                    projectile2.ThingToNeverIntercept = this.currentTarget.Thing;
                }
                if (!projectile2.def.projectile.flyOverhead)
                {
                    projectile2.InterceptWalls = true;
                }
                projectile2.Launch(launcher, drawPos, shootLine.Dest, equipment, this.currentTarget.Thing);
                return(true);
            }
            if (Rand.Value > shotReport.ChanceToNotHitCover)
            {
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToCover", -1f);
                }
                if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn)
                {
                    Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
                    if (!projectile2.def.projectile.flyOverhead)
                    {
                        projectile2.InterceptWalls = true;
                    }
                    projectile2.Launch(launcher, drawPos, randomCoverToMissInto, equipment, this.currentTarget.Thing);
                    return(true);
                }
            }
            if (DebugViewSettings.drawShooting)
            {
                MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToHit", -1f);
            }
            if (!projectile2.def.projectile.flyOverhead)
            {
                projectile2.InterceptWalls = (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full);
            }
            if (this.currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, this.currentTarget, equipment, this.currentTarget.Thing);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, shootLine.Dest, equipment, this.currentTarget.Thing);
            }
            return(true);
        }
        public bool FireProjectile()
        {
            if (base.currentTarget.HasThing && base.currentTarget.Thing.Map != base.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = this.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine shootLine = default(ShootLine);
            bool      flag      = base.TryFindShootLineFromTo(base.caster.Position, base.currentTarget, out shootLine);

            if (base.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (base.EquipmentSource != null)
            {
                CompChangeableProjectile comp = base.EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
            }
            Thing        launcher     = base.caster;
            Thing        equipment    = base.EquipmentSource;
            CompMannable compMannable = base.caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = base.caster;
                // Earn skills
                if (compMannable.ManningPawn.skills != null)
                {
                    int skillsAffectingAccuracy = 0;
                    if (Settings.intellectualAffectsMortarAccuracy)
                    {
                        skillsAffectingAccuracy++;
                    }
                    if (Settings.shootingAffectsMortarAccuracy)
                    {
                        skillsAffectingAccuracy++;
                    }

                    float skillXP = verbProps.AdjustedFullCycleTime(this, CasterPawn) * 100;
                    skillXP /= skillsAffectingAccuracy;

                    if (Settings.intellectualAffectsMortarAccuracy)
                    {
                        compMannable.ManningPawn.skills.Learn(SkillDefOf.Intellectual, skillXP, false);
                    }
                    if (Settings.shootingAffectsMortarAccuracy)
                    {
                        compMannable.ManningPawn.skills.Learn(SkillDefOf.Shooting, skillXP, false);
                    }
                }
            }
            Vector3    drawPos     = base.caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, base.caster.Map, WipeMode.Vanish);

            // If targetting a pawn
            if (Settings.targetLeading)
            {
                if (currentTarget != null && currentTarget.Thing != null && currentTarget.Thing is Pawn targetPawn && targetPawn.pather.curPath != null)
                {
                    List <IntVec3> nodes = new List <IntVec3>(targetPawn.pather.curPath.NodesReversed);
                    nodes.Reverse();
                    // Purge outdated nodes from list
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        if (nodes[i] == targetPawn.Position)
                        {
                            // Remove all previous nodes
                            nodes.RemoveRange(0, i);
                            //Log.Message("Removed " + i + " entries. First node is now " + nodes[0].ToString());
                            break;
                        }
                    }
                    // Path of target pawn from current to destination
                    // Need travel speed of pawn, estimate Vec3 they will be in based on travel speed of our projectile
                    float targetMoveSpeed     = targetPawn.GetStatValue(StatDefOf.MoveSpeed);
                    float projectileMoveSpeed = projectile.projectile.speed;

                    // Estimate position target will be in after this amount of time
                    IntVec3 bestTarget     = targetPawn.Position;
                    float   bestTimeOffset = float.MaxValue;
                    //Log.Message("Default time offset = " + Mathf.Abs(((targetPawn.Position - caster.Position).LengthHorizontal) / projectileMoveSpeed));
                    float accumulatedTargetTime = 0f;

                    IntVec3 previousPosition = targetPawn.Position;
                    foreach (IntVec3 pathPosition in nodes)
                    {
                        float projectileDistanceFromTarget     = (pathPosition - caster.Position).LengthHorizontal;
                        float timeForProjectileToReachPosition = projectileDistanceFromTarget / projectileMoveSpeed;

                        //float pawnDistanceFromTarget = (pathPosition - targetPawn.Position).LengthHorizontal;
                        //float timeForPawnToReachPosition = pawnDistanceFromTarget / targetMoveSpeed;

                        float pawnDistanceFromLastPositionToHere         = (pathPosition - previousPosition).LengthHorizontal;
                        float timeForPawnToReachPositionFromLastPosition = pawnDistanceFromLastPositionToHere / targetMoveSpeed;
                        accumulatedTargetTime += timeForPawnToReachPositionFromLastPosition;

                        float timeOffset = Mathf.Abs(timeForProjectileToReachPosition - accumulatedTargetTime);
                        if (timeOffset < bestTimeOffset)
                        {
                            bestTarget     = pathPosition;
                            bestTimeOffset = timeOffset;
                            //Log.Message("Position " + pathPosition.ToString() + " is better. Time offset is " + timeOffset);
                        }
                        else
                        {
                            //Log.Message("Position " + pathPosition.ToString() + " is not better. Time offset is " + timeOffset);
                        }

                        previousPosition = pathPosition;
                    }
                    //Log.Message("Initial target cell = " + currentTarget.Cell.ToString() + " and new target is " + bestTarget.ToString());
                    currentTarget = new LocalTargetInfo(bestTarget);
                }
            }

            if (base.verbProps.forcedMissRadius > 0.5f)
            {
                float adjustedForcedMissRadius        = GetAdjustedForcedMissRadius();
                ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.All;
                IntVec3            c = currentTarget.Cell;
                if (adjustedForcedMissRadius > 0.5f)
                {
                    int max  = GenRadial.NumCellsInRadius(adjustedForcedMissRadius);
                    int num2 = Rand.Range(0, max);
                    c = base.currentTarget.Cell + GenRadial.RadialPattern[num2];

                    /*if (num2 > 0)
                     * {
                     *  this.ThrowDebugText("ToRadius");
                     *  this.ThrowDebugText("Rad\nDest", c);
                     *  ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                     *  if (Rand.Chance(0.5f))
                     *  {
                     *      projectileHitFlags = ProjectileHitFlags.All;
                     *  }
                     *  if (!base.canHitNonTargetPawnsNow)
                     *  {
                     *      projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                     *  }
                     *  projectile2.Launch(launcher, drawPos, c, base.currentTarget, projectileHitFlags, equipment, null);
                     *  return true;
                     * }*/
                }

                //Log.Message("Final target is " + c.ToString());
                projectile2.Launch(launcher, drawPos, c, base.currentTarget, projectileHitFlags, equipment, null);
                return(true);
            }
            ShotReport shotReport            = ShotReport.HitReportFor(base.caster, this, base.currentTarget);
            Thing      randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef   targetCoverDef        = (randomCoverToMissInto == null) ? null : randomCoverToMissInto.def;

            /*if (!Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture))
             * {
             *  shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
             *  this.ThrowDebugText("ToWild" + ((!base.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp"));
             *  this.ThrowDebugText("Wild\nDest", shootLine.Dest);
             *  ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
             *  if (Rand.Chance(0.5f) && base.canHitNonTargetPawnsNow)
             *  {
             *      projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
             *  }
             *  projectile2.Launch(launcher, drawPos, shootLine.Dest, base.currentTarget, projectileHitFlags2, equipment, targetCoverDef);
             *  return true;
             * }*/
            /*if (base.currentTarget.Thing != null && base.currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance))
             * {
             *  this.ThrowDebugText("ToCover" + ((!base.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp"));
             *  this.ThrowDebugText("Cover\nDest", randomCoverToMissInto.Position);
             *  ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
             *  if (base.canHitNonTargetPawnsNow)
             *  {
             *      projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
             *  }
             *  projectile2.Launch(launcher, drawPos, randomCoverToMissInto, base.currentTarget, projectileHitFlags3, equipment, targetCoverDef);
             *  return true;
             * }*/
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (base.canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!base.currentTarget.HasThing || base.currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            this.ThrowDebugText("ToHit" + ((!base.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp"));
            if (base.currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, base.currentTarget, base.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", base.currentTarget.Cell);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, shootLine.Dest, base.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", shootLine.Dest);
            }
            return(true);
        }
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     WhoIsManningMe = base.GetComp<CompMannable>();
 }
        // Token: 0x060057CC RID: 22476 RVA: 0x0017B880 File Offset: 0x00179C80
        protected override bool TryCastShot()
        {
            //If we are aiming at something real on the map
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = this.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            //Check to see if we have line of sight
            ShootLine shootLine;
            bool      flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLine);

            if (this.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (this.ownerEquipment != null)
            {
                CompChangeableProjectile comp = this.ownerEquipment.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    //!!!!!!!!!!!!!!!! This could be used to subtract from a battery pack
                    comp.Notify_ProjectileLaunched();
                }
            }
            //Launcher is the user; equipment is what is being used to shoot
            Thing        launcher     = this.caster;
            Thing        equipment    = this.ownerEquipment;
            CompMannable compMannable = this.caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = this.caster;
            }
            //This drawPos may need to be modified so that the beam emerges from the weapon and not the user
            Vector3    drawPos     = this.caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, this.caster.Map);

            //Can the projectile strike something on its flightpath?
            projectile2.FreeIntercept = (this.canFreeInterceptNow && !projectile2.def.projectile.flyOverhead);
            //ShotReport gives us our chance that the shot actual hit
            ShotReport shotReport = ShotReport.HitReportFor(this.caster, this, this.currentTarget);

            //If the shot was a miss...
            if (Rand.Value > shotReport.ChanceToNotGoWild_IgnoringPosture)
            {
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToWild", -1f);
                }
                //Modify the shoot line to hit something else
                shootLine.ChangeDestToMissWild();
                if (this.currentTarget.HasThing)
                {
                    //Ensure that the projectile actually hits something else
                    projectile2.ThingToNeverIntercept = this.currentTarget.Thing;
                }
                if (!projectile2.def.projectile.flyOverhead)
                {
                    projectile2.InterceptWalls = true;
                }
                //Launch doomed projectile for shootLine's bad destination
                //Consider giving the beam projectile a function to switch destinations when something gets between launcher and shootLine.Dest
                projectile2.Launch(launcher, drawPos, shootLine.Dest, equipment, this.currentTarget.Thing);
                return(true);
            }
            if (Rand.Value > shotReport.ChanceToNotHitCover)
            {
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToCover", -1f);
                }
                if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn)
                {
                    Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
                    if (!projectile2.def.projectile.flyOverhead)
                    {
                        projectile2.InterceptWalls = true;
                    }
                    projectile2.Launch(launcher, drawPos, randomCoverToMissInto, equipment, this.currentTarget.Thing);
                    return(true);
                }
            }
            if (DebugViewSettings.drawShooting)
            {
                MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToHit", -1f);
            }
            if (!projectile2.def.projectile.flyOverhead)
            {
                projectile2.InterceptWalls = (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full);
            }
            if (this.currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, this.currentTarget, equipment, this.currentTarget.Thing);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, shootLine.Dest, equipment, this.currentTarget.Thing);
            }
            return(true);
        }