// Token: 0x0600048F RID: 1167 RVA: 0x0002F174 File Offset: 0x0002D574
        protected override Job TryGiveJob(Pawn pawn)
        {
            Map map = pawn.Map;

            if (!pawn.HostileTo(Faction.OfPlayer))
            {
                return(null);
            }
            bool            flag          = pawn.HostileTo(Faction.OfPlayer);
            CellRect        cellRect      = CellRect.CenteredOn(pawn.Position, 5);
            List <Building> list          = map.listerBuildings.allBuildingsColonist.FindAll(x => x.TryGetComp <CompPowerBattery>() != null);
            List <Building> listPlants    = list.FindAll(x => x.TryGetComp <CompPowerPlant>() != null);
            List <Building> listBatteries = list.FindAll(x => x.TryGetComp <CompPowerBattery>() != null);
            List <Building> listConduit   = list.FindAll(x => x.TryGetComp <CompPowerTransmitter>() != null);

            for (int i = 0; i < 35; i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                if (randomCell.InBounds(pawn.Map))
                {
                    Building edifice = randomCell.GetEdifice(pawn.Map);
                    if (flag)
                    {
                        if (edifice != null && TrashUtility.ShouldTrashBuilding(pawn, edifice, false) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map, false, null, 0, 0) && (edifice.TryGetComp <CompPowerPlant>() != null || edifice.TryGetComp <CompPowerBattery>() != null || edifice.TryGetComp <CompPowerTransmitter>() != null))
                        {
                            if (DebugViewSettings.drawDestSearch && Find.CurrentMap == pawn.Map)
                            {
                                Find.CurrentMap.debugDrawer.FlashCell(randomCell, 1f, "trash bld", 50);
                            }
                            Job job;

                            Building building = edifice as Building;
                            bool     flagb    = building != null && building.def.building.isInert;
                            if (flagb)
                            {
                                return(null);
                            }
                            //   job = TrashUtility.TrashJob(pawn, building, true);
                            job = new Job(RimWorld.JobDefOf.AttackMelee, edifice);
                            if (job != null)
                            {
                                return(job);
                            }
                        }
                    }
                    if (DebugViewSettings.drawDestSearch && Find.CurrentMap == pawn.Map)
                    {
                        Find.CurrentMap.debugDrawer.FlashCell(randomCell, 0f, "trash no", 50);
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            //Log.Message(pawn + " - " + pawn.mindState.duty);
            if (!pawn.HostileTo(Faction.OfPlayer))
            {
                //Log.Message("0 - " + pawn + " - null", true);
                return(null);
            }

            if (RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot))
            {
                //Log.Message(pawn + " found spot: " + spot, true);
                if (TryFindBestItemToSteal(pawn.Position, pawn.Map, 50f, out Thing item, pawn))                // && !GenAI.InDangerousCombat(pawn))
                {
                    Job job = JobMaker.MakeJob(JobDefOf.Steal);
                    job.targetA       = item;
                    job.targetB       = spot;
                    job.canBashDoors  = true;
                    job.canBashFences = true;
                    job.count         = Mathf.Min(item.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / item.def.VolumePerUnit));
                    //Log.Message("3 - " + pawn + " - " + job, true);
                    return(job);
                }
                //Log.Message(pawn + " cant find item to steal", true);
            }
            bool     flag     = pawn.natives.IgniteVerb != null && pawn.natives.IgniteVerb.IsStillUsableBy(pawn) && pawn.HostileTo(Faction.OfPlayer);
            CellRect cellRect = CellRect.CenteredOn(pawn.Position, 5);

            for (int i = 0; i < 35; i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                if (!randomCell.InBounds(pawn.Map))
                {
                    continue;
                }
                Building edifice = randomCell.GetEdifice(pawn.Map);
                if (edifice != null && TrashUtility.ShouldTrashBuilding(pawn, edifice) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map))
                {
                    Job job = TrashJob(pawn, edifice);
                    if (job != null)
                    {
                        //Log.Message("1 - " + pawn + " - " + job, true);
                        return(job);
                    }
                }
                if (flag)
                {
                    Plant plant = randomCell.GetPlant(pawn.Map);
                    if (plant != null && TrashUtility.ShouldTrashPlant(pawn, plant) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map))
                    {
                        Job job2 = TrashJob(pawn, plant);
                        if (job2 != null)
                        {
                            //Log.Message("2 - " + pawn + " - " + job2, true);

                            return(job2);
                        }
                    }
                }
            }

            List <Building> allBuildingsColonist = pawn.Map.listerBuildings.allBuildingsColonist;

            if (allBuildingsColonist.Count == 0)
            {
                //Log.Message("4 - " + pawn + " - null", true);
                return(null);
            }
            foreach (var building in allBuildingsColonist.OrderBy(x => IntVec3Utility.DistanceTo(x.Position, pawn.Position)).Take(10).InRandomOrder())
            {
                if (TrashUtility.ShouldTrashBuilding(pawn, building, true) && pawn.CanReach(building, PathEndMode.Touch, Danger.None))
                {
                    Job job = TrashJob(pawn, building, true);
                    if (job != null)
                    {
                        //Log.Message("5 - " + pawn + " - " + job, true);
                        return(job);
                    }
                }
            }
            if (RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot2))
            {
                //Log.Message(pawn + " found spot: " + spot2, true);
                if (TryFindBestItemToSteal(pawn.Position, pawn.Map, 100f, out Thing item, pawn, danger: Danger.None))                // && !GenAI.InDangerousCombat(pawn))
                {
                    Job job = JobMaker.MakeJob(JobDefOf.Steal);
                    job.targetA       = item;
                    job.targetB       = spot2;
                    job.canBashDoors  = true;
                    job.canBashFences = true;
                    job.count         = Mathf.Min(item.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / item.def.VolumePerUnit));
                    //Log.Message("6 - " + pawn + " - " + job, true);
                    return(job);
                }
                //Log.Message(pawn + " cant find item to steal", true);
            }
            //Log.Message("7 - " + pawn + " - null", true);
            return(null);
        }