Exemplo n.º 1
0
        public static int GetModifiedRelation(this Hero hero, Hero otherHero)
        {
            ExplainedNumber relationBetweenHeroes = new ExplainedNumber(CharacterRelationManager.GetHeroRelation(hero, otherHero), null, null);

            deGetPersonalityEffects(Campaign.Current.Models.DiplomacyModel is DefaultDiplomacyModel defaultDiplomacyModel ? defaultDiplomacyModel : new DefaultDiplomacyModel(), ref relationBetweenHeroes, hero, otherHero);
            return(MBMath.Round(MBMath.ClampFloat(relationBetweenHeroes.ResultNumber + (RelativesHelper.BloodRelatives(hero, otherHero) ? 30f : 0f), -100f, 100f)));
        }
        protected override bool TryGetUnitPositionIndexFromLocalPosition(
            Vec2 localPosition,
            out int fileIndex,
            out int rankIndex)
        {
            Vec2  vec2_1 = new Vec2(0.0f, -this.Radius);
            Vec2  vec2_2 = localPosition - vec2_1;
            float length = vec2_2.Length;

            rankIndex = MBMath.Round((float)(((double)length - (double)this.Radius) / ((double)this.Distance + (double)this.UnitDiameter) * -1.0));
            if (rankIndex < 0 || rankIndex >= this.RankCount)
            {
                fileIndex = -1;
                return(false);
            }
            if ((double)this.Radius - (double)rankIndex * ((double)this.Distance + (double)this.UnitDiameter) < 0.0)
            {
                fileIndex = -1;
                return(false);
            }
            int unitCountOfRank = this.GetUnitCountOfRank(rankIndex);
            int num1            = (this.FileCount - unitCountOfRank) / 2;

            vec2_2.x *= -1f;
            float num2 = vec2_2.RotationInRadians - 3.141593f;

            if ((double)num2 < 0.0)
            {
                num2 += 6.283185f;
            }
            int num3 = MBMath.Round((float)((double)num2 / 2.0 / 3.14159274101257) * (float)unitCountOfRank);

            fileIndex = num3 + num1;
            return(fileIndex >= 0 && fileIndex < this.FileCount);
        }
        public void FormFromDepth(int depth)
        {
            int countWithOverride = this.GetUnitCountWithOverride();

            depth = Math.Min(this.GetMaximumDepth(countWithOverride), depth);
            float num1 = (float)(6.28318548202515 * ((double)this.Distance + (double)this.UnitDiameter) / ((double)this.Interval + (double)this.UnitDiameter));
            int   num2 = MBMath.Round((float)(depth * (depth - 1) / 2) * num1);

            this.FormFromCircumference((float)MBMath.Round((float)((countWithOverride + num2) / depth)) * (this.Interval + this.UnitDiameter));
        }
        public void FormFromCircumference(float circumference)
        {
            int   countWithOverride = this.GetUnitCountWithOverride();
            int   maximumDepth      = this.GetMaximumDepth(countWithOverride);
            float num1     = (float)(6.28318548202515 * ((double)this.Distance + (double)this.UnitDiameter) / ((double)this.Interval + (double)this.UnitDiameter));
            int   num2     = MBMath.Round((float)(maximumDepth * (maximumDepth - 1) / 2) * num1);
            float minValue = (float)Math.Max(0, Math.Min(MBMath.Round((float)((countWithOverride + num2) / maximumDepth)), countWithOverride) - 1) * (this.Interval + this.UnitDiameter);
            float maxValue = (float)Math.Max(0, countWithOverride - 1) * (this.Interval + this.UnitDiameter);

            circumference = MBMath.ClampFloat(circumference, minValue, maxValue);
            this.Width    = circumference + this.UnitDiameter;
        }
        public static void Postfix(ref int __result, CharacterObject character, StatExplainer explanation)
        {
            var result = __result;

            var explainedNumber = new ExplainedNumber(result, explanation);

            var perk = ActivePatch._perk;

            PerkHelper.AddPerkBonusForCharacter(perk, character, ref explainedNumber);

            __result = MBMath.Round(explainedNumber.ResultNumber);
        }
Exemplo n.º 6
0
        private static int ConvertLootToGold(IEnumerable <ItemRosterElement> lootedItemsRecoveredFromCasualties)
        {
            int num = 0;

            foreach (ItemRosterElement lootedItemsRecoveredFromCasualty in lootedItemsRecoveredFromCasualties)
            {
                int amount = lootedItemsRecoveredFromCasualty.Amount;
                EquipmentElement equipmentElement = lootedItemsRecoveredFromCasualty.EquipmentElement;
                num = num + amount * MBMath.Round((float)equipmentElement.GetBaseValue() * 0.5f);
            }
            return(num);
        }
Exemplo n.º 7
0
        private int GetBaseRelationValueOfCurrentGoldCost()
        {
            if (_clan == Clan.PlayerClan)
            {
                return(0);
            }

            float influenceValue            = this.IntValue * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence();
            float relationValuePerInfluence = (float)Campaign.Current.Models.DiplomacyModel.GetRelationValueOfSupportingClan() / Campaign.Current.Models.DiplomacyModel.GetInfluenceCostOfSupportingClan();

            return(MBMath.Round(influenceValue * relationValuePerInfluence));
        }
Exemplo n.º 8
0
        public override void GetXpFromHit(CharacterObject attackerTroop, CharacterObject attackedTroop, int damage, bool isFatal, MissionTypeEnum missionType, out int xpAmount)
        {
            if (attackerTroop == null || attackedTroop == null)
            {
                xpAmount = 0;
                return;
            }
            int num = attackerTroop.MaxHitPoints();

            xpAmount = MBMath.Round(0.4f * ((attackedTroop.GetPower() + 0.5f) * (float)(Math.Min(damage, num) + (isFatal ? num : 0))));
            //There are three things to do here: Tournament Experience, Arena Experience, Troop Experience.
            if (attackerTroop.IsHero)
            {
                if (missionType == MissionTypeEnum.Tournament)
                {
                    if (Settings.Instance.TournamentHeroExperienceMultiplierEnabled)
                    {
                        xpAmount = (int)Math.Round(Settings.Instance.TournamentHeroExperienceMultiplier * (float)xpAmount);
                    }
                    else
                    {
                        xpAmount = MathF.Round((float)xpAmount * 0.25f);
                    }
                }
                else if (missionType == MissionTypeEnum.PracticeFight)
                {
                    if (Settings.Instance.ArenaHeroExperienceMultiplierEnabled)
                    {
                        xpAmount = (int)Math.Round(Settings.Instance.ArenaHeroExperienceMultiplier * (float)xpAmount);
                    }
                    else
                    {
                        xpAmount = MathF.Round((float)xpAmount * 0.0625f);
                    }
                }
            }
            else if ((missionType == MissionTypeEnum.Battle || missionType == MissionTypeEnum.SimulationBattle))
            {
                if (Settings.Instance.TroopBattleSimulationExperienceMultiplierEnabled && missionType == MissionTypeEnum.SimulationBattle)
                {
                    xpAmount = (int)Math.Round(xpAmount * Settings.Instance.TroopBattleSimulationExperienceMultiplier);
                }
                else if (missionType == MissionTypeEnum.SimulationBattle)
                {
                    xpAmount *= 8;
                }
                else if (Settings.Instance.TroopBattleExperienceMultiplierEnabled && missionType == MissionTypeEnum.Battle)
                {
                    xpAmount = (int)Math.Round(xpAmount * Settings.Instance.TroopBattleExperienceMultiplier);
                }
            }
        }
        private static void FormFromCircumference(TaleWorlds.MountAndBlade.CircularFormation circularFormation, float circumference,
                                                  int countWithOverride, int maximumDepth, float distance, float interval, float unitDiameter)
        {
            float num1     = (float)(6.28318548202515 * (distance + (double)unitDiameter) / (interval + (double)unitDiameter));
            int   num2     = MBMath.Round(maximumDepth * (maximumDepth - 1) / 2 * num1);
            float minValue =
                Math.Max(0, Math.Min(MBMath.Round((countWithOverride + num2) / maximumDepth), countWithOverride)) *
                (interval + unitDiameter);
            float maxValue = Math.Max(0, countWithOverride - 1) * (interval + unitDiameter);

            circumference           = MBMath.ClampFloat(circumference, minValue, maxValue);
            circularFormation.Width = circumference + unitDiameter;
        }
Exemplo n.º 10
0
        public void FillHeroData(HeroAdminCharacter hero)
        {
            this._hero             = hero;
            this.CurrentFocusLevel = hero.GetFocusValue(this.Skill);
            int        boundAttributeCurrentValue = hero.GetAttributeValue(this.Skill.CharacterAttributeEnum);
            TextObject boundAttributeName         = CharacterAttributes.GetCharacterAttribute(this.Skill.CharacterAttributeEnum).Name;
            float      num = Campaign.Current.Models.CharacterDevelopmentModel.CalculateLearningRate(boundAttributeCurrentValue, this.CurrentFocusLevel, this.Level, this._hero.Level, boundAttributeName, false).ResultNumber;

            this.LearningRate          = num;
            this.CanLearnSkill         = (num > 0f);
            this.FullLearningRateLevel = MBMath.Round(Campaign.Current.Models.CharacterDevelopmentModel.CalculateLearningLimit(boundAttributeCurrentValue, this.CurrentFocusLevel, boundAttributeName, false).ResultNumber);
            this.Level = hero.GetSkillValue(this._skillObject);
            RefreshPerks();
        }
Exemplo n.º 11
0
        private static bool Prefix(CharacterObject attackerTroop, CharacterObject attackedTroop, int damage, bool isFatal, CombatXpModel.MissionTypeEnum missionType, out int xpAmount)
        {
#if VERSION111
            int num = attackedTroop.MaxHitPoints();
            xpAmount = MBMath.Round(0.4f * ((attackedTroop.GetPower() + 0.5f) * (float)(Math.Min(damage, num) + (isFatal ? num : 0))));

            if (missionType == CombatXpModel.MissionTypeEnum.SimulationBattle)
            {
#pragma warning disable CS1717 // Assignment made to same variable
                xpAmount = xpAmount;
#pragma warning restore CS1717 // Assignment made to same variable
            }
            if (missionType == CombatXpModel.MissionTypeEnum.PracticeFight)
            {
                xpAmount = MathF.Round((float)xpAmount * TournamentXPSettings.Instance.ArenaXPAdjustment);
            }
            if (missionType == CombatXpModel.MissionTypeEnum.Tournament)
            {
                xpAmount = MathF.Round((float)xpAmount * TournamentXPSettings.Instance.TournamentXPAdjustment);
            }
#endif
#if VERSION120
            float single;
            int   num   = attackedTroop.MaxHitPoints();
            float power = 0.4f * ((attackedTroop.GetPower() + 0.5f) * (Math.Min(damage, num) + (isFatal ? num : 0)));
            if (missionType == CombatXpModel.MissionTypeEnum.NoXp)
            {
                single = 0f;
            }
            else if (missionType == CombatXpModel.MissionTypeEnum.PracticeFight)
            {
                single = TournamentXPSettings.Instance.ArenaXPAdjustment;
            }
            else if (missionType == CombatXpModel.MissionTypeEnum.Tournament)
            {
                single = TournamentXPSettings.Instance.TournamentXPAdjustment;
            }
            else if (missionType == CombatXpModel.MissionTypeEnum.SimulationBattle)
            {
                single = 0.9f;
            }
            else
            {
                single = (missionType == CombatXpModel.MissionTypeEnum.Battle ? 1f : 1f);
            }
            xpAmount = MathF.Round(power * single);
#endif
            return(false);
        }
