示例#1
0
        // ===================== Goodwill management =====================
        public static bool AffectGoodwillWith(Faction faction, Faction other, int goodwillChange, bool canSendMessage = true, bool canSendHostilityLetter = true, string reason = null, GlobalTargetInfo?lookTarget = null)
        {
            if (goodwillChange == 0)
            {
                return(true);
            }
            int num  = faction.GoodwillWith(other);
            int num2 = Mathf.Clamp(num + goodwillChange, -100, 100);

            if (num == num2)
            {
                return(true);
            }
            FactionRelation factionRelation = faction.RelationWith(other, false);

            factionRelation.goodwill = num2;
            bool flag;

            factionRelation.CheckKindThresholds(faction, canSendHostilityLetter, reason, (!lookTarget.HasValue) ? GlobalTargetInfo.Invalid : lookTarget.Value, out flag);
            FactionRelation     factionRelation2 = other.RelationWith(faction, false);
            FactionRelationKind kind             = factionRelation2.kind;

            factionRelation2.goodwill = factionRelation.goodwill;
            factionRelation2.kind     = factionRelation.kind;
            bool flag2;

            if (kind != factionRelation2.kind)
            {
                other.Notify_RelationKindChanged(faction, kind, canSendHostilityLetter, reason, (!lookTarget.HasValue) ? GlobalTargetInfo.Invalid : lookTarget.Value, out flag2);
            }

            if ((faction == Util_Faction.MiningCoFaction) &&
                (other == Faction.OfPlayer) &&
                (factionRelation.kind == FactionRelationKind.Hostile))
            {
                Util_Misc.Partnership.globalGoodwillFeeInSilver = WorldComponent_Partnership.globalGoodwillCostInSilver;
                Util_Misc.OrbitalHealing.Notify_BecameHostileToColony();
                foreach (Map map in Find.Maps)
                {
                    if (map.IsPlayerHome)
                    {
                        List <Building_Spaceship> takeOffRequestList = new List <Building_Spaceship>();
                        foreach (Thing thing in map.listerThings.AllThings)
                        {
                            if (thing is Building_Spaceship)
                            {
                                takeOffRequestList.Add(thing as Building_Spaceship);
                            }
                        }
                        foreach (Building_Spaceship spaceship in takeOffRequestList)
                        {
                            spaceship.RequestTakeOff();
                        }
                    }
                    LordManager lordManager = map.lordManager;
                    for (int j = 0; j < lordManager.lords.Count; j++)
                    {
                        Lord lord = lordManager.lords[j];
                        if (lord.faction == Util_Faction.MiningCoFaction)
                        {
                            lord.ReceiveMemo("BecameHostileToColony");
                        }
                    }
                }
            }

            /*else
             * {
             *  flag2 = false;
             * }
             * if (canSendMessage && !flag && !flag2 && Current.ProgramState == ProgramState.Playing && (faction.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);
        }