protected override ThoughtState CurrentStateInternal(Pawn p)
        {
            if (p.def == ThingDefOf.Avali)
            {
                return(ThoughtState.Inactive);
            }
            List <Hediff> hediffs = p.health.hediffSet.hediffs;

            for (int i = 0; i < hediffs.Count; i++)
            {
                Hediff hediff = hediffs[i];
                if (hediff != null && hediff.Part != null && hediff.Part.Label == "nose")
                {
                    if (hediff.def == RimWorld.HediffDefOf.MissingBodyPart)
                    {
                        return(ThoughtState.Inactive);
                    }
                }
            }

            List <Thing> avaliPawns = new List <Thing>();
            Room         room       = p.GetRoom(RegionType.Set_Passable);

            if (room.PsychologicallyOutdoors)
            {
                return(ThoughtState.Inactive);
            }
            List <Pawn> freeColonistsAndPrisoners = p.GetRoom(RegionType.Set_Passable).Map.mapPawns.FreeColonistsAndPrisoners.ToList();

            for (int i = 0; i < freeColonistsAndPrisoners.Count; i++)
            {
                Thing freeColonistOrPrisoner = freeColonistsAndPrisoners[i] as Thing;
                if (freeColonistOrPrisoner != null)
                {
                    avaliPawns.Add(freeColonistOrPrisoner);
                }
            }

            if (avaliPawns.Count == 0)
            {
                return(ThoughtState.Inactive);
            }

            int avaliPawnsInRange = AvaliUtility.FindAllThingsOnMapAtRange(p, ThingDefOf.Avali, null, avaliPawns, rangeInCells, maxAvaliPawns, false, false).Count;

            if (avaliPawnsInRange > 0)
            {
                avaliPawnsInRange--;
                if (avaliPawnsInRange > 5)
                {
                    avaliPawnsInRange = 5;
                }
                return(ThoughtState.ActiveAtStage(avaliPawnsInRange));
            }

            return(ThoughtState.Inactive);
        }
예제 #2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //this.FailOnDespawnedOrNull(BedInd);
            this.FailOnDespawnedOrNull(PartnerInd);
            this.FailOn(() => !partner.health.capacities.CanBeAwake);

            Building partnerCellBuilding = partner.Position.GetFirstBuilding(Map);

            if (partnerCellBuilding == null || partnerCellBuilding.GetStatValue(StatDefOf.Comfort) < 0.5f)
            {
                Room room = pawn.GetRoom(RegionType.Set_Passable);
                if (room == null)
                {
                    yield break;
                }
                AvaliUtility.FindAllThingsOnMapAtRange(pawn, null, typeof(Pawn), room.ContainedAndAdjacentThings, 20, 9999, true, true);

                /*
                 * Predicate<Thing> validator = delegate(Thing t)
                 * {
                 *      Thing building2 = t as Building;
                 *
                 *      return (building2.def.thingClass == typeof(Building_Bed) || building2.def.building.isSittable) && pawn.CanReserve(building2, 1, -1, null, false);
                 * };
                 */
                //Thing thing = (Thing)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(thingDef), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), maxSearchDistance, validator, null, 0, -1, false, RegionType.Set_Passable, false);



                //List<Thing> buildingsInRoom = AvaliUtility.FindAllThingsOnMapAtRange(pawn, null, typeof(Building), room.ContainedAndAdjacentThings, 20, 9999, true, true);



                /*if (room.PsychologicallyOutdoors)
                 * {
                 *
                 * }*/
            }

            yield break;
        }
예제 #3
0
        public void TryStartUseJob(Pawn selPawn)
        {
            if (debug)
            {
                Log.Message("TryStartUseJob");
            }

            Job job = null;

            if (Props.workTable == null)
            {
                job = new Job(Props.useJob, parent, null, null);

                Thing sittableThing = AvaliUtility.FindAllThingsOnMapAtRange(selPawn, null, typeof(Building), null, 15, 1, true, true).First();
                if (sittableThing != null)
                {
                    job = new Job(Props.useJob, parent, sittableThing, null);
                }

                if (debug)
                {
                    Log.Message(selPawn + " job = " + Props.useJob + ", " + parent + ", " + sittableThing);
                }
            }
            else
            {
                Thing workTable = null;

                if (Props.workTable == ThingDef.Named("SimpleResearchBench"))
                {
                    workTable = AvaliUtility.FindClosestUnoccupiedThing(selPawn, ThingDef.Named("HiTechResearchBench"), 9999, true);
                    if (debug)
                    {
                        Log.Message("Closest unoccupied hi-tech research bench = " + workTable);
                    }
                }

                if (workTable == null)
                {
                    workTable = AvaliUtility.FindClosestUnoccupiedThing(selPawn, Props.workTable, 9999, false);
                    if (debug)
                    {
                        Log.Message("Closest unoccupied work table = " + workTable);
                    }
                }

                if (workTable == null)
                {
                    //if (Props.workTable.defName == "HiTechResearchBench") new AcceptanceReport("NoHiTechResearchBench".Translate());
                    //else if (Props.workTable.defName == "SimpleResearchBench") new AcceptanceReport("NoResearchBench".Translate());
                    //else new AcceptanceReport("NoAppropriateWorkBench".Translate());

                    if (debug)
                    {
                        Log.Message("workTable = null");
                    }
                    return;
                }

                if (!workTable.def.hasInteractionCell)
                {
                    Log.Error(workTable + " not have interaction cell.");
                    return;
                }

                job = new Job(Props.useJob, parent, workTable, workTable.OccupiedRect().ClosestCellTo(workTable.InteractionCell));
            }

            job.count = 1;
            selPawn.jobs.TryTakeOrderedJob(job, JobTag.MiscWork);
        }
예제 #4
0
        public override IEnumerable <FloatMenuOption> CompFloatMenuOptions(Pawn selPawn)
        {
            if (selPawn.CanReserveAndReach(parent, PathEndMode.ClosestTouch, Danger.Deadly, 1, -1, null, false))
            {
                if (parent.GetType() != typeof(Apparel))
                {
                    yield break;
                }

                if (!selPawn.IsColonist || !selPawn.Awake())
                {
                    yield break;
                }

                List <Thing> avalablePawns = AvaliUtility.FindAllThingsOnMapAtRange(parent, null, typeof(Pawn), null, float.MaxValue, int.MaxValue, true, true);
                if (avalablePawns.Count == 0)
                {
                    yield break;
                }

                const string putOnLabel = "PutOnLabel";

                for (int i = 0; i < avalablePawns.Count; i++)
                {
                    var p = avalablePawns[i] as Pawn;
                    //Log.Message("p = " + p + "; i = " + i);

                    if (p != null && p != selPawn)
                    {
                        if (!p.IsColonist && !p.IsPrisonerOfColony)
                        {
                            if (!p.Downed)
                            {
                                continue;
                            }
                            if (p.RaceProps.IsMechanoid || !p.RaceProps.ToolUser)
                            {
                                continue;
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }

                    var alienDef = p.def as ThingDef_AlienRace;
                    if (alienDef != null)
                    {
                        List <string> apparelList = alienDef.alienRace.raceRestriction.apparelList;
                        if (apparelList.Count > 0)
                        {
                            apparelList.AddRange(alienDef.alienRace.raceRestriction.whiteApparelList);
                            bool isCompatibleApparel = false;

                            for (int j = 0; j < apparelList.Count; j++)
                            {
                                string apparel = apparelList[j];

                                if (parent.def.defName == apparel)
                                {
                                    isCompatibleApparel = true;
                                    break;
                                }
                            }

                            if (!isCompatibleApparel)
                            {
                                continue;
                            }
                        }
                    }

                    yield return(new FloatMenuOption(putOnLabel.Translate(p.Label), delegate
                    {
                        Job job = new Job(JobDefOf.PutOn, parent, p, selPawn.Position);
                        job.count = 1;
                        selPawn.jobs.TryTakeOrderedJob(job, JobTag.MiscWork);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
            }

            yield break;
        }