public override void Interacted(Pawn initiator, Pawn recipient, List <RulePackDef> extraSentencePacks, out string letterText, out string letterLabel, out LetterDef letterDef)
        {
            letterText  = null;
            letterLabel = null;
            letterDef   = null;
            //Choose a time that works with their schedule, based on their personality
            Dictionary <int, float> possibleHours = new Dictionary <int, float>();

            for (int i = 0; i < GenDate.HoursPerDay; i++)
            {
                possibleHours.Add(i, 0f);
            }
            foreach (PersonalityNodeDef d in DefDatabase <PersonalityNodeDef> .AllDefsListForReading)
            {
                if (d.preferredDateHours != null)
                {
                    foreach (int h in d.preferredDateHours)
                    {
                        possibleHours[h] += (Mathf.Pow(Mathf.Abs(0.5f - PsycheHelper.Comp(initiator).Psyche.GetPersonalityRating(d)), 2) / (1.3f - PsycheHelper.Comp(initiator).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Aggressive)) + Mathf.Pow(Mathf.Abs(0.5f - PsycheHelper.Comp(recipient).Psyche.GetPersonalityRating(d)), 2) / (1.3f - PsycheHelper.Comp(recipient).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Aggressive)) / 2f);
                    }
                }
            }
            int hour = possibleHours.Keys.RandomElementByWeight(h => possibleHours[h] * RendezvousUtility.TimeAssignmentFactor(initiator, h) * RendezvousUtility.TimeAssignmentFactor(recipient, h));
            //More Spontaneous couples will plan their dates sooner; possibly even immediately!
            int day = Find.TickManager.TicksAbs + Mathf.RoundToInt(GenDate.TicksPerDay * 5 * (((1f - PsycheHelper.Comp(initiator).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Spontaneous)) + (1f - PsycheHelper.Comp(recipient).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Spontaneous))) / 2f));
            Hediff_PlannedDate plannedDate = HediffMaker.MakeHediff(HediffDefOfPsychology.PlannedDate, initiator) as Hediff_PlannedDate;

            plannedDate.partner = recipient;
            plannedDate.day     = day;
            plannedDate.hour    = hour;
            initiator.health.AddHediff(plannedDate);
            PsycheHelper.Comp(initiator).Psyche.lastDateTick = day;
            PsycheHelper.Comp(recipient).Psyche.lastDateTick = day;
            if (PsychologyBase.SendDateLetters())
            {
                int    hourDiscrepancy = GenDate.HourOfDay(day, Find.WorldGrid.LongLatOf(initiator.Map.Tile).x) - hour;
                int    accurateTime    = day + (Math.Abs(hourDiscrepancy) * GenDate.TicksPerHour);
                String dateTime        = GenDate.QuadrumDateStringAt(accurateTime, Find.WorldGrid.LongLatOf(initiator.Map.Tile).x);
                Letter dateLetter      = LetterMaker.MakeLetter("LetterLabelDatePlanned".Translate(), "LetterDatePlanned".Translate(initiator, recipient, dateTime, hour), LetterDefOf.PositiveEvent);
                Find.LetterStack.ReceiveLetter(dateLetter);
            }
        }
Exemple #2
0
        //StoryState
        public static void Postfix(StoryState __instance, FiringIncident fi, IIncidentTarget ___target, ref int ___lastThreatBigTick)
        {
            if (fi.parms.forced || fi.parms.target != ___target)
            {
                return;
            }

            if (fi.parms.target is Map map)
            {
                bool ally = fi.def.category == IncidentCategoryDefOf.FactionArrival;
                bool raid = fi.def.category == IncidentCategoryDefOf.ThreatBig;
                if (ally || raid)
                {
                    float delayDays = ally ? DelayDays.DelayAllyDays(map) : DelayDays.DelayRaidDays(map);

                    string eventDesc = ally ? "visitors" : "threats";

                    if (delayDays > 0)
                    {
                        __instance.lastFireTicks[fi.def] += (int)(delayDays * GenDate.TicksPerDay);

                        if (Mod.settings.logResults)
                        {
                            string date = GenDate.QuadrumDateStringAt(GenTicks.TicksGame, 0);
                            Verse.Log.Message($"On {date}, Safely Hidden Away delayed {eventDesc} to {map.info.parent.LabelShortCap} by {delayDays:0.0} days.");
                        }

                        if (raid)
                        {
                            int last = ___lastThreatBigTick + ((int)(delayDays * GenDate.TicksPerDay));

                            ___lastThreatBigTick = last;
                        }
                    }
                }
            }
        }
Exemple #3
0
        public override void Tick()
        {
            Pawn dead = null;

            base.Tick();
            if (dead == null)
            {
                Corpse corpse = (grave as Building_Grave).Corpse;
                if (corpse != null && corpse.InnerPawn != null)
                {
                    dead = corpse.InnerPawn;
                }
                else
                {
                    Log.Warning("[Psychology] A funeral was planned for someone, but they're gone now.");
                    pawn.health.RemoveHediff(this);
                }
            }
            if (!announced && ageTicks > GenDate.TicksPerHour)
            {
                Find.LetterStack.ReceiveLetter("LetterLabelFuneralPlanned".Translate(dead), "LetterFuneralPlanned".Translate(pawn, dead, GenDate.QuadrumDateStringAt(GenDate.TickGameToAbs(date), Find.WorldGrid.LongLatOf(pawn.Map.Tile).x), hour), LetterDefOf.PositiveEvent, pawn);
                announced = true;
            }
            if (GenLocalDate.DayOfYear(pawn.Map) >= day && GenLocalDate.HourOfDay(pawn.Map) == hour)
            {
                Find.LetterStack.ReceiveLetter("LetterLabelFuneralStarted".Translate(dead), "LetterFuneralStarted".Translate(dead), LetterDefOf.PositiveEvent, grave);
                LordMaker.MakeNewLord(pawn.Faction, new LordJob_Joinable_Funeral(spot, grave as Building_Grave), pawn.Map, null);
                pawn.health.RemoveHediff(this);
            }
        }