public static void DefectKingdomDebug(Clan clan, Kingdom kingdom)
        {
            if (!SettingsHelper.SystemDebugEnabled(AOSystems.EnsuredLoyalty, DebugType.General, new List <IFaction>()
            {
                clan, kingdom
            }))
            {
                return;
            }

            InDebugBranch = true;
            JoinKingdomAsClanBarterable asClanBarterable = new JoinKingdomAsClanBarterable(clan.Leader, kingdom);
            int  ClanBarterableValueForClan    = asClanBarterable.GetValueForFaction(clan);
            int  ClanBarterableValueForKingdom = asClanBarterable.GetValueForFaction(kingdom);
            bool NativeDecision = ClanBarterableValueForClan + ClanBarterableValueForKingdom <= 0;

            TextObject ResultTextObject = new TextObject(Debug_Defect);

            StringHelper.SetEntitiyProperties(ResultTextObject, "LEAVING_CLAN", clan, true);
            StringHelper.SetEntitiyProperties(ResultTextObject, "TARGET_KINGDOM", kingdom);
            StringHelper.SetNumericVariable(ResultTextObject, "CURRENT_BARTERABLE", ClanBarterableValueForClan, "N0");
            StringHelper.SetNumericVariable(ResultTextObject, "TARGET_BARTERABLE", ClanBarterableValueForKingdom, "N0");
            ResultTextObject.SetTextVariable("CLAN_DECISION", NativeDecision ? StayDecision : LeaveDecision);

            bool IsLoyaltyEnsured = LoyaltyManager.CheckLoyalty(clan, out TextObject LoyaltyTextObject, kingdom);

            LoyaltyTextObject.SetTextVariable("TRANSITION_PART", NativeDecision == IsLoyaltyEnsured ? LoyaltyManager.TransitionFromSame : LoyaltyManager.TransitionFromDifferent);
            ResultTextObject.SetTextVariable("ENSURED_LOYALTY_RESULT", LoyaltyTextObject);

            MessageHelper.SimpleMessage(ResultTextObject);
            InDebugBranch = false;
        }
        public static bool MigrationPrefix(Clan clan1, Kingdom kingdom) //Bool prefixes compete with each other and skip others, as well as original, if return false
        {
            try
            {
                if (kingdom.Leader != Hero.MainHero)
                {
                    return(true);
                }

                JoinKingdomAsClanBarterable asClanBarterable = new JoinKingdomAsClanBarterable(clan1.Leader, kingdom);
                int valueForFaction1 = asClanBarterable.GetValueForFaction(clan1);
                int valueForFaction2 = asClanBarterable.GetValueForFaction(kingdom);
                int checkSum         = valueForFaction1 + valueForFaction2;
                int num2             = (valueForFaction1 < 0) ? -valueForFaction1 : 0;
                if (checkSum <= 0 || num2 > kingdom.Leader.Gold * 0.5)
                {
                    return(false);
                }

                MigrationManager.AwaitPlayerDecision(clan1);
                return(false);
            }
            catch (Exception ex)
            {
                MethodInfo?methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
                DebugHelper.HandleException(ex, methodInfo, "Harmony patch for ConsiderDefection");
                return(true);
            }
        }
Ejemplo n.º 3
0
        private ComplexCost GetWithholdCost()
        {
            if (!SettingsHelper.SubSystemEnabled(SubSystemType.LoyaltyWithholding, LeavingClan))
            {
                return(null);
            }

            if (TargetKingdom != null)
            {
                JoinKingdomAsClanBarterable asClanBarterable = new JoinKingdomAsClanBarterable(LeavingClan.Leader, TargetKingdom);
                int ClanBarterableValueForClan    = asClanBarterable.GetValueForFaction(LeavingClan);
                int ClanBarterableValueForKingdom = asClanBarterable.GetValueForFaction(TargetKingdom);
                ClanBarterable = asClanBarterable;
                BarterableSum  = ClanBarterableValueForClan + ClanBarterableValueForKingdom;
            }
            else
            {
                LeaveKingdomAsClanBarterable asClanBarterable = new LeaveKingdomAsClanBarterable(LeavingClan.Leader, null);
                int ClanBarterableValueForFaction             = asClanBarterable.GetValueForFaction(LeavingClan);
                ClanBarterable = asClanBarterable;
                BarterableSum  = ClanBarterableValueForFaction - (LeavingClan.IsMinorFaction ? 500 : 0);
            }

            if (BarterableSum <= Settings.Instance.WithholdToleranceLimit * 1000000)
            {
                return(null);
            }
            BaseCalculatedCost = Math.Sqrt(BarterableSum) / Math.Log10(BarterableSum);

            return
                (new ComplexCost
                 (
                     (int)(BaseCalculatedCost * Settings.Instance.WithholdInfluenceMultiplier),
                     Settings.Instance.UseWithholdBribing && Settings.Instance.WithholdToleranceLimitForBribes * 1000000 < BarterableSum ? (int)BaseCalculatedCost * Settings.Instance.WithholdGoldMultiplier : 0
                 ));
        }
