Added BaseWeaponClass, WeaponInventory, WeaponItemClass, Character basic functionality

This commit is contained in:
Marcel Hara 2023-09-27 15:02:06 +01:00
parent 10eb04fa77
commit 09b22ff33d
8 changed files with 92 additions and 2 deletions

View File

@ -3,6 +3,8 @@
#include "BaseWeaponClass.h"
#include "Components/CapsuleComponent.h"
// Sets default values
ABaseWeaponClass::ABaseWeaponClass()

View File

@ -6,6 +6,8 @@
#include "WeaponItemClass.h"
#include "BaseWeaponClass.generated.h"
class UCapsuleComponent;
UCLASS()
class ENDLESSVENDETTA_API ABaseWeaponClass : public AWeaponItemClass
{
@ -22,4 +24,20 @@ protected:
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere)
FName WeaponName;
UPROPERTY(EditAnywhere)
int WeaponDamage;
UPROPERTY(EditAnywhere)
float FireRate;
UPROPERTY(EditAnywhere)
int MagazineSize;
UPROPERTY(EditAnywhere)
UTexture2D* WeaponImage;
};

View File

@ -69,6 +69,9 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
//Looking
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Look);
//Weapon Switching
EnhancedInputComponent->BindAction(WeaponEquipAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::WeaponEquip);
}
}
@ -99,6 +102,11 @@ void AEndlessVendettaCharacter::Look(const FInputActionValue& Value)
}
}
void AEndlessVendettaCharacter::WeaponEquip()
{
UE_LOG(LogTemp, Display, TEXT("EQUIPPING WEAPONS"));
}
void AEndlessVendettaCharacter::SetHasRifle(bool bNewHasRifle)
{
bHasRifle = bNewHasRifle;

View File

@ -7,6 +7,7 @@
#include "InputActionValue.h"
#include "EndlessVendettaCharacter.generated.h"
class UWeaponInventory;
class UInputComponent;
class USkeletalMeshComponent;
class USceneComponent;
@ -39,6 +40,10 @@ class AEndlessVendettaCharacter : public ACharacter
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
class UInputAction* MoveAction;
/** Weapon Equip Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
class UInputAction* WeaponEquipAction;
public:
AEndlessVendettaCharacter();
@ -71,6 +76,8 @@ protected:
/** Called for looking input */
void Look(const FInputActionValue& Value);
void WeaponEquip();
protected:
// APawn interface
virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override;
@ -82,6 +89,9 @@ public:
/** Returns FirstPersonCameraComponent subobject **/
UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; }
private:
UWeaponInventory* WeaponInventory;
};

View File

@ -3,6 +3,8 @@
#include "WeaponInventory.h"
#include "WeaponItemClass.h"
// Sets default values for this component's properties
UWeaponInventory::UWeaponInventory()
@ -10,8 +12,7 @@ UWeaponInventory::UWeaponInventory()
// 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;
// ...
}
@ -33,3 +34,11 @@ void UWeaponInventory::TickComponent(float DeltaTime, ELevelTick TickType, FActo
// ...
}
//Called from blueprints from the player
void UWeaponInventory::WeaponPickup(AActor* WeaponPickedUp)
{
AWeaponItemClass* WeaponItemClass = Cast<AWeaponItemClass>(WeaponPickedUp);
WeaponsArray.Add(WeaponItemClass);
WeaponPickedUp->Destroy();
}

View File

@ -7,6 +7,8 @@
#include "WeaponInventory.generated.h"
class AWeaponItemClass;
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class ENDLESSVENDETTA_API UWeaponInventory : public UActorComponent
{
@ -20,7 +22,23 @@ protected:
// Called when the game starts
virtual void BeginPlay() override;
UPROPERTY(VisibleAnywhere, Category = "Weapon System")
TArray<AWeaponItemClass*> WeaponsArray;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
//Using a getter to get the protected weaponsArray
UFUNCTION()
TArray<AWeaponItemClass*> GetWeaponArray() const { return WeaponsArray; }
//Using a Setter to set the protected weapons array to the getter
UFUNCTION()
void SetArray(const TArray<AWeaponItemClass*> weaponArray) { WeaponsArray = weaponArray; }
private:
//Called from blueprints from the player
UFUNCTION(BlueprintCallable)
void WeaponPickup(AActor* WeaponPickedUp);
};

View File

@ -24,3 +24,18 @@ void AWeaponItemClass::Tick(float DeltaTime)
Super::Tick(DeltaTime);
}
//Called from WeaponInventory actor component class
void AWeaponItemClass::Equip(ABaseWeaponClass* PickedUpWeapon)
{
//get the weapons in the array from component
//whatever input is being pressed add that to the player socket
//if there is no gun simply add it to the socket
//if there is a weapon remove from socket and add the requested one
}
//Called from WeaponInventory actor component class
void AWeaponItemClass::Unequip(ABaseWeaponClass* PickedUpWeapon)
{
//same as equip but
}

View File

@ -6,6 +6,8 @@
#include "GameFramework/Actor.h"
#include "WeaponItemClass.generated.h"
class ABaseWeaponClass;
UCLASS()
class ENDLESSVENDETTA_API AWeaponItemClass : public AActor
{
@ -22,4 +24,12 @@ protected:
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
private:
UFUNCTION()
void Equip(ABaseWeaponClass* PickedUpWeapon);
UFUNCTION()
void Unequip(ABaseWeaponClass* PickedUpWeapon);
};