static bool Prefix(LordToil_DoOpportunisticTaskOrCover __instance)
        {
            if (!__instance.cover || Find.TickManager.TicksGame % 181 > RefcellRespeedConfig.currentTimeMultiplier - 1)
            {
                return(false);
            }
            List <Thing> alreadyTakenTargets = (List <Thing>)null;

            for (int index = 0; index < __instance.lord.ownedPawns.Count; ++index)
            {
                Pawn ownedPawn = __instance.lord.ownedPawns[index];
                if (!ownedPawn.Downed && ownedPawn.mindState.duty.def == DutyDefOf.AssaultColony)
                {
                    Thing target = (Thing)null;
                    if (__instance.TryFindGoodOpportunisticTaskTarget(ownedPawn, out target, alreadyTakenTargets) && !__instance.Map.reservationManager.IsReservedByAnyoneOf((LocalTargetInfo)target, __instance.lord.faction) && !GenAI.InDangerousCombat(ownedPawn))
                    {
                        ownedPawn.mindState.duty = new PawnDuty(__instance.DutyDef);
                        ownedPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        if (alreadyTakenTargets == null)
                        {
                            alreadyTakenTargets = new List <Thing>();
                        }
                        alreadyTakenTargets.Add(target);
                    }
                }
            }
            return(false);
        }
