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);
        }
示例#2
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);
        }
示例#3
0
        // Token: 0x06000006 RID: 6 RVA: 0x0000225C File Offset: 0x0000045C
        protected override bool TryCastShot()
        {
            bool flag = this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                ThingDef projectile = this.Projectile;
                bool     flag2      = projectile == null;
                if (flag2)
                {
                    result = false;
                }
                else
                {
                    ShootLine shootLine;
                    bool      flag3 = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLine);
                    bool      flag4 = this.verbProps.stopBurstWithoutLos && !flag3;
                    if (flag4)
                    {
                        result = false;
                    }
                    else
                    {
                        bool flag5 = this.EquipmentSource != null;
                        if (flag5)
                        {
                            CompChangeableProjectile comp = this.EquipmentSource.GetComp <CompChangeableProjectile>();
                            bool flag6 = comp != null;
                            if (flag6)
                            {
                                comp.Notify_ProjectileLaunched();
                            }
                        }
                        Thing        thing        = this.caster;
                        Thing        thing2       = this.EquipmentSource;
                        CompMannable compMannable = this.caster.TryGetComp <CompMannable>();
                        bool         flag7        = compMannable != null && compMannable.ManningPawn != null;
                        if (flag7)
                        {
                            thing  = compMannable.ManningPawn;
                            thing2 = this.caster;
                        }
                        Vector3    drawPos     = this.caster.DrawPos;
                        Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, this.caster.Map);
                        int        num         = this.PelletsPerShot(projectile);
                        bool       flag8       = num < 1;
                        if (flag8)
                        {
                            num = 1;
                        }
                        Projectile[] array  = new Projectile[num];
                        ShootLine[]  array2 = new ShootLine[num];
                        for (int i = 0; i < num; i++)
                        {
                            base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out array2[i]);
                            array[i] = (Projectile)GenSpawn.Spawn(projectile, array2[i].Source, this.caster.Map);
                            //array[i].FreeIntercept = (this.canFreeInterceptNow && !array[i].def.projectile.flyOverhead);
                        }
                        float num2 = (this.currentTarget.Cell - this.caster.Position).LengthHorizontal;
                        float num3 = this.ScatterRadiusAt10tilesAway(projectile) * num2 / 10f;
                        float num4 = this.verbProps.forcedMissRadius + this.ForsedScatterRadius(projectile) + num3;
                        int   j    = 0;
                        while (j < num)
                        {
                            bool flag9 = num4 > 0.5f;
                            if (!flag9)
                            {
                                goto IL_41E;
                            }
                            float num5   = (float)(this.currentTarget.Cell - this.caster.Position).LengthHorizontalSquared;
                            bool  flag10 = num5 < 9f;
                            float num6;
                            if (flag10)
                            {
                                num6 = 0f;
                            }
                            else
                            {
                                bool flag11 = num5 < 25f;
                                if (flag11)
                                {
                                    num6 = num4 * 0.5f;
                                }
                                else
                                {
                                    bool flag12 = num5 < 49f;
                                    if (flag12)
                                    {
                                        num6 = num4 * 0.8f;
                                    }
                                    else
                                    {
                                        num6 = num4 * 1f;
                                    }
                                }
                            }
                            bool flag13 = num6 > 0.5f;
                            if (!flag13)
                            {
                                goto IL_41E;
                            }
                            int  max    = GenRadial.NumCellsInRadius(num4);
                            int  num7   = Rand.Range(0, max);
                            bool flag14 = num7 > 0;
                            if (flag14)
                            {
                                bool drawShooting = DebugViewSettings.drawShooting;
                                if (drawShooting)
                                {
                                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToForRad", -1f);
                                }
                                bool hasThing = this.currentTarget.HasThing;
                                if (hasThing)
                                {
                                    array[j].HitFlags = ProjectileHitFlags.All;
                                    //array[j].ThingToNeverIntercept = this.currentTarget.Thing;
                                }
                                bool flag15 = !array[j].def.projectile.flyOverhead;
                                if (flag15)
                                {
                                    array[j].HitFlags = ProjectileHitFlags.IntendedTarget;
                                }
                                IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num7];
                                array[j].Launch(thing, origin: drawPos, usedTarget: new LocalTargetInfo(c), intendedTarget: currentTarget, equipment: thing2, hitFlags: array[j].HitFlags);
                            }
                            else
                            {
                                array[j].Launch(thing, origin: drawPos, usedTarget: new LocalTargetInfo(this.currentTarget.Cell), intendedTarget: currentTarget, equipment: thing2, hitFlags: array[j].HitFlags);
                                //array[j].Launch(thing, drawPos, this.currentTarget.Cell, thing2, this.currentTarget.Thing);
                            }
IL_6D8:
                            j++;
                            continue;
