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);
            }
        }
        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;
        }
예제 #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
                 ));
        }