示例#2
0
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (!RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot))
     {
         return(null);
     }
     if (KidnapAIUtility.TryFindGoodKidnapVictim(pawn, 18f, out Pawn victim) && !GenAI.InDangerousCombat(pawn))
     {
         Job job = new Job(JobDefOf.Kidnap);
         job.targetA = victim;
         job.targetB = spot;
         job.count   = 1;
         return(job);
     }
     return(null);
 }
        private static Toil JumpToAlsoCollectTargetInQueue(Toil gotoGetTargetToil, TargetIndex ind)
        {
            const float MaxDist = 8;

            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn actor = toil.actor;

                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error("JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.");
                    return;
                }

                //Early-out
                if (actor.carryTracker.Full)
                {
                    return;
                }

                Job curJob      = actor.jobs.curJob;
                var targetQueue = curJob.GetTargetQueue(ind);

                if (targetQueue.NullOrEmpty())
                {
                    return;
                }

                //Find an item in the queue matching what you're carrying
                for (int i = 0; i < targetQueue.Count; i++)
                {
                    //Can't use item - skip
                    if (!GenAI.CanUseItemForWork(actor, targetQueue[i].Thing))
                    {
                        continue;
                    }

                    //Cannot stack with thing in hands - skip
                    if (!targetQueue[i].Thing.CanStackWith(actor.carryTracker.CarriedThing))
                    {
                        continue;
                    }

                    //Too far away - skip
                    if ((actor.Position - targetQueue[i].Thing.Position).LengthHorizontalSquared > MaxDist * MaxDist)
                    {
                        continue;
                    }

                    //Determine num in hands
                    int numInHands = (actor.carryTracker.CarriedThing == null) ? 0 : actor.carryTracker.CarriedThing.stackCount;

                    //Determine num to take
                    int numToTake = curJob.countQueue[i];
                    numToTake = Mathf.Min(numToTake, targetQueue[i].Thing.def.stackLimit - numInHands);
                    numToTake = Mathf.Min(numToTake, actor.carryTracker.AvailableStackSpace(targetQueue[i].Thing.def));

                    //Won't take any - skip
                    if (numToTake <= 0)
                    {
                        continue;
                    }

                    //Set me to go get it
                    curJob.count = numToTake;
                    curJob.SetTarget(ind, targetQueue[i].Thing);

                    //Remove the amount to take from the num to bring list
                    //Remove from queue if I'm going to take all
                    curJob.countQueue[i] -= numToTake;
                    if (curJob.countQueue[i] == 0)
                    {
                        curJob.countQueue.RemoveAt(i);
                        targetQueue.RemoveAt(i);
                    }

                    //Jump to toil
                    actor.jobs.curDriver.JumpToToil(gotoGetTargetToil);
                    return;
                }
            };

            return(toil);
        }
        public override void CompTick()
        {
            base.CompTick();
            if (IsMounted)
            {
                if (!Driver.Spawned)
                {
                    parent.DeSpawn();
                    return;
                }

                if (Driver.Dead || Driver.Downed || Driver.health.InPainShock ||
                    Driver.MentalStateDef == MentalStateDefOf.WanderPsychotic ||
                    (parent.IsForbidden(Faction.OfPlayer) && Driver.Faction == Faction.OfPlayer))
                {
                    if (!Driver.Position.InBounds())
                    {
                        DismountAt(Driver.Position);
                        return;
                    }

                    DismountAt(Driver.Position - parent.def.interactionCellOffset.RotatedBy(Driver.Rotation));
                    Driver.Position = Driver.Position.RandomAdjacentCell8Way();
                    return;
                }


                if (Find.TickManager.TicksGame - tickCheck >= tickCooldown)
                {
                    if (Driver.Faction == Faction.OfPlayer && Driver.CurJob != null)
                    {
                        if (Driver.CurJob.def.playerInterruptible && (
                                Driver.CurJob.def == JobDefOf.GotoWander ||
                                Driver.CurJob.def == JobDefOf.Open ||
                                Driver.CurJob.def == JobDefOf.ManTurret ||
                                Driver.CurJob.def == JobDefOf.EnterCryptosleepCasket ||
                                Driver.CurJob.def == JobDefOf.UseNeurotrainer ||
                                Driver.CurJob.def == JobDefOf.UseArtifact ||
                                Driver.CurJob.def == JobDefOf.DoBill ||
                                Driver.CurJob.def == JobDefOf.Research ||
                                Driver.CurJob.def == JobDefOf.OperateDeepDrill ||
                                Driver.CurJob.def == JobDefOf.Repair ||
                                Driver.CurJob.def == JobDefOf.FixBrokenDownBuilding ||
                                Driver.CurJob.def == JobDefOf.UseCommsConsole ||
                                Driver.CurJob.def == JobDefOf.BuryCorpse ||
                                Driver.CurJob.def == JobDefOf.TradeWithPawn ||
                                Driver.CurJob.def == JobDefOf.Lovin ||
                                Driver.CurJob.def == JobDefOf.SocialFight ||
                                Driver.CurJob.def == JobDefOf.Maintain ||
                                Driver.CurJob.def == JobDefOf.MarryAdjacentPawn ||
                                Driver.CurJob.def == JobDefOf.SpectateCeremony ||
                                Driver.CurJob.def == JobDefOf.StandAndBeSociallyActive ||
                                Driver.CurJob.def == JobDefOf.LayDown ||
                                Driver.CurJob.def == JobDefOf.Ingest ||
                                Driver.CurJob.def == JobDefOf.SocialRelax ||
                                Driver.CurJob.def == JobDefOf.Refuel ||
                                Driver.CurJob.def == JobDefOf.FillFermentingBarrel ||
                                Driver.CurJob.def == JobDefOf.TakeBeerOutOfFermentingBarrel ||
                                Driver.CurJob.def == JobDefOf.TakeWoundedPrisonerToBed ||
                                Driver.CurJob.def == JobDefOf.TakeToBedToOperate ||
                                Driver.CurJob.def == JobDefOf.EscortPrisonerToBed ||
                                Driver.CurJob.def == JobDefOf.CarryToCryptosleepCasket ||
                                Driver.CurJob.def == JobDefOf.ReleasePrisoner ||
                                Driver.CurJob.def == JobDefOf.PrisonerAttemptRecruit ||
                                Driver.CurJob.def == JobDefOf.PrisonerFriendlyChat ||
                                Driver.CurJob.def == JobDefOf.PrisonerExecution ||
                                Driver.CurJob.def == JobDefOf.FeedPatient ||
                                Driver.CurJob.def == JobDefOf.TendPatient ||
                                Driver.CurJob.def == JobDefOf.VisitSickPawn ||
                                Driver.CurJob.def == JobDefOf.Slaughter ||
                                Driver.CurJob.def == JobDefOf.Milk ||
                                Driver.CurJob.def == JobDefOf.Shear ||
                                Driver.CurJob.def == JobDefOf.Train ||
                                Driver.CurJob.def == JobDefOf.Mate ||
                                Driver.health.NeedsMedicalRest ||
                                Driver.health.PrefersMedicalRest
                                ) && Driver.Position.Roofed())
                        {
                            parent.Position = Position.ToIntVec3();
                            parent.Rotation = Driver.Rotation;
                            if (!Driver.Position.InBounds())
                            {
                                DismountAt(Driver.Position);
                                return;
                            }
                            DismountAt(Driver.Position - InteractionOffset.ToIntVec3());
                            Driver.Position = Driver.Position.RandomAdjacentCell8Way();
                            return;
                        }
                    }
                    tickCheck    = Find.TickManager.TicksGame;
                    tickCooldown = Rand.RangeInclusive(60, 180);

                    CompVehicle vehicleComp = parent.TryGetComp <CompVehicle>();

                    if (!vehicleComp.MotorizedWithoutFuel())
                    {
                        CompRefuelable refuelableComp = parent.TryGetComp <CompRefuelable>();
                        Job            jobNew         = ToolsForHaulUtility.DismountInBase(Driver, MapComponent_ToolsForHaul.currentVehicle[Driver]);

                        if (Driver.Faction == Faction.OfPlayer)
                        {
                            if (!GenAI.EnemyIsNear(Driver, 40f))
                            {
                                if (parent.HitPoints / parent.MaxHitPoints < 0.65f ||
                                    (Driver.CurJob != null && Driver.jobs.curDriver.asleep) ||
                                    vehicleComp.tankLeaking ||
                                    !refuelableComp.HasFuel)
                                {
                                    Driver.jobs.StartJob(jobNew, JobCondition.InterruptForced);
                                }
                            }
                        }

                        else if (!refuelableComp.HasFuel)
                        {
                            Dismount();
                            FireUtility.TryStartFireIn(Position.ToIntVec3(), 0.1f);
                        }
                    }
                }
                if (Find.TickManager.TicksGame - tickLastDoorCheck >= 96 &&
                    (Driver.Position.GetEdifice() is Building_Door || parent.Position.GetEdifice() is Building_Door))
                {
                    lastPassedDoor =
                        (Driver.Position.GetEdifice() is Building_Door
                            ? Driver.Position.GetEdifice()
                            : parent.Position.GetEdifice()) as Building_Door;
                    lastPassedDoor.StartManualOpenBy(Driver);
                    tickLastDoorCheck = Find.TickManager.TicksGame;
                }
                else if (Find.TickManager.TicksGame - tickLastDoorCheck >= 96 && lastPassedDoor != null)
                {
                    lastPassedDoor.StartManualCloseBy(Driver);
                    lastPassedDoor = null;
                }
                if (Driver.pather.Moving && Driver.Position != (Driver.pather.Destination.Cell))
                {
                    lastDrawAsAngle = Driver.Rotation.AsAngle;
                    parent.Position = (Position.ToIntVec3());
                    parent.Rotation = (Driver.Rotation);
                }
            }
        }
 public override void LordToilTick()
 {
     if (cover && Find.TickManager.TicksGame % 181 == 0)
     {
         List <Thing> list = null;
         for (int i = 0; i < lord.ownedPawns.Count; i++)
         {
             Pawn pawn = lord.ownedPawns[i];
             if (!pawn.Downed && pawn.mindState.duty.def == DutyDefOf.AssaultColony)
             {
                 Thing target = null;
                 if (TryFindGoodOpportunisticTaskTarget(pawn, out target, list) && !base.Map.reservationManager.IsReservedByAnyoneOf(target, lord.faction) && !GenAI.InDangerousCombat(pawn))
                 {
                     pawn.mindState.duty = new PawnDuty(DutyDef);
                     pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                     if (list == null)
                     {
                         list = new List <Thing>();
                     }
                     list.Add(target);
                 }
             }
         }
     }
 }
        // Token: 0x060004D1 RID: 1233 RVA: 0x0003100C File Offset: 0x0002F40C
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (!SettingsHelper.latest.AllowPredalienImpregnations)
            {
                return(null);
            }
            if (pawn.jobs.debugLog)
            {
                pawn.jobs.DebugLogEvent(string.Format("JobGiver_PredalienImpregnate TryGiveJob"));
            }
            Pawn t;

            if (XenomorphKidnapUtility.TryFindGoodImpregnateVictim(pawn, 18f, out t, null) && !GenAI.InDangerousCombat(pawn))
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("victim found: {0}", t.LabelShortCap));
                }
                return(new Job(XenomorphDefOf.RRY_Job_Xenomorph_PredalienImpregnate)
                {
                    targetA = t
                });
            }
            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            Predicate <Thing> validator = delegate(Thing t)
            {
                Pawn pawn3 = (Pawn)t;
                return(pawn3.Downed && pawn3.Faction == pawn.Faction && !pawn3.InBed() && pawn.CanReserve(pawn3, 1, -1, null, false) && !pawn3.IsForbidden(pawn) && !GenAI.EnemyIsNear(pawn3, 25f));
            };
            Pawn pawn2 = (Pawn)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), this.radius, validator, null, 0, -1, false, RegionType.Set_Passable, false);
            Job  result;

            if (pawn2 == null)
            {
                result = null;
            }
            else
            {
                Building_Bed building_Bed = RestUtility.FindBedFor(pawn2, pawn, pawn2.HostFaction == pawn.Faction, false, false);
                if (building_Bed == null || !pawn2.CanReserve(building_Bed, 1, -1, null, false))
                {
                    result = null;
                }
                else
                {
                    result = new Job(JobDefOf.Rescue, pawn2, building_Bed)
                    {
                        count = 1
                    };
                }
            }
            return(result);
        }
示例#8
0
        // Token: 0x06000524 RID: 1316 RVA: 0x0003381C File Offset: 0x00031C1C
        protected override Job TryGiveJob(Pawn pawn)
        {
            Predicate <Thing> validator = delegate(Thing t)
            {
                Pawn  pawn3   = (Pawn)t;
                float eggDist = 9999f;
                Thing egg     = XenomorphUtil.ClosestReachableEgg(pawn3);
                if (egg != null)
                {
                    eggDist = XenomorphUtil.DistanceBetween(pawn3.Position, egg.Position);
                }
                else
                {
                    return(false);
                }
                if (eggDist == 9999f || eggDist <= 5)
                {
                    return(false);
                }
                return(pawn3.Downed && pawn3.Faction != pawn.Faction && XenomorphUtil.isInfectablePawn(pawn3) && pawn.CanReserve(pawn3, 1, -1, null, false) && !pawn3.IsForbidden(pawn) && !GenAI.EnemyIsNear(pawn3, 25f));
            };
            Pawn pawn2 = (Pawn)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), this.radius, validator, null, 0, -1, false, RegionType.Set_Passable, false);

            if (pawn2 == null)
            {
                return(null);
            }
            Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(XenomorphDefOf.RRY_EggXenomorphFertilized), PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), 9999f, null, null, 0, -1, false, RegionType.Set_Passable, false);

            if (thing == null)
            {
                return(null);

                thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(XenomorphDefOf.RRY_EggXenomorphFertilized), PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), 9999f, null, null, 0, -1, false, RegionType.Set_Passable, false);
                if (thing == null)
                {
                    return(null);
                }
            }
            return(new Job(XenomorphDefOf.RRY_Job_XenomorphKidnap, pawn2, thing)
            {
                count = 1
            });
        }
示例#9
0
        internal static bool PawnCanOpen(this Building_Door d, Pawn p)
        {
            Lord lord = p.GetLord();

            return((lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(p)) || d.Faction == null || GenAI.MachinesLike(d.Faction, p) || p.health.hediffSet.HasHediff(HediffDefOfPsychology.Thief));
        }
