Exemplo n.º 1
0
        public static bool TryFindRandomCellInSermonArea(BuildingAltar altar, Pawn pawn, out IntVec3 result)
        {
            if (pawn.mindState.duty.focus.Cell == null)
            {
                Log.Message("NoFocusCell");
            }
            IntVec3  cell;
            Building chair;

            WatchBuildingUtility.TryFindBestWatchCell(altar, pawn, true, out cell, out chair);


            if (chair != null)
            {
                result = chair.Position;
                return(true);
            }

            result = cell;
            if (cell == null)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        public static List <Pawn> GetSermonFlock(BuildingAltar altar)
        {
            List <Pawn> tmp  = new List <Pawn>();
            Room        room = altar.GetRoom();

            if (room.Role != RoomRoleDefOf.PrisonBarracks && room.Role != RoomRoleDefOf.PrisonCell)
            {
                List <Pawn> listeners = altar.Map.mapPawns.AllPawnsSpawned.FindAll(x => x.RaceProps.intelligence == Intelligence.Humanlike);
                bool[]      flag      = new bool[listeners.Count];
                for (int i = 0; i < listeners.Count; i++)
                {
                    if (!flag[i] && SermonUtility.ShouldAttendSermon(listeners[i], altar.preacher))
                    {
                        tmp.Add(listeners[i]);
                        flag[i] = true;
                    }
                }
            }
            else
            {
                List <Pawn> prisoners = altar.Map.mapPawns.PrisonersOfColonySpawned.FindAll(x => x.RaceProps.intelligence == Intelligence.Humanlike);
                bool[]      flag2     = new bool[prisoners.Count];
                for (int i = 0; i < prisoners.Count; i++)
                {
                    if (!flag2[i] && SermonUtility.ShouldAttendSermon(prisoners[i], altar.preacher))
                    {
                        tmp.Add(prisoners[i]);
                        flag2[i] = true;
                    }
                }
            }

            return(tmp);
        }
        private static void ForceListenersTest(BuildingAltar altar)
        {
            IntVec3  result;
            Building chair;

            foreach (Pawn p in altar.Map.mapPawns.AllPawnsSpawned.FindAll(x => x.RaceProps.intelligence == Intelligence.Humanlike))
            {
                if (!SermonUtility.IsPreacher(p))
                {
                    if (!WatchBuildingUtility.TryFindBestWatchCell(altar, p, true, out result, out chair))
                    {
                        if (!WatchBuildingUtility.TryFindBestWatchCell(altar as Thing, p, false, out result, out chair))
                        {
                            return;
                        }
                    }
                    if (chair != null)
                    {
                        Job J = new Job(C_JobDefOf.AttendSermon, altar.preacher, altar, chair);
                        p.QueueJob(J);
                        p.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    }
                    else
                    {
                        Job J = new Job(C_JobDefOf.AttendSermon, altar.preacher, altar, result);
                        p.QueueJob(J);
                        p.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    }
                }
            }
        }
        public static void OpenPreacherSelectMenu(BuildingAltar altar)
        {
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            list.Add(new FloatMenuOption("(" + "NoneLower".Translate() + ")", delegate
            {
                altar.preacher = null;
            }, MenuOptionPriority.Default, null, null, 0f, null));

            foreach (Pawn current in altar.Map.mapPawns.FreeColonistsSpawned)
            {
                if (!SermonUtility.IsPreacher(current))
                {
                    Need_Soul nsoul = current.needs.TryGetNeed <Need_Soul>();
                    if (nsoul == null)
                    {
                        nsoul = new Need_Soul(current);
                    }
                    SoulTrait strait = nsoul.DevotionTrait;
                    string    text1  = current.NameStringShort + " (" + strait.SoulCurrentData.label + ")";

                    Action action;
                    Pawn   localCol = current;
                    action = delegate
                    {
                        altar.preacher = localCol;
                    };
                    list.Add(new FloatMenuOption(text1, action, MenuOptionPriority.Default, null, null, 0f, null));
                }
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
        public static void SermonTickCheckEnd(Pawn pawn, BuildingAltar altar)
        {
            var curJob = pawn.CurJob;

            var soul = pawn.needs.TryGetNeed <Need_Soul>();

            if (soul == null)
            {
                return;
            }

            Room  temple = altar.GetRoom();
            float num    = 1 + CommonMisc.Radar.FindAllPawnsInRoomCount(temple) / 10;

            soul.GainNeed(curJob.def.joyGainRate * num);

            if (!pawn.GetTimeAssignment().allowJoy)
            {
                pawn.jobs.curDriver.EndJobWith(JobCondition.InterruptForced);
            }
            if ((double)soul.CurLevel < 0.999899983406067)
            {
                return;
            }
            pawn.jobs.curDriver.EndJobWith(JobCondition.Succeeded);
        }
Exemplo n.º 6
0
 public static void GiveAttendSermonJob(BuildingAltar altar, Pawn attendee)
 {
     if (!SermonUtility.IsPreacher(attendee))
     {
         IntVec3  result;
         Building chair;
         if (!WatchBuildingUtility.TryFindBestWatchCell(altar, attendee, true, out result, out chair))
         {
             if (!WatchBuildingUtility.TryFindBestWatchCell(altar as Thing, attendee, false, out result, out chair))
             {
                 return;
             }
         }
         if (chair != null)
         {
             Job J = new Job(C_JobDefOf.AttendSermon, altar.preacher, altar, chair);
             attendee.QueueJob(J);
             attendee.jobs.EndCurrentJob(JobCondition.InterruptForced);
         }
         else
         {
             Job J = new Job(C_JobDefOf.AttendSermon, altar.preacher, altar, result);
             attendee.QueueJob(J);
             attendee.jobs.EndCurrentJob(JobCondition.InterruptForced);
         }
     }
 }
Exemplo n.º 7
0
 public Dialog_RenameTemple(BuildingAltar altar)
 {
     this.Altar                   = altar;
     this.forcePause              = true;
     this.closeOnEscapeKey        = false;
     this.absorbInputAroundWindow = true;
 }
        public override float GetScore(Room room)
        {
            int          num = 0;
            List <Thing> allContainedThings = room.AllContainedThings;

            for (int i = 0; i < allContainedThings.Count; i++)
            {
                Thing         thing = allContainedThings[i];
                BuildingAltar altar = thing as BuildingAltar;
                if (altar != null && altar.def.size.x > 1)
                {
                    num += 20;
                }
                else if (altar != null && altar.def.size.x == 1)
                {
                    if (altar != null && altar.def.size.x > 1)
                    {
                        num += 5;
                    }
                }
            }
            if (num >= 20)
            {
                return(10000);
            }
            return(0f);
        }
Exemplo n.º 9
0
        public static void ForceSermonV2(BuildingAltar altar)
        {
            IntVec3 b   = altar.def.interactionCellOffset.RotatedBy(altar.Rotation) + altar.Position;
            Job     job = new Job(C_JobDefOf.HoldSermon, altar, b);

            altar.preacher.QueueJob(job);
            altar.preacher.jobs.EndCurrentJob(JobCondition.InterruptForced);
            //    BuildingAltar.GetSermonFlock(altar);
        }
 private static string PreacherLabel(BuildingAltar altar)
 {
     if (altar.preacher == null)
     {
         return("None");
     }
     else
     {
         return(altar.preacher.NameStringShort);
     }
 }
Exemplo n.º 11
0
 public static bool PawnIsPreacher(Pawn p, List <BuildingAltar> alts, out BuildingAltar altar)
 {
     foreach (BuildingAltar b in alts)
     {
         if (b.preacher == p && (b.DoMorningSermon || b.DoEveningSermon))
         {
             altar = b;
             return(true);
         }
     }
     altar = null;
     return(false);
 }
Exemplo n.º 12
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(AltarIndex, JobCondition.Incompletable);
            yield return(Toils_Reserve.Reserve(AltarIndex, 1));

            yield return(Toils_Reserve.Reserve(AltarInteractionCell, 1));

            Toil gotoAltarToil;

            gotoAltarToil = Toils_Goto.GotoThing(AltarInteractionCell, PathEndMode.OnCell);

            yield return(gotoAltarToil);

            //     Log.Message("A");
            //       if (this.CurJob == null) Log.Message("NOJob?");

            var altarToil = new Toil();

            altarToil.defaultCompleteMode = ToilCompleteMode.Delay;
            altarToil.defaultDuration     = this.CurJob.def.joyDuration;
            altarToil.AddPreTickAction(() =>
            {
                //          if (this.pawn == null) Log.Message("No Pawn??");
                //          if (this.TargetA == null) Log.Message("NoTargetA");
                this.pawn.Drawer.rotator.FaceCell(this.TargetA.Cell);
                this.pawn.GainComfortFromCellIfPossible();
                ThrowPreacherMote(this.pawn);
            });
            yield return(altarToil);

            //          Log.Message("B");
            //       if (this.pawn.jobs.curDriver == null) Log.Message("NoDriver");
            //          if (this.pawn.jobs.curJob == null) Log.Message("NoJob");
            this.AddFinishAction(() =>
            {
                if (this.TargetA.HasThing)
                {
                    this.Map.reservationManager.Release(this.CurJob.targetA.Thing, pawn);
                }
                else
                {
                    this.Map.reservationManager.Release(this.CurJob.targetA.Cell, this.pawn);
                }
                BuildingAltar altar = this.TargetA.Thing as BuildingAltar;
                altar.CalledInFlock = false;
                SermonUtility.HoldSermonTickCheckEnd(this.pawn, altar);

                //            Log.Message("C");
            });
        }
Exemplo n.º 13
0
        public static void ForceSermon(BuildingAltar altar, bool isMorningPrayer = true)
        {
            IntVec3 b = altar.def.interactionCellOffset.RotatedBy(altar.Rotation) + altar.Position;

            altar.activeSermon = true;
            List <Pawn> list = new List <Pawn>();

            if (!list.Contains(altar.preacher))
            {
                list.Add(altar.preacher);
            }
            list.AddRange(SermonUtility.GetSermonFlock(altar));

            Lord lord = LordMaker.MakeNewLord(altar.Faction, new LordJob_Sermon(altar, isMorningPrayer), altar.Map, list);
        }
Exemplo n.º 14
0
        public override Job TryGiveJob(Pawn pawn)
        {
            Log.Message("TryingToHostsermon");
            if (PawnUtility.WillSoonHaveBasicNeed(pawn))
            {
                return(null);
            }
            if (Find.StoryWatcher.watcherDanger.DangerRating != StoryDanger.None)
            {
                return(null);
            }

            Job job = new Job(CorruptionDefOfs.HoldSermon, assignedAltar, assignedAltar.InteractionCell);

            BuildingAltar.GetSermonFlock(assignedAltar);
            return(job);
        }
Exemplo n.º 15
0
        public static bool TryFindRandomCellInSermonArea(BuildingAltar altar, Pawn pawn, out IntVec3 result)
        {
            IntVec3  cell;
            Building chair;

            WatchBuildingUtility.TryFindBestWatchCell(altar, pawn, true, out cell, out chair);


            if (chair != null)
            {
                result = chair.Position;
                return(true);
            }

            result = cell;
            if (cell == null)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 16
0
        public static void HoldSermonTickCheckEnd(Pawn preacher, BuildingAltar altar)
        {
            var soul = preacher.needs.TryGetNeed <Need_Soul>();

            if (soul == null)
            {
                return;
            }

            float num = 0f;

            foreach (Pawn l in Find.MapPawns.AllPawnsSpawned.FindAll(x => x.Position.InHorDistOf(preacher.Position, 20f) == true))
            {
                num += 0.002f;
            }

            if (movingSermon(preacher))
            {
                num += 0.01f;
            }

            soul.GainNeed(num);
        }
Exemplo n.º 17
0
        public static bool GetBestPreacher(Pawn p, out Pawn bestPreacher, out BuildingAltar altar)
        {
            List <Pawn> opposingDevotees = p.needs.TryGetNeed <Need_Soul>().OpposingDevotees;

            if (opposingDevotees == null)
            {
                opposingDevotees = new List <Pawn>();
            }
            List <Pawn> availablePreachers = p.Map.mapPawns.FreeColonistsSpawned.ToList <Pawn>().FindAll(s => s.CurJob.def == C_JobDefOf.HoldSermon);

            //Select best preacher of colony

            bestPreacher = availablePreachers.Aggregate((i1, i2) => i1.skills.GetSkill(SkillDefOf.Social).Level > i2.skills.GetSkill(SkillDefOf.Social).Level ? i1 : i2);
            altar        = SermonUtility.chosenAltar(bestPreacher);
            //Check if pawn has listened to this preacher before and if he is of an opposing faith. If so, another preacher will be chosen

            while (opposingDevotees.Contains(bestPreacher))
            {
                if (availablePreachers.Count > 1)
                {
                    availablePreachers.Remove(bestPreacher);
                    bestPreacher = availablePreachers.Aggregate((i1, i2) => i1.skills.GetSkill(SkillDefOf.Social).Level > i2.skills.GetSkill(SkillDefOf.Social).Level ? i1 : i2);
                    altar        = chosenAltar(bestPreacher);
                }
                else
                {
                    bestPreacher = null;
                    altar        = null;
                }
            }
            if (bestPreacher != null && altar != null)
            {
                return(true);
            }
            return(false);
        }
        public static void DrawTempleCard(Rect rect, BuildingAltar altar)
        {
            GUI.BeginGroup(rect);
            Rect rect2 = new Rect(rect.x, rect.y + 20f, 250f, 55f);

            Text.Font = GameFont.Medium;
            Widgets.Label(rect2, altar.RoomName);
            Text.Font = GameFont.Small;

            Rect rect3 = rect2;

            rect3.y      = rect2.yMax + 30f;
            rect3.width  = 200f;
            rect3.height = 25f;
            Widgets.Label(rect3, "Preacher".Translate() + ": ");
            rect3.xMin = rect3.center.x + 10f;
            string label2 = PreacherLabel(altar);

            if (Widgets.ButtonText(rect3, label2, true, false, true))
            {
                TempleCardUtility.OpenPreacherSelectMenu(altar);
            }
            Rect rect4 = rect3;

            rect4.y    += 35f;
            rect4.width = 200f;
            if (Widgets.ButtonText(rect4, "RenameTemple".Translate(), true, false, true))
            {
                Find.WindowStack.Add(new Dialog_RenameTemple(altar));
            }
            Rect rectDebug1 = rect4;

            rectDebug1.y += 25f;
            if (DebugSettings.godMode)
            {
                if (Widgets.ButtonText(rectDebug1, "ForceSermonDebug".Translate(), true, false, true))
                {
                    SermonUtility.ForceSermon(altar);
                }
                Rect rectDebug2 = rectDebug1;
                rectDebug2.y += 25f;
                if (Widgets.ButtonText(rectDebug2, "ForceListenersDebug".Translate(), true, false, true))
                {
                    TempleCardUtility.ForceListenersTest(altar);
                }
            }

            Rect rect5 = rect4;

            rect5.x     = rect4.xMax + 5f;
            rect5.width = 200f;
            rect5.y    -= 20f;
            Widgets.CheckboxLabeled(rect5, "MorningSermons".Translate(), ref altar.OptionMorning, false);
            Rect rect6 = rect5;

            rect6.y += 20f;
            Widgets.CheckboxLabeled(rect6, "EveningSermons".Translate(), ref altar.OptionEvening, false);


            GUI.EndGroup();
        }