Updated BaseItem,Jelly1,Inventory Component,Temp

Updated all the scripts adding more functionality, Currently just added a very basic Use item and it giving the character health.
This commit is contained in:
MH261677 2022-11-14 16:52:57 +00:00
parent 8f0a770bfb
commit 83d4d16588
8 changed files with 39 additions and 15 deletions

View File

@ -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);

View File

@ -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;
};

View File

@ -2,3 +2,10 @@
#include "BaseItem.h"
//constructor
UBaseItem::UBaseItem()
{
ItemDisplayName = FText::FromString("ItemName");
ItemUseAction = FText::FromString("UseAction");
}

View File

@ -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);
};

View File

@ -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;
}
}

View File

@ -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;
};

View File

@ -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
}
}

View File

@ -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);
};