示例#10
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;

            if (pawn2 == null || !pawn2.Downed || pawn2.Faction != pawn.Faction || pawn2.InBed() || !pawn.CanReserve(pawn2, 1, -1, null, forced) || GenAI.EnemyIsNear(pawn2, 40f))
            {
                return(false);
            }
            Thing thing = FindBed(pawn, pawn2);

            if (thing != null && pawn2.CanReserve(thing))
            {
                return(true);
            }
            return(false);
        }
        public override Job TryGiveJob(Pawn pawn)
        {
            float   Searchradius = SearchRadius;
            IntVec3 c            = IntVec3.Invalid;

            if (pawn.kindDef == AdeptusPawnKindDefOf.OG_Necron_Tomb_Spyder)
            {
                if (TombSpyderUtility.TryFindGoodRepairTarget(pawn, Searchradius, out Pawn pt, null) && !GenAI.InDangerousCombat(pawn))
                {
                    return(new Job(AdeptusJobDefOf.OG_XB_Job_Necron_TombSpyderRepair)
                    {
                        targetA = pt,
                        count = 1
                    });
                }
                else
                {
                    if (TombSpyderUtility.TryFindGoodRessTarget(pawn, Searchradius, out Corpse ct, null) && !GenAI.InDangerousCombat(pawn))
                    {
                        return(new Job(AdeptusJobDefOf.OG_XB_Job_Necron_TombSpyderRepair)
                        {
                            targetA = ct,
                            count = 1
                        });
                    }
                }
            }
示例#12
0
        public override void UpdateAllDuties()
        {
            if (!this.Data.sapperDest.IsValid && this.lord.ownedPawns.Any <Pawn>())
            {
                this.Data.sapperDest = GenAI.RandomRaidDest(this.lord.ownedPawns[0].Position, base.Map);
            }
            List <Pawn> list = null;

            if (this.Data.sapperDest.IsValid)
            {
                list = new List <Pawn>();
                for (int i = 0; i < this.lord.ownedPawns.Count; i++)
                {
                    Pawn pawn = this.lord.ownedPawns[i];
                    if (SappersUtility.IsGoodSapper(pawn))
                    {
                        list.Add(pawn);
                    }
                }
                if (list.Count == 0 && this.lord.ownedPawns.Count >= 2)
                {
                    Pawn pawn2 = null;
                    int  num   = 0;
                    for (int j = 0; j < this.lord.ownedPawns.Count; j++)
                    {
                        if (SappersUtility.IsGoodBackupSapper(this.lord.ownedPawns[j]))
                        {
                            int level = this.lord.ownedPawns[j].skills.GetSkill(SkillDefOf.Mining).Level;
                            if (pawn2 == null || level > num)
                            {
                                pawn2 = this.lord.ownedPawns[j];
                                num   = level;
                            }
                        }
                    }
                    if (pawn2 != null)
                    {
                        list.Add(pawn2);
                    }
                }
            }
            for (int k = 0; k < this.lord.ownedPawns.Count; k++)
            {
                Pawn pawn3 = this.lord.ownedPawns[k];
                if (list != null && list.Contains(pawn3))
                {
                    pawn3.mindState.duty = new PawnDuty(DutyDefOf.Sapper, this.Data.sapperDest, -1f);
                }
                else if (!list.NullOrEmpty <Pawn>())
                {
                    float randomInRange;
                    if (pawn3.equipment != null && pawn3.equipment.Primary != null && pawn3.equipment.Primary.def.IsRangedWeapon)
                    {
                        randomInRange = LordToil_AssaultColonySappers.EscortRadiusRanged.RandomInRange;
                    }
                    else
                    {
                        randomInRange = LordToil_AssaultColonySappers.EscortRadiusMelee.RandomInRange;
                    }
                    pawn3.mindState.duty = new PawnDuty(DutyDefOf.Escort, list.RandomElement <Pawn>(), randomInRange);
                }
                else
                {
                    pawn3.mindState.duty = new PawnDuty(DutyDefOf.AssaultColony);
                }
            }
        }
示例#13
0
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (!RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot))
     {
         return(null);
     }
     if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 12f, out Thing item, pawn) && !GenAI.InDangerousCombat(pawn))
     {
         Job job = new Job(JobDefOf.Steal);
         job.targetA = item;
         job.targetB = spot;
         job.count   = Mathf.Min(item.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / item.def.VolumePerUnit));
         return(job);
     }
     return(null);
 }
