Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Repsi.uproject
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"FileVersion": 3,
"EngineAssociation": "4.25",
"Category": "",
"Description": "",
"Modules": [
{
"Name": "RepsiCore",
"Type": "Runtime",
"LoadingPhase": "Default"
}
]
}
{
"FileVersion": 3,
"EngineAssociation": "5.6",
"Category": "",
"Description": "",
"Modules": [
{
"Name": "RepsiCore",
"Type": "Runtime",
"LoadingPhase": "Default"
}
]
}
23 changes: 12 additions & 11 deletions Source/Repsi.Target.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using UnrealBuildTool;

public class RepsiTarget : TargetRules
{
public RepsiTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "RepsiCore" } );
}
}
using UnrealBuildTool;

public class RepsiTarget : TargetRules
{
public RepsiTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
DefaultBuildSettings = BuildSettingsVersion.V5;
ExtraModuleNames.AddRange( new string[] { "RepsiCore" } );
}
}
208 changes: 105 additions & 103 deletions Source/RepsiCore/Private/TargetSphere.cpp
Original file line number Diff line number Diff line change
@@ -1,103 +1,105 @@
#include "TargetSphere.h"

#include "Net/UnrealNetwork.h"
#include "UObject/ConstructorHelpers.h"
#include "Engine/EngineTypes.h"
#include "Engine/StaticMesh.h"
#include "Materials/MaterialInterface.h"
#include "Components/SceneComponent.h"
#include "Components/StaticMeshComponent.h"

#include "DamageType_WeaponFire.h"
#include "RepsiPawn.h"

ATargetSphere::ATargetSphere(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshFinder(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));
static ConstructorHelpers::FObjectFinder<UMaterialInterface> MaterialFinder(TEXT("Material'/Game/Assets/TargetSphere/M_TargetSphere.M_TargetSphere'"));

// Enable replication, and set a relatively short cull distance for testing
bReplicates = true;
NetCullDistanceSquared = FMath::Square(1500.0f);

// This actor will tick for a moment after it's shot, so it can animate its color
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = false;
ColorChangeDuration = 0.333f;

// Make our Actor damageable initially, so Weapon traces will deal damage
SetCanBeDamaged(true);

RootComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("RootComponent"));

MeshComponent = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("MeshComponent"));
MeshComponent->SetupAttachment(RootComponent);
MeshComponent->SetStaticMesh(MeshFinder.Object);
MeshComponent->SetMaterial(0, MaterialFinder.Object);
}

void ATargetSphere::PostInitializeComponents()
{
Super::PostInitializeComponents();

MeshMID = MeshComponent->CreateDynamicMaterialInstance(0);
}

float ATargetSphere::InternalTakePointDamage(float Damage, FPointDamageEvent const& PointDamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
// If shot with a Weapon, accept the damage event and randomize the sphere's Color
if (PointDamageEvent.DamageTypeClass == UDamageType_WeaponFire::StaticClass())
{
const ARepsiPawn* Pawn = EventInstigator ? EventInstigator->GetPawn<ARepsiPawn>() : nullptr;
if (Pawn)
{
Color = Pawn->Color;
OnRep_Color();
}
return Damage;
}
return Super::InternalTakePointDamage(Damage, PointDamageEvent, EventInstigator, DamageCauser);
}

void ATargetSphere::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);

// Compute our relative progress in the color change animation
const float CurrentTime = GetWorld()->GetTimeSeconds();
const float ColorChangeElapsed = CurrentTime - LastColorChangeTime;
const float ColorChangeAlpha = ColorChangeDuration < KINDA_SMALL_NUMBER ? 1.0f : FMath::Min(1.0f, ColorChangeElapsed / ColorChangeDuration);

// Start interpolating toward a brighter version of new color, settling on
// the unmodified color at the end
const FLinearColor TargetColor = Color * FMath::Lerp(10.0f, 1.0f, ColorChangeAlpha);
const FLinearColor NewColor = FLinearColor::LerpUsingHSV(PreviousColor, TargetColor, ColorChangeAlpha);
if (MeshMID)
{
MeshMID->SetVectorParameterValue(TEXT("Color"), NewColor);
}

