public override void AfterStart()
        {
            int ofHealthyMembers1    = _battleCombatants[0].NumberOfHealthyMembers;
            int ofHealthyMembers2    = _battleCombatants[1].NumberOfHealthyMembers;
            int defenderInitialSpawn = MBMath.Floor(ofHealthyMembers1);
            int attackerInitialSpawn = MBMath.Floor(ofHealthyMembers2 * 0.1f);

            _missionAgentSpawnLogic.SetSpawnHorses(BattleSideEnum.Defender, true);
            _missionAgentSpawnLogic.SetSpawnHorses(BattleSideEnum.Attacker, true);
            _missionAgentSpawnLogic.InitWithSinglePhase(ofHealthyMembers1, ofHealthyMembers2, defenderInitialSpawn, attackerInitialSpawn, false, false);
            _missionAgentSpawnLogic.ReserveReinforcement(BattleSideEnum.Attacker, ofHealthyMembers2 - attackerInitialSpawn);
        }
Example #2
0
        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);
        }
Example #3
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);
        }
Example #4
0
        public static int GetModifiedRelation(this Hero hero, Hero otherHero)
        {
#if STABLE
            ExplainedNumber relationBetweenHeroes = new ExplainedNumber(CharacterRelationManager.GetHeroRelation(hero, otherHero), false, 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)));
#else
            int relationBetweenHeroes = CharacterRelationManager.GetHeroRelation(hero, otherHero);
            deGetPersonalityEffects !(Campaign.Current.Models.DiplomacyModel is DefaultDiplomacyModel defaultDiplomacyModel ? defaultDiplomacyModel : new DefaultDiplomacyModel(), ref relationBetweenHeroes, hero, otherHero);
            return(MBMath.Round(MBMath.ClampFloat(relationBetweenHeroes + (RelativesHelper.BloodRelatives(hero, otherHero) ? 30f : 0f), -100f, 100f)));
#endif
        }
        public static float GetFormAllianceScore(Kingdom kingdom, Kingdom otherKingdom)
        {
            float totalScore    = 0;
            float totalStrength = 0;

            float[] kingdomStrengths = Kingdom.All.Select(curKingdom => curKingdom.TotalStrength).OrderBy(a => a).ToArray();

            int   halfIndex = kingdomStrengths.Count() / 2;
            float medianStrength;

            if ((kingdomStrengths.Length % 2) == 0)
            {
                medianStrength = (kingdomStrengths.ElementAt(halfIndex) + kingdomStrengths.ElementAt(halfIndex - 1)) / 2;
            }
            else
            {
                medianStrength = kingdomStrengths.ElementAt(halfIndex);
            }

            // weak faction bonus
            float averageStrength = totalStrength / Kingdom.All.Count;

            if (kingdom.TotalStrength <= medianStrength)
            {
                totalScore += (int)AllianceScore.BelowMedianStrength;
            }

            // common enemies
            IEnumerable <Kingdom> commonEnemies = FactionManager.GetEnemyKingdoms(kingdom).Intersect(FactionManager.GetEnemyKingdoms(otherKingdom));

            totalScore += commonEnemies.Count() * (int)AllianceScore.HasCommonEnemy;

            // bordering or inside territory modifier
            if (kingdom.IsInsideTeritoryOf(otherKingdom))
            {
                float traitScore = 0;
                traitScore -= (int)AllianceScore.SharesBorder * kingdom.Leader.GetHeroTraits().Calculating;
                traitScore += (int)AllianceScore.SharesBorder * kingdom.Leader.GetHeroTraits().Mercy;

                totalScore += traitScore;
            }

            // existing alliances
            totalScore -= (int)AllianceScore.ExistingAlliance * Kingdom.All.Except(new[] { kingdom, otherKingdom }).Where(curKingdom => FactionManager.IsAlliedWithFaction(kingdom, curKingdom)).Count();

            // relation modifier
            float relationModifier = MBMath.ClampFloat((float)Math.Log((kingdom.Leader.GetRelation(otherKingdom.Leader) + 100f) / 100f, 1.5), -1, 1);

            totalScore += (int)AllianceScore.Relationship * relationModifier;

            return(totalScore);
        }
Example #6
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;
        }
