From 811856b219221034ad92c0fbf73b00e5622957e5 Mon Sep 17 00:00:00 2001 From: MH261677 Date: Fri, 18 Nov 2022 14:53:22 +0000 Subject: [PATCH] Updated InventoryComponent & TempCharacter Made it so the buy system is universal meaning any devs will not have to keep adding more if statements just to set the items price. It can all be done in editor now and it all handles itself in the code. --- .../the_twilight_abyss/BaseItems/InventoryComponent.cpp | 2 +- Source/the_twilight_abyss/BaseItems/InventoryComponent.h | 2 +- Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp b/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp index a5a1a9f..40d8473 100644 --- a/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp @@ -60,7 +60,7 @@ bool UInventoryComponent::Remove(class UBaseItem* BaseItem) return false; } -UBaseItem* UInventoryComponent::GetItem(int32 Index) +UBaseItem* UInventoryComponent::GetItem(int Index) { return Items[Index]; } diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h index bcfead2..af87438 100644 --- a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h @@ -40,5 +40,5 @@ public: TArray Items; // The items currently in the inventory UFUNCTION(BlueprintCallable, Category= "Inventory") - class UBaseItem* GetItem(int32 Index); + class UBaseItem* GetItem(int Index); }; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index dc32492..9a0637b 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -41,6 +41,8 @@ void ATempCharacter::RightMoveInput(float Axis) void ATempCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); + + UE_LOG(LogTemp, Warning, TEXT("Gold: %d"),GoldBalance); } // Gives the character the functionality @@ -81,14 +83,11 @@ void ATempCharacter::LineTraceLogic() } if(OutHit.GetActor()->FindComponentByClass()) { - if(GoldBalance >= 100) + if(GoldBalance >= OutHit.GetActor()->FindComponentByClass()->GetItem(0)->ItemCostPrice) { - GoldBalance -= 100; + GoldBalance -= OutHit.GetActor()->FindComponentByClass()->GetItem(0)->ItemCostPrice; Inventory->AddItem(OutHit.GetActor()->FindComponentByClass()->GetItem(0)); - //Inventory->AddItem(Cast(OutHit.GetActor())); - //Inventory->AddItem(OutHit.GetActor()->Get("HealingJelly")); UE_LOG(LogTemp, Display, TEXT("Item Purchased")); - } if(GoldBalance <= 0) {