HAxis sos
This commit is contained in:
15
Source/UnrealProject/Doodads/BaseSkillObject.cpp
Normal file
15
Source/UnrealProject/Doodads/BaseSkillObject.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "BaseSkillObject.h"
|
||||
|
||||
/*
|
||||
void UBaseSkillObject::Serialize( FArchive& a_ar )
|
||||
{
|
||||
Super::Serialize( a_ar );
|
||||
|
||||
UE_LOG( LogTemp, Warning, TEXT( "UBaseSkillObject: Serializing..." ) );
|
||||
|
||||
a_ar << *this;
|
||||
}
|
||||
*/
|
||||
70
Source/UnrealProject/Doodads/BaseSkillObject.h
Normal file
70
Source/UnrealProject/Doodads/BaseSkillObject.h
Normal file
@@ -0,0 +1,70 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SkillObject.h"
|
||||
#include "Items/ItemBase.h"
|
||||
#include "BaseSkillObject.generated.h"
|
||||
|
||||
class AModifier;
|
||||
|
||||
USTRUCT()
|
||||
struct FSkillItem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
USkeletalMesh* mesh;
|
||||
UPROPERTY(EditAnywhere)
|
||||
EItemTypeEnum type;
|
||||
};
|
||||
|
||||
USTRUCT()
|
||||
struct FSkillItemHolder
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
bool isVisible;
|
||||
UPROPERTY(EditAnywhere, meta = (EditCondition = "isVisible"))
|
||||
TArray<FSkillItem> itemsToEquip;
|
||||
UPROPERTY(EditDefaultsOnly, meta = (EditCondition = "isVisible"))
|
||||
UParticleSystem* particleEffect;
|
||||
};
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class ESkillShapeType : uint8
|
||||
{
|
||||
Active = 0,
|
||||
Passive,
|
||||
Sustain,
|
||||
Coop,
|
||||
};
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
class UNREALPROJECT_API UBaseSkillObject : public USkillObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Skill")
|
||||
TArray<TSubclassOf<AModifier>> modifiers;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Skill")
|
||||
TArray<class UAbilityInfo*> abilityEffects;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Skill")
|
||||
ESkillShapeType skillShapeType;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Skill")
|
||||
FSkillItemHolder visibleItems;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Skill")
|
||||
FIntPoint pivot;
|
||||
|
||||
/*
|
||||
virtual void Serialize( FArchive& a_ar ) override;
|
||||
|
||||
friend FArchive& operator<<( FArchive& a_ar, UBaseSkillObject& a_v )
|
||||
{
|
||||
UE_LOG( LogTemp, Warning, TEXT( "UBaseSkillObject: << Operator..." ) );
|
||||
return a_ar;
|
||||
}
|
||||
*/
|
||||
};
|
||||
256
Source/UnrealProject/Doodads/CharacterCarousel.cpp
Normal file
256
Source/UnrealProject/Doodads/CharacterCarousel.cpp
Normal file
@@ -0,0 +1,256 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "CharacterCarousel.h"
|
||||
#include "CharacterBase.h"
|
||||
#include "DefaultGameInstance.h"
|
||||
|
||||
|
||||
|
||||
ACharacterCarousel::ACharacterCarousel()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
selectedCharacterIndex = 0;
|
||||
m_visualSelected = 0;
|
||||
selected = false;
|
||||
|
||||
m_zoom = 0;
|
||||
|
||||
selectedCharacterOffset = FVector(30, -120, 0);
|
||||
}
|
||||
|
||||
|
||||
void ACharacterCarousel::BeginPlay()
|
||||
{
|
||||
check(IsValid(characterBlueprint));
|
||||
|
||||
Super::BeginPlay();
|
||||
|
||||
// Fix the rotation
|
||||
FRotator rotation = GetActorRotation();
|
||||
SetActorRotation(FRotator(0, rotation.Yaw, 0));
|
||||
|
||||
const FVector position = GetActorLocation();
|
||||
const FVector forward = GetActorForwardVector();
|
||||
const FVector right = GetActorRightVector();
|
||||
|
||||
UDefaultGameInstance* instance = Cast<UDefaultGameInstance>(GetGameInstance());
|
||||
check(instance);
|
||||
UCharacterSettings* settings = instance->GetCharacterSettings();
|
||||
check(settings);
|
||||
|
||||
for (int32 i = 0; i < settings->characterSaves.Num(); i++)
|
||||
{
|
||||
FActorSpawnParameters spawnParams;
|
||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
ACharacterBase* actor = GetWorld()->SpawnActor<ACharacterBase>(characterBlueprint, GetActorLocation(), GetActorRotation(), spawnParams);
|
||||
m_characters.Add(actor);
|
||||
}
|
||||
}
|
||||
void ACharacterCarousel::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
||||
{
|
||||
Super::EndPlay(EndPlayReason);
|
||||
|
||||
for (int32 i = 0; i < m_characters.Num(); i++)
|
||||
{
|
||||
if (IsValid(m_characters[i]))
|
||||
m_characters[i]->Destroy();
|
||||
}
|
||||
m_characters.SetNum(0);
|
||||
}
|
||||
|
||||
|
||||
inline float MoveTowardsTarget(float current, float target, float delta, float min = 0.0005f)
|
||||
{
|
||||
const int32 moveDir = target > current ? 1 : -1;
|
||||
float d = FMath::Abs((target - current) * delta);
|
||||
if (d < 0.0005f) d = 0.0005f;
|
||||
|
||||
current += d * moveDir;
|
||||
|
||||
// Clamp
|
||||
current = (moveDir == 1) ?
|
||||
(current > target ? target : current) :
|
||||
(current < target ? target : current);
|
||||
|
||||
return current;
|
||||
}
|
||||
void ACharacterCarousel::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
if (m_characters.Num() == 0)
|
||||
return;
|
||||
|
||||
// Zoom towards the target
|
||||
const float zoomTarget = selected ? 1 : 0;
|
||||
m_zoom = MoveTowardsTarget(m_zoom, zoomTarget, DeltaTime * 10);
|
||||
|
||||
const FVector position = GetActorLocation();
|
||||
const FVector forward = GetActorForwardVector();
|
||||
const FVector right = GetActorRightVector();
|
||||
|
||||
const float carouselRadius = 1200;
|
||||
const float carouselAngle = 10;
|
||||
const FVector pivot = position - forward * carouselRadius;
|
||||
|
||||
// Clamp the selected index (may be altered from a blueprint)
|
||||
selectedCharacterIndex = selectedCharacterIndex < 0 ? 0 : selectedCharacterIndex >= m_characters.Num() ? m_characters.Num() - 1 : selectedCharacterIndex;
|
||||
|
||||
// Animate the carousel
|
||||
const float target = float(selectedCharacterIndex);
|
||||
m_visualSelected = MoveTowardsTarget(m_visualSelected, target, DeltaTime * (selected ? 10 : 5));
|
||||
|
||||
// Spawn and set the characters
|
||||
const FRotator rotation = GetActorRotation();
|
||||
const FVector arm = forward * carouselRadius;
|
||||
const FVector selectedOffset = rotation.RotateVector(selectedCharacterOffset) * m_zoom;
|
||||
|
||||
for (int32 i = 0; i < m_characters.Num(); i++)
|
||||
{
|
||||
const int32 distance = i - selectedCharacterIndex;
|
||||
if (distance < -2 || distance > 2)
|
||||
{
|
||||
// Dont render characters off screen
|
||||
m_characters[i]->GetRootComponent()->SetVisibility(false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_characters[i]->GetRootComponent()->SetVisibility(true, true);
|
||||
|
||||
// Set the position relative from the pivot
|
||||
FRotator rotator(0, -carouselAngle * (float(i) - m_visualSelected), 0);
|
||||
if (m_zoom > 0) rotator.Yaw *= (m_zoom + 1);
|
||||
FVector offset = rotator.RotateVector(arm);
|
||||
if (i == selectedCharacterIndex)
|
||||
offset += selectedOffset;
|
||||
m_characters[i]->SetActorLocation(pivot + offset);
|
||||
m_characters[i]->SetActorRotation(rotator + FRotator(0, rotation.Yaw, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ACharacterCarousel::Reset()
|
||||
{
|
||||
selectedCharacterIndex = 0;
|
||||
m_visualSelected = 0;
|
||||
selected = false;
|
||||
|
||||
m_zoom = 0;
|
||||
}
|
||||
|
||||
void ACharacterCarousel::Next()
|
||||
{
|
||||
if(!selected && m_characters.Num() > 0 && selectedCharacterIndex < m_characters.Num() - 1)
|
||||
selectedCharacterIndex++;
|
||||
}
|
||||
void ACharacterCarousel::Previous()
|
||||
{
|
||||
if (!selected && selectedCharacterIndex > 0)
|
||||
selectedCharacterIndex--;
|
||||
}
|
||||
|
||||
void ACharacterCarousel::ToggleSelect(bool enabled)
|
||||
{
|
||||
selected = enabled;
|
||||
}
|
||||
|
||||
void ACharacterCarousel::CreateNewCharacter(const FString& name)
|
||||
{
|
||||
UDefaultGameInstance* instance = Cast<UDefaultGameInstance>(GetGameInstance());
|
||||
check(instance);
|
||||
UCharacterSettings* settings = instance->GetCharacterSettings();
|
||||
check(settings);
|
||||
|
||||
// Create a scene actor
|
||||
ACharacterBase* actor = GetWorld()->SpawnActor<ACharacterBase>(characterBlueprint, GetActorLocation(), GetActorRotation());
|
||||
m_characters.Add(actor);
|
||||
|
||||
// Select this character
|
||||
selected = false;
|
||||
selectedCharacterIndex = m_characters.Num() - 1;
|
||||
m_zoom = 0;
|
||||
|
||||
// Add to save
|
||||
FCharacterSave save;
|
||||
save.name = name;
|
||||
settings->characterSaves.Add(save);
|
||||
instance->SaveSettings();
|
||||
}
|
||||
void ACharacterCarousel::DeleteCharacter(int32 index)
|
||||
{
|
||||
UDefaultGameInstance* instance = Cast<UDefaultGameInstance>(GetGameInstance());
|
||||
check(instance);
|
||||
UCharacterSettings* settings = instance->GetCharacterSettings();
|
||||
check(settings);
|
||||
|
||||
if (index < 0 || index >= settings->characterSaves.Num())
|
||||
{
|
||||
JERROR("Invalid character index");
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroy scene actor
|
||||
m_characters[index]->Destroy();
|
||||
m_characters.RemoveAt(index);
|
||||
if (index == selectedCharacterIndex)
|
||||
selectedCharacterIndex--;
|
||||
|
||||
// Unselect
|
||||
selected = false;
|
||||
m_zoom = 0;
|
||||
|
||||
// Remove from save
|
||||
settings->characterSaves.RemoveAt(index);
|
||||
instance->SaveSettings();
|
||||
}
|
||||
|
||||
ACharacterBase* ACharacterCarousel::GetCharacterModel(int32 index)
|
||||
{
|
||||
if (index < 0 || index >= m_characters.Num())
|
||||
{
|
||||
JERROR("Invalid character index");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return m_characters[index];
|
||||
}
|
||||
int32 ACharacterCarousel::GetCharacterNum()
|
||||
{
|
||||
return m_characters.Num();
|
||||
}
|
||||
|
||||
|
||||
void ACharacterCarousel::SaveCharacterName(const FString& name, int32 index)
|
||||
{
|
||||
UDefaultGameInstance* instance = Cast<UDefaultGameInstance>(GetGameInstance());
|
||||
check(instance);
|
||||
UCharacterSettings* settings = instance->GetCharacterSettings();
|
||||
check(settings);
|
||||
|
||||
if (index < 0 || index >= settings->characterSaves.Num())
|
||||
{
|
||||
JERROR("Invalid character index");
|
||||
return;
|
||||
}
|
||||
|
||||
settings->characterSaves[index].name = name;
|
||||
instance->SaveSettings();
|
||||
}
|
||||
FString ACharacterCarousel::GetCharacterName(int32 index)
|
||||
{
|
||||
UDefaultGameInstance* instance = Cast<UDefaultGameInstance>(GetGameInstance());
|
||||
check(instance);
|
||||
UCharacterSettings* settings = instance->GetCharacterSettings();
|
||||
check(settings);
|
||||
|
||||
if (index < 0 || index >= settings->characterSaves.Num())
|
||||
{
|
||||
JERROR("Invalid character index");
|
||||
return FString();
|
||||
}
|
||||
|
||||
return settings->characterSaves[index].name;
|
||||
}
|
||||
70
Source/UnrealProject/Doodads/CharacterCarousel.h
Normal file
70
Source/UnrealProject/Doodads/CharacterCarousel.h
Normal file
@@ -0,0 +1,70 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "CharacterSettings.h"
|
||||
#include "CharacterCarousel.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API ACharacterCarousel : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
ACharacterCarousel();
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
||||
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaSeconds) override;
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
void Reset();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
void Next();
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
void Previous();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
void ToggleSelect(bool enabled);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
void CreateNewCharacter(const FString& name);
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
void DeleteCharacter(int32 index);
|
||||
|
||||
// Index of the current selected character
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Carousel")
|
||||
int32 selectedCharacterIndex;
|
||||
|
||||
// Wether the current character is also selected
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Carousel")
|
||||
bool selected;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Carousel")
|
||||
TSubclassOf<class ACharacterBase> characterBlueprint;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
class ACharacterBase* GetCharacterModel(int32 index);
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
int32 GetCharacterNum();
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Carousel")
|
||||
FVector selectedCharacterOffset;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
void SaveCharacterName(const FString& name, int32 index);
|
||||
UFUNCTION(BlueprintCallable, Category = "Carousel")
|
||||
FString GetCharacterName(int32 index);
|
||||
|
||||
private:
|
||||
TArray<class ACharacterBase*> m_characters;
|
||||
float m_visualSelected;
|
||||
float m_zoom;
|
||||
};
|
||||
66
Source/UnrealProject/Doodads/CharacterSettings.cpp
Normal file
66
Source/UnrealProject/Doodads/CharacterSettings.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "CharacterSettings.h"
|
||||
#include "SkillTreeWidget.h"
|
||||
#include "UserWidget.h"
|
||||
|
||||
#define SAVE_SLOT_NAME TEXT("WIEBERSAVE tm")
|
||||
|
||||
static UClass* skillTreeWidgetClass;
|
||||
|
||||
UCharacterSettings::UCharacterSettings(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
skillTreeWidgetClass = ConstructorHelpers::FClassFinder<USkillTreeWidget>(TEXT("/Game/Assets/GUI/WEEGEE_SkillTree")).Class;
|
||||
}
|
||||
|
||||
UCharacterSettings* UCharacterSettings::Load()
|
||||
{
|
||||
UCharacterSettings* settings = Cast<UCharacterSettings>(UGameplayStatics::LoadGameFromSlot(SAVE_SLOT_NAME, 0));
|
||||
if (!settings)
|
||||
{
|
||||
settings = Cast<UCharacterSettings>(UGameplayStatics::CreateSaveGameObject(UCharacterSettings::StaticClass()));
|
||||
}
|
||||
check(settings);
|
||||
|
||||
for (auto& save : settings->characterSaves)
|
||||
{
|
||||
for (TFieldIterator<UProperty> PropIt(FCharacterCustomization::StaticStruct()); PropIt; ++PropIt)
|
||||
{
|
||||
UFloatProperty* fProperty = Cast<UFloatProperty>(*PropIt);
|
||||
|
||||
if (IsValid(fProperty))
|
||||
{
|
||||
float* valPtr = fProperty->GetPropertyValuePtr_InContainer(&save.characterCustomization);
|
||||
*valPtr = FMath::Clamp(*valPtr, 0.5f, 1.5f);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
void UCharacterSettings::Save(UCharacterSettings* settings)
|
||||
{
|
||||
UGameplayStatics::SaveGameToSlot(settings, SAVE_SLOT_NAME, 0);
|
||||
}
|
||||
|
||||
TArray<FCharacterSave> UCharacterSettings::GetValidCharacters() const
|
||||
{
|
||||
UCharacterSettings* settings = Cast<UCharacterSettings>(UGameplayStatics::LoadGameFromSlot(SAVE_SLOT_NAME, 0));
|
||||
if (!settings)
|
||||
{
|
||||
settings = Cast<UCharacterSettings>(UGameplayStatics::CreateSaveGameObject(UCharacterSettings::StaticClass()));
|
||||
}
|
||||
check(settings);
|
||||
|
||||
TArray<FCharacterSave> result;
|
||||
for (FCharacterSave& save : settings->characterSaves)
|
||||
{
|
||||
if (save.skillTreeState.ValidateSkillTree())
|
||||
result.Add(save);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
47
Source/UnrealProject/Doodads/CharacterSettings.h
Normal file
47
Source/UnrealProject/Doodads/CharacterSettings.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/SaveGame.h"
|
||||
#include "SkillTreeState.h"
|
||||
#include "PlayerSetupState.h"
|
||||
#include "CharacterSettings.generated.h"
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FCharacterSave
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Save")
|
||||
FString name;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Save")
|
||||
FSkillTreeState skillTreeState;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Save")
|
||||
FCharacterCustomization characterCustomization;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Save")
|
||||
int32 characterClass;
|
||||
};
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API UCharacterSettings : public USaveGame
|
||||
{
|
||||
GENERATED_BODY()
|
||||
private:
|
||||
|
||||
public:
|
||||
UCharacterSettings(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Basic")
|
||||
TArray<FCharacterSave> characterSaves;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Basic")
|
||||
TArray<FCharacterSave> GetValidCharacters() const;
|
||||
public:
|
||||
static UCharacterSettings* Load();
|
||||
static void Save(UCharacterSettings* settings);
|
||||
|
||||
};
|
||||
74
Source/UnrealProject/Doodads/FixupUtility.cpp
Normal file
74
Source/UnrealProject/Doodads/FixupUtility.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "FixupUtility.h"
|
||||
#include "AbilityInfo.h"
|
||||
#include "AssetRegistryInterface.h"
|
||||
#include "AssetRegistryModule.h"
|
||||
#include "SpawnerBase.h"
|
||||
|
||||
void UFixupUtility::FixupAbilityInfos()
|
||||
{
|
||||
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
|
||||
TArray<FAssetData> AssetData;
|
||||
FARFilter Filter;
|
||||
Filter.ClassNames.Add(UAbilityInfo::StaticClass()->GetFName());
|
||||
//Filter.PackagePaths.Add("/Content/Assets/Abilities");
|
||||
AssetRegistryModule.Get().GetAssets(Filter, AssetData);
|
||||
|
||||
for(auto& d : AssetData)
|
||||
{
|
||||
UAbilityInfo* info = Cast<UAbilityInfo>(d.GetAsset());
|
||||
if(info)
|
||||
{
|
||||
GPRINT("Fixing up " + info->GetName());
|
||||
//info->actionType = info->isToggleAbility ? EAbilityActionType::Toggle : EAbilityActionType::Normal;
|
||||
//info->abilityCategory = EAbilityCategory::Unassigned;
|
||||
//info->Modify();
|
||||
}
|
||||
}
|
||||
}
|
||||
void UFixupUtility::FixAICastRanges(const FString& filter, float setRange, bool evenIfNotZero)
|
||||
{
|
||||
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
|
||||
TArray<FAssetData> AssetData;
|
||||
FARFilter Filter;
|
||||
Filter.ClassNames.Add(UAbilityInfo::StaticClass()->GetFName());
|
||||
//Filter.PackagePaths.Add("/Content/Assets/Abilities/Boss");
|
||||
if(filter.Len() > 0)
|
||||
{
|
||||
Filter.PackagePaths.Add(*filter);
|
||||
}
|
||||
AssetRegistryModule.Get().GetAssets(Filter, AssetData);
|
||||
|
||||
for(auto& d : AssetData)
|
||||
{
|
||||
UAbilityInfo* info = Cast<UAbilityInfo>(d.GetAsset());
|
||||
if(info)
|
||||
{
|
||||
GPRINT("Fixing up AIRange on " + info->GetName());
|
||||
if(info->AICastRange == 0 || evenIfNotZero)
|
||||
{
|
||||
info->AICastRange = setRange;
|
||||
info->Modify();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void UFixupUtility::FixupSpawners()
|
||||
{
|
||||
UWorld* world = GEngine->GetWorld();
|
||||
if(world)
|
||||
{
|
||||
for(TActorIterator<ASpawnerBase> it(world); it; ++it)
|
||||
{
|
||||
ASpawnerBase* sp = *it;
|
||||
sp->displayMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
void UFixupUtility::CrashTheEditor()
|
||||
{
|
||||
uint32* funPointer = (uint32*)0x1;
|
||||
GPRINT(*funPointer);
|
||||
}
|
||||
25
Source/UnrealProject/Doodads/FixupUtility.h
Normal file
25
Source/UnrealProject/Doodads/FixupUtility.h
Normal file
@@ -0,0 +1,25 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GlobalEditorUtilityBase.h"
|
||||
#include "FixupUtility.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API UFixupUtility : public UGlobalEditorUtilityBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable, Category="HACKS")
|
||||
void FixupAbilityInfos();
|
||||
UFUNCTION(BlueprintCallable, Category = "HACKS")
|
||||
void FixAICastRanges(const FString& filter, float setRange, bool evenIfNotZero = false);
|
||||
UFUNCTION(BlueprintCallable, Category = "HACKS")
|
||||
void FixupSpawners();
|
||||
UFUNCTION(BlueprintCallable, Category = "HACKS")
|
||||
void CrashTheEditor();
|
||||
};
|
||||
11
Source/UnrealProject/Doodads/NetworkDoodad.cpp
Normal file
11
Source/UnrealProject/Doodads/NetworkDoodad.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "NetworkDoodad.h"
|
||||
|
||||
|
||||
ANetworkDoodad::ANetworkDoodad()
|
||||
{
|
||||
bReplicates = true;
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
}
|
||||
23
Source/UnrealProject/Doodads/NetworkDoodad.h
Normal file
23
Source/UnrealProject/Doodads/NetworkDoodad.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "NetworkDoodad.generated.h"
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class ToggleType : uint8
|
||||
{
|
||||
ToggleObject,
|
||||
OpenObject,
|
||||
CloseObject,
|
||||
};
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API ANetworkDoodad : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ANetworkDoodad();
|
||||
};
|
||||
91
Source/UnrealProject/Doodads/NetworkDoor.cpp
Normal file
91
Source/UnrealProject/Doodads/NetworkDoor.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
|
||||
#include "NetworkDoor.h"
|
||||
|
||||
|
||||
ANetworkDoor::ANetworkDoor()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
debugColorCode = FColor::Red;
|
||||
|
||||
doorCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("Cube"));
|
||||
doorCollider->SetCollisionProfileName(TEXT("BlockAll"));
|
||||
RootComponent = doorCollider;
|
||||
|
||||
meshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
|
||||
meshComponent->AttachTo(doorCollider);
|
||||
|
||||
isDoorClosed = true;
|
||||
closeAfterTime = 0.0f;
|
||||
|
||||
debugSinkDepth = 250;
|
||||
}
|
||||
|
||||
|
||||
void ANetworkDoor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
m_openTime = 0.0f;
|
||||
}
|
||||
|
||||
void ANetworkDoor::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
if (doorCollider)
|
||||
{
|
||||
// Enable or disable the door collider
|
||||
doorCollider->SetCollisionEnabled(isDoorClosed ? ECollisionEnabled::QueryAndPhysics : ECollisionEnabled::NoCollision);
|
||||
}
|
||||
|
||||
if (meshComponent)
|
||||
{
|
||||
const FVector localPos = meshComponent->GetRelativeTransform().GetLocation();
|
||||
const FVector targetPos = FVector(0, 0, isDoorClosed ? 0.0f : -debugSinkDepth);
|
||||
|
||||
const float distanceSqr = FVector::DistSquared(localPos, targetPos);
|
||||
if (distanceSqr > 0.01f)
|
||||
{
|
||||
FVector dif = targetPos - localPos;
|
||||
dif.Normalize();
|
||||
float speed = DeltaTime * 800 * (debugSinkDepth / 250.0f);
|
||||
const float distance = FMath::Sqrt(distanceSqr);
|
||||
if (speed > distance) speed = distance;
|
||||
dif *= speed;
|
||||
meshComponent->SetRelativeLocation(localPos + dif);
|
||||
}
|
||||
}
|
||||
|
||||
if(Role == ROLE_Authority && !isDoorClosed && closeAfterTime > 0)
|
||||
{
|
||||
m_openTime += DeltaTime;
|
||||
if(m_openTime >= closeAfterTime)
|
||||
{
|
||||
SetDoorState(true);
|
||||
m_openTime = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ANetworkDoor::ToggleDoor()
|
||||
{
|
||||
// Server only function
|
||||
check(Role == ROLE_Authority);
|
||||
isDoorClosed = !isDoorClosed;
|
||||
}
|
||||
|
||||
void ANetworkDoor::SetDoorState(bool NewState)
|
||||
{
|
||||
// Server only function
|
||||
check(Role == ROLE_Authority);
|
||||
isDoorClosed = NewState;
|
||||
}
|
||||
|
||||
void ANetworkDoor::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||
{
|
||||
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||
|
||||
DOREPLIFETIME(ANetworkDoor, isDoorClosed);
|
||||
}
|
||||
40
Source/UnrealProject/Doodads/NetworkDoor.h
Normal file
40
Source/UnrealProject/Doodads/NetworkDoor.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "NetworkDoodad.h"
|
||||
#include "NetworkDoor.generated.h"
|
||||
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API ANetworkDoor : public ANetworkDoodad
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ANetworkDoor();
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
virtual void Tick(float DeltaSeconds) override;
|
||||
|
||||
void ToggleDoor();
|
||||
void SetDoorState(bool NewState);
|
||||
|
||||
UPROPERTY(Replicated, EditAnywhere, Category = "Switch Components")
|
||||
bool isDoorClosed;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
float closeAfterTime;
|
||||
UPROPERTY(EditAnywhere)
|
||||
FColor debugColorCode;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
float debugSinkDepth;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
class UBoxComponent* doorCollider;
|
||||
UPROPERTY(EditAnywhere)
|
||||
class UStaticMeshComponent* meshComponent;
|
||||
|
||||
private:
|
||||
float m_openTime;
|
||||
};
|
||||
92
Source/UnrealProject/Doodads/NetworkSwitch.cpp
Normal file
92
Source/UnrealProject/Doodads/NetworkSwitch.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "NetworkDoor.h"
|
||||
|
||||
#include "NetworkCharacter.h"
|
||||
#include "NetworkSwitchComponent.h"
|
||||
#include "CreatureSpawn.h"
|
||||
#include "NetworkSwitch.h"
|
||||
|
||||
|
||||
|
||||
ANetworkSwitch::ANetworkSwitch()
|
||||
{
|
||||
cooldown = m_elapsedTime = 0.0f;
|
||||
cubeCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("Cube"));
|
||||
cubeCollider->SetCollisionProfileName(TEXT("BlockAll"));
|
||||
RootComponent = cubeCollider;
|
||||
|
||||
meshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh"));
|
||||
meshComponent->AttachTo(RootComponent);
|
||||
|
||||
visualizerComponent = CreateDefaultSubobject<UNetworkSwitchComponent>(TEXT("Visualizer"));
|
||||
visualizerComponent->AttachTo(RootComponent);
|
||||
|
||||
isSwitchClosed = false;
|
||||
|
||||
toggles = false;
|
||||
}
|
||||
|
||||
void ANetworkSwitch::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
m_elapsedTime = cooldown;
|
||||
|
||||
if (Role != ROLE_Authority)
|
||||
return;
|
||||
|
||||
// Init the door states
|
||||
if (!toggles)
|
||||
{
|
||||
for (int32 i = 0; i < doorsToOpen.Num(); i++)
|
||||
{
|
||||
if (doorsToOpen[i])
|
||||
doorsToOpen[i]->SetDoorState(isSwitchClosed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ANetworkSwitch::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
// Animate the switch (must be replaced with an actual animated mesh in future)
|
||||
meshComponent->SetRelativeRotation(FRotator(isSwitchClosed ? 30 : -30, 0, 0));
|
||||
|
||||
if (Role != ROLE_Authority)
|
||||
return;
|
||||
|
||||
if (cooldown > 0)
|
||||
m_elapsedTime += DeltaTime;
|
||||
}
|
||||
|
||||
void ANetworkSwitch::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||
{
|
||||
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||
|
||||
DOREPLIFETIME(ANetworkSwitch, isSwitchClosed);
|
||||
}
|
||||
|
||||
void ANetworkSwitch::Toggle()
|
||||
{
|
||||
check(Role == ROLE_Authority);
|
||||
|
||||
if (m_elapsedTime < cooldown)
|
||||
return;
|
||||
|
||||
m_elapsedTime = 0;
|
||||
isSwitchClosed = !isSwitchClosed;
|
||||
|
||||
// Toggle all linked doors
|
||||
for (int32 i = 0; i < doorsToOpen.Num(); i++)
|
||||
{
|
||||
if (doorsToOpen[i])
|
||||
{
|
||||
if (toggles)
|
||||
doorsToOpen[i]->ToggleDoor();
|
||||
else
|
||||
doorsToOpen[i]->SetDoorState(isSwitchClosed);
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Source/UnrealProject/Doodads/NetworkSwitch.h
Normal file
41
Source/UnrealProject/Doodads/NetworkSwitch.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "NetworkDoodad.h"
|
||||
#include "NetworkSwitch.generated.h"
|
||||
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API ANetworkSwitch : public ANetworkDoodad
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ANetworkSwitch();
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
virtual void Tick(float DeltaSeconds) override;
|
||||
|
||||
void Toggle();
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
TArray<class ANetworkDoor*> doorsToOpen;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
float cooldown;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
bool toggles;
|
||||
|
||||
UPROPERTY(Replicated, EditAnywhere, Category = "Switch Components")
|
||||
bool isSwitchClosed;
|
||||
|
||||
private:
|
||||
float m_elapsedTime;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
class UBoxComponent* cubeCollider;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
class UStaticMeshComponent* meshComponent;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
class UNetworkSwitchComponent* visualizerComponent;
|
||||
};
|
||||
108
Source/UnrealProject/Doodads/NetworkSwitchComponent.cpp
Normal file
108
Source/UnrealProject/Doodads/NetworkSwitchComponent.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "NetworkSwitchComponent.h"
|
||||
#include "NetworkDoor.h"
|
||||
#include "NetworkSwitch.h"
|
||||
#include "NetworkTrigger.h"
|
||||
#include "Spawners/CreatureSpawn.h"
|
||||
|
||||
UNetworkSwitchComponent::UNetworkSwitchComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
|
||||
{
|
||||
ShapeColor = FColor(223, 149, 157, 255);
|
||||
|
||||
bUseEditorCompositing = true;
|
||||
|
||||
networkDoodad = Cast<ANetworkDoodad>(GetAttachmentRootActor());
|
||||
creatureSpawn = Cast<ACreatureSpawn>(GetAttachmentRootActor());
|
||||
}
|
||||
|
||||
FPrimitiveSceneProxy* UNetworkSwitchComponent::CreateSceneProxy()
|
||||
{
|
||||
class FDrawConeSceneProxy : public FPrimitiveSceneProxy
|
||||
{
|
||||
public:
|
||||
const UNetworkSwitchComponent* component;
|
||||
FDrawConeSceneProxy(const UNetworkSwitchComponent* InComponent)
|
||||
: FPrimitiveSceneProxy(InComponent)
|
||||
, networkDoodad(InComponent->networkDoodad)
|
||||
, creatureSpawn(InComponent->creatureSpawn)
|
||||
, bDrawOnlyIfSelected(InComponent->bDrawOnlyIfSelected)
|
||||
, component(InComponent)
|
||||
{
|
||||
bWillEverBeLit = false;
|
||||
}
|
||||
|
||||
|
||||
virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override
|
||||
{
|
||||
QUICK_SCOPE_CYCLE_COUNTER(STAT_GetDynamicMeshElements_DrawDynamicElements);
|
||||
|
||||
const FMatrix& LocalToWorld = GetLocalToWorld();
|
||||
|
||||
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
||||
{
|
||||
const FSceneView* View = Views[ViewIndex];
|
||||
|
||||
FPrimitiveDrawInterface* PDI = Collector.GetPDI(ViewIndex);
|
||||
if (networkDoodad)
|
||||
{
|
||||
if (networkDoodad->IsA(ANetworkTrigger::StaticClass()))
|
||||
{
|
||||
const ANetworkTrigger* const obj = Cast<const ANetworkTrigger>(networkDoodad);
|
||||
for (int32 i = 0; i < obj->doorsToOpen.Num(); i++)
|
||||
{
|
||||
if (obj->doorsToOpen[i])
|
||||
PDI->DrawLine(obj->GetActorLocation() + FVector(0, 0, 100), obj->doorsToOpen[i]->GetActorLocation() + FVector(0, 0, 100), obj->doorsToOpen[i]->debugColorCode, SDPG_World);
|
||||
}
|
||||
for (int32 i = 0; i < obj->creaturesToSpawn.Num(); i++)
|
||||
{
|
||||
if (obj->creaturesToSpawn[i])
|
||||
PDI->DrawLine(obj->GetActorLocation() + FVector(0, 0, 100), obj->creaturesToSpawn[i]->GetActorLocation() + FVector(0, 0, 100), obj->creaturesToSpawn[i]->debugColorCode, SDPG_World);
|
||||
}
|
||||
}
|
||||
if (networkDoodad->IsA(ANetworkSwitch::StaticClass()))
|
||||
{
|
||||
const ANetworkSwitch* const obj = Cast<const ANetworkSwitch>(networkDoodad);
|
||||
for (int32 i = 0; i < obj->doorsToOpen.Num(); i++)
|
||||
{
|
||||
if (obj->doorsToOpen[i])
|
||||
PDI->DrawLine(obj->GetActorLocation() + FVector(0, 0, 100), obj->doorsToOpen[i]->GetActorLocation() + FVector(0, 0, 100), obj->doorsToOpen[i]->debugColorCode, SDPG_World);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (creatureSpawn)
|
||||
{
|
||||
|
||||
for (int32 i = 0; i < creatureSpawn->doorsToOpen.Num(); i++)
|
||||
{
|
||||
if (creatureSpawn->doorsToOpen[i])
|
||||
PDI->DrawLine(creatureSpawn->GetActorLocation() + FVector(0, 0, 100), creatureSpawn->doorsToOpen[i]->GetActorLocation() + FVector(0, 0, 100), creatureSpawn->doorsToOpen[i]->debugColorCode, SDPG_World);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView* View) const override
|
||||
{
|
||||
FPrimitiveViewRelevance Result;
|
||||
Result.bDrawRelevance = IsSelected();
|
||||
Result.bDynamicRelevance = true;
|
||||
Result.bShadowRelevance = IsShadowCast(View);
|
||||
Result.bEditorPrimitiveRelevance = UseEditorCompositing(View);
|
||||
return Result;
|
||||
}
|
||||
|
||||
virtual uint32 GetMemoryFootprint(void) const override { return(sizeof(*this) + GetAllocatedSize()); }
|
||||
uint32 GetAllocatedSize(void) const { return(FPrimitiveSceneProxy::GetAllocatedSize()); }
|
||||
|
||||
private:
|
||||
const uint32 bDrawOnlyIfSelected : 1;
|
||||
const ANetworkDoodad* networkDoodad;
|
||||
const ACreatureSpawn* creatureSpawn;
|
||||
const FColor ShapeColor = FColor(255, 0, 0, 255);
|
||||
const FTransform transform;
|
||||
};
|
||||
|
||||
return new FDrawConeSceneProxy(this);
|
||||
}
|
||||
21
Source/UnrealProject/Doodads/NetworkSwitchComponent.h
Normal file
21
Source/UnrealProject/Doodads/NetworkSwitchComponent.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "NetworkSwitchComponent.generated.h"
|
||||
|
||||
class ANetworkSwitch;
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API UNetworkSwitchComponent : public UCapsuleComponent
|
||||
{
|
||||
GENERATED_UCLASS_BODY()
|
||||
|
||||
public:
|
||||
class ANetworkDoodad* networkDoodad;
|
||||
class ACreatureSpawn* creatureSpawn;
|
||||
|
||||
virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
|
||||
|
||||
};
|
||||
123
Source/UnrealProject/Doodads/NetworkTrigger.cpp
Normal file
123
Source/UnrealProject/Doodads/NetworkTrigger.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "NetworkDoor.h"
|
||||
#include "NetworkPlayer.h"
|
||||
#include "NetworkSwitchComponent.h"
|
||||
#include "CreatureSpawn.h"
|
||||
#include "DefaultGameMode.h"
|
||||
#include "NetworkTrigger.h"
|
||||
|
||||
|
||||
|
||||
ANetworkTrigger::ANetworkTrigger()
|
||||
{
|
||||
openMode = OpenMode::NoKeyRequired;
|
||||
cooldown = m_elapsedTime = 0.0f;
|
||||
cubeCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("Cube"));
|
||||
RootComponent = cubeCollider;
|
||||
|
||||
meshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh"));
|
||||
meshComponent->AttachTo(RootComponent);
|
||||
|
||||
visualizerComponent = CreateDefaultSubobject<UNetworkSwitchComponent>(TEXT("Visualizer"));
|
||||
visualizerComponent->AttachTo(RootComponent);
|
||||
cubeCollider->OnComponentBeginOverlap.AddDynamic(this, &ANetworkTrigger::OnOverlapBegin); // set up a notification for when this component overlaps something
|
||||
}
|
||||
|
||||
void ANetworkTrigger::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
m_elapsedTime = cooldown;
|
||||
}
|
||||
|
||||
void ANetworkTrigger::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
if (Role != ROLE_Authority)
|
||||
return;
|
||||
|
||||
if (cooldown > 0)
|
||||
m_elapsedTime += DeltaTime;
|
||||
}
|
||||
|
||||
void ANetworkTrigger::OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||
{
|
||||
if (Role != ROLE_Authority)
|
||||
return;
|
||||
|
||||
if (!(OtherActor && (OtherActor != this) && OtherComp))
|
||||
return;
|
||||
if (!OtherActor->IsA(ANetworkPlayer::StaticClass()))
|
||||
return;
|
||||
if (m_elapsedTime < cooldown)
|
||||
return;
|
||||
ANetworkPlayer* player = Cast<ANetworkPlayer>(OtherActor);
|
||||
AController* const controller = player->GetController();
|
||||
if (!controller)
|
||||
return;
|
||||
|
||||
if (openMode != OpenMode::NoKeyRequired)
|
||||
{
|
||||
if (openMode == OpenMode::TreasureRoomKey)
|
||||
{
|
||||
if (!player->HasKey(PlayerKeyType::TreasureRoomKey))
|
||||
return;
|
||||
ADefaultGameMode* gameMode = (ADefaultGameMode*)GetWorld()->GetAuthGameMode();
|
||||
gameMode->BossHasBeenKilled(player->GetTeam());
|
||||
}
|
||||
else if (openMode == OpenMode::BossRoomKeyParts)
|
||||
{
|
||||
// Check if this team has all key fragments
|
||||
ANetworkPlayer* const teamMate = player->GetTeamMate();
|
||||
int32 playerKeyCompletion = 0, requiredKeyCompletion = 0;
|
||||
for (int32 i = keyFragmentMin; i <= keyFragmentMax; i++)
|
||||
{
|
||||
const int32 lsl = (1 << i);
|
||||
requiredKeyCompletion += lsl;
|
||||
playerKeyCompletion += player->HasKey(PlayerKeyType(i)) ? lsl : 0;
|
||||
if (IsValid(teamMate))
|
||||
playerKeyCompletion |= teamMate->HasKey(PlayerKeyType(i)) ? lsl : 0;
|
||||
}
|
||||
|
||||
// Key is not complete
|
||||
if (requiredKeyCompletion != playerKeyCompletion)
|
||||
return;
|
||||
|
||||
// Remove the key fragments
|
||||
for (int32 i = keyFragmentMin; i <= keyFragmentMax; i++)
|
||||
{
|
||||
player->ClearKey(PlayerKeyType(i));
|
||||
if (IsValid(teamMate))
|
||||
teamMate->ClearKey(PlayerKeyType(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_elapsedTime = 0;
|
||||
|
||||
for (size_t i = 0; i < creaturesToSpawn.Num(); i++)
|
||||
{
|
||||
if (!creaturesToSpawn[i]->spawnContinuous)
|
||||
creaturesToSpawn[i]->SpawnMobs();
|
||||
}
|
||||
for (int32 i = 0; i < doorsToOpen.Num(); i++)
|
||||
{
|
||||
if (doorsToOpen[i])
|
||||
{
|
||||
switch (toggleMode)
|
||||
{
|
||||
case ToggleType::CloseObject:
|
||||
doorsToOpen[i]->SetDoorState(true);
|
||||
break;
|
||||
case ToggleType::OpenObject:
|
||||
doorsToOpen[i]->SetDoorState(false);
|
||||
break;
|
||||
case ToggleType::ToggleObject:
|
||||
doorsToOpen[i]->ToggleDoor();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Source/UnrealProject/Doodads/NetworkTrigger.h
Normal file
52
Source/UnrealProject/Doodads/NetworkTrigger.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "NetworkDoodad.h"
|
||||
#include "NetworkPlayer.h"
|
||||
#include "NetworkTrigger.generated.h"
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class OpenMode : uint8
|
||||
{
|
||||
NoKeyRequired = 0,
|
||||
BossRoomKeyParts = 1,
|
||||
TreasureRoomKey = 2,
|
||||
};
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API ANetworkTrigger : public ANetworkDoodad
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ANetworkTrigger();
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
TArray<class ANetworkDoor*> doorsToOpen;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
TArray<class ACreatureSpawn*> creaturesToSpawn;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
float cooldown;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
OpenMode openMode;
|
||||
|
||||
UFUNCTION()
|
||||
void OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
|
||||
virtual void Tick(float DeltaSeconds) override;
|
||||
|
||||
private:
|
||||
float m_elapsedTime;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
class UBoxComponent* cubeCollider;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
class UStaticMeshComponent* meshComponent;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
class UNetworkSwitchComponent* visualizerComponent;
|
||||
UPROPERTY(EditAnywhere, Category = "Switch Components")
|
||||
ToggleType toggleMode;
|
||||
};
|
||||
40
Source/UnrealProject/Doodads/ParticleEffect.cpp
Normal file
40
Source/UnrealProject/Doodads/ParticleEffect.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "ParticleEffect.h"
|
||||
|
||||
|
||||
AParticleEffect::AParticleEffect()
|
||||
{
|
||||
// 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;
|
||||
duration = 5.0f;
|
||||
RootComponent = particleComponent = CreateDefaultSubobject<UParticleSystemComponent>("PSys");
|
||||
followActor = nullptr;
|
||||
}
|
||||
|
||||
void AParticleEffect::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
void AParticleEffect::Tick( float DeltaTime )
|
||||
{
|
||||
Super::Tick( DeltaTime );
|
||||
duration -= DeltaTime;
|
||||
if (followActor)
|
||||
SetActorTransform(followActor->GetTransform());
|
||||
if (duration <= 0.0f)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void AParticleEffect::Init(UParticleSystem* particleSystem, float duration)
|
||||
{
|
||||
this->duration = duration;
|
||||
particleComponent->SetTemplate(particleSystem);
|
||||
particleComponent->InitializeSystem();
|
||||
}
|
||||
|
||||
29
Source/UnrealProject/Doodads/ParticleEffect.h
Normal file
29
Source/UnrealProject/Doodads/ParticleEffect.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "ParticleEffect.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API AParticleEffect : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AParticleEffect();
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
virtual void Tick( float DeltaSeconds ) override;
|
||||
|
||||
void Init(UParticleSystem* particleSystem, float duration);
|
||||
|
||||
UPROPERTY()
|
||||
UParticleSystemComponent* particleComponent;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Target")
|
||||
AActor* followActor;
|
||||
|
||||
float duration;
|
||||
|
||||
};
|
||||
37
Source/UnrealProject/Doodads/Prefs.cpp
Normal file
37
Source/UnrealProject/Doodads/Prefs.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "Prefs.h"
|
||||
|
||||
#define PREFS_SLOT_NAME TEXT("WIEBERPREFS tm")
|
||||
|
||||
UPrefs::UPrefs(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
useControllerName = "";
|
||||
|
||||
musicVolume = 1.0f;
|
||||
sfxVolume = 1.0f;
|
||||
|
||||
while (customGraphicsSettings.Num() < 6)
|
||||
customGraphicsSettings.Add(3);
|
||||
|
||||
usingCustomGraphicsSettings = false;
|
||||
}
|
||||
|
||||
UPrefs* UPrefs::Load()
|
||||
{
|
||||
UPrefs* settings = Cast<UPrefs>(UGameplayStatics::LoadGameFromSlot(PREFS_SLOT_NAME, 0));
|
||||
if (!settings)
|
||||
{
|
||||
settings = Cast<UPrefs>(UGameplayStatics::CreateSaveGameObject(UPrefs::StaticClass()));
|
||||
}
|
||||
check(settings);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
void UPrefs::Save(UPrefs* settings)
|
||||
{
|
||||
UGameplayStatics::SaveGameToSlot(settings, PREFS_SLOT_NAME, 0);
|
||||
}
|
||||
33
Source/UnrealProject/Doodads/Prefs.h
Normal file
33
Source/UnrealProject/Doodads/Prefs.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/SaveGame.h"
|
||||
#include "Prefs.generated.h"
|
||||
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API UPrefs : public USaveGame
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPrefs(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Basic")
|
||||
FString useControllerName;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Basic")
|
||||
float musicVolume;
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Basic")
|
||||
float sfxVolume;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Graphics")
|
||||
bool usingCustomGraphicsSettings;
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Graphics")
|
||||
TArray<int32> customGraphicsSettings;
|
||||
|
||||
public:
|
||||
static UPrefs* Load();
|
||||
static void Save(UPrefs* settings);
|
||||
};
|
||||
44
Source/UnrealProject/Doodads/Shrine.cpp
Normal file
44
Source/UnrealProject/Doodads/Shrine.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "NetworkGhost.h"
|
||||
#include "Shrine.h"
|
||||
|
||||
|
||||
// Sets default values
|
||||
AShrine::AShrine()
|
||||
{
|
||||
// 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;
|
||||
|
||||
displayMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
|
||||
displayMesh->bHiddenInGame = true;
|
||||
displayMesh->bGenerateOverlapEvents = false;
|
||||
displayMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||
RootComponent = displayMesh;
|
||||
|
||||
shrineTrigger = CreateDefaultSubobject<USphereComponent>(TEXT("RespawnArea"));
|
||||
shrineTrigger->SetCollisionProfileName(TEXT("GhostOverlap"));
|
||||
shrineTrigger->AttachTo(RootComponent);
|
||||
shrineTrigger->OnComponentBeginOverlap.AddDynamic(this, &AShrine::OnOverlapBegin);
|
||||
shrineTrigger->OnComponentEndOverlap.AddDynamic(this, &AShrine::OnOverlapEnd);
|
||||
shrineTrigger->SetSphereRadius(300);
|
||||
shrineTrigger->AttachTo(RootComponent);
|
||||
}
|
||||
|
||||
|
||||
void AShrine::OnOverlapBegin(AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||
{
|
||||
ANetworkGhost* ghost = Cast<ANetworkGhost>(OtherActor);
|
||||
if (!IsValid(ghost)) return;
|
||||
|
||||
ghost->shrinesInRange++;
|
||||
}
|
||||
void AShrine::OnOverlapEnd(AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
{
|
||||
ANetworkGhost* ghost = Cast<ANetworkGhost>(OtherActor);
|
||||
if (!IsValid(ghost)) return;
|
||||
|
||||
if (ghost->shrinesInRange > 0)
|
||||
ghost->shrinesInRange--;
|
||||
}
|
||||
28
Source/UnrealProject/Doodads/Shrine.h
Normal file
28
Source/UnrealProject/Doodads/Shrine.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "Shrine.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API AShrine : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
AShrine();
|
||||
|
||||
|
||||
UPROPERTY(VisibleAnywhere, Category = "Respawn")
|
||||
class UStaticMeshComponent* displayMesh;
|
||||
UPROPERTY(EditAnywhere, Category = "Respawn")
|
||||
class USphereComponent* shrineTrigger;
|
||||
|
||||
UFUNCTION()
|
||||
void OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
UFUNCTION()
|
||||
void OnOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user