parent
a51acf9d02
commit
e68312eaec
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,68 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "MyExplosion.h"
|
||||
|
||||
#include "Trooper.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "Net/UnrealNetwork.h"
|
||||
#include "Particles/ParticleSystemComponent.h"
|
||||
|
||||
AMyExplosion::AMyExplosion() {
|
||||
// if (!CollisionComponent) {
|
||||
// CollisionComponent = CreateDefaultSubobject<USphereComponent>(
|
||||
// TEXT("SphereComponent"));
|
||||
// RootComponent = CollisionComponent;
|
||||
// }
|
||||
if (!ParticleSystemComponent) {
|
||||
ParticleSystemComponent = CreateDefaultSubobject<
|
||||
UParticleSystemComponent>(
|
||||
TEXT("ParticleSystemComponent"));
|
||||
RootComponent = ParticleSystemComponent;
|
||||
}
|
||||
InitialLifeSpan = 1.0f;
|
||||
}
|
||||
|
||||
void AMyExplosion::Initialize(float damage,
|
||||
float splashRadius,
|
||||
uint8 playerIndex) {
|
||||
Damage = damage;
|
||||
PlayerIndex = playerIndex;
|
||||
float Scale = splashRadius / 50;
|
||||
// CollisionComponent->SetWorldScale3D({Scale, Scale, Scale});
|
||||
if (ParticleSystemComponent && ParticleSystemComponent->IsValidLowLevel()) {
|
||||
ParticleSystemComponent->SetWorldScale3D({Scale, Scale, Scale});
|
||||
}
|
||||
}
|
||||
|
||||
void AMyExplosion::BeginPlay() {
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void AMyExplosion::NotifyActorBeginOverlap(AActor *OtherActor) {
|
||||
Super::NotifyActorBeginOverlap(OtherActor);
|
||||
ATrooper *OtherTrooper = Cast<ATrooper>(OtherActor);
|
||||
if (OtherTrooper) {
|
||||
UE_LOG(LogTemp, Warning,
|
||||
TEXT(
|
||||
"Begin explosion 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 AMyExplosion::GetLifetimeReplicatedProps(
|
||||
TArray<FLifetimeProperty> &OutLifetimeProps) const {
|
||||
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||
DOREPLIFETIME(AMyExplosion, Damage);
|
||||
DOREPLIFETIME(AMyExplosion, PlayerIndex);
|
||||
// DOREPLIFETIME(AMyExplosion, CollisionComponent);
|
||||
DOREPLIFETIME(AMyExplosion, ParticleSystemComponent);
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "MyExplosion.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class TURNBASEDTUTORIAL_API AMyExplosion : public AActor {
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AMyExplosion();
|
||||
|
||||
void Initialize(float damage,
|
||||
float splashRadius,
|
||||
uint8 playerIndex);
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual void NotifyActorBeginOverlap(AActor *OtherActor) override;
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
float Damage;
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
int8 PlayerIndex = -1;
|
||||
|
||||
// UPROPERTY(EditAnywhere, Replicated)
|
||||
// USphereComponent *CollisionComponent;
|
||||
|
||||
UPROPERTY(EditAnywhere, Replicated)
|
||||
UParticleSystemComponent *ParticleSystemComponent;
|
||||
};
|
Loading…
Reference in new issue