Add Basic Spell System (#9)
Co-authored-by: alhashij <alhashimy.janna@gmail.com> Reviewed-on: #9 Co-authored-by: Lance1416 <lanceli1416@gmail.com> Co-committed-by: Lance1416 <lanceli1416@gmail.com>
This commit was merged in pull request #9.
This commit is contained in:
@@ -3,18 +3,18 @@
|
||||
|
||||
#include "LumiCharacter.h"
|
||||
|
||||
#include "Engine/LocalPlayer.h"
|
||||
#include "Engine/UserInterfaceSettings.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "GameFramework/Controller.h"
|
||||
#include "InputActionValue.h"
|
||||
#include "Engine/LocalPlayer.h"
|
||||
#include "Engine/UserInterfaceSettings.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "GameFramework/Controller.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "InputActionValue.h"
|
||||
#include "WizardingCentral/Utils/OneDollar/UniStrokeDataTable.h"
|
||||
#include "WizardingCentral/Utils/OneDollar/UniStrokeResult.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogLumiCharacter);
|
||||
static const FString SpellTemplatesTablePath = TEXT("/Game/DataTables/SpellTemplates.SpellTemplates");
|
||||
|
||||
// Sets default values
|
||||
ALumiCharacter::ALumiCharacter()
|
||||
@@ -49,8 +49,17 @@ ALumiCharacter::ALumiCharacter()
|
||||
// Spell System
|
||||
bIsDrawing = false;
|
||||
SpellRecognizer = new FUniStrokeRecognizer();
|
||||
if (SpellTemplatesTable)
|
||||
LoadSpellTemplates();
|
||||
if (SpellTemplatesTable == nullptr)
|
||||
{
|
||||
SpellTemplatesTable = Cast<UDataTable>(
|
||||
StaticLoadObject(
|
||||
UDataTable::StaticClass(),
|
||||
nullptr,
|
||||
*SpellTemplatesTablePath
|
||||
)
|
||||
);
|
||||
}
|
||||
LoadSpellTemplates();
|
||||
}
|
||||
|
||||
ELumiStance ALumiCharacter::GetCurrentStance() const
|
||||
@@ -67,7 +76,7 @@ void ALumiCharacter::BeginPlay()
|
||||
|
||||
if (!GetPlayerController(LumiController))
|
||||
{
|
||||
UE_LOG(LogLumiCharacter, Error, TEXT("ALumiCharacter::BeginPlay() Failed to get LumiController!"));
|
||||
UE_LOG(LogTemp, Error, TEXT("ALumiCharacter::BeginPlay() Failed to get LumiController!"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,19 +120,21 @@ bool ALumiCharacter::IsLastJump() const
|
||||
|
||||
void ALumiCharacter::OnGrabActionTriggered(const FInputActionValue& Value)
|
||||
{
|
||||
UE_LOG(LogLumiCharacter, Log, TEXT("Grab Triggered"));
|
||||
UE_LOG(LogTemp, Log, TEXT("Grab Triggered"));
|
||||
}
|
||||
|
||||
void ALumiCharacter::OnJumpActionStarted(const FInputActionValue& Value)
|
||||
{
|
||||
// Broadcast that the jump has started
|
||||
OnJumpStarted.Broadcast();
|
||||
UE_LOG(LogLumiCharacter, Log, TEXT("Jump Started"));
|
||||
UE_LOG(LogTemp, Log, TEXT("Jump Started"));
|
||||
|
||||
Jump();
|
||||
}
|
||||
|
||||
void ALumiCharacter::OnJumpActionOngoing(const FInputActionValue& Value) {}
|
||||
void ALumiCharacter::OnJumpActionOngoing(const FInputActionValue& Value)
|
||||
{
|
||||
}
|
||||
|
||||
void ALumiCharacter::OnJumpActionCompleted(const FInputActionValue& Value)
|
||||
{
|
||||
@@ -171,12 +182,12 @@ void ALumiCharacter::OnLookActionTriggered(const FInputActionValue& Value)
|
||||
|
||||
void ALumiCharacter::OnDefaultStance_Implementation()
|
||||
{
|
||||
UE_LOG(LogLumiCharacter, Log, TEXT("OnDefaultStance_Implementation()"));
|
||||
UE_LOG(LogTemp, Log, TEXT("OnDefaultStance_Implementation()"));
|
||||
}
|
||||
|
||||
void ALumiCharacter::OnMagicStance_Implementation()
|
||||
{
|
||||
UE_LOG(LogLumiCharacter, Log, TEXT("OnMagicStance_Implementation()"));
|
||||
UE_LOG(LogTemp, Log, TEXT("OnMagicStance_Implementation()"));
|
||||
}
|
||||
|
||||
void ALumiCharacter::OnSpellActionStarted()
|
||||
@@ -190,7 +201,7 @@ void ALumiCharacter::OnSpellActionCompleted()
|
||||
if (SpellSystemState == Casting)
|
||||
SpellSystemState = bIsTraining ? Training : Recognizing;
|
||||
|
||||
UE_LOG(LogLumiCharacter, Log, TEXT("OnSpellActionCompleted() Current State: %d"), SpellSystemState);
|
||||
UE_LOG(LogTemp, Log, TEXT("OnSpellActionCompleted() Current State: %d"), SpellSystemState);
|
||||
|
||||
switch (SpellSystemState)
|
||||
{
|
||||
@@ -276,6 +287,16 @@ void ALumiCharacter::AddSpellTemplateToTable(const FString& Name)
|
||||
HideTrainWidget();
|
||||
}
|
||||
|
||||
void ALumiCharacter::OnSpellCast_Implementation(const FString& SpellName)
|
||||
{
|
||||
UE_LOG(
|
||||
LogTemp,
|
||||
Log,
|
||||
TEXT("ALumiCharacter::OnSpellCast_Implementation() Spell: %s"),
|
||||
*SpellName
|
||||
);
|
||||
}
|
||||
|
||||
bool ALumiCharacter::GetPlayerController(APlayerController*& LumiController) const
|
||||
{
|
||||
LumiController = Cast<APlayerController>(this->Controller);
|
||||
@@ -300,17 +321,19 @@ void ALumiCharacter::LoadSpellTemplates() const
|
||||
void ALumiCharacter::CastSpell()
|
||||
{
|
||||
const TArray<FVector2D>* CurrentPoints = SpellOverlay->GetSpellPoints();
|
||||
const FUniStrokeResult Result = SpellRecognizer->Recognize(*CurrentPoints, false);
|
||||
const FUniStrokeResult Result = SpellRecognizer->Recognize(*CurrentPoints);
|
||||
|
||||
bool bHasMatch = false;
|
||||
if (Result.Score < 0.8f)
|
||||
{
|
||||
UE_LOG(LogLumiCharacter, Log, TEXT("ALumiCharacter::CastSpell() No match found!"));
|
||||
UE_LOG(LogTemp, Log, TEXT("ALumiCharacter::CastSpell() No match found!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
bHasMatch = true;
|
||||
UE_LOG(LogLumiCharacter, Log, TEXT("ALumiCharacter::CastSpell() Spell: %s"), *Result.Name);
|
||||
UE_LOG(LogTemp, Log, TEXT("ALumiCharacter::CastSpell() Spell: %s"), *Result.Name);
|
||||
|
||||
OnSpellCast(Result.Name);
|
||||
}
|
||||
|
||||
// TODO: Handle Spell Casting
|
||||
|
||||
Reference in New Issue
Block a user