Skip to content

Commit

Permalink
Improve inertia classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jul 9, 2024
1 parent 8b0776e commit 084846b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
57 changes: 57 additions & 0 deletions Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Comfort.Common;
using EFT;
using System;
using UnityEngine;

namespace Fika.Core.Coop.ClientClasses
{
/// <summary>
/// Used to simulate having near no inertia
/// </summary>
public class NoInertiaMovementContext : MovementContext
{
public new static NoInertiaMovementContext Create(Player player, Func<IAnimator> animatorGetter, Func<ICharacterController> characterControllerGetter, LayerMask groundMask)
{
NoInertiaMovementContext movementContext = Create<NoInertiaMovementContext>(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<BackendConfigSettingsClass>.Instance.Health.Falling.SafeHeight, Singleton<BackendConfigSettingsClass>.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();
}
}
}
3 changes: 3 additions & 0 deletions Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Fika.Core.Coop.ClientClasses
{
/// <summary>
/// Currently unused
/// </summary>
public class NoInertiaPhysical : PlayerPhysicalClass
{
private CoopPlayer coopPlayer;
Expand Down
17 changes: 16 additions & 1 deletion Fika.Core/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAnimator>(GetBodyAnimatorCommon),
new Func<ICharacterController>(GetCharacterControllerCommon), movement_MASK);
}
else
{
MovementContext = NoInertiaMovementContext.Create(this, new Func<IAnimator>(GetBodyAnimatorCommon),
new Func<ICharacterController>(GetCharacterControllerCommon), movement_MASK);
}
}

public override void OnSkillLevelChanged(GClass1778 skill)
Expand Down

0 comments on commit 084846b

Please sign in to comment.