public override Job TryGiveJobWhileInBed(Pawn pawn)
        {
#if DEBUG
            Verse.Log.Message("TryGiveJobWhileInBed " + pawn.Label);
#endif

            Room room             = pawn.GetRoom();
            PerformanceManager pm = pawn.Map.GetComponent <PerformanceManager>();

            // get music spots in pawn's current room
            List <CompMusicSpot> localMusicSpots = pm.ListActiveMusicSpots().Where(x => room.Cells.Contains(x.parent.Position)).ToList();

            // if no music spots then give up
            if (localMusicSpots.Count == 0)
            {
                return(null);
            }

#if DEBUG
            Verse.Log.Message(String.Format("{0} local spots", localMusicSpots.Count));
#endif

            workingSpots = localMusicSpots;

            // pick a random one
            CompMusicSpot CompMusicSpot;
            while (workingSpots.TryRandomElement(out CompMusicSpot))
            {
                workingSpots.Remove(CompMusicSpot);

                // is a performance currently in progress
                if (pawn.Map.GetComponent <PerformanceManager>().HasPerformance(CompMusicSpot.parent))
                {
#if DEBUG
                    Verse.Log.Message("Found performance");
#endif

                    Job job = new Job(def.jobDef, CompMusicSpot.parent, pawn.CurrentBed());
                    return(job);
                }
            }

            return(null);
        }
Beispiel #2
0
        public override IEnumerable <Thing> PotentialWorkThingsGlobal(Pawn pawn)
        {
            PerformanceManager pm = pawn.Map.GetComponent <PerformanceManager>();

            if (!pm.CanPlayForWorkNow(pawn))
            {
                return(null);
            }

            IEnumerable <Thing> things = pm.ListActiveMusicSpots().Select(x => (Thing)x.parent);

            //we also need to check for availibilty of an instrument here
            if (PerformanceManager.HeldInstrument(pawn) == null)
            {
                things = things.Where(x => pm.AnyAvailableMapInstruments(pawn, x));
            }

            //Verse.Log.Message(String.Format("PotentialWorkThingsGlobal for {0}: {1} things", pawn.Label, things.Count()));

            return(things);
        }
        private Job TryGiveJobInt(Pawn pawn, Predicate <CompMusicSpot> musicSpotValidator)
        {
#if DEBUG
            Verse.Log.Message(String.Format("{0} trying to listen to music", pawn.LabelShort));
#endif

            PerformanceManager pm = pawn.Map.GetComponent <PerformanceManager>();

            // if no music spots then give up
            if (pm.ListActiveMusicSpots().Count == 0)
            {
                return(null);
            }
            // load all music spots on map into list
            workingSpots.Clear();
            for (int i = 0; i < pm.ListActiveMusicSpots().Count; i++)
            {
                workingSpots.Add(pm.ListActiveMusicSpots()[i]);
            }

            // pick a random one
            CompMusicSpot CompMusicSpot;
            while (workingSpots.TryRandomElement(out CompMusicSpot))
            {
                // remove from list
                workingSpots.Remove(CompMusicSpot);
                // check zones etc
                if (!CompMusicSpot.parent.IsForbidden(pawn))
                {
                    // see if there's a safe path to get there
                    if (pawn.CanReach(CompMusicSpot.parent, PathEndMode.Touch, Danger.None, false, TraverseMode.ByPawn))
                    {
                        // prisoners seperated from colonists
                        if (CompMusicSpot.parent.IsSociallyProper(pawn))
                        {
                            // only friendly factions
                            if (CompMusicSpot.parent.IsPoliticallyProper(pawn))
                            {
                                // check passed in predicate - i.e. parties
                                if (musicSpotValidator == null || musicSpotValidator(CompMusicSpot))
                                {
                                    // is a performance currently in progress
                                    if (pawn.Map.GetComponent <PerformanceManager>().HasPerformance(CompMusicSpot.parent))
                                    {
#if DEBUG
                                        Verse.Log.Message("Found performance to listen to");
#endif
                                        // find a place to sit or stand, or return null if there aren't any


                                        Job job;

                                        IntVec3 standingSpot;
                                        if (pm.TryFindChairNear(CompMusicSpot, pawn, out Thing chair))
                                        {
#if DEBUG
                                            Verse.Log.Message("Found chair");
#endif
                                            job = new Job(this.def.jobDef, CompMusicSpot.parent, chair);
                                            return(job);
                                        }
                                        else if (pm.TryFindSitSpotOnGroundNear(CompMusicSpot, pawn, out standingSpot))
                                        {
#if DEBUG
                                            Verse.Log.Message("Found standing spot");
#endif
                                            job = new Job(this.def.jobDef, CompMusicSpot.parent, standingSpot);
                                            return(job);
                                        }
                                        else
                                        {
#if DEBUG
                                            Verse.Log.Message("Failed to find chair or standing spot");
#endif
                                            return(null);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

#if DEBUG
            Verse.Log.Message("Failed to find performance");
#endif
            return(null);
        }
        private Job TryGiveJobInt(Pawn pawn, Predicate <CompMusicSpot> musicSpotValidator)
        {
            //quit roll for low skill without instrument
            PerformanceManager pm = pawn.Map.GetComponent <PerformanceManager>();
            int skill             = pawn.skills.GetSkill(SkillDefOf.Artistic).Level;

            if (PerformanceManager.HeldInstrument(pawn) == null && skill < 3 && Verse.Rand.Chance(.75f))
            {
                return(null);
            }

            // if no music spots then give up
            if (pm.ListActiveMusicSpots().Count == 0)
            {
                return(null);
            }

            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) ||
                !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Hearing) ||
                !pawn.Awake() ||
                pawn.WorkTagIsDisabled(WorkTags.Artistic))
            {
                return(null);
            }

            // load all music spots on map into list
            JoyGiver_MusicPlay.workingSpots.Clear();
            for (int i = 0; i < pm.ListActiveMusicSpots().Count; i++)
            {
                JoyGiver_MusicPlay.workingSpots.Add(pm.ListActiveMusicSpots()[i]);
            }

            // pick a random one
            CompMusicSpot CompMusicSpot;

            while (JoyGiver_MusicPlay.workingSpots.TryRandomElement(out CompMusicSpot))
            {
                // remove from list
                JoyGiver_MusicPlay.workingSpots.Remove(CompMusicSpot);
                // check zones etc
                if (!CompMusicSpot.parent.IsForbidden(pawn))
                {
                    // see if there's a safe path to get there
                    if (pawn.CanReach(CompMusicSpot.parent, PathEndMode.Touch, Danger.None, false, TraverseMode.ByPawn))
                    {
                        // prisoners seperated from colonists
                        if (CompMusicSpot.parent.IsSociallyProper(pawn))
                        {
                            // only friendly factions
                            if (CompMusicSpot.parent.IsPoliticallyProper(pawn))
                            {
                                // check passed in predicate - i.e. parties
                                if (musicSpotValidator == null || musicSpotValidator(CompMusicSpot))
                                {
                                    //check for an instrument
                                    if (PerformanceManager.HeldInstrument(pawn) != null || pm.AnyAvailableMapInstruments(pawn, CompMusicSpot.parent))
                                    {
                                        Thing instrument;

                                        if (pm.TryFindInstrumentToPlay(CompMusicSpot.parent, pawn, out instrument))
                                        {
                                            // find a place to sit or stand, or return null if there aren't any
                                            LocalTargetInfo chairOrSpot = null;

                                            if (pm.TryFindStandingSpotOrChair(CompMusicSpot, pawn, instrument, out chairOrSpot))
                                            {
                                                Job job = new Job(def.jobDef, CompMusicSpot.parent, chairOrSpot, instrument);

                                                job.count = 1;

                                                return(job);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }