Пример #1
0
        public static void DetermineSupport(MakePeaceKingdomDecision __instance, ref float __result, Clan clan, DecisionOutcome possibleOutcome)
        {
            var test1 = new PeaceBarterable(__instance.Kingdom, __instance.FactionToMakePeaceWith, CampaignTime.Years(1f)).GetValueForFaction(clan);

            //InformationManager.DisplayMessage(new InformationMessage(__instance.FactionToMakePeaceWith.Name.ToString() + ":" + test1.ToString()));

            var shouldPeaceBeDeclared = (bool)possibleOutcome.GetType().GetField("ShouldPeaceBeDeclared", BindingFlags.Instance | BindingFlags.Public).GetValue(possibleOutcome);

            if (DiplomacySetting.Instance.EnableMakePeaceStrategyPlus)
            {
                var atWars = (from x in clan.Kingdom.Stances
                              where x.IsAtWar && x.Faction1.IsKingdomFaction && x.Faction2.IsKingdomFaction
                              select x).ToArray <StanceLink>();

                //var plus = 2 * atWars.Length * (float)(new PeaceBarterable(__instance.Kingdom, __instance.FactionToMakePeaceWith, CampaignTime.Years(1f)).GetValueForFaction(clan)) * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence();

                var plus = 1f;

                var settlementsOccupyed = DiplomacySetting.GetFactionSettlementOccupyedByFaction(clan.MapFaction, __instance.FactionToMakePeaceWith).Sum(a => a.IsCastle ? 2 : 3);
                plus *= settlementsOccupyed == 0 ? 0f : (float)Math.Sqrt(settlementsOccupyed);

                StanceLink stanceWith = clan.MapFaction.GetStanceWith(__instance.FactionToMakePeaceWith);

                var toDays = stanceWith.WarStartDate.ElapsedDaysUntilNow;
                //兼容旧档
                if (toDays > 2000)
                {
                    Traverse.Create(stanceWith).Property("WarStartDate").SetValue(CampaignTime.Now);
                    toDays = stanceWith.WarStartDate.ElapsedDaysUntilNow;
                }
                var daysFactor = Math.Min(9, toDays < 20 ? 1 : toDays / 20f);
                var factor     = Math.Max(0, daysFactor - plus);

                var clanMercy = clan.Leader.GetTraitLevel(DefaultTraits.Mercy) * 20;

                if (shouldPeaceBeDeclared)
                {
                    __result += Math.Abs(__result) / 10 * (factor) + clanMercy;
                }
                else
                {
                    //  __result -= Math.Abs(__result) / 10 * (resultFactor) - clanMercy;
                }
            }

            if (__instance.ProposerClan == Clan.PlayerClan && DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision > 0 && __result >= 0)
            {
                var relation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, clan.Leader);
                relation = relation > 0 ? relation : 0;

                if (shouldPeaceBeDeclared)
                {
                    __result += Math.Abs(__result) * DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision * relation / 100f;
                }
                else
                {
                    __result -= Math.Abs(__result) * DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision / 10 * relation / 100f;
                }
            }
        }
        public static bool ConsiderWar(Clan clan, IFaction otherMapFaction)
        {
            if (!clan.IsKingdomFaction || !otherMapFaction.IsKingdomFaction || !DiplomacySetting.CanDeclareWar(clan, otherMapFaction, true, true))
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
        /// <summary>
        /// 显示战争状态
        /// </summary>
        private void ShowWar()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Campaign.Current != null && Campaign.Current.GameStarted && InputKey.End.IsPressed() &&
                Game.Current.GameStateManager.ActiveState.GetType() == typeof(MapState) &&
                !Game.Current.GameStateManager.ActiveState.IsMenuState &&
                !Game.Current.GameStateManager.ActiveState.IsMission)
            {
                string text = "";
                int    num  = 0;
                foreach (Kingdom item in Kingdom.All)
                {
                    if (item != null)
                    {
                        num++;

                        var s = DiplomacySetting.GetAllFactionOccupyFactionSettlement(item).Count;

                        text += $"{num}.{s} {item.Name}({Math.Round(item.MapFaction.TotalStrength)}) 战争于 ";
                        int num2 = 0;
                        foreach (Kingdom item2 in Kingdom.All.OrderBy((Kingdom w) => w.Name.ToString()))
                        {
                            if (item2 != null && !item.Name.Equals(item2.Name) && item.IsAtWarWith(item2))
                            {
                                text += $"{item2.Name} 和 ";
                                num2++;
                            }
                        }

                        text = text.Substring(0, text.Length - 3);

                        //text = ((num2 <= 0) ? (text.Substring(0, text.Length - 8) + " 和平于") : text.Substring(0, text.Length - 5));
                        text += ";\n\n";
                    }
                }
                InformationManager.ShowInquiry(new InquiryData("战争状态", text, isAffirmativeOptionShown: true, isNegativeOptionShown: false, "OK", "", null, null));
            }
        }
Пример #4
0
        public static IFaction GetRandomPossibleDeclarWar(Kingdom kingdom)
        {
            var atWars = Kingdom.All.Where(a => a != kingdom && a.IsAtWarWith(kingdom)).ToList();

            var strength = kingdom.MapFaction.TotalStrength;


            if (atWars.Count > 1)
            {
                return(null);
            }

            if (atWars.Count > 0)
            {
                var avgStrength = atWars.Sum(a => a.MapFaction.TotalStrength) / atWars.Count;

                var avgSettlement = 1f * atWars.Sum(a => a.Settlements.Where(s => s.IsTown || s.IsCastle).Count()) / atWars.Count;

                if (strength < avgStrength * 1.2f)
                {
                    return(null);
                }
            }

            var             nears   = DiplomacySetting.GetNearFactionsWithFaction(kingdom, Kingdom.All);
            float           num     = 0f;
            IFaction        faction = null;
            List <IFaction> occupy  = DiplomacySetting.GetAllFactionOccupyFactionSettlement(kingdom);

            foreach (IFaction item in nears)
            {
                var atWars2 = Kingdom.All.Where(a => a != item && a.IsAtWarWith(item)).Count();

                if (atWars2 > 2)
                {
                    continue;
                }

                float scoreOfDeclaringWar = strength / item.MapFaction.TotalStrength;

                if (item.MapFaction.TotalStrength > strength * 1.2f && atWars2 > 0)
                {
                    scoreOfDeclaringWar = 1f;
                }

                if (occupy.Contains(item))
                {
                    if (DiplomacySetting.InTruce(kingdom, item))
                    {
                        if (atWars2 < 1)
                        {
                            continue;
                        }
                        if (atWars2 < 2 && MBRandom.RandomFloat < 0.5f)
                        {
                            continue;
                        }
                    }

                    scoreOfDeclaringWar *= 2;
                }
                else
                {
                    if (DiplomacySetting.InTruce(kingdom, item))
                    {
                        continue;
                    }
                }

                if (kingdom.Culture == item.Culture)
                {
                    var factor = Math.Max(0.4f, 1 - Kingdom.All.Where(a => a.Settlements != null && a.Settlements.Where(t => t.IsTown).Count() > 3 && (a.Culture != kingdom.Culture || a.Ruler == Hero.MainHero)).Count() * 0.15f);
                    scoreOfDeclaringWar *= factor;
                }

                if (scoreOfDeclaringWar > num)
                {
                    faction = item;
                    num     = scoreOfDeclaringWar;
                }
            }

            if (faction != null && MBRandom.RandomFloat < num * 0.2f)
            {
                if (occupy.Count > 0 && !occupy.Contains(faction))
                {
                    return(null);
                }

                return(faction);
            }
            return(null);
        }
        // [HarmonyPrefix]
        // [HarmonyPatch("ThinkAboutDeclaringWar")]
        private static bool ThinkAboutDeclaringWar(PoliticalStagnationAndBorderIncidentCampaignBehavior __instance, Kingdom kingdom)
        {
            var atWars = Kingdom.All.Where(a => a != kingdom && a.IsAtWarWith(kingdom)).ToList();

            if (atWars.Count > 1)
            {
                return(false);
            }

            List <IFaction> possibleKingdomsToDeclareWar = FactionHelper.GetPossibleKingdomsToDeclareWar(kingdom);


            var             nears   = DiplomacySetting.GetNearFactionsWithFaction(kingdom, Kingdom.All);
            var             results = nears.Intersect(possibleKingdomsToDeclareWar).ToList();
            float           num     = 0f;
            IFaction        faction = null;
            List <IFaction> occupy  = DiplomacySetting.GetAllFactionOccupyFactionSettlement(kingdom);

            foreach (IFaction item in results)
            {
                var factor1 = 1f;

                var atWars2 = Kingdom.All.Where(a => a != item && a.IsAtWarWith(item)).Count();
                if (occupy.Contains(item))
                {
                    if (DiplomacySetting.InTruce(kingdom, item))
                    {
                        if (atWars2 < 1)
                        {
                            continue;
                        }
                        if (atWars2 < 2 && MBRandom.RandomFloat < 0.5f)
                        {
                            continue;
                        }
                    }

                    factor1 = 1.5f;
                }
                else
                {
                    if (atWars2 > 2)
                    {
                        continue;
                    }
                    if (DiplomacySetting.InTruce(kingdom, item))
                    {
                        continue;
                    }
                }

                //float scoreOfDeclaringWar = factor1 * Campaign.Current.Models.DiplomacyModel.GetScoreOfDeclaringWar(kingdom, item);
                float scoreOfDeclaringWar = factor1 * 1f;

                if (kingdom.Culture == item.Culture)
                {
                    var factor = Math.Max(0.1f, 1 - Kingdom.All.Where(a => a.MapFaction != null && a.MapFaction.Settlements.Where(t => t.IsTown).Count() > 3 && (a.Culture != kingdom.Culture || a.Ruler == Hero.MainHero)).Count() * 0.15f);
                    scoreOfDeclaringWar *= factor * 0.5f;
                }

                if (scoreOfDeclaringWar > num)
                {
                    faction = item;
                    num     = scoreOfDeclaringWar;
                }
            }

            if (faction != null && MBRandom.RandomFloat < 0.2f)
            {
                DeclareWarAction.ApplyDeclareWarOverProvocation(kingdom, faction);
            }
            return(false);
        }