示例#1
0
        protected bool CanHit(Thing thing)
        {
            if (!thing.Spawned)
            {
                return(false);
            }
            if (thing == launcher)
            {
                return(false);
            }
            bool flag = false;

            foreach (IntVec3 item in thing.OccupiedRect())
            {
                List <Thing> thingList = item.GetThingList(base.Map);
                bool         flag2     = false;
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] != thing && thingList[i].def.Fillage == FillCategory.Full && thingList[i].def.Altitude >= thing.def.Altitude)
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                return(false);
            }
            ProjectileHitFlags hitFlags = HitFlags;

            if (thing == intendedTarget && (hitFlags & ProjectileHitFlags.IntendedTarget) != 0)
            {
                return(true);
            }
            if (thing != intendedTarget)
            {
                if (thing is Pawn)
                {
                    if ((hitFlags & ProjectileHitFlags.NonTargetPawns) != 0)
                    {
                        return(true);
                    }
                }
                else if ((hitFlags & ProjectileHitFlags.NonTargetWorld) != 0)
                {
                    return(true);
                }
            }
            if (thing == intendedTarget && thing.def.Fillage == FillCategory.Full)
            {
                return(true);
            }
            return(false);
        }
示例#2
0
 public void Launch(Thing launcher, Vector3 origin, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null, ThingDef targetCoverDef = null)
 {
     this.launcher       = launcher;
     this.origin         = origin;
     this.usedTarget     = usedTarget;
     this.intendedTarget = intendedTarget;
     this.targetCoverDef = targetCoverDef;
     HitFlags            = hitFlags;
     if (equipment != null)
     {
         equipmentDef           = equipment.def;
         weaponDamageMultiplier = equipment.GetStatValue(StatDefOf.RangedWeapon_DamageMultiplier);
     }
     else
     {
         equipmentDef           = null;
         weaponDamageMultiplier = 1f;
     }
     destination   = usedTarget.Cell.ToVector3Shifted() + Gen.RandomHorizontalVector(0.3f);
     ticksToImpact = Mathf.CeilToInt(StartingTicksToImpact);
     if (ticksToImpact < 1)
     {
         ticksToImpact = 1;
     }
     if (!def.projectile.soundAmbient.NullOrUndefined())
     {
         SoundInfo info = SoundInfo.InMap(this, MaintenanceType.PerTick);
         ambientSustainer = def.projectile.soundAmbient.TrySpawnSustainer(info);
     }
 }
示例#3
0
 public static void OverriddenHitFlags(Projectile __instance, ref ProjectileHitFlags __result)
 {
     if (__instance.AllComps.FirstOrDefault(c => c is CompTurretProjectileProperties) is CompTurretProjectileProperties comp && comp.hitflag.HasValue)
     {
         __result = comp.hitflag.Value;
     }
 }
示例#4
0
            static void Postfix(Projectile __instance, Thing ___launcher, ref ProjectileHitFlags ___desiredHitFlags, ref ProjectileHitFlags __result)
            {
                // Short-circuit
                if (!__result.HasFlag(ProjectileHitFlags.NonTargetWorld))
                {
                    return;
                }

                // Find the Pawn's weapon
                if (!(___launcher is Pawn pawn))
                {
                    return;
                }
                var comp = pawn.equipment?.Primary?.TryGetComp <CompLootAffixableThing>();

                if (comp == null)
                {
                    return;
                }

                // Does the weapon have the ShootThroughWalls modifier?
                if (!comp.AllModifiers.Any(lam => lam is LootAffixModifier_ShootThroughWalls))
                {
                    return;
                }

                // Remove the NonTargetWorld flag from both current and future results.  (NonTargetPawns are still
                // fair game.)
                __result           &= ~ProjectileHitFlags.NonTargetWorld;
                ___desiredHitFlags &= ~ProjectileHitFlags.NonTargetWorld;
            }
