From 7699a088ae5d7805781aa7ea35d288013977147b Mon Sep 17 00:00:00 2001 From: MH261677 Date: Mon, 14 Nov 2022 15:53:50 +0000 Subject: [PATCH] Added Jelly1 and ItemPurchaseComponent class Jelly1 is the test item i am creating and i also added a health variable for the temp character --- .../BaseItems/InventoryComponent.h | 6 +- .../BaseItems/Items/BaseItem.h | 12 +++ .../BaseItems/Items/Jelly1.cpp | 14 +++ .../BaseItems/Items/Jelly1.h | 21 +++++ .../ItemPurchaseComponent.cpp | 35 ++++++++ .../ItemPurchaseComponent.h | 26 ++++++ .../PlayerTemp/TempCharacter.cpp | 3 +- .../PlayerTemp/TempCharacter.cpp~ | 87 ------------------- .../PlayerTemp/TempCharacter.h | 3 + 9 files changed, 116 insertions(+), 91 deletions(-) create mode 100644 Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp create mode 100644 Source/the_twilight_abyss/BaseItems/Items/Jelly1.h create mode 100644 Source/the_twilight_abyss/MerchantInteraction/ItemPurchaseComponent.cpp create mode 100644 Source/the_twilight_abyss/MerchantInteraction/ItemPurchaseComponent.h delete mode 100644 Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp~ diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h index e4fbe77..bb4b7d1 100644 --- a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h @@ -22,6 +22,8 @@ protected: public: // Called every frame - virtual void TickComponent(float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) override; + 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.h b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h index 74a4e45..6f29afe 100644 --- a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h +++ b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h @@ -35,7 +35,19 @@ public: 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); + + //The use Item class to use the item in the player Inventory + virtual void Use(class ATempCharacter* Character) PURE_VIRTUAL(UBaseItem); }; diff --git a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp b/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp new file mode 100644 index 0000000..0e68019 --- /dev/null +++ b/Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp @@ -0,0 +1,14 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Jelly1.h" + +void UJelly1::Buy(UItemPurchaseComponent* PurchaseItem) +{ + Super::Buy(PurchaseItem); +} + +void UJelly1::Use(ATempCharacter* Character) +{ + Super::Use(Character); +} diff --git a/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h b/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h new file mode 100644 index 0000000..42a56b1 --- /dev/null +++ b/Source/the_twilight_abyss/BaseItems/Items/Jelly1.h @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BaseItem.h" +#include "Jelly1.generated.h" + +/** + * + */ +UCLASS() +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/MerchantInteraction/ItemPurchaseComponent.cpp b/Source/the_twilight_abyss/MerchantInteraction/ItemPurchaseComponent.cpp new file mode 100644 index 0000000..0f06d98 --- /dev/null +++ b/Source/the_twilight_abyss/MerchantInteraction/ItemPurchaseComponent.cpp @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ItemPurchaseComponent.h" + + +// Sets default values for this component's properties +UItemPurchaseComponent::UItemPurchaseComponent() +{ + // 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; + + // ... +} + + +// Called when the game starts +void UItemPurchaseComponent::BeginPlay() +{ + Super::BeginPlay(); + + // ... + +} + + +// Called every frame +void UItemPurchaseComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + diff --git a/Source/the_twilight_abyss/MerchantInteraction/ItemPurchaseComponent.h b/Source/the_twilight_abyss/MerchantInteraction/ItemPurchaseComponent.h new file mode 100644 index 0000000..9b7bb90 --- /dev/null +++ b/Source/the_twilight_abyss/MerchantInteraction/ItemPurchaseComponent.h @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "ItemPurchaseComponent.generated.h" + + +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class THE_TWILIGHT_ABYSS_API UItemPurchaseComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UItemPurchaseComponent(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; +}; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 83bf10b..2b4919e 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -20,7 +20,7 @@ ATempCharacter::ATempCharacter() 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) { diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp~ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp~ deleted file mode 100644 index 83bf10b..0000000 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp~ +++ /dev/null @@ -1,87 +0,0 @@ -// 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/MerchantInteraction/Interaction.h" - - -// CONSTRUCTOR -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; -} - -// Called when the game starts or when spawned -void ATempCharacter::BeginPlay() -{ - Super::BeginPlay(); - -} - -//Binds the input we made in the setup player component to the forward vector -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) -{ - AddMovementInput(GetActorRightVector() * Axis); -} - - -// Called every frame -void ATempCharacter::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); -} - -// Called to bind functionality to input -void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) -{ - Super::SetupPlayerInputComponent(PlayerInputComponent); - PlayerInputComponent->BindAxis(TEXT("Move Forward / Backward"), this, &ATempCharacter::ForwardInput); - PlayerInputComponent->BindAxis(TEXT("Move Right / Left"), this, &ATempCharacter::RightMoveInput); - 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 -} - -void ATempCharacter::KeyPressed() -{ - LineTraceLogic(); -} - -void ATempCharacter::LineTraceLogic() -{ - float GlobalTrace = TraceDistance; - FHitResult OutHit; - FVector Start = GetActorLocation(); - FVector End = Start + GlobalTrace * GetActorForwardVector(); - - FCollisionQueryParams TraceParams; - - TraceParams.AddIgnoredActor(this); - - bool bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams); - if (bHit) - { - if(OutHit.GetActor() == nullptr) - { - return; - } - if (AInteraction* MyInteractable = Cast(OutHit.GetActor())) - { - DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); - MyInteractable->OnInteract(); - UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); - } - } -} diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 3f170b4..fd5924c 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -35,4 +35,7 @@ public: float TraceDistance = 200; void LineTraceLogic(); + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Health") + float Health; };