diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp b/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp index d3e0cb0..007c15a 100644 --- a/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp @@ -26,8 +26,7 @@ void UInventoryComponent::BeginPlay() // Called every frame -void UInventoryComponent::TickComponent(float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) +void UInventoryComponent::TickComponent(float DeltaTime, ELevelTick TickType,FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h index bb4b7d1..f9ab60e 100644 --- a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h @@ -23,7 +23,4 @@ protected: public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - - UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) - int32 GoldBalance = 500; }; diff --git a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp index 62ba79f..1fd0d31 100644 --- a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp +++ b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp @@ -2,3 +2,10 @@ #include "BaseItem.h" + +//constructor +UBaseItem::UBaseItem() +{ + ItemDisplayName = FText::FromString("ItemName"); + ItemUseAction = FText::FromString("UseAction"); +} diff --git a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h index 6f29afe..0c308a5 100644 --- a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h +++ b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h @@ -15,6 +15,8 @@ class THE_TWILIGHT_ABYSS_API UBaseItem : public UObject GENERATED_BODY() public: + + UBaseItem(); //The text that will be displayed for using the item (Equip, Eat) UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") FText ItemUseAction; @@ -46,8 +48,12 @@ public: class UInventoryComponent* StoredItems; //The buy class to purchase the item - virtual void Buy(class UItemPurchaseComponent* PurchaseItem) PURE_VIRTUAL(UBaseItem); + 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); }; diff --git a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp b/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp index 0e68019..b5d5506 100644 --- a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp +++ b/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp @@ -3,12 +3,13 @@ #include "Jelly1.h" -void UJelly1::Buy(UItemPurchaseComponent* PurchaseItem) -{ - Super::Buy(PurchaseItem); -} +#include "the_twilight_abyss/PlayerTemp/TempCharacter.h" + void UJelly1::Use(ATempCharacter* Character) { - Super::Use(Character); + if(Character) + { + Character->Health += 10; + } } diff --git a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h b/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h index 42a56b1..3b6c55f 100644 --- a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h +++ b/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h @@ -15,7 +15,6 @@ class THE_TWILIGHT_ABYSS_API UJelly1 : public UBaseItem GENERATED_BODY() protected: - virtual void Buy(class UItemPurchaseComponent* PurchaseItem) override; - + virtual void Use(class ATempCharacter* Character) override; }; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 2b4919e..6e204db 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -6,6 +6,7 @@ #include "Engine/GameViewportClient.h" #include "Blueprint/UserWidget.h" #include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h" +#include "the_twilight_abyss/BaseItems/Items/BaseItem.h" #include "the_twilight_abyss/MerchantInteraction/Interaction.h" @@ -41,7 +42,7 @@ void ATempCharacter::Tick(float DeltaTime) Super::Tick(DeltaTime); } -// Called to bind functionality to input +// Gives the character the functionality void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); @@ -50,14 +51,15 @@ void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompo PlayerInputComponent->BindAxis(TEXT("Turn Right / Left Mouse"), this, &ATempCharacter::AddControllerYawInput); PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput); PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed); - // custom keybind Interact } +// When the player presses the E key void ATempCharacter::KeyPressed() { LineTraceLogic(); } +// Line trace logic void ATempCharacter::LineTraceLogic() { float GlobalTrace = TraceDistance; @@ -84,3 +86,12 @@ void ATempCharacter::LineTraceLogic() } } } + +void ATempCharacter::UseItem(class UBaseItem* Item) +{ + if(Item) + { + Item->Use(this); + Item->OnUse(this); //Blueprint Version + } +} diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index fd5924c..11da9ba 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -38,4 +38,8 @@ public: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Health") float Health; + + //Using the item in the inventory + UFUNCTION(BlueprintCallable, Category= "Items") + void UseItem(class UBaseItem* Item); };