Example #8
0
        internal static float DetermineInfluenceCostForFormingAlliance(Kingdom kingdom, Kingdom otherKingdom, bool isPlayerRequested = false)
        {
            const float baseInfluenceCost = 100f;

            if (isPlayerRequested)
            {
                return(MBMath.ClampFloat((float)Math.Pow(AllianceScoringModel.FormAllianceScoreThreshold / Math.Max(AllianceScoringModel.GetFormAllianceScore(kingdom, otherKingdom), 1f), 4), 1f, 256f) * baseInfluenceCost);
            }
            else
            {
                return(baseInfluenceCost);
            }
        }
        private int GetBaseRelationValueOfCurrentGoldCost()
        {
            if (_clan == Clan.PlayerClan)
            {
                return(0);
            }

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

            return(MBMath.Round(influenceValue * relationValuePerInfluence));
        }
Example #10
0
        internal override float GetTacticWeight()
        {
            if (this.team.Formations.All <Formation>((Func <Formation, bool>)(f => !f.QuerySystem.IsRangedFormation)))
            {
                return(0.0f);
            }
            double num1 = (double)this.team.QuerySystem.RangedRatio * (double)this.team.QuerySystem.MemberCount / ((double)this.team.QuerySystem.MemberCount - (double)(this.team.QuerySystem.RangedCavalryRatio * (float)this.team.QuerySystem.MemberCount));
            float  num2 = this.team.QuerySystem.RangedRatio + this.team.QuerySystem.RangedCavalryRatio;
            float  num3 = this.team.QuerySystem.EnemyRangedRatio + this.team.QuerySystem.EnemyRangedCavalryRatio;
            double num4 = (double)MBMath.ClampFloat((double)num3 > 0.0 ? num2 / num3 : 2f, 0.5f, 2f);

            return((float)(num1 * num4) * (float)Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio));
        }
        public static List <uint> GetHairColorGradientPoints(int curGender, int age)
        {
            int         hairColorCount = MBBodyProperties.GetHairColorCount(curGender, age);
            List <uint> uintList       = new List <uint>();

            Vec3[] colors = new Vec3[hairColorCount];
            MBAPI.IMBFaceGen.GetHairColorGradientPoints(curGender, (float)age, colors);
            foreach (Vec3 vec3 in colors)
            {
                uintList.Add(MBMath.ColorFromRGBA(vec3.x, vec3.y, vec3.z, 1f));
            }
            return(uintList);
        }
        protected int GetMaximumDepth(int unitCount)
        {
            int val1 = 0;
            int num  = 0;

            while (num < unitCount)
            {
                int val2 = MBMath.Floor((float)(6.28318548202515 * (double)((float)val1 * (this.Distance + this.UnitDiameter)) / ((double)this.Interval + (double)this.UnitDiameter)));
                num += Math.Max(1, val2);
                ++val1;
            }
            return(Math.Max(val1, 1));
        }
Example #13
0
 private void TickCameraZoom(float dt)
 {
     if (!((NativeObject)this._camera != (NativeObject)null))
     {
         return;
     }
     this.SetCamFovHorizontal(MBMath.ClampFloat(this._camera.HorizontalFov + this._curZoomSpeed, 0.1f, 2f));
     if ((double)dt <= 0.0)
     {
         return;
     }
     this._curZoomSpeed = MBMath.Lerp(this._curZoomSpeed, 0.0f, MBMath.ClampFloat(dt * 25.9f, 0.0f, 1f), 1E-05f);
 }
