Exemple #1
0
        public override Job JobOnThing(Pawn pawn, Thing t)
        {
            Building_TurretGunCR turret = t as Building_TurretGunCR;

            if (turret == null)
            {
                return(null);
            }

            Thing ammo = GenClosest.ClosestThingReachable(pawn.Position,
                                                          ThingRequest.ForDef(turret.compAmmo.selectedAmmo),
                                                          PathEndMode.ClosestTouch,
                                                          TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn),
                                                          80,
                                                          x => !x.IsForbidden(pawn) && pawn.CanReserve(x));

            if (ammo == null)
            {
                return(null);
            }
            int amountNeeded = turret.compAmmo.Props.magazineSize;

            if (turret.compAmmo.currentAmmo == turret.compAmmo.selectedAmmo)
            {
                amountNeeded -= turret.compAmmo.curMagCount;
            }
            return(new Job(DefDatabase <JobDef> .GetNamed("ReloadTurret"), t, ammo)
            {
                maxNumToCarry = Mathf.Min(amountNeeded, ammo.stackCount)
            });
        }
Exemple #2
0
        /// <summary>
        /// Handles activating aim mode at the start of the burst
        /// </summary>
        public override void WarmupComplete()
        {
            if (xpTicks <= 0)
            {
                xpTicks = Mathf.CeilToInt(verbProps.warmupTicks * 0.5f);
            }

            if (this.shouldAim && !this.isAiming)
            {
                float targetDist = (this.currentTarget.Cell - this.caster.Position).LengthHorizontal;
                int   aimTicks   = (int)Mathf.Lerp(aimTicksMin, aimTicksMax, (targetDist / 100));
                if (CasterIsPawn)
                {
                    this.CasterPawn.stances.SetStance(new Stance_Warmup(aimTicks, this.currentTarget, this));
                    this.isAiming = true;
                    return;
                }
                else
                {
                    Building_TurretGunCR turret = caster as Building_TurretGunCR;
                    if (turret != null)
                    {
                        turret.burstWarmupTicksLeft += aimTicks;
                        this.isAiming = true;
                        return;
                    }
                }
            }

            // Shooty stuff
            base.WarmupComplete();
            this.isAiming = false;
        }
Exemple #3
0
        public override bool HasJobOnThing(Pawn pawn, Thing t)
        {
            Building_TurretGunCR turret = t as Building_TurretGunCR;

            if (turret == null || !turret.allowAutomaticReload)
            {
                return(false);
            }
            return(HasJobOnThingForced(pawn, t));
        }
        private void InitTurret()
        {
            Building_TurretGunCR turret = parent as Building_TurretGunCR;

            if (turret != null && turret.gun == null)
            {
                gun        = (Thing)ThingMaker.MakeThing(parent.def.building.turretGunDef);
                turret.gun = gun;
            }
        }
Exemple #5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            if (pawn.Faction != Faction.OfPlayer)
            {
                TargetThingB.SetForbidden(false, false);
                this.FailOnDestroyedOrNull(TargetIndex.A);
                this.FailOnDestroyedOrNull(TargetIndex.B);
            }
            else
            {
                this.FailOnDestroyedNullOrForbidden(TargetIndex.A);
                this.FailOnDestroyedNullOrForbidden(TargetIndex.B);
            }

            // Haul ammo
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

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

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

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

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

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.A, null, false));

            // Wait in place
            var waitToil = new Toil();

            waitToil.initAction = new Action(delegate
            {
                waitToil.actor.pather.StopDead();
                compReloader.TryStartReload();
            });
            waitToil.defaultCompleteMode = ToilCompleteMode.Delay;
            waitToil.defaultDuration     = Mathf.CeilToInt(compReloader.Props.reloadTicks / pawn.GetStatValue(StatDef.Named("ReloadSpeed")));
            yield return(waitToil.WithProgressBarToilDelay(TargetIndex.A));

            //Actual reloader
            var reloadToil = new Toil();

            reloadToil.defaultCompleteMode = ToilCompleteMode.Instant;
            reloadToil.initAction          = new Action(delegate
            {
                Building_TurretGunCR turret = TargetThingA as Building_TurretGunCR;
                if (compReloader != null && turret.compAmmo != null)
                {
                    compReloader.LoadAmmo(TargetThingB);
                }
            });
            reloadToil.EndOnDespawnedOrNull(TargetIndex.B);
            yield return(reloadToil);
        }
Exemple #6
0
        public override bool HasJobOnThingForced(Pawn pawn, Thing t)
        {
            Building_TurretGunCR turret = t as Building_TurretGunCR;

            if (turret == null || !turret.needsReload || !pawn.CanReserveAndReach(turret, PathEndMode.ClosestTouch, Danger.Deadly) || turret.IsForbidden(pawn.Faction))
            {
                return(false);
            }
            Thing ammo = GenClosest.ClosestThingReachable(pawn.Position,
                                                          ThingRequest.ForDef(turret.compAmmo.selectedAmmo),
                                                          PathEndMode.ClosestTouch,
                                                          TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn),
                                                          80,
                                                          x => !x.IsForbidden(pawn) && pawn.CanReserve(x));

            return(ammo != null);
        }