Exemplo n.º 12
0
        static void Postfix(PartyBase party, CharacterObject troopToBoost, ref int __result)
        {
            if (BannerlordTweaksSettings.Instance is { } settings&& settings.PrisonerConformityTweaksEnabled && !(party.LeaderHero is null))
            {
                float num;
                if (party.LeaderHero == Hero.MainHero ||
                    (!(party.Owner is null) && party.Owner.Clan == Hero.MainHero.Clan && settings.PrisonerConformityTweaksApplyToClan) ||
                    (settings.PrisonerConformityTweaksApplyToAi))
                {
                    num = __result * (1 + settings.PrisonerConformityTweakBonus);
                    party.MobileParty.EffectiveQuartermaster.AddSkillXp(DefaultSkills.Charm, (num * .05f));
                    __result = MBMath.Round(num);
                }
            }

            // Add Tier-Specific Boosts?
        }
Exemplo n.º 13
0
        private static void Postfix(CharacterObject attackerTroop, CharacterObject attackedTroop, int damage, bool isFatal, CombatXpModel.MissionTypeEnum missionType, out int xpAmount)
        {
            int num = attackedTroop.MaxHitPoints();

            xpAmount = MBMath.Round(0.4f * ((attackedTroop.GetPower() + 0.5f) * (float)(Math.Min(damage, num) + (isFatal ? num : 0))));

            if (missionType == CombatXpModel.MissionTypeEnum.SimulationBattle)
            {
#pragma warning disable CS1717 // Assignment made to same variable
                xpAmount = xpAmount;
#pragma warning restore CS1717 // Assignment made to same variable
            }
            if (missionType == CombatXpModel.MissionTypeEnum.PracticeFight)
            {
                xpAmount = MathF.Round((float)xpAmount * TournamentXPSettings.Instance.ArenaXPAdjustment);
            }
            if (missionType == CombatXpModel.MissionTypeEnum.Tournament)
            {
                xpAmount = MathF.Round((float)xpAmount * TournamentXPSettings.Instance.TournamentXPAdjustment);
            }
        }
