public void CheckKindThresholds(Faction faction, bool canSendLetter, string reason, GlobalTargetInfo lookTarget, out bool sentLetter) { FactionRelationKind previousKind = kind; sentLetter = false; if (kind != 0 && goodwill <= -75) { kind = FactionRelationKind.Hostile; faction.Notify_RelationKindChanged(other, previousKind, canSendLetter, reason, lookTarget, out sentLetter); } if (kind != FactionRelationKind.Ally && goodwill >= 75) { kind = FactionRelationKind.Ally; faction.Notify_RelationKindChanged(other, previousKind, canSendLetter, reason, lookTarget, out sentLetter); } if (kind == FactionRelationKind.Hostile && goodwill >= 0) { kind = FactionRelationKind.Neutral; faction.Notify_RelationKindChanged(other, previousKind, canSendLetter, reason, lookTarget, out sentLetter); } if (kind == FactionRelationKind.Ally && goodwill <= 0) { kind = FactionRelationKind.Neutral; faction.Notify_RelationKindChanged(other, previousKind, canSendLetter, reason, lookTarget, out sentLetter); } }
public bool TrySetRelationKind(Faction other, FactionRelationKind kind, bool canSendLetter = true, string reason = null, GlobalTargetInfo?lookTarget = null) { FactionRelation factionRelation = this.RelationWith(other, false); if (factionRelation.kind == kind) { return(true); } switch (kind) { case FactionRelationKind.Hostile: this.TryAffectGoodwillWith(other, -75 - factionRelation.goodwill, false, canSendLetter, reason, lookTarget); return(factionRelation.kind == FactionRelationKind.Hostile); case FactionRelationKind.Neutral: this.TryAffectGoodwillWith(other, -factionRelation.goodwill, false, canSendLetter, reason, lookTarget); return(factionRelation.kind == FactionRelationKind.Neutral); case FactionRelationKind.Ally: this.TryAffectGoodwillWith(other, 75 - factionRelation.goodwill, false, canSendLetter, reason, lookTarget); return(factionRelation.kind == FactionRelationKind.Ally); default: throw new NotSupportedException(kind.ToString()); } }
internal void <> m__3() { Pawn t = this.caravan.PawnsListForReading[0]; Faction faction = this.faction; Faction ofPlayer = Faction.OfPlayer; FactionRelationKind kind = FactionRelationKind.Hostile; string reason = "GoodwillChangedReason_AttackedCaravan".Translate(); faction.TrySetRelationKind(ofPlayer, kind, true, reason, new GlobalTargetInfo?(t)); Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(this.caravan, new IntVec3(100, 1, 100), WorldObjectDefOf.AttackedNonPlayerCaravan); IntVec3 playerSpot; IntVec3 enemySpot; MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out playerSpot, out enemySpot); CaravanEnterMapUtility.Enter(this.caravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(playerSpot, map, 12, null), CaravanDropInventoryMode.DoNotDrop, true); List <Pawn> list = this.metCaravan.PawnsListForReading.ToList <Pawn>(); CaravanEnterMapUtility.Enter(this.metCaravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(enemySpot, map, 12, null), CaravanDropInventoryMode.DoNotDrop, false); LordMaker.MakeNewLord(this.faction, new LordJob_DefendAttackedTraderCaravan(list[0].Position), map, list); Find.TickManager.CurTimeSpeed = TimeSpeed.Paused; CameraJumper.TryJumpAndSelect(t); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(list, "LetterRelatedPawnsGroupGeneric".Translate(new object[] { Faction.OfPlayer.def.pawnsPlural }), LetterDefOf.NeutralEvent, true, true); }
private static bool TrySetRelationKind(Faction self, Faction other, FactionRelationKind kind, bool canSendLetter = true) { FactionRelation factionRelation = self.RelationWith(other); if (factionRelation.kind == kind) { return(true); } if (!self.HasGoodwill) { self.SetRelationDirect(other, kind, canSendLetter); return(true); } switch (kind) { case FactionRelationKind.Hostile: self.TryAffectGoodwillWith(other, -75 - factionRelation.baseGoodwill, canSendMessage: false, canSendLetter); return(factionRelation.kind == FactionRelationKind.Hostile); case FactionRelationKind.Neutral: self.TryAffectGoodwillWith(other, -factionRelation.baseGoodwill, canSendMessage: false, canSendLetter); return(factionRelation.kind == FactionRelationKind.Neutral); case FactionRelationKind.Ally: self.TryAffectGoodwillWith(other, 75 - factionRelation.baseGoodwill, canSendMessage: false, canSendLetter); return(factionRelation.kind == FactionRelationKind.Ally); default: throw new NotSupportedException(kind.ToString()); } }
private void Outcome_Disaster(Caravan caravan) { LongEventHandler.QueueLongEvent(delegate { FactionRelationKind playerRelationKind = base.Faction.PlayerRelationKind; int randomInRange = DiplomacyTuning.Goodwill_PeaceTalksDisasterRange.RandomInRange; base.Faction.TryAffectGoodwillWith(Faction.OfPlayer, randomInRange, canSendMessage: false, canSendHostilityLetter: false); base.Faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile, canSendLetter: false); IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, caravan); incidentParms.faction = base.Faction; PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, incidentParms, ensureCanGenerateAtLeastOnePawn: true); defaultPawnGroupMakerParms.generateFightersOnly = true; List <Pawn> list = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms).ToList(); Map map = CaravanIncidentUtility.SetupCaravanAttackMap(caravan, list, sendLetterIfRelatedPawns: false); if (list.Any()) { LordMaker.MakeNewLord(incidentParms.faction, new LordJob_AssaultColony(base.Faction), map, list); } Find.TickManager.Notify_GeneratedPotentiallyHostileMap(); GlobalTargetInfo target = (list.Any() ? new GlobalTargetInfo(list[0].Position, map) : GlobalTargetInfo.Invalid); TaggedString letterLabel = "LetterLabelPeaceTalks_Disaster".Translate(); TaggedString letterText = GetLetterText("LetterPeaceTalks_Disaster".Translate(base.Faction.def.pawnsPlural.CapitalizeFirst(), base.Faction.NameColored, Mathf.RoundToInt(randomInRange)), caravan, playerRelationKind); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, "LetterRelatedPawnsGroupGeneric".Translate(Faction.OfPlayer.def.pawnsPlural), informEvenIfSeenBefore: true); Find.LetterStack.ReceiveLetter(letterLabel, letterText, LetterDefOf.ThreatBig, target, base.Faction); }, "GeneratingMapForNewEncounter", doAsynchronously: false, null); }
public override void DoWindowContents(Rect inRect) { GUI.BeginGroup(inRect); Rect rect = new Rect(0f, 0f, inRect.width / 2f, 70f); Rect rect2 = new Rect(0f, rect.yMax, rect.width, 60f); Rect rect3 = new Rect(inRect.width / 2f, 0f, inRect.width / 2f, 70f); Rect rect4 = new Rect(inRect.width / 2f, rect.yMax, rect.width, 60f); Text.Font = GameFont.Medium; Widgets.Label(rect, negotiator.LabelCap); Text.Anchor = TextAnchor.UpperRight; Widgets.Label(rect3, commTarget.GetCallLabel()); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; GUI.color = new Color(1f, 1f, 1f, 0.7f); Widgets.Label(rect2, "SocialSkillIs".Translate(negotiator.skills.GetSkill(SkillDefOf.Social).Level)); Text.Anchor = TextAnchor.UpperRight; Widgets.Label(rect4, commTarget.GetInfoText()); Faction faction = commTarget.GetFaction(); if (faction != null) { FactionRelationKind playerRelationKind = faction.PlayerRelationKind; GUI.color = playerRelationKind.GetColor(); Rect rect5 = new Rect(rect4.x, rect4.y + Text.CalcHeight(commTarget.GetInfoText(), rect4.width) + Text.SpaceBetweenLines, rect4.width, 30f); Widgets.Label(rect5, playerRelationKind.GetLabel()); } Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; GUI.EndGroup(); float num = 147f; Rect rect6 = new Rect(0f, num, inRect.width, inRect.height - num); DrawNode(rect6); }
public static void Postfix(Faction __instance, Faction other) { var currentFactionDefExtension = FactionDefExtension.Get(__instance.def); var otherFactionDefExtension = FactionDefExtension.Get(other.def); var currentToOtherFactionGoodwill = currentFactionDefExtension?.startingGoodwillByFactionDefs?.Find(x => x.factionDef == other.def); var otherToCurrentFactionGoodwill = otherFactionDefExtension?.startingGoodwillByFactionDefs?.Find(x => x.factionDef == __instance.def); // If at least one of the factions references the other via custom values in the FactionDefExtension if (currentToOtherFactionGoodwill != null || otherToCurrentFactionGoodwill != null) { // Get the lowest range of goodwill possible between factions int?currentToOtherFactionGoodwillMin = currentToOtherFactionGoodwill?.Min; int?currentToOtherFactionGoodwillMax = currentToOtherFactionGoodwill?.Max; int?otherToCurrentFactionGoodwillMin = otherToCurrentFactionGoodwill?.Min; int?otherToCurrentFactionGoodwillMax = otherToCurrentFactionGoodwill?.Max; int mutualGoodwillMin = MinOfNullableInts(currentToOtherFactionGoodwillMin, otherToCurrentFactionGoodwillMin); int mutualGoodwillMax = MinOfNullableInts(currentToOtherFactionGoodwillMax, otherToCurrentFactionGoodwillMax); // Generate a random goodwill value within the range int finalMutualGoodWill = Rand.RangeInclusive(mutualGoodwillMin, mutualGoodwillMax); // Assign mutual faction relations FactionRelationKind kind = (finalMutualGoodWill > -10) ? ((finalMutualGoodWill < 75) ? FactionRelationKind.Neutral : FactionRelationKind.Ally) : FactionRelationKind.Hostile; FactionRelation factionRelation = __instance.RelationWith(other, false); factionRelation.baseGoodwill = finalMutualGoodWill; factionRelation.kind = kind; FactionRelation factionRelation2 = other.RelationWith(__instance, false); factionRelation2.baseGoodwill = finalMutualGoodWill; factionRelation2.kind = kind; } }
public void TryMakeInitialRelationsWith(Faction other) { if (RelationWith(other, allowNull: true) == null) { int a = (!def.permanentEnemy) ? def.startingGoodwill.RandomInRange : (-100); if (IsPlayer) { a = 100; } int b = (!other.def.permanentEnemy) ? other.def.startingGoodwill.RandomInRange : (-100); if (other.IsPlayer) { b = 100; } int num = Mathf.Min(a, b); FactionRelationKind kind = (num > -10) ? ((num < 75) ? FactionRelationKind.Neutral : FactionRelationKind.Ally) : FactionRelationKind.Hostile; FactionRelation factionRelation = new FactionRelation(); factionRelation.other = other; factionRelation.goodwill = num; factionRelation.kind = kind; relations.Add(factionRelation); FactionRelation factionRelation2 = new FactionRelation(); factionRelation2.other = this; factionRelation2.goodwill = num; factionRelation2.kind = kind; other.relations.Add(factionRelation2); } }
private void Outcome_Disaster(Caravan caravan) { LongEventHandler.QueueLongEvent(delegate() { FactionRelationKind playerRelationKind = this.Faction.PlayerRelationKind; int randomInRange = DiplomacyTuning.Goodwill_PeaceTalksDisasterRange.RandomInRange; this.Faction.TryAffectGoodwillWith(Faction.OfPlayer, randomInRange, false, false, null, null); this.Faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile, false, null, null); IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, caravan); incidentParms.faction = this.Faction; PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, incidentParms, true); defaultPawnGroupMakerParms.generateFightersOnly = true; List <Pawn> list = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms, true).ToList <Pawn>(); Map map = CaravanIncidentUtility.SetupCaravanAttackMap(caravan, list, false); if (list.Any <Pawn>()) { LordMaker.MakeNewLord(incidentParms.faction, new LordJob_AssaultColony(this.Faction, true, true, false, false, true), map, list); } Find.TickManager.Notify_GeneratedPotentiallyHostileMap(); GlobalTargetInfo target = (!list.Any <Pawn>()) ? GlobalTargetInfo.Invalid : new GlobalTargetInfo(list[0].Position, map, false); string label = "LetterLabelPeaceTalks_Disaster".Translate(); string letterText = this.GetLetterText("LetterPeaceTalks_Disaster".Translate(new object[] { this.Faction.def.pawnsPlural.CapitalizeFirst(), this.Faction.Name, Mathf.RoundToInt((float)randomInRange) }), caravan, playerRelationKind); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref label, ref letterText, "LetterRelatedPawnsGroupGeneric".Translate(new object[] { Faction.OfPlayer.def.pawnsPlural }), true, true); Find.LetterStack.ReceiveLetter(label, letterText, LetterDefOf.ThreatBig, target, this.Faction, null); }, "GeneratingMapForNewEncounter", false, null); }
public override void AssignDebugData() { base.AssignDebugData(); faction1 = Find.FactionManager.RandomEnemyFaction(); faction2 = Faction.OfPlayer; relationKind = FactionRelationKind.Neutral; }
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>() }); }
private void Outcome_Success(Caravan caravan) { FactionRelationKind playerRelationKind = base.Faction.PlayerRelationKind; int randomInRange = DiplomacyTuning.Goodwill_PeaceTalksSuccessRange.RandomInRange; base.Faction.TryAffectGoodwillWith(Faction.OfPlayer, randomInRange, false, false, null, null); Find.LetterStack.ReceiveLetter("LetterLabelPeaceTalks_Success".Translate(), this.GetLetterText("LetterPeaceTalks_Success".Translate(base.Faction.Name, randomInRange), caravan, playerRelationKind), LetterDefOf.PositiveEvent, caravan, base.Faction, null); }
private bool TryGetFaction(FactionRelationKind kind, out Faction faction) { if ((from f in Find.FactionManager.AllFactionsVisible where f != Faction.OfPlayer && f.PlayerRelationKind == kind select f).TryRandomElement(out faction)) { return(true); } return(false); }
private void Outcome_Backfire(Caravan caravan) { FactionRelationKind playerRelationKind = base.Faction.PlayerRelationKind; int randomInRange = DiplomacyTuning.Goodwill_PeaceTalksBackfireRange.RandomInRange; base.Faction.TryAffectGoodwillWith(Faction.OfPlayer, randomInRange, canSendMessage: false, canSendHostilityLetter: false); Find.LetterStack.ReceiveLetter("LetterLabelPeaceTalks_Backfire".Translate(), GetLetterText("LetterPeaceTalks_Backfire".Translate(base.Faction.Name, randomInRange), caravan, playerRelationKind), LetterDefOf.NegativeEvent, caravan, base.Faction); }
private bool TryGetFaction(FactionRelationKind kind, IntRange minReqGoodWill, out Faction faction) { if ((from f in Find.FactionManager.AllFactionsVisible where f != Faction.OfPlayer && f.PlayerRelationKind == kind && minReqGoodWill.InRange(f.PlayerGoodwill) select f).TryRandomElement(out faction)) { return(true); } return(false); }
private bool TryGetFactionWithFilter(FactionRelationKind kind, IntRange minReqGoodWill, FactionDef filter, out Faction faction) { if ((from f in Find.FactionManager.AllFactions where f != Faction.OfPlayer && f.PlayerRelationKind == kind && minReqGoodWill.InRange(f.PlayerGoodwill) && f.def == filter select f).TryRandomElement(out faction)) { return(true); } return(false); }
private void Outcome_Success(Caravan caravan) { FactionRelationKind playerRelationKind = base.Faction.PlayerRelationKind; int randomInRange = DiplomacyTuning.Goodwill_PeaceTalksSuccessRange.RandomInRange; base.Faction.TryAffectGoodwillWith(Faction.OfPlayer, randomInRange, canSendMessage: false, canSendHostilityLetter: false); Find.LetterStack.ReceiveLetter("LetterLabelPeaceTalks_Success".Translate(), GetLetterText("LetterPeaceTalks_Success".Translate(base.Faction.NameColored, randomInRange), caravan, playerRelationKind, TryGainRoyalFavor(caravan)), LetterDefOf.PositiveEvent, caravan, base.Faction); }
public bool TryAffectGoodwillWith(Faction other, int goodwillChange, bool canSendMessage = true, bool canSendHostilityLetter = true, string reason = null, GlobalTargetInfo?lookTarget = null) { if (this.def.hidden || other.def.hidden || this.def.permanentEnemy || other.def.permanentEnemy || this.defeated || other.defeated || other == this) { return(false); } if (goodwillChange > 0 && ((this.IsPlayer && SettlementUtility.IsPlayerAttackingAnySettlementOf(other)) || (other.IsPlayer && SettlementUtility.IsPlayerAttackingAnySettlementOf(this)))) { return(false); } if (goodwillChange == 0) { return(true); } int num = this.GoodwillWith(other); int num2 = Mathf.Clamp(num + goodwillChange, -100, 100); if (num == num2) { return(true); } FactionRelation factionRelation = this.RelationWith(other, false); factionRelation.goodwill = num2; bool flag; factionRelation.CheckKindThresholds(this, canSendHostilityLetter, reason, (!lookTarget.HasValue) ? GlobalTargetInfo.Invalid : lookTarget.Value, out flag); FactionRelation factionRelation2 = other.RelationWith(this, false); FactionRelationKind kind = factionRelation2.kind; factionRelation2.goodwill = factionRelation.goodwill; factionRelation2.kind = factionRelation.kind; bool flag2; if (kind != factionRelation2.kind) { other.Notify_RelationKindChanged(this, kind, canSendHostilityLetter, reason, (!lookTarget.HasValue) ? GlobalTargetInfo.Invalid : lookTarget.Value, out flag2); } else { flag2 = false; } if (canSendMessage && !flag && !flag2 && Current.ProgramState == ProgramState.Playing && (this.IsPlayer || other.IsPlayer)) { Faction faction = (!this.IsPlayer) ? this : other; string text; if (!reason.NullOrEmpty()) { text = "MessageGoodwillChangedWithReason".Translate(faction.name, num.ToString("F0"), factionRelation.goodwill.ToString("F0"), reason); } else { text = "MessageGoodwillChanged".Translate(faction.name, num.ToString("F0"), factionRelation.goodwill.ToString("F0")); } Messages.Message(text, (!lookTarget.HasValue) ? GlobalTargetInfo.Invalid : lookTarget.Value, ((float)goodwillChange <= 0f) ? MessageTypeDefOf.NegativeEvent : MessageTypeDefOf.PositiveEvent, true); } return(true); }
public void Notify_MemberCaptured(Pawn member, Faction violator) { if (violator != this && RelationKindWith(violator) != 0) { FactionRelationKind kind = FactionRelationKind.Hostile; string reason = "GoodwillChangedReason_CapturedPawn".Translate(member.LabelShort, member); TrySetRelationKind(violator, kind, canSendLetter: true, reason, member); } }
public void Notify_FactionRelationsChanged(Faction otherFaction, FactionRelationKind previousRelationKind) { this.CheckTransitionOnSignal(new TriggerSignal { type = TriggerSignalType.FactionRelationsChanged, faction = otherFaction, previousRelationKind = new FactionRelationKind?(previousRelationKind) }); }
public static string GetLabel(this FactionRelationKind kind) { return(kind switch { FactionRelationKind.Hostile => "Hostile".Translate(), FactionRelationKind.Neutral => "Neutral".Translate(), FactionRelationKind.Ally => "Ally".Translate(), _ => "error", });
private static void InitializeFaction(Faction faction, FactionRelationKind kind) { if (ScenPartUtility.cachedFactionDefAffectedByForcedFactionGoodwill.ContainsKey(faction.def)) { IntRange range = ScenPartUtility.cachedFactionDefAffectedByForcedFactionGoodwill.TryGetValue(faction.def); faction.TryAffectGoodwillWith(Faction.OfPlayer, range.RandomInRange - faction.PlayerGoodwill, false, false); } Find.FactionManager.Add(faction); }
protected override bool TryExecuteWorker(IncidentParms parms) { if (parms.target is Map) { return(IncidentDefOf.TravelerGroup.Worker.TryExecute(parms)); } Caravan caravan = (Caravan)parms.target; if (!TryFindFaction(out Faction faction)) { return(false); } CameraJumper.TryJumpAndSelect(caravan); List <Pawn> pawns = GenerateCaravanPawns(faction); Caravan metCaravan = CaravanMaker.MakeCaravan(pawns, faction, -1, addToWorldPawnsIfNotAlready: false); string text = "CaravanMeeting".Translate(caravan.Name, faction.Name, PawnUtility.PawnKindsToCommaList(metCaravan.PawnsListForReading, useAnd: true)).CapitalizeFirst(); DiaNode diaNode = new DiaNode(text); Pawn bestPlayerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan); if (metCaravan.CanTradeNow) { DiaOption diaOption = new DiaOption("CaravanMeeting_Trade".Translate()); diaOption.action = delegate { Find.WindowStack.Add(new Dialog_Trade(bestPlayerNegotiator, metCaravan)); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(metCaravan.Goods.OfType <Pawn>(), "LetterRelatedPawnsTradingWithOtherCaravan".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent); }; if (bestPlayerNegotiator == null) { diaOption.Disable("CaravanMeeting_TradeIncapable".Translate()); } diaNode.options.Add(diaOption); } DiaOption diaOption2 = new DiaOption("CaravanMeeting_Attack".Translate()); diaOption2.action = delegate { LongEventHandler.QueueLongEvent(delegate { Pawn t = caravan.PawnsListForReading[0]; Faction faction3 = faction; Faction ofPlayer = Faction.OfPlayer; FactionRelationKind kind = FactionRelationKind.Hostile; string reason = "GoodwillChangedReason_AttackedCaravan".Translate(); faction3.TrySetRelationKind(ofPlayer, kind, canSendLetter: true, reason, t); Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(caravan, new IntVec3(100, 1, 100), WorldObjectDefOf.AttackedNonPlayerCaravan); MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out IntVec3 playerSpot, out IntVec3 enemySpot); CaravanEnterMapUtility.Enter(caravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(playerSpot, map, 12), CaravanDropInventoryMode.DoNotDrop, draftColonists: true); List <Pawn> list = metCaravan.PawnsListForReading.ToList(); CaravanEnterMapUtility.Enter(metCaravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(enemySpot, map, 12)); LordMaker.MakeNewLord(faction, new LordJob_DefendAttackedTraderCaravan(list[0].Position), map, list); Find.TickManager.Notify_GeneratedPotentiallyHostileMap(); CameraJumper.TryJumpAndSelect(t); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(list, "LetterRelatedPawnsGroupGeneric".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, informEvenIfSeenBefore: true); }, "GeneratingMapForNewEncounter", doAsynchronously: false, null);
static bool Prefix() { if (Find.TickManager.TicksGame == 0 || Find.TickManager.TicksGame % 900000 > RefcellRespeedConfig.currentTimeMultiplier - 1) { return(false); } List <Settlement> settlements = Find.WorldObjects.Settlements; SettlementProximityGoodwillUtility.tmpGoodwillOffsets.Clear(); for (int index = 0; index < settlements.Count; ++index) { Settlement settlement = settlements[index]; if (settlement.Faction == Faction.OfPlayer) { SettlementProximityGoodwillUtility.AppendProximityGoodwillOffsets(settlement.Tile, SettlementProximityGoodwillUtility.tmpGoodwillOffsets, true, false); } } if (!SettlementProximityGoodwillUtility.tmpGoodwillOffsets.Any <Pair <Settlement, int> >()) { return(false); } SettlementProximityGoodwillUtility.SortProximityGoodwillOffsets(SettlementProximityGoodwillUtility.tmpGoodwillOffsets); List <Faction> factionsListForReading = Find.FactionManager.AllFactionsListForReading; bool flag = false; TaggedString text = "LetterFactionBaseProximity".Translate() + "\n\n" + SettlementProximityGoodwillUtility.ProximityGoodwillOffsetsToString(SettlementProximityGoodwillUtility.tmpGoodwillOffsets); for (int index1 = 0; index1 < factionsListForReading.Count; ++index1) { Faction faction = factionsListForReading[index1]; if (faction != Faction.OfPlayer) { int goodwillChange = 0; for (int index2 = 0; index2 < SettlementProximityGoodwillUtility.tmpGoodwillOffsets.Count; ++index2) { if (SettlementProximityGoodwillUtility.tmpGoodwillOffsets[index2].First.Faction == faction) { goodwillChange += SettlementProximityGoodwillUtility.tmpGoodwillOffsets[index2].Second; } } FactionRelationKind playerRelationKind = faction.PlayerRelationKind; if (faction.TryAffectGoodwillWith(Faction.OfPlayer, goodwillChange, false, false)) { flag = true; faction.TryAppendRelationKindChangedInfo(ref text, playerRelationKind, faction.PlayerRelationKind); } } } if (!flag) { return(false); } Find.LetterStack.ReceiveLetter((string)"LetterLabelFactionBaseProximity".Translate(), (string)text, LetterDefOf.NegativeEvent); return(false); }
private static bool IsFactionFriendly(Faction f) { if (f == Faction.OfPlayer) { return(true); } FactionRelationKind kind = f.RelationWith(Faction.OfPlayer, false).kind; return(kind != FactionRelationKind.Hostile); }
private string GetLetterText(string baseText, Caravan caravan, FactionRelationKind previousRelationKind) { string text = baseText; Pawn pawn = BestCaravanPawnUtility.FindBestDiplomat(caravan); if (pawn != null) { text = text + "\n\n" + "PeaceTalksSocialXPGain".Translate(pawn.LabelShort, 6000f.ToString("F0"), pawn.Named("PAWN")); } base.Faction.TryAppendRelationKindChangedInfo(ref text, previousRelationKind, base.Faction.PlayerRelationKind); return(text); }
public static void CheckSettlementProximityGoodwillChange() { if (Find.TickManager.TicksGame == 0 || Find.TickManager.TicksGame % 900000 != 0) { return; } List <Settlement> settlements = Find.WorldObjects.Settlements; tmpGoodwillOffsets.Clear(); for (int i = 0; i < settlements.Count; i++) { Settlement settlement = settlements[i]; if (settlement.Faction == Faction.OfPlayer) { AppendProximityGoodwillOffsets(settlement.Tile, tmpGoodwillOffsets, ignoreIfAlreadyMinGoodwill: true, ignorePermanentlyHostile: false); } } if (!tmpGoodwillOffsets.Any()) { return; } SortProximityGoodwillOffsets(tmpGoodwillOffsets); List <Faction> allFactionsListForReading = Find.FactionManager.AllFactionsListForReading; bool flag = false; TaggedString text = "LetterFactionBaseProximity".Translate() + "\n\n" + ProximityGoodwillOffsetsToString(tmpGoodwillOffsets); for (int j = 0; j < allFactionsListForReading.Count; j++) { Faction faction = allFactionsListForReading[j]; if (faction == Faction.OfPlayer) { continue; } int num = 0; for (int k = 0; k < tmpGoodwillOffsets.Count; k++) { if (tmpGoodwillOffsets[k].First.Faction == faction) { num += tmpGoodwillOffsets[k].Second; } } FactionRelationKind playerRelationKind = faction.PlayerRelationKind; if (faction.TryAffectGoodwillWith(Faction.OfPlayer, num, canSendMessage: false, canSendHostilityLetter: false)) { flag = true; faction.TryAppendRelationKindChangedInfo(ref text, playerRelationKind, faction.PlayerRelationKind); } } if (flag) { Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseProximity".Translate(), text, LetterDefOf.NegativeEvent); } }
public void TryAppendRelationKindChangedInfo(StringBuilder text, FactionRelationKind previousKind, FactionRelationKind newKind, string reason = null) { string text2 = null; this.TryAppendRelationKindChangedInfo(ref text2, previousKind, newKind, reason); if (!text2.NullOrEmpty()) { text.AppendLine(); text.AppendLine(); text.Append(text2); } }
public static void CheckSettlementProximityGoodwillChange() { if (Find.TickManager.TicksGame == 0 || Find.TickManager.TicksGame % 900000 != 0) { return; } List <Settlement> settlements = Find.WorldObjects.Settlements; SettlementProximityGoodwillUtility.tmpGoodwillOffsets.Clear(); for (int i = 0; i < settlements.Count; i++) { Settlement settlement = settlements[i]; if (settlement.Faction == Faction.OfPlayer) { SettlementProximityGoodwillUtility.AppendProximityGoodwillOffsets(settlement.Tile, SettlementProximityGoodwillUtility.tmpGoodwillOffsets, true, false); } } if (!SettlementProximityGoodwillUtility.tmpGoodwillOffsets.Any <Pair <Settlement, int> >()) { return; } SettlementProximityGoodwillUtility.SortProximityGoodwillOffsets(SettlementProximityGoodwillUtility.tmpGoodwillOffsets); List <Faction> allFactionsListForReading = Find.FactionManager.AllFactionsListForReading; bool flag = false; string text = "LetterFactionBaseProximity".Translate() + "\n\n" + SettlementProximityGoodwillUtility.ProximityGoodwillOffsetsToString(SettlementProximityGoodwillUtility.tmpGoodwillOffsets); for (int j = 0; j < allFactionsListForReading.Count; j++) { Faction faction = allFactionsListForReading[j]; if (faction != Faction.OfPlayer) { int num = 0; for (int k = 0; k < SettlementProximityGoodwillUtility.tmpGoodwillOffsets.Count; k++) { if (SettlementProximityGoodwillUtility.tmpGoodwillOffsets[k].First.Faction == faction) { num += SettlementProximityGoodwillUtility.tmpGoodwillOffsets[k].Second; } } FactionRelationKind playerRelationKind = faction.PlayerRelationKind; if (faction.TryAffectGoodwillWith(Faction.OfPlayer, num, false, false, null, null)) { flag = true; faction.TryAppendRelationKindChangedInfo(ref text, playerRelationKind, faction.PlayerRelationKind, null); } } } if (flag) { Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseProximity".Translate(), text, LetterDefOf.NegativeEvent, null); } }
private void DrawFactionInfo(Rect rect, Faction faction) { Text.Anchor = TextAnchor.LowerRight; FactionRelationKind playerRelationKind = faction.PlayerRelationKind; GUI.color = playerRelationKind.GetColor(); Widgets.Label(rect, playerRelationKind.GetLabel()); rect.height -= Text.CalcHeight(playerRelationKind.GetLabel(), rect.width) + Text.SpaceBetweenLines; GUI.color = Color.gray; Widgets.Label(rect, faction.Name + "\n" + "goodwill".Translate().CapitalizeFirst() + ": " + faction.PlayerGoodwill.ToStringWithSign()); GenUI.ResetLabelAlign(); GUI.color = Color.white; }