Implemented Base Gadget Tutorial Class

This commit is contained in:
Rafal Swierczek 2023-11-01 21:52:47 +00:00
parent d705e61070
commit 8694b8746b
7 changed files with 91 additions and 9 deletions

View File

@ -421,15 +421,16 @@ bool AEndlessVendettaCharacter::GetHasRifle()
return bHasRifle; return bHasRifle;
} }
void AEndlessVendettaCharacter::UpdateGadgetType(TSubclassOf<AGadgetBase> NewGadgetClass) bool AEndlessVendettaCharacter::UpdateGadgetType(TSubclassOf<AGadgetBase> NewGadgetClass)
{ {
if (NewGadgetClass.GetDefaultObject()->IsA(AReconGadget::StaticClass()) && GadgetManager->CantReplaceReconGadget()) return; if (NewGadgetClass.GetDefaultObject()->IsA(AReconGadget::StaticClass()) && GadgetManager->CantReplaceReconGadget()) return false;
if (NewGadgetClass.GetDefaultObject()->IsA(ACombatGadget::StaticClass()) && GadgetManager->CantReplaceCombatGadget()) return; if (NewGadgetClass.GetDefaultObject()->IsA(ACombatGadget::StaticClass()) && GadgetManager->CantReplaceCombatGadget()) return false;
for (UActorComponent* PlayersCamera : GetComponentsByTag(UCameraComponent::StaticClass(), FName("PlayersCamera"))) for (UActorComponent* PlayersCamera : GetComponentsByTag(UCameraComponent::StaticClass(), FName("PlayersCamera")))
{ {
GadgetManager->SpawnGadget(NewGadgetClass, Cast<UCameraComponent>(PlayersCamera)); GadgetManager->SpawnGadget(NewGadgetClass, Cast<UCameraComponent>(PlayersCamera));
break; break;
} }
return true;
} }

View File

@ -181,5 +181,6 @@ public:
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void CheckpointCompletedUI(); void CheckpointCompletedUI();
void UpdateGadgetType(TSubclassOf<AGadgetBase> NewGadgetClass); // Returns true if successfully changed to a new gadget, can fail if the target gadget to replace is being used
bool UpdateGadgetType(TSubclassOf<AGadgetBase> NewGadgetClass);
}; };

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "EnhancedInputSubsystemInterface.h" #include "EnhancedInputSubsystemInterface.h"
#include "GadgetTutorial/BaseGadgetTutorial.h"
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "GadgetBase.generated.h" #include "GadgetBase.generated.h"
@ -119,6 +120,10 @@ public:
{ {
return GadgetInUse; return GadgetInUse;
} }
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
TSubclassOf<ABaseGadgetTutorial> GadgetTutorialClass;
// Sets default values for this actor's properties // Sets default values for this actor's properties
AGadgetBase(); AGadgetBase();

View File

@ -0,0 +1,32 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "BaseGadgetTutorial.h"
// Sets default values
ABaseGadgetTutorial::ABaseGadgetTutorial()
{
// 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;
}
// Called when the game starts or when spawned
void ABaseGadgetTutorial::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABaseGadgetTutorial::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ABaseGadgetTutorial::DestroyTutorial()
{
UE_LOG(LogTemp, Warning, TEXT("Destroyed Tutorial"));
Destroy();
}

View File

@ -0,0 +1,35 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "BaseGadgetTutorial.generated.h"
UCLASS()
class ENDLESSVENDETTA_API ABaseGadgetTutorial : public AActor
{
GENERATED_BODY()
UPROPERTY(EditDefaultsOnly, Category = "Gadget Tutorial")
FTransform SpawnTransform;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Sets default values for this actor's properties
ABaseGadgetTutorial();
// Called every frame
virtual void Tick(float DeltaTime) override;
virtual void DestroyTutorial();
FTransform GetSpawnTransform()
{
return SpawnTransform;
}
};

View File

@ -86,12 +86,17 @@ void AGadgetTutorialStation::PreviousGadget()
void AGadgetTutorialStation::SelectGadget() void AGadgetTutorialStation::SelectGadget()
{ {
// Give Player the gadget // Eventually expand to give player feedback of being denied if changing gadgets fails
// Despawn current gadgetRange if (!EndlessVendettaCharacter->UpdateGadgetType(GadgetsArray[GadgetIndex])) return;
// Spawn in the correct gadget range for the gadget
EndlessVendettaCharacter->UpdateGadgetType(GadgetsArray[GadgetIndex]); if (IsValid(CurrentGadgetTutorial)) CurrentGadgetTutorial->DestroyTutorial();
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
TSubclassOf<ABaseGadgetTutorial> GadgetTutorialToSpawnInClass = GadgetsArray[GadgetIndex]->GetDefaultObject<AGadgetBase>()->GadgetTutorialClass;
FTransform SpawnTransform = GadgetTutorialToSpawnInClass->GetDefaultObject<ABaseGadgetTutorial>()->GetSpawnTransform();
AActor* GadgetTutorialActor = GetWorld()->SpawnActor<AActor>(GadgetTutorialToSpawnInClass, SpawnTransform.GetLocation(), SpawnTransform.GetRotation().Rotator(), SpawnParams);
CurrentGadgetTutorial = Cast<ABaseGadgetTutorial>(GadgetTutorialActor);
} }
void AGadgetTutorialStation::CloseWidget() void AGadgetTutorialStation::CloseWidget()

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "BaseGadgetTutorial.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h" #include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "EndlessVendetta/GadgetSystem/GadgetBase.h" #include "EndlessVendetta/GadgetSystem/GadgetBase.h"
#include "EndlessVendetta/InteractionInterface.h" #include "EndlessVendetta/InteractionInterface.h"
@ -29,6 +30,8 @@ class ENDLESSVENDETTA_API AGadgetTutorialStation : public AActor, public IIntera
UGadgetMenu* GadgetMenu; UGadgetMenu* GadgetMenu;
ABaseGadgetTutorial* CurrentGadgetTutorial;
protected: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;