public static void Postfix(RimWorld.Building_TurretGun __instance, ref bool __result)
 {
     if (AMAMod.Dev && __instance is Building_TurretGun Turret)
     {
         __result = Turret.IsMortarOrProjectileFliesOverhead;
     }
 }
 public static void Postfix(RimWorld.Building_TurretGun __instance, ref bool __result)
 {
     if (AMAMod.Dev && __instance is Building_TurretGun Turret)
     {
         __result = Turret.CanSetForcedTarget;
     }
 }
 public static void Postfix(RimWorld.Building_TurretGun __instance, ref bool __result)
 {
     if (AMAMod.Dev && __instance is Building_TurretGun Turret)
     {
         __result = Turret.IsMortar;
     }
 }
Exemple #4
0
        public static Thing FindAmmoForTurret(Pawn pawn, Building_TurretGun gun)
        {
            StorageSettings   allowedShellsSettings = (!pawn.IsColonist) ? null : gun.gun.TryGetComp <CompChangeableProjectile>().allowedShellsSettings;
            Predicate <Thing> validator             = (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t, 10, 1, null, false) && (allowedShellsSettings == null || allowedShellsSettings.AllowedToAccept(t));

            return(GenClosest.ClosestThingReachable(gun.Position, gun.Map, ThingRequest.ForGroup(ThingRequestGroup.Shell), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 40f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
        }
 public static void Postfix(RimWorld.Building_TurretGun __instance, ref bool __result)
 {
     if (AMAMod.Dev && __instance is Building_TurretGun Turret)
     {
         __result = Turret.PlayerControlled;
     }
 }
Exemple #6
0
        private static bool GunNeedsLoading(Building b)
        {
            Building_TurretGun building_TurretGun = b as Building_TurretGun;

            if (building_TurretGun == null)
            {
                return(false);
            }
            CompChangeableProjectile compChangeableProjectile = building_TurretGun.gun.TryGetComp <CompChangeableProjectile>();

            return(compChangeableProjectile != null && !compChangeableProjectile.Loaded);
        }
Exemple #7
0
        private static bool GunNeedsLoading(Building b)
        {
            Building_TurretGun building_TurretGun = b as Building_TurretGun;
            bool result;

            if (building_TurretGun == null)
            {
                result = false;
            }
            else
            {
                CompChangeableProjectile compChangeableProjectile = building_TurretGun.gun.TryGetComp <CompChangeableProjectile>();
                result = (compChangeableProjectile != null && !compChangeableProjectile.Loaded);
            }
            return(result);
        }
        public static Thing FindAmmoForTurret(Pawn pawn, Building_TurretGun gun)
        {
            StorageSettings   allowedShellsSettings = pawn.IsColonist ? gun.gun.TryGetComp <CompChangeableProjectile>().allowedShellsSettings : null;
            Predicate <Thing> validator             = delegate(Thing t)
            {
                if (t.IsForbidden(pawn))
                {
                    return(false);
                }
                if (!pawn.CanReserve(t, 10, 1))
                {
                    return(false);
                }
                return((allowedShellsSettings == null || allowedShellsSettings.AllowedToAccept(t)) ? true : false);
            };

            return(GenClosest.ClosestThingReachable(gun.Position, gun.Map, ThingRequest.ForGroup(ThingRequestGroup.Shell), PathEndMode.OnCell, TraverseParms.For(pawn), 40f, validator));
        }
Exemple #9
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            _003CMakeNewToils_003Ec__Iterator0 _003CMakeNewToils_003Ec__Iterator = (_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_004e: stateMachine*/;

            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            Toil gotoTurret   = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell);
            Toil loadIfNeeded = new Toil();

            loadIfNeeded.initAction = delegate
            {
                Pawn               actor              = loadIfNeeded.actor;
                Building           building           = (Building)actor.CurJob.targetA.Thing;
                Building_TurretGun building_TurretGun = building as Building_TurretGun;
                if (!JobDriver_ManTurret.GunNeedsLoading(building))
                {
                    _003CMakeNewToils_003Ec__Iterator._0024this.JumpToToil(gotoTurret);
                }
                else
                {
                    Thing thing = JobDriver_ManTurret.FindAmmoForTurret(_003CMakeNewToils_003Ec__Iterator._0024this.pawn, building_TurretGun);
                    if (thing == null)
                    {
                        if (actor.Faction == Faction.OfPlayer)
                        {
                            Messages.Message("MessageOutOfNearbyShellsFor".Translate(actor.LabelShort, building_TurretGun.Label).CapitalizeFirst(), building_TurretGun, MessageTypeDefOf.NegativeEvent);
                        }
                        actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                    }
                    actor.CurJob.targetB = thing;
                    actor.CurJob.count   = 1;
                }
            };
            yield return(loadIfNeeded);

            /*Error: Unable to find new state assignment for yield return*/;
        }
Exemple #10
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            Toil gotoTurret   = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell);
            Toil loadIfNeeded = new Toil();

            loadIfNeeded.initAction = delegate
            {
                Pawn               actor              = loadIfNeeded.actor;
                Building           building           = (Building)actor.CurJob.targetA.Thing;
                Building_TurretGun building_TurretGun = building as Building_TurretGun;
                if (!JobDriver_ManTurret.GunNeedsLoading(building))
                {
                    this.$this.JumpToToil(gotoTurret);
                    return;
                }
                Thing thing = JobDriver_ManTurret.FindAmmoForTurret(this.$this.pawn, building_TurretGun);
                if (thing == null)
                {
                    if (actor.Faction == Faction.OfPlayer)
                    {
                        Messages.Message("MessageOutOfNearbyShellsFor".Translate(new object[]
                        {
                            actor.LabelShort,
                            building_TurretGun.Label
                        }).CapitalizeFirst(), building_TurretGun, MessageTypeDefOf.NegativeEvent, true);
                    }
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
                actor.CurJob.targetB = thing;
                actor.CurJob.count   = 1;
            };
            yield return(loadIfNeeded);

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 10, 1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(TargetIndex.B));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Pawn actor = loadIfNeeded.actor;
                    Building building = (Building)actor.CurJob.targetA.Thing;
                    Building_TurretGun building_TurretGun = building as Building_TurretGun;
                    SoundDefOf.Artillery_ShellLoaded.PlayOneShot(new TargetInfo(building_TurretGun.Position, building_TurretGun.Map, false));
                    building_TurretGun.gun.TryGetComp <CompChangeableProjectile>().LoadShell(actor.CurJob.targetB.Thing.def, 1);
                    actor.carryTracker.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
            });

            yield return(gotoTurret);

            Toil man = new Toil();

            man.tickAction = delegate
            {
                Pawn     actor    = man.actor;
                Building building = (Building)actor.CurJob.targetA.Thing;
                if (JobDriver_ManTurret.GunNeedsLoading(building))
                {
                    this.$this.JumpToToil(loadIfNeeded);
                    return;
                }
                building.GetComp <CompMannable>().ManForATick(actor);
            };
            man.defaultCompleteMode = ToilCompleteMode.Never;
            man.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
            yield return(man);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            Toil gotoTurret   = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell);
            Toil loadIfNeeded = new Toil();

            loadIfNeeded.initAction = delegate
            {
                Pawn               actor3 = loadIfNeeded.actor;
                Building           obj    = (Building)actor3.CurJob.targetA.Thing;
                Building_TurretGun building_TurretGun2 = obj as Building_TurretGun;
                if (!GunNeedsLoading(obj))
                {
                    JumpToToil(gotoTurret);
                }
                else
                {
                    Thing thing = FindAmmoForTurret(pawn, building_TurretGun2);
                    if (thing == null)
                    {
                        if (actor3.Faction == Faction.OfPlayer)
                        {
                            Messages.Message("MessageOutOfNearbyShellsFor".Translate(actor3.LabelShort, building_TurretGun2.Label, actor3.Named("PAWN"), building_TurretGun2.Named("GUN")).CapitalizeFirst(), building_TurretGun2, MessageTypeDefOf.NegativeEvent);
                        }
                        actor3.jobs.EndCurrentJob(JobCondition.Incompletable);
                    }
                    actor3.CurJob.targetB = thing;
                    actor3.CurJob.count   = 1;
                }
            };
            yield return(loadIfNeeded);

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 10, 1));

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(TargetIndex.B));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor2 = loadIfNeeded.actor;
                Building_TurretGun building_TurretGun = ((Building)actor2.CurJob.targetA.Thing) as Building_TurretGun;
                SoundDefOf.Artillery_ShellLoaded.PlayOneShot(new TargetInfo(building_TurretGun.Position, building_TurretGun.Map));
                building_TurretGun.gun.TryGetComp <CompChangeableProjectile>().LoadShell(actor2.CurJob.targetB.Thing.def, 1);
                actor2.carryTracker.innerContainer.ClearAndDestroyContents();
            };
            yield return(toil);

            yield return(gotoTurret);

            Toil man = new Toil();

            man.tickAction = delegate
            {
                Pawn     actor    = man.actor;
                Building building = (Building)actor.CurJob.targetA.Thing;
                if (GunNeedsLoading(building))
                {
                    JumpToToil(loadIfNeeded);
                }
                else
                {
                    building.GetComp <CompMannable>().ManForATick(actor);
                    man.actor.rotationTracker.FaceCell(building.Position);
                }
            };
            man.handlingFacing      = true;
            man.defaultCompleteMode = ToilCompleteMode.Never;
            man.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
            yield return(man);
        }