IL_41E:
                            ShotReport shotReport = ShotReport.HitReportFor(this.caster, this, this.currentTarget);
                            bool flag16 = Rand.Value > shotReport.AimOnTargetChance_IgnoringPosture;
                            if (flag16)
                            {
                                bool drawShooting2 = DebugViewSettings.drawShooting;
                                if (drawShooting2)
                                {
                                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToWild", -1f);
                                }
                                array2[j].ChangeDestToMissWild(shotReport.AimOnTargetChance);
                                bool hasThing2 = this.currentTarget.HasThing;
                                if (hasThing2)
                                {
                                    array[j].HitFlags = ProjectileHitFlags.All;
                                    //array[j].ThingToNeverIntercept = this.currentTarget.Thing;
                                }
                                bool flag17 = !array[j].def.projectile.flyOverhead;
                                if (flag17)
                                {
                                    array[j].HitFlags = ProjectileHitFlags.IntendedTarget;
                                    //array[j].InterceptWalls = true;
                                }
                                array[j].Launch(thing, origin: drawPos, usedTarget: new LocalTargetInfo(array2[j].Dest), intendedTarget: currentTarget, equipment: thing2, hitFlags: array[j].HitFlags);
                                //array[j].Launch(thing, drawPos, array2[j].Dest, thing2, this.currentTarget.Thing);
                                goto IL_6D8;
                            }
                            bool flag18 = Rand.Value > shotReport.PassCoverChance;
                            if (flag18)
                            {
                                bool drawShooting3 = DebugViewSettings.drawShooting;
                                if (drawShooting3)
                                {
                                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToCover", -1f);
                                }
                                bool flag19 = this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn;
                                if (flag19)
                                {
                                    Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
                                    bool  flag20 = !array[j].def.projectile.flyOverhead;
                                    if (flag20)
                                    {
                                        array[j].HitFlags = ProjectileHitFlags.IntendedTarget;
                                    }
                                    array[j].Launch(thing, origin: drawPos, usedTarget: new LocalTargetInfo(randomCoverToMissInto), intendedTarget: currentTarget, equipment: thing2, hitFlags: array[j].HitFlags);
                                    //array[j].Launch(thing, drawPos, randomCoverToMissInto, thing2, this.currentTarget.Thing);
                                    goto IL_6D8;
                                }
                            }
                            bool drawShooting4 = DebugViewSettings.drawShooting;
                            if (drawShooting4)
                            {
                                MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToHit", -1f);
                            }
                            bool flag21 = !array[j].def.projectile.flyOverhead && (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full);
                            if (flag21)
                            {
                                array[j].HitFlags = ProjectileHitFlags.IntendedTarget;
                            }
                            bool flag22 = this.currentTarget.Thing != null;
                            if (flag22)
                            {
                                array[j].Launch(thing, origin: drawPos, usedTarget: currentTarget, intendedTarget: currentTarget, equipment: thing2, hitFlags: array[j].HitFlags);
                                //array[j].Launch(thing, drawPos, this.currentTarget, thing2, this.currentTarget.Thing);
                            }
                            else
                            {
                                array[j].Launch(thing, origin: drawPos, usedTarget: new LocalTargetInfo(array2[j].Dest), intendedTarget: currentTarget, equipment: thing2, hitFlags: array[j].HitFlags);
                                //array[j].Launch(thing, drawPos, array2[j].Dest, thing2, this.currentTarget.Thing);
                            }
                            goto IL_6D8;
                        }
                        result = true;
                    }
                }
            }
            return(result);
        }
        // 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);
        }
