Example #1
0
        private float FeeDemandChance(Faction faction)
        {
            FactionRelation factionRelation = faction.RelationWith(Faction.OfPlayer, false);
            float           x = Mathf.Max(factionRelation.goodwill, 0f);

            return(GenMath.LerpDouble(0f, 100f, 0.5f, 0f, x));
        }
Example #2
0
        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());
            }
        }
Example #3
0
 public void TryMakeInitialRelationsWith(Faction other)
 {
     if (this.RelationWith(other, true) == null)
     {
         float a = this.def.startingGoodwill.RandomInRange;
         if (this.IsPlayer)
         {
             a = 100f;
         }
         float b = other.def.startingGoodwill.RandomInRange;
         if (other.IsPlayer)
         {
             b = 100f;
         }
         float           num             = Mathf.Min(a, b);
         FactionRelation factionRelation = new FactionRelation();
         factionRelation.other    = other;
         factionRelation.goodwill = num;
         factionRelation.hostile  = (num < -40.0);
         this.relations.Add(factionRelation);
         FactionRelation factionRelation2 = new FactionRelation();
         factionRelation2.other    = this;
         factionRelation2.goodwill = num;
         factionRelation2.hostile  = (num < -40.0);
         other.relations.Add(factionRelation2);
     }
 }
Example #4
0
 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);
     }
 }
Example #5
0
        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);
        }
Example #6
0
        public bool AffectGoodwillWith(Faction other, float goodwillChange)
        {
            if (!this.def.hidden && !other.def.hidden)
            {
                if (goodwillChange > 0.0 && !this.def.appreciative)
                {
                    return(false);
                }
                if (goodwillChange > 0.0)
                {
                    if (this.IsPlayer && SettlementUtility.IsPlayerAttackingAnySettlementOf(other))
                    {
                        goto IL_0076;
                    }
                    if (other.IsPlayer && SettlementUtility.IsPlayerAttackingAnySettlementOf(this))
                    {
                        goto IL_0076;
                    }
                }
                float           num             = this.GoodwillWith(other);
                float           value           = num + goodwillChange;
                FactionRelation factionRelation = this.RelationWith(other, false);
                factionRelation.goodwill = Mathf.Clamp(value, -100f, 100f);
                if (!this.HostileTo(other) && this.GoodwillWith(other) < -80.0)
                {
                    this.SetHostileTo(other, true);
                    if (Current.ProgramState == ProgramState.Playing && Find.TickManager.TicksGame > 100 && other == Faction.OfPlayer)
                    {
                        Find.LetterStack.ReceiveLetter("LetterLabelRelationsChangeBad".Translate(), "RelationsBrokenDown".Translate(this.name), LetterDefOf.NegativeEvent, (string)null);
                    }
                }
                if (this.HostileTo(other) && this.GoodwillWith(other) > 0.0)
                {
                    this.SetHostileTo(other, false);
                    if (Current.ProgramState == ProgramState.Playing && Find.TickManager.TicksGame > 100 && other == Faction.OfPlayer)
                    {
                        Find.LetterStack.ReceiveLetter("LetterLabelRelationsChangeGood".Translate(), "RelationsWarmed".Translate(this.name), LetterDefOf.PositiveEvent, (string)null);
                    }
                }
                return((this.IsPlayer || other.IsPlayer) && !this.HostileTo(other) && this.def.appreciative && (goodwillChange > 0.0 || factionRelation.goodwill != num));
            }
            return(false);

IL_0076:
            return(false);
        }
Example #7
0
        public void TryMakeInitialRelationsWith(Faction other)
        {
            if (this.RelationWith(other, true) != null)
            {
                return;
            }
            int a = (!this.def.permanentEnemy) ? this.def.startingGoodwill.RandomInRange : -100;

            if (this.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;

            if (num <= -10)
            {
                kind = FactionRelationKind.Hostile;
            }
            else if (num >= 75)
            {
                kind = FactionRelationKind.Ally;
            }
            else
            {
                kind = FactionRelationKind.Neutral;
            }
            FactionRelation factionRelation = new FactionRelation();

            factionRelation.other    = other;
            factionRelation.goodwill = num;
            factionRelation.kind     = kind;
            this.relations.Add(factionRelation);
            FactionRelation factionRelation2 = new FactionRelation();

            factionRelation2.other    = this;
            factionRelation2.goodwill = num;
            factionRelation2.kind     = kind;
            other.relations.Add(factionRelation2);
        }
Example #8
0
        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);
        }
Example #9
0
        public void SetHostileTo(Faction other, bool hostile)
        {
            if (!this.def.hidden && !other.def.hidden)
            {
                FactionRelation factionRelation = this.RelationWith(other, false);
                if (hostile)
                {
                    if (Current.ProgramState == ProgramState.Playing)
                    {
                        foreach (Pawn item in PawnsFinder.AllMapsWorldAndTemporary_Alive.ToList())
                        {
                            if (item.Faction == this && item.HostFaction == other)
                            {
                                goto IL_0088;
                            }
                            if (item.Faction == other && item.HostFaction == this)
                            {
                                goto IL_0088;
                            }
                            continue;
IL_0088:
                            item.guest.SetGuestStatus(item.HostFaction, true);
                        }
                    }
                    if (!factionRelation.hostile)
                    {
                        other.RelationWith(this, false).hostile = true;
                        factionRelation.hostile = true;
                        if (factionRelation.goodwill > -80.0)
                        {
                            factionRelation.goodwill = -80f;
                        }
                    }
                }
                else if (factionRelation.hostile)
                {
                    other.RelationWith(this, false).hostile = false;
                    factionRelation.hostile = false;
                    if (factionRelation.goodwill < 0.0)
                    {
                        factionRelation.goodwill = 0f;
                    }
                }
                if (Current.ProgramState == ProgramState.Playing)
                {
                    List <Map> maps = Find.Maps;
                    for (int i = 0; i < maps.Count; i++)
                    {
                        maps[i].attackTargetsCache.Notify_FactionHostilityChanged(this, other);
                        LordManager lordManager = maps[i].lordManager;
                        for (int j = 0; j < lordManager.lords.Count; j++)
                        {
                            Lord lord = lordManager.lords[j];
                            if (lord.faction == other)
                            {
                                lord.Notify_FactionRelationsChanged(this);
                            }
                            else if (lord.faction == this)
                            {
                                lord.Notify_FactionRelationsChanged(other);
                            }
                        }
                    }
                }
            }
        }
 private bool <RemoveAllRelations> m__1(FactionRelation x)
 {
     return(x.other == this);
 }