Exemplo n.º 14
0
        public static void Postfix(ref int __result, CharacterObject character, StatExplainer explanation = null)
        {
            ExplainedNumber bonuses = new ExplainedNumber(__result, explanation);

            //PerkHelper.AddPerkBonusForCharacter(DefaultPerks.OneHanded.ExtraHp, character, ref bonuses);
            //PerkHelper.AddPerkBonusForCharacter(DefaultPerks.TwoHanded.ExtraHp, character, ref bonuses);
            //PerkHelper.AddPerkBonusForCharacter(DefaultPerks.Polearm.ExtraHp, character, ref bonuses);
            //PerkHelper.AddPerkBonusForCharacter(DefaultPerks.Athletics.Endurance, character, ref bonuses);
            //PerkHelper.AddPerkBonusForCharacter(DefaultPerks.Medicine.PreventiveMedicine, character, ref bonuses);
            try
            {
                var ScoutingExtra1 = PerkObject.FindFirst(a => a.Name.GetID() == "dDKOoD3e");
                if (ScoutingExtra1 != null)
                {
                    PerkHelper.AddPerkBonusForCharacter(ScoutingExtra1, character, ref bonuses);
                }
                __result = MBMath.Round(bonuses.ResultNumber);
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 15
0
        public GrantFiefItemVM(Settlement settlement, Hero targetHero, Action <GrantFiefItemVM> onSelect)
        {
            Settlement = settlement;
            Name       = settlement.Name.ToString();
            var component = settlement.GetComponent <SettlementComponent>();

            SettlementImagePath = ((component is null) ? "placeholder" : (component.BackgroundMeshName + "_t"));
            var component2 = settlement.GetComponent <Town>();

            if (component2 is not null)
            {
                Prosperity = MBMath.Round(component2.Prosperity);
                IconPath   = component2.BackgroundMeshName;
            }
            else if (settlement.IsCastle)
            {
                Prosperity = MBMath.Round(settlement.Prosperity);
                IconPath   = "";
            }
            Garrison      = Settlement.Town.GarrisonParty?.Party.NumberOfAllMembers ?? 0;
            _onSelect     = onSelect;
            RelationBonus = string.Concat(new string[] { GrantFiefAction.PreviewPositiveRelationChange(Settlement, targetHero).ToString(), "+" });
        }
Exemplo n.º 16
0
        public override void GetXpFromHit(CharacterObject attackerTroop, CharacterObject captain, CharacterObject attackedTroop, PartyBase party, int damage, bool isFatal, MissionTypeEnum missionType, out int xpAmount)
        {
            if (attackerTroop == null || attackedTroop == null)
            {
                xpAmount = 0;
                return;
            }

            int   num = attackerTroop.MaxHitPoints();
            float troopPowerBasedOnContext;

            if (party != null && party.MapEvent != null)
            {
                troopPowerBasedOnContext = Campaign.Current.Models.MilitaryPowerModel.GetTroopPowerBasedOnContext(attackerTroop, party.MapEvent.EventType, party.Side, missionType == CombatXpModel.MissionTypeEnum.SimulationBattle);
            }
            else
            {
                troopPowerBasedOnContext = Campaign.Current.Models.MilitaryPowerModel.GetTroopPowerBasedOnContext(attackerTroop, MapEvent.BattleTypes.None, BattleSideEnum.None, false);
            }
            xpAmount = MBMath.Round(0.4f * ((troopPowerBasedOnContext + 0.5f) * (float)(Math.Min(damage, num) + (isFatal ? num : 0))));
            if (missionType == CombatXpModel.MissionTypeEnum.NoXp)
            {
                xpAmount = 0;
            }

            if (attackerTroop.IsHero && missionType == MissionTypeEnum.Tournament)
            {
                if (BannerlordTweaksSettings.Instance is { } settings&& settings.TournamentHeroExperienceMultiplierEnabled)
                {
                    xpAmount = (int)MathF.Round(settings.TournamentHeroExperienceMultiplier * (float)xpAmount);
                }
                else
                {
                    xpAmount = MathF.Round((float)xpAmount * 0.33f);
                }
            }
Exemplo n.º 17
0
        internal static bool GiveShareOfLootToPartyPre(ref object __instance, PartyBase partyToReceiveLoot, PartyBase winnerParty, float lootAmount)
        {
            //var ___LootedMembers= Traverse.Create<LootCollectorType>(__instance).Field("LootedMembers").GetValue()
            var ___LootedMembers      = LootCollectorType.GetProperty("LootedMembers", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as TroopRoster;
            var ___LootedPrisoners    = LootCollectorType.GetProperty("LootedPrisoners", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as TroopRoster;
            var ___CasualtiesInBattle = LootCollectorType.GetProperty("CasualtiesInBattle", BindingFlags.Public | BindingFlags.Instance).GetValue(__instance) as TroopRoster;
            var ___LootedItems        = LootCollectorType.GetProperty("LootedItems", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as ItemRoster;

            bool flag = winnerParty == PartyBase.MainParty;
            List <TroopRosterElement> troopRosterElements = new List <TroopRosterElement>();

            foreach (TroopRosterElement lootedMember in ___LootedMembers)
            {
                int             number    = lootedMember.Number;
                CharacterObject character = lootedMember.Character;
                for (int i = 0; i < number; i++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        TroopRosterElement troopRosterElement = new TroopRosterElement(character)
                        {
                            Number        = 1,
                            WoundedNumber = 1
                        };
                        troopRosterElements.Add(troopRosterElement);
                    }
                }
            }
            foreach (TroopRosterElement troopRosterElement1 in troopRosterElements)
            {
                ___LootedMembers.AddToCounts(troopRosterElement1.Character, -1, false, 0, 0, true, -1);
            }
            foreach (TroopRosterElement troopRosterElement2 in troopRosterElements)
            {
                if (!troopRosterElement2.Character.IsHero)
                {
                    partyToReceiveLoot.PrisonRoster.AddToCounts(troopRosterElement2.Character, troopRosterElement2.Number, false, 0, 0, true, -1);
                }
                else if (!partyToReceiveLoot.IsMobile)
                {
                    TakePrisonerAction.Apply(partyToReceiveLoot, troopRosterElement2.Character.HeroObject);
                }
                else
                {
                    TakePrisonerAction.Apply(partyToReceiveLoot, troopRosterElement2.Character.HeroObject);
                }
            }
            ICollection <ItemRosterElement> itemRosterElements = new List <ItemRosterElement>();

            for (int j = ___LootedItems.Count <ItemRosterElement>() - 1; j >= 0; j--)
            {
                ItemRosterElement elementCopyAtIndex = ___LootedItems.GetElementCopyAtIndex(j);
                int num = 0;
                EquipmentElement equipmentElement = elementCopyAtIndex.EquipmentElement;
                ItemObject       item             = equipmentElement.Item;
                equipmentElement = elementCopyAtIndex.EquipmentElement;
                ItemRosterElement itemRosterElement = new ItemRosterElement(item, 1, equipmentElement.ItemModifier);
                for (int k = 0; k < elementCopyAtIndex.Amount; k++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        itemRosterElements.Add(itemRosterElement);
                        num++;
                    }
                }
                ___LootedItems.AddToCounts(itemRosterElement.EquipmentElement, -num, true);
            }
            partyToReceiveLoot.ItemRoster.Add(itemRosterElements);
            for (int l = ___LootedPrisoners.Count <TroopRosterElement>() - 1; l >= 0; l--)
            {
                int             elementNumber    = ___LootedPrisoners.GetElementNumber(l);
                CharacterObject characterAtIndex = ___LootedPrisoners.GetCharacterAtIndex(l);
                int             num1             = 0;
                for (int m = 0; m < elementNumber; m++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        partyToReceiveLoot.MemberRoster.AddToCounts(characterAtIndex, 1, false, 0, 0, true, -1);
                        num1++;
                    }
                }
                ___LootedPrisoners.AddToCounts(characterAtIndex, -num1, false, 0, 0, true, -1);
            }
            ICollection <TroopRosterElement> troopRosterElements1 = new List <TroopRosterElement>();

            for (int n = ___CasualtiesInBattle.Count <TroopRosterElement>() - 1; n >= 0; n--)
            {
                int                elementNumber1      = ___CasualtiesInBattle.GetElementNumber(n);
                CharacterObject    characterObject     = ___CasualtiesInBattle.GetCharacterAtIndex(n);
                int                num2                = 0;
                TroopRosterElement troopRosterElement3 = new TroopRosterElement(characterObject);
                for (int o = 0; o < elementNumber1; o++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        troopRosterElements1.Add(troopRosterElement3);
                        num2++;
                    }
                }
                ___CasualtiesInBattle.AddToCounts(characterObject, -num2, false, 0, 0, true, -1);
            }
            ExplainedNumber explainedNumber = new ExplainedNumber(1f, null);

            if (winnerParty.MobileParty != null && winnerParty.MobileParty.Leader != null)
            {
                //Get the best looter
                if (winnerParty.MobileParty == MobileParty.MainParty)
                {
                    SkillHelper.AddSkillBonusForCharacter(DefaultSkills.Roguery, DefaultSkillEffects.RogueryLootBonus, BMHelpers.CharacterHelpers.GetCharacterWithHighestSkill(winnerParty, DefaultSkills.Roguery), ref explainedNumber, true);
                }
                else
                {
                    SkillHelper.AddSkillBonusForCharacter(DefaultSkills.Roguery, DefaultSkillEffects.RogueryLootBonus, winnerParty.MobileParty.Leader, ref explainedNumber, true);
                }
            }
            if (flag)
            {
                IEnumerable <ItemRosterElement> itemRosterElements1 = LootCasualties(troopRosterElements1, explainedNumber.ResultNumber, flag);
                partyToReceiveLoot.ItemRoster.Add(itemRosterElements1);
            }
            else if (partyToReceiveLoot.LeaderHero != null)
            {
                int gold = ConvertLootToGold(LootCasualties(troopRosterElements1, 0.5f));
                gold = MBMath.Round((float)gold * 0.5f * explainedNumber.ResultNumber);
                GiveGoldAction.ApplyBetweenCharacters(null, partyToReceiveLoot.LeaderHero, gold, false);
                return(false);
            }

            return(false);
        }
Exemplo n.º 18
0
        internal void GiveShareOfLootToParty(PartyBase partyToReceiveLoot, PartyBase winnerParty, float lootAmount)
        {
            bool flag = winnerParty == PartyBase.MainParty;
            List <TroopRosterElement> troopRosterElements = new List <TroopRosterElement>();

            foreach (TroopRosterElement lootedMember in this.LootedMembers)
            {
                int             number    = lootedMember.Number;
                CharacterObject character = lootedMember.Character;
                for (int i = 0; i < number; i++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        TroopRosterElement troopRosterElement = new TroopRosterElement(character)
                        {
                            Number        = 1,
                            WoundedNumber = 1
                        };
                        troopRosterElements.Add(troopRosterElement);
                    }
                }
            }
            foreach (TroopRosterElement troopRosterElement1 in troopRosterElements)
            {
                this.LootedMembers.AddToCounts(troopRosterElement1.Character, -1, false, 0, 0, true, -1);
            }
            foreach (TroopRosterElement troopRosterElement2 in troopRosterElements)
            {
                if (!troopRosterElement2.Character.IsHero)
                {
                    partyToReceiveLoot.PrisonRoster.AddToCounts(troopRosterElement2.Character, troopRosterElement2.Number, false, 0, 0, true, -1);
                }
                else if (!partyToReceiveLoot.IsMobile)
                {
                    TakePrisonerAction.Apply(partyToReceiveLoot, troopRosterElement2.Character.HeroObject);
                }
                else
                {
                    TakePrisonerAction.Apply(partyToReceiveLoot, troopRosterElement2.Character.HeroObject);
                }
            }
            ICollection <ItemRosterElement> itemRosterElements = new List <ItemRosterElement>();

            for (int j = this.LootedItems.Count <ItemRosterElement>() - 1; j >= 0; j--)
            {
                ItemRosterElement elementCopyAtIndex = this.LootedItems.GetElementCopyAtIndex(j);
                int num = 0;
                EquipmentElement equipmentElement = elementCopyAtIndex.EquipmentElement;
                ItemObject       item             = equipmentElement.Item;
                equipmentElement = elementCopyAtIndex.EquipmentElement;
                ItemRosterElement itemRosterElement = new ItemRosterElement(item, 1, equipmentElement.ItemModifier);
                for (int k = 0; k < elementCopyAtIndex.Amount; k++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        itemRosterElements.Add(itemRosterElement);
                        num++;
                    }
                }
                this.LootedItems.AddToCounts(itemRosterElement, -num, true);
            }
            partyToReceiveLoot.ItemRoster.Add(itemRosterElements);
            for (int l = this.LootedPrisoners.Count <TroopRosterElement>() - 1; l >= 0; l--)
            {
                int             elementNumber    = this.LootedPrisoners.GetElementNumber(l);
                CharacterObject characterAtIndex = this.LootedPrisoners.GetCharacterAtIndex(l);
                int             num1             = 0;
                for (int m = 0; m < elementNumber; m++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        partyToReceiveLoot.MemberRoster.AddToCounts(characterAtIndex, 1, false, 0, 0, true, -1);
                        num1++;
                    }
                }
                this.LootedPrisoners.AddToCounts(characterAtIndex, -num1, false, 0, 0, true, -1);
            }
            ICollection <TroopRosterElement> troopRosterElements1 = new List <TroopRosterElement>();

            for (int n = this.CasualtiesInBattle.Count <TroopRosterElement>() - 1; n >= 0; n--)
            {
                int                elementNumber1      = this.CasualtiesInBattle.GetElementNumber(n);
                CharacterObject    characterObject     = this.CasualtiesInBattle.GetCharacterAtIndex(n);
                int                num2                = 0;
                TroopRosterElement troopRosterElement3 = new TroopRosterElement(characterObject);
                for (int o = 0; o < elementNumber1; o++)
                {
                    if (MBRandom.RandomFloat < lootAmount)
                    {
                        troopRosterElements1.Add(troopRosterElement3);
                        num2++;
                    }
                }
                this.CasualtiesInBattle.AddToCounts(characterObject, -num2, false, 0, 0, true, -1);
            }
            ExplainedNumber explainedNumber = new ExplainedNumber(1f, null);

            if (winnerParty.MobileParty != null && winnerParty.MobileParty.Leader != null)
            {
                SkillHelper.AddSkillBonusForCharacter(DefaultSkills.Roguery, DefaultSkillEffects.RogueryLootBonus, winnerParty.MobileParty.Leader, ref explainedNumber, true);
            }
            if (flag)
            {
                IEnumerable <ItemRosterElement> itemRosterElements1 = this.LootCasualties(troopRosterElements1, explainedNumber.ResultNumber);
                partyToReceiveLoot.ItemRoster.Add(itemRosterElements1);
            }
            else if (partyToReceiveLoot.LeaderHero != null)
            {
                int gold = LootCollector.ConvertLootToGold(this.LootCasualties(troopRosterElements1, 0.5f));
                gold = MBMath.Round((float)gold * 0.5f * explainedNumber.ResultNumber);
                GiveGoldAction.ApplyBetweenCharacters(null, partyToReceiveLoot.LeaderHero, gold, false);
                return;
            }
        }
