Cody WIP before cleanup

This commit is contained in:
2026-06-17 22:49:44 -04:00
parent 299687734f
commit abccaaa14c
7 changed files with 224 additions and 5 deletions

View File

@@ -33,13 +33,14 @@ void AProjectileBase::BeginPlay()
if (collision)
collision->OnComponentHit.AddDynamic(this, &AProjectileBase::OnHit);
}
// Called every frame
void AProjectileBase::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector Location = GetActorLocation();
GEngine->AddOnScreenDebugMessage(3,10.f,FColor::Red,FString::Printf(TEXT("Projectile Location %f,%f,%f"), Location.X, Location.Y, Location.Z));
}

View File

@@ -13,6 +13,7 @@ AWeaponBase::AWeaponBase()
}
// Called when the game starts or when spawned
void AWeaponBase::BeginPlay()
{
@@ -46,3 +47,82 @@ void AWeaponBase::MagRepacking()
// }
}
}
void AWeaponBase::Server_SpawnProjectile_Implementation()
{
FVector Location;
if (WeaponMesh->DoesSocketExist("Socket_Projectile"))
Location = WeaponMesh->GetSocketLocation("Socket_Projectile");
FRotator Rotation = GetActorRotation();
FVector Dir = GetOwner()->GetActorForwardVector();
// GetActorEyesViewPoint(Location, Rotation);
if (Location.Equals(FVector::ZeroVector))
Location += Dir * 55.f;
else
{
GEngine->AddOnScreenDebugMessage(2,10.f,FColor::Green,TEXT("Server Failed to get Socket Location"));
return;
}
if (!ProjectileClass)
{
GEngine->AddOnScreenDebugMessage(2, 10.f, FColor::Emerald, "Server No Projectile Set");
return;
}
FActorSpawnParameters SpawnInfo;
SpawnInfo.Owner = GetOwner();
SpawnInfo.Instigator = GetInstigator();
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
GEngine->AddOnScreenDebugMessage(2,10.f,FColor::Red,FString::Printf(TEXT("Server Spawning Projectile Location %f,%f,%f"), Location.X, Location.Y, Location.Z));
AActor* projectile = GetWorld()->SpawnActor<AActor>(ProjectileClass, Location, Rotation, SpawnInfo);
if (!projectile)
GEngine->AddOnScreenDebugMessage(2,10.f,FColor::Red,TEXT("Failed to Spawn"));
Client_SpawnProjectile();
}
bool AWeaponBase::Server_SpawnProjectile_Validate()
{
return true;
}
void AWeaponBase::Client_SpawnProjectile_Implementation()
{
FVector Location;
if (WeaponMesh->DoesSocketExist("Socket_Projectile"))
Location = WeaponMesh->GetSocketLocation("Socket_Projectile");
FRotator Rotation = GetActorRotation();
FVector Dir = GetActorForwardVector();
// GetActorEyesViewPoint(Location, Rotation);
if (Location.Equals(FVector::ZeroVector))
Location += Dir * 55.f;
else
{
GEngine->AddOnScreenDebugMessage(1,10.f,FColor::Green,TEXT("Client Failed to get Socket Location"));
return;
}
if (!ProjectileClass)
{
GEngine->AddOnScreenDebugMessage(1, 10.f, FColor::Emerald, "Client No Projectile Set");
return;
}
FActorSpawnParameters SpawnInfo;
SpawnInfo.Owner = this;
SpawnInfo.Instigator = GetInstigator();
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
GEngine->AddOnScreenDebugMessage(1,10.f,FColor::Red,FString::Printf(TEXT("Client Spawning Projectile Location %f,%f,%f"), Location.X, Location.Y, Location.Z));
GetWorld()->SpawnActor<AActor>(ProjectileClass, Location, Rotation, SpawnInfo);
}
bool AWeaponBase::Client_SpawnProjectile_Validate()
{
return true;
}

View File

@@ -37,6 +37,9 @@ private:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon Ammo", meta=(AllowPrivateAccess=true))
int RESERVE_AMMO_POOL_DEFAULT = 120;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon Ammo", meta=(AllowPrivateAccess=true))
TSubclassOf<AActor> ProjectileClass;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta=(AllowPrivateAccess=true))
USkeletalMeshComponent* WeaponMesh;
@@ -55,6 +58,13 @@ public:
/*Functions*/
UFUNCTION()
void MagRepacking();
UFUNCTION(Server, Reliable, WithValidation, BlueprintCallable)
void Server_SpawnProjectile();
UFUNCTION(Client, Reliable, WithValidation, BlueprintCallable)
void Client_SpawnProjectile();
/*C++ only declarations*/
private: