Пример #1
0
        private void ApplyEscapeChanceToExceededPrisoners(CharacterObject character, MobileParty capturerParty)
        {
            const float num = 0.1f;

            if (capturerParty.IsGarrison || capturerParty.IsMilitia || character.IsPlayerCharacter)
            {
                return;
            }

            if (CEApplyExceedChanceToEscape(character, capturerParty))
            {
                return;
            }

            if (!(MBRandom.RandomFloat < num))
            {
                return;
            }
            if (character.IsHero)
            {
                EndCaptivityAction.ApplyByEscape(character.HeroObject);
                return;
            }
            capturerParty.PrisonRoster.AddToCounts(character, -1);
        }
        private static bool Prefix(Hero hero)
        {
            if (!PrisonerEscapeSetting.Instance.IsEnabled)
            {
                return(true);
            }

            if (hero.IsPrisoner && hero.PartyBelongedToAsPrisoner != null && hero != Hero.MainHero)
            {
                var time = (CampaignTime.Now - hero.CaptivityStartTime).ToDays;

                float num = Math.Min((float)(time * time / (PrisonerEscapeSetting.Instance.Basedays * PrisonerEscapeSetting.Instance.Basedays * 10)), 0.075f);

                if (hero.PartyBelongedToAsPrisoner.IsMobile)
                {
                    num *= 6f - (float)Math.Pow(Math.Min(81, hero.PartyBelongedToAsPrisoner.NumberOfHealthyMembers), 0.25);

                    if (hero.PartyBelongedToAsPrisoner.MapFaction.IsBanditFaction)
                    {
                        num *= 100f;
                    }
                }
                if (hero.PartyBelongedToAsPrisoner == PartyBase.MainParty || (hero.PartyBelongedToAsPrisoner.IsSettlement && hero.PartyBelongedToAsPrisoner.Settlement.OwnerClan == Clan.PlayerClan))
                {
                    num *= (hero.PartyBelongedToAsPrisoner.IsSettlement ? 0.5f : 0.33f);
                }

                if (MBRandom.RandomFloat < num)
                {
                    EndCaptivityAction.ApplyByEscape(hero, null);
                }
            }
            return(false);
        }
Пример #3
0
        public void DailyHeroTick(Hero hero)
        {
            if (!hero.IsPrisoner || hero.PartyBelongedToAsPrisoner == null || hero == Hero.MainHero)
            {
                return;
            }

            if (CESettings.Instance.EscapeAutoRansom.SelectedIndex == 1 && hero.Clan != null && hero.PartyBelongedToAsPrisoner.MapFaction != null && MBRandom.RandomFloat < 0.1f)
            {
                // DiplomaticBartersBehavior
                IFaction mapFaction = hero.PartyBelongedToAsPrisoner.MapFaction;
                SetPrisonerFreeBarterable setPrisonerFreeBarterable = new SetPrisonerFreeBarterable(hero, mapFaction.Leader, hero.PartyBelongedToAsPrisoner, hero.Clan.Leader);
                if (setPrisonerFreeBarterable.GetValueForFaction(mapFaction) + setPrisonerFreeBarterable.GetValueForFaction(hero.Clan) > 0)
                {
                    IEnumerable <Barterable> baseBarterables = new Barterable[] { setPrisonerFreeBarterable };

                    BarterData barterData = new BarterData(mapFaction.Leader, hero.Clan.Leader, null, null, null, 0, true);
                    barterData.AddBarterGroup(new DefaultsBarterGroup());
                    foreach (Barterable barterable in baseBarterables)
                    {
                        barterable.SetIsOffered(true);
                        barterData.AddBarterable <DefaultsBarterGroup>(barterable, true);
                    }
                    Campaign.Current.BarterManager.ExecuteAIBarter(barterData, mapFaction, hero.Clan, mapFaction.Leader, hero.Clan.Leader);
                    return;
                }
            }

            if (CEApplyHeroChanceToEscape(hero))
            {
                return;
            }

            float num = 0.075f;

            if (hero.PartyBelongedToAsPrisoner.IsMobile)
            {
                num *= 6f - (float)Math.Pow(Math.Min(81, hero.PartyBelongedToAsPrisoner.NumberOfHealthyMembers), 0.25);
            }

            if (hero.PartyBelongedToAsPrisoner == PartyBase.MainParty || hero.PartyBelongedToAsPrisoner.IsSettlement && hero.PartyBelongedToAsPrisoner.Settlement.OwnerClan == Clan.PlayerClan)
            {
                num *= hero.PartyBelongedToAsPrisoner.IsSettlement
                    ? 0.5f
                    : 0.33f;
            }

            if (MBRandom.RandomFloat < num)
            {
                EndCaptivityAction.ApplyByEscape(hero);
                return;
            }
        }