示例#14
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;
            CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();

            if (pawn.health.hediffSet.HasHediff(HediffDef.Named("TM_EntertainingHD"), false) && comp.nextEntertainTick < Find.TickManager.TicksGame)
            {
                if (pawn2 != null && pawn2 != pawn && pawn2.RaceProps.Humanlike && pawn2.IsColonist && pawn2.Awake() && !pawn2.Drafted && !pawn.Drafted)
                {
                    if ((pawn.Position - pawn2.Position).LengthHorizontal < 50f && !GenAI.EnemyIsNear(pawn2, 40f))
                    {
                        IEnumerable <Pawn> breakingPawnsExtreme = BreakRiskAlertUtility.PawnsAtRiskExtreme;
                        foreach (Pawn current in breakingPawnsExtreme)
                        {
                            if (current == pawn2)
                            {
                                bool flag = true;
                                List <Thought_Memory> pawn2Memories = pawn.needs.mood.thoughts.memories.Memories;
                                for (int i = 0; i < pawn2Memories.Count; i++)
                                {
                                    if (pawn2Memories[i].def.defName == "TM_EntertainedTD" && pawn2Memories[i].MoodOffset() > 11f)
                                    {
                                        flag = false;
                                    }
                                }
                                if (flag)
                                {
                                    return(true);
                                }
                                return(false);
                            }
                        }
                        IEnumerable <Pawn> breakingPawnsMajor = BreakRiskAlertUtility.PawnsAtRiskMajor;
                        foreach (Pawn current in breakingPawnsMajor)
                        {
                            if (current == pawn2)
                            {
                                bool flag = true;
                                List <Thought_Memory> pawn2Memories = pawn.needs.mood.thoughts.memories.Memories;
                                for (int i = 0; i < pawn2Memories.Count; i++)
                                {
                                    if (pawn2Memories[i].def.defName == "TM_EntertainedTD")
                                    {
                                        flag = false;
                                    }
                                }
                                if (flag)
                                {
                                    return(true);
                                }
                                return(false);
                            }
                        }
                        IEnumerable <Pawn> breakingPawnsMinor = BreakRiskAlertUtility.PawnsAtRiskMinor;
                        foreach (Pawn current in breakingPawnsMinor)
                        {
                            if (current == pawn2)
                            {
                                bool flag = true;
                                List <Thought_Memory> pawn2Memories = pawn.needs.mood.thoughts.memories.Memories;
                                for (int i = 0; i < pawn2Memories.Count; i++)
                                {
                                    if (pawn2Memories[i].def.defName == "TM_EntertainedTD")
                                    {
                                        flag = false;
                                    }
                                }
                                if (flag)
                                {
                                    return(true);
                                }
                                return(false);
                            }
                        }
                    }
                }
            }
            return(false);
        }
        // Token: 0x060004D1 RID: 1233 RVA: 0x0003100C File Offset: 0x0002F40C
        protected override Job TryGiveJob(Pawn pawn)
        {
            float   Searchradius = HuntingRange;
            Map     map          = pawn.Map;
            IntVec3 c            = IntVec3.Invalid;
            Pawn    Victim       = null;

            if (!pawn.isXenomorph(out Comp_Xenomorph xenomorph) || map == null)
            {
                return(null);
            }
            MapComponent_HiveGrid hiveGrid = pawn.Map.HiveGrid();

            /*
             * if (GenAI.InDangerousCombat(pawn))
             * {
             *  Log.Warning(string.Format("{0} is InDangerousCombat", pawn.NameShortColored));
             * }
             */
            if (XenomorphKidnapUtility.TryFindGoodKidnapVictim(pawn, Searchradius, out Victim, null, forceRoofed, allowCocooned, minRadius, allowHosts) && !GenAI.InDangerousCombat(pawn))
            {
                if (xenomorph.HiveLoc.IsValid && xenomorph.HiveLoc.InBounds(map) && xenomorph.HiveLoc != IntVec3.Zero)
                {
                    c = xenomorph.HiveLoc;
                }

                /*
                 * else
                 * if (!hiveGrid.Hivelist.NullOrEmpty())
                 * {
                 *  c = hiveGrid.Hivelist.RandomElement().Position;
                 * }
                 * else
                 * if (!hiveGrid.HiveLoclist.NullOrEmpty())
                 * {
                 *  c = hiveGrid.HiveLoclist.RandomElement();
                 * }
                 * else
                 */
                bool selected = pawn.Map != null?Find.Selector.SelectedObjects.Contains(pawn) && (Prefs.DevMode) : false;

                if (c != IntVec3.Invalid && Victim != null && pawn.CanReach(c, PathEndMode.ClosestTouch, Danger.Deadly, true, TraverseMode.PassAllDestroyableThings))
                {
                    Predicate <IntVec3> validator = delegate(IntVec3 y)
                    {
                        bool roofed   = (y.Roofed(pawn.Map) && this.forceRoofed) || !this.forceRoofed;
                        bool adjacent = c.AdjacentTo8WayOrInside(y);
                        bool filled   = y.Filled(pawn.Map);
                        bool edifice  = y.GetEdifice(pawn.Map).DestroyedOrNull();
                        bool building = y.GetFirstBuilding(pawn.Map).DestroyedOrNull();
                        bool thingA   = y.GetThingList(pawn.Map).Any(x => x.GetType() == typeof(Building_XenoEgg) && x.GetType() == typeof(Building_XenomorphCocoon) && x.GetType() == typeof(HiveLike));
                        //    Log.Message(string.Format("{0}, adjacent: {1}, filled: {2}, edifice: {3}, building: {4}", y, !adjacent, !filled, edifice, building));
                        return(!adjacent && !filled && edifice && building && !thingA && roofed && pawn.CanReserveAndReach(y, PathEndMode.OnCell, Danger.Deadly, layer: ReservationLayerDefOf.Floor));
                    };
                    if (pawn.GetLord() != null && pawn.GetLord() is Lord lord)
                    {
                        //    Log.Message(string.Format("TryFindGoodHiveLoc pawn.GetLord() != null"));
                    }
                    else
                    {
                        //   Log.Message(string.Format("TryFindGoodHiveLoc pawn.GetLord() == null"));
                    }
                    if (pawn.mindState.duty.def != XenomorphDefOf.RRY_Xenomorph_DefendAndExpandHive && pawn.mindState.duty.def != XenomorphDefOf.RRY_Xenomorph_DefendHiveAggressively)
                    {
                        pawn.mindState.duty = new PawnDuty(XenomorphDefOf.RRY_Xenomorph_DefendAndExpandHive, c, 40f);
                    }
                    if (RCellFinder.TryFindRandomCellNearWith(c, validator, pawn.Map, out IntVec3 lc, 2, 8))
                    {
                        return(new Job(XenomorphDefOf.RRY_Job_Xenomorph_Kidnap)
                        {
                            targetA = Victim,
                            targetB = lc,
                            targetC = lc.RandomAdjacentCell8Way(),
                            count = 1
                        });
                    }
                }
                else
                {
                    Log.Error("No suitable hive location found");
                    //   if (Find.Selector.SelectedObjects.Contains(pawn)) Log.Message(string.Format("{0} something went wrong", this));
                }
            }
            else
            {
                //    Log.Error("No suitable Victim found");
            }
            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            Predicate <Thing> validator = delegate(Thing t)
            {
                Pawn pawn3 = (Pawn)t;
                return((pawn3.Downed && pawn3.Faction == pawn.Faction && !pawn3.InBed() && pawn.CanReserve(pawn3) && !pawn3.IsForbidden(pawn) && !GenAI.EnemyIsNear(pawn3, 25f)) ? true : false);
            };
            Pawn pawn2 = (Pawn)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.OnCell, TraverseParms.For(pawn), radius, validator);

            if (pawn2 == null)
            {
                return(null);
            }
            Building_Bed building_Bed = RestUtility.FindBedFor(pawn2, pawn, pawn2.HostFaction == pawn.Faction, checkSocialProperness: false);

            if (building_Bed == null || !pawn2.CanReserve(building_Bed))
            {
                return(null);
            }
            Job job = JobMaker.MakeJob(JobDefOf.Rescue, pawn2, building_Bed);

            job.count = 1;
            return(job);
        }
