Beispiel #1
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;
            }
        }