Ejemplo n.º 4
0
        public static void Postfix(IFaction factionForEvaluation, int __result, JoinKingdomAsClanBarterable __instance)
        {
            try
            {
                Hero iOriginalOwner     = __instance.OriginalOwner;
                Clan iOriginalOwnerClan = iOriginalOwner.Clan;

                if (!LoyaltyDebugHelper.InDebugBranch || !SettingsHelper.SystemDebugEnabled(AOSystems.EnsuredLoyalty, DebugType.Technical, new List <IFaction>()
                {
                    factionForEvaluation, iOriginalOwnerClan
                }))
                {
                    return;
                }

                Kingdom   iOriginalOwnerKingdom = iOriginalOwnerClan.Kingdom;
                Kingdom   iTargetKingdom        = __instance.TargetKingdom;
                PartyBase iOriginalParty        = __instance.OriginalParty;
                //Hero leader = iOriginalOwner.MapFaction.Leader;

                float CalculatedResult = -1000000f;
                int   valueForFaction  = 0;
                float settlementValue  = 0f;

                float ScoreOfClanToJoinKingdom = Campaign.Current.Models.DiplomacyModel.GetScoreOfClanToJoinKingdom(iOriginalOwnerClan, iTargetKingdom);
                float ScoreOfKingdomToGetClan  = Campaign.Current.Models.DiplomacyModel.GetScoreOfKingdomToGetClan(iTargetKingdom, iOriginalOwnerClan);

                if (iTargetKingdom.IsKingdomFaction)
                {
                    if (factionForEvaluation == iOriginalOwnerClan)
                    {
                        CalculatedResult = ScoreOfClanToJoinKingdom;
                        if (iOriginalOwnerKingdom != null)
                        {
                            valueForFaction = new LeaveKingdomAsClanBarterable(iOriginalOwner, iOriginalParty).GetValueForFaction(factionForEvaluation);
                            if (!iTargetKingdom.IsAtWarWith(iOriginalOwnerKingdom))
                            {
                                settlementValue   = iOriginalOwnerClan.CalculateSettlementValue(iOriginalOwnerKingdom);
                                CalculatedResult -= settlementValue;
                            }
                            CalculatedResult += valueForFaction;
                        }
                    }
                    else if (factionForEvaluation.MapFaction == iTargetKingdom)
                    {
                        CalculatedResult = ScoreOfKingdomToGetClan;
                    }
                }
                string UnitValueDebugInfo = string.Format("JoinKingdom - UnitValueForFaction. factionForEvaluation: {0}." +
                                                          " ScoreOfClanToJoinKingdom = {1}. GetScoreOfKingdomToGetClan = {2}. ValueForFaction = {3}. SettlementValue = {4}. CalculatedResult = {5}. NativeResult = {6}",
                                                          (factionForEvaluation != null) ? factionForEvaluation.Name.ToString() : "is null",
                                                          ScoreOfClanToJoinKingdom.ToString("N"),
                                                          ScoreOfKingdomToGetClan.ToString("N"),
                                                          valueForFaction.ToString("N"), settlementValue.ToString("N"), CalculatedResult.ToString("N"), __result.ToString("N"));

                MessageHelper.TechnicalMessage(UnitValueDebugInfo);
            }
            catch (Exception ex)
            {
                MethodInfo methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
                DebugHelper.HandleException(ex, methodInfo, "Harmony patch for JoinKingdomAsClanBarterable.GetUnitValueForFaction");
            }
        }