示例#5
0
        protected bool CanHit(Thing thing)
        {
            if (!thing.Spawned)
            {
                return(false);
            }
            if (thing == this.launcher)
            {
                return(false);
            }
            bool flag = false;

            CellRect.CellRectIterator iterator = thing.OccupiedRect().GetIterator();
            while (!iterator.Done())
            {
                List <Thing> thingList = iterator.Current.GetThingList(base.Map);
                bool         flag2     = false;
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] != thing && thingList[i].def.Fillage == FillCategory.Full && thingList[i].def.Altitude >= thing.def.Altitude)
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    flag = true;
                    break;
                }
                iterator.MoveNext();
            }
            if (!flag)
            {
                return(false);
            }
            ProjectileHitFlags hitFlags = this.HitFlags;

            if (thing == this.intendedTarget && (hitFlags & ProjectileHitFlags.IntendedTarget) != ProjectileHitFlags.None)
            {
                return(true);
            }
            if (thing != this.intendedTarget)
            {
                if (thing is Pawn)
                {
                    if ((hitFlags & ProjectileHitFlags.NonTargetPawns) != ProjectileHitFlags.None)
                    {
                        return(true);
                    }
                }
                else if ((hitFlags & ProjectileHitFlags.NonTargetWorld) != ProjectileHitFlags.None)
                {
                    return(true);
                }
            }
            return(thing == this.intendedTarget && thing.def.Fillage == FillCategory.Full);
        }
