Ejemplo n.º 1
0
        static bool Prefix(PartyBase party, float renownValueOfBattle, float contributionShare, StatExplainer explanation, ref float __result)
        {
            bool patched = false;

            try
            {
                if (party.LeaderHero != null && party.LeaderHero == Hero.MainHero)
                {
                    ExplainedNumber stat;
                    stat = new ExplainedNumber((renownValueOfBattle * contributionShare) * Settings.Instance.BattleRenownMultiplier, explanation);

                    if (party.IsMobile)
                    {
                        if (party.MobileParty.HasPerk(DefaultPerks.TwoHanded.Notorious))
                        {
                            PerkHelper.AddPerkBonusForParty(DefaultPerks.TwoHanded.Notorious, party.MobileParty, ref stat);
                        }
                        if (party.MobileParty.HasPerk(DefaultPerks.Charm.ShowYourScars))
                        {
                            PerkHelper.AddPerkBonusForParty(DefaultPerks.Charm.ShowYourScars, party.MobileParty, ref stat);
                        }
                    }
                    __result = stat.ResultNumber;
                    patched  = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"An error occurred during DefaultBattleRewardModelPatch. Reverting to original behaviour...\n\nException:\n{ex.Message}\n\n{ex.InnerException?.Message}\n\n{ex.InnerException?.InnerException?.Message}");
            }
            return(!patched);
        }
        static bool Prefix(PartyBase party, float renownValueOfBattle, float contributionShare, StatExplainer explanation, ref float __result)
        {
            bool patched = false;

            try
            {
                var battleRenownMultiplier = 1f;

                if (Settings.Instance.BattleRewardApplyToAI || party.LeaderHero != null && party.LeaderHero == Hero.MainHero)
                {
                    battleRenownMultiplier = Settings.Instance.BattleRenownMultiplier;
                }

                var stat = new ExplainedNumber((renownValueOfBattle * contributionShare) * battleRenownMultiplier, explanation);

                //TODO:: Implement this the same as native in next game update
                //if (party.IsMobile && party.MobileParty.HasPerk(DefaultPerks.Charm.ShowYourScars))
                //{
                //        PerkHelper.AddPerkBonusForParty(DefaultPerks.Charm.ShowYourScars, party.MobileParty, ref stat);
                //}
                if (party.IsMobile && party.Leader != null && party.Leader.HeroObject != null && party.LeaderHero.GetPerkValue(DefaultPerks.Charm.ShowYourScars))
                {
                    PerkHelper.AddPerkBonusForParty(DefaultPerks.Charm.ShowYourScars, party.MobileParty, true, ref stat);
                }

                __result = stat.ResultNumber;
                patched  = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show($"An error occurred during DefaultBattleRewardModelRenownPatch. Reverting to original behaviour...\n\nException:\n{ex.Message}\n\n{ex.InnerException?.Message}\n\n{ex.InnerException?.InnerException?.Message}");
            }

            return(!patched);
        }
Ejemplo n.º 3
0
        private static float CalculateMoralGain(IEnumerable <PartyBase> attackers)
        {
            var moraleGain = new ExplainedNumber(4f);
            var perk       = ActivePatch._perk;

            foreach (var attacker in attackers)
            {
                PerkHelper.AddPerkBonusForParty(perk, attacker.MobileParty, ref moraleGain);
            }

            return(moraleGain.ResultNumber);
        }
