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 bool TryAffectGoodwillWith(Faction other, int goodwillChange, bool canSendMessage = true, bool canSendHostilityLetter = true, string reason = null, GlobalTargetInfo?lookTarget = null) { if (!CanChangeGoodwillFor(other, goodwillChange)) { return(false); } if (goodwillChange == 0) { return(true); } int num = GoodwillWith(other); int num2 = Mathf.Clamp(num + goodwillChange, -100, 100); if (num == num2) { return(true); } FactionRelation factionRelation = RelationWith(other); factionRelation.goodwill = num2; factionRelation.CheckKindThresholds(this, canSendHostilityLetter, reason, lookTarget ?? GlobalTargetInfo.Invalid, out bool sentLetter); FactionRelation factionRelation2 = other.RelationWith(this); FactionRelationKind kind = factionRelation2.kind; factionRelation2.goodwill = factionRelation.goodwill; factionRelation2.kind = factionRelation.kind; bool sentLetter2; if (kind != factionRelation2.kind) { other.Notify_RelationKindChanged(this, kind, canSendHostilityLetter, reason, lookTarget ?? GlobalTargetInfo.Invalid, out sentLetter2); } else { sentLetter2 = false; } if (canSendMessage && !sentLetter && !sentLetter2 && Current.ProgramState == ProgramState.Playing && (IsPlayer || other.IsPlayer)) { Faction faction = IsPlayer ? other : this; string text = reason.NullOrEmpty() ? ((string)"MessageGoodwillChanged".Translate(faction.name, num.ToString("F0"), factionRelation.goodwill.ToString("F0"))) : ((string)"MessageGoodwillChangedWithReason".Translate(faction.name, num.ToString("F0"), factionRelation.goodwill.ToString("F0"), reason)); Messages.Message(text, lookTarget ?? GlobalTargetInfo.Invalid, ((float)goodwillChange > 0f) ? MessageTypeDefOf.PositiveEvent : MessageTypeDefOf.NegativeEvent); } return(true); }