示例#6
0
        private static bool CanHit(Projectile __instance, Thing thing)
        {
            if (!thing.Spawned)
            {
                return(false);
            }
            if (thing == __instance.Launcher)
            {
                return(false);
            }
            bool flag = false;

            foreach (IntVec3 c in thing.OccupiedRect())
            {
                //List<Thing> thingList = c.GetThingList(__instance.Map);
                IEnumerable <Thing> enumThing = __instance.Map.thingGrid.ThingsAt(c);
                bool flag2 = false;
                //for (int i = 0; i < thingList.Count; i++)
                foreach (Thing tlThing in enumThing)
                {
                    if (tlThing != null && tlThing != thing && tlThing.def != null && tlThing.def.Fillage == FillCategory.Full && tlThing.def.Altitude >= thing.def.Altitude)
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                return(false);
            }
            ProjectileHitFlags hitFlags = __instance.HitFlags;

            if (thing == __instance.intendedTarget && (hitFlags & ProjectileHitFlags.IntendedTarget) != ProjectileHitFlags.None)
            {
                return(true);
            }
            if (thing != __instance.intendedTarget)
            {
                if (thing is Pawn)
                {
                    if ((hitFlags & ProjectileHitFlags.NonTargetPawns) != ProjectileHitFlags.None)
                    {
                        return(true);
                    }
                }
                else if ((hitFlags & ProjectileHitFlags.NonTargetWorld) != ProjectileHitFlags.None)
                {
                    return(true);
                }
            }
            return(thing == __instance.intendedTarget && thing.def.Fillage == FillCategory.Full);
        }
示例#7
0
        protected override bool TryCastShot()
        {
            Log.Message("test3");
            AERIALChangeableProjectile comp = EquipmentSource.GetComp <AERIALChangeableProjectile>();
            Thing    launcher   = caster;
            ThingDef projectile = Projectile;

            if (projectile == null)
            {
                return(false);
            }
            Log.Message("test");
            Thing     equipment = EquipmentSource;
            Vector3   drawPos   = this.caster.DrawPos;
            ShootLine shootLine;
            bool      flag = base.TryFindShootLineFromTo(caster.Position, currentTarget, out shootLine);
            float     num  = VerbUtility.CalculateAdjustedForcedMiss(this.verbProps.forcedMissRadius, this.currentTarget.Cell - this.caster.Position);
            int       max  = GenRadial.NumCellsInRadius(num);
            int       num2 = Rand.Range(0, max);
            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;
            }
            IntVec3 pos = shootLine.Source;

            pos.x += 20;
            pos.z += 20;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, pos, this.caster.Map, WipeMode.Vanish);

            projectile2.Launch(launcher, drawPos, c, this.currentTarget, projectileHitFlags, equipment, null);
            comp.loadedShells.RemoveAt(comp.loadedShells.Count - 1);

            if (!comp.loadedShells.NullOrEmpty())
            {
                pos         = shootLine.Source;
                pos.z      -= 20;
                pos.x      -= 20;
                projectile  = Projectile;
                projectile2 = (Projectile)GenSpawn.Spawn(projectile, pos, this.caster.Map, WipeMode.Vanish);
                projectile2.Launch(launcher, drawPos, c, this.currentTarget, projectileHitFlags, equipment, null);
                comp.loadedShells.RemoveAt(comp.loadedShells.Count - 1);
            }

            Log.Message($"{comp.loadedShells.Count}");
            return(true);
        }
        // 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);
        }
 public void Launch(Thing launcher, AbilityDef abilityDef, Vector3 origin, LocalTargetInfo targ,
                    ProjectileHitFlags hitFlags, Thing equipment = null, List <ApplyHediffs> applyHediffs = null,
                    List <ApplyMentalStates> applyMentalStates   = null, List <SpawnThings> spawnThings   = null)
 {
     //Log.Message("Projectile_AbilityBase");
     localApplyHediffs      = applyHediffs;
     localApplyMentalStates = applyMentalStates;
     localSpawnThings       = spawnThings;
     localAbilityDef        = abilityDef;
     base.Launch(launcher, targ, targ, hitFlags, equipment); //TODO
 }
        public bool TryLaunchProjectileCheck(ThingDef projectileDef, LocalTargetInfo launchTarget)
        {
            DebugMessage(launchTarget.ToString());
            var flag = TryFindShootLineFromTo(caster.Position, launchTarget, out var shootLine);

            if (verbProps.requireLineOfSight && verbProps.stopBurstWithoutLos && !flag)
            {
                Messages.Message("AU_NoLineOfSight".Translate(), MessageTypeDefOf.RejectInput);
                return(false);
            }
            var drawPos    = caster.DrawPos;
            var projectile = (Projectile_AbilityBase)GenSpawn.Spawn(projectileDef, shootLine.Source, caster.Map);

            projectile.extraDamages     = UseAbilityProps.extraDamages;
            projectile.localSpawnThings = UseAbilityProps.thingsToSpawn;
            verbProps.soundCast?.PlayOneShot(new TargetInfo(caster.Position, caster.Map, false));
            verbProps.soundCastTail?.PlayOneShotOnCamera();
            if (DebugViewSettings.drawShooting)
            {
                MoteMaker.ThrowText(caster.DrawPos, caster.Map, "ToHit", -1f);
            }
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (this.canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            DebugMessage(launchTarget.ToString());
            projectile.Launch(caster, Ability.Def, drawPos, launchTarget, projectileHitFlags4, null,
                              UseAbilityProps.hediffsToApply,
                              UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
            return(true);
        }
        // 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);
        }
示例#12
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: 0x0600529E RID: 21150 RVA: 0x0012980C File Offset: 0x00127C0C
        public void Launch(Thing launcher, Vector3 origin, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null, ThingDef targetCoverDef = null)
        {
            this.launcher       = launcher;
            this.origin         = origin;
            this.usedTarget     = usedTarget;
            this.intendedTarget = intendedTarget;
            this.targetCoverDef = targetCoverDef;
            this.HitFlags       = hitFlags;
            if (equipment != null)
            {
                this.equipmentDef           = equipment.def;
                this.weaponDamageMultiplier = equipment.GetStatValue(StatDefOf.RangedWeapon_DamageMultiplier, true);

                //    Log.Message(string.Format("Original weaponDamageMultiplier: {0}", weaponDamageMultiplier));
                if (equipment.Stuff != null)
                {
                    //    Log.Message(string.Format("equipment.Stuff: {0}", equipment.Stuff));
                    //    weaponDamageMultiplier *= equipment.Stuff.GetStatValueAbstract(equipmentDef.Verbs[0].defaultProjectile.projectile.damageDef.armorCategory.multStat, null);
                    //    Log.Message(string.Format("Stuffable weaponDamageMultiplier: {0}", weaponDamageMultiplier));
                }
            }
            else
            {
                this.equipmentDef           = null;
                this.weaponDamageMultiplier = 1f;
            }
            this.destination   = usedTarget.Cell.ToVector3Shifted() + Gen.RandomHorizontalVector(0.3f);
            this.ticksToImpact = this.StartingTicksToImpact;
            if (!this.def.projectile.soundAmbient.NullOrUndefined())
            {
                SoundInfo info = SoundInfo.InMap(this, MaintenanceType.PerTick);
                this.ambientSustainer = this.def.projectile.soundAmbient.TrySpawnSustainer(info);
            }
        }
        // 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);
        }
