Ejemplo n.º 1
0
        public static bool AcceptableGameConditionsToStartCeremony(Map map)
        {
            bool result;

            if (!MarriageCeremonyUtility.AcceptableGameConditionsToContinueCeremony(map))
            {
                result = false;
            }
            else if (GenLocalDate.HourInteger(map) < 5 || GenLocalDate.HourInteger(map) > 16)
            {
                result = false;
            }
            else if (GatheringsUtility.AnyLordJobPreventsNewGatherings(map))
            {
                result = false;
            }
            else if (map.dangerWatcher.DangerRating != StoryDanger.None)
            {
                result = false;
            }
            else
            {
                int num = 0;
                foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned)
                {
                    if (pawn.Drafted)
                    {
                        num++;
                    }
                }
                result = ((float)num / (float)map.mapPawns.FreeColonistsSpawnedCount < 0.5f);
            }
            return(result);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.mindState.duty == null)
            {
                return(null);
            }
            LordJob_Joinable_Concert lordJob_Joinable_Concert = pawn.GetLord().LordJob as LordJob_Joinable_Concert;

            if (lordJob_Joinable_Concert == null || lordJob_Joinable_Concert.Organizer != pawn)
            {
                return(null);
            }
            IntVec3 gatherSpot = pawn.mindState.duty.focus.Cell;
            Building_MusicalInstrument building_MusicalInstrument = pawn.Map.listerBuildings.AllBuildingsColonistOfClass <Building_MusicalInstrument>().Where(delegate(Building_MusicalInstrument i)
            {
                if (!GatheringsUtility.InGatheringArea(i.InteractionCell, gatherSpot, pawn.Map))
                {
                    return(false);
                }
                return(GatheringWorker_Concert.InstrumentAccessible(i, pawn) ? true : false);
            }).RandomElementWithFallback();

            if (building_MusicalInstrument != null)
            {
                Job job = JobMaker.MakeJob(JobDefOf.Play_MusicalInstrument, building_MusicalInstrument, building_MusicalInstrument.InteractionCell);
                job.doUntilGatheringEnded = true;
                job.expiryInterval        = lordJob_Joinable_Concert.DurationTicks;
                return(job);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static bool AcceptableGameConditionsToStartCeremony(Map map)
        {
            if (!AcceptableGameConditionsToContinueCeremony(map))
            {
                return(false);
            }
            if (GenLocalDate.HourInteger(map) < 5 || GenLocalDate.HourInteger(map) > 16)
            {
                return(false);
            }
            if (GatheringsUtility.AnyLordJobPreventsNewGatherings(map))
            {
                return(false);
            }
            if (map.dangerWatcher.DangerRating != 0)
            {
                return(false);
            }
            int num = 0;

            foreach (Pawn item in map.mapPawns.FreeColonistsSpawned)
            {
                if (item.Drafted)
                {
                    num++;
                }
            }
            if ((float)num / (float)map.mapPawns.FreeColonistsSpawnedCount >= 0.5f)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        public override bool GizmoDisabled(out string reason)
        {
            LordJob_Joinable_Speech lordJob_Joinable_Speech = parent.pawn.GetLord()?.LordJob as LordJob_Joinable_Speech;

            if (lordJob_Joinable_Speech != null && lordJob_Joinable_Speech.Organizer == parent.pawn)
            {
                reason = "AbilitySpeechDisabledAlreadyGivingSpeech".Translate();
                return(true);
            }
            if (GatheringsUtility.AnyLordJobPreventsNewGatherings(parent.pawn.Map))
            {
                reason = "AbilitySpeechDisabledAnotherGatheringInProgress".Translate();
                return(true);
            }
            Building_Throne assignedThrone = parent.pawn.ownership.AssignedThrone;

            if (assignedThrone == null)
            {
                reason = "AbilitySpeechDisabledNoThroneAssigned".Translate();
                return(true);
            }
            if (!parent.pawn.CanReserveAndReach(assignedThrone, PathEndMode.InteractionCell, parent.pawn.NormalMaxDanger()))
            {
                reason = "AbilitySpeechDisabledNoThroneIsNotAccessible".Translate();
                return(true);
            }
            if (parent.pawn.royalty.GetUnmetThroneroomRequirements().Any())
            {
                reason = "AbilitySpeechDisabledNoThroneUndignified".Translate();
                return(true);
            }
            reason = null;
            return(false);
        }
Ejemplo n.º 5
0
 public bool CanExecute(Map map, Pawn organizer = null, bool ignoreGameConditions = false)
 {
     if (ignoreGameConditions || GatheringsUtility.AcceptableGameConditionsToStartGathering(map, this))
     {
         return(Worker.CanExecute(map, organizer));
     }
     return(false);
 }
Ejemplo n.º 6
0
 protected override IntVec3 GetExactWanderDest(Pawn pawn)
 {
     if (!GatheringsUtility.TryFindRandomCellInGatheringArea(pawn, out IntVec3 result))
     {
         return(IntVec3.Invalid);
     }
     return(result);
 }
        protected override bool Satisfied(Pawn pawn)
        {
            if (pawn.mindState.duty == null)
            {
                return(false);
            }
            IntVec3 cell = pawn.mindState.duty.focus.Cell;

            return(GatheringsUtility.InGatheringArea(pawn.Position, cell, pawn.Map));
        }
Ejemplo n.º 8
0
 public static bool ShouldPawnKeepPartying(Pawn p)
 {
     if (p.timetable != null && !p.timetable.CurrentAssignment.allowJoy)
     {
         return(false);
     }
     if (!GatheringsUtility.ShouldGuestKeepAttendingGathering(p))
     {
         return(false);
     }
     return(true);
 }
 protected virtual bool ShouldBeCalledOff()
 {
     if (!GatheringsUtility.PawnCanStartOrContinueGathering(organizer))
     {
         return(true);
     }
     if (!GatheringsUtility.AcceptableGameConditionsToContinueGathering(base.Map))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 10
0
 public override bool CanExecute(Map map, Pawn organizer = null)
 {
     if (organizer != null)
     {
         FindFiancees(organizer, out var firstFiance, out var secondFiance);
         if (!GatheringsUtility.PawnCanStartOrContinueGathering(firstFiance) || !GatheringsUtility.PawnCanStartOrContinueGathering(secondFiance))
         {
             return(false);
         }
     }
     return(base.CanExecute(map, organizer));
 }
Ejemplo n.º 11
0
        public static bool TryFindGatheringSpot(Pawn organizer, GatheringDef gatheringDef, out IntVec3 result)
        {
            bool enjoyableOutside = JoyUtility.EnjoyableOutsideNow(organizer);
            Map  map = organizer.Map;
            Predicate <IntVec3> baseValidator  = (IntVec3 cell) => GatheringsUtility.ValidateGatheringSpot(cell, gatheringDef, organizer, enjoyableOutside);
            List <ThingDef>     gatherSpotDefs = gatheringDef.gatherSpotDefs;

            try
            {
                foreach (ThingDef item in gatherSpotDefs)
                {
                    foreach (Building item2 in map.listerBuildings.AllBuildingsColonistOfDef(item))
                    {
                        tmpSpotThings.Add(item2);
                    }
                }
                if ((from x in tmpSpotThings
                     where baseValidator(x.Position)
                     select x.Position).TryRandomElement(out result))
                {
                    return(true);
                }
            }
            finally
            {
                tmpSpotThings.Clear();
            }
            Predicate <IntVec3> noPartySpotValidator = delegate(IntVec3 cell)
            {
                Room room = cell.GetRoom(map);
                return((room == null || room.IsHuge || room.PsychologicallyOutdoors || room.CellCount >= 10) ? true : false);
            };

            foreach (CompGatherSpot item3 in map.gatherSpotLister.activeSpots.InRandomOrder())
            {
                for (int i = 0; i < 10; i++)
                {
                    IntVec3 intVec = CellFinder.RandomClosewalkCellNear(item3.parent.Position, item3.parent.Map, 4);
                    if (baseValidator(intVec) && noPartySpotValidator(intVec))
                    {
                        result = intVec;
                        return(true);
                    }
                }
            }
            if (CellFinder.TryFindRandomCellNear(organizer.Position, organizer.Map, 25, (IntVec3 cell) => baseValidator(cell) && noPartySpotValidator(cell), out result))
            {
                return(true);
            }
            result = IntVec3.Invalid;
            return(false);
        }
 public static bool FianceCanContinueCeremony(Pawn pawn, Pawn otherPawn)
 {
     if (!GatheringsUtility.PawnCanStartOrContinueGathering(pawn))
     {
         return(false);
     }
     if (pawn.HostileTo(otherPawn))
     {
         return(false);
     }
     if (pawn.Spawned && !pawn.Downed)
     {
         return(!pawn.InMentalState);
     }
     return(false);
 }
 private bool AreFiancesInPartyArea()
 {
     if (!lord.ownedPawns.Contains(firstPawn) || !lord.ownedPawns.Contains(secondPawn))
     {
         return(false);
     }
     if (firstPawn.Map != base.Map || !GatheringsUtility.InGatheringArea(firstPawn.Position, spot, base.Map))
     {
         return(false);
     }
     if (secondPawn.Map != base.Map || !GatheringsUtility.InGatheringArea(secondPawn.Position, spot, base.Map))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 14
0
        public static bool AcceptableGameConditionsToStartParty(Map map)
        {
            if (!AcceptableGameConditionsToContinueParty(map))
            {
                return(false);
            }
            if (GenLocalDate.HourInteger(map) < 4 || GenLocalDate.HourInteger(map) > 21)
            {
                return(false);
            }
            if (GatheringsUtility.AnyLordJobPreventsNewGatherings(map))
            {
                return(false);
            }
            if (map.dangerWatcher.DangerRating != 0)
            {
                return(false);
            }
            int freeColonistsSpawnedCount = map.mapPawns.FreeColonistsSpawnedCount;

            if (freeColonistsSpawnedCount < 4)
            {
                return(false);
            }
            int num = 0;

            foreach (Pawn item in map.mapPawns.FreeColonistsSpawned)
            {
                if (item.health.hediffSet.BleedRateTotal > 0f)
                {
                    return(false);
                }
                if (item.Drafted)
                {
                    num++;
                }
            }
            if ((float)num / (float)freeColonistsSpawnedCount >= 0.5f)
            {
                return(false);
            }
            if (!EnoughPotentialGuestsToStartParty(map))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 15
0
        public static bool AcceptableGameConditionsToStartParty(Map map)
        {
            bool result;

            if (!PartyUtility.AcceptableGameConditionsToContinueParty(map))
            {
                result = false;
            }
            else if (GenLocalDate.HourInteger(map) < 4 || GenLocalDate.HourInteger(map) > 21)
            {
                result = false;
            }
            else if (GatheringsUtility.AnyLordJobPreventsNewGatherings(map))
            {
                result = false;
            }
            else if (map.dangerWatcher.DangerRating != StoryDanger.None)
            {
                result = false;
            }
            else
            {
                int freeColonistsSpawnedCount = map.mapPawns.FreeColonistsSpawnedCount;
                if (freeColonistsSpawnedCount < 4)
                {
                    result = false;
                }
                else
                {
                    int num = 0;
                    foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned)
                    {
                        if (pawn.health.hediffSet.BleedRateTotal > 0f)
                        {
                            return(false);
                        }
                        if (pawn.Drafted)
                        {
                            num++;
                        }
                    }
                    result = ((float)num / (float)freeColonistsSpawnedCount < 0.5f && PartyUtility.EnoughPotentialGuestsToStartParty(map, null));
                }
            }
            return(result);
        }
Ejemplo n.º 16
0
        public override void LordToilTick()
        {
            List <Pawn> ownedPawns = lord.ownedPawns;

            for (int i = 0; i < ownedPawns.Count; i++)
            {
                if (GatheringsUtility.InGatheringArea(ownedPawns[i].Position, spot, base.Map))
                {
                    ownedPawns[i].needs.joy.GainJoy(joyPerTick, JoyKindDefOf.Social);
                    if (!Data.presentForTicks.ContainsKey(ownedPawns[i]))
                    {
                        Data.presentForTicks.Add(ownedPawns[i], 0);
                    }
                    Data.presentForTicks[ownedPawns[i]]++;
                }
            }
        }
 public override float VoluntaryJoinPriorityFor(Pawn p)
 {
     if (IsInvited(p))
     {
         if (!GatheringsUtility.ShouldPawnKeepGathering(p, gatheringDef))
         {
             return(0f);
         }
         if (spot.IsForbidden(p))
         {
             return(0f);
         }
         if (!lord.ownedPawns.Contains(p) && IsGatheringAboutToEnd())
         {
             return(0f);
         }
         return(VoluntarilyJoinableLordJobJoinPriorities.SocialGathering);
     }
     return(0f);
 }
 public virtual bool CanExecute(Map map, Pawn organizer = null)
 {
     if (organizer == null)
     {
         organizer = FindOrganizer(map);
     }
     if (organizer == null)
     {
         return(false);
     }
     if (!TryFindGatherSpot(organizer, out var _))
     {
         return(false);
     }
     if (!GatheringsUtility.PawnCanStartOrContinueGathering(organizer))
     {
         return(false);
     }
     return(true);
 }
 private bool ShouldAfterPartyBeCalledOff()
 {
     if (firstPawn.Destroyed || secondPawn.Destroyed)
     {
         return(true);
     }
     if (firstPawn.Downed || secondPawn.Downed)
     {
         return(true);
     }
     if (spot.GetDangerFor(firstPawn, base.Map) != Danger.None || spot.GetDangerFor(secondPawn, base.Map) != Danger.None)
     {
         return(true);
     }
     if (!GatheringsUtility.AcceptableGameConditionsToContinueGathering(base.Map))
     {
         return(true);
     }
     return(false);
 }
 private bool ShouldCeremonyBeCalledOff()
 {
     if (firstPawn.Destroyed || secondPawn.Destroyed)
     {
         return(true);
     }
     if (!firstPawn.relations.DirectRelationExists(PawnRelationDefOf.Fiance, secondPawn))
     {
         return(true);
     }
     if (spot.GetDangerFor(firstPawn, base.Map) != Danger.None || spot.GetDangerFor(secondPawn, base.Map) != Danger.None)
     {
         return(true);
     }
     if (!GatheringsUtility.AcceptableGameConditionsToContinueGathering(base.Map) || !MarriageCeremonyUtility.FianceCanContinueCeremony(firstPawn, secondPawn) || !MarriageCeremonyUtility.FianceCanContinueCeremony(secondPawn, firstPawn))
     {
         return(true);
     }
     return(false);
 }
        private Thing FindBestGame(Pawn pawn, bool inBed, IntVec3 gatheringSpot)
        {
            tmpCandidates.Clear();
            GetSearchSet(pawn, tmpCandidates);
            if (tmpCandidates.Count == 0)
            {
                return(null);
            }
            Predicate <Thing> predicate = (Thing t) => CanInteractWith(pawn, t, inBed);

            if (gatheringSpot.IsValid)
            {
                Predicate <Thing> oldValidator = predicate;
                predicate = ((Thing x) => GatheringsUtility.InGatheringArea(x.Position, gatheringSpot, pawn.Map) && oldValidator(x));
            }
            Thing result = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, tmpCandidates, PathEndMode.OnCell, TraverseParms.For(pawn), 9999f, predicate);

            tmpCandidates.Clear();
            return(result);
        }
Ejemplo n.º 22
0
        private Thing FindFood(Pawn pawn, IntVec3 gatheringSpot)
        {
            Predicate <Thing> validator = delegate(Thing x)
            {
                if (!x.IngestibleNow)
                {
                    return(false);
                }
                if (!x.def.IsNutritionGivingIngestible)
                {
                    return(false);
                }
                if (!GatheringsUtility.InGatheringArea(x.Position, gatheringSpot, pawn.Map))
                {
                    return(false);
                }
                if (x.def.IsDrug)
                {
                    return(false);
                }
                if ((int)x.def.ingestible.preferability <= 4)
                {
                    return(false);
                }
                if (!pawn.WillEat(x))
                {
                    return(false);
                }
                if (x.IsForbidden(pawn))
                {
                    return(false);
                }
                if (!x.IsSociallyProper(pawn))
                {
                    return(false);
                }
                return(pawn.CanReserve(x) ? true : false);
            };

            return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.NoPassClosedDoors), 14f, validator, null, 0, 12));
        }
