// Fill out your copyright notice in the Description page of Project Settings. #include "WeaponBase.h" // Sets default values AWeaponBase::AWeaponBase() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; bReplicates = true; WeaponMesh = CreateDefaultSubobject(TEXT("Weapon Component")); } // Called when the game starts or when spawned void AWeaponBase::BeginPlay() { Super::BeginPlay(); // AMMO_REPACK.AddDynamic(this, &AWeaponBase::MagRepacking); for (int i = 0; i < RESERVE_MAG_COUNT; i++) { // AMagazineActor* mag = new AMagazineActor(); // mag->SetAmmoValues(MAX_AMMO_COUNT); // ActiveMags.Add(mag); } } // Called every frame void AWeaponBase::Tick(float DeltaTime) { Super::Tick(DeltaTime); } void AWeaponBase::MagRepacking() { RESERVE_AMMO_POOL_DEFAULT -= 1; if (RESERVE_AMMO_POOL_DEFAULT <= 0) { RESERVE_AMMO_POOL_DEFAULT = 0; // for (AMagazineActor* mag : ActiveMags) // { // mag->hasReserveAmmo = false; // } } } 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(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(ProjectileClass, Location, Rotation, SpawnInfo); } bool AWeaponBase::Client_SpawnProjectile_Validate() { return true; }