diff --git a/Source/vampires/WeaponInventoryComponent.cpp b/Source/vampires/WeaponInventoryComponent.cpp new file mode 100644 index 0000000..99411f7 --- /dev/null +++ b/Source/vampires/WeaponInventoryComponent.cpp @@ -0,0 +1,46 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "WeaponInventoryComponent.h" + +#include "Kismet/GameplayStatics.h" + +// Sets default values for this component's properties +UWeaponInventoryComponent::UWeaponInventoryComponent() +{ + // 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 = false; + + // ... +} + + +// Called when the game starts +void UWeaponInventoryComponent::BeginPlay() +{ + Super::BeginPlay(); + + // ... + +} + +void UWeaponInventoryComponent::InitializeInventory() +{ + inventory.Empty(); + + for (TSubclassOf weapon : initialInventory) + { + AddWeaponToInventory(weapon); + } +} + +void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf Weapon) +{ + AWeapon* weapon = GetWorld()->SpawnActor(Weapon); + weapon->SetActorTransform(GetOwner()->GetTransform()); + weapon->SetOwner(GetOwner()); + weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepRelativeTransform); + inventory.Add(weapon); +} + diff --git a/Source/vampires/WeaponInventoryComponent.h b/Source/vampires/WeaponInventoryComponent.h new file mode 100644 index 0000000..8ce8c87 --- /dev/null +++ b/Source/vampires/WeaponInventoryComponent.h @@ -0,0 +1,41 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Weapon.h" +#include "Components/ActorComponent.h" +#include "WeaponInventoryComponent.generated.h" + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class VAMPIRES_API UWeaponInventoryComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + + UPROPERTY() + TArray> initialInventory; + +private: + UPROPERTY() + TArray inventory; + +public: + // Sets default values for this component's properties + UWeaponInventoryComponent(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + + +public: + + UFUNCTION() + void InitializeInventory(); + + UFUNCTION() + void AddWeaponToInventory(TSubclassOf Weapon); +};