// Disable ticking once the animation is finished
if (ColorChangeAlpha >= 1.0f)
{
SetActorTickEnabled(false);
}
}

void ATargetSphere::OnRep_Color()
{
if (MeshMID)
{
PreviousColor = MeshMID->K2_GetVectorParameterValue(TEXT("Color"));
}
LastColorChangeTime = GetWorld()->GetTimeSeconds();
SetActorTickEnabled(true);
}

void ATargetSphere::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);

DOREPLIFETIME(ATargetSphere, Color);
}
#include "TargetSphere.h"

#include "Net/UnrealNetwork.h"
#include "UObject/ConstructorHelpers.h"
#include "Engine/EngineTypes.h"
#include "Engine/StaticMesh.h"
#include "Materials/MaterialInterface.h"
#include "Components/SceneComponent.h"
#include "Components/StaticMeshComponent.h"
#include "GameFramework/DamageType.h" // Add this include for FPointDamageEvent
#include "Engine/DamageEvents.h" // Include this header for FPointDamageEvent

#include "DamageType_WeaponFire.h"
#include "RepsiPawn.h"

ATargetSphere::ATargetSphere(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshFinder(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));
static ConstructorHelpers::FObjectFinder<UMaterialInterface> MaterialFinder(TEXT("Material'/Game/Assets/TargetSphere/M_TargetSphere.M_TargetSphere'"));

// Enable replication, and set a relatively short cull distance for testing
bReplicates = true;
NetCullDistanceSquared = FMath::Square(1500.0f);

// This actor will tick for a moment after it's shot, so it can animate its color
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = false;
ColorChangeDuration = 0.333f;

// Make our Actor damageable initially, so Weapon traces will deal damage
SetCanBeDamaged(true);

RootComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("RootComponent"));

MeshComponent = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("MeshComponent"));
MeshComponent->SetupAttachment(RootComponent);
MeshComponent->SetStaticMesh(MeshFinder.Object);
MeshComponent->SetMaterial(0, MaterialFinder.Object);
}

void ATargetSphere::PostInitializeComponents()
{
Super::PostInitializeComponents();

MeshMID = MeshComponent->CreateDynamicMaterialInstance(0);
}

float ATargetSphere::InternalTakePointDamage(float Damage, FPointDamageEvent const& PointDamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
// If shot with a Weapon, accept the damage event and randomize the sphere's Color
if (PointDamageEvent.DamageTypeClass == UDamageType_WeaponFire::StaticClass())
{
const ARepsiPawn* Pawn = EventInstigator ? EventInstigator->GetPawn<ARepsiPawn>() : nullptr;
if (Pawn)
{
Color = Pawn->Color;
OnRep_Color();
}
return Damage;
}
return Super::InternalTakePointDamage(Damage, PointDamageEvent, EventInstigator, DamageCauser);
}

void ATargetSphere::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);

// Compute our relative progress in the color change animation
const float CurrentTime = GetWorld()->GetTimeSeconds();
const float ColorChangeElapsed = CurrentTime - LastColorChangeTime;
const float ColorChangeAlpha = ColorChangeDuration < KINDA_SMALL_NUMBER ? 1.0f : FMath::Min(1.0f, ColorChangeElapsed / ColorChangeDuration);

// Start interpolating toward a brighter version of new color, settling on
// the unmodified color at the end
const FLinearColor TargetColor = Color * FMath::Lerp(10.0f, 1.0f, ColorChangeAlpha);
const FLinearColor NewColor = FLinearColor::LerpUsingHSV(PreviousColor, TargetColor, ColorChangeAlpha);
if (MeshMID)
{
MeshMID->SetVectorParameterValue(TEXT("Color"), NewColor);
}

// Disable ticking once the animation is finished
if (ColorChangeAlpha >= 1.0f)
{
SetActorTickEnabled(false);
}
}

void ATargetSphere::OnRep_Color()
{
if (MeshMID)
{
PreviousColor = MeshMID->K2_GetVectorParameterValue(TEXT("Color"));
}
LastColorChangeTime = GetWorld()->GetTimeSeconds();
SetActorTickEnabled(true);
}

void ATargetSphere::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);

DOREPLIFETIME(ATargetSphere, Color);
}
Loading