示例#5
0
        protected override bool TryCastShot()
        {
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            //  ThingDef projectile = this.Projectile;
            ThingDef projectile = this.Projectile;

            //   projectile.projectileWhenLoaded.
            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.EquipmentSource != null)
            {
                CompChangeableProjectile comp = this.EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
            }
            Thing        launcher     = this.caster;
            Thing        equipment    = this.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);


            //---------------
            int pellets = this.PelletsPerShot(projectile);

            if (pellets < 1)
            {
                pellets = 1;
            }

            Projectile[] projectiles = new Projectile[pellets];
            ShootLine[]  shootLines  = new ShootLine[pellets];
            for (int i = 0; i < pellets; i++)
            {
                base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLines[i]);
                projectiles[i] = (Projectile)GenSpawn.Spawn(projectile, shootLines[i].Source, this.caster.Map);
                //projectiles[i].FreeIntercept = (this.canFreeInterceptNow && !projectiles[i].def.projectile.flyOverhead);
            }

            //projectile2.FreeIntercept = (this.canFreeInterceptNow && !projectile2.def.projectile.flyOverhead);
            //projectile3.FreeIntercept = (this.canFreeInterceptNow && !projectile2.def.projectile.flyOverhead);
            //projectile4.FreeIntercept = (this.canFreeInterceptNow && !projectile2.def.projectile.flyOverhead);
            float distance   = (float)(this.currentTarget.Cell - this.caster.Position).LengthHorizontal;
            float scatter    = ScatterRadiusAt10tilesAway(projectile) * distance / 10.0f;
            float missRadius = this.verbProps.forcedMissRadius + ForsedScatterRadius(projectile) + scatter;

            for (int i = 0; i < pellets; i++)
            {
                if (missRadius > 0.5f)
                {
                    float num = (float)(this.currentTarget.Cell - this.caster.Position).LengthHorizontalSquared;
                    float num2;
                    if (num < 9f)
                    {
                        num2 = 0f;
                    }
                    else if (num < 25f)
                    {
                        num2 = missRadius * 0.5f;
                    }
                    else if (num < 49f)
                    {
                        num2 = missRadius * 0.8f;
                    }
                    else
                    {
                        num2 = missRadius * 1f;
                    }
                    if (num2 > 0.5f)
                    {
                        int max = GenRadial.NumCellsInRadius(missRadius);
                        //int num3 = Rand.Range(0, max);
                        int num3 = Rand.Range(0, max);
                        if (num3 > 0)
                        {
                            if (DebugViewSettings.drawShooting)
                            {
                                MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToForRad", -1f);
                            }
                            //if (this.currentTarget.HasThing)
                            //{
                            //    // projectile2.ThingToNeverIntercept = this.currentTarget.Thing;

                            //   projectiles[i].ThingToNeverIntercept = this.currentTarget.Thing;
                            //}

                            //if (!projectiles[i].def.projectile.flyOverhead)
                            //{
                            //        projectiles[i].InterceptWalls = true;
                            //}
                            IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num3];
                            projectiles[i].Launch(launcher, origin: drawPos, usedTarget: new LocalTargetInfo(c), intendedTarget: currentTarget, hitFlags: projectiles[i].HitFlags, equipment: equipment);
                            //projectile2.Launch(launcher, drawPos, c, equipment, this.currentTarget.Thing);
                            //projectile3.Launch(launcher, drawPos, c, equipment, this.currentTarget.Thing);
                            //projectile4.Launch(launcher, drawPos, c, equipment, this.currentTarget.Thing);
                            continue;// return true;
                        }
                        else
                        {
                            projectiles[i].Launch(launcher, origin: drawPos, usedTarget: new LocalTargetInfo(this.currentTarget.Cell), intendedTarget: currentTarget, hitFlags: projectiles[i].HitFlags, equipment: equipment);
                            //projectiles[i].Launch(launcher, drawPos, this.currentTarget.Cell, equipment, this.currentTarget.Thing);
                            continue;
                        }
                    }
                }
                ShotReport shotReport = ShotReport.HitReportFor(this.caster, this, this.currentTarget);
                if (Rand.Value > shotReport.AimOnTargetChance_IgnoringPosture)
                {
                    if (DebugViewSettings.drawShooting)
                    {
                        MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToWild", -1f);
                    }

                    shootLines[i].ChangeDestToMissWild(shotReport.AimOnTargetChance);
                    // shootLine2.ChangeDestToMissWild();

                    if (this.currentTarget.HasThing)
                    {
                        projectiles[i].HitFlags = ProjectileHitFlags.All;
                        // projectile2.ThingToNeverIntercept = this.currentTarget.Thing;
                    }
                    if (!projectiles[i].def.projectile.flyOverhead)
                    {
                        projectiles[i].HitFlags = ProjectileHitFlags.IntendedTarget;
                    }
                    projectiles[i].Launch(launcher, origin: drawPos, usedTarget: new LocalTargetInfo(shootLines[i].Dest), intendedTarget: currentTarget, hitFlags: projectiles[i].HitFlags, equipment: equipment);
                    //projectiles[i].Launch(launcher, drawPos, shootLines[i].Dest, equipment, this.currentTarget.Thing);
                    //projectile2.Launch(launcher, drawPos, shootLine2.Dest, equipment, this.currentTarget.Thing);
                    continue;//return true;
                }
                if (Rand.Value > shotReport.PassCoverChance)
                {
                    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 (!projectiles[i].def.projectile.flyOverhead)
                        {
                            projectiles[i].HitFlags = ProjectileHitFlags.IntendedTarget;
                        }
                        projectiles[i].Launch(launcher, origin: drawPos, usedTarget: new LocalTargetInfo(randomCoverToMissInto), intendedTarget: currentTarget, hitFlags: projectiles[i].HitFlags, equipment: equipment);
                        //projectiles[i].Launch(launcher, drawPos, randomCoverToMissInto, equipment, this.currentTarget.Thing);
                        //projectile2.Launch(launcher, drawPos, randomCoverToMissInto, equipment, this.currentTarget.Thing);
                        continue;//return true;
                    }
                }
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToHit", -1f);
                }

                if (!projectiles[i].def.projectile.flyOverhead && (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full))
                {
                    projectiles[i].HitFlags = ProjectileHitFlags.IntendedTarget;
                }

                if (this.currentTarget.Thing != null)
                {
                    projectiles[i].Launch(launcher, origin: drawPos, usedTarget: currentTarget, intendedTarget: currentTarget, hitFlags: projectiles[i].HitFlags, equipment: equipment);
                    //projectiles[i].Launch(launcher, drawPos, this.currentTarget, equipment, this.currentTarget.Thing);
                }
                else
                {
                    projectiles[i].Launch(launcher, origin: drawPos, usedTarget: new LocalTargetInfo(shootLines[i].Dest), intendedTarget: currentTarget, hitFlags: projectiles[i].HitFlags, equipment: equipment);
                    //projectiles[i].Launch(launcher, drawPos, shootLines[i].Dest, equipment, this.currentTarget.Thing);
                }
            }

            return(true);
        }