Example #14
0
        private void RespecHero(Hero hero)
        {
            InformationManager.DisplayMessage(new InformationMessage($"{hero.Name} will be demolished."));

            InformationManager.DisplayMessage(new InformationMessage($"Clearing Perks..."));
            hero.ClearPerks();

            int statpoints        = hero.HeroDeveloper.UnspentAttributePoints;
            int focuspoints       = hero.HeroDeveloper.UnspentFocusPoints;
            int focus_to_add      = 0;
            int statpoints_to_add = 0;

            InformationManager.DisplayMessage(new InformationMessage($"Unspent: {statpoints} stat | {focuspoints} focus"));

            InformationManager.DisplayMessage(new InformationMessage($"Demolishing focus..."));

            foreach (SkillObject skill in DefaultSkills.GetAllSkills())
            {
                int focus_in_skill = hero.HeroDeveloper.GetFocus(skill);

                if (focus_in_skill > 0)
                {
                    InformationManager.DisplayMessage(new InformationMessage($"{skill.Name}; {focus_in_skill}"));
                    focus_to_add += focus_in_skill;
                }
            }

            InformationManager.DisplayMessage(new InformationMessage($"{focus_to_add} focus points reclaimed"));
            hero.HeroDeveloper.UnspentFocusPoints += MBMath.ClampInt(focus_to_add, 0, 999);

            hero.HeroDeveloper.ClearFocuses();

            InformationManager.DisplayMessage(new InformationMessage($"Demolishing stats..."));

            for (CharacterAttributesEnum statEnum = CharacterAttributesEnum.Vigor; statEnum < CharacterAttributesEnum.NumCharacterAttributes; statEnum++)
            {
                int attributeValue = hero.GetAttributeValue(statEnum);
                InformationManager.DisplayMessage(new InformationMessage($"{statEnum} {attributeValue} --> 0"));
                statpoints_to_add += attributeValue;
                hero.SetAttributeValue(statEnum, 0);
            }

            InformationManager.DisplayMessage(new InformationMessage($"{statpoints_to_add} stat points reclaimed"));


            hero.HeroDeveloper.UnspentAttributePoints += MBMath.ClampInt(statpoints_to_add, 0, 999);


            InformationManager.DisplayMessage(new InformationMessage($"Unspent: {hero.HeroDeveloper.UnspentAttributePoints} stat | {hero.HeroDeveloper.UnspentFocusPoints} focus"));
        }
 protected override void OnBehaviorActivatedAux()
 {
     this._cantShoot         = false;
     this._cantShootDistance = float.MaxValue;
     this._behaviorState     = BehaviorSkirmish.BehaviorState.Shooting;
     this._cantShootTimer.Reset(Mission.Current.Time, MBMath.Lerp(5f, 10f, (float)(((double)MBMath.ClampFloat((float)this.formation.CountOfUnits, 10f, 60f) - 10.0) * 0.0199999995529652)));
     this.CalculateCurrentOrder();
     this.formation.MovementOrder    = this.CurrentOrder;
     this.formation.FacingOrder      = this.CurrentFacingOrder;
     this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLoose;
     this.formation.FiringOrder      = FiringOrder.FiringOrderFireAtWill;
     this.formation.FormOrder        = FormOrder.FormOrderWide;
     this.formation.WeaponUsageOrder = WeaponUsageOrder.WeaponUsageOrderUseAny;
 }
        public override void AfterStart()
        {
            Scene             scene = base.Mission.Scene;
            List <GameEntity> list  = base.Mission.Scene.FindEntitiesWithTag("sp_special_item").ToList <GameEntity>();

            int num  = MBMath.Floor((float)this._mapEvent.GetNumberOfInvolvedMen(BattleSideEnum.Defender));
            int num2 = MBMath.Floor((float)this._mapEvent.GetNumberOfInvolvedMen(BattleSideEnum.Attacker));
            int defenderInitialSpawn = num;
            int attackerInitialSpawn = num2;

            this._missionAgentSpawnLogic.SetSpawnHorses(BattleSideEnum.Defender, false);
            this._missionAgentSpawnLogic.SetSpawnHorses(BattleSideEnum.Attacker, false);
            this._missionAgentSpawnLogic.InitWithSinglePhase(num, num2, defenderInitialSpawn, attackerInitialSpawn, true, true, 1f);
        }
Example #17
0
        /// <summary>
        /// Indexes a world-based coordinate into the collision grid
        /// </summary>
        /// <returns>The grid-based position.</returns>
        /// <param name="position">World-based position to index.</param>
        public Point IndexOf(Point position)
        {
            var pos = MBMath.WrapGrid(
                position.X / _cellSize,
                position.Y / _cellSize,
                _grid.ColCount, _grid.RowCount
                );

            return(new Point
            {
                X = pos.X,
                Y = pos.Y
            });
        }
Example #18
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();
        }
Example #19
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);
        }
        private static int GetMaximumDepth(int unitCount, float distance, float interval, float unitDiameter)
        {
            int val1 = 0;
            int num  = 0;

            while (num < unitCount)
            {
                int val2 = MBMath.Floor((float)(6.28318548202515 *
                                                (val1 * (distance + unitDiameter)) /
                                                (interval + (double)unitDiameter)));
                num += Math.Max(1, val2);
                ++val1;
            }
            return(Math.Max(val1, 1));
        }
Example #21
0
 protected override void OnTickAsAI(float dt)
 {
     if (Morale < 20f)
     {
         canCrumble = crumbleTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission));
         if (canCrumble)
         {
             float damageTaken = 0.01f / Morale;
             damageTaken = MBMath.ClampFloat(damageTaken, 0, 1);
             Agent.ApplyDamage(damageTaken);
             crumbleTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
             //Helpers.Say(Agent.Name + " took " + damageTaken + " crumbling damage from low binding");
         }
     }
 }
 protected override void OnTickAsAI(float dt)
 {
     if (base.Morale < 20f)
     {
         canCrumble = crumbleTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission));
         if (canCrumble)
         {
             float damageTaken = 0.01f / base.Morale;
             damageTaken        = MBMath.ClampFloat(damageTaken, 0, 1);
             this.Agent.Health -= damageTaken;
             crumbleTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
             Helpers.Say(this.Agent.Name + " took " + damageTaken + " damage from low morale.");
         }
     }
 }
        public static void ResetFocus([NotNull] this Hero hero)
        {
            //var focus = DefaultSkills.GetAllSkills().Sum(skill => hero.HeroDeveloper.GetFocus(skill));
            //hero.HeroDeveloper.UnspentFocusPoints += MBMath.ClampInt(focus, 0, 999);
            //hero.HeroDeveloper.ClearFocuses();
            int count = 0;

            foreach (var item in DefaultSkills.GetAllSkills())
            {
                var focus = hero.HeroDeveloper.GetFocus(item);
                hero.HeroDeveloper.AddFocus(item, 0 - focus, false);
                count += focus;
            }
            hero.HeroDeveloper.UnspentFocusPoints += MBMath.ClampInt(count, 0, 999);
        }
Example #24
0
        public void RefocusHero(Hero hero)
        {
            int num  = 0;
            int num2 = 0;

            foreach (SkillObject skill in DefaultSkills.GetAllSkills())
            {
                int focus = hero.HeroDeveloper.GetFocus(skill);
                if (focus > 0)
                {
                    num += focus;
                    hero.HeroDeveloper.AddFocus(skill, num2 - focus, false);
                }
            }
            hero.HeroDeveloper.UnspentFocusPoints += MBMath.ClampInt(num, 0, 999);
        }
 public void ChangeTeamScore(Team team, int scoreChange)
 {
     this._sides[(int)team.Side].SideScore += scoreChange;
     this._sides[(int)team.Side].SideScore  = MBMath.ClampInt(this._sides[(int)team.Side].SideScore, -120000, 120000);
     if (GameNetwork.IsServer)
     {
         GameNetwork.BeginBroadcastModuleEvent();
         GameNetwork.WriteMessage((GameNetworkMessage) new NetworkMessages.FromServer.UpdateRoundScores(this.GetRoundScore(BattleSideEnum.Attacker), this.GetRoundScore(BattleSideEnum.Defender)));
         GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
     }
     if (this.OnRoundPropertiesChanged == null)
     {
         return;
     }
     this.OnRoundPropertiesChanged();
 }
Example #26
0
        protected internal override void OnTick(float dt)
        {
            if ((double)dt == 0.0)
            {
                return;
            }
            MatrixFrame globalFrame = this.GameEntity.GetGlobalFrame();
            MetaMesh    metaMesh    = this.GameEntity.GetMetaMesh(0);

            if ((NativeObject)metaMesh == (NativeObject)null)
            {
                return;
            }
            Vec3 vec3_1 = globalFrame.origin - this._prevFlagMeshFrame;

            vec3_1.x /= dt;
            vec3_1.y /= dt;
            vec3_1.z /= dt;
            Vec3 vec3_2 = new Vec3(20f, z: -10f) * 0.1f - vec3_1;

            if ((double)vec3_2.LengthSquared < 9.99999993922529E-09)
            {
                return;
            }
            Vec3 local = globalFrame.rotation.TransformToLocal(vec3_2);

            local.z = 0.0f;
            double num1  = (double)local.Normalize();
            float  theta = (float)Math.Atan2((double)local.y, (double)local.x);

            this.SmoothTheta(ref theta, dt);
            Vec3        scaleVector = metaMesh.Frame.rotation.GetScaleVector();
            MatrixFrame identity    = MatrixFrame.Identity;

            identity.Scale(scaleVector);
            identity.rotation.RotateAboutUp(theta);
            this._prevTheta = theta;
            float num2 = this._prevSkew + Math.Min((float)Math.Acos((double)Vec3.DotProduct(vec3_2, globalFrame.rotation.u) / (double)vec3_2.Length) - this._prevSkew, 150f * dt) * 0.05f;

            this._prevSkew = num2;
            float num3 = MBMath.ClampFloat(vec3_2.Length, 1f / 1000f, 10000f);

            this._time             += (float)((double)dt * (double)num3 * 0.5);
            metaMesh.Frame          = identity;
            metaMesh.VectorUserData = new Vec3((float)Math.Cos((double)num2), 1f - (float)Math.Sin((double)num2), w: this._time);
            this._prevFlagMeshFrame = globalFrame.origin;
        }
