Merge branch 'merchant-system' into Turn-Base-System-V2

# Conflicts:
#	Config/DefaultEngine.ini
#	Content/Blueprints/Combat_UI/CombatCharacter.uasset
#	Content/Merchant/BP_MerchantGameMode.uasset
This commit is contained in:
Philip W 2022-11-29 15:50:55 +00:00
commit af1813fd9a
33 changed files with 142 additions and 85 deletions

BIN
Content/Blueprints/BP_CrossHair.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
Content/Blueprints/BP_Interaction.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
Content/Blueprints/Display_UI/BP_CrossHair.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/Display_UI/WBP_Health.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/Inventory_UI/WBP_ItemDisplay.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/Inventory_UI/WBP_PlayerInventory.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/Blueprints/Items/BP_BuffPlacedItem.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/Blueprints/Merchant/BP_Interaction.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/Merchant/BP_MerchantGameMode.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/Merchant/Merchant_Blueprint.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/Merchant/Merchant_UI/BP_OPENDIAL.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/Player/BP_MyTempCharacter.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/WBP_ItemDisplay.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
Content/Blueprints/WBP_Shop.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Levels/MerchantPrototype.umap (Stored with Git LFS)

Binary file not shown.

BIN
Content/Merchant/BP_OPENDIAL.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Merchant_Blueprint.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -22,39 +22,60 @@ void UInventoryComponent::BeginPlay()
{
Super::BeginPlay();
//activates the AddItem function for every DefaultItem that inherits BaseItem
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)
{
UE_LOG(LogTemp, Display, TEXT("THERE ARE MORE ITEMS THAN THE INVENTORY SLOTS"));
return false;
}
BaseItem->StoredItems = this;
BaseItem->World = GetWorld();
Items.Add(BaseItem);
//Update UI
BaseItem->SubItemID++;
UE_LOG(LogTemp, Display, TEXT("ITEM HAS BEEN ADDED"));
//log the itemid
UE_LOG(LogTemp, Display, TEXT("ITEM ID: %d"), BaseItem->ItemID);
UE_LOG(LogTemp, Display, TEXT("SUBITEM ID: %d"), BaseItem->SubItemID);
//Refreshes the inventory
OnInventoryUpdated.Broadcast();
return true;
}
bool UInventoryComponent::Remove(UBaseItem* BaseItem)
// remove only gets called once on the same item
bool UInventoryComponent::Remove(class UBaseItem* BaseItem)
{
if(BaseItem)
{
UE_LOG(LogTemp, Display, TEXT("ItEM HAS BEEN REMOVED"));
BaseItem->StoredItems = nullptr;
BaseItem->World = nullptr;
Items.RemoveSingle(BaseItem);
if(BaseItem->SubItemID < Items.Num())
{
Items.RemoveSingle(BaseItem);
BaseItem->SubItemID --;
UE_LOG(LogTemp, Display, TEXT("ItemRemoved"));
UE_LOG(LogTemp, Display, TEXT("SUBITEM ID: %d"), BaseItem->SubItemID);
}
//Items.RemoveSingle(BaseItem);
OnInventoryUpdated.Broadcast(); // Updates UI
return true;
}
return false;
}
UBaseItem* UInventoryComponent::GetItem(int Index)
{
return Items[Index];
}

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Items/EatableItems.h"
#include "InventoryComponent.generated.h"
//OUR DELEGATE IS CALLED FONINVENTORYUPDATED
@ -33,9 +34,16 @@ public:
UPROPERTY(EditDefaultsOnly, Category= "Inventory")
int32 MaxItemSlots;
UPROPERTY(EditDefaultsOnly, Category = "Inventory")
int MaxItemStack;
UPROPERTY(BlueprintAssignable, Category= "Inventory")
FOnInventoryUpdated OnInventoryUpdated; //This is our delegate
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Items")
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category= "Items")
TArray<class UBaseItem*> Items; // The items currently in the inventory
UFUNCTION(BlueprintCallable, Category= "Inventory")
class UBaseItem* GetItem(int Index);
};

View File

@ -46,6 +46,18 @@ public:
//The cost of the item
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
int ItemCostPrice;
UPROPERTY(EditAnywhere, Category = "Item")
bool isHealingItem;
UPROPERTY(EditAnywhere, Category = "Item")
bool isDamageBuffItem;
UPROPERTY(EditAnywhere, Category = "Item")
int ItemID;
UPROPERTY(EditAnywhere, Category = "Item")
int SubItemID;
//reference to the UInventoryComponent script
UPROPERTY()
@ -60,7 +72,4 @@ public:
//This is the same as the use item class but its in BP instead
UFUNCTION(BlueprintImplementableEvent)
void OnUse(class ATempCharacter* Character);
UFUNCTION(BlueprintImplementableEvent)
void OnBuy(class ATempCharacter* PurchaseItem);
};