Пример #4
0
 internal void MakeFreedHeroesEscape(TroopRoster freedTroops)
 {
     for (int i = freedTroops.Count <TroopRosterElement>() - 1; i >= 0; i--)
     {
         CharacterObject characterAtIndex = freedTroops.GetCharacterAtIndex(i);
         if (characterAtIndex.IsHero)
         {
             if (!characterAtIndex.IsPlayerCharacter)
             {
                 EndCaptivityAction.ApplyByReleasedAfterBattle(characterAtIndex.HeroObject, null, null);
             }
             freedTroops.RemoveTroop(characterAtIndex, 1, new UniqueTroopDescriptor(), 0);
         }
     }
 }
 private static bool OnGameLoaded(CampaignGameStarter campaignGameStarter)
 {
     foreach (Settlement settlement in Settlement.All)
     {
         foreach (TroopRosterElement troopRosterElement in settlement.Party.PrisonRoster.GetTroopRoster())
         {
             if (troopRosterElement.Character.IsHero && troopRosterElement.Character.HeroObject != Hero.MainHero && !troopRosterElement.Character.HeroObject.MapFaction.IsAtWarWith(settlement.MapFaction))
             {
                 if (troopRosterElement.Character.HeroObject.PartyBelongedToAsPrisoner == settlement.Party && troopRosterElement.Character.HeroObject.IsPrisoner)
                 {
                     EndCaptivityAction.ApplyByReleasing(troopRosterElement.Character.HeroObject, null);
                 }
                 else
                 {
                     settlement.Party.PrisonRoster.RemoveTroop(troopRosterElement.Character, 1, default, 0);
Пример #6
0
        private void ConsequenceRelease(Companion companion, Hero hero)
        {
            if (!companion.MultipleRestrictedListOfConsequences.Contains(RestrictedListOfConsequences.Leave))
            {
                return;
            }

            try
            {
                EndCaptivityAction.ApplyByReleasing(hero);
            }
            catch (Exception e)
            {
                CECustomHandler.ForceLogToFile("Failure of ConsequenceRelease: " + e.ToString());
            }
        }
Пример #7
0
        private bool CEApplyExceedChanceToEscape(CharacterObject character, MobileParty capturerParty)
        {
            if (CESettings.Instance == null)
            {
                return(false);
            }

            if (!CESettings.Instance.PrisonerExceeded)
            {
                return(true);
            }

            bool isHeroParty = capturerParty.LeaderHero == Hero.MainHero;

            if (character.IsHero)
            {
                bool customCheck = isHeroParty ? CESettings.Instance.PrisonerHeroEscapeParty : CESettings.Instance.PrisonerHeroEscapeOther;
                if (!customCheck)
                {
                    return(false);
                }
                int numEscapeChance = isHeroParty ? CESettings.Instance.PrisonerHeroEscapeChanceParty : CESettings.Instance.PrisonerHeroEscapeChanceOther;
                if (MBRandom.RandomInt(100) < numEscapeChance)
                {
                    EndCaptivityAction.ApplyByEscape(character.HeroObject);
                }
            }
            else
            {
                bool customCheck = isHeroParty ? CESettings.Instance.PrisonerNonHeroEscapeParty : CESettings.Instance.PrisonerNonHeroEscapeOther;
                if (!customCheck)
                {
                    return(false);
                }
                int numEscapeChance = isHeroParty ? CESettings.Instance.PrisonerNonHeroEscapeChanceParty : CESettings.Instance.PrisonerNonHeroEscapeChanceOther;
                if (MBRandom.RandomInt(100) < numEscapeChance)
                {
                    capturerParty.PrisonRoster.AddToCounts(character, -1);
                }
            }

            return(true);
        }
 public static void DailyTick()
 {
     foreach (Hero hero in Hero.All)
     {
         if (hero == null)
         {
             return;
         }
         if (hero.PartyBelongedToAsPrisoner == null && hero.IsPrisoner && hero.IsAlive && !hero.IsActive && !hero.IsNotSpawned && !hero.IsReleased)
         {
             float days = hero.CaptivityStartTime.ElapsedDaysUntilNow;
             if (BannerlordTweaksSettings.Instance is { } settings&& (days > (settings.MinimumDaysOfImprisonment + 3)))
             {
                 DebugHelpers.ColorGreenMessage("Releasing " + hero.Name + " due to Missing Hero Bug. (" + (int)days + " days)");
                 DebugHelpers.QuickInformationMessage("Releasing " + hero.Name + " due to Missing Hero Bug. (" + (int)days + " days)");
                 EndCaptivityAction.ApplyByReleasing(hero);
             }
         }
     }
 }
Пример #9
0
        private bool CEApplyHeroChanceToEscape(Hero hero)
        {
            if (CESettings.Instance == null)
            {
                return(false);
            }

            bool inSettlement = hero.PartyBelongedToAsPrisoner.IsSettlement;

            if (hero.PartyBelongedToAsPrisoner.LeaderHero == Hero.MainHero || inSettlement && hero.PartyBelongedToAsPrisoner.Settlement.OwnerClan == Clan.PlayerClan)
            {
                bool customCheck = inSettlement ? CESettings.Instance.PrisonerHeroEscapeSettlement : CESettings.Instance.PrisonerHeroEscapeParty;
                if (!customCheck)
                {
                    return(false);
                }
                int numEscapeChance = inSettlement ? CESettings.Instance.PrisonerHeroEscapeChanceSettlement : CESettings.Instance.PrisonerHeroEscapeChanceParty;
                if (MBRandom.RandomInt(100) < numEscapeChance)
                {
                    EndCaptivityAction.ApplyByEscape(hero);
                }
            }
            else
            {
                bool customCheck = CESettings.Instance.PrisonerHeroEscapeOther;
                if (!customCheck)
                {
                    return(false);
                }
                int numEscapeChance = CESettings.Instance.PrisonerHeroEscapeChanceOther;
                if (MBRandom.RandomInt(100) < numEscapeChance)
                {
                    EndCaptivityAction.ApplyByEscape(hero);
                }
            }
            return(true);
        }
Пример #10
0
        /// <summary>
        /// Custom CheckCaptivityChange Function
        /// </summary>
        /// <param name="dt"></param>
        /// <returns>EventName</returns>
        public override string CheckCaptivityChange(float dt)
        {
            if (!PlayerCaptivity.IsCaptive)
            {
                return(DefaultOverridenCheckCaptivityChange(dt));
            }

            if (Hero.MainHero.Age < 18f)
            {
                EndCaptivityAction.ApplyByReleasing(Hero.MainHero);
                InformationManager.DisplayMessage(new InformationMessage(("Invalid Age: " + Hero.MainHero.Age), Colors.Gray));
                CECustomHandler.ForceLogToFile("Underaged Player Detected. Age: " + Hero.MainHero.Age);
                return("menu_captivity_end_by_party_removed");
            }

            if (CEHelper.delayedEvents.Count > 0)
            {
                string eventToFire = null;

                bool shouldFireEvent = CEHelper.delayedEvents.Any(item =>
                {
                    if (item.eventName != null && item.eventTime < Campaign.Current.CampaignStartTime.ElapsedHoursUntilNow)
                    {
                        CECustomHandler.LogToFile("Firing " + item.eventName);
                        if (item.conditions == true)
                        {
                            string result = CEEventManager.FireSpecificEvent(item.eventName);
                            switch (result)
                            {
                            case "$FAILEDTOFIND":
                                CECustomHandler.LogToFile("Failed to load event list.");
                                break;

                            case "$EVENTNOTFOUND":
                                CECustomHandler.LogToFile("Event not found.");
                                break;

                            case "$EVENTCONDITIONSNOTMET":
                                CECustomHandler.LogToFile("Event conditions are not met.");
                                break;

                            default:
                                if (result.StartsWith("$"))
                                {
                                    CECustomHandler.LogToFile(result.Substring(1));
                                }
                                else
                                {
                                    eventToFire       = item.eventName;
                                    item.hasBeenFired = true;
                                    return(true);
                                }
                                break;
                            }
                        }
                        else
                        {
                            eventToFire        = item.eventName.ToLower();
                            CEEvent foundevent = CEPersistence.CEEventList.FirstOrDefault(ceevent => ceevent.Name.ToLower() == eventToFire);
                            if (foundevent != null && !foundevent.MultipleRestrictedListOfFlags.Contains(RestrictedListOfFlags.Captive))
                            {
                                eventToFire = null;
                                return(false);
                            }
                            item.hasBeenFired = true;
                            return(true);
                        }
                    }
                    return(false);
                });

                if (shouldFireEvent)
                {
                    CEHelper.delayedEvents.RemoveAll(item => item.hasBeenFired);
                    PlayerCaptivity.LastCheckTime = CampaignTime.Now;
                    return(eventToFire);
                }
            }

            if (PlayerCaptivity.CaptorParty != null && !PlayerCaptivity.CaptorParty.IsSettlement)
            {
                if (!CheckEvent())
                {
                    return(DefaultOverridenCheckCaptivityChange(dt));
                }
                PlayerCaptivity.LastCheckTime = CampaignTime.Now;

                CECustomHandler.LogToFile("About to choose a event!");
                CEEvent captiveEvent = CEEventManager.ReturnWeightedChoiceOfEvents();

                if (captiveEvent != null)
                {
                    return(captiveEvent.Name);
                }
            }
            else
            {
                if (!CheckEvent())
                {
                    return(DefaultOverridenCheckCaptivityChange(dt));
                }
                PlayerCaptivity.LastCheckTime = CampaignTime.Now;

                CECustomHandler.LogToFile("About to choose a settlement event!");
                CEEvent captiveEvent = CEEventManager.ReturnWeightedChoiceOfEvents();

                if (captiveEvent != null)
                {
                    return(captiveEvent.Name);
                }
            }

            return(DefaultOverridenCheckCaptivityChange(dt));
        }
Пример #11
0
        public static bool Prefix(Hero hero)
        {
            bool   result        = true;
            bool   proceed       = false;
            bool   playerProceed = false;
            string text          = " has escaped";

            try
            {
                bool isPlayer = hero.IsPrisoner && hero.PartyBelongedToAsPrisoner != null &&
                                (hero.PartyBelongedToAsPrisoner.IsMobile &&
                                 hero.PartyBelongedToAsPrisoner == PartyBase.MainParty ||
                                 hero.PartyBelongedToAsPrisoner.IsSettlement &&
                                 hero.PartyBelongedToAsPrisoner.Settlement.OwnerClan == Clan.PlayerClan);

                bool  enable           = isPlayer || Support.settings.ai_applied;
                float generalChance    = enable ? (float)Support.settings.general_chance : 1;
                float travelChance     = enable ? (float)Support.settings.traveling_chance : 1;
                float settlementChance = enable ? (float)Support.settings.settlement_chance : 1;

                // ***************************************
                // Original method from decompiled source (except for commented lines)
                // ***************************************
                if (!hero.IsPrisoner || hero.PartyBelongedToAsPrisoner == null || hero == Hero.MainHero)
                {
                    return(false);
                }
                float baseNumber = 0.05f /**/ * generalChance /**/;  // general chance modificaiton
                if (hero.PartyBelongedToAsPrisoner.IsMobile && hero.PartyBelongedToAsPrisoner.MobileParty.CurrentSettlement == null)
                {
                    // travel chance modification
                    baseNumber *= (5f - (float)Math.Pow(Math.Min(81, hero.PartyBelongedToAsPrisoner.NumberOfHealthyMembers), 0.25)) /**/ * travelChance /**/;
                    /**/ text   = " slipped away from " + (hero.IsFemale ? "her" : "his") + " guards and escaped"; /**/
                }
                // settlement chance modification begin
                else if (hero.PartyBelongedToAsPrisoner.IsSettlement)
                {
                    baseNumber *= settlementChance;
                    text        = " is missing from " + (hero.IsFemale ? "her" : "his") + " cell";
                }
                // end
                if (hero.PartyBelongedToAsPrisoner == PartyBase.MainParty || hero.PartyBelongedToAsPrisoner.IsSettlement && hero.PartyBelongedToAsPrisoner.Settlement.OwnerClan == Clan.PlayerClan || hero.PartyBelongedToAsPrisoner.IsMobile && hero.PartyBelongedToAsPrisoner.MobileParty.CurrentSettlement != null && hero.PartyBelongedToAsPrisoner.MobileParty.CurrentSettlement.OwnerClan == Clan.PlayerClan)
                {
                    baseNumber *= 0.5f;
                }
                ExplainedNumber explainedNumber = new ExplainedNumber(baseNumber);
                if (hero.PartyBelongedToAsPrisoner.IsSettlement)
                {
                    if (hero.PartyBelongedToAsPrisoner.Settlement.IsTown)
                    {
                        PerkHelper.AddPerkBonusForTown(DefaultPerks.Riding.MountedPatrols, hero.PartyBelongedToAsPrisoner.Settlement.Town, ref explainedNumber);
                        PerkHelper.AddPerkBonusForTown(DefaultPerks.Roguery.SweetTalker, hero.PartyBelongedToAsPrisoner.Settlement.Town, ref explainedNumber);
                    }
                    if (hero.PartyBelongedToAsPrisoner.Settlement.IsTown || hero.PartyBelongedToAsPrisoner.Settlement.IsCastle)
                    {
                        PerkHelper.AddPerkBonusForTown(DefaultPerks.Engineering.PrisonArchitect, hero.PartyBelongedToAsPrisoner.Settlement.Town, ref explainedNumber);
                    }
                }
                if (hero.PartyBelongedToAsPrisoner.IsMobile)
                {
                    if (hero.Clan != null && hero.Clan.Leader != null && hero.Clan.Leader.GetPerkValue(DefaultPerks.Roguery.FleetFooted))
                    {
                        explainedNumber.AddFactor(DefaultPerks.Roguery.FleetFooted.SecondaryBonus);
                    }
                    if (hero.PartyBelongedToAsPrisoner.MobileParty.HasPerk(DefaultPerks.Riding.MountedPatrols))
                    {
                        PerkHelper.AddPerkBonusForParty(DefaultPerks.Riding.MountedPatrols, hero.PartyBelongedToAsPrisoner.MobileParty, true, ref explainedNumber);
                    }
                    if (hero.PartyBelongedToAsPrisoner.MobileParty.HasPerk(DefaultPerks.Roguery.RansomBroker))
                    {
                        PerkHelper.AddPerkBonusForParty(DefaultPerks.Roguery.RansomBroker, hero.PartyBelongedToAsPrisoner.MobileParty, false, ref explainedNumber);
                    }
                }
                if (hero.PartyBelongedToAsPrisoner.IsMobile && hero.PartyBelongedToAsPrisoner.MobileParty.HasPerk(DefaultPerks.Scouting.KeenSight, true))
                {
                    PerkHelper.AddPerkBonusForParty(DefaultPerks.Scouting.KeenSight, hero.PartyBelongedToAsPrisoner.MobileParty, false, ref explainedNumber);
                }
                if (MBRandom.RandomFloat >= explainedNumber.ResultNumber)
                {
                    // Relation modification begin
                    if (isPlayer && Support.settings.daily_penalty != 0)
                    {
                        Support.ChangeRelation(Hero.MainHero, hero, -Support.settings.daily_penalty);
                        Support.ChangeFamilyRelation(Hero.MainHero, hero, 0, -Support.settings.daily_penalty);
                    }
                    // end
                    return(false);
                }
                EndCaptivityAction.ApplyByEscape(hero);
                // Notification modification begin
                if (isPlayer)
                {
                    Support.LogMessage(hero.Name.ToString() + " " + text);
                }
                // end
                return(false);
            }
            catch (Exception exe) { }

            return(result);
        }
Пример #12
0
 private void LCELordDefeatedLordAnswerReleaseOnConsequence()
 {
     EndCaptivityAction.ApplyByReleasedByPlayerAfterBattle(Hero.OneToOneConversationHero, Hero.MainHero, null);
     _dynamics.RelationsModifier(CharacterObject.OneToOneConversationCharacter.HeroObject, 4, null, true, true);
     DialogHelper.SetDialogString("DEFEAT_LORD_ANSWER", "str_prisoner_released");
 }