Example #27
0
        public static Color AddFactorInHSB(
            this Color rgbColor,
            float hueDifference,
            float saturationDifference,
            float brighnessDifference)
        {
            Vec3 vec3 = MBMath.RGBtoHSB(rgbColor);

            vec3.x = (float)(((double)vec3.x + (double)hueDifference * 360.0) % 360.0);
            if ((double)vec3.x < 0.0)
            {
                vec3.x += 360f;
            }
            vec3.y = MBMath.ClampFloat(vec3.y + saturationDifference, 0.0f, 1f);
            vec3.z = MBMath.ClampFloat(vec3.z + brighnessDifference, 0.0f, 1f);
            return(MBMath.HSBtoRGB(vec3.x, vec3.y, vec3.z, rgbColor.Alpha));
        }
Example #28
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?
        }
 protected internal override void OnEditorVariableChanged(string variableName)
 {
     base.OnEditorVariableChanged(variableName);
     if (variableName == "minRadius")
     {
         this.minRadius = MBMath.ClampFloat(this.minRadius, 0.1f, this.maxRadius);
     }
     if (variableName == "maxRadius")
     {
         this.maxRadius = MBMath.ClampFloat(this.maxRadius, this.minRadius, float.MaxValue);
     }
     if (!(variableName == "hideAllProbes"))
     {
         return;
     }
     MapAtmosphereProbe.hideAllProbesStatic = this.hideAllProbes;
 }
Example #30
0
        public override Agent.UsageDirection GetBlockDirection(Mission mission)
        {
            Agent mainAgent = mission.MainAgent;
            float num1      = float.MinValue;

            Agent.UsageDirection usageDirection = Agent.UsageDirection.AttackDown;
            foreach (Agent agent in (IEnumerable <Agent>)mission.Agents)
            {
                if (agent.IsHuman)
                {
                    switch (agent.GetCurrentActionStage(1))
                    {
                    case Agent.ActionStage.AttackReady:
                    case Agent.ActionStage.AttackQuickReady:
                    case Agent.ActionStage.AttackRelease:
                        if (agent.IsEnemyOf(mainAgent))
                        {
                            Vec3   v1   = agent.Position - mainAgent.Position;
                            float  num2 = v1.Normalize();
                            double num3 = (double)MBMath.ClampFloat(Vec3.DotProduct(v1, mainAgent.LookDirection) + 0.8f, 0.0f, 1f);
                            float  num4 = MBMath.ClampFloat((float)(1.0 / ((double)num2 + 0.5)), 0.0f, 1f);
                            float  num5 = MBMath.ClampFloat((float)(-(double)Vec3.DotProduct(v1, agent.LookDirection) + 0.5), 0.0f, 1f);
                            double num6 = (double)num4;
                            float  num7 = (float)(num3 * num6) * num5;
                            if ((double)num7 > (double)num1)
                            {
                                num1           = num7;
                                usageDirection = agent.GetCurrentActionDirection(1);
                                if (usageDirection == Agent.UsageDirection.None)
                                {
                                    usageDirection = Agent.UsageDirection.AttackDown;
                                    continue;
                                }
                                continue;
                            }
                            continue;
                        }
                        continue;

                    default:
                        continue;
                    }
                }
            }
            return(usageDirection);
        }