示例#17
0
        public virtual bool PawnCanOpen(Pawn p)
        {
            Lord lord = p.GetLord();

            return((lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(p)) || WildManUtility.WildManShouldReachOutsideNow(p) || base.Faction == null || (p.guest != null && p.guest.Released) || GenAI.MachinesLike(base.Faction, p));
        }
示例#18
0
        static void Postfix(WorkGiver_RescueDowned __instance, ref Pawn pawn, ref Thing t, ref bool forced, ref bool __result)
        {
            // mostly the original method, repeated, with three commented changes

            if (__result == true)
            {
                return;                   //new guard clause
            }
            Pawn pawn2 = t as Pawn;

            //if (pawn2 != null && pawn2.Downed && pawn2.Faction == pawn.Faction && !pawn2.InBed())
            if (pawn2 != null && pawn2.Downed && pawn.Map.designationManager.DesignationOn(pawn2, DesignationDefOf.Tame) != null && !pawn2.InBed())
            {
                LocalTargetInfo target = pawn2;
                bool            ignoreOtherReservations = forced;
                if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations) && !GenAI.EnemyIsNear(pawn2, 40f))
                {
                    //Thing thing = FindBed(pawn, pawn2);
                    Thing thing = RestUtility.FindBedFor(pawn2, pawn, pawn2.HostFaction == pawn.Faction, checkSocialProperness: false);
                    if (thing != null && pawn2.CanReserve(thing))
                    {
                        __result = true;
                        return;
                    }
                    __result = false;
                    return;
                }
            }
            __result = false;
            return;
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            IntVec3 vec;

            if (!RCellFinder.TryFindBestExitSpot(pawn, out vec))
            {
                return(null);
            }

            List <Thing> steelVehicle = new List <Thing>();

            foreach (Vehicle_Turret vehicle_Cart in ToolsForHaulUtility.CartTurret)
            {
                if (ToolsForHaulUtility.IsDriver(pawn))
                {
                    break;
                }
                if (pawn.RaceProps.Animal || !pawn.RaceProps.Humanlike || !pawn.RaceProps.hasGenders)
                {
                    break;
                }
                if (!vehicle_Cart.IsBurning() && vehicle_Cart.Position.InHorDistOf(pawn.Position, 12f) && !vehicle_Cart.mountableComp.IsMounted && (float)vehicle_Cart.HitPoints / vehicle_Cart.MaxHitPoints > 0.2f && vehicle_Cart.VehicleSpeed >= pawn.GetStatValue(StatDefOf.MoveSpeed) && pawn.CanReserveAndReach(vehicle_Cart, PathEndMode.InteractionCell, Danger.Deadly))
                {
                    steelVehicle.Add(vehicle_Cart);
                }
            }
            foreach (Vehicle_Cart vehicle_Cart in ToolsForHaulUtility.Cart)
            {
                if (ToolsForHaulUtility.IsDriver(pawn))
                {
                    break;
                }
                if (pawn.RaceProps.Animal || !pawn.RaceProps.Humanlike || !pawn.RaceProps.hasGenders)
                {
                    break;
                }
                if (!vehicle_Cart.IsBurning() && vehicle_Cart.Position.InHorDistOf(pawn.Position, 12f) && !vehicle_Cart.mountableComp.IsMounted && (float)vehicle_Cart.HitPoints / vehicle_Cart.MaxHitPoints > 0.2f && vehicle_Cart.VehicleSpeed >= pawn.GetStatValue(StatDefOf.MoveSpeed) && pawn.CanReserveAndReach(vehicle_Cart, PathEndMode.InteractionCell, Danger.Deadly))
                {
                    steelVehicle.Add(vehicle_Cart);
                }
            }
            if (steelVehicle.Any() && !GenAI.InDangerousCombat(pawn))
            {
                IOrderedEnumerable <Thing> orderedEnumerable = steelVehicle.OrderBy(x => x.Position.DistanceToSquared(pawn.Position));
                Job job = new Job(HaulJobDefOf.Mount);
                orderedEnumerable.First().SetFaction(null);
                job.targetA = orderedEnumerable.First();

                return(job);
            }

            Thing thing;

            if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, 12f, out thing, pawn) && !GenAI.InDangerousCombat(pawn))
            {
                return(new Job(JobDefOf.Steal)
                {
                    targetA = thing,
                    targetB = vec,
                    maxNumToCarry = Mathf.Min(thing.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / thing.def.VolumePerUnit))
                });
            }
            return(null);
        }