View File

@ -9,33 +9,34 @@
UEatableItems::UEatableItems()
{
ItemID;
SubItemID;
}
void UEatableItems::Use(ATempCharacter* Character)
{
if(Character)
{
Character->Health += 10;
if(isHealingItem == true)
{
Character->Health += 10;
UE_LOG(LogTemp, Display, TEXT("Healed"));
}
if(isDamageBuffItem == true)
{
// need to add the damage buff functionality here
UE_LOG(LogTemp, Display, TEXT("Damage Buffed"));
}
if(StoredItems)
{
StoredItems->Remove(this);
}
}
/*
when player uses the item syrengine to debuff enemies
detect what enemie actors the player is fighting with
lower their damage by a value.
*/
}
void UEatableItems::Buy(ATempCharacter* PurchaseItem)
{
if(PurchaseItem)
{
if(PurchaseItem->GoldBalance <= 0)
{
UE_LOG(LogTemp, Display, TEXT("Not Enough Gold"));
}
else
{
PurchaseItem->GoldBalance -= ItemCostPrice;
}
}
}

View File

@ -19,5 +19,4 @@ class THE_TWILIGHT_ABYSS_API UEatableItems : public UBaseItem
protected:
virtual void Use(class ATempCharacter* Character) override;
virtual void Buy(ATempCharacter* PurchaseItem) override;
};

View File

@ -30,7 +30,13 @@ void AInteraction::Tick(float DeltaTime)
void AInteraction::OnInteract()
{
UUserWidget* spawnedWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
spawnedWidget->AddToViewport(0);
CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
CurrentWidget->AddToViewport(0);
FTimerHandle WidgetTimer;
GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, WaitTimer, false);
}
void AInteraction::RemoveWidget()
{
CurrentWidget->RemoveFromViewport();
}

View File

@ -27,5 +27,10 @@ public:
TSubclassOf<UUserWidget> Widget;
virtual void OnInteract();
virtual void RemoveWidget();
UPROPERTY()
UUserWidget* CurrentWidget;
UPROPERTY(EditAnywhere)
float WaitTimer = 8.0f;
};

View File

@ -1,6 +1,8 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "TempCharacter.h"
#include "IDetailTreeNode.h"
#include "Blueprint/UserWidget.h"
#include "the_twilight_abyss/BaseItems/InventoryComponent.h"
#include "the_twilight_abyss/BaseItems/Items/BaseItem.h"
@ -14,6 +16,8 @@ ATempCharacter::ATempCharacter()
PrimaryActorTick.bCanEverTick = true;
Inventory = CreateDefaultSubobject<UInventoryComponent>("Inventory");
Inventory->MaxItemSlots = 10;
GoldBalance = GoldBalance;
Health = Health;
}
// Called when the game starts or when spawned
@ -70,21 +74,22 @@ void ATempCharacter::LineTraceLogic()
TraceParams.AddIgnoredActor(this);
bool bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
if (bHit)
{
//we store the GetItem function from InventoryComponent into ItemArray variable
auto ItemArray = OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0);
if(OutHit.GetActor() == nullptr)
{
return;
}
if(OutHit.GetActor()->ActorHasTag("HealingJelly"))
if(OutHit.GetActor()->FindComponentByClass<UInventoryComponent>())
{
if(GoldBalance >= 100)
if(GoldBalance >= ItemArray->ItemCostPrice)
{
GoldBalance -= 100;
GoldBalance -= ItemArray->ItemCostPrice;
Inventory->AddItem(ItemArray);
UE_LOG(LogTemp, Display, TEXT("Item Purchased"));
// UInventoryComponent* tempInventory = GetOwner()->FindComponentByClass<UInventoryComponent>();
// tempInventory->AddItem(ItemToBuy);
}
if(GoldBalance <= 0)
{
@ -109,12 +114,3 @@ void ATempCharacter::UseItem(class UBaseItem* Item)
}
}
void ATempCharacter::BuyItem(UBaseItem* BuyItem)
{
if(BuyItem)
{
BuyItem->Buy(this);
BuyItem->OnBuy(this);
}
}

View File

@ -41,19 +41,16 @@ public:
void LineTraceLogic();
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Health")
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health")
float Health;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Gold")
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Gold")
int GoldBalance;
UPROPERTY(VisibleDefaultsOnly, Category = "LineTrace")
bool bHit;
//Using the item in the inventory
UFUNCTION(BlueprintCallable, Category= "Items")
void UseItem(class UBaseItem* Item); // Overriding the BaseItem Class
UFUNCTION(BlueprintCallable, Category= "Items")
void BuyItem(class UBaseItem* BuyItem);
// UPROPERTY(EditAnywhere, Category= "Items")
// UBaseItem ItemToBuy;
};