Ejemplo n.º 23
0
        protected override bool TryFindGatherSpot(Pawn organizer, out IntVec3 spot)
        {
            bool enjoyableOutside = JoyUtility.EnjoyableOutsideNow(organizer);

            _ = organizer.Map;
            IEnumerable <Building_MusicalInstrument> enumerable = organizer.Map.listerBuildings.AllBuildingsColonistOfClass <Building_MusicalInstrument>();

            try
            {
                int num = -1;
                foreach (Building_MusicalInstrument item in enumerable)
                {
                    if (GatheringsUtility.ValidateGatheringSpot_NewTemp(item.InteractionCell, def, organizer, enjoyableOutside, ignoreRequiredColonistCount: false) && InstrumentAccessible(item, organizer))
                    {
                        float instrumentRange = item.def.building.instrumentRange;
                        if ((float)num < instrumentRange)
                        {
                            tmpInstruments.Clear();
                        }
                        else if ((float)num > instrumentRange)
                        {
                            continue;
                        }
                        tmpInstruments.Add(item);
                    }
                }
                if (!tmpInstruments.TryRandomElement(out var result))
                {
                    spot = IntVec3.Invalid;
                    return(false);
                }
                spot = result.InteractionCell;
                return(true);
            }
            finally
            {
                tmpInstruments.Clear();
            }
        }
Ejemplo n.º 24
0
 public static bool ShouldGuestKeepAttendingCeremony(Pawn p)
 {
     return(GatheringsUtility.ShouldGuestKeepAttendingGathering(p));
 }
 protected virtual Pawn FindOrganizer(Map map)
 {
     return(GatheringsUtility.FindRandomGatheringOrganizer(Faction.OfPlayer, map, def));
 }
 protected override Trigger_TicksPassed GetTimeoutTrigger()
 {
     return(new Trigger_TicksPassedAfterConditionMet(base.DurationTicks, () => GatheringsUtility.InGatheringArea(organizer.Position, spot, organizer.Map), 60));
 }
Ejemplo n.º 27
0
        public override StateGraph CreateGraph()
        {
            StateGraph stateGraph = new StateGraph();
            LordToil   lordToil   = CreateGatheringToil(spot, organizer, gatheringDef);

            stateGraph.AddToil(lordToil);
            LordToil_End lordToil_End = new LordToil_End();

            stateGraph.AddToil(lordToil_End);
            float      speechDuration = 12500f;
            Transition transition     = new Transition(lordToil, lordToil_End);

            transition.AddTrigger(new Trigger_TickCondition(ShouldBeCalledOff));
            transition.AddTrigger(new Trigger_PawnKilled());
            transition.AddTrigger(new Trigger_PawnLost(PawnLostCondition.LeftVoluntarily, organizer));
            transition.AddPreAction(new TransitionAction_Custom((Action) delegate
            {
                ApplyOutcome((float)lord.ticksInToil / speechDuration);
            }));
            stateGraph.AddTransition(transition);
            timeoutTrigger = new Trigger_TicksPassedAfterConditionMet((int)speechDuration, () => GatheringsUtility.InGatheringArea(organizer.Position, spot, organizer.Map), 60);
            Transition transition2 = new Transition(lordToil, lordToil_End);

            transition2.AddTrigger(timeoutTrigger);
            transition2.AddPreAction(new TransitionAction_Custom((Action) delegate
            {
                ApplyOutcome(1f);
            }));
            stateGraph.AddTransition(transition2);
            return(stateGraph);
        }
 public override Job TryGiveJobInGatheringArea(Pawn pawn, IntVec3 gatheringSpot)
 {
     return(TryGiveJobInt(pawn, (CompGatherSpot x) => GatheringsUtility.InGatheringArea(x.parent.Position, gatheringSpot, pawn.Map)));
 }
Ejemplo n.º 29
0
 public override Job TryGiveJobInGatheringArea(Pawn pawn, IntVec3 gatheringSpot)
 {
     return(TryGiveJobInternal(pawn, (Thing x) => !x.Spawned || GatheringsUtility.InGatheringArea(x.Position, gatheringSpot, pawn.Map)));
 }
Ejemplo n.º 30
0
 public static bool ShouldPawnKeepPartying(Pawn p)
 {
     return((p.timetable == null || p.timetable.CurrentAssignment.allowJoy) && GatheringsUtility.ShouldGuestKeepAttendingGathering(p));
 }