Ejemplo n.º 1
0
 public bool TryStartGathering(GatheringDef gatheringDef)
 {
     if (!gatheringDef.Worker.TryExecute(map))
     {
         return(false);
     }
     lastLordStartTick        = Find.TickManager.TicksGame;
     startRandomGatheringASAP = false;
     return(true);
 }
Ejemplo n.º 2
0
 public static bool ShouldPawnKeepGathering(Pawn p, GatheringDef gatheringDef)
 {
     if (gatheringDef.respectTimetable && p.timetable != null && !p.timetable.CurrentAssignment.allowJoy)
     {
         return(false);
     }
     if (!ShouldGuestKeepAttendingGathering(p))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        public static Pawn FindRandomGatheringOrganizer(Faction faction, Map map, GatheringDef gatheringDef)
        {
            Predicate <Pawn> v = (Pawn x) => x.RaceProps.Humanlike && !x.InBed() && !x.InMentalState && x.GetLord() == null && ShouldPawnKeepGathering(x, gatheringDef) && !x.Drafted && (gatheringDef.requiredTitleAny == null || gatheringDef.requiredTitleAny.Count == 0 || (x.royalty != null && x.royalty.AllTitlesInEffectForReading.Any((RoyalTitle t) => gatheringDef.requiredTitleAny.Contains(t.def))));

            if ((from x in map.mapPawns.SpawnedPawnsInFaction(faction)
                 where v(x)
                 select x).TryRandomElement(out Pawn result))
            {
                return(result);
            }
            return(null);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public static bool EnoughPotentialGuestsToStartGathering(Map map, GatheringDef gatheringDef, IntVec3?gatherSpot = null)
        {
            int value = Mathf.RoundToInt((float)map.mapPawns.FreeColonistsSpawnedCount * 0.65f);

            value = Mathf.Clamp(value, 2, 10);
            int num = 0;

            foreach (Pawn item in map.mapPawns.FreeColonistsSpawned)
            {
                if (ShouldPawnKeepGathering(item, gatheringDef) && (!gatherSpot.HasValue || !gatherSpot.Value.IsForbidden(item)) && (!gatherSpot.HasValue || item.CanReach(gatherSpot.Value, PathEndMode.Touch, Danger.Some)))
                {
                    num++;
                }
            }
            return(num >= value);
        }
Ejemplo n.º 6
0
        public static bool AcceptableGameConditionsToStartGathering(Map map, GatheringDef gatheringDef)
        {
            if (!AcceptableGameConditionsToContinueGathering(map))
            {
                return(false);
            }
            if (GenLocalDate.HourInteger(map) < 4 || GenLocalDate.HourInteger(map) > 21)
            {
                return(false);
            }
            if (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 (!EnoughPotentialGuestsToStartGathering(map, gatheringDef))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
        public static bool ValidateGatheringSpot(IntVec3 cell, GatheringDef gatheringDef, Pawn organizer, bool enjoyableOutside)
        {
            Map map = organizer.Map;

            if (!cell.Standable(map))
            {
                return(false);
            }
            if (cell.GetDangerFor(organizer, map) != Danger.None)
            {
                return(false);
            }
            if (!enjoyableOutside && !cell.Roofed(map))
            {
                return(false);
            }
            if (cell.IsForbidden(organizer))
            {
                return(false);
            }
            if (!organizer.CanReserveAndReach(cell, PathEndMode.OnCell, Danger.None))
            {
                return(false);
            }
            bool flag = cell.GetRoom(map)?.isPrisonCell ?? false;

            if (organizer.IsPrisoner != flag)
            {
                return(false);
            }
            if (!EnoughPotentialGuestsToStartGathering(map, gatheringDef, cell))
            {
                return(false);
            }
            return(true);
        }
 public LordJob_Joinable_Concert(IntVec3 spot, Pawn organizer, GatheringDef gatheringDef)
     : base(spot, organizer, gatheringDef)
 {
 }
Ejemplo n.º 9
0
 protected override LordToil CreateGatheringToil(IntVec3 spot, Pawn organizer, GatheringDef gatheringDef)
 {
     return(new LordToil_Speech(spot, gatheringDef, organizer));
 }
Ejemplo n.º 10
0
 public LordJob_Joinable_Party(IntVec3 spot, Pawn organizer, GatheringDef gatheringDef)
     : base(spot, organizer, gatheringDef)
 {
     durationTicks = Rand.RangeInclusive(5000, 15000);
 }
Ejemplo n.º 11
0
 public LordToil_Speech(IntVec3 spot, GatheringDef gatheringDef, Pawn organizer)
     : base(spot, gatheringDef)
 {
     this.organizer = organizer;
     data           = new LordToilData_Speech();
 }
 public LordJob_Joinable_Gathering(IntVec3 spot, Pawn organizer, GatheringDef gatheringDef)
 {
     this.spot         = spot;
     this.organizer    = organizer;
     this.gatheringDef = gatheringDef;
 }
 public LordToil_Gathering(IntVec3 spot, GatheringDef gatheringDef)
 {
     this.spot         = spot;
     this.gatheringDef = gatheringDef;
 }
 public static bool ValidateGatheringSpot(IntVec3 cell, GatheringDef gatheringDef, Pawn organizer, bool enjoyableOutside)
 {
     return(ValidateGatheringSpot_NewTemp(cell, gatheringDef, organizer, enjoyableOutside, ignoreRequiredColonistCount: false));
 }
 protected abstract LordToil CreateGatheringToil(IntVec3 spot, Pawn organizer, GatheringDef gatheringDef);
 protected override LordToil CreateGatheringToil(IntVec3 spot, Pawn organizer, GatheringDef gatheringDef)
 {
     return(new LordToil_Concert(spot, organizer, gatheringDef));
 }
Ejemplo n.º 17
0
 public LordToil_Concert(IntVec3 spot, Pawn organizer, GatheringDef gatheringDef, float joyPerTick = 3.5E-05f)
     : base(spot, gatheringDef, joyPerTick)
 {
     this.organizer = organizer;
 }
Ejemplo n.º 18
0
 public LordToil_Party(IntVec3 spot, GatheringDef gatheringDef, float joyPerTick = 3.5E-05f)
     : base(spot, gatheringDef)
 {
     this.joyPerTick = joyPerTick;
     data            = new LordToilData_Party();
 }