예제 #1
0
        public static void AppendPsychologyThoughts(TaleNewsPawnDied __instance, Pawn recipient)
        {
            Pawn killer = __instance.Killer;
            Pawn victim = __instance.Victim;

            // Psychology did a lot of work to exclude thoughts from Bleeding Heart.

            if (recipient.Faction == victim.Faction)
            {
                new IndividualThoughtToAdd(Psycho_ThoughtDefOf.WitnessedDeathAllyBleedingHeart, recipient).Add();
            }
            else if (victim.Faction == null || victim.Faction.HostileTo(recipient.Faction) || recipient.story.traits.HasTrait(Psycho_TraitDefOf.BleedingHeart))
            {
                new IndividualThoughtToAdd(Psycho_ThoughtDefOf.WitnessedDeathNonAllyBleedingHeart, recipient).Add();
            }
            bool traitsDisallowDesensitization = recipient.story.traits.HasTrait(Psycho_TraitDefOf.BleedingHeart) || recipient.story.traits.HasTrait(TraitDefOf.Psychopath) || recipient.story.traits.HasTrait(TraitDefOf.Bloodlust) || recipient.story.traits.HasTrait(Psycho_TraitDefOf.Desensitized);
            // ALL PRAISE GOD RANDY OUR ONE TRUE LORD
            bool randyAllowsDesensitization = (recipient.GetHashCode() ^ ((GenLocalDate.DayOfYear(recipient) + GenLocalDate.Year(recipient) + (int)(GenLocalDate.DayPercent(recipient) * 5f) * 60) * 391)) % 1000 == 0;

            // No Bleeding Heart + No Psychopath + No Bloodlust + No Desensitised + Random Genner
            if (!traitsDisallowDesensitization && randyAllowsDesensitization)
            {
                // Gain Desensitized
                recipient.story.traits.GainTrait(new Trait(Psycho_TraitDefOf.Desensitized));
                recipient.needs.mood.thoughts.memories.TryGainMemory(Psycho_ThoughtDefOf.RecentlyDesensitized);
            }
        }
예제 #2
0
        public override void Tick()
        {
            base.Tick();
            switch ((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 5) * 60) * 391) % (50 * (13 - ((this.CurStageIndex + 1) * 2))))
            {
            case 0:
                panic          = true;
                this.Severity += 0.00000002f;
                if (pawn.Spawned && pawn.RaceProps.Humanlike)
                {
                    if (pawn.jobs.curJob.def != JobDefOf.FleeAndCower && !pawn.jobs.curDriver.asleep)
                    {
                        pawn.jobs.StartJob(new Job(JobDefOf.FleeAndCower, pawn.Position), JobCondition.InterruptForced, null, false, true, null);
                    }
                    else if (pawn.jobs.curDriver.asleep)
                    {
                        pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.DreamNightmare);
                    }
                }
                break;

            default:
                panic = false;
                break;
            }
        }
        private void Payment(List <Thing> payment, bool vassalPay, bool TributePay, string factionList)
        {
            if (GenLocalDate.Year(Find.AnyPlayerHomeMap) >= year)
            {
                year = GenLocalDate.Year(Find.AnyPlayerHomeMap) + 1;
            }
            if (GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap) >= dayOfMonth)
            {
                dayOfMonth = ClosestNumberOf15(GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap) + 1);
            }
            if (!payment.NullOrEmpty())
            {
                string text = "";
                if (vassalPay && TributePay)
                {
                    text += "FactionVassalSilverRecivedBoth".Translate(GenThing.GetMarketValue(payment).ToStringMoney(), GenLabel.ThingsLabel(payment, string.Empty));
                }
                else if (vassalPay)
                {
                    text += "FactionVassalSilverRecivedVassals".Translate(GenThing.GetMarketValue(payment).ToStringMoney(), GenLabel.ThingsLabel(payment, string.Empty));
                }
                else if (TributePay)
                {
                    text += "FactionVassalSilverRecivedTrivutaries".Translate(GenThing.GetMarketValue(payment).ToStringMoney(), GenLabel.ThingsLabel(payment, string.Empty));
                }

                factionList.Remove(factionList.Count() - 1);
                DropPodUtility.DropThingsNear(DropCellFinder.TradeDropSpot(Find.AnyPlayerHomeMap), Find.AnyPlayerHomeMap, payment, 110, false, true, true);
                Find.LetterStack.ReceiveLetter("LetterFactionVassalSilverRecived".Translate(), text + factionList, LetterDefOf.PositiveEvent, null);
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
        //
        public static bool DayOfYearWithin(this Pawn p, List <IntRange> parameters)
        {
            if (p.Map == null)
            {
                return(false);
            }

            int val = GenLocalDate.DayOfYear(p);

            return(parameters.Any(ir => ir.min >= val && ir.max <= val));
        }
        public static void ClearYesterdaysSkillValues(Pawn pawn)
        {
            int num = GenLocalDate.DayOfYear(pawn);

            if (PawnMeleeSkillValues.ContainsKey(pawn.ThingID) && PawnMeleeSkillValues[pawn.ThingID].DayOfYear != num)
            {
                PawnMeleeSkillValues.Remove(pawn.ThingID);
            }
            if (PawnShootingSkillValues.ContainsKey(pawn.ThingID) && PawnShootingSkillValues[pawn.ThingID].DayOfYear != num)
            {
                PawnShootingSkillValues.Remove(pawn.ThingID);
            }
        }
예제 #7
0
        public static int NowToTicks(int tileId)
        {
            var day  = GenLocalDate.DayOfYear(tileId);
            var year = GenLocalDate.Year(tileId);

            var ticks = DateToTicks(day, year);

            if (ticks == 0)
            {
                ticks = 1;
            }

            return(ticks);
        }
예제 #8
0
        public static void CancelJob(ref Job __result, Pawn pawn)
        {
            Pawn partner = LovePartnerRelationUtility.GetPartnerInMyBed(pawn);

            if (PsycheHelper.PsychologyEnabled(pawn) && PsycheHelper.PsychologyEnabled(partner) && PsychologyBase.ActivateKinsey())
            {
                float random  = Rand.ValueSeeded((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 2) * 60) * 391));
                float random2 = Rand.ValueSeeded((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(partner) + GenLocalDate.Year(partner) + (int)(GenLocalDate.DayPercent(partner) * 2) * 60) * 391));
                if (random > PsycheHelper.Comp(pawn).Sexuality.AdjustedSexDrive&& random2 > PsycheHelper.Comp(partner).Sexuality.AdjustedSexDrive)
                {
                    __result = null;
                }
            }
        }
