44
55#include " Core/Actor/AccelByteWarsMissile.h"
66
7+ #include " AccelByteWarsMissileTrail.h"
78#include " AccelByteWars/Core/Player/AccelByteWarsPlayerPawn.h"
89#include " Core/GameModes/AccelByteWarsInGameGameMode.h"
910#include " Core/GameStates/AccelByteWarsInGameGameState.h"
@@ -61,6 +62,8 @@ void AAccelByteWarsMissile::BeginPlay()
6162
6263 // Setup event for OnOwnerDestroyed (in blueprint)
6364 DestroyActorOnOwnerDestroyed ();
65+
66+ SpawnMissileTrail ();
6467}
6568
6669void AAccelByteWarsMissile::Destroyed ()
@@ -241,6 +244,10 @@ void AAccelByteWarsMissile::OnRepNotify_Color()
241244 return ;
242245
243246 AccelByteWarsProceduralMesh->UpdateColor (Color);
247+ if (HasAuthority ())
248+ {
249+ MissileTrail->Server_SetColor (Color);
250+ }
244251}
245252
246253void AAccelByteWarsMissile::OnRepNotify_Velocity ()
@@ -516,10 +523,6 @@ void AAccelByteWarsMissile::DecrementPlayerMissileCount()
516523 if (GetOwner () == nullptr )
517524 return ;
518525
519- AAccelByteWarsPlayerPawn* ABPawn = Cast<AAccelByteWarsPlayerPawn>(GetOwner ());
520- if (ABPawn == nullptr )
521- return ;
522-
523526 AAccelByteWarsPlayerController* ABPlayerController = Cast<AAccelByteWarsPlayerController>(GetOwner ()->GetInstigatorController ());
524527 if (ABPlayerController == nullptr )
525528 return ;
@@ -532,8 +535,6 @@ void AAccelByteWarsMissile::DecrementPlayerMissileCount()
532535 return ;
533536
534537 ABPlayerState->MissilesFired --;
535- ABPawn->FiredMissile = nullptr ;
536- ABPawn->MissileTrail = nullptr ;
537538}
538539
539540void AAccelByteWarsMissile::NotifyShipHitByMissile () const
@@ -588,3 +589,27 @@ void AAccelByteWarsMissile::NotifyShipHitByMissile() const
588589 );
589590 }
590591}
592+
593+ void AAccelByteWarsMissile::SpawnMissileTrail ()
594+ {
595+ if (!HasAuthority ())
596+ {
597+ return ;
598+ }
599+
600+ FActorSpawnParameters SpawnParameters;
601+ SpawnParameters.Owner = this ;
602+ SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
603+
604+ MissileTrail = Owner->GetWorld ()->SpawnActor <AAccelByteWarsMissileTrail>(
605+ MissileTrailActor,
606+ FTransform (GetActorRotation (), GetActorLocation ()),
607+ SpawnParameters);
608+ if (!MissileTrail)
609+ {
610+ return ;
611+ }
612+
613+ MissileTrail->SetReplicates (true );
614+ MissileTrail->AttachToActor (this , FAttachmentTransformRules::SnapToTargetIncludingScale);
615+ }
0 commit comments