示例#15
0
        //Projectile
        public static bool Launch_Prefix(Projectile __instance, Thing launcher, Vector3 origin,
                                         LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment,
                                         ThingDef targetCoverDef)
        {
            DebugMessage("14a :: -- Enter Launch_Prefix --");
            if (firingAllLasers)
            {
                DebugMessage("14a :: firingAllLasers was True");
                DebugMessage("14a :: -- Exit Launch_Prefix --");
                return(true);
            }

            if (launcher == null || launcher is not Pawn p || p.def.defName != "Alien_ElderThing_Race_Standard")
            {
                return(true);
            }

            DebugMessage("14a :: Launcher is Elder Thing");
            if (equipment != null)
            {
                DebugMessage("14a :: Equipment is not null");
                if (equipment.def.defName == "ElderThing_LaserGun")
                {
                    DebugMessage("14a :: Equipped LaserGun");
                    if (p.MapHeld is { } m)
                    {
                        DebugMessage("14a :: Map is valid");
                        var chosenTargets = new Dictionary <Pawn, ShootLine>();

                        var potentialTargets =
                            from target in m.mapPawns.AllPawnsSpawned
                            where
                            target.Faction != null &&
                            target.Faction.HostileTo(p.Faction) &&
                            new LocalTargetInfo(target) != usedTarget
                            select target;

                        if (potentialTargets.Any())
                        {
                            DebugMessage($"14a :: Potential targets: {potentialTargets.Count()}");
                            firingAllLasers = true;
                            DebugMessage("14a :: firingAllLasers Set: True");
                            foreach (var target in potentialTargets)
                            {
                                var resultingLine = new ShootLine();
                                var verb          = p.equipment.PrimaryEq.PrimaryVerb;
                                if (verb.verbProps.stopBurstWithoutLos &&
                                    !verb.TryFindShootLineFromTo(p.Position, target, out resultingLine))
                                {
                                    DebugMessage($"14a :: Target {target} out of sight/range.");
                                    continue;
                                }

                                DebugMessage($"14a :: Target {target} added to target list.");
                                chosenTargets.Add(target, resultingLine);
                            }

                            for (var shotsFired = 0;
                                 shotsFired < chosenTargets.Count && shotsFired < 4;
                                 shotsFired++)
                            {
                                var currentTarget = chosenTargets.ElementAt(shotsFired).Key;
                                var currentLine   = chosenTargets.ElementAt(shotsFired).Value;
                                DebugMessage($"14a :: Fired {shotsFired + 1} at {currentTarget}");
                                var projectile2 =
                                    (Projectile)GenSpawn.Spawn(__instance.def, currentLine.Source, p.Map);
                                projectile2.Launch(launcher, currentTarget, currentTarget,
                                                   hitFlags, false, equipment);
                            }

                            firingAllLasers = false;
                            DebugMessage("14a :: firingAllLasers Set: False");
                        }
                    }
                }
            }

            DebugMessage("14a :: -- Exit Launch_Prefix --");

            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 static void CopyAndLaunchProjectileFromPosition(Projectile projectileToCopy, Thing launcher, IntVec3 fromPosition, LocalTargetInfo target, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null)
 {
     if (projectileToCopy != null && projectileToCopy is Projectile)
     {
         Projectile newProjectile = (Projectile)GenSpawn.Spawn(projectileToCopy, fromPosition, launcher.Map, WipeMode.Vanish);
         newProjectile.Launch(launcher, target, intendedTarget, hitFlags, false, equipment);
     }
 }
 public static void Postfix(Projectile __instance, Thing launcher, Vector3 origin, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, bool preventFriendlyFire = false, Thing equipment = null, ThingDef targetCoverDef = null)
 {
     if (__instance is ExpandableProjectile expandableProjectile && expandableProjectile.def.reachMaxRangeAlways)
     {
         expandableProjectile.SetDestinationToMax(equipment);
     }
 }
示例#19
0
 public void Launch(Thing launcher, Vector3 origin, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null, ThingDef targetCoverDef = null)
 {
     this.launcher       = launcher;
     this.origin         = origin;
     this.usedTarget     = usedTarget;
     this.intendedTarget = intendedTarget;
     this.targetCoverDef = targetCoverDef;
     this.HitFlags       = hitFlags;
     if (equipment != null)
     {
         this.equipmentDef = equipment.def;
     }
     else
     {
         this.equipmentDef = null;
     }
     this.destination   = usedTarget.Cell.ToVector3Shifted() + Gen.RandomHorizontalVector(0.3f);
     this.ticksToImpact = this.StartingTicksToImpact;
     if (!this.def.projectile.soundAmbient.NullOrUndefined())
     {
         SoundInfo info = SoundInfo.InMap(this, MaintenanceType.PerTick);
         this.ambientSustainer = this.def.projectile.soundAmbient.TrySpawnSustainer(info);
     }
 }
        public static void CopyAndLaunchProjectile(Projectile projectileToCopy, Thing launcher, LocalTargetInfo target, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null)
        {
            Projectile newProjectile = (Projectile)GenSpawn.Spawn(projectileToCopy, launcher.Position, launcher.Map, WipeMode.Vanish);

            newProjectile.Launch(launcher, target, intendedTarget, hitFlags, equipment);
        }
示例#21
0
        protected new bool?TryLaunchProjectile(ThingDef projectileDef, LocalTargetInfo launchTarget)
        {
            DebugMessage(launchTarget.ToString());
            var flag = TryFindShootLineFromTo(caster.Position, launchTarget, out var shootLine);

            if (verbProps.stopBurstWithoutLos && !flag)
            {
                DebugMessage("Targeting cancelled");
                return(false);
            }
            var drawPos     = caster.DrawPos;
            var projectile2 = (Projectile_AbilityBase)GenSpawn.Spawn(projectileDef, shootLine.Source, caster.Map);

            projectile2.extraDamages     = UseAbilityProps.extraDamages;
            projectile2.localSpawnThings = UseAbilityProps.thingsToSpawn;
            verbProps.soundCast?.PlayOneShot(new TargetInfo(caster.Position, caster.Map, false));
            verbProps.soundCastTail?.PlayOneShotOnCamera();
            if (DebugViewSettings.drawShooting)
            {
                MoteMaker.ThrowText(caster.DrawPos, caster.Map, "ToHit", -1f);
            }


            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(CasterPawn, drawPos, c, this.currentTarget, projectileHitFlags, caster, null);
                        projectile2.Launch(caster, Ability.Def, drawPos, c, projectileHitFlags, null,
                                           UseAbilityProps.hediffsToApply,
                                           UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
                        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) ? 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(CasterPawn, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags2, caster, targetCoverDef);
                projectile2.Launch(caster, Ability.Def, drawPos, shootLine.Dest, projectileHitFlags2, null,
                                   UseAbilityProps.hediffsToApply,
                                   UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
                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(CasterPawn, drawPos, randomCoverToMissInto, this.currentTarget, projectileHitFlags3, caster, targetCoverDef);
                projectile2.Launch(caster, Ability.Def, drawPos, randomCoverToMissInto, projectileHitFlags3, null,
                                   UseAbilityProps.hediffsToApply,
                                   UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
                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(CasterPawn, drawPos, this.currentTarget, this.currentTarget, projectileHitFlags4, caster, targetCoverDef);
                projectile2.Launch(caster, Ability.Def, drawPos, currentTarget, projectileHitFlags4, null,
                                   UseAbilityProps.hediffsToApply,
                                   UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
                this.ThrowDebugText("Hit\nDest", this.currentTarget.Cell);
            }
            else
            {
                //    projectile2.Launch(CasterPawn, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags4, caster, targetCoverDef);
                projectile2.Launch(caster, Ability.Def, drawPos, shootLine.Dest, projectileHitFlags4, null,
                                   UseAbilityProps.hediffsToApply,
                                   UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
                this.ThrowDebugText("Hit\nDest", shootLine.Dest);
            }

            /*
             * ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;
             * if (this.canHitNonTargetPawnsNow)
             * {
             * projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
             * }
             * if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full)
             * {
             * projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
             * }
             * DebugMessage(launchTarget.ToString());
             * projectile2.Launch(caster, Ability.Def, drawPos, launchTarget, projectileHitFlags4, null,
             * UseAbilityProps.hediffsToApply,
             * UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
             */
            return(true);
        }
示例#22
0
        public bool TryCastShot_V1Vanilla_Modified()
        {
            var result = false;

            if (currentTarget.HasThing && currentTarget.Thing.Map != caster.Map)
            {
                return(false);
            }
            var flag = TryFindShootLineFromTo(caster.Position, currentTarget, out var shootLine);

            if (verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            var drawPos    = caster.DrawPos;
            var projectile = (Projectile)GenSpawn.Spawn(verbProps.defaultProjectile, shootLine.Source, caster.Map);

            ///MODIFIED SECTION
            ////////////////////////////////////////////

            if (lastShotReflected)
            {
                ////Log.Message("lastShotReflected Called");
                projectile.Launch(caster, currentTarget, currentTarget, ProjectileHitFlags.IntendedTarget, ownerEquipment); //TODO
                return(true);
            }

            ////////////////////////////////////////////
            //

            //projectile.FreeIntercept = canFreeInterceptNow && !projectile.def.projectile.flyOverhead;
            if (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(this.verbProps.forcedMissRadius);
                    int num2 = Rand.Range(0, max);
                    if (num2 > 0)
                    {
                        if (DebugViewSettings.drawShooting)
                        {
                            MoteMaker.ThrowText(caster.DrawPos, caster.Map, "ToForRad", -1f);
                        }
                        var c = currentTarget.Cell + GenRadial.RadialPattern[num2];
                        ProjectileHitFlags projectileHitFlags;
                        if (Rand.Chance(0.5f))
                        {
                            projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                        }
                        else
                        {
                            projectileHitFlags = ProjectileHitFlags.All;
                        }
                        if (!this.canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                        }
                        projectile.Launch(caster, currentTarget, c, projectileHitFlags, ownerEquipment); //TODO
                        return(true);
                    }
                }
            }
            var      shotReport            = ShotReport.HitReportFor(caster, this, currentTarget);
            Thing    randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef targetCoverDef        = (randomCoverToMissInto == null) ? null : randomCoverToMissInto.def;

            if (!Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture))
            {
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToWild", -1f);
                }
                shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
                ProjectileHitFlags projectileHitFlags2;
                if (Rand.Chance(0.5f))
                {
                    projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                }
                else
                {
                    projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                    if (this.canHitNonTargetPawnsNow)
                    {
                        projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
                    }
                }
                projectile.Launch(caster, currentTarget, shootLine.Dest, projectileHitFlags2, ownerEquipment); //TODO
                return(true);
            }
            if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance))
            {
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(caster.DrawPos, caster.Map, "ToCover", -1f);
                }
                if (currentTarget.Thing != null && currentTarget.Thing.def.category == ThingCategory.Pawn)
                {
                    ProjectileHitFlags projectileHitFlags5 = ProjectileHitFlags.NonTargetWorld;
                    if (this.canHitNonTargetPawnsNow)
                    {
                        projectileHitFlags5 |= ProjectileHitFlags.NonTargetPawns;
                    }
                    projectile.Launch(caster, currentTarget, randomCoverToMissInto, projectileHitFlags5, ownerEquipment);
                    return(true);
                }
            }
            else
            {
                if (!Rand.Chance(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)
                    {
                        ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
                        if (this.canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
                        }
                        projectile.Launch(caster, drawPos, randomCoverToMissInto, this.currentTarget,
                                          projectileHitFlags3, ownerEquipment, targetCoverDef);
                        return(true);
                    }
                }
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToHit", -1f);
                }
                ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;
                if (this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
                }
                if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full)
                {
                    projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
                }
                if (this.currentTarget.Thing != null)
                {
                    projectile.Launch(caster, drawPos, this.currentTarget, this.currentTarget, projectileHitFlags4,
                                      ownerEquipment, targetCoverDef);
                }
                else
                {
                    projectile.Launch(caster, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags4,
                                      ownerEquipment, targetCoverDef);
                }
                result = true;
            }
            return(result);
        }
        protected new bool?TryLaunchProjectile(ThingDef projectileDef, LocalTargetInfo launchTarget)
        {
            ShootLine shootLine;
            bool      flag  = base.TryFindShootLineFromTo(this.caster.Position, launchTarget, out shootLine);
            bool      flag2 = this.verbProps.stopBurstWithoutLos && !flag;
            bool?     result;

            if (flag2)
            {
                result = new bool?(false);
            }
            else
            {
                Vector3    drawPos    = this.caster.DrawPos;
                Projectile projectile = (Projectile)GenSpawn.Spawn(projectileDef, shootLine.Source, this.caster.Map, WipeMode.Vanish);
                SoundDef   soundCast  = this.verbProps.soundCast;
                if (soundCast != null)
                {
                    soundCast.PlayOneShot(new TargetInfo(this.caster.Position, this.caster.Map, false));
                }
                SoundDef soundCastTail = this.verbProps.soundCastTail;
                if (soundCastTail != null)
                {
                    soundCastTail.PlayOneShotOnCamera(null);
                }
                bool drawShooting = DebugViewSettings.drawShooting;
                if (drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToHit", -1f);
                }
                ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.IntendedTarget;
                bool canHitNonTargetPawnsNow          = this.canHitNonTargetPawnsNow;
                if (canHitNonTargetPawnsNow)
                {
                    projectileHitFlags |= ProjectileHitFlags.NonTargetPawns;
                }
                bool flag3 = !this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full;
                if (flag3)
                {
                    projectileHitFlags |= ProjectileHitFlags.NonTargetWorld;
                }

                // miss chance
                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) && !((VerbProperties_Ability)verbProps).AlwaysHits)
                {
                    shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
                    ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                    if (Rand.Chance(0.5f) && this.canHitNonTargetPawnsNow)
                    {
                        projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
                    }
                    projectile.Launch(caster, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags2, null, targetCoverDef);
                    return(true);
                }
                if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance) && !((VerbProperties_Ability)verbProps).AlwaysHits)
                {
                    ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
                    if (this.canHitNonTargetPawnsNow)
                    {
                        projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
                    }
                    projectile.Launch(caster, drawPos, randomCoverToMissInto, this.currentTarget, projectileHitFlags3, null, targetCoverDef);
                    return(true);
                }
                // miss chance end

                projectile.Launch(caster, launchTarget, launchTarget, projectileHitFlags, null);
                result = new bool?(true);
            }
            return(result);
        }