示例#20
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            var ingList      = job.GetTargetQueue(IngredientInd);
            var ingCountList = job.countQueue;

            // this.job.SetTarget(IngredientPlaceCellInd, this.TargetA.Thing.InteractionCell);
            var startToil = Toils_General.Do(
                () =>
            {
                job.SetTarget(IngredientInd, ingList[0].Thing);
                job.count = ingCountList[0];
                ingList.RemoveAt(0);
                ingCountList.RemoveAt(0);
            });

            // 材料キューの先頭を取り出してセット
            yield return(startToil);

            // 材料の置き場所へ移動
            var gotoToil = Toils_Goto.GotoThing(IngredientInd, PathEndMode.Touch);

            yield return(gotoToil);

            // 材料を運ぶ
            yield return(Toils_Haul.StartCarryThing(IngredientInd));

            // 運ぶものリストの中に同種の材料があり、まだ物を持てる場合、設備へ持っていく前に取りに行く
            yield return(Toils_General.Do(
                             () =>
            {
                var actor = pawn;
                var curJob = actor.jobs.curJob;
                var targetQueue = curJob.GetTargetQueue(IngredientInd);
                if (targetQueue.NullOrEmpty())
                {
                    return;
                }

                if (curJob.count <= 0)
                {
                    return;
                }

                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error(
                        "JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.");
                    return;
                }

                if (actor.carryTracker.AvailableStackSpace(actor.carryTracker.CarriedThing.def) <= 0)
                {
                    return;
                }

                for (var i = 0; i < targetQueue.Count; i++)
                {
                    if (!GenAI.CanUseItemForWork(actor, targetQueue[i].Thing))
                    {
                        actor.jobs.EndCurrentJob(JobCondition.Incompletable);
                        return;
                    }

                    if (targetQueue[i].Thing.def != actor.carryTracker.CarriedThing.def)
                    {
                        continue;
                    }

                    curJob.SetTarget(IngredientInd, targetQueue[i].Thing);
                    curJob.count = curJob.countQueue[i];
                    targetQueue.RemoveAt(i);
                    curJob.countQueue.RemoveAt(i);
                    actor.jobs.curDriver.JumpToToil(gotoToil);
                    break;
                }
            }));

            // 運ぶ
            yield return(Toils_Haul.CarryHauledThingToCell(IngredientPlaceCellInd));

            // 運んだものリスト(使用素材)に追加
            yield return(Toils_Mizu.AddPlacedThing());

            // 運んだものを置く
            yield return(Toils_Haul.PlaceCarriedThingInCellFacing(BillGiverInd));

            // まだ材料があるならさらに運ぶ
            yield return(Toils_General.Do(
                             () =>
            {
                if (job.GetTargetQueue(IngredientInd).Count > 0)
                {
                    pawn.jobs.curDriver.JumpToToil(startToil);
                }
            }));

            // レシピ実行
            yield return(Toils_Recipe.DoRecipeWork());

            // 水の注入完了処理
            yield return(Toils_Mizu.FinishPourRecipe(BillGiverInd));
        }
            internal bool <> m__0(Thing t)
            {
                Pawn pawn = (Pawn)t;

                return(pawn.Downed && pawn.Faction == this.pawn.Faction && !pawn.InBed() && this.pawn.CanReserve(pawn, 1, -1, null, false) && !pawn.IsForbidden(this.pawn) && !GenAI.EnemyIsNear(pawn, 25f));
            }
