Esempio n. 1
0
 private void OnDefeat()
 {
     foreach (Thing thing in things)
     {
         thing.SetFaction(null);
         thing.TryGetComp <CompSendSignalOnPawnProximity>()?.Expire();
         CompSendSignalOnCountdown compSendSignalOnCountdown = thing.TryGetComp <CompSendSignalOnCountdown>();
         if (compSendSignalOnCountdown != null)
         {
             compSendSignalOnCountdown.ticksLeft = 0;
         }
         ThingWithComps thingWithComps;
         if ((thingWithComps = (thing as ThingWithComps)) != null)
         {
             thingWithComps.BroadcastCompSignal("MechClusterDefeated");
         }
     }
     lord.Notify_MechClusterDefeated();
     for (int i = 0; i < thingsToNotifyOnDefeat.Count; i++)
     {
         thingsToNotifyOnDefeat[i].Notify_LordDestroyed();
     }
     mechClusterDefeated = true;
     foreach (Pawn item in base.Map.mapPawns.FreeColonistsSpawned)
     {
         item.needs?.mood?.thoughts.memories.TryGainMemory(ThoughtDefOf.DefeatedMechCluster);
     }
     QuestUtility.SendQuestTargetSignals(lord.questTags, "AllEnemiesDefeated");
     Messages.Message("MessageMechClusterDefeated".Translate(), new LookTargets(defSpot, base.Map), MessageTypeDefOf.PositiveEvent);
     SoundDefOf.MechClusterDefeated.PlayOneShotOnCamera(base.Map);
 }
Esempio n. 2
0
 public void ForceLaunch()
 {
     ShipCountdown.InitiateCountdown(this);
     if (base.Spawned)
     {
         QuestUtility.SendQuestTargetSignals(base.Map.Parent.questTags, "LaunchedShip");
     }
 }
Esempio n. 3
0
        public void Notify_LeaderLost()
        {
            Pawn pawn = leader;

            GenerateNewLeader();
            Find.LetterStack.ReceiveLetter("LetterLeaderChangedLabel".Translate(name, LeaderTitle).CapitalizeFirst(), "LetterLeaderChanged".Translate(pawn.Name.ToStringFull, NameColored, leader.Name.ToStringFull, LeaderTitle, pawn.Named("OLDLEADER"), leader.Named("NEWLEADER")).CapitalizeFirst(), LetterDefOf.NeutralEvent, GlobalTargetInfo.Invalid, this);
            QuestUtility.SendQuestTargetSignals(pawn.questTags, "NoLongerFactionLeader", pawn.Named("SUBJECT"), leader.Named("NEWFACTIONLEADER"));
        }
Esempio n. 4
0
 public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
 {
     if (charlonsReactor)
     {
         QuestUtility.SendQuestTargetSignals(base.Map.Parent.questTags, "ReactorDestroyed");
     }
     base.Destroy(mode);
 }
        public void SendLaunchedSignals(List <CompTransporter> transporters)
        {
            string signalPart = (AllRequiredThingsLoaded ? "SentSatisfied" : "SentUnsatisfied");

            for (int i = 0; i < transporters.Count; i++)
            {
                QuestUtility.SendQuestTargetSignals(transporters[i].parent.questTags, signalPart, transporters[i].parent.Named("SUBJECT"), transporters[i].innerContainer.ToList().Named("SENT"));
            }
        }
        public override void Tick()
        {
            if (!this.IsHashIntervalTick(177))
            {
                return;
            }
            bool allDone = AllDone;

            if (!complete && allDone)
            {
                complete = true;
                QuestUtility.SendQuestTargetSignals(questTags, "MonumentCompleted", this.Named("SUBJECT"));
            }
            if (complete && !allDone)
            {
                QuestUtility.SendQuestTargetSignals(questTags, "MonumentDestroyed", this.Named("SUBJECT"));
                if (!base.Destroyed)
                {
                    Destroy();
                }
            }
            else
            {
                if (!allDone)
                {
                    return;
                }
                if (AnyDisallowedBuilding)
                {
                    ticksSinceDisallowedBuilding += 177;
                    if (DisallowedBuildingTicksExpired)
                    {
                        Messages.Message("MessageMonumentDestroyedBecauseOfDisallowedBuilding".Translate(), new TargetInfo(base.Position, base.Map), MessageTypeDefOf.NegativeEvent);
                        QuestUtility.SendQuestTargetSignals(questTags, "MonumentDestroyed", this.Named("SUBJECT"));
                        if (!base.Destroyed)
                        {
                            Destroy();
                        }
                    }
                }
                else
                {
                    ticksSinceDisallowedBuilding = 0;
                }
            }
        }
Esempio n. 7
0
 public void Kidnap(Pawn pawn, Pawn kidnapper)
 {
     if (kidnappedPawns.Contains(pawn))
     {
         Log.Error("Tried to kidnap already kidnapped pawn " + pawn);
         return;
     }
     if (pawn.Faction == faction)
     {
         Log.Error("Tried to kidnap pawn with the same faction: " + pawn);
         return;
     }
     pawn.PreKidnapped(kidnapper);
     if (pawn.Spawned)
     {
         pawn.DeSpawn();
     }
     kidnappedPawns.Add(pawn);
     if (!Find.WorldPawns.Contains(pawn))
     {
         Find.WorldPawns.PassToWorld(pawn);
         if (!Find.WorldPawns.Contains(pawn))
         {
             Log.Error("WorldPawns discarded kidnapped pawn.");
             kidnappedPawns.Remove(pawn);
         }
     }
     if (pawn.Faction == Faction.OfPlayer)
     {
         PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(pawn, null, PawnDiedOrDownedThoughtsKind.Lost);
         BillUtility.Notify_ColonistUnavailable(pawn);
         if (kidnapper != null)
         {
             Find.LetterStack.ReceiveLetter("LetterLabelPawnsKidnapped".Translate(pawn.Named("PAWN")), "LetterPawnsKidnapped".Translate(pawn.Named("PAWN"), kidnapper.Faction.Named("FACTION")), LetterDefOf.NegativeEvent);
         }
     }
     QuestUtility.SendQuestTargetSignals(pawn.questTags, "Kidnapped", this.Named("SUBJECT"), kidnapper.Named("KIDNAPPER"));
     Find.GameEnder.CheckOrUpdateGameOver();
 }
Esempio n. 8
0
 private void OnPostTitleChanged(Faction faction, RoyalTitleDef newTitle)
 {
     pawn.Notify_DisabledWorkTypesChanged();
     pawn.needs?.AddOrRemoveNeedsAsAppropriate();
     if (newTitle != null)
     {
         if (newTitle.disabledJoyKinds != null && pawn.jobs != null && RoyalTitleUtility.ShouldBecomeConceitedOnNewTitle(pawn))
         {
             foreach (JoyKindDef disabledJoyKind in newTitle.disabledJoyKinds)
             {
                 pawn.jobs.Notify_JoyKindDisabled(disabledJoyKind);
             }
         }
         for (int i = 0; i < newTitle.grantedAbilities.Count; i++)
         {
             pawn.abilities.GainAbility(newTitle.grantedAbilities[i]);
         }
         UpdateHighestTitleAchieved(faction, newTitle);
     }
     QuestUtility.SendQuestTargetSignals(pawn.questTags, "TitleChanged", pawn.Named("SUBJECT"));
     MeditationFocusTypeAvailabilityCache.ClearFor(pawn);
 }
Esempio n. 9
0
 public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
 {
     if (!questTags.NullOrEmpty())
     {
         bool         flag = false;
         List <Thing> list = base.Map.listerThings.ThingsOfDef(def);
         for (int i = 0; i < list.Count; i++)
         {
             Hive hive;
             if ((hive = (list[i] as Hive)) != null && hive != this && hive.CompDormant.Awake && !hive.questTags.NullOrEmpty() && QuestUtility.AnyMatchingTags(hive.questTags, questTags))
             {
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             QuestUtility.SendQuestTargetSignals(questTags, "AllHivesDestroyed");
         }
     }
     base.Destroy(mode);
 }
Esempio n. 10
0
		public static void DoRecruit(Pawn recruiter, Pawn recruitee, float recruitChance, out string letterLabel, out string letter, bool useAudiovisualEffects = true, bool sendLetter = true)
		{
			letterLabel = null;
			letter = null;
			recruitChance = Mathf.Clamp01(recruitChance);
			string value = recruitee.LabelIndefinite();
			if (recruitee.apparel != null && recruitee.apparel.LockedApparel != null)
			{
				List<Apparel> lockedApparel = recruitee.apparel.LockedApparel;
				for (int num = lockedApparel.Count - 1; num >= 0; num--)
				{
					recruitee.apparel.Unlock(lockedApparel[num]);
				}
			}
			if (recruitee.royalty != null)
			{
				foreach (RoyalTitle item in recruitee.royalty.AllTitlesForReading)
				{
					if (item.def.replaceOnRecruited != null)
					{
						recruitee.royalty.SetTitle(item.faction, item.def.replaceOnRecruited, grantRewards: false, rewardsOnlyForNewestTitle: false, sendLetter: false);
					}
				}
			}
			if (recruitee.guest != null)
			{
				recruitee.guest.SetGuestStatus(null);
			}
			bool flag = recruitee.Name != null;
			if (recruitee.Faction != recruiter.Faction)
			{
				recruitee.SetFaction(recruiter.Faction, recruiter);
			}
			if (recruitee.RaceProps.Humanlike)
			{
				if (useAudiovisualEffects)
				{
					letterLabel = "LetterLabelMessageRecruitSuccess".Translate() + ": " + recruitee.LabelShortCap;
					if (sendLetter)
					{
						Find.LetterStack.ReceiveLetter(letterLabel, "MessageRecruitSuccess".Translate(recruiter, recruitee, recruitChance.ToStringPercent(), recruiter.Named("RECRUITER"), recruitee.Named("RECRUITEE")), LetterDefOf.PositiveEvent, recruitee);
					}
				}
				TaleRecorder.RecordTale(TaleDefOf.Recruited, recruiter, recruitee);
				recruiter.records.Increment(RecordDefOf.PrisonersRecruited);
				if (recruitee.needs.mood != null)
				{
					recruitee.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.RecruitedMe, recruiter);
				}
				QuestUtility.SendQuestTargetSignals(recruitee.questTags, "Recruited", recruitee.Named("SUBJECT"));
			}
			else
			{
				if (useAudiovisualEffects)
				{
					if (!flag)
					{
						Messages.Message("MessageTameAndNameSuccess".Translate(recruiter.LabelShort, value, recruitChance.ToStringPercent(), recruitee.Name.ToStringFull, recruiter.Named("RECRUITER"), recruitee.Named("RECRUITEE")).AdjustedFor(recruitee), recruitee, MessageTypeDefOf.PositiveEvent);
					}
					else
					{
						Messages.Message("MessageTameSuccess".Translate(recruiter.LabelShort, value, recruitChance.ToStringPercent(), recruiter.Named("RECRUITER")), recruitee, MessageTypeDefOf.PositiveEvent);
					}
					if (recruiter.Spawned && recruitee.Spawned)
					{
						MoteMaker.ThrowText((recruiter.DrawPos + recruitee.DrawPos) / 2f, recruiter.Map, "TextMote_TameSuccess".Translate(recruitChance.ToStringPercent()), 8f);
					}
				}
				recruiter.records.Increment(RecordDefOf.AnimalsTamed);
				RelationsUtility.TryDevelopBondRelation(recruiter, recruitee, 0.01f);
				if (Rand.Chance(Mathf.Lerp(0.02f, 1f, recruitee.RaceProps.wildness)) || recruitee.IsWildMan())
				{
					TaleRecorder.RecordTale(TaleDefOf.TamedAnimal, recruiter, recruitee);
				}
				if (PawnsFinder.AllMapsWorldAndTemporary_Alive.Count((Pawn p) => p.playerSettings != null && p.playerSettings.Master == recruiter) >= 5)
				{
					TaleRecorder.RecordTale(TaleDefOf.IncreasedMenagerie, recruiter, recruitee);
				}
			}
			if (recruitee.caller != null)
			{
				recruitee.caller.DoCall();
			}
		}
        public override StateGraph CreateGraph()
        {
            StateGraph stateGraph = new StateGraph();

            if (!ModLister.RoyaltyInstalled)
            {
                Log.ErrorOnce("Bestowing ceremony is a Royalty-specific game system. If you want to use this code please check ModLister.RoyaltyInstalled before calling it. See rules on the Ludeon forum for more info.", 3454535);
                return(stateGraph);
            }
            LordToil_Wait lordToil_Wait = new LordToil_Wait();

            stateGraph.AddToil(lordToil_Wait);
            LordToil_Wait lordToil_Wait2 = new LordToil_Wait();

            stateGraph.AddToil(lordToil_Wait2);
            LordToil_Wait lordToil_Wait3 = new LordToil_Wait();

            stateGraph.AddToil(lordToil_Wait3);
            LordToil_BestowingCeremony_MoveInPlace lordToil_BestowingCeremony_MoveInPlace = new LordToil_BestowingCeremony_MoveInPlace(spotCell, target);

            stateGraph.AddToil(lordToil_BestowingCeremony_MoveInPlace);
            LordToil_BestowingCeremony_Wait lordToil_BestowingCeremony_Wait = new LordToil_BestowingCeremony_Wait(target);

            stateGraph.AddToil(lordToil_BestowingCeremony_Wait);
            exitToil = ((shuttle == null) ? ((LordToil) new LordToil_ExitMap(LocomotionUrgency.Walk)) : ((LordToil) new LordToil_EnterShuttleOrLeave(shuttle, LocomotionUrgency.Walk, canDig: true, interruptCurrentJob: true)));
            stateGraph.AddToil(exitToil);
            Transition transition = new Transition(lordToil_Wait, lordToil_Wait2);

            transition.AddTrigger(new Trigger_Custom((TriggerSignal signal) => signal.type == TriggerSignalType.Tick && bestower.Spawned));
            stateGraph.AddTransition(transition);
            Transition transition2 = new Transition(lordToil_Wait2, lordToil_BestowingCeremony_MoveInPlace);

            transition2.AddTrigger(new Trigger_TicksPassed(600));
            stateGraph.AddTransition(transition2);
            Transition transition3 = new Transition(lordToil_BestowingCeremony_MoveInPlace, lordToil_BestowingCeremony_Wait);

            transition3.AddTrigger(new Trigger_Custom((TriggerSignal signal) => signal.type == TriggerSignalType.Tick && bestower.Position == spotCell));
            stateGraph.AddTransition(transition3);
            Transition transition4 = new Transition(lordToil_BestowingCeremony_Wait, exitToil);

            transition4.AddTrigger(new Trigger_TicksPassed(30000));
            transition4.AddPostAction(new TransitionAction_Custom((Action) delegate
            {
                QuestUtility.SendQuestTargetSignals(lord.questTags, "CeremonyExpired", lord.Named("SUBJECT"));
            }));
            stateGraph.AddTransition(transition4);
            Transition transition5 = new Transition(lordToil_BestowingCeremony_Wait, lordToil_Wait3);

            transition5.AddTrigger(new Trigger_Memo("CeremonyFinished"));
            transition5.AddPostAction(new TransitionAction_Custom((Action) delegate
            {
                QuestUtility.SendQuestTargetSignals(lord.questTags, "CeremonyDone", lord.Named("SUBJECT"));
            }));
            stateGraph.AddTransition(transition5);
            Transition transition6 = new Transition(lordToil_Wait3, exitToil);

            transition6.AddTrigger(new Trigger_TicksPassed(600));
            stateGraph.AddTransition(transition6);
            Transition transition7 = new Transition(lordToil_BestowingCeremony_MoveInPlace, exitToil);

            transition7.AddSource(lordToil_BestowingCeremony_Wait);
            transition7.AddTrigger(new Trigger_BecamePlayerEnemy());
            stateGraph.AddTransition(transition7);
            Transition transition8 = new Transition(lordToil_BestowingCeremony_MoveInPlace, exitToil);

            transition8.AddSource(lordToil_BestowingCeremony_Wait);
            transition8.AddTrigger(new Trigger_Custom((TriggerSignal signal) => signal.type == TriggerSignalType.Tick && bestower.Spawned && !bestower.CanReach(spotCell, PathEndMode.OnCell, Danger.Deadly)));
            transition8.AddPostAction(new TransitionAction_Custom((Action) delegate
            {
                Messages.Message("MessageBestowingSpotUnreachable".Translate(), bestower, MessageTypeDefOf.NegativeEvent);
                QuestUtility.SendQuestTargetSignals(lord.questTags, "CeremonyFailed", lord.Named("SUBJECT"));
            }));
            stateGraph.AddTransition(transition8);
            if (!questEndedSignal.NullOrEmpty())
            {
                Transition transition9 = new Transition(lordToil_BestowingCeremony_MoveInPlace, exitToil);
                transition9.AddSource(lordToil_BestowingCeremony_Wait);
                transition9.AddSource(lordToil_Wait);
                transition9.AddSource(lordToil_Wait2);
                transition9.AddTrigger(new Trigger_Signal(questEndedSignal));
                stateGraph.AddTransition(transition9);
            }
            return(stateGraph);
        }
 public void MakeCeremonyFail()
 {
     QuestUtility.SendQuestTargetSignals(lord.questTags, "CeremonyFailed", lord.Named("SUBJECT"));
 }
Esempio n. 13
0
        public void SetGuestStatus(Faction newHost, bool prisoner = false)
        {
            if (newHost != null)
            {
                Released = false;
            }
            if (newHost == HostFaction && prisoner == IsPrisoner)
            {
                return;
            }
            if (!prisoner && pawn.Faction.HostileTo(newHost))
            {
                Log.Error("Tried to make " + pawn + " a guest of " + newHost + " but their faction " + pawn.Faction + " is hostile to " + newHost);
                return;
            }
            if (newHost != null && newHost == pawn.Faction && !prisoner)
            {
                Log.Error("Tried to make " + pawn + " a guest of their own faction " + pawn.Faction);
                return;
            }
            bool num = prisoner && (!IsPrisoner || HostFaction != newHost);

            isPrisonerInt = prisoner;
            Faction faction = hostFactionInt;

            hostFactionInt = newHost;
            Pawn obj = pawn;
            bool clearMentalState = prisoner;

            obj.ClearMind(newHost != null, clearInspiration: false, clearMentalState);
            if (num)
            {
                pawn.DropAndForbidEverything();
                pawn.GetLord()?.Notify_PawnLost(pawn, PawnLostCondition.MadePrisoner);
                if (pawn.Drafted)
                {
                    pawn.drafter.Drafted = false;
                }
                float x = pawn.RecruitDifficulty(Faction.OfPlayer);
                resistance  = StartingResistancePerRecruitDifficultyCurve.Evaluate(x);
                resistance *= StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent);
                resistance *= StartingResistanceRandomFactorRange.RandomInRange;
                if (pawn.royalty != null)
                {
                    RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                    if (mostSeniorTitle != null)
                    {
                        resistance *= mostSeniorTitle.def.recruitmentResistanceFactor;
                        resistance += mostSeniorTitle.def.recruitmentResistanceOffset;
                    }
                }
                resistance = GenMath.RoundRandom(resistance);
            }
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
            pawn.health.surgeryBills.Clear();
            if (pawn.ownership != null)
            {
                pawn.ownership.Notify_ChangedGuestStatus();
            }
            ReachabilityUtility.ClearCacheFor(pawn);
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.UpdateRegistryForPawn(pawn);
                pawn.Map.attackTargetsCache.UpdateTarget(pawn);
            }
            AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn);
            if (prisoner && pawn.playerSettings != null)
            {
                pawn.playerSettings.Notify_MadePrisoner();
            }
            if (faction != hostFactionInt)
            {
                QuestUtility.SendQuestTargetSignals(pawn.questTags, "ChangedHostFaction", pawn.Named("SUBJECT"), hostFactionInt.Named("FACTION"));
            }
        }
Esempio n. 14
0
 public void Send()
 {
     if (!ModLister.RoyaltyInstalled)
     {
         Log.ErrorOnce("Shuttle is a Royalty-specific game system. If you want to use this code please check ModLister.RoyaltyInstalled before calling it. See rules on the Ludeon forum for more info.", 8811221);
     }
     else
     {
         if (sending)
         {
             return;
         }
         if (!parent.Spawned)
         {
             Log.Error("Tried to send " + parent + ", but it's unspawned.");
             return;
         }
         List <CompTransporter> transportersInGroup = TransportersInGroup;
         if (transportersInGroup == null)
         {
             Log.Error("Tried to send " + parent + ", but it's not in any group.");
         }
         else
         {
             if (!LoadingInProgressOrReadyToLaunch)
             {
                 return;
             }
             if (!AllRequiredThingsLoaded)
             {
                 if (dropEverythingIfUnsatisfied)
                 {
                     Transporter.CancelLoad();
                 }
                 else if (dropNonRequiredIfUnsatisfied)
                 {
                     for (int i = 0; i < transportersInGroup.Count; i++)
                     {
                         for (int num = transportersInGroup[i].innerContainer.Count - 1; num >= 0; num--)
                         {
                             Thing thing = transportersInGroup[i].innerContainer[num];
                             Pawn  pawn;
                             if (!IsRequired(thing) && (requiredColonistCount <= 0 || (pawn = (thing as Pawn)) == null || !pawn.IsColonist))
                             {
                                 transportersInGroup[i].innerContainer.TryDrop(thing, ThingPlaceMode.Near, out Thing _);
                             }
                         }
                     }
                 }
             }
             sending = true;
             bool allRequiredThingsLoaded = AllRequiredThingsLoaded;
             Map  map = parent.Map;
             Transporter.TryRemoveLord(map);
             string signalPart = allRequiredThingsLoaded ? "SentSatisfied" : "SentUnsatisfied";
             for (int j = 0; j < transportersInGroup.Count; j++)
             {
                 QuestUtility.SendQuestTargetSignals(transportersInGroup[j].parent.questTags, signalPart, transportersInGroup[j].parent.Named("SUBJECT"), transportersInGroup[j].innerContainer.ToList().Named("SENT"));
             }
             List <Pawn> list = new List <Pawn>();
             for (int k = 0; k < transportersInGroup.Count; k++)
             {
                 CompTransporter compTransporter = transportersInGroup[k];
                 for (int num2 = transportersInGroup[k].innerContainer.Count - 1; num2 >= 0; num2--)
                 {
                     Pawn pawn2 = transportersInGroup[k].innerContainer[num2] as Pawn;
                     if (pawn2 != null)
                     {
                         if (pawn2.IsColonist && !requiredPawns.Contains(pawn2))
                         {
                             list.Add(pawn2);
                         }
                         pawn2.ExitMap(allowedToJoinOrCreateCaravan: false, Rot4.Invalid);
                     }
                 }
                 compTransporter.innerContainer.ClearAndDestroyContentsOrPassToWorld();
                 Thing newThing = ThingMaker.MakeThing(ThingDefOf.ShuttleLeaving);
                 compTransporter.CleanUpLoadingVars(map);
                 compTransporter.parent.Destroy(DestroyMode.QuestLogic);
                 GenSpawn.Spawn(newThing, compTransporter.parent.Position, map);
             }
             if (list.Count != 0)
             {
                 for (int l = 0; l < transportersInGroup.Count; l++)
                 {
                     QuestUtility.SendQuestTargetSignals(transportersInGroup[l].parent.questTags, "SentWithExtraColonists", transportersInGroup[l].parent.Named("SUBJECT"), list.Named("SENTCOLONISTS"));
                 }
             }
             sending = false;
         }
     }
 }
Esempio n. 15
0
        public void Notify_RelationKindChanged(Faction other, FactionRelationKind previousKind, bool canSendLetter, string reason, GlobalTargetInfo lookTarget, out bool sentLetter)
        {
            if (Current.ProgramState != ProgramState.Playing || other != OfPlayer)
            {
                canSendLetter = false;
            }
            sentLetter = false;
            ColoredText.ClearCache();
            FactionRelationKind factionRelationKind = RelationKindWith(other);

            if (factionRelationKind == FactionRelationKind.Hostile)
            {
                if (Current.ProgramState == ProgramState.Playing)
                {
                    foreach (Pawn item in PawnsFinder.AllMapsWorldAndTemporary_Alive.ToList())
                    {
                        if ((item.Faction == this && item.HostFaction == other) || (item.Faction == other && item.HostFaction == this))
                        {
                            item.guest.SetGuestStatus(item.HostFaction, prisoner: true);
                        }
                    }
                }
                if (other == OfPlayer)
                {
                    QuestUtility.SendQuestTargetSignals(questTags, "BecameHostileToPlayer", this.Named("SUBJECT"));
                }
            }
            if (other == OfPlayer && !this.HostileTo(OfPlayer))
            {
                List <Site> list  = new List <Site>();
                List <Site> sites = Find.WorldObjects.Sites;
                for (int i = 0; i < sites.Count; i++)
                {
                    if (sites[i].factionMustRemainHostile && sites[i].Faction == this && !sites[i].HasMap)
                    {
                        list.Add(sites[i]);
                    }
                }
                if (list.Any())
                {
                    string str;
                    string str2;
                    if (list.Count == 1)
                    {
                        str  = "LetterLabelSiteNoLongerHostile".Translate();
                        str2 = "LetterSiteNoLongerHostile".Translate(NameColored, list[0].Label);
                    }
                    else
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int j = 0; j < list.Count; j++)
                        {
                            if (stringBuilder.Length != 0)
                            {
                                stringBuilder.AppendLine();
                            }
                            stringBuilder.Append("  - " + list[j].LabelCap);
                            ImportantPawnComp component = list[j].GetComponent <ImportantPawnComp>();
                            if (component != null && component.pawn.Any)
                            {
                                stringBuilder.Append(" (" + component.pawn[0].LabelCap + ")");
                            }
                        }
                        str  = "LetterLabelSiteNoLongerHostileMulti".Translate();
                        str2 = (string)("LetterSiteNoLongerHostileMulti".Translate(NameColored) + ":\n\n") + stringBuilder;
                    }
                    Find.LetterStack.ReceiveLetter(str, str2, LetterDefOf.NeutralEvent, new LookTargets(list.Select((Site x) => new GlobalTargetInfo(x.Tile))));
                    for (int k = 0; k < list.Count; k++)
                    {
                        list[k].Destroy();
                    }
                }
            }
            if (other == OfPlayer && this.HostileTo(OfPlayer))
            {
                List <WorldObject> allWorldObjects = Find.WorldObjects.AllWorldObjects;
                for (int l = 0; l < allWorldObjects.Count; l++)
                {
                    if (allWorldObjects[l].Faction == this)
                    {
                        TradeRequestComp component2 = allWorldObjects[l].GetComponent <TradeRequestComp>();
                        if (component2 != null && component2.ActiveRequest)
                        {
                            component2.Disable();
                        }
                    }
                }
                foreach (Map map in Find.Maps)
                {
                    map.passingShipManager.RemoveAllShipsOfFaction(this);
                }
            }
            if (canSendLetter)
            {
                TaggedString text = "";
                TryAppendRelationKindChangedInfo(ref text, previousKind, factionRelationKind, reason);
                switch (factionRelationKind)
                {
                case FactionRelationKind.Hostile:
                    Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_Hostile".Translate(Name), text, LetterDefOf.NegativeEvent, lookTarget, this);
                    sentLetter = true;
                    break;

                case FactionRelationKind.Ally:
                    Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_Ally".Translate(Name), text, LetterDefOf.PositiveEvent, lookTarget, this);
                    sentLetter = true;
                    break;

                case FactionRelationKind.Neutral:
                    if (previousKind == FactionRelationKind.Hostile)
                    {
                        Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_NeutralFromHostile".Translate(Name), text, LetterDefOf.PositiveEvent, lookTarget, this);
                        sentLetter = true;
                    }
                    else
                    {
                        Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_NeutralFromAlly".Translate(Name), text, LetterDefOf.NeutralEvent, lookTarget, this);
                        sentLetter = true;
                    }
                    break;
                }
            }
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }
            List <Map> maps = Find.Maps;

            for (int m = 0; m < maps.Count; m++)
            {
                maps[m].attackTargetsCache.Notify_FactionHostilityChanged(this, other);
                LordManager lordManager = maps[m].lordManager;
                for (int n = 0; n < lordManager.lords.Count; n++)
                {
                    Lord lord = lordManager.lords[n];
                    if (lord.faction == other)
                    {
                        lord.Notify_FactionRelationsChanged(this, previousKind);
                    }
                    else if (lord.faction == this)
                    {
                        lord.Notify_FactionRelationsChanged(other, previousKind);
                    }
                }
            }
        }
Esempio n. 16
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo gizmo in base.GetGizmos())
            {
                yield return(gizmo);
            }
            if (!AllDone)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandCancelMonumentMarker".Translate();
                command_Action.defaultDesc  = "CommandCancelMonumentMarkerDesc".Translate();
                command_Action.icon         = CancelCommandTex;
                command_Action.action       = delegate
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmCancelMonumentMarker".Translate(), delegate
                    {
                        QuestUtility.SendQuestTargetSignals(questTags, "MonumentCancelled", this.Named("SUBJECT"));
                        RemovePossiblyRelatedBlueprints();
                        this.Uninstall();
                    }, destructive: true));
                };
                yield return(command_Action);
            }
            bool flag = false;

            foreach (SketchEntity entity in sketch.Entities)
            {
                SketchBuildable sketchBuildable = entity as SketchBuildable;
                if (sketchBuildable != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null)
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                Command_Action command_Action2 = new Command_Action();
                command_Action2.defaultLabel = "CommandPlaceBlueprints".Translate();
                command_Action2.defaultDesc  = "CommandPlaceBlueprintsDesc".Translate();
                command_Action2.icon         = PlaceBlueprintsCommandTex;
                MonumentMarker monumentMarker = default(MonumentMarker);
                ThingDef       stuffLocal     = default(ThingDef);
                command_Action2.action = delegate
                {
                    IEnumerable <ThingDef> enumerable = AllowedStuffs();
                    if (!enumerable.Any())
                    {
                        PlaceAllBlueprints(null);
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else if (enumerable.Count() == 1)
                    {
                        PlaceAllBlueprints(enumerable.First());
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else
                    {
                        List <FloatMenuOption> list = new List <FloatMenuOption>();
                        bool flag4 = false;
                        foreach (ThingDef item in enumerable)
                        {
                            if (base.Map.listerThings.ThingsOfDef(item).Count > 0)
                            {
                                flag4 = true;
                                break;
                            }
                        }
                        foreach (ThingDef item2 in enumerable)
                        {
                            monumentMarker = this;
                            if (!flag4 || base.Map.listerThings.ThingsOfDef(item2).Count != 0)
                            {
                                stuffLocal = item2;
                                list.Add(new FloatMenuOption(stuffLocal.LabelCap, delegate
                                {
                                    monumentMarker.PlaceAllBlueprints(stuffLocal);
                                }, item2));
                            }
                        }
                        Find.WindowStack.Add(new FloatMenu(list));
                    }
                };
                yield return(command_Action2);
            }
            foreach (Gizmo questRelatedGizmo in QuestUtility.GetQuestRelatedGizmos(this))
            {
                yield return(questRelatedGizmo);
            }
            if (Prefs.DevMode)
            {
                bool flag2 = false;
                foreach (SketchEntity entity2 in sketch.Entities)
                {
                    if (!entity2.IsSameSpawned(entity2.pos + base.Position, base.Map) && !entity2.IsSpawningBlocked(entity2.pos + base.Position, base.Map))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (flag2)
                {
                    Command_Action command_Action3 = new Command_Action();
                    command_Action3.defaultLabel = "Dev: Build all";
                    command_Action3.action       = delegate
                    {
                        DebugBuildAll();
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    };
                    yield return(command_Action3);
                }
            }
            tmpUniqueBuildableDefs.Clear();
            foreach (SketchEntity entity3 in sketch.Entities)
            {
                SketchBuildable sketchBuildable2 = entity3 as SketchBuildable;
                if (sketchBuildable2 != null && !entity3.IsSameSpawnedOrBlueprintOrFrame(entity3.pos + base.Position, base.Map) && tmpUniqueBuildableDefs.Add(new Pair <BuildableDef, ThingDef>(sketchBuildable2.Buildable, sketchBuildable2.Stuff)))
                {
                    SketchTerrain sketchTerrain;
                    if ((sketchTerrain = (sketchBuildable2 as SketchTerrain)) != null && sketchTerrain.treatSimilarAsSame)
                    {
                        TerrainDef terrain = sketchBuildable2.Buildable as TerrainDef;
                        if (terrain.designatorDropdown != null)
                        {
                            Designator designator = BuildCopyCommandUtility.FindAllowedDesignatorRoot(sketchBuildable2.Buildable);
                            if (designator != null)
                            {
                                yield return(designator);
                            }
                        }
                        else
                        {
                            IEnumerable <TerrainDef> allDefs = DefDatabase <TerrainDef> .AllDefs;
                            foreach (TerrainDef item3 in allDefs)
                            {
                                if (item3.BuildableByPlayer && item3.designatorDropdown == null)
                                {
                                    bool flag3 = true;
                                    for (int i = 0; i < terrain.affordances.Count; i++)
                                    {
                                        if (!item3.affordances.Contains(terrain.affordances[i]))
                                        {
                                            flag3 = false;
                                            break;
                                        }
                                    }
                                    if (flag3)
                                    {
                                        Command command = BuildCopyCommandUtility.BuildCommand(item3, null, item3.label, item3.description, allowHotKey: false);
                                        if (command != null)
                                        {
                                            yield return(command);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Command command2 = BuildCopyCommandUtility.BuildCommand(sketchBuildable2.Buildable, sketchBuildable2.Stuff, entity3.Label, sketchBuildable2.Buildable.description, allowHotKey: false);
                        if (command2 != null)
                        {
                            yield return(command2);
                        }
                    }
                }
            }
            tmpUniqueBuildableDefs.Clear();
        }
Esempio n. 17
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnAggroMentalStateAndHostile(TargetIndex.A);
            this.FailOn(delegate
            {
                if (job.def.makeTargetPrisoner)
                {
                    if (!DropBed.ForPrisoners)
                    {
                        return(true);
                    }
                }
                else if (DropBed.ForPrisoners != Takee.IsPrisoner)
                {
                    return(true);
                }
                return(false);
            });
            yield return(Toils_Bed.ClaimBedIfNonMedical(TargetIndex.B, TargetIndex.A));

            AddFinishAction(delegate
            {
                if (job.def.makeTargetPrisoner && Takee.ownership.OwnedBed == DropBed && Takee.Position != RestUtility.GetBedSleepingSlotPosFor(Takee, DropBed))
                {
                    Takee.ownership.UnclaimBed();
                }
            });
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.B)
                         .FailOn(() => job.def == JobDefOf.Arrest && !Takee.CanBeArrestedBy(pawn))
                         .FailOn(() => !pawn.CanReach(DropBed, PathEndMode.OnCell, Danger.Deadly))
                         .FailOn(() => (job.def == JobDefOf.Rescue || job.def == JobDefOf.Capture) && !Takee.Downed)
                         .FailOnSomeonePhysicallyInteracting(TargetIndex.A));

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                if (job.def.makeTargetPrisoner)
                {
                    Pawn pawn = (Pawn)job.targetA.Thing;
                    pawn.GetLord()?.Notify_PawnAttemptArrested(pawn);
                    GenClamor.DoClamor(pawn, 10f, ClamorDefOf.Harm);
                    if (job.def == JobDefOf.Arrest && !pawn.CheckAcceptArrest(base.pawn))
                    {
                        base.pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                    }
                    if (!pawn.IsPrisoner)
                    {
                        QuestUtility.SendQuestTargetSignals(pawn.questTags, "Arrested", pawn.Named("SUBJECT"));
                    }
                }
            };
            yield return(toil);

            Toil toil2 = Toils_Haul.StartCarryThing(TargetIndex.A).FailOnNonMedicalBedNotOwned(TargetIndex.B, TargetIndex.A);

            toil2.AddPreInitAction(CheckMakeTakeeGuest);
            yield return(toil2);

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch));

            Toil toil3 = new Toil();

            toil3.initAction = delegate
            {
                CheckMakeTakeePrisoner();
                if (Takee.playerSettings == null)
                {
                    Takee.playerSettings = new Pawn_PlayerSettings(Takee);
                }
            };
            yield return(toil3);

            yield return(Toils_Reserve.Release(TargetIndex.B));

            Toil toil4 = new Toil();

            toil4.initAction = delegate
            {
                IntVec3 position = DropBed.Position;
                pawn.carryTracker.TryDropCarriedThing(position, ThingPlaceMode.Direct, out Thing _);
                if (!DropBed.Destroyed && (DropBed.OwnersForReading.Contains(Takee) || (DropBed.Medical && DropBed.AnyUnoccupiedSleepingSlot) || Takee.ownership == null))
                {
                    Takee.jobs.Notify_TuckedIntoBed(DropBed);
                    if (Takee.RaceProps.Humanlike && job.def != JobDefOf.Arrest && !Takee.IsPrisonerOfColony)
                    {
                        Takee.relations.Notify_RescuedBy(pawn);
                    }
                    Takee.mindState.Notify_TuckedIntoBed();
                }
                if (Takee.IsPrisonerOfColony)
                {
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.PrisonerTab, Takee, OpportunityType.GoodToKnow);
                }
            };
            toil4.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil4);
        }
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo gizmo in base.GetGizmos())
            {
                yield return(gizmo);
            }
            if (!AllDone)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandCancelMonumentMarker".Translate();
                command_Action.defaultDesc  = "CommandCancelMonumentMarkerDesc".Translate();
                command_Action.icon         = CancelCommandTex;
                command_Action.action       = delegate
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmCancelMonumentMarker".Translate(), delegate
                    {
                        QuestUtility.SendQuestTargetSignals(questTags, "MonumentCancelled", this.Named("SUBJECT"));
                        RemovePossiblyRelatedBlueprints();
                        this.Uninstall();
                    }, destructive: true));
                };
                yield return(command_Action);
            }
            bool flag = false;

            foreach (SketchEntity entity in sketch.Entities)
            {
                SketchBuildable sketchBuildable = entity as SketchBuildable;
                if (sketchBuildable != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null)
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                Command_Action command_Action2 = new Command_Action();
                command_Action2.defaultLabel = "CommandPlaceBlueprints".Translate();
                command_Action2.defaultDesc  = "CommandPlaceBlueprintsDesc".Translate();
                command_Action2.icon         = PlaceBlueprintsCommandTex;
                command_Action2.action       = delegate
                {
                    IEnumerable <ThingDef> enumerable = AllowedStuffs();
                    if (!enumerable.Any())
                    {
                        PlaceAllBlueprints(null);
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else if (enumerable.Count() == 1)
                    {
                        PlaceAllBlueprints(enumerable.First());
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else
                    {
                        ListFloatMenuOptions(enumerable, delegate(ThingDef stuff)
                        {
                            PlaceAllBlueprints(stuff);
                        });
                    }
                };
                yield return(command_Action2);
            }
            foreach (Gizmo questRelatedGizmo in QuestUtility.GetQuestRelatedGizmos(this))
            {
                yield return(questRelatedGizmo);
            }
            if (Prefs.DevMode)
            {
                bool flag2 = false;
                foreach (SketchEntity entity2 in sketch.Entities)
                {
                    if (!entity2.IsSameSpawned(entity2.pos + base.Position, base.Map) && !entity2.IsSpawningBlocked(entity2.pos + base.Position, base.Map))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (flag2)
                {
                    Command_Action command_Action3 = new Command_Action();
                    command_Action3.defaultLabel = "Dev: Build all";
                    command_Action3.action       = delegate
                    {
                        DebugBuildAll();
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    };
                    yield return(command_Action3);
                }
                if (AllDone && AnyDisallowedBuilding && !DisallowedBuildingTicksExpired)
                {
                    Command_Action command_Action4 = new Command_Action();
                    command_Action4.defaultLabel = "Dev: Disallowed building ticks +6 hours";
                    command_Action4.action       = delegate
                    {
                        ticksSinceDisallowedBuilding += 15000;
                    };
                    yield return(command_Action4);
                }
            }
            tmpUniqueBuildableDefs.Clear();
            foreach (SketchEntity entity3 in sketch.Entities)
            {
                SketchBuildable buildable = entity3 as SketchBuildable;
                if (buildable == null || entity3.IsSameSpawnedOrBlueprintOrFrame(entity3.pos + base.Position, base.Map) || !tmpUniqueBuildableDefs.Add(new Pair <BuildableDef, ThingDef>(buildable.Buildable, buildable.Stuff)))
                {
                    continue;
                }
                SketchTerrain sketchTerrain;
                if ((sketchTerrain = buildable as SketchTerrain) != null && sketchTerrain.treatSimilarAsSame)
                {
                    TerrainDef terrain = buildable.Buildable as TerrainDef;
                    if (terrain.designatorDropdown != null)
                    {
                        Designator designator = BuildCopyCommandUtility.FindAllowedDesignatorRoot(buildable.Buildable);
                        if (designator != null)
                        {
                            yield return(designator);
                        }
                    }
                    else
                    {
                        IEnumerable <TerrainDef> allDefs = DefDatabase <TerrainDef> .AllDefs;
                        foreach (TerrainDef item in allDefs)
                        {
                            if (!item.BuildableByPlayer || item.designatorDropdown != null)
                            {
                                continue;
                            }
                            bool flag3 = true;
                            for (int i = 0; i < terrain.affordances.Count; i++)
                            {
                                if (!item.affordances.Contains(terrain.affordances[i]))
                                {
                                    flag3 = false;
                                    break;
                                }
                            }
                            if (flag3)
                            {
                                Command command = BuildCopyCommandUtility.BuildCommand(item, null, item.label, item.description, allowHotKey: false);
                                if (command != null)
                                {
                                    yield return(command);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Command command2 = BuildCopyCommandUtility.BuildCommand(buildable.Buildable, buildable.Stuff, entity3.LabelCap, buildable.Buildable.description, allowHotKey: false);
                    if (command2 != null)
                    {
                        yield return(command2);
                    }
                }
                Command_Action placeBlueprintsCommand = GetPlaceBlueprintsCommand(buildable);
                if (placeBlueprintsCommand != null)
                {
                    yield return(placeBlueprintsCommand);
                }
            }
            tmpUniqueBuildableDefs.Clear();
        }