diff --git a/Content/Blueprints/Items/BP_HealingSyringe.uasset b/Content/Blueprints/Items/BP_HealingSyringe.uasset new file mode 100644 index 0000000..95e16d9 --- /dev/null +++ b/Content/Blueprints/Items/BP_HealingSyringe.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e387511b72d482c0cef5dcaf48822ceba438b4bd0cc13ff7410220ca992f15c +size 6030 diff --git a/Content/Blueprints/Items/BP_Jelly1.uasset b/Content/Blueprints/Items/BP_Jelly1.uasset new file mode 100644 index 0000000..e947689 --- /dev/null +++ b/Content/Blueprints/Items/BP_Jelly1.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d8d52b9430b52830e8488a07bdc388bb5a602828a0b898e727c18aeb583fffb +size 5894 diff --git a/Content/Blueprints/Items/BP_Jelly2.uasset b/Content/Blueprints/Items/BP_Jelly2.uasset new file mode 100644 index 0000000..bd7ba3a --- /dev/null +++ b/Content/Blueprints/Items/BP_Jelly2.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:302db81a27f3921406ca175911dd01315a52040b80af2d5515e150f169383463 +size 5894 diff --git a/Content/Blueprints/Items/BP_Jelly3.uasset b/Content/Blueprints/Items/BP_Jelly3.uasset new file mode 100644 index 0000000..9941cf8 --- /dev/null +++ b/Content/Blueprints/Items/BP_Jelly3.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b443f673bb208fa1d7dd5a10319aaf03d7173f4232adda4d9e692895c6c6ade +size 5894 diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp b/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp index 007c15a..30d29bd 100644 --- a/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp @@ -2,6 +2,9 @@ #include "InventoryComponent.h" +#include "Items/BaseItem.h" + + // Sets default values for this component's properties @@ -11,7 +14,7 @@ UInventoryComponent::UInventoryComponent() // off to improve performance if you don't need them. PrimaryComponentTick.bCanEverTick = true; - // ... + MaxItemSlots = 10; } @@ -20,16 +23,39 @@ void UInventoryComponent::BeginPlay() { Super::BeginPlay(); - // ... - + for(auto & BaseItem : DefaultItems) + { + AddItem(BaseItem); + } } - -// Called every frame -void UInventoryComponent::TickComponent(float DeltaTime, ELevelTick TickType,FActorComponentTickFunction* ThisTickFunction) +bool UInventoryComponent::AddItem(class UBaseItem* BaseItem) { - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + //if the items is over the maxinventoryslots then it wont add the item + if (Items.Num() >= MaxItemSlots || !BaseItem) + { + return false; + } + BaseItem->StoredItems = this; + BaseItem->World = GetWorld(); + Items.Add(BaseItem); + + //Update UI + OnInventoryUpdated.Broadcast(); - // ... + return true; +} + +bool UInventoryComponent::Remove(UBaseItem* BaseItem) +{ + if(BaseItem) + { + BaseItem->StoredItems = nullptr; + BaseItem->World = nullptr; + Items.RemoveSingle(BaseItem); + OnInventoryUpdated.Broadcast(); // Updates UI + return true; + } + return false; } diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h index f9ab60e..d2fbb5a 100644 --- a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h @@ -6,6 +6,8 @@ #include "Components/ActorComponent.h" #include "InventoryComponent.generated.h" +//OUR DELEGATE IS CALLED FONINVENTORYUPDATED +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnInventoryUpdated); UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class THE_TWILIGHT_ABYSS_API UInventoryComponent : public UActorComponent @@ -21,6 +23,19 @@ protected: virtual void BeginPlay() override; public: - // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + bool AddItem(class UBaseItem* BaseItem); //adds the item to the player + + bool Remove(class UBaseItem* BaseItem); //removes the item from the player + + UPROPERTY(EditDefaultsOnly, Instanced) + TArray DefaultItems; //Items you start the game with IF YOU WANT YOU CAN JUST NOT USE THIS + + UPROPERTY(EditDefaultsOnly, Category= "Inventory") + int32 MaxItemSlots; + + UPROPERTY(BlueprintAssignable, Category= "Inventory") + FOnInventoryUpdated OnInventoryUpdated; //This is our delegate + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Items") + TArray Items; // The items currently in the inventory }; diff --git a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h index 0c308a5..639bc1b 100644 --- a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h +++ b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h @@ -6,6 +6,7 @@ #include "UObject/Object.h" #include "BaseItem.generated.h" + /** * */ @@ -15,45 +16,50 @@ class THE_TWILIGHT_ABYSS_API UBaseItem : public UObject GENERATED_BODY() public: - UBaseItem(); + + virtual class UWorld* GetWorld() const { return World; }; + + UPROPERTY(Transient) + class UWorld* World; + //The text that will be displayed for using the item (Equip, Eat) - UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") FText ItemUseAction; //The actual mesh of the item - UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") class UStaticMesh* ItemMesh; //The picture of the item icon - UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") class UTexture2D* ItemIcon; //The name of the item - UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") FText ItemDisplayName; //The description of the item - UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") FText ItemDescription; //The cost of the item - UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") int32 ItemCostPrice; //ADD A HEALING ITEM VALUE? - + //reference to the UInventoryComponent script UPROPERTY() class UInventoryComponent* StoredItems; //The buy class to purchase the item - virtual void Buy(class UItemPurchaseComponent* PurchaseItem) PURE_VIRTUAL(UBaseItem); // WILL SET THIS UP LATER + virtual void Buy(class UItemPurchaseComponent* PurchaseItem) PURE_VIRTUAL(UBaseItem); // WILL SET THIS UP LATER //The use Item class to use the item in the player Inventory virtual void Use(class ATempCharacter* Character) PURE_VIRTUAL(UBaseItem); //This is the same as the use item class but its in BP instead UFUNCTION(BlueprintImplementableEvent) - void OnUse (class ATempCharacter* Character); + void OnUse(class ATempCharacter* Character); }; diff --git a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp b/Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp similarity index 71% rename from Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp rename to Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp index b5d5506..63956df 100644 --- a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp +++ b/Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp @@ -1,12 +1,12 @@ // Fill out your copyright notice in the Description page of Project Settings. -#include "Jelly1.h" +#include "EatableItems.h" #include "the_twilight_abyss/PlayerTemp/TempCharacter.h" -void UJelly1::Use(ATempCharacter* Character) +void UEatableItems::Use(ATempCharacter* Character) { if(Character) { diff --git a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h b/Source/the_twilight_abyss/BaseItems/Items/EatableItems.h similarity index 72% rename from Source/the_twilight_abyss/BaseItems/Items/Jelly1.h rename to Source/the_twilight_abyss/BaseItems/Items/EatableItems.h index 3b6c55f..127041f 100644 --- a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h +++ b/Source/the_twilight_abyss/BaseItems/Items/EatableItems.h @@ -4,13 +4,13 @@ #include "CoreMinimal.h" #include "BaseItem.h" -#include "Jelly1.generated.h" +#include "EatableItems.generated.h" /** * */ UCLASS() -class THE_TWILIGHT_ABYSS_API UJelly1 : public UBaseItem +class THE_TWILIGHT_ABYSS_API UEatableItems : public UBaseItem { GENERATED_BODY() diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 6e204db..092c3e6 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -1,11 +1,9 @@ // Fill out your copyright notice in the Description page of Project Settings. #include "TempCharacter.h" -#include "UObject/SoftObjectPath.h" -#include "Dialogs/Dialogs.h" -#include "Engine/GameViewportClient.h" #include "Blueprint/UserWidget.h" #include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h" +#include "the_twilight_abyss/BaseItems/InventoryComponent.h" #include "the_twilight_abyss/BaseItems/Items/BaseItem.h" #include "the_twilight_abyss/MerchantInteraction/Interaction.h" @@ -15,6 +13,8 @@ ATempCharacter::ATempCharacter() { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; + Inventory = CreateDefaultSubobject("Inventory"); + Inventory->MaxItemSlots = 10; } // Called when the game starts or when spawned