151 lines
5.7 KiB
C++
151 lines
5.7 KiB
C++
// // Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
|
//
|
|
//
|
|
// #include "Mover/Modifers/GMS_MovementStateModifer.h"
|
|
//
|
|
// #include "MoverComponent.h"
|
|
// #include "DefaultMovementSet/Settings/CommonLegacyMovementSettings.h"
|
|
// #include "MoveLibrary/MovementUtils.h"
|
|
// #include "Mover/GMS_MoverStructLibrary.h"
|
|
//
|
|
//
|
|
// FGMS_MovementStateModifier::FGMS_MovementStateModifier()
|
|
// {
|
|
// DurationMs = -1.0f;
|
|
// }
|
|
//
|
|
// void FGMS_MovementStateModifier::OnStart(UMoverComponent* MoverComp, const FMoverTimeStep& TimeStep, const FMoverSyncState& SyncState, const FMoverAuxStateContext& AuxState)
|
|
// {
|
|
// const FGMS_MoverMovementControlInputs* Inputs = SyncState.SyncStateCollection.FindMutableDataByType<FGMS_MoverMovementControlInputs>();
|
|
//
|
|
// if (UStanceSettings* StanceSettings = MoverComp->FindSharedSettings_Mutable<UStanceSettings>())
|
|
// {
|
|
// if (const UCapsuleComponent* CapsuleComponent = Cast<UCapsuleComponent>(MoverComp->GetUpdatedComponent()))
|
|
// {
|
|
// float OldHalfHeight = CapsuleComponent->GetScaledCapsuleHalfHeight();
|
|
// float NewHalfHeight = 0;
|
|
// float NewEyeHeight = 0;
|
|
//
|
|
// switch (ActiveStance)
|
|
// {
|
|
// default:
|
|
// case EStanceMode::Crouch:
|
|
// NewHalfHeight = StanceSettings->CrouchHalfHeight;
|
|
// NewEyeHeight = StanceSettings->CrouchedEyeHeight;
|
|
// break;
|
|
//
|
|
// // Prone isn't currently implemented
|
|
// case EStanceMode::Prone:
|
|
// UE_LOG(LogMover, Warning, TEXT("Stance got into prone stance - That stance is not currently implemented."));
|
|
// // TODO: returning here so we don't apply any bad state to actor in case prone was set. Eventually, the return should be removed once prone is implemented properly
|
|
// DurationMs = 0;
|
|
// return;
|
|
// }
|
|
//
|
|
// ApplyMovementSettings(MoverComp);
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// void FGMS_MovementStateModifier::OnEnd(UMoverComponent* MoverComp, const FMoverTimeStep& TimeStep, const FMoverSyncState& SyncState, const FMoverAuxStateContext& AuxState)
|
|
// {
|
|
// const AActor* OwnerCDO = Cast<AActor>(MoverComp->GetOwner()->GetClass()->GetDefaultObject());
|
|
//
|
|
// if (UCapsuleComponent* CapsuleComponent = Cast<UCapsuleComponent>(MoverComp->GetUpdatedComponent()))
|
|
// {
|
|
// if (const UCapsuleComponent* OriginalCapsule = UMovementUtils::GetOriginalComponentType<UCapsuleComponent>(MoverComp->GetOwner()))
|
|
// {
|
|
// if (const APawn* OwnerCDOAsPawn = Cast<APawn>(OwnerCDO))
|
|
// {
|
|
// AdjustCapsule(MoverComp, CapsuleComponent->GetScaledCapsuleHalfHeight(), OriginalCapsule->GetScaledCapsuleHalfHeight(), OwnerCDOAsPawn->BaseEyeHeight);
|
|
// RevertMovementSettings(MoverComp);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// void FGMS_MovementStateModifier::OnPreMovement(UMoverComponent* MoverComp, const FMoverTimeStep& TimeStep)
|
|
// {
|
|
// // TODO: Check for different inputs/state here and manage swapping between stances - use AdjustCapsule and Apply/Revert movement settings.
|
|
//
|
|
// // TODO: Prone isn't currently implemented - so we're just going to cancel the modifier if we got into that state
|
|
// if (ActiveStance == EStanceMode::Prone)
|
|
// {
|
|
// UE_LOG(LogMover, Warning, TEXT("Stance got into prone stance - That stance is not currently implemented."));
|
|
// DurationMs = 0;
|
|
// }
|
|
// }
|
|
//
|
|
// void FGMS_MovementStateModifier::OnPostMovement(UMoverComponent* MoverComp, const FMoverTimeStep& TimeStep, const FMoverSyncState& SyncState, const FMoverAuxStateContext& AuxState)
|
|
// {
|
|
// FMovementModifierBase::OnPostMovement(MoverComp, TimeStep, SyncState, AuxState);
|
|
// }
|
|
//
|
|
// FMovementModifierBase* FGMS_MovementStateModifier::Clone() const
|
|
// {
|
|
// FGMS_MovementStateModifier* CopyPtr = new FGMS_MovementStateModifier(*this);
|
|
// return CopyPtr;
|
|
// }
|
|
//
|
|
// void FGMS_MovementStateModifier::NetSerialize(FArchive& Ar)
|
|
// {
|
|
// Super::NetSerialize(Ar);
|
|
// }
|
|
//
|
|
// UScriptStruct* FGMS_MovementStateModifier::GetScriptStruct() const
|
|
// {
|
|
// return StaticStruct();
|
|
// }
|
|
//
|
|
// FString FGMS_MovementStateModifier::ToSimpleString() const
|
|
// {
|
|
// return FString::Printf(TEXT("Stance Modifier"));
|
|
// }
|
|
//
|
|
// void FGMS_MovementStateModifier::AddReferencedObjects(FReferenceCollector& Collector)
|
|
// {
|
|
// Super::AddReferencedObjects(Collector);
|
|
// }
|
|
//
|
|
//
|
|
// void FGMS_MovementStateModifier::ApplyMovementSettings(UMoverComponent* MoverComp)
|
|
// {
|
|
// switch (ActiveStance)
|
|
// {
|
|
// default:
|
|
// case EStanceMode::Crouch:
|
|
// if (UStanceSettings* StanceSettings = MoverComp->FindSharedSettings_Mutable<UStanceSettings>())
|
|
// {
|
|
// // Update relevant movement settings
|
|
// if (UCommonLegacyMovementSettings* MovementSettings = MoverComp->FindSharedSettings_Mutable<UCommonLegacyMovementSettings>())
|
|
// {
|
|
// MovementSettings->Acceleration = StanceSettings->CrouchingMaxAcceleration;
|
|
// MovementSettings->MaxSpeed = StanceSettings->CrouchingMaxSpeed;
|
|
// }
|
|
// }
|
|
//
|
|
// break;
|
|
//
|
|
// // Prone isn't currently implemented properly so we're just doing nothing for now
|
|
// case EStanceMode::Prone:
|
|
// UE_LOG(LogMover, Warning, TEXT("Stance got into prone stance - That mode is not currently implemented fully."));
|
|
// break;
|
|
// }
|
|
// }
|
|
//
|
|
// void FGMS_MovementStateModifier::RevertMovementSettings(UMoverComponent* MoverComp)
|
|
// {
|
|
// if (const UMoverComponent* CDOMoverComp = UMovementUtils::GetOriginalComponentType<UMoverComponent>(MoverComp->GetOwner()))
|
|
// {
|
|
// const UCommonLegacyMovementSettings* OriginalMovementSettings = CDOMoverComp->FindSharedSettings<UCommonLegacyMovementSettings>();
|
|
// UCommonLegacyMovementSettings* MovementSettings = MoverComp->FindSharedSettings_Mutable<UCommonLegacyMovementSettings>();
|
|
//
|
|
// // Revert movement settings back to original settings
|
|
// if (MovementSettings && OriginalMovementSettings)
|
|
// {
|
|
// MovementSettings->Acceleration = OriginalMovementSettings->Acceleration;
|
|
// MovementSettings->MaxSpeed = OriginalMovementSettings->MaxSpeed;
|
|
// }
|
|
// }
|
|
// }
|