Added Start Functionality for weapons to inventory

This commit is contained in:
MARCEL HARA 2023-11-23 12:03:15 +00:00
parent 5bdee1fbaf
commit ad2d62dc73
5 changed files with 36 additions and 5 deletions

View File

@ -65,6 +65,8 @@ void AEndlessVendettaCharacter::BeginPlay()
GadgetManager->SpawnGadgetsOnBeginPlay(Cast<USceneComponent>(PlayersCamera));
break;
}
InventoryComponent = Cast<UInventoryComponent>(GetWorld()->GetFirstPlayerController()->GetComponentByClass(UInventoryComponent::StaticClass()));
}
void AEndlessVendettaCharacter::Tick(float DeltaTime)

View File

@ -8,6 +8,7 @@
#include "InputActionValue.h"
#include "Components/ArrowComponent.h"
#include "GadgetSystem/GadgetManager.h"
#include "EndlessVendettaCharacter.generated.h"
class UWeaponInventory;
@ -200,4 +201,6 @@ public:
// Returns true if successfully changed to a new gadget, can fail if the target gadget to replace is being used
bool UpdateGadgetType(TSubclassOf<AGadgetBase> NewGadgetClass);
UInventoryComponent* InventoryComponent;
};

View File

@ -19,7 +19,7 @@ UInventoryComponent::UInventoryComponent()
void UInventoryComponent::InitializeComponent()
{
Super::InitializeComponent();
PlayerCharacter = Cast<AEndlessVendettaCharacter>(GetOwner());
PlayerCharacter = GetOwner();
ItemToPickup = nullptr;
}
@ -188,6 +188,26 @@ void UInventoryComponent::UpdateInventorySize_Implementation(const int _Columns,
InventoryItems.SetNum(Columns * Rows);
}
void UInventoryComponent::SetPrimaryWeapon(AActor* const _PrimaryWeapon)
{
PrimaryWeapon = _PrimaryWeapon;
}
AActor* UInventoryComponent::GetPrimaryWeapon() const
{
return PrimaryWeapon;
}
void UInventoryComponent::SetSecondaryWeapon(AActor* const _SecondaryWeapon)
{
SecondaryWeapon = _SecondaryWeapon;
}
AActor* UInventoryComponent::GetSecondaryWeapon() const
{
return SecondaryWeapon;
}
bool UInventoryComponent::IsTileValid(const FInventoryTile InventoryTile) const
{
if (InventoryTile.X >= 0 && InventoryTile.Y >= 0 && InventoryTile.X < Columns && InventoryTile.Y < Columns && InventoryTile.Y <= Rows)

View File

@ -5,7 +5,6 @@
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "InventoryStructs.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "InventoryComponent.generated.h"
@ -64,14 +63,21 @@ public:
void UpdateInventorySize(const int _Columns, const int _Rows);
virtual void UpdateInventorySize_Implementation(const int _Columns, const int _Rows);
void SetPrimaryWeapon(AActor* const _PrimaryWeapon);
AActor* GetPrimaryWeapon() const;
void SetSecondaryWeapon(AActor* const _SecondaryWeapon);
AActor* GetSecondaryWeapon() const;
private:
bool IsTileValid(const FInventoryTile InventoryTile) const;
UPROPERTY()
AEndlessVendettaCharacter* PlayerCharacter;
AActor* PlayerCharacter;
UPROPERTY()
AActor* ItemToPickup;
bool IsDirty = false;
UPROPERTY()
TArray<UBaseItem*> InventoryItems;
AActor* PrimaryWeapon;
AActor* SecondaryWeapon;
};