Example #1
0
        internal static IEnumerable <CodeInstruction> CalculateBasePartySpeedPatch(IEnumerable <CodeInstruction> ins)
        {
            // ReSharper disable once EntityNameCapturedOnly.Local
            float SlowBM(MobileParty mobileParty, float input)
            {
                if (PartyMilitiaMap.ContainsKey(mobileParty))
                {
                    return(input * 0.15f);
                }

                return(input);
            }

            var codes = ins.ToListQ();

            for (var index = 0; index < codes.Count; index++)
            {
                if (codes[index].opcode == OpCodes.Call &&
                    codes[index + 1].opcode == OpCodes.Stloc_S &&
                    codes[index + 2].opcode == OpCodes.Ldloca_S &&
                    codes[index + 3].opcode == OpCodes.Ldloc_S)
                {
                    codes.InsertRange(index + 1, new List <CodeInstruction>
                    {
                        new(OpCodes.Dup),
                        new(OpCodes.Ldarg_1),
                        new(OpCodes.Call, AccessTools.Method(typeof(MilitiaPatches), nameof(SlowBM)))
                    });
Example #2
0
 private static void Postfix(MobileParty mobileParty, ref ExplainedNumber __result)
 {
     if (PartyMilitiaMap.ContainsKey(mobileParty))
     {
         __result.AddFactor(SpeedModifier, new TextObject("Bandit Militia"));
     }
 }
Example #3
0
 private static void Postfix(MobileParty __instance, MobileParty targetParty, ref bool __result)
 {
     if (__result &&
         !targetParty.IsGarrison &&
         !targetParty.IsMilitia &&
         PartyMilitiaMap.ContainsKey(__instance))
     //Militias.Any(x => x.MobileParty == __instance))
     {
         if (targetParty == MobileParty.MainParty)
         {
             __result = true;
         }
         else
         {
             var party1Strength = __instance.GetTotalStrengthWithFollowers();
             var party2Strength = targetParty.GetTotalStrengthWithFollowers();
             var delta          = (party1Strength - party2Strength) / party1Strength * 100;
             __result = delta <= Globals.Settings.PartyStrengthDeltaPercent;
         }
     }
 }
Example #4
0
 internal static bool IsBM(MobileParty mobileParty)
 {
     return(mobileParty != null &&
            PartyMilitiaMap.ContainsKey(mobileParty));
 }
Example #5
0
            private static void Postfix()
            {
                try
                {
                    if (Campaign.Current.TimeControlMode == CampaignTimeControlMode.Stop ||
                        Campaign.Current.TimeControlMode == CampaignTimeControlMode.UnstoppableFastForwardForPartyWaitTime ||
                        Campaign.Current.TimeControlMode == CampaignTimeControlMode.FastForwardStop ||
                        Campaign.Current.TimeControlMode == CampaignTimeControlMode.StoppableFastForward ||
                        GlobalMilitiaPower > CalculatedGlobalPowerLimit)
                    {
                        return;
                    }

                    var parties = MobileParty.All.Where(x =>
                                                        x.Party.IsMobile &&
                                                        x.CurrentSettlement == null &&
                                                        !x.IsCurrentlyUsedByAQuest &&
                                                        x.IsBandit).ToList();
                    //T.Restart();
                    for (var index = 0; index < parties.Count; index++)
                    {
                        var mobileParty = parties[index];
                        if (mobileParty.MoveTargetParty != null &&
                            mobileParty.MoveTargetParty.IsBandit ||
                            // Calradia Expanded Kingdoms
                            mobileParty.ToString().Contains("manhunter") ||
                            mobileParty.IsTooBusyToMerge())
                        {
                            continue;
                        }

                        CampaignTime?lastChangeDate = null;
                        if (PartyMilitiaMap.ContainsKey(mobileParty))
                        {
                            lastChangeDate = PartyMilitiaMap[mobileParty].LastMergedOrSplitDate;
                        }

                        if (CampaignTime.Now < lastChangeDate + CampaignTime.Hours(Globals.Settings.CooldownHours))
                        {
                            continue;
                        }

                        var targetParty = MobileParty.FindPartiesAroundPosition(mobileParty.Position2D, FindRadius,
                                                                                x => x != mobileParty && IsValidParty(x) &&
                                                                                x.MemberRoster.TotalManCount + mobileParty.MemberRoster.TotalManCount >= Globals.Settings.MinPartySize)
                                          .ToList().GetRandomElement()?.Party;

                        // "nobody" is a valid answer
                        if (targetParty == null)
                        {
                            continue;
                        }

                        CampaignTime?targetLastChangeDate = null;
                        if (PartyMilitiaMap.ContainsKey(targetParty.MobileParty))
                        {
                            targetLastChangeDate = PartyMilitiaMap[mobileParty].LastMergedOrSplitDate;
                        }

                        if (CampaignTime.Now < targetLastChangeDate + CampaignTime.Hours(Globals.Settings.CooldownHours))
                        {
                            continue;
                        }

                        var militiaTotalCount = mobileParty.MemberRoster.TotalManCount + targetParty.MemberRoster.TotalManCount;
                        if (militiaTotalCount < Globals.Settings.MinPartySize ||
                            militiaTotalCount > CalculatedMaxPartySize ||
                            mobileParty.Party.TotalStrength > CalculatedMaxPartyStrength ||
                            NumMountedTroops(mobileParty.MemberRoster) + NumMountedTroops(targetParty.MemberRoster) > militiaTotalCount / 2)
                        {
                            continue;
                        }

                        if (Campaign.Current.Models.MapDistanceModel.GetDistance(targetParty.MobileParty, mobileParty) > MergeDistance)
                        {
                            Mod.Log($"{mobileParty} seeking > {targetParty.MobileParty}");
                            mobileParty.SetMoveEscortParty(targetParty.MobileParty);
                            //Mod.Log($"SetNavigationModeParty ==> {T.ElapsedTicks / 10000F:F3}ms");

                            if (targetParty.MobileParty.MoveTargetParty != mobileParty)
                            {
                                Mod.Log($"{targetParty.MobileParty} seeking back > {mobileParty}");
                                targetParty.MobileParty.SetMoveEscortParty(mobileParty);
                                //Mod.Log($"SetNavigationModeTargetParty ==> {T.ElapsedTicks / 10000F:F3}ms");
                            }

                            continue;
                        }

                        if (Settlement.FindSettlementsAroundPosition(mobileParty.Position2D, MinDistanceFromHideout, x => x.IsHideout()).Any())
                        {
                            continue;
                        }

                        // create a new party merged from the two
                        var rosters = MergeRosters(mobileParty, targetParty);
                        var militia = new Militia(mobileParty, rosters[0], rosters[1]);
                        militia.MobileParty.SetMovePatrolAroundPoint(militia.MobileParty.Position2D);

                        // teleport new militias near the player
                        if (TestingMode)
                        {
                            // in case a prisoner
                            var party = Hero.MainHero.PartyBelongedTo ?? Hero.MainHero.PartyBelongedToAsPrisoner.MobileParty;
                            militia.MobileParty.Position2D = party.Position2D;
                        }

                        militia.MobileParty.Party.Visuals.SetMapIconAsDirty();
                        Trash(mobileParty);
                        Trash(targetParty.MobileParty);
                        //Mod.Log($">>> Finished all work: {T.ElapsedTicks / 10000F:F3}ms.");
                    }

                    //Mod.Log($"Looped ==> {T.ElapsedTicks / 10000F:F3}ms");
                }
                catch (Exception ex)
                {
                    Mod.Log(ex);
                }
            }