예제 #1
0
        public static Thing FindTarget(Pawn pawn)
        {
            List <Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned;

            if (allPawns == null || !allPawns.Any())
            {
                return(null);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(null);
            }
            List <Thing> targets = new List <Thing>();

            foreach (Pawn target in allPawns)
            {
                if (!target.DestroyedOrNull() && !target.Downed)
                {
                    if (target.Faction == null || (target.Faction != null && target.Faction != pawn.Faction))
                    {
                        bool recentAttack          = target.mindState != null && target.mindState.lastAttackedTarget == pawn && target.mindState.lastAttackTargetTick <= Find.TickManager.TicksGame && target.mindState.lastAttackTargetTick > Find.TickManager.TicksGame - ticksInAttackMode;
                        bool withinHiveAndInVisual = JobGiver_InsectGather.WithinHive(pawn, target as Thing, false) && GenSight.LineOfSight(pawn.Position, target.Position, pawn.Map, true, null, 0, 0);
                        if (recentAttack || withinHiveAndInVisual)
                        {
                            if (!BetterInfestationsMod.settings.disabledDefList.Contains(target.def.defName))
                            {
                                targets.Add(target as Thing);
                            }
                        }
                    }
                }
            }
            return(JobGiver_InsectGather.GetClosest(pawn, targets));
        }
예제 #2
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "BI_Maintain"))
            {
                return(null);
            }
            Queen queen = HiveUtility.FindQueen(pawn);

            if (queen != null && JobGiver_InsectGather.WithinHive(pawn, pawn, true))
            {
                List <Egg> eggs = queen.spawnedEggs;
                if (eggs != null && eggs.Any())
                {
                    foreach (Egg egg in eggs)
                    {
                        if (egg != null && pawn.CanReserve(egg))
                        {
                            CompMaintainable compMaintainable = egg.TryGetComp <CompMaintainable>();
                            if (compMaintainable != null && compMaintainable.CurStage != MaintainableStage.Healthy)
                            {
                                return(new Job(DefDatabase <JobDef> .GetNamed("BI_Maintain"), egg));
                            }
                        }
                    }
                }
            }
            return(null);
        }
예제 #3
0
 public static Thing FindTarget(Pawn pawn)
 {
     List<Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned;
     if (allPawns == null || !allPawns.Any())
     {
         return null;
     }
     if (BetterInfestationsMod.settings == null)
     {
         return null;
     }
     List<Thing> targetList = new List<Thing>();
     foreach (Pawn target in allPawns)
     {
         if (target.DestroyedOrNull())
         {
             continue;
         }
         if (target.Faction != null && target.Faction == pawn.Faction)
         {
             continue;
         }
         if (target.Downed && JobGiver_InsectGather.WithinHive(pawn, target, true))
         {
             continue;
         }
         if (!BetterInfestationsMod.settings.disabledDefList.Contains(target.def.defName))
         {
             targetList.Add(target as Thing);
         }
     }           
     return JobGiver_InsectGather.GetClosest(pawn, targetList);
 }
예제 #4
0
        public static Thing GetAttacker(Pawn pawn, Thing target, bool attackingHive)
        {
            Pawn            pawnTarget   = target as Pawn;
            Insect          enemyBug     = target as Insect;
            Building_Turret turretTarget = target as Building_Turret;
            bool            recentAttack = false;

            if (pawnTarget != null)
            {
                recentAttack = pawnTarget.mindState.lastAttackTargetTick <= Find.TickManager.TicksGame && pawnTarget.mindState.lastAttackTargetTick > Find.TickManager.TicksGame - ticksInAttackMode;
            }
            else if (turretTarget != null)
            {
                recentAttack = turretTarget.LastAttackTargetTick <= Find.TickManager.TicksGame && turretTarget.LastAttackTargetTick > Find.TickManager.TicksGame - ticksInAttackMode;
            }
            int  dist = IntVec3Utility.ManhattanDistanceFlat(pawn.PositionHeld, target.PositionHeld);
            bool withinHiveAndInVisual = JobGiver_InsectGather.WithinHive(pawn, target, false) && GenSight.LineOfSight(pawn.Position, target.Position, pawn.Map, true, null, 0, 0);
            bool enemyPawnThreat       = (withinHiveAndInVisual || (attackingHive && recentAttack)) && dist < maxAttackDistance;
            bool enemyInsectThreat     = enemyBug != null && enemyBug.Faction != pawn.Faction && GenSight.LineOfSight(pawn.Position, enemyBug.Position, pawn.Map, true, null, 0, 0) && dist < 30;

            if (enemyPawnThreat || enemyInsectThreat)
            {
                if (pawn.CanReach(target, PathEndMode.Touch, Danger.Deadly, true, TraverseMode.PassDoors))
                {
                    return(target);
                }
            }
            return(null);
        }
예제 #5
0
        public static Thing FindTarget(Pawn pawn)
        {
            List <Thing> allThings = pawn.Map.listerThings.ThingsOfDef(ThingDefOf.InsectJelly);

            if (allThings == null || !allThings.Any())
            {
                return(null);
            }
            List <Thing> targetList = new List <Thing>();

            foreach (Thing thing in allThings)
            {
                if (JobGiver_InsectGather.WithinHive(pawn, thing, false))
                {
                    targetList.Add(thing);
                }
            }
            return(JobGiver_InsectGather.GetClosest(pawn, targetList));
        }
예제 #6
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "BI_InsectButcher"))
            {
                return(null);
            }
            if (!ButcherCheck(pawn))
            {
                return(null);
            }
            Thing thing = JobGiver_InsectGather.FindTarget(pawn, true);

            if (thing == null || !JobGiver_InsectGather.WithinHive(pawn, pawn, false))
            {
                return(null);
            }
            Job job = new Job(DefDatabase <JobDef> .GetNamed("BI_InsectButcher"), thing)
            {
                ignoreForbidden = true,
                count           = 1
            };

            return(job);
        }
예제 #7
0
        public static Thing FindTarget(Pawn pawn)
        {
            List <Thing> allThings = pawn.Map.listerThings.AllThings;

            if (allThings == null || !allThings.Any())
            {
                return(null);
            }
            List <Thing> targetList = new List <Thing>();

            foreach (Thing thing in allThings)
            {
                if (thing != null)
                {
                    Corpse corpse = thing as Corpse;
                    Pawn   p      = thing as Pawn;
                    Queen  q      = thing as Queen;

                    if (thing.def.category == ThingCategory.Item && !thing.def.IsCorpse && (thing.IngestibleNow || thing.def.defName == "WoodLog") && !JobGiver_InsectGather.WithinHive(pawn, thing, true))
                    {
                        targetList.Add(thing);
                    }
                    else if (corpse != null && corpse.InnerPawn != null && corpse.InnerPawn.RaceProps.IsFlesh && corpse.GetRotStage() != RotStage.Dessicated && !JobGiver_InsectGather.WithinHive(pawn, thing, true))
                    {
                        targetList.Add(thing);
                    }
                    else if (p != null && p.RaceProps.IsFlesh && (p.Faction == null || (p.Faction != null && p.Faction != pawn.Faction)) && !JobGiver_InsectGather.WithinHive(pawn, thing, true))
                    {
                        targetList.Add(thing);
                    }
                    else if (q != null && HiveUtility.FindQueen(pawn) == q)
                    {
                        targetList.Add(thing);
                    }
                }
            }
            return(GetClosest(pawn, targetList));
        }