Exemplo n.º 19
0
        public static void GetAttackCollisionResults(Mission.Missile missile, bool isHorseArcher, float armorAmountFloat, WeaponComponentData shieldOnBack, AgentFlag victimAgentFlag, float victimAgentAbsorbedDamageRatio, float damageMultiplierOfBone, float combatDifficultyMultiplier, MissionWeapon victimShield, bool canGiveDamageToAgentShield, bool isVictimAgentLeftStance, bool isFriendlyFire, bool doesAttackerHaveMountAgent, bool doesVictimHaveMountAgent, Vec2 attackerAgentMovementVelocity, Vec3 attackerAgentMountMovementDirection, float attackerMovementDirectionAsAngle, Vec2 victimAgentMovementVelocity, Vec3 victimAgentMountMovementDirection, float victimMovementDirectionAsAngle, bool isVictimAgentSameWithAttackerAgent, bool isAttackerAgentMine, bool isAttackerAgentHasRiderAgent, bool isAttackerAgentRiderAgentIsMine, bool isAttackerAgentMount, bool isVictimAgentMine, bool isVictimAgentHasRiderAgent, bool isVictimAgentRiderAgentIsMine, bool isVictimAgentMount, bool isAttackerAgentNull, bool isAttackerAIControlled, BasicCharacterObject attackerAgentCharacter, BasicCharacterObject victimAgentCharacter, Vec3 attackerAgentMovementDirection, Vec3 attackerAgentVelocity, float attackerAgentMountChargeDamageProperty, Vec3 attackerAgentCurrentWeaponOffset, bool isAttackerAgentHuman, bool isAttackerAgentActive, bool isAttackerAgentCharging, bool isVictimAgentNull, float victimAgentScale, float victimAgentWeight, float victimAgentTotalEncumbrance, bool isVictimAgentHuman, Vec3 victimAgentVelocity, Vec3 victimAgentPosition, int weaponAttachBoneIndex, MissionWeapon offHandItem, bool isHeadShot, bool crushedThrough, bool IsVictimRiderAgentSameAsAttackerAgent, float momentumRemaining, ref AttackCollisionData attackCollisionData, bool cancelDamage, string victimAgentName, out CombatLogData combatLog)
        {
            float distance = 0f;

            if (attackCollisionData.IsMissile)
            {
                distance = (attackCollisionData.MissileStartingPosition - attackCollisionData.CollisionGlobalPosition).Length;
            }
            combatLog = new CombatLogData(isVictimAgentSameWithAttackerAgent, isAttackerAgentHuman, isAttackerAgentMine, isAttackerAgentHasRiderAgent, isAttackerAgentRiderAgentIsMine, isAttackerAgentMount, isVictimAgentHuman, isVictimAgentMine, false, isVictimAgentHasRiderAgent, isVictimAgentRiderAgentIsMine, isVictimAgentMount, false, IsVictimRiderAgentSameAsAttackerAgent, false, false, distance);
            ItemObject          itemFromWeaponKind  = ItemObject.GetItemFromWeaponKind(attackCollisionData.AffectorWeaponKind);
            WeaponComponentData weaponComponentData = (itemFromWeaponKind != null) ? itemFromWeaponKind.GetWeaponWithUsageIndex(attackCollisionData.CurrentUsageIndex) : null;
            bool flag = Extensions.HitWithAnotherBone(ref attackCollisionData, weaponAttachBoneIndex);
            Vec3 agentVelocityContribution  = Extensions.GetAgentVelocityContribution(doesAttackerHaveMountAgent, attackerAgentMovementVelocity, attackerAgentMountMovementDirection, attackerMovementDirectionAsAngle);
            Vec3 agentVelocityContribution2 = Extensions.GetAgentVelocityContribution(doesVictimHaveMountAgent, victimAgentMovementVelocity, victimAgentMountMovementDirection, victimMovementDirectionAsAngle);

            if (attackCollisionData.IsColliderAgent)
            {
                combatLog.IsRangedAttack = attackCollisionData.IsMissile;
                combatLog.HitSpeed       = (attackCollisionData.IsMissile ? (agentVelocityContribution2 - attackCollisionData.MissileVelocity).Length : (agentVelocityContribution - agentVelocityContribution2).Length);
            }
            float baseMagnitude;
            int   speedBonus;

            Mission.ComputeBlowMagnitude(ref attackCollisionData, doesVictimHaveMountAgent, weaponComponentData, isAttackerAgentNull, attackerAgentCharacter, attackerAgentMovementDirection, attackerAgentVelocity, attackerAgentMountChargeDamageProperty, attackerAgentCurrentWeaponOffset, isAttackerAgentHuman, isAttackerAgentActive, isAttackerAgentCharging, isVictimAgentNull, victimAgentScale, victimAgentWeight, victimAgentTotalEncumbrance, isVictimAgentHuman, victimAgentVelocity, victimAgentPosition, momentumRemaining, cancelDamage, flag, attackCollisionData.MissileTotalDamage, agentVelocityContribution, agentVelocityContribution2, out attackCollisionData.BaseMagnitude, out baseMagnitude, out attackCollisionData.MovementSpeedDamageModifier, out speedBonus);
            DamageTypes damageType = (itemFromWeaponKind == null || flag || attackCollisionData.IsAlternativeAttack || attackCollisionData.IsFallDamage || attackCollisionData.IsHorseCharge) ? DamageTypes.Blunt : ((DamageTypes)attackCollisionData.DamageType);

            combatLog.DamageType = damageType;
            if (!attackCollisionData.IsColliderAgent && attackCollisionData.EntityExists)
            {
                string name         = PhysicsMaterial.GetFromIndex(attackCollisionData.PhysicsMaterialIndex).Name;
                bool   isWoodenBody = name == "wood" || name == "wood_weapon" || name == "wood_shield";
                attackCollisionData.BaseMagnitude  *= Extensions.GetEntityDamageMultiplier(isAttackerAgentCharging, weaponComponentData, damageType, isWoodenBody);
                attackCollisionData.InflictedDamage = MBMath.ClampInt((int)attackCollisionData.BaseMagnitude, 0, 2000);
                combatLog.InflictedDamage           = attackCollisionData.InflictedDamage;
            }
            int num = 0;

            if (attackCollisionData.IsColliderAgent && !isVictimAgentNull)
            {
                if (attackCollisionData.IsAlternativeAttack)
                {
                    baseMagnitude = attackCollisionData.BaseMagnitude;
                }
                if (attackCollisionData.AttackBlockedWithShield)
                {
                    Mission.ComputeBlowDamageOnShield(isAttackerAgentNull, isAttackerAgentActive, isAttackerAgentCharging, canGiveDamageToAgentShield, isVictimAgentLeftStance, victimShield, ref attackCollisionData, weaponComponentData, attackCollisionData.BaseMagnitude);
                    attackCollisionData.AbsorbedByArmor = attackCollisionData.InflictedDamage;
                }
                else
                {
                    Mission.ComputeBlowDamage(armorAmountFloat, shieldOnBack, victimAgentFlag, victimAgentAbsorbedDamageRatio, damageMultiplierOfBone, combatDifficultyMultiplier, damageType, baseMagnitude, attackCollisionData.CollisionGlobalPosition, itemFromWeaponKind, attackCollisionData.AttackBlockedWithShield, attackCollisionData.CollidedWithShieldOnBack, speedBonus, cancelDamage, attackCollisionData.IsFallDamage, out attackCollisionData.InflictedDamage, out attackCollisionData.AbsorbedByArmor, out num);
                }



                GCOToolbox.GCOToolbox.ProjectileBalance.ApplyProjectileArmorResistance(armorAmountFloat, ref attackCollisionData, missile, isHorseArcher);


                combatLog.InflictedDamage = attackCollisionData.InflictedDamage;
                combatLog.AbsorbedDamage  = attackCollisionData.AbsorbedByArmor;

                //combatLog.AttackProgress = attackCollisionData.AttackProgress;
                //issionGameModels.Current.AgentApplyDamageModel.CalculateDamage(attackerAgentCharacter, victimAgentCharacter, offHandItem, isHeadShot, isVictimAgentMount, isVictimAgentHuman, doesAttackerHaveMountAgent, isVictimAgentNull, isAttackerAgentHuman, attackCollisionData, weaponComponentData);
                //combatLog.ExtraDamage = attackCollisionData.InflictedDamage - combatLog.InflictedDamage;
            }
            if (!attackCollisionData.IsFallDamage && isFriendlyFire && !isAttackerAIControlled && GameNetwork.IsSessionActive)
            {
                int num2 = attackCollisionData.IsMissile ? MultiplayerOptions.OptionType.FriendlyFireDamageRangedSelfPercent.GetIntValue(MultiplayerOptions.MultiplayerOptionsAccessMode.CurrentMapOptions) : MultiplayerOptions.OptionType.FriendlyFireDamageMeleeSelfPercent.GetIntValue(MultiplayerOptions.MultiplayerOptionsAccessMode.CurrentMapOptions);
                attackCollisionData.SelfInflictedDamage = MBMath.Round((float)attackCollisionData.InflictedDamage * ((float)num2 * 0.01f));
                int num3 = attackCollisionData.IsMissile ? MultiplayerOptions.OptionType.FriendlyFireDamageRangedFriendPercent.GetIntValue(MultiplayerOptions.MultiplayerOptionsAccessMode.CurrentMapOptions) : MultiplayerOptions.OptionType.FriendlyFireDamageMeleeFriendPercent.GetIntValue(MultiplayerOptions.MultiplayerOptionsAccessMode.CurrentMapOptions);
                attackCollisionData.InflictedDamage = MBMath.Round((float)attackCollisionData.InflictedDamage * ((float)num3 * 0.01f));
                if (isVictimAgentMount && !doesAttackerHaveMountAgent)
                {
                    attackCollisionData.InflictedDamage = MBMath.Round((float)attackCollisionData.InflictedDamage * 0.1f);
                }
                combatLog.InflictedDamage = attackCollisionData.InflictedDamage;
                combatLog.IsFriendlyFire  = true;
            }
            if (attackCollisionData.AttackBlockedWithShield && attackCollisionData.InflictedDamage > 0 && (int)victimShield.HitPoints - attackCollisionData.InflictedDamage <= 0)
            {
                attackCollisionData.IsShieldBroken = true;
            }
        }
