Example #1
0
        public static bool CanDeclareWar(IFaction faction, IFaction faction2, bool checkNears = false, bool checkTruce = false)
        {
            var atWars  = Kingdom.All.Where(a => a != faction && a.IsAtWarWith(faction)).Count();
            var atWars2 = Kingdom.All.Where(a => a != faction2 && a.IsAtWarWith(faction2)).Count();

            if (atWars > 1 || atWars2 > 2 || (checkTruce && DiplomacySetting.InTruce(faction, faction2)))
            {
                return(false);
            }

            if (checkNears)
            {
                var nears = DiplomacySetting.GetNearFactionsWithFaction(faction, Kingdom.All, 4);
                if (!nears.Exists(a => a.MapFaction == faction2.MapFaction))
                {
                    return(false);
                }
            }

            var settlementByOccupyed = GetAllFactionOccupyFactionSettlement(faction).ToList();

            var rate = (atWars > 1 ? 1f : (atWars == 1 ? 0.5f : 0.1f));

            if (settlementByOccupyed.Count != 0 && !settlementByOccupyed.Contains(faction2) && MBRandom.RandomFloat < rate)
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        public static Dictionary <IFaction, List <Settlement> > GetFactionSettlementOccupyedByOtherFactions(IFaction faction)
        {
            Dictionary <IFaction, List <Settlement> > factions = new Dictionary <IFaction, List <Settlement> >();

            if (!faction.IsKingdomFaction || !DiplomacySetting.GetAllFactionOriginalSettlement().ContainsKey(faction.MapFaction))
            {
                return(factions);
            }

            foreach (var item in DiplomacySetting.GetAllFactionOriginalSettlement()[faction.MapFaction])
            {
                if (item.OwnerClan.MapFaction != faction.MapFaction)
                {
                    if (!factions.ContainsKey(item.OwnerClan.MapFaction))
                    {
                        factions.Add(item.OwnerClan.MapFaction, new List <Settlement> {
                            item
                        });
                    }
                    else
                    {
                        factions[item.OwnerClan.MapFaction].Add(item);
                    }
                }
            }
            return(factions);
        }
Example #3
0
        public static List <Settlement> GetFactionSettlementOccupyedByFaction(IFaction faction, IFaction other)
        {
            var factions = DiplomacySetting.GetFactionSettlementOccupyedByOtherFactions(faction);

            if (factions.ContainsKey(other))
            {
                return(factions[other]);
            }
            return(new List <Settlement>());
        }
Example #4
0
        public static bool InTruce(IFaction faction, IFaction faction2)
        {
            var days = DiplomacySetting.GetElapsedDaysSinceTruceWithFaction(faction, faction2);

            if (days < DiplomacySetting.Instance.TruceDays)
            {
                return(true);
            }
            return(false);
        }
Example #5
0
 public DiplomacySetting()
 {
     Instance = this;
 }
Example #6
0
 public static List <IFaction> GetAllFactionOccupyFactionSettlement(IFaction faction)
 {
     return(DiplomacySetting.GetFactionSettlementOccupyedByOtherFactions(faction).Keys.ToList());
 }