示例#24
0
        protected bool?TryLaunchProjectile(ThingDef projectileDef, LocalTargetInfo launchTarget)
        {
            DebugMessage(launchTarget.ToString());
            var flag = TryFindShootLineFromTo(caster.Position, launchTarget, out var shootLine);

            if (verbProps.stopBurstWithoutLos && !flag)
            {
                DebugMessage("Targeting cancelled");
                return(false);
            }
            var drawPos    = caster.DrawPos;
            var projectile = (Projectile_AbilityBase)GenSpawn.Spawn(projectileDef, shootLine.Source, caster.Map);

            projectile.extraDamages     = UseAbilityProps.extraDamages;
            projectile.localSpawnThings = UseAbilityProps.thingsToSpawn;

            //projectile. FreeIntercept = canFreeInterceptNow && !projectile.def.projectile.flyOverhead;
            var shotReport = ShotReport.HitReportFor(caster, this, launchTarget);

            verbProps.soundCast?.PlayOneShot(new TargetInfo(caster.Position, caster.Map, false));
            verbProps.soundCastTail?.PlayOneShotOnCamera();
//            if (!UseAbilityProps.AlwaysHits)
//            {
//                Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
//                ThingDef targetCoverDef = (randomCoverToMissInto == null) ? null : randomCoverToMissInto.def;
//                if (!Rand.Chance(shotReport.ChanceToNotGoWild_IgnoringPosture))
//                {
//                    if (DebugViewSettings.drawShooting)
//                        MoteMaker.ThrowText(caster.DrawPos, caster.Map, "ToWild", -1f);
//                    shootLine.ChangeDestToMissWild();
//                    ProjectileHitFlags projectileHitFlags2;
//                    if (Rand.Chance(0.5f))
//                    {
//                        projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
//                    }
//                    else
//                    {
//                        projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
//                        if (this.canHitNonTargetPawnsNow)
//                        {
//                            projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
//                        }
//                    }
//                    projectile.Launch(caster, Ability.Def, drawPos, shootLine.Dest, projectileHitFlags2, EquipmentSource,
//                        UseAbilityProps.hediffsToApply, UseAbilityProps.mentalStatesToApply,
//                        UseAbilityProps.thingsToSpawn);
//                    return true;
//                }
//                if (!Rand.Chance(shotReport.ChanceToNotHitCover))
//                {
//                    if (DebugViewSettings.drawShooting)
//                        MoteMaker.ThrowText(caster.DrawPos, caster.Map, "ToCover", -1f);
//                    if (launchTarget.Thing != null && launchTarget.Thing.def.category == ThingCategory.Pawn)
//                    {
//                        randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
//                        ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
//                        if (this.canHitNonTargetPawnsNow)
//                        {
//                            projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
//                        }
//                        projectile.Launch(caster, Ability.Def, drawPos, randomCoverToMissInto, projectileHitFlags3, null,
//                            UseAbilityProps.hediffsToApply, UseAbilityProps.mentalStatesToApply,
//                            UseAbilityProps.thingsToSpawn);
//                        return true;
//                    }
//                }
//            }
            if (DebugViewSettings.drawShooting)
            {
                MoteMaker.ThrowText(caster.DrawPos, caster.Map, "ToHit", -1f);
            }
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (this.canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            DebugMessage(launchTarget.ToString());
            projectile.Launch(caster, Ability.Def, drawPos, launchTarget, projectileHitFlags4, null, UseAbilityProps.hediffsToApply,
                              UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
            return(true);
        }
示例#25
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);
        }
        public static void CopyAndLaunchThingFromPosition(ThingDef projectileToCopy, Thing launcher, IntVec3 fromPosition, Map map, LocalTargetInfo target, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null)
        {
            Projectile newProjectile = (Projectile)GenSpawn.Spawn(projectileToCopy, fromPosition, map, WipeMode.Vanish);

            if (newProjectile != null && newProjectile is Projectile)
            {
                newProjectile.Launch(launcher, target, intendedTarget, hitFlags, false, equipment);
            }
        }
示例#27
0
 public void Launch(Thing launcher, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null)
 {
     this.Launch(launcher, base.Position.ToVector3Shifted(), usedTarget, intendedTarget, hitFlags, equipment, null);
 }
示例#28
0
        private void LanuchWithDamageMultiplier(Projectile projectile2, Thing launcher, Vector3 origin, LocalTargetInfo usedTarget, LocalTargetInfo intendedTarget, ProjectileHitFlags hitFlags, Thing equipment = null, ThingDef targetCoverDef = null)
        {
            projectile2.Launch(launcher, origin, usedTarget, intendedTarget, hitFlags, equipment, targetCoverDef);
            if (EquipmentSource == null)
            {
                return;
            }

            //取消掉精度修正,不管有没有反正null一下
            Patch.Methons.adjustedAccuracyFactor = null;
            if (CompShootMode == null)
            {
                return;
            }
            CompShootMode.PostPostProjectileLaunch(projectile2);
        }
示例#29
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);
        }
示例#30
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);
        }