예제 #9
0
 public static Thought_Memory AddDesensitizedChance(Thought_Memory thought_Memory, Pawn pawn)
 {
     if (thought_Memory != null && thought_Memory.def == ThoughtDefOf.ObservedLayingCorpse)
     {
         if (!pawn.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn.story.traits.HasTrait(TraitDefOf.Bloodlust) && !pawn.story.traits.HasTrait(TraitDefOfPsychology.Desensitized))
         {
             if (((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 5) * 60) * 391) % 1000) == 0)
             {
                 pawn.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized));
                 pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.RecentlyDesensitized);
             }
         }
     }
     return(thought_Memory);
 }
예제 #10
0
        public static void CancelJob(ref Job __result, Pawn pawn)
        {
            Pawn           partnerInMyBed = LovePartnerRelationUtility.GetPartnerInMyBed(pawn);
            PsychologyPawn realPawn       = pawn as PsychologyPawn;
            PsychologyPawn realPartner    = partnerInMyBed as PsychologyPawn;

            if (realPawn != null && realPartner != null && PsychologyBase.ActivateKinsey() && realPawn.sexuality != null && realPartner.sexuality != null)
            {
                float random = Rand.ValueSeeded((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 2) * 60) * 391));
                if (random > realPawn.sexuality.AdjustedSexDrive && random > realPartner.sexuality.AdjustedSexDrive)
                {
                    __result = null;
                }
            }
        }
예제 #11
0
        private static void ClearYesterdaysSkillValues(Pawn pawn)
        {
            // This gets the day of the year in the pawn's local time, which is important because the daily XP reset is
            // done by using midnight in the pawn's local time. See Pawn_SkillTracker::SkillsTick()
            // Here the day is used instead of the hour because it is not guaranteed that the job will be checked every hour, or even every day.
            int dayOfYear = GenLocalDate.DayOfYear(pawn);

            if (PawnMeleeSkillValues.ContainsKey(pawn.ThingID) && PawnMeleeSkillValues[pawn.ThingID].DayOfYear != dayOfYear)
            {
                PawnMeleeSkillValues.Remove(pawn.ThingID);
            }
            if (PawnShootingSkillValues.ContainsKey(pawn.ThingID) && PawnShootingSkillValues[pawn.ThingID].DayOfYear != dayOfYear)
            {
                PawnShootingSkillValues.Remove(pawn.ThingID);
            }
        }
예제 #12
0
        internal static void _ObserveSurroundingThings(this PawnObserver _this)
        {
            Pawn pawn = _this.GetPawn();

            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
            {
                return;
            }
            Room room = RoomQuery.RoomAt(pawn);
            int  num  = 0;

            while ((float)num < 100f)
            {
                IntVec3 c = pawn.Position + GenRadial.RadialPattern[num];
                if (c.InBounds(pawn.Map))
                {
                    if (RoomQuery.RoomAt(c, pawn.Map) == room)
                    {
                        List <Thing> thingList = c.GetThingList(pawn.Map);
                        for (int i = 0; i < thingList.Count; i++)
                        {
                            IThoughtGiver thoughtGiver = thingList[i] as IThoughtGiver;
                            if (thoughtGiver != null)
                            {
                                Thought_Memory thought_Memory = thoughtGiver.GiveObservedThought();
                                if (thought_Memory != null)
                                {
                                    if (thought_Memory.def == ThoughtDefOf.ObservedLayingCorpse)
                                    {
                                        if (!pawn.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn.story.traits.HasTrait(TraitDefOf.Bloodlust) && !pawn.story.traits.HasTrait(TraitDefOfPsychology.Desensitized))
                                        {
                                            if (((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 5) * 60) * 391) % 1000) == 0)
                                            {
                                                pawn.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized));
                                                pawn.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.RecentlyDesensitized, null);
                                            }
                                        }
                                    }
                                    pawn.needs.mood.thoughts.memories.TryGainMemoryThought(thought_Memory, null);
                                }
                            }
                        }
                    }
                }
                num++;
            }
        }
예제 #13
0
        public static void DesensitizeViaCorpse(PawnObserver __instance)
        {
            Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>();

            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
            {
                return;
            }
            RoomGroup roomGroup = pawn.GetRoomGroup();
            Map       map       = pawn.Map;
            int       num       = 0;

            while ((float)num < 100f)
            {
                IntVec3 intVec = pawn.Position + GenRadial.RadialPattern[num];
                if (intVec.InBounds(map))
                {
                    if (intVec.GetRoomGroup(map) == roomGroup)
                    {
                        if (GenSight.LineOfSight(intVec, pawn.Position, map, true, null, 0, 0))
                        {
                            List <Thing> thingList = intVec.GetThingList(map);
                            for (int i = 0; i < thingList.Count; i++)
                            {
                                IThoughtGiver thoughtGiver = thingList[i] as IThoughtGiver;
                                if (thoughtGiver != null)
                                {
                                    Thought_Memory thought_Memory = thoughtGiver.GiveObservedThought();
                                    if (thought_Memory != null && thought_Memory.def == ThoughtDefOf.ObservedLayingCorpse)
                                    {
                                        if (!pawn.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn.story.traits.HasTrait(TraitDefOf.Bloodlust) && !pawn.story.traits.HasTrait(TraitDefOfPsychology.Desensitized))
                                        {
                                            if (((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 5) * 60) * 391) % 1000) == 0)
                                            {
                                                pawn.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized));
                                                pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.RecentlyDesensitized, null);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                num++;
            }
        }
예제 #14
0
        protected override ThoughtState CurrentStateInternal(Pawn p)
        {
            switch ((p.GetHashCode() ^ (GenLocalDate.DayOfYear(p) + GenLocalDate.Year(p) + (int)(GenLocalDate.DayPercent(p) * 10) * 60) * 391) % 12)
            {
            case 0:
                return(ThoughtState.ActiveAtStage(0));

            case 1:
                return(ThoughtState.ActiveAtStage(1));

            case 2:
                return(ThoughtState.ActiveAtStage(1));

            case 3:
                return(ThoughtState.ActiveAtStage(2));

            case 4:
                return(ThoughtState.ActiveAtStage(2));

            case 5:
                return(ThoughtState.Inactive);

            case 6:
                return(ThoughtState.Inactive);

            case 7:
                return(ThoughtState.ActiveAtStage(3));

            case 8:
                return(ThoughtState.ActiveAtStage(3));

            case 9:
                return(ThoughtState.ActiveAtStage(4));

            case 10:
                return(ThoughtState.ActiveAtStage(4));

            case 11:
                return(ThoughtState.ActiveAtStage(5));

            default:
                throw new NotImplementedException();
            }
        }
        protected override ThoughtState CurrentStateInternal(Pawn p)
        {
            switch ((p.GetHashCode() ^ (GenLocalDate.DayOfYear(p) + GenLocalDate.Year(p) + (int)(GenMath.RoundTo(GenLocalDate.DayPercent(p), 0.25f) * 10) * 60) * 391) % 12)
            {
            case 0:
                return((p.story.traits.DegreeOfTrait(SyrTraitDefOf.Neurotic) == 2) ? ThoughtState.ActiveAtStage(0) : ThoughtState.Inactive);

            case 1:
                return(ThoughtState.ActiveAtStage(1));

            case 2:
                return(ThoughtState.ActiveAtStage(1));

            case 3:
                return(ThoughtState.ActiveAtStage(2));

            case 4:
                return(ThoughtState.ActiveAtStage(2));

            case 5:
                return(ThoughtState.Inactive);

            case 6:
                return(ThoughtState.Inactive);

            case 7:
                return(ThoughtState.ActiveAtStage(3));

            case 8:
                return(ThoughtState.ActiveAtStage(3));

            case 9:
                return(ThoughtState.ActiveAtStage(4));

            case 10:
                return(ThoughtState.ActiveAtStage(4));

            case 11:
                return((p.story.traits.DegreeOfTrait(SyrTraitDefOf.Neurotic) == 2) ? ThoughtState.ActiveAtStage(5) : ThoughtState.Inactive);

            default:
                throw new NotImplementedException();
            }
        }
예제 #16
0
        //generate PredictableSeed for Verse.Rand
        public static int PredictableSeed()
        {
            int seed = 0;

            try
            {
                Map map = Find.CurrentMap;
                //int seedHourOfDay = GenLocalDate.HourOfDay(map);
                //int seedDayOfYear = GenLocalDate.DayOfYear(map);
                //int seedYear = GenLocalDate.Year(map);
                seed = (GenLocalDate.HourOfDay(map) + GenLocalDate.DayOfYear(map)) * GenLocalDate.Year(map);
                //int seed = (seedHourOfDay + seedDayOfYear) * seedYear;
                //Log.Warning("seedHourOfDay: " + seedHourOfDay + "\nseedDayOfYear: " + seedDayOfYear + "\nseedYear: " + seedYear + "\n" + seed);
            }
            catch
            {
                seed = Rand.Int;
            }
            return(seed);
        }
예제 #17
0
        public static void PlanFuneral(Building_Grave __instance, Pawn worker)
        {
            Pawn planner;

            (from c in worker.Map.mapPawns.FreeColonistsSpawned
             where c.relations.OpinionOf(__instance.Corpse.InnerPawn) >= 20
             select c).TryRandomElementByWeight((c) => Mathf.Max(0f, c.relations.OpinionOf(__instance.Corpse.InnerPawn) - (PsycheHelper.PsychologyEnabled(c) ? 100f * (1f - PsycheHelper.Comp(c).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Nostalgic)) : 0f)), out planner);
            if (planner != null && PsycheHelper.PsychologyEnabled(__instance.Corpse.InnerPawn) && !PsycheHelper.Comp(__instance.Corpse.InnerPawn).AlreadyBuried)
            {
                Func <int, float> timeAssignmentFactor = delegate(int h)
                {
                    if (planner.timetable.GetAssignment(h) == TimeAssignmentDefOf.Joy)
                    {
                        return(1.25f);
                    }
                    if (planner.timetable.GetAssignment(h) == TimeAssignmentDefOf.Anything)
                    {
                        return(0.9f);
                    }
                    return(0f);
                };
                int hour = -1;
                if (Enumerable.Range(0, GenDate.HoursPerDay).TryRandomElementByWeight(h => timeAssignmentFactor(h), out hour))
                {
                    int date       = Find.TickManager.TicksGame + Mathf.RoundToInt(GenDate.TicksPerDay * (2f + (PsycheHelper.PsychologyEnabled(planner) ? 3f - (5f * PsycheHelper.Comp(planner).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Spontaneous)) : 0f)));
                    int currentDay = GenDate.DayOfYear(GenDate.TickGameToAbs(date), Find.WorldGrid.LongLatOf(planner.Map.Tile).x);
                    if (currentDay <= GenLocalDate.DayOfYear(planner.Map) && GenDate.HourOfDay(GenDate.TickGameToAbs(date), Find.WorldGrid.LongLatOf(planner.Map.Tile).x) > hour)
                    {
                        date += GenDate.TicksPerDay * (currentDay - GenLocalDate.DayOfYear(planner.Map));
                    }
                    Hediff_Funeral planFuneral = HediffMaker.MakeHediff(HediffDefOfPsychology.PlannedFuneral, planner) as Hediff_Funeral;
                    planFuneral.date  = date;
                    planFuneral.hour  = hour;
                    planFuneral.day   = GenDate.DayOfYear(GenDate.TickGameToAbs(date), Find.WorldGrid.LongLatOf(planner.Map.Tile).x);
                    planFuneral.grave = __instance;
                    planFuneral.spot  = __instance.Position;
                    planner.health.AddHediff(planFuneral);
                    PsycheHelper.Comp(__instance.Corpse.InnerPawn).AlreadyBuried = true;
                }
            }
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();
            if (!WorkManager.Enabled)
            {
                return;
            }
            var day       = GenLocalDate.DayOfYear(map);
            var hourFloat = GenLocalDate.HourFloat(map);

            if ((Find.TickManager.TicksGame + GetHashCode()) % 60 != 0 || Math.Abs(day - _currentDay) * 24 +
                Math.Abs(hourFloat - _currentTime) < 24f / Settings.UpdateFrequency)
            {
                return;
            }
            #if DEBUG
            Log.Message($"----- Work Manager: Updating work priorities... (day = {day}, hour = {hourFloat}) -----",
                        true);
            #endif
            if (!Current.Game.playSettings.useWorkPriorities)
            {
                Current.Game.playSettings.useWorkPriorities = true;
                foreach (var pawn in PawnsFinder.AllMapsWorldAndTemporary_Alive.Where(pawn =>
                                                                                      pawn.Faction == Faction.OfPlayer))
                {
                    pawn.workSettings?.Notify_UseWorkPrioritiesChanged();
                }
            }
            UpdateCache();
            if (_allPawns.Any())
            {
                AssignWorkPriorities();
            }
            _currentDay  = day;
            _currentTime = hourFloat;
            #if DEBUG
            Log.Message("----------------------------------------------------", true);
            #endif
        }
        public static void TrackPawnShootingSkill(Pawn pawn, SkillRecord skill)
        {
            int dayOfYear = GenLocalDate.DayOfYear(pawn);

            PawnShootingSkillValues[pawn.ThingID] = new SkillXpValues(dayOfYear, skill.xpSinceMidnight, skill.xpSinceLastLevel);
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();
            if (!WorkManager.Enabled)
            {
                return;
            }
            if (Find.TickManager.CurTimeSpeed == TimeSpeed.Paused || Find.TickManager.TicksGame % 60 != 0)
            {
                return;
            }
            var year        = GenLocalDate.Year(map);
            var day         = GenLocalDate.DayOfYear(map);
            var hourFloat   = GenLocalDate.HourFloat(map);
            var hoursPassed = (year - _workUpdateTime.Year) * 60 * 24 + (day - _workUpdateTime.Day) * 24 + hourFloat -
                              _workUpdateTime.Hour;

            if (Settings.UpdateFrequency == 0)
            {
                Settings.UpdateFrequency = 24;
            }
            if (hoursPassed < 24f / Settings.UpdateFrequency)
            {
                return;
            }
            if (!Current.Game.playSettings.useWorkPriorities)
            {
                Current.Game.playSettings.useWorkPriorities = true;
                foreach (var pawn in PawnsFinder.AllMapsWorldAndTemporary_Alive.Where(pawn =>
                                                                                      pawn.Faction == Faction.OfPlayer))
                {
                    pawn.workSettings?.Notify_UseWorkPrioritiesChanged();
                }
            }
            if (Settings.AssignEveryoneWorkTypes == null)
            {
                Settings.AssignEveryoneWorkTypes =
                    new List <AssignEveryoneWorkType>(Settings.DefaultAssignEveryoneWorkTypes);
            }
            if (Prefs.DevMode && Settings.VerboseLogging)
            {
                Log.Message(
                    $"----- Work Manager: Updating work priorities... (day = {day}, hour = {hourFloat}, passed = {hoursPassed:N1}) -----");
            }
            _workUpdateTime.Year = year;
            _workUpdateTime.Day  = day;
            _workUpdateTime.Hour = hourFloat;
            UpdateCache();
            UpdateWorkPriorities();
            ApplyWorkPriorities();
            if (Settings.ManageWorkSchedule && (year - _scheduleUpdateTime.Year) * 60 * 24 +
                (day - _scheduleUpdateTime.Day) * 24 + hourFloat - _scheduleUpdateTime.Hour >= 24)
            {
                _scheduleUpdateTime.Year = year;
                _scheduleUpdateTime.Day  = day;
                _scheduleUpdateTime.Hour = hourFloat;
                UpdateSchedule();
            }
            if (Prefs.DevMode && Settings.VerboseLogging)
            {
                Log.Message("----------------------------------------------------");
            }
        }
        private void WarUpdate(War war)
        {
            Faction f1 = war.AttackerFaction();
            Faction f2 = war.DefenderFaction();

            if (f1 == null || f2 == null || f1.defeated || f2.defeated)
            {
                Wars.Remove(war);
                return;
            }
            // Settlement conqured
            int chance = WarEventChance.RandomInRange;

            // Event Chance - 0.000675% every 600 ticks

            // Settlement Conqoured 0.00005%
            if (chance < 5)
            {
                Settlement settlement;
                // if f1
                if (Rand.Chance(0.5f + GetByFaction(f2).resources == GetByFaction(f1).resources ? GetByFaction(f2).resources / GetByFaction(f1).resources < 1 ? (0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : -(0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : 0))
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f1).RandomElement();
                    GetByFaction(f1).history += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarSettlementConqueredWinner".Translate(settlement, f2);
                    GetByFaction(f2).history += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarSettlementConqueredLoser".Translate(settlement, f1);
                }
                // if f2
                else
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f2).RandomElement();
                }

                Settlement set = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                set.SetFaction(settlement.Faction == f1 ? f2 : f1);

                set.Tile = settlement.Tile;
                set.Name = settlement.Name;
                Find.WorldObjects.Remove(settlement);
                Find.WorldObjects.Add(set);

                GetByFaction(set.Faction).resources        += SETTLEMENT_RESOURCE_VALUE;
                GetByFaction(settlement.Faction).resources -= SETTLEMENT_RESOURCE_VALUE * 5;
                Messages.Message("MessageFactionWarSettlementConquered".Translate(set.Faction, settlement, settlement.Faction), MessageTypeDefOf.NeutralEvent);
                war.warHistory += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageFactionWarSettlementConquered".Translate(set.Faction, settlement, settlement.Faction) + "\n\n";
                return;
            }
            // Settlement raided 0.00005%
            if (chance < 10)
            {
                Settlement settlement;
                // if f1
                if (Rand.Chance(0.5f + (GetByFaction(f2).resources / GetByFaction(f1).resources) < 1 ? (0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : -(0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f))))
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f1).RandomElement();
                }
                // if f2
                else
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f2).RandomElement();
                }
                Find.WorldObjects.Remove(settlement);

                GetByFaction(settlement.Faction == f1 ? f2 : f1).resources += SETTLEMENT_RESOURCE_VALUE / 2;
                GetByFaction(settlement.Faction).resources -= SETTLEMENT_RESOURCE_VALUE * 5;
                Messages.Message(FE_GrammarUtility.WarEvent(settlement.Faction == f1 ? f2 : f1, settlement.Faction, settlement), MessageTypeDefOf.NeutralEvent);
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(settlement.Faction == f1 ? f2 : f1, settlement.Faction, settlement) + "\n\n";
                return;
            }
            // Artifact cache - Background 0.0007%
            if (chance < 80)
            {
                if (Rand.Chance(0.5f))
                {
                    GetByFaction(f1).resources += LARGE_EVENT_Cache_RESOURCE_VALUE;
                    war.warHistory             += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(f1) + "\n\n";
                }
                else
                {
                    GetByFaction(f2).resources += LARGE_EVENT_Cache_RESOURCE_VALUE;
                    war.warHistory             += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(f2) + "\n\n";
                }
                return;
            }
            // Farms burned - Background 0.001%
            if (chance < 180)
            {
                if (Rand.Chance(0.5f))
                {
                    GetByFaction(f2).resources -= MEDIUM_EVENT_RESOURCE_VALUE;
                    war.warHistory             += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarFarms".Translate(f1, f2) + "\n\n";
                }
                else
                {
                    GetByFaction(f1).resources -= MEDIUM_EVENT_RESOURCE_VALUE;
                    war.warHistory             += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarFarms".Translate(f2, f1) + "\n\n";
                }
                return;
            }
            // Supply Depot 0.00025%
            if (chance < 205)
            {
                if (!Find.WorldObjects.Settlements.Where(x => (x.Faction == f1 && GetByFaction(f1).resources >= MEDIUM_EVENT_RESOURCE_VALUE * 2) || (x.Faction == f2 && GetByFaction(f1).resources >= MEDIUM_EVENT_RESOURCE_VALUE * 2)).TryRandomElement(out Settlement settlement))
                {
                    return;
                }
                if (!GetByFaction(settlement.Faction).SupplyDepots.Any(x => x > 10 * Global.DayInTicks) || !Find.WorldObjects.AllWorldObjects.Any(x => x.GetComponent <WorldObjectComp_SupplyDepot>() != null && x.GetComponent <WorldObjectComp_SupplyDepot>().IsActive&& x.GetComponent <TimeoutComp>().TicksLeft > 10 * Global.DayInTicks))
                {
                    return;
                }
                if (settlement.Faction.HostileTo(Faction.OfPlayer) && TileFinder.TryFindPassableTileWithTraversalDistance(settlement.Tile, 5, 25, out int tile))
                {
                    Site worldObject = SiteMaker.MakeSite(SiteCoreDefOf.Nothing, SitePartDefOf.Outpost, tile, settlement.Faction);
                    worldObject.GetComponent <TimeoutComp>().StartTimeout(Global.DayInTicks * 14);
                    WorldObjectComp_SupplyDepot.Type type = Rand.Chance(0.5f) ? WorldObjectComp_SupplyDepot.Type.Food : WorldObjectComp_SupplyDepot.Type.Weapons;
                    worldObject.GetComponent <WorldObjectComp_SupplyDepot>().StartComp(type);
                    worldObject.customLabel = "Supply Depot: " + type;
                    Find.WorldObjects.Add(worldObject);
                    Messages.Message("MessageFactionWarSupply".Translate(settlement.Faction), worldObject, MessageTypeDefOf.NeutralEvent, false);
                }
                else
                {
                    GetByFaction(settlement.Faction).SupplyDepots.Add(Global.DayInTicks * 14);
                    Messages.Message("MessageFactionWarSupply".Translate(settlement.Faction), null, MessageTypeDefOf.NeutralEvent, false);
                }
                GetByFaction(settlement.Faction).resources -= MEDIUM_EVENT_RESOURCE_VALUE;
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarSupply".Translate(settlement.Faction) + "\n\n";
                return;
            }
            // Caravan ambushed - Background 0.00125%
            if (chance < 355)
            {
                Faction ambusher = Rand.Chance(0.5f) ? f2 : f1;

                GetByFaction(ambusher == f1 ? f2 : f1).resources -= MINOR_EVENT_RESOURCE_VALUE;
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarCaravanAmbush".Translate(ambusher, ambusher == f1 ? f2 : f1) + "\n\n";
                return;
            }
            // Minor Outpost raided - Background 0.001%
            if (chance < 455)
            {
                Faction raider = Rand.Chance(0.5f) ? f2 : f1;

                GetByFaction(raider == f1 ? f2 : f1).resources -= MEDIUM_EVENT_RESOURCE_VALUE;
                GetByFaction(raider).resources += MEDIUM_EVENT_RESOURCE_VALUE / 2;
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarMinorOutpostRaid".Translate(raider, raider == f1 ? f2 : f1) + "\n\n";
                return;
            }
            // Failed Settlement raid - Background 0.001%
            if (chance < 555)
            {
                Settlement settlement;
                // if f1
                if (Rand.Chance(0.5f + (GetByFaction(f2).resources / GetByFaction(f1).resources) < 1 ? (0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : -(0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f))))
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f1).RandomElement();
                }
                // if f2
                else
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f2).RandomElement();
                }
                Find.WorldObjects.Remove(settlement);

                GetByFaction(settlement.Faction == f1 ? f2 : f1).resources -= LARGE_EVENT_Cache_RESOURCE_VALUE;

                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(settlement.Faction == f1 ? f2 : f1, settlement.Faction, settlement, true) + "\n\n";
                return;
            }

            // settlement Nuked - toxic fallout 0.00005%
            if (chance < 560 && Find.TickManager.TicksGame > Global.DayInTicks * 20 && Find.Storyteller.difficulty.difficulty >= 2 && !Find.AnyPlayerHomeMap.GameConditionManager.ConditionIsActive(GameConditionDefOf.ToxicFallout))
            {
                if (!(Rand.Chance(0.5f + GetByFaction(f2).resources == GetByFaction(f1).resources ? GetByFaction(f2).resources / GetByFaction(f1).resources < 1 ? (0.5f - (GetByFaction(f2).resources / GetByFaction(f1).resources / 2f)) : -(0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : 0) && (f1.def.techLevel == TechLevel.Industrial || f1.def.techLevel == TechLevel.Spacer) &&
                      Find.WorldObjects.Settlements.Where(x => x.Faction == f2 && Utilities.Reachable(Find.AnyPlayerHomeMap.Tile, x.Tile, 30)).TryRandomElement(out Settlement ruin)))
                {
                    if (!((f2.def.techLevel == TechLevel.Industrial || f1.def.techLevel == TechLevel.Spacer) && Find.WorldObjects.Settlements.Where(x => x.Faction == f1 && Utilities.Reachable(Find.AnyPlayerHomeMap.Tile, x.Tile, 30)).TryRandomElement(out ruin)))
                    {
                        return;
                    }
                }
                Find.WorldObjects.Remove(ruin);

                GetByFaction(ruin.Faction).resources -= SETTLEMENT_RESOURCE_VALUE * 7;
                IncidentParms parms = new IncidentParms()
                {
                    forced = true,
                    target = Find.AnyPlayerHomeMap
                };
                IncidentDefOf.ToxicFallout.Worker.TryExecute(parms);
                Messages.Message("MessageFactionWarSettlementNuked".Translate(ruin, ruin.Faction == f1 ? f2 : f1), MessageTypeDefOf.ThreatSmall);

                GetByFaction(ruin.Faction == f1 ? f2 : f1).history += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageFactionWarSettlementWinner".Translate(ruin, ruin.Faction, ruin.Faction == f1 ? f2 : f1) + "\n\n";
                GetByFaction(ruin.Faction).history += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageFactionWarSettlementNukedLoser".Translate(ruin, ruin.Faction == f1 ? f2 : f1) + "\n\n";
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarSettlementNukedHistory".Translate(ruin.Faction == f1 ? f2 : f1, ruin, ruin.Faction) + "\n\n";
                return;
            }
            // Factories sabotaged - background - 0.001%
            if (chance < 660)
            {
                Faction spy = Rand.Chance(0.5f) ? f2 : f1;

                GetByFaction(spy).resources -= MINOR_EVENT_RESOURCE_VALUE;
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(spy, spy == f1 ? f2 : f1) + "\n\n";
                return;
            }
        }
예제 #22
0
        public static void AppendPsychologyThoughts(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind, ref List <IndividualThoughtToAdd> outIndividualThoughts, ref List <ThoughtDef> outAllColonistsThoughts)
        {
            bool flag  = dinfo.HasValue && dinfo.Value.Def.execution;
            bool flag2 = victim.IsPrisonerOfColony && !victim.guilt.IsGuilty && !victim.InAggroMentalState;
            bool flag3 = dinfo.HasValue && dinfo.Value.Def.ExternalViolenceFor(victim) && dinfo.Value.Instigator != null && dinfo.Value.Instigator is Pawn;

            if (flag3)
            {
                Pawn pawn = (Pawn)dinfo.Value.Instigator;
                if (!pawn.Dead && pawn.needs.mood != null && pawn.story != null && pawn != victim)
                {
                    if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died && victim.HostileTo(pawn))
                    {
                        if (victim.Faction != null && victim.Faction.HostileTo(pawn.Faction) && !flag2)
                        {
                            outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KilledHumanlikeEnemy, pawn, victim, 1f, 1f));
                        }
                    }
                }
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died && victim.Spawned)
            {
                List <Pawn> allPawnsSpawned = victim.Map.mapPawns.AllPawnsSpawned;
                for (int i = 0; i < allPawnsSpawned.Count; i++)
                {
                    Pawn pawn2 = allPawnsSpawned[i];
                    if (pawn2 != victim && pawn2.needs.mood != null)
                    {
                        if (!flag && (pawn2.MentalStateDef != MentalStateDefOf.SocialFighting || ((MentalState_SocialFighting)pawn2.MentalState).otherPawn != victim))
                        {
                            if (pawn2.Position.InHorDistOf(victim.Position, 12f) && GenSight.LineOfSight(victim.Position, pawn2.Position, victim.Map, false) && pawn2.Awake() && pawn2.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
                            {
                                if (pawn2.Faction == victim.Faction)
                                {
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.WitnessedDeathAllyBleedingHeart, pawn2, null, 1f, 1f));
                                }
                                else if (victim.Faction == null || (!victim.Faction.HostileTo(pawn2.Faction) || pawn2.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart)))
                                {
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.WitnessedDeathNonAllyBleedingHeart, pawn2, null, 1f, 1f));
                                }
                                if (!pawn2.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn2.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn2.story.traits.HasTrait(TraitDefOf.Bloodlust) && !pawn2.story.traits.HasTrait(TraitDefOfPsychology.Desensitized))
                                {
                                    if (((pawn2.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn2) + GenLocalDate.Year(pawn2) + (int)(GenLocalDate.DayPercent(pawn2) * 5) * 60) * 391) % 1000) == 0)
                                    {
                                        pawn2.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized));
                                        pawn2.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.RecentlyDesensitized, null);
                                    }
                                }
                            }
                            else if (victim.Faction == Faction.OfPlayer && victim.Faction == pawn2.Faction && victim.HostFaction != pawn2.Faction)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KnowColonistDiedBleedingHeart, pawn2, null, 1f, 1f));
                            }
                            if (flag2 && pawn2.Faction == Faction.OfPlayer && !pawn2.IsPrisoner)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KnowPrisonerDiedInnocentBleedingHeart, pawn2, null, 1f, 1f));
                            }
                        }
                    }
                }
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Banished && victim.IsColonist)
            {
                outAllColonistsThoughts.Add(ThoughtDefOfPsychology.ColonistAbandonedBleedingHeart);
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.BanishedToDie)
            {
                if (victim.IsColonist)
                {
                    outAllColonistsThoughts.Add(ThoughtDefOfPsychology.ColonistAbandonedToDieBleedingHeart);
                }
                else if (victim.IsPrisonerOfColony)
                {
                    outAllColonistsThoughts.Add(ThoughtDefOfPsychology.PrisonerAbandonedToDieBleedingHeart);
                }
            }
        }
        // Balance High priority
        private void WarAftermath(Faction loser, Faction winner)
        {
            if (loser == null || winner == null)
            {
                return;
            }
            if (GetByFaction(winner)?.resources < 100 || !EndGame_Settings.WarAftermath)
            {
                Find.LetterStack.ReceiveLetter("LetterLabelWarOutcome".Translate(), "MessageFactionWarWhitePeace".Translate(loser, winner), LetterDefOf.PositiveEvent);
                GetByFaction(loser).resources += (int)loser.def.techLevel * TECHLEVEL_RESOURCE_VALUE;

                GetByFaction(loser).history  += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarWhitePeace".Translate(loser, winner) + "\n\n";
                GetByFaction(winner).history += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarWhitePeace".Translate(loser, winner) + "\n\n";
                return;
            }
            if (GetByFaction(winner).resources < 4000)
            {
                Find.LetterStack.ReceiveLetter("LetterLabelWarOutcome".Translate(), "MessageFactionWarFactionDestoryed".Translate(loser, winner), LetterDefOf.PositiveEvent, null, winner);
                GetByFaction(winner).history += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarFactionDestoryed".Translate(loser, winner) + "\n\n";

                IEnumerable <Settlement> settlements = Find.WorldObjects.Settlements.Where(x => x.Faction == loser);
                int     groupSize       = 0;
                int     groupMax        = (settlements.Count() / 2) + 1;
                Faction splinterFaction = new Faction();

                foreach (Settlement s in settlements.ToList())
                {
                    if (groupSize == 0)
                    {
                        splinterFaction = FactionGenerator.NewGeneratedFaction(loser.def);
                        splinterFaction.colorFromSpectrum = FactionGenerator.NewRandomColorFromSpectrum(splinterFaction);

                        Find.WorldObjects.Remove(Find.WorldObjects.Settlements.Where(x => x.Faction == splinterFaction).RandomElement());
                    }

                    Settlement replace = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                    replace.Tile = s.Tile;
                    replace.SetFaction(splinterFaction);
                    replace.Name = s.Name;
                    Find.WorldObjects.Remove(s);
                    Find.WorldObjects.Add(replace);
                    groupSize++;
                    if (groupSize == groupMax)
                    {
                        Find.FactionManager.Add(splinterFaction);
                        Find.Maps.ForEach((x) => { x.pawnDestinationReservationManager.RegisterFaction(splinterFaction); });
                        groupSize = 0;
                    }
                }
                if (groupSize < groupMax)
                {
                    Find.FactionManager.Add(splinterFaction);
                    Find.CurrentMap.pawnDestinationReservationManager.RegisterFaction(splinterFaction);
                }

                foreach (WorldObject ob in Find.WorldObjects.AllWorldObjects.Where(x => x.Faction == loser).ToList())
                {
                    Find.WorldObjects.Remove(ob);
                }
                loser.defeated = true;
                Wars.RemoveAll(war => war.DefenderFaction() == loser || war.AttackerFaction() == loser);
                factionInfo.Remove(GetByFaction(loser));
                return;
            }

            //if(GetByFaction(winner).resources < 7000) //if another case is added later.
            {
                Find.LetterStack.ReceiveLetter("LetterLabelWarOutcome".Translate(), "MessageFactionWarFactionConquered".Translate(loser, winner), LetterDefOf.PositiveEvent);
                GetByFaction(winner).history += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarFactionConquered".Translate(loser, winner) + "\n\n";

                foreach (Settlement s in Find.WorldObjects.Settlements.Where(x => x.Faction == loser).ToList())
                {
                    Settlement replace = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                    replace.Tile = s.Tile;
                    replace.SetFaction(winner);
                    replace.Name = s.Name;
                    Find.WorldObjects.Remove(s);
                    Find.WorldObjects.Add(replace);
                }
                foreach (WorldObject ob in Find.WorldObjects.AllWorldObjects.Where(x => x.Faction == loser).ToList())
                {
                    Find.WorldObjects.Remove(ob);
                }
                GetByFaction(winner).resources = (Find.WorldObjects.Settlements.Count(x => x.Faction == winner) * SETTLEMENT_RESOURCE_VALUE) + ((int)winner.def.techLevel * TECHLEVEL_RESOURCE_VALUE);
                loser.defeated = true;
                Wars.RemoveAll(war => war.DefenderFaction() == loser || war.AttackerFaction() == loser);
                factionInfo.Remove(GetByFaction(loser));
                return;
            }
        }
        public override void WorldComponentTick()
        {
            if (Find.AnyPlayerHomeMap == null)
            {
                return;
            }
            List <Thing> payment = new List <Thing>();
            string       factionList = "";
            bool         vassalPay = false, TributePay = false;

            foreach (LE_FactionInfo f in Utilities.FactionsWar().factionInfo.Where(i => i.vassalage != 0))
            {
                if (f.vassalage == 2)
                {
                    if (f.faction.PlayerRelationKind == FactionRelationKind.Hostile)
                    {
                        f.vassalage = 0;
                        return;
                    }
                    // Goodwill decay
                    else if (Find.TickManager.TicksGame % (Global.DayInTicks * 7) == 0)
                    {
                        f.faction.TryAffectGoodwillWith(Faction.OfPlayer, RelationsInvestment(f, payment), false, true, "FactionVassalageGoodWillDecay".Translate());
                    }
                    // Investment returns
                    if (GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap) == dayOfMonth)
                    {
                        ArmoryInvestment(f, payment, ref vassalPay);
                        WeaponryInvestment(f, payment, ref vassalPay);
                        RawMaterialsInvestment(f, payment, ref vassalPay);
                        MedicineInvestment(f, payment, ref vassalPay);
                        DruglabsInvestment(f, payment, ref vassalPay);
                        ProstheticslabsInvestment(f, payment, ref vassalPay);
                        FoodInvestment(f, payment, ref vassalPay);
                        ComponentInvestment(f, payment, ref vassalPay);
                        TradeInvestment(f, payment, ref vassalPay);

                        if (vassalPay)
                        {
                            factionList += f.faction + ",";
                        }
                    }
                }

                if (f.vassalage == 1)
                {
                    if (f.faction.PlayerRelationKind == FactionRelationKind.Hostile)
                    {
                        f.vassalage = 0;
                        return;
                    }
                    // Goodwill decay
                    else if (Find.TickManager.TicksGame % (Global.DayInTicks * 7) == 0)
                    {
                        f.faction.TryAffectGoodwillWith(Faction.OfPlayer, -5, false, true, "FactionVassalageGoodWillDecay".Translate());
                    }
                    // Tribute
                    if (GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap) == dayOfMonth)
                    {
                        Thing silver = ThingMaker.MakeThing(ThingDefOf.Silver);
                        silver.stackCount = new IntRange(850 + (f.faction.PlayerGoodwill * 8), 1300 + (f.faction.PlayerGoodwill * 8)).RandomInRange;
                        factionList      += f.faction + ",";
                        TributePay        = true;
                    }
                }
            }
            Payment(payment, vassalPay, TributePay, factionList);
        }
예제 #25
0
        private static void _AppendThoughts_Humanlike(Pawn victim, DamageInfo?dinfo, Hediff hediff, PawnDiedOrDownedThoughtsKind thoughtsKind, List <IndividualThoughtToAdd> outIndividualThoughts, List <ThoughtDef> outAllColonistsThoughts)
        {
            var  IsExecution        = typeof(PawnDiedOrDownedThoughtsUtility).GetMethod("IsExecution", BindingFlags.Static | BindingFlags.NonPublic);
            var  IsInnocentPrisoner = typeof(PawnDiedOrDownedThoughtsUtility).GetMethod("IsInnocentPrisoner", BindingFlags.Static | BindingFlags.NonPublic);
            bool flag  = (bool)IsExecution.Invoke(null, new object[] { dinfo, hediff });
            bool flag2 = (bool)IsInnocentPrisoner.Invoke(null, new object[] { victim });
            bool flag3 = dinfo.HasValue && dinfo.Value.Def.externalViolence && dinfo.Value.Instigator != null && dinfo.Value.Instigator is Pawn;

            if (flag3)
            {
                Pawn pawn = (Pawn)dinfo.Value.Instigator;
                if (!pawn.Dead && pawn.needs.mood != null && pawn.story != null && pawn != victim)
                {
                    if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died)
                    {
                        outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KilledHumanlikeBloodlust, pawn, null, 1f, 1f));
                    }
                    if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died && victim.HostileTo(pawn))
                    {
                        if (victim.Faction != null && PawnUtility.IsFactionLeader(victim) && victim.Faction.HostileTo(pawn.Faction))
                        {
                            outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.DefeatedHostileFactionLeader, pawn, victim, 1f, 1f));
                        }
                        else if (victim.Faction != null && victim.Faction.HostileTo(pawn.Faction) && !flag2)
                        {
                            outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KilledHumanlikeEnemy, pawn, victim, 1f, 1f));
                        }
                        if (victim.kindDef.combatPower > 250f)
                        {
                            outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.DefeatedMajorEnemy, pawn, victim, 1f, 1f));
                        }
                    }
                }
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died && victim.Spawned)
            {
                List <Pawn> allPawnsSpawned = victim.Map.mapPawns.AllPawnsSpawned;
                for (int i = 0; i < allPawnsSpawned.Count; i++)
                {
                    Pawn pawn2 = allPawnsSpawned[i];
                    if (pawn2 != victim && pawn2.needs.mood != null)
                    {
                        if (!flag && (pawn2.MentalStateDef != MentalStateDefOf.SocialFighting || ((MentalState_SocialFighting)pawn2.MentalState).otherPawn != victim))
                        {
                            if (pawn2.Position.InHorDistOf(victim.Position, 12f) && GenSight.LineOfSight(victim.Position, pawn2.Position, victim.Map, false) && pawn2.Awake() && pawn2.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
                            {
                                if (pawn2.Faction == victim.Faction)
                                {
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathAlly, pawn2, null, 1f, 1f));
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.WitnessedDeathAllyBleedingHeart, pawn2, null, 1f, 1f));
                                }
                                else if (victim.Faction == null || (!victim.Faction.HostileTo(pawn2.Faction) || pawn2.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart)))
                                {
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathNonAlly, pawn2, null, 1f, 1f));
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.WitnessedDeathNonAllyBleedingHeart, pawn2, null, 1f, 1f));
                                }
                                if (pawn2.relations.FamilyByBlood.Contains(victim))
                                {
                                    outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathFamily, pawn2, null, 1f, 1f));
                                }
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.WitnessedDeathBloodlust, pawn2, null, 1f, 1f));
                                if (!pawn2.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn2.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn2.story.traits.HasTrait(TraitDefOf.Bloodlust) && !pawn2.story.traits.HasTrait(TraitDefOfPsychology.Desensitized))
                                {
                                    if (((pawn2.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn2) + GenLocalDate.Year(pawn2) + (int)(GenLocalDate.DayPercent(pawn2) * 5) * 60) * 391) % 1000) == 0)
                                    {
                                        pawn2.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized));
                                        pawn2.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.RecentlyDesensitized, null);
                                    }
                                }
                            }
                            else if (victim.Faction == Faction.OfPlayer && victim.Faction == pawn2.Faction && victim.HostFaction != pawn2.Faction)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KnowColonistDied, pawn2, null, 1f, 1f));
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KnowColonistDiedBleedingHeart, pawn2, null, 1f, 1f));
                            }
                            if (flag2 && pawn2.Faction == Faction.OfPlayer && !pawn2.IsPrisoner)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KnowPrisonerDiedInnocent, pawn2, null, 1f, 1f));
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOfPsychology.KnowPrisonerDiedInnocentBleedingHeart, pawn2, null, 1f, 1f));
                            }
                        }
                    }
                }
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Abandoned && victim.IsColonist)
            {
                outAllColonistsThoughts.Add(ThoughtDefOf.ColonistAbandoned);
                outAllColonistsThoughts.Add(ThoughtDefOfPsychology.ColonistAbandonedBleedingHeart);
            }
            if (thoughtsKind == PawnDiedOrDownedThoughtsKind.AbandonedToDie)
            {
                if (victim.IsColonist)
                {
                    outAllColonistsThoughts.Add(ThoughtDefOf.ColonistAbandonedToDie);
                    outAllColonistsThoughts.Add(ThoughtDefOfPsychology.ColonistAbandonedToDieBleedingHeart);
                }
                else if (victim.IsPrisonerOfColony)
                {
                    outAllColonistsThoughts.Add(ThoughtDefOf.PrisonerAbandonedToDie);
                    outAllColonistsThoughts.Add(ThoughtDefOfPsychology.PrisonerAbandonedToDieBleedingHeart);
                }
            }
        }