示例#22
0
        public virtual bool PawnCanOpen(Pawn p)
        {
            Lord lord = p.GetLord();

            return((lord != null && lord.LordJob != null && lord.LordJob.CanOpenAnyDoor(p)) || (p.IsWildMan() && !p.mindState.wildManEverReachedOutside) || base.Faction == null || (p.guest != null && p.guest.Released) || GenAI.MachinesLike(base.Faction, p));
        }
        public override void UpdateAllDuties()
        {
            List <Thing> list = null;

            for (int i = 0; i < lord.ownedPawns.Count; i++)
            {
                Pawn  pawn   = lord.ownedPawns[i];
                Thing target = null;
                if (!cover || (TryFindGoodOpportunisticTaskTarget(pawn, out target, list) && !GenAI.InDangerousCombat(pawn)))
                {
                    if (pawn.mindState.duty == null || pawn.mindState.duty.def != DutyDef)
                    {
                        pawn.mindState.duty = new PawnDuty(DutyDef);
                        pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    }
                    if (list == null)
                    {
                        list = new List <Thing>();
                    }
                    list.Add(target);
                }
                else
                {
                    pawn.mindState.duty = new PawnDuty(DutyDefOf.AssaultColony);
                }
            }
        }
        // Token: 0x060004D1 RID: 1233 RVA: 0x0003100C File Offset: 0x0002F40C
        protected override Job TryGiveJob(Pawn pawn)
        {
            float   Searchradius = HuntingRange;
            IntVec3 c            = IntVec3.Invalid;

            if (XenomorphKidnapUtility.TryFindGoodKidnapVictim(pawn, Searchradius, out Pawn t, null) && !GenAI.InDangerousCombat(pawn))
            {
                if (XenomorphKidnapUtility.TryFindGoodHiveLoc(pawn, t, out c))
                {
                    ThingDef namedA   = XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon;
                    ThingDef namedB   = XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon;
                    bool     selected = pawn.Map != null?Find.Selector.SelectedObjects.Contains(pawn) && (Prefs.DevMode) : false;

                    if (c != IntVec3.Invalid && t != null && pawn.CanReach(c, PathEndMode.ClosestTouch, Danger.Deadly, true, TraverseMode.PassAllDestroyableThings))
                    {
                        Predicate <IntVec3> validator = delegate(IntVec3 y)
                        {
                            bool adjacent = c.AdjacentTo8WayOrInside(y);
                            bool filled   = y.Filled(pawn.Map);
                            bool edifice  = y.GetEdifice(pawn.Map).DestroyedOrNull();
                            bool building = y.GetFirstBuilding(pawn.Map).DestroyedOrNull();
                            bool thingA   = y.GetFirstThing(pawn.Map, namedA).DestroyedOrNull();
                            bool thingB   = y.GetFirstThing(pawn.Map, namedB).DestroyedOrNull();
                            //Log.Message(string.Format("{0} {1} {2} {3} {4} {5}", y, !adjacent, !filled, edifice, building, thing));
                            return(!adjacent && !filled && edifice && building && thingA && thingB);
                        };

                        bool b = RCellFinder.TryFindRandomCellNearWith(c, validator, pawn.Map, out IntVec3 lc, 6, 12);

                        return(new Job(XenomorphDefOf.RRY_Job_XenomorphKidnap)
                        {
                            targetA = t,
                            targetB = lc,
                            count = 1
                        });
                    }
                    else
                    {
                        if (Find.Selector.SelectedObjects.Contains(pawn))
                        {
                            Log.Message(string.Format("{0} something went wrong", this));
                        }
                    }
                }
                else
                {
                    if (Find.Selector.SelectedObjects.Contains(pawn))
                    {
                        Log.Message(string.Format("{0} No Cocooning spot Found", this));
                    }
                }
            }
 public override bool ActivateOn(Lord lord, TriggerSignal signal)
 {
     if (signal.type == TriggerSignalType.Tick && Find.TickManager.TicksGame % 120 == 0 && Find.TickManager.TicksGame - lord.lastPawnHarmTick > 300)
     {
         TriggerData_PawnCycleInd data = this.Data;
         data.pawnCycleInd++;
         if (data.pawnCycleInd >= lord.ownedPawns.Count)
         {
             data.pawnCycleInd = 0;
         }
         if (lord.ownedPawns.Any <Pawn>())
         {
             Pawn pawn = lord.ownedPawns[data.pawnCycleInd];
             Pawn pawn2;
             if (pawn.Spawned && !pawn.Downed && pawn.MentalStateDef == null && KidnapAIUtility.TryFindGoodKidnapVictim(pawn, 8f, out pawn2, null) && !GenAI.InDangerousCombat(pawn))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        protected override Job TryGiveJob(Pawn pawn)
        {
            IntVec3 c;
            Job     result;
            Pawn    t;

            if (!RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
            {
                result = null;
            }
            else if (KidnapAIUtility.TryFindGoodKidnapVictim(pawn, 18f, out t, null) && !GenAI.InDangerousCombat(pawn))
            {
                result = new Job(JobDefOf.Kidnap)
                {
                    targetA = t,
                    targetB = c,
                    count   = 1
                };
            }
            else
            {
                result = null;
            }
            return(result);
        }
示例#27
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;
            CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>();

            if (pawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_CommanderAuraHD, false))
            {
                HediffComp_CommanderAura hdComp = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_CommanderAuraHD).TryGetComp <HediffComp_CommanderAura>();
                if (hdComp != null && hdComp.nextSpeechTick < Find.TickManager.TicksGame)
                {
                    if (pawn2 != null && pawn2 != pawn && pawn2.RaceProps.Humanlike && pawn2.IsColonist && pawn2.Awake() && !pawn2.Drafted && !pawn.Drafted && !pawn2.Downed)
                    {
                        if (pawn2.InMentalState && (pawn.Position - pawn2.Position).LengthHorizontal < 50f && !GenAI.EnemyIsNear(pawn2, 20f))
                        {
                            hdComp.nextSpeechTick = Find.TickManager.TicksGame + 100;
                            LocalTargetInfo target = pawn2;
                            if (pawn.CanReserveAndReach(target, PathEndMode.Touch, Danger.Deadly, 1, -1, null, true))
                            {
                                hdComp.nextSpeechTick = Find.TickManager.TicksGame + (Rand.Range(12000, 15000) - (1200 * hdComp.pwrVal));
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
示例#28
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;

            if (pawn2 != null && pawn2.Downed && pawn2.Faction == pawn.Faction && !pawn2.InBed())
            {
                LocalTargetInfo target = pawn2;
                bool            ignoreOtherReservations = forced;
                if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations) && !GenAI.EnemyIsNear(pawn2, 40f))
                {
                    Thing thing = FindBed(pawn, pawn2);
                    if (thing != null && pawn2.CanReserve(thing))
                    {
                        return(true);
                    }
                    return(false);
                }
            }
            return(false);
        }
示例#29
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            IntVec3 c = default(IntVec3);

            if (!RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
            {
                return(null);
            }
            Thing thing = default(Thing);

            if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 12f, out thing, pawn, (List <Thing>)null) && !GenAI.InDangerousCombat(pawn))
            {
                Job job = new Job(JobDefOf.Steal);
                job.targetA = thing;
                job.targetB = c;
                job.count   = Mathf.Min(thing.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity, true) / thing.def.VolumePerUnit));
                return(job);
            }
            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            IntVec3 c;
            Job     result;
            Thing   thing;

            if (!RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
            {
                result = null;
            }
            else if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 12f, out thing, pawn, null) && !GenAI.InDangerousCombat(pawn))
            {
                result = new Job(JobDefOf.Steal)
                {
                    targetA = thing,
                    targetB = c,
                    count   = Mathf.Min(thing.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity, true) / thing.def.VolumePerUnit))
                };
            }
            else
            {
                result = null;
            }
            return(result);
        }