Ejemplo n.º 4
0
        private static void ApplyPerkBonusToRaidHit(MapEvent __instance, float hitDamage)
        {
            var perk = ActivePatch._perk;
            var partyMemberHitDamage = new ExplainedNumber(hitDamage);

            foreach (var party in __instance.AttackerSide.Parties.Where(x => x.MobileParty != null))
            {
                PerkHelper.AddPerkBonusForParty(perk, party.MobileParty, ref partyMemberHitDamage);
            }

            RaidingHelper.SetHitDamage(__instance, partyMemberHitDamage.ResultNumber);
        }
        private static void ApplyPerkExtraRewardBonusToRaidHit(MapEvent __instance, float hitDamage)
        {
            var perk = ActivePatch._perk;
            var partyMemberHitDamage = new ExplainedNumber(hitDamage);

            foreach (var party in __instance.AttackerSide.Parties.Where(x => x.MobileParty != null))
            {
                PerkHelper.AddPerkBonusForParty(perk, party.MobileParty, ref partyMemberHitDamage);
            }

            var damageBonus = partyMemberHitDamage.ResultNumber - partyMemberHitDamage.BaseNumber;

            RaidingHelper.SetHitDamage(__instance, partyMemberHitDamage.ResultNumber);
            RaidingHelper.IncreaseSettlementHitPoints(__instance, damageBonus);
        }
        private static void CalculateBonusFlatHpAndRateFromPerk(SiegeEvent.SiegeEngineConstructionProgress justDeployedEngine,
                                                                ISiegeEventSide sideSiegeEvent, out float bonusFlatHp, out float bonusHpRate)
        {
            var perk = ActivePatch._perk;
            var partyMemberHealth = new ExplainedNumber(justDeployedEngine.SiegeEngine.MaxHitPoints);
            var partyMemberRate   = new ExplainedNumber(100);

            foreach (var siegeParty in sideSiegeEvent.SiegeParties.Where(x => x.MobileParty != null))
            {
                PerkHelper.AddPerkBonusForParty(perk, siegeParty.MobileParty, ref partyMemberHealth);
                PerkHelper.AddPerkBonusForParty(perk, siegeParty.MobileParty, ref partyMemberRate);
            }

            bonusFlatHp = partyMemberHealth.ResultNumber - partyMemberHealth.BaseNumber;
            bonusHpRate = partyMemberRate.ResultNumber - partyMemberRate.BaseNumber;
        }
        // Token: 0x06002010 RID: 8208 RVA: 0x00083220 File Offset: 0x00081420
        private float GetWoundedModifier(int totalMenCount, int numWounded, MobileParty party)
        {
            numWounded -= totalMenCount / 4;
            if (numWounded <= 0)
            {
                return(0f);
            }
            if (totalMenCount == 0)
            {
                return(-0.5f);
            }
            float           baseNumber      = Math.Max(-0.8f, -0.05f * (float)numWounded / (float)totalMenCount);
            ExplainedNumber explainedNumber = new ExplainedNumber(baseNumber, null);

            PerkHelper.AddPerkBonusForParty(DefaultPerks.Medicine.MobileAid, party, ref explainedNumber);
            return(explainedNumber.ResultNumber);
        }
Ejemplo n.º 8
0
        private static void CalculateBonusDamageAndRates(
            SiegeEngineType siegeEngineType,
            ISiegeEventSide siegeEventSide, out float bonusRateOnly, out float bonusDamageOnly)
        {
            var perk              = ActivePatch._perk;
            var baseDamage        = siegeEngineType.Damage;
            var partyMemberDamage = new ExplainedNumber(baseDamage);
            var partyMemberRate   = new ExplainedNumber(100f);
            var parties           = siegeEventSide.SiegeParties.Where(x => x.MobileParty != null);

            foreach (var party in parties)
            {
                PerkHelper.AddPerkBonusForParty(perk, party.MobileParty, ref partyMemberRate);
                PerkHelper.AddPerkBonusForParty(perk, party.MobileParty, ref partyMemberDamage);
            }

            bonusRateOnly   = partyMemberRate.ResultNumber - 100;
            bonusDamageOnly = partyMemberDamage.ResultNumber - baseDamage;
        }
Ejemplo n.º 9
0
        public static bool GetDailyHealingHpForHeroes(ref float __result, MobileParty party, StatExplainer explanation, TextObject ____settlementText, TextObject ____starvingText, TextObject ____bushDoctorPerkText)
        {
            ExplainedNumber explainedNumber = new ExplainedNumber(2f, explanation, null);

            SkillHelper.AddSkillBonusForParty(DefaultSkills.Medicine, DefaultSkillEffects.HealingRateBonus, party, ref explainedNumber);
            if (party.CurrentSettlement != null || party.LastVisitedSettlement != null && party.LastVisitedSettlement.IsVillage && party.LastVisitedSettlement.Position2D.DistanceSquared(party.Position2D) < 1f)
            {
                explainedNumber.Add(5f, ____settlementText);
            }
            if (!party.IsGarrison && !party.IsMilitia)
            {
                if (party.PartyMoveMode != MoveModeType.Hold)
                {
                    PerkHelper.AddPerkBonusForParty(DefaultPerks.Medicine.WalkItOff, party, ref explainedNumber);
                }
                else
                {
                    PerkHelper.AddPerkBonusForParty(DefaultPerks.Medicine.TriageTent, party, ref explainedNumber);
                }
            }
            if (party.Morale >= Campaign.Current.Models.PartyMoraleModel.HighMoraleValue)
            {
                PerkHelper.AddPerkBonusForParty(DefaultPerks.Medicine.BestMedicine, party, ref explainedNumber);
            }
            if (party.CurrentSettlement != null)
            {
                explainedNumber.Add(5f, ____settlementText);
                if (party.CurrentSettlement.IsTown && party.SiegeEvent == null && !party.CurrentSettlement.IsUnderSiege)
                {
                    PerkHelper.AddPerkBonusForParty(DefaultPerks.Medicine.GoodLodging, party, ref explainedNumber);
                }
            }
            else if (!party.IsMoving && party.LastVisitedSettlement != null && party.LastVisitedSettlement.IsVillage && party.LastVisitedSettlement.Position2D.DistanceSquared(party.Position2D) < 1f && !party.IsRaiding && !party.LastVisitedSettlement.IsUnderRaid && party.HasPerk(DefaultPerks.Medicine.BushDoctor))
            {
                explainedNumber.AddFactor(DefaultPerks.Medicine.BushDoctor.SecondaryBonus, ____bushDoctorPerkText);
            }
            if (party.Party.IsStarving && party.CurrentSettlement == null)
            {
                explainedNumber.Add(-5f, ____starvingText);
            }
            __result = explainedNumber.ResultNumber;
            return(false);
        }
