From 084846bfd1b4fc31c5424d4c24feb1509fb90b76 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:16:30 +0200 Subject: [PATCH] Improve inertia classes --- .../ClientClasses/NoInertiaMovementContext.cs | 57 +++++++++++++++++++ .../Coop/ClientClasses/NoInertiaPhysical.cs | 3 + Fika.Core/Coop/Players/CoopPlayer.cs | 17 +++++- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs diff --git a/Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs b/Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs new file mode 100644 index 00000000..0d39124d --- /dev/null +++ b/Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs @@ -0,0 +1,57 @@ +using Comfort.Common; +using EFT; +using System; +using UnityEngine; + +namespace Fika.Core.Coop.ClientClasses +{ + /// + /// Used to simulate having near no inertia + /// + public class NoInertiaMovementContext : MovementContext + { + public new static NoInertiaMovementContext Create(Player player, Func animatorGetter, Func characterControllerGetter, LayerMask groundMask) + { + NoInertiaMovementContext movementContext = Create(player, animatorGetter, characterControllerGetter, groundMask); + return movementContext; + } + + public override void Init() + { + base.Init(); + TiltInertia = 0.22f; + WalkInertia = 0.005f; + SprintBrakeInertia = 0f; + } + + public override void WeightRelatedValuesUpdated() + { + if (_player.ProceduralWeaponAnimation != null) + { + _player.ProceduralWeaponAnimation.Overweight = _player.Physical.Overweight; + _player.ProceduralWeaponAnimation.UpdateSwayFactors(); + _player.ProceduralWeaponAnimation.UpdateSwaySettings(); + _player.ProceduralWeaponAnimation.WeaponFlipSpeed = InertiaSettings.WeaponFlipSpeed.Evaluate(_player.Physical.Inertia); + } + UpdateCovertEfficiency(_player.MovementContext.ClampedSpeed, true); + _player.UpdateStepSoundRolloff(); + _player.HealthController.FallSafeHeight = Mathf.Lerp(Singleton.Instance.Health.Falling.SafeHeight, Singleton.Instance.Stamina.SafeHeightOverweight, _player.Physical.Overweight); + PlayerAnimatorTransitionSpeed = TransitionSpeed; + if (PoseLevel > _player.Physical.MaxPoseLevel && CurrentState is MovementState movementState) + { + movementState.ChangePose(_player.Physical.MaxPoseLevel - PoseLevel); + } + if (_player.PoseMemo > _player.Physical.MaxPoseLevel) + { + _player.PoseMemo = _player.Physical.MaxPoseLevel; + } + float walkSpeedLimit = _player.Physical.WalkSpeedLimit; + RemoveStateSpeedLimit(Player.ESpeedLimit.Weight); + if (walkSpeedLimit < 1f) + { + AddStateSpeedLimit(walkSpeedLimit * MaxSpeed, Player.ESpeedLimit.Weight); + } + UpdateCharacterControllerSpeedLimit(); + } + } +} diff --git a/Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs b/Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs index 6b0d1792..41718af3 100644 --- a/Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs +++ b/Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs @@ -5,6 +5,9 @@ namespace Fika.Core.Coop.ClientClasses { + /// + /// Currently unused + /// public class NoInertiaPhysical : PlayerPhysicalClass { private CoopPlayer coopPlayer; diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index e1d2414c..9e2b1d6c 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -118,9 +118,24 @@ await player.Init(rotation, layerName, pointOfView, profile, inventoryController return player; } - public override BasePhysicalClass CreatePhysical() + /*public override BasePhysicalClass CreatePhysical() { return FikaPlugin.Instance.UseInertia ? new PlayerPhysicalClass() : new NoInertiaPhysical(); + }*/ + + public override void CreateMovementContext() + { + LayerMask movement_MASK = EFTHardSettings.Instance.MOVEMENT_MASK; + if (FikaPlugin.Instance.UseInertia) + { + MovementContext = MovementContext.Create(this, new Func(GetBodyAnimatorCommon), + new Func(GetCharacterControllerCommon), movement_MASK); + } + else + { + MovementContext = NoInertiaMovementContext.Create(this, new Func(GetBodyAnimatorCommon), + new Func(GetCharacterControllerCommon), movement_MASK); + } } public override void OnSkillLevelChanged(GClass1778 skill)