2022-05-23 18:41:30 +00:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
#include "LyraEquipmentInstance.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
|
2022-05-23 18:41:30 +00:00
|
|
|
#include "Components/SkeletalMeshComponent.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "Engine/EngineTypes.h"
|
|
|
|
#include "GameFramework/Actor.h"
|
|
|
|
#include "GameFramework/Character.h"
|
|
|
|
#include "GameFramework/Pawn.h"
|
|
|
|
#include "LyraEquipmentDefinition.h"
|
|
|
|
#include "Math/Transform.h"
|
|
|
|
#include "Misc/AssertionMacros.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
#include "Net/UnrealNetwork.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "Templates/Casts.h"
|
|
|
|
|
|
|
|
#if UE_WITH_IRIS
|
|
|
|
#include "Iris/ReplicationSystem/ReplicationFragmentUtil.h"
|
|
|
|
#endif // UE_WITH_IRIS
|
|
|
|
|
|
|
|
class FLifetimeProperty;
|
|
|
|
class UClass;
|
|
|
|
class USceneComponent;
|
2022-05-23 18:41:30 +00:00
|
|
|
|
|
|
|
ULyraEquipmentInstance::ULyraEquipmentInstance(const FObjectInitializer& ObjectInitializer)
|
|
|
|
: Super(ObjectInitializer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UWorld* ULyraEquipmentInstance::GetWorld() const
|
|
|
|
{
|
|
|
|
if (APawn* OwningPawn = GetPawn())
|
|
|
|
{
|
|
|
|
return OwningPawn->GetWorld();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ULyraEquipmentInstance::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
|
|
|
{
|
|
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
|
|
|
|
|
|
DOREPLIFETIME(ThisClass, Instigator);
|
|
|
|
DOREPLIFETIME(ThisClass, SpawnedActors);
|
|
|
|
}
|
|
|
|
|
2022-09-13 07:18:28 +00:00
|
|
|
#if UE_WITH_IRIS
|
|
|
|
void ULyraEquipmentInstance::RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags)
|
|
|
|
{
|
|
|
|
using namespace UE::Net;
|
|
|
|
|
|
|
|
Super::RegisterReplicationFragments(Context, RegistrationFlags);
|
|
|
|
|
|
|
|
// Build descriptors and allocate PropertyReplicationFragments for this object
|
|
|
|
FReplicationFragmentUtil::CreateAndRegisterFragmentsForObject(this, Context, RegistrationFlags);
|
|
|
|
}
|
|
|
|
#endif // UE_WITH_IRIS
|
|
|
|
|
2022-05-23 18:41:30 +00:00
|
|
|
APawn* ULyraEquipmentInstance::GetPawn() const
|
|
|
|
{
|
|
|
|
return Cast<APawn>(GetOuter());
|
|
|
|
}
|
|
|
|
|
|
|
|
APawn* ULyraEquipmentInstance::GetTypedPawn(TSubclassOf<APawn> PawnType) const
|
|
|
|
{
|
|
|
|
APawn* Result = nullptr;
|
|
|
|
if (UClass* ActualPawnType = PawnType)
|
|
|
|
{
|
|
|
|
if (GetOuter()->IsA(ActualPawnType))
|
|
|
|
{
|
|
|
|
Result = Cast<APawn>(GetOuter());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ULyraEquipmentInstance::SpawnEquipmentActors(const TArray<FLyraEquipmentActorToSpawn>& ActorsToSpawn)
|
|
|
|
{
|
|
|
|
if (APawn* OwningPawn = GetPawn())
|
|
|
|
{
|
|
|
|
USceneComponent* AttachTarget = OwningPawn->GetRootComponent();
|
|
|
|
if (ACharacter* Char = Cast<ACharacter>(OwningPawn))
|
|
|
|
{
|
|
|
|
AttachTarget = Char->GetMesh();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const FLyraEquipmentActorToSpawn& SpawnInfo : ActorsToSpawn)
|
|
|
|
{
|
|
|
|
AActor* NewActor = GetWorld()->SpawnActorDeferred<AActor>(SpawnInfo.ActorToSpawn, FTransform::Identity, OwningPawn);
|
|
|
|
NewActor->FinishSpawning(FTransform::Identity, /*bIsDefaultTransform=*/ true);
|
|
|
|
NewActor->SetActorRelativeTransform(SpawnInfo.AttachTransform);
|
|
|
|
NewActor->AttachToComponent(AttachTarget, FAttachmentTransformRules::KeepRelativeTransform, SpawnInfo.AttachSocket);
|
|
|
|
|
|
|
|
SpawnedActors.Add(NewActor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ULyraEquipmentInstance::DestroyEquipmentActors()
|
|
|
|
{
|
|
|
|
for (AActor* Actor : SpawnedActors)
|
|
|
|
{
|
|
|
|
if (Actor)
|
|
|
|
{
|
|
|
|
Actor->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ULyraEquipmentInstance::OnEquipped()
|
|
|
|
{
|
|
|
|
K2_OnEquipped();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ULyraEquipmentInstance::OnUnequipped()
|
|
|
|
{
|
|
|
|
K2_OnUnequipped();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ULyraEquipmentInstance::OnRep_Instigator()
|
|
|
|
{
|
|
|
|
}
|