Ejemplo n.º 10
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);
        }
        public static bool Prefix(ref float __result,
                                  PartyBase party,
                                  CharacterObject character,
                                  DamageTypes damageType,
                                  PartyBase enemyParty = null)
        {
            if (character.IsHero)
            {
                if (character.HeroObject.AlwaysDie)
                {
                    __result = 0.0f;
                    return(false);
                }
                if (character.HeroObject.AlwaysUnconscious)
                {
                    __result = 1f;
                    return(false);
                }
            }

            bool  hasDamageData       = BasicCharacterObjectCustomMembers.ExcessiveDamages.TryRemove(character.Id, out float excessiveDamage);
            float damageTypeDeathRate = damageType == DamageTypes.Blunt ?
                                        SubModule.Settings.Battle_SurviveByArmor_BluntDeathRate : 1.0f;

            bool  useMedicine;
            bool  useLevel;
            bool  useArmor;
            float baseDeathRate;

            if (SubModule.Settings.Battle_SurviveByArmor_SurviveByExcessiveDamage && hasDamageData)
            {
                baseDeathRate = GetExcessiveDamageDeathRate(excessiveDamage);
                useMedicine   = SubModule.Settings.Battle_SurviveByArmor_ApplyMedicine;
                useLevel      = SubModule.Settings.Battle_SurviveByArmor_ApplyLevel;
                useArmor      = SubModule.Settings.Battle_SurviveByArmor_ApplyArmor;
            }
            else
            {
                baseDeathRate = 1.0f;
                useMedicine   = true;
                useLevel      = !SubModule.Settings.Battle_SurviveByArmor_SurviveByArmorValue;
                useArmor      = SubModule.Settings.Battle_SurviveByArmor_SurviveByArmorValue;
            }

            ExplainedNumber stat = new ExplainedNumber(character.IsHero ? 10f : 1f, (StringBuilder)null);

            if (party != null && party.MobileParty != null)
            {
                if (useMedicine)
                {
                    SkillHelper.AddSkillBonusForParty(DefaultSkills.Medicine, DefaultSkillEffects.SurgeonSurvivalBonus, party.MobileParty, ref stat);
                    if (enemyParty?.MobileParty != null && enemyParty.MobileParty.HasPerk(DefaultPerks.Medicine.DoctorsOath))
                    {
                        SkillHelper.AddSkillBonusForParty(DefaultSkills.Medicine, DefaultSkillEffects.SurgeonSurvivalBonus, enemyParty.MobileParty, ref stat);
                    }
                    if (character.IsHero && (party.MobileParty.Leader?.HeroObject != null && party.MobileParty.LeaderHero != character.HeroObject))
                    {
                        PerkHelper.AddPerkBonusForParty(DefaultPerks.Medicine.FortitudeTonic, party.MobileParty, ref stat);
                    }
                }
                if (useArmor)
                {
                    try
                    {
                        float head       = character.GetHeadArmorSum();
                        float body       = character.GetBodyArmorSum();
                        float arm        = character.GetArmArmorSum();
                        float leg        = character.GetLegArmorSum();
                        float totalArmor = head + body + arm + leg;
                        stat.Add(totalArmor / SubModule.Settings.Battle_SurviveByArmor_ArmorValueThreshold * 16f * 0.03f, (TextObject)null);
                    }
                    catch (NullReferenceException)
                    {
                        // Cannot find FirstBattleEquipment for the troop, possible the troop is added by other mods
                        stat.Add((float)character.Level * 0.03f, (TextObject)null);
                    }
                }
                if (useLevel)
                {
                    stat.Add((float)character.Level * 0.03f, (TextObject)null);
                }
            }
            float deathRate = damageTypeDeathRate * baseDeathRate / stat.ResultNumber;

            __result = 1.0f - deathRate;
            if (__result < 0f)
            {
                __result = 0f;
            }
            if (__result > 1f)
            {
                __result = 1f;
            }

            return(false);
        }