diff --git a/Content/Characters/Mannequins/Anims/Unarmed/ABP_Unarmed.uasset b/Content/Characters/Mannequins/Anims/Unarmed/ABP_Unarmed.uasset index 05cfb06..ca2756d 100644 Binary files a/Content/Characters/Mannequins/Anims/Unarmed/ABP_Unarmed.uasset and b/Content/Characters/Mannequins/Anims/Unarmed/ABP_Unarmed.uasset differ diff --git a/Source/OpenConflict/Weapons/MagazineActor.cpp b/Source/OpenConflict/Weapons/MagazineActor.cpp new file mode 100644 index 0000000..8cb7c15 --- /dev/null +++ b/Source/OpenConflict/Weapons/MagazineActor.cpp @@ -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; +} \ No newline at end of file diff --git a/Source/OpenConflict/Weapons/MagazineActor.h b/Source/OpenConflict/Weapons/MagazineActor.h new file mode 100644 index 0000000..382096a --- /dev/null +++ b/Source/OpenConflict/Weapons/MagazineActor.h @@ -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); +}; diff --git a/Source/OpenConflict/Weapons/WeaponBase.cpp b/Source/OpenConflict/Weapons/WeaponBase.cpp index 6449d14..3df1ecd 100644 --- a/Source/OpenConflict/Weapons/WeaponBase.cpp +++ b/Source/OpenConflict/Weapons/WeaponBase.cpp @@ -8,6 +8,8 @@ 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")); } @@ -15,6 +17,13 @@ AWeaponBase::AWeaponBase() 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); + } } @@ -25,3 +34,15 @@ void AWeaponBase::Tick(float 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; + // } + } +} diff --git a/Source/OpenConflict/Weapons/WeaponBase.h b/Source/OpenConflict/Weapons/WeaponBase.h index 962ab25..f65d3f3 100644 --- a/Source/OpenConflict/Weapons/WeaponBase.h +++ b/Source/OpenConflict/Weapons/WeaponBase.h @@ -4,23 +4,79 @@ #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; -public: - // Sets default values for this actor's properties - AWeaponBase(); + /*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 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: +public: + /*Properties*/ + + /*Functions*/ // Called every frame virtual void Tick(float DeltaTime) override; - + + // Sets default values for this actor's properties + AWeaponBase(); + }; diff --git a/Source/OpenConflict/Weapons/WeaponEnums.h b/Source/OpenConflict/Weapons/WeaponEnums.h new file mode 100644 index 0000000..f52c110 --- /dev/null +++ b/Source/OpenConflict/Weapons/WeaponEnums.h @@ -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") +}; \ No newline at end of file