|
|
@ -3,15 +3,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "MyProjectile.h"
|
|
|
|
#include "MyProjectile.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Trooper.h"
|
|
|
|
#include "Net/UnrealNetwork.h"
|
|
|
|
#include "Net/UnrealNetwork.h"
|
|
|
|
#include "VisualLogger/VisualLoggerCustomVersion.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AMyProjectile::AMyProjectile() {
|
|
|
|
AMyProjectile::AMyProjectile() {
|
|
|
|
|
|
|
|
// if (!RootComponent) {
|
|
|
|
|
|
|
|
// RootComponent = CreateDefaultSubobject<USceneComponent>(
|
|
|
|
|
|
|
|
// TEXT("ProjectileSceneComponent"));
|
|
|
|
|
|
|
|
// }
|
|
|
|
// if (!CollisionComponent) {
|
|
|
|
// if (!CollisionComponent) {
|
|
|
|
// CollisionComponent = CreateDefaultSubobject<USphereComponent>(
|
|
|
|
// CollisionComponent = CreateDefaultSubobject<USphereComponent>(
|
|
|
|
// TEXT("SphereComponent"));
|
|
|
|
// TEXT("SphereComponent"));
|
|
|
|
|
|
|
|
// RootComponent = CollisionComponent;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// RootComponent = CollisionComponent;
|
|
|
|
|
|
|
|
if (!ProjectileMeshComponent) {
|
|
|
|
if (!ProjectileMeshComponent) {
|
|
|
|
ProjectileMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(
|
|
|
|
ProjectileMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(
|
|
|
|
TEXT("ProjectileMeshComponent"));
|
|
|
|
TEXT("ProjectileMeshComponent"));
|
|
|
@ -27,7 +31,9 @@ AMyProjectile::AMyProjectile() {
|
|
|
|
ProjectileMovementComponent = CreateDefaultSubobject<
|
|
|
|
ProjectileMovementComponent = CreateDefaultSubobject<
|
|
|
|
UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
|
|
|
|
UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
|
|
|
|
ProjectileMovementComponent->SetUpdatedComponent(
|
|
|
|
ProjectileMovementComponent->SetUpdatedComponent(
|
|
|
|
|
|
|
|
// CollisionComponent);
|
|
|
|
ProjectileMeshComponent);
|
|
|
|
ProjectileMeshComponent);
|
|
|
|
|
|
|
|
ProjectileMovementComponent->bRotationFollowsVelocity = true;
|
|
|
|
ProjectileMovementComponent->InitialSpeed = 1000.0f;
|
|
|
|
ProjectileMovementComponent->InitialSpeed = 1000.0f;
|
|
|
|
ProjectileMovementComponent->MaxSpeed = 1000.0f;
|
|
|
|
ProjectileMovementComponent->MaxSpeed = 1000.0f;
|
|
|
|
ProjectileMovementComponent->ProjectileGravityScale = 0.0f;
|
|
|
|
ProjectileMovementComponent->ProjectileGravityScale = 0.0f;
|
|
|
@ -42,6 +48,7 @@ void AMyProjectile::Initialize(const UAbility *Ability,
|
|
|
|
ProjectileMovementComponent->MaxSpeed = Ability->Speed;
|
|
|
|
ProjectileMovementComponent->MaxSpeed = Ability->Speed;
|
|
|
|
Damage = Ability->Damage;
|
|
|
|
Damage = Ability->Damage;
|
|
|
|
float Scale = Ability->LinearWidth / 100;
|
|
|
|
float Scale = Ability->LinearWidth / 100;
|
|
|
|
|
|
|
|
// CollisionComponent->SetSphereRadius(Ability->LinearWidth / 2);
|
|
|
|
ProjectileMeshComponent->SetWorldScale3D({Scale, Scale, Scale});
|
|
|
|
ProjectileMeshComponent->SetWorldScale3D({Scale, Scale, Scale});
|
|
|
|
PlayerIndex = playerIndex;
|
|
|
|
PlayerIndex = playerIndex;
|
|
|
|
SetLifeSpan(PathLength / Ability->Speed);
|
|
|
|
SetLifeSpan(PathLength / Ability->Speed);
|
|
|
@ -52,6 +59,51 @@ void AMyProjectile::Shoot(FVector From, FVector To) const {
|
|
|
|
(To - From).GetSafeNormal() * ProjectileMovementComponent->InitialSpeed;
|
|
|
|
(To - From).GetSafeNormal() * ProjectileMovementComponent->InitialSpeed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AMyProjectile::NotifyActorBeginOverlap(AActor *OtherActor) {
|
|
|
|
|
|
|
|
Super::NotifyActorBeginOverlap(OtherActor);
|
|
|
|
|
|
|
|
ATrooper *OtherTrooper = Cast<ATrooper>(OtherActor);
|
|
|
|
|
|
|
|
if (OtherTrooper) {
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning,
|
|
|
|
|
|
|
|
TEXT("Begin overlap: id: %d, index: %d, damage: %f, my index: %d"
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
OtherTrooper->GetId(), OtherTrooper->GetPlayerIndex(), Damage,
|
|
|
|
|
|
|
|
PlayerIndex);
|
|
|
|
|
|
|
|
if (PlayerIndex != -1 && PlayerIndex != OtherTrooper->
|
|
|
|
|
|
|
|
GetPlayerIndex()) {
|
|
|
|
|
|
|
|
OtherTrooper->TakeDamage(Damage);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Overlapped not a trooper"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AMyProjectile::NotifyHit(UPrimitiveComponent *MyComp,
|
|
|
|
|
|
|
|
AActor *Other,
|
|
|
|
|
|
|
|
UPrimitiveComponent *OtherComp,
|
|
|
|
|
|
|
|
bool bSelfMoved,
|
|
|
|
|
|
|
|
FVector HitLocation,
|
|
|
|
|
|
|
|
FVector HitNormal,
|
|
|
|
|
|
|
|
FVector NormalImpulse,
|
|
|
|
|
|
|
|
const FHitResult &Hit) {
|
|
|
|
|
|
|
|
Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation,
|
|
|
|
|
|
|
|
HitNormal,
|
|
|
|
|
|
|
|
NormalImpulse, Hit);
|
|
|
|
|
|
|
|
ATrooper *OtherTrooper = Cast<ATrooper>(Other);
|
|
|
|
|
|
|
|
if (OtherTrooper) {
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning,
|
|
|
|
|
|
|
|
TEXT("On Hit: id: %d, index: %d, damage: %f, my index: %d"
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
OtherTrooper->GetId(), OtherTrooper->GetPlayerIndex(), Damage,
|
|
|
|
|
|
|
|
PlayerIndex);
|
|
|
|
|
|
|
|
if (PlayerIndex != -1 && PlayerIndex != OtherTrooper->
|
|
|
|
|
|
|
|
GetPlayerIndex()) {
|
|
|
|
|
|
|
|
OtherTrooper->TakeDamage(Damage);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Overlapped not a trooper"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AMyProjectile::BeginPlay() {
|
|
|
|
void AMyProjectile::BeginPlay() {
|
|
|
|
Super::BeginPlay();
|
|
|
|
Super::BeginPlay();
|
|
|
@ -61,4 +113,8 @@ void AMyProjectile::GetLifetimeReplicatedProps(
|
|
|
|
TArray<FLifetimeProperty> &OutLifetimeProps) const {
|
|
|
|
TArray<FLifetimeProperty> &OutLifetimeProps) const {
|
|
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
|
|
DOREPLIFETIME(AMyProjectile, Damage);
|
|
|
|
DOREPLIFETIME(AMyProjectile, Damage);
|
|
|
|
|
|
|
|
DOREPLIFETIME(AMyProjectile, PlayerIndex);
|
|
|
|
|
|
|
|
// DOREPLIFETIME(AMyProjectile, CollisionComponent);
|
|
|
|
|
|
|
|
DOREPLIFETIME(AMyProjectile, ProjectileMeshComponent);
|
|
|
|
|
|
|
|
DOREPLIFETIME(AMyProjectile, ProjectileMovementComponent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|