示例#1
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);
        }
        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);
        }
        protected override bool TryCastShot()
        {
            bool result;

            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                result = false;
            }
            else
            {
                ThingDef projectile = this.Projectile;
                if (projectile == null)
                {
                    result = false;
                }
                else
                {
                    ShootLine shootLine;
                    bool      flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLine);
                    if (this.verbProps.stopBurstWithoutLos && !flag)
                    {
                        result = false;
                    }
                    else
                    {
                        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, 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 == null) ? null : randomCoverToMissInto.def;
                        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;
                            }
                            projectile2.Launch(launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags2, equipment, targetCoverDef);
                            result = true;
                        }
                        else 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;
                            }
                            projectile2.Launch(launcher, drawPos, randomCoverToMissInto, this.currentTarget, projectileHitFlags3, equipment, targetCoverDef);
                            result = true;
                        }
                        else
                        {
                            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);
                                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);
                            }
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }