Beispiel #1
0
        public static void CheckDefeated(Settlement factionBase)
        {
            if (factionBase.Faction == Faction.OfPlayer)
            {
                return;
            }
            Map map = factionBase.Map;

            if (map == null || !SettlementDefeatUtility.IsDefeated(map, factionBase.Faction))
            {
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("LetterFactionBaseDefeated".Translate(new object[]
            {
                factionBase.Label,
                TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(60000)
            }));
            if (!SettlementDefeatUtility.HasAnyOtherBase(factionBase))
            {
                factionBase.Faction.defeated = true;
                stringBuilder.AppendLine();
                stringBuilder.AppendLine();
                stringBuilder.Append("LetterFactionBaseDefeated_FactionDestroyed".Translate(new object[]
                {
                    factionBase.Faction.Name
                }));
            }
            foreach (Faction current in Find.FactionManager.AllFactions)
            {
                if (!current.def.hidden && !current.IsPlayer && current != factionBase.Faction && current.HostileTo(factionBase.Faction))
                {
                    FactionRelationKind playerRelationKind = current.PlayerRelationKind;
                    if (current.TryAffectGoodwillWith(Faction.OfPlayer, 20, false, false, null, null))
                    {
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine();
                        stringBuilder.Append("RelationsWith".Translate(new object[]
                        {
                            current.Name
                        }) + ": " + 20.ToStringWithSign());
                        current.TryAppendRelationKindChangedInfo(stringBuilder, playerRelationKind, current.PlayerRelationKind, null);
                    }
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), stringBuilder.ToString(), LetterDefOf.PositiveEvent, new GlobalTargetInfo(factionBase.Tile), factionBase.Faction, null);
            DestroyedSettlement destroyedSettlement = (DestroyedSettlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.DestroyedSettlement);

            destroyedSettlement.Tile = factionBase.Tile;
            Find.WorldObjects.Add(destroyedSettlement);
            map.info.parent = destroyedSettlement;
            Find.WorldObjects.Remove(factionBase);
            destroyedSettlement.GetComponent <TimedForcedExit>().StartForceExitAndRemoveMapCountdown();
            TaleRecorder.RecordTale(TaleDefOf.CaravanAssaultSuccessful, new object[]
            {
                map.mapPawns.FreeColonists.RandomElement <Pawn>()
            });
        }
        public static void CheckDefeated(Settlement factionBase)
        {
            if (factionBase.Faction == Faction.OfPlayer)
            {
                return;
            }
            Map map = factionBase.Map;

            if (map == null || !IsDefeated(map, factionBase.Faction))
            {
                return;
            }
            DestroyedSettlement destroyedSettlement = (DestroyedSettlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.DestroyedSettlement);

            destroyedSettlement.Tile = factionBase.Tile;
            destroyedSettlement.SetFaction(factionBase.Faction);
            Find.WorldObjects.Add(destroyedSettlement);
            TimedDetectionRaids component = destroyedSettlement.GetComponent <TimedDetectionRaids>();

            component.CopyFrom(factionBase.GetComponent <TimedDetectionRaids>());
            component.SetNotifiedSilently();
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("LetterFactionBaseDefeated".Translate(factionBase.Label, component.DetectionCountdownTimeLeftString));
            if (!HasAnyOtherBase(factionBase))
            {
                factionBase.Faction.defeated = true;
                stringBuilder.AppendLine();
                stringBuilder.AppendLine();
                stringBuilder.Append("LetterFactionBaseDefeated_FactionDestroyed".Translate(factionBase.Faction.Name));
            }
            foreach (Faction allFaction in Find.FactionManager.AllFactions)
            {
                if (!allFaction.Hidden && !allFaction.IsPlayer && allFaction != factionBase.Faction && allFaction.HostileTo(factionBase.Faction))
                {
                    FactionRelationKind playerRelationKind = allFaction.PlayerRelationKind;
                    if (allFaction.TryAffectGoodwillWith(Faction.OfPlayer, 20, canSendMessage: false, canSendHostilityLetter: false))
                    {
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine();
                        stringBuilder.Append("RelationsWith".Translate(allFaction.Name) + ": " + 20.ToStringWithSign());
                        allFaction.TryAppendRelationKindChangedInfo(stringBuilder, playerRelationKind, allFaction.PlayerRelationKind);
                    }
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), stringBuilder.ToString(), LetterDefOf.PositiveEvent, new GlobalTargetInfo(factionBase.Tile), factionBase.Faction);
            map.info.parent = destroyedSettlement;
            factionBase.Destroy();
            TaleRecorder.RecordTale(TaleDefOf.CaravanAssaultSuccessful, map.mapPawns.FreeColonists.RandomElement());
        }