Exemplo n.º 20
0
        private void BattleSizeSpawnTick()
        {
            int troopsCanBeSpawned = this.NumberOfTroopsCanBeSpawned;

            if (this.NumberOfRemainingTroops <= 0 || troopsCanBeSpawned <= 0)
            {
                return;
            }
            int   num1    = this.DefenderActivePhase.TotalSpawnNumber + this.AttackerActivePhase.TotalSpawnNumber;
            int   number1 = MBMath.Round((float)troopsCanBeSpawned * (float)this.DefenderActivePhase.TotalSpawnNumber / (float)num1);
            int   number2 = troopsCanBeSpawned - number1;
            float num2    = (float)(this.DefenderActivePhase.InitialSpawnedNumber - this._missionSides[0].NumberOfActiveTroops) / (float)this.DefenderActivePhase.InitialSpawnedNumber;
            float num3    = (float)(this.AttackerActivePhase.InitialSpawnedNumber - this._missionSides[1].NumberOfActiveTroops) / (float)this.AttackerActivePhase.InitialSpawnedNumber;

            if (MissionAgentSpawnLogic.MaxNumberOfAgentsForMission - this.Mission.AllAgents.Count < troopsCanBeSpawned * 2 || (double)troopsCanBeSpawned < (double)this._battleSize * 0.100000001490116 && (double)num2 < 0.5 && (double)num3 < 0.5)
            {
                return;
            }
            float val = MBMath.ClampFloat(num2 / 0.5f - num3 / 0.5f, -1f, 1f);

            if ((double)val > 0.0)
            {
                int num4 = MBMath.Round((float)number2 * val);
                number2 -= num4;
                number1 += num4;
            }
            else if ((double)val < 0.0)
            {
                float num4 = MBMath.Absf(val);
                int   num5 = MBMath.Round((float)number1 * num4);
                number1 -= num5;
                number2 += num5;
            }
            int num6 = Math.Max(number1 - this.DefenderActivePhase.RemainingSpawnNumber, 0);
            int num7 = Math.Max(number2 - this.AttackerActivePhase.RemainingSpawnNumber, 0);

            if (num6 > 0 && num7 > 0)
            {
                number1 = this.DefenderActivePhase.RemainingSpawnNumber;
                number2 = this.AttackerActivePhase.RemainingSpawnNumber;
            }
            else if (num6 > 0)
            {
                number1 = this.DefenderActivePhase.RemainingSpawnNumber;
                number2 = Math.Min(number2 + num6, this.AttackerActivePhase.RemainingSpawnNumber);
            }
            else if (num7 > 0)
            {
                number2 = this.AttackerActivePhase.RemainingSpawnNumber;
                number1 = Math.Min(number1 + num7, this.DefenderActivePhase.RemainingSpawnNumber);
            }
            if (this._missionSides[0].TroopSpawningActive && number1 > 0)
            {
                this.DefenderActivePhase.RemainingSpawnNumber -= this._missionSides[0].SpawnTroops(number1, true, true);
            }
            if (!this._missionSides[1].TroopSpawningActive || number2 <= 0)
            {
                return;
            }
            this.AttackerActivePhase.RemainingSpawnNumber -= this._missionSides[1].SpawnTroops(number2, true, true);
        }