Compare commits
22 Commits
7e393cd7bb
...
WeaponBase
| Author | SHA1 | Date | |
|---|---|---|---|
| da3abbfafb | |||
| 7a2a24b654 | |||
| 5dbee0a354 | |||
| 16e03e2360 | |||
| 7d48a2d40b | |||
| 0361eb2c00 | |||
| 47e434f596 | |||
| 5f827eeadf | |||
| 970101a74c | |||
| 3f02fd02e5 | |||
| 4662e6701a | |||
| ecd15c271f | |||
| 494d76833f | |||
| da46541a07 | |||
| ef5830dea3 | |||
| c7e3a83497 | |||
| 646276ab2c | |||
| 7b9a33abfe | |||
| 3b9a02b3b1 | |||
| dd3648f5b9 | |||
| a3a120491d | |||
| eb402e0458 |
Binary file not shown.
Binary file not shown.
BIN
Content/ProofOfConcept/ProjectileBase_BP.uasset
Normal file
BIN
Content/ProofOfConcept/ProjectileBase_BP.uasset
Normal file
Binary file not shown.
BIN
Content/Worlds/_GENERATED/Core/ProjectileBase.uasset
Normal file
BIN
Content/Worlds/_GENERATED/Core/ProjectileBase.uasset
Normal file
Binary file not shown.
@@ -9,6 +9,7 @@ UDDIHealth::UDDIHealth()
|
||||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
||||
// off to improve performance if you don't need them.
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
SetIsReplicatedByDefault(true);
|
||||
MaxHealth = 0;
|
||||
CurrentHealth = 0;
|
||||
ClassName = ClassNames::Scout;
|
||||
@@ -41,7 +42,7 @@ void UDDIHealth::BeginPlay()
|
||||
MaxHealth += seg;
|
||||
|
||||
CurrentHealth = MaxHealth;
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Cyan, FString::Printf(TEXT("CurrentHealth: %d"), CurrentHealth));
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Emerald, FString::Printf(TEXT("CurrentHealth: %d"), CurrentHealth));
|
||||
}
|
||||
|
||||
|
||||
@@ -81,10 +82,9 @@ void UDDIHealth::Heal()
|
||||
// Called to cause damage
|
||||
void UDDIHealth::TakeDamage(int DamageValue)
|
||||
{
|
||||
// if (HealTimer.IsValid())
|
||||
// HealTimer.Invalidate();
|
||||
GetWorld()->GetTimerManager().ClearTimer(HealTimer);
|
||||
|
||||
CurrentHealth -= DamageValue;
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::Printf(TEXT("Client Hit\nHealth: %d"), CurrentHealth));
|
||||
|
||||
}
|
||||
@@ -36,13 +36,13 @@ protected:
|
||||
ClassNames ClassName;
|
||||
|
||||
/*Functions*/
|
||||
UFUNCTION(BlueprintAuthorityOnly, BlueprintCallable, Category = "Health")
|
||||
void TakeDamage(int DamageValue);
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
UFUNCTION(BlueprintAuthorityOnly, BlueprintCallable, Category = "Health")
|
||||
void TakeDamage(int DamageValue);
|
||||
|
||||
/*C++ only declarations*/
|
||||
private:
|
||||
|
||||
@@ -9,7 +9,7 @@ struct FHealthSegment : public FTableRowBase
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health Segments")
|
||||
ClassNames Class;
|
||||
ClassNames Class = ClassNames::Basic;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health Segments")
|
||||
TArray<int> SegmentList;
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
|
||||
#include "DDICharacter.h"
|
||||
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "OpenConflict/Weapons/Projectiles/ProjectileBase.h"
|
||||
|
||||
// Sets default values
|
||||
ADDICharacter::ADDICharacter()
|
||||
@@ -17,6 +20,12 @@ ADDICharacter::ADDICharacter()
|
||||
CameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f));
|
||||
CameraComponent->bUsePawnControlRotation = true;
|
||||
|
||||
HealthComponent = CreateDefaultSubobject<UDDIHealth>(TEXT("HealthComponent"));
|
||||
|
||||
GetCapsuleComponent()->SetCollisionProfileName(TEXT("BlockAllDynamic"));
|
||||
GetCapsuleComponent()->SetGenerateOverlapEvents(true);
|
||||
GetCapsuleComponent()->SetNotifyRigidBodyCollision(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +34,11 @@ void ADDICharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (GetCapsuleComponent())
|
||||
{
|
||||
GetCapsuleComponent()->OnComponentHit.AddDynamic(this, &ADDICharacter::OnHit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
@@ -34,4 +48,73 @@ void ADDICharacter::Tick(float DeltaTime)
|
||||
|
||||
}
|
||||
|
||||
void ADDICharacter::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||
{
|
||||
Server_CharacterHit(HitComponent, OtherActor, OtherComp, NormalImpulse, Hit);
|
||||
}
|
||||
|
||||
void ADDICharacter::TakeDamage(int Damage)
|
||||
{
|
||||
HealthComponent->TakeDamage(Damage);
|
||||
}
|
||||
|
||||
bool ADDICharacter::Server_SpawnProjectile_Validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void ADDICharacter::Server_SpawnProjectile_Implementation()
|
||||
{
|
||||
FVector Location = GetActorLocation();
|
||||
FRotator Rotation = GetActorRotation();
|
||||
FVector Dir = GetActorForwardVector();
|
||||
|
||||
// GetActorEyesViewPoint(Location, Rotation);
|
||||
|
||||
Location += Dir * 55.f;
|
||||
|
||||
if (!ProjectileClass)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(1, 10.f, FColor::Emerald, "No Projectile Set");
|
||||
return;
|
||||
}
|
||||
|
||||
FActorSpawnParameters SpawnInfo;
|
||||
SpawnInfo.Owner = this;
|
||||
SpawnInfo.Instigator = GetInstigator();
|
||||
GetWorld()->SpawnActor<AActor>(ProjectileClass, Location, Rotation, SpawnInfo);
|
||||
}
|
||||
|
||||
void ADDICharacter::Client_CharacterHit_Implementation()
|
||||
{
|
||||
TakeDamage(10);
|
||||
OnDamageTaken();
|
||||
|
||||
}
|
||||
bool ADDICharacter::Client_CharacterHit_Validate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void ADDICharacter::Server_CharacterHit_Implementation(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||
{
|
||||
if (AProjectileBase* Projectile = Cast<AProjectileBase>(OtherActor))
|
||||
{
|
||||
// if (Cast<ADDICharacter>(Projectile->Owner) == this)
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Emerald, "Damage dealt");
|
||||
Client_CharacterHit();
|
||||
}
|
||||
}
|
||||
bool ADDICharacter::Server_CharacterHit_Validate(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ADDICharacter::OnRep_Health()
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "Health Replicated");
|
||||
}
|
||||
|
||||
void ADDICharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||
{
|
||||
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||
DOREPLIFETIME(ADDICharacter, HealthComponent);
|
||||
}
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Components/DDIHealth.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "Net/UnrealNetwork.h"
|
||||
#include "DDICharacter.generated.h"
|
||||
|
||||
|
||||
@@ -12,20 +14,69 @@ UCLASS()
|
||||
class OPENCONFLICT_API ADDICharacter : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
/*UPROPERTY and UFUNCTION declarations*/
|
||||
private:
|
||||
/*Properties*/
|
||||
|
||||
public:
|
||||
// Sets default values for this character's properties
|
||||
ADDICharacter();
|
||||
/*Functions*/
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Events")
|
||||
void OnDamageTaken();
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera")
|
||||
UCameraComponent* CameraComponent;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Health", ReplicatedUsing=OnRep_Health)
|
||||
UDDIHealth* HealthComponent;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Projectile")
|
||||
TSubclassOf<AActor> ProjectileClass;
|
||||
|
||||
/*Functions*/
|
||||
UFUNCTION()
|
||||
void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
||||
|
||||
UFUNCTION()
|
||||
void TakeDamage(int Damage);
|
||||
|
||||
UFUNCTION(Server, Reliable, WithValidation, BlueprintCallable)
|
||||
void Server_SpawnProjectile();
|
||||
|
||||
UFUNCTION(Client, Reliable, WithValidation, BlueprintCallable)
|
||||
void Client_CharacterHit();
|
||||
|
||||
UFUNCTION(Server, Reliable, WithValidation, BlueprintCallable)
|
||||
void Server_CharacterHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
||||
|
||||
UFUNCTION()
|
||||
void OnRep_Health();
|
||||
|
||||
/*C++ only declarations*/
|
||||
private:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
// Sets default values for this character's properties
|
||||
ADDICharacter();
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera")
|
||||
UCameraComponent* CameraComponent;
|
||||
|
||||
};
|
||||
|
||||
63
Source/OpenConflict/Weapons/MagazineActor.cpp
Normal file
63
Source/OpenConflict/Weapons/MagazineActor.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "MagazineActor.h"
|
||||
|
||||
#include "OpenConflict/PlayerCharacter/Components/DDIHealth.h"
|
||||
|
||||
// Sets default values
|
||||
AMagazineActor::AMagazineActor()
|
||||
{
|
||||
// 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;
|
||||
|
||||
|
||||
}
|
||||
// Called when the game starts or when spawned
|
||||
void AMagazineActor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void AMagazineActor::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
if (!ActiveMag && CurrentCount < MAX_COUNT )
|
||||
{
|
||||
GetWorld()->GetTimerManager().SetTimer(RepackTimer, this, &AMagazineActor::PackMag, RepackDelay, true, RepackDelay);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AMagazineActor::PackMag()
|
||||
{
|
||||
if (hasReserveAmmo)
|
||||
{
|
||||
CurrentCount += 1;
|
||||
AMMO_REPACK.Broadcast();
|
||||
}
|
||||
|
||||
if (CurrentCount >= MAX_COUNT)
|
||||
{
|
||||
CurrentCount = MAX_COUNT;
|
||||
GetWorld()->GetTimerManager().ClearTimer(RepackTimer);
|
||||
}
|
||||
}
|
||||
|
||||
void AMagazineActor::StripRound()
|
||||
{
|
||||
CurrentCount -= 1;
|
||||
if (CurrentCount <= 0)
|
||||
{
|
||||
CurrentCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void AMagazineActor::SetAmmoValues(int MaxCount)
|
||||
{
|
||||
MAX_COUNT = MaxCount;
|
||||
CurrentCount = MAX_COUNT;
|
||||
}
|
||||
76
Source/OpenConflict/Weapons/MagazineActor.h
Normal file
76
Source/OpenConflict/Weapons/MagazineActor.h
Normal file
@@ -0,0 +1,76 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "MagazineActor.generated.h"
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FAMMO_REPACK);
|
||||
UCLASS()
|
||||
class OPENCONFLICT_API AMagazineActor : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
/*UPROPERTY and UFUNCTION declarations*/
|
||||
private:
|
||||
/*Properties*/
|
||||
UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess=true))
|
||||
int MAX_COUNT;
|
||||
UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess=true))
|
||||
int CurrentCount;
|
||||
UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess=true))
|
||||
bool ActiveMag = false;
|
||||
UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess=true))
|
||||
float RepackDelay = 0.5f;
|
||||
|
||||
|
||||
/*Functions*/
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FAMMO_REPACK AMMO_REPACK;
|
||||
|
||||
/*Functions*/
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void EmptyMagEvent();
|
||||
|
||||
/*C++ only declarations*/
|
||||
private:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
void PackMag();
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
FTimerHandle RepackTimer;
|
||||
|
||||
/*Functions*/
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
bool hasReserveAmmo = true;
|
||||
|
||||
|
||||
/*Functions*/
|
||||
// Sets default values for this actor's properties
|
||||
AMagazineActor();
|
||||
AMagazineActor(int MaxCount);
|
||||
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
void StripRound();
|
||||
void SetAmmoValues(int MaxCount);
|
||||
};
|
||||
34
Source/OpenConflict/Weapons/MagazineComponenet.cpp
Normal file
34
Source/OpenConflict/Weapons/MagazineComponenet.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "MagazineComponenet.h"
|
||||
|
||||
// Sets default values for this component's properties
|
||||
UMagazineComponenet::UMagazineComponenet()
|
||||
{
|
||||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
||||
// off to improve performance if you don't need them.
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
// Called when the game starts
|
||||
void UMagazineComponenet::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// ...
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Called every frame
|
||||
void UMagazineComponenet::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
28
Source/OpenConflict/Weapons/MagazineComponenet.h
Normal file
28
Source/OpenConflict/Weapons/MagazineComponenet.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "MagazineComponenet.generated.h"
|
||||
|
||||
|
||||
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
||||
class OPENCONFLICT_API UMagazineComponenet : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
UMagazineComponenet();
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
|
||||
};
|
||||
52
Source/OpenConflict/Weapons/Projectiles/ProjectileBase.cpp
Normal file
52
Source/OpenConflict/Weapons/Projectiles/ProjectileBase.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "ProjectileBase.h"
|
||||
|
||||
#include "OpenConflict/PlayerCharacter/DDICharacter.h"
|
||||
|
||||
// Sets default values
|
||||
AProjectileBase::AProjectileBase()
|
||||
{
|
||||
// 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;
|
||||
bNetLoadOnClient = true;
|
||||
|
||||
InitialLifeSpan = 3.f;
|
||||
|
||||
|
||||
collision = CreateDefaultSubobject<USphereComponent>("Collision");
|
||||
RootComponent = collision;
|
||||
collision->BodyInstance.SetCollisionProfileName(TEXT("BlockAllDynamic"));
|
||||
|
||||
projectileMesh = CreateDefaultSubobject<UStaticMeshComponent>("ProjectileMesh");
|
||||
projectileMesh->SetupAttachment(collision);
|
||||
|
||||
projectileMotion = CreateDefaultSubobject<UProjectileMovementComponent>("ProjectileMovementComponent");
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void AProjectileBase::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (collision)
|
||||
collision->OnComponentHit.AddDynamic(this, &AProjectileBase::OnHit);
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void AProjectileBase::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void AProjectileBase::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||
{
|
||||
// if (ADDICharacter* character = Cast<ADDICharacter>(OtherActor))
|
||||
Destroy();
|
||||
|
||||
}
|
||||
64
Source/OpenConflict/Weapons/Projectiles/ProjectileBase.h
Normal file
64
Source/OpenConflict/Weapons/Projectiles/ProjectileBase.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "GameFramework/ProjectileMovementComponent.h"
|
||||
#include "ProjectileBase.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class OPENCONFLICT_API AProjectileBase : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
/*UPROPERTY and UFUNCTION declarations*/
|
||||
private:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Projectile")
|
||||
UStaticMeshComponent* projectileMesh;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Projectile")
|
||||
USphereComponent* collision;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Projectile")
|
||||
UProjectileMovementComponent* projectileMotion;
|
||||
|
||||
/*Functions*/
|
||||
UFUNCTION()
|
||||
void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
||||
|
||||
|
||||
/*C++ only declarations*/
|
||||
private:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
// Sets default values for this actor's properties
|
||||
AProjectileBase();
|
||||
|
||||
};
|
||||
48
Source/OpenConflict/Weapons/WeaponBase.cpp
Normal file
48
Source/OpenConflict/Weapons/WeaponBase.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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<USkeletalMeshComponent>(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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
82
Source/OpenConflict/Weapons/WeaponBase.h
Normal file
82
Source/OpenConflict/Weapons/WeaponBase.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "WeaponEnums.h"
|
||||
// #include "UMagazine.h"
|
||||
#include "WeaponBase.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class OPENCONFLICT_API AWeaponBase : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
/*UPROPERTY and UFUNCTION declarations*/
|
||||
private:
|
||||
/*Properties*/
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon HUD", meta=(AllowPrivateAccess=true))
|
||||
UTexture2D* Texture;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon Anims", meta=(AllowPrivateAccess=true))
|
||||
WeaponNames WeaponNameEnum;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon Anims", meta=(AllowPrivateAccess=true))
|
||||
FName AttachSocketName;
|
||||
|
||||
/*Ammo counter for in mags*/
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon Ammo", meta=(AllowPrivateAccess=true))
|
||||
int MAX_AMMO_COUNT = 30; //Tracks max ammo in one mag, not to be edited during runtime ever
|
||||
UPROPERTY(BlueprintReadOnly, Category="Weapon Ammo", meta=(AllowPrivateAccess=true))
|
||||
int MagIndex; //Tracks index for ActiveMags Array
|
||||
// UPROPERTY(BlueprintReadOnly, Category="Weapon Ammo", meta=(AllowPrivateAccess=true))
|
||||
// TArray<UMagazine*> ActiveMags; //Tracks all mags for weapon
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon Ammo", meta=(AllowPrivateAccess=true))
|
||||
int RESERVE_MAG_COUNT = 2; //Tracks how many mags are kept in reserve. DO NOT INCLUDE MAG IN WEAPON
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon Ammo", meta=(AllowPrivateAccess=true))
|
||||
int RESERVE_AMMO_POOL_DEFAULT = 120;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta=(AllowPrivateAccess=true))
|
||||
USkeletalMeshComponent* WeaponMesh;
|
||||
|
||||
/*Functions*/
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
// UPROPERTY(BlueprintAssignable)
|
||||
// FAMMO_REPACK AMMO_REPACK;
|
||||
|
||||
/*Functions*/
|
||||
UFUNCTION()
|
||||
void MagRepacking();
|
||||
|
||||
/*C++ only declarations*/
|
||||
private:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
// Sets default values for this actor's properties
|
||||
AWeaponBase();
|
||||
|
||||
};
|
||||
13
Source/OpenConflict/Weapons/WeaponEnums.h
Normal file
13
Source/OpenConflict/Weapons/WeaponEnums.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "WeaponEnums.generated.h"
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class WeaponNames : uint8
|
||||
{
|
||||
Pistol = 0 UMETA(DisplayName = "Pistol"),
|
||||
Rifle = 1 UMETA(DisplayName = "Rifle"),
|
||||
Shotgun = 2 UMETA(DisplayName = "Shotgun"),
|
||||
Sniper = 3 UMETA(DisplayName = "Sniper")
|
||||
};
|
||||
Reference in New Issue
Block a user