Merge branch 'merchant-system' into Turn-Base-System
# Conflicts: # Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp
This commit is contained in:
commit
d8dcef64e8
BIN
Content/Blueprints/BP_Interaction.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/BP_Interaction.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Blueprints/BP_MyTempCharacter.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/BP_MyTempCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Blueprints/Items/BP_HealingJelly.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Blueprints/Items/BP_HealingJelly.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Blueprints/WBP_ItemDisplay.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Blueprints/WBP_ItemDisplay.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Blueprints/WBP_PlayerInventory.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Blueprints/WBP_PlayerInventory.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Images/testimage.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Images/testimage.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Levels/MerchantPrototype.umap
(Stored with Git LFS)
BIN
Content/Levels/MerchantPrototype.umap
(Stored with Git LFS)
Binary file not shown.
62
Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp
Normal file
62
Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "InventoryComponent.h"
|
||||
#include "Items/BaseItem.h"
|
||||
|
||||
|
||||
|
||||
|
||||
// Sets default values for this component's properties
|
||||
UInventoryComponent::UInventoryComponent()
|
||||
{
|
||||
// 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 = true;
|
||||
|
||||
MaxItemSlots = 10;
|
||||
}
|
||||
|
||||
|
||||
// Called when the game starts
|
||||
void UInventoryComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
for(auto & BaseItem : DefaultItems)
|
||||
{
|
||||
AddItem(BaseItem);
|
||||
}
|
||||
}
|
||||
|
||||
bool UInventoryComponent::AddItem(class UBaseItem* BaseItem)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
|
41
Source/the_twilight_abyss/BaseItems/InventoryComponent.h
Normal file
41
Source/the_twilight_abyss/BaseItems/InventoryComponent.h
Normal file
@ -0,0 +1,41 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#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
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
UInventoryComponent();
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
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<class UBaseItem*> 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<class UBaseItem*> Items; // The items currently in the inventory
|
||||
};
|
16
Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp
Normal file
16
Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "BaseItem.h"
|
||||
|
||||
//constructor
|
||||
UBaseItem::UBaseItem()
|
||||
{
|
||||
ItemDisplayName = FText::FromString("ItemName");
|
||||
ItemUseAction = FText::FromString("UseAction");
|
||||
}
|
||||
|
||||
void UBaseItem::Use(ATempCharacter* Character)
|
||||
{
|
||||
|
||||
}
|
65
Source/the_twilight_abyss/BaseItems/Items/BaseItem.h
Normal file
65
Source/the_twilight_abyss/BaseItems/Items/BaseItem.h
Normal file
@ -0,0 +1,65 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "BaseItem.generated.h"
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(Abstract, BlueprintType, Blueprintable, EditInlineNew, DefaultToInstanced)
|
||||
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")
|
||||
FText ItemUseAction;
|
||||
|
||||
//The actual mesh of the item
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
|
||||
class UStaticMesh* ItemMesh;
|
||||
|
||||
//The picture of the item icon
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
|
||||
class UTexture2D* ItemIcon;
|
||||
|
||||
//The name of the item
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
|
||||
FText ItemDisplayName;
|
||||
|
||||
//The description of the item
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
|
||||
FText ItemDescription;
|
||||
|
||||
//The cost of the 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
|
||||
|
||||
//The use Item class to use the item in the player Inventory
|
||||
virtual void Use(class ATempCharacter* Character);
|
||||
|
||||
//This is the same as the use item class but its in BP instead
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void OnUse(class ATempCharacter* Character);
|
||||
};
|
15
Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp
Normal file
15
Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "EatableItems.h"
|
||||
|
||||
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
|
||||
|
||||
|
||||
void UEatableItems::Use(ATempCharacter* Character)
|
||||
{
|
||||
if(Character)
|
||||
{
|
||||
Character->Health += 10;
|
||||
}
|
||||
}
|
20
Source/the_twilight_abyss/BaseItems/Items/EatableItems.h
Normal file
20
Source/the_twilight_abyss/BaseItems/Items/EatableItems.h
Normal file
@ -0,0 +1,20 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BaseItem.h"
|
||||
#include "EatableItems.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class THE_TWILIGHT_ABYSS_API UEatableItems : public UBaseItem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Use(class ATempCharacter* Character) override;
|
||||
};
|
@ -12,7 +12,6 @@ AInteraction::AInteraction()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
WidgetBase = CreateDefaultSubobject<UWidgetComponent>(TEXT("Widget Base Class"));
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
@ -31,7 +30,7 @@ void AInteraction::Tick(float DeltaTime)
|
||||
|
||||
void AInteraction::OnInteract()
|
||||
{
|
||||
auto spawnedWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
|
||||
UUserWidget* spawnedWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
|
||||
spawnedWidget->AddToViewport(0);
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,10 @@ protected:
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
class UWidgetComponent* WidgetBase;
|
||||
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
TSubclassOf<UUserWidget> Widget;
|
||||
|
||||
virtual void OnInteract();
|
||||
};
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
||||
@ -14,13 +12,15 @@ 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<UInventoryComponent>("Inventory");
|
||||
Inventory->MaxItemSlots = 10;
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ATempCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
Health = 100;
|
||||
}
|
||||
|
||||
//Binds the input we made in the setup player component to the forward vector
|
||||
@ -28,7 +28,6 @@ void ATempCharacter::ForwardInput(float Axis)
|
||||
{
|
||||
AddMovementInput(GetActorForwardVector() * Axis);
|
||||
}
|
||||
|
||||
//Binds the input we made in the setup player component to the right vector
|
||||
void ATempCharacter::RightMoveInput(float Axis)
|
||||
{
|
||||
@ -42,7 +41,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);
|
||||
@ -51,14 +50,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;
|
||||
@ -79,10 +79,18 @@ void ATempCharacter::LineTraceLogic()
|
||||
}
|
||||
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
|
||||
{
|
||||
|
||||
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
|
||||
MyInteractable->OnInteract();
|
||||
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ATempCharacter::UseItem(class UBaseItem* Item)
|
||||
{
|
||||
if(Item)
|
||||
{
|
||||
Item->Use(this);
|
||||
Item->OnUse(this); //Blueprint Version
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,10 @@ class THE_TWILIGHT_ABYSS_API ATempCharacter : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
//Player inventory
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true"))
|
||||
class UInventoryComponent* Inventory; //Using the InventoryComponent class
|
||||
|
||||
public:
|
||||
// Sets default values for this character's properties
|
||||
ATempCharacter();
|
||||
@ -35,4 +39,11 @@ public:
|
||||
float TraceDistance = 200;
|
||||
|
||||
void LineTraceLogic();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Health")
|
||||
float Health;
|
||||
|
||||
//Using the item in the inventory
|
||||
UFUNCTION(BlueprintCallable, Category= "Items")
|
||||
void UseItem(class UBaseItem* Item); // Overriding the BaseItem Class
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user