public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Hearing) || !pawn.Awake() || pawn.WorkTagIsDisabled(WorkTags.Artistic)) { return(false); } PerformanceManager pm = pawn.Map.GetComponent <PerformanceManager>(); if (!pm.CanPlayForWorkNow(pawn)) { return(false); } CompMusicSpot compMusicSpot = t.TryGetComp <CompMusicSpot>(); CompMusicalInstrument instrumentComp = t.TryGetComp <CompMusicalInstrument>(); CompPowerTrader powerComp = t.TryGetComp <CompPowerTrader>(); if (compMusicSpot == null) { return(false); } if (!compMusicSpot.Active || instrumentComp == null) { return(false); } IntVec3 standingSpot; if (!pm.TryFindSitSpotOnGroundNear(compMusicSpot, pawn, out standingSpot)) { return(false); } Thing instrument; LocalTargetInfo chairOrSpot = null; if (forced && instrumentComp != null && instrumentComp.Props.isBuilding && pawn.CanReserveAndReach(t, PathEndMode.Touch, Danger.None) && (powerComp == null || powerComp.PowerOn)) { if (!pm.TryFindStandingSpotOrChair(compMusicSpot, pawn, t, out chairOrSpot)) { return(false); } } else if (pm.TryFindInstrumentToPlay(compMusicSpot.parent, pawn, out instrument, true)) { #if DEBUG Verse.Log.Message(String.Format("{0} chose to play {1}", pawn.LabelShort, instrument.LabelShort)); #endif if (!pm.TryFindStandingSpotOrChair(compMusicSpot, pawn, instrument, out chairOrSpot)) { return(false); } } else { return(false); } return(true); }
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); }
public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) { //Verse.Log.Message(String.Format("Trying to play at {0}", thing.Label)); if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Hearing) || !pawn.Awake() || pawn.WorkTagIsDisabled(WorkTags.Artistic)) { return(null); } PerformanceManager pm = pawn.Map.GetComponent <PerformanceManager>(); if (!pm.CanPlayForWorkNow(pawn)) { return(null); } CompMusicSpot compMusicSpot = thing.TryGetComp <CompMusicSpot>(); if (compMusicSpot == null) { return(null); } if (!compMusicSpot.Active) { return(null); } Job job; IntVec3 standingSpot; if (!pm.TryFindSitSpotOnGroundNear(compMusicSpot, pawn, out standingSpot)) { return(null); } job = new Job(JobDefOf_MusicPlayWork.MusicPlayWork, compMusicSpot.parent); //, standingSpot); Thing instrument; CompMusicSpot musicSpotComp = thing.TryGetComp <CompMusicSpot>(); CompMusicalInstrument instrumentComp = thing.TryGetComp <CompMusicalInstrument>(); CompPowerTrader powerComp = thing.TryGetComp <CompPowerTrader>(); LocalTargetInfo chairOrSpot = null; if (forced && instrumentComp != null && instrumentComp.Props.isBuilding && pawn.CanReserveAndReach(thing, PathEndMode.Touch, Danger.None) && (powerComp == null || powerComp.PowerOn)) { if (!pm.TryFindStandingSpotOrChair(musicSpotComp, pawn, thing, out chairOrSpot)) { return(null); } job.targetB = chairOrSpot; job.targetC = thing; } else if (pm.TryFindInstrumentToPlay(compMusicSpot.parent, pawn, out instrument, true)) { #if DEBUG Verse.Log.Message(String.Format("{0} chose to play {1}", pawn.LabelShort, instrument.LabelShort)); #endif if (!pm.TryFindStandingSpotOrChair(musicSpotComp, pawn, instrument, out chairOrSpot)) { return(null); } job.targetB = chairOrSpot; job.targetC = instrument; } else { #if DEBUG Verse.Log.Message(String.Format("{0} couldn't find an instrument", pawn.LabelShort)); #endif return(null); } job.count = 1; return(job); }