84 lines
4.0 KiB
C++
84 lines
4.0 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "EleriAbilitySystemComponent.h"
|
|
#include "GameplayEffect.h"
|
|
#include "Attributes/PrimaryAttributeSet.h"
|
|
#include "ProjectEleri/System/MainBlueprintFunctionLibrary.h"
|
|
#include "ProjectEleri/Settings/EleriGameSettings.h"
|
|
|
|
|
|
|
|
void UEleriAbilitySystemComponent::AddExp(UObject* WorldContextObject, FGameplayAttribute GameplayAttribute, float Amount) {
|
|
|
|
}
|
|
|
|
void UEleriAbilitySystemComponent::AddProfessionExp(UObject* WorldContextObject, EProfessionType Profession, float Amount) {
|
|
AddExp(WorldContextObject, GetGameplayAttributeForProfession(Profession), Amount);
|
|
|
|
if (UEleriAbilitySystemComponent* ASC = UMainBlueprintFunctionLibrary::GetAbilitySystemComponentFromPlayer(WorldContextObject)) {
|
|
if (FActiveGameplayEffectHandle* ActiveEffectHandle = ASC->ProfessionModifierEffectsContainer.Find(Profession)) {
|
|
ASC->SetActiveGameplayEffectLevel(*ActiveEffectHandle, GetProfessionLevel(WorldContextObject, Profession));
|
|
}
|
|
}
|
|
}
|
|
|
|
int32 UEleriAbilitySystemComponent::GetProfessionLevel(UObject* WorldContextObject, EProfessionType Profession) {
|
|
if (UEleriAbilitySystemComponent* ASC = UMainBlueprintFunctionLibrary::GetAbilitySystemComponentFromPlayer(WorldContextObject)) {
|
|
if (const UEleriGameSettings* GameSettings = GetDefault<UEleriGameSettings>()) {
|
|
switch (Profession) {
|
|
case EProfessionType::ALCHEMY:
|
|
return GameSettings->GetProfessionLevelForExp(ASC->GetNumericAttribute(UPrimaryAttributeSet::GetAlchemyExpAttribute()));
|
|
case EProfessionType::BOTANY:
|
|
return GameSettings->GetProfessionLevelForExp(ASC->GetNumericAttribute(UPrimaryAttributeSet::GetBotanyExpAttribute()));
|
|
case EProfessionType::GATHERING:
|
|
return GameSettings->GetProfessionLevelForExp(ASC->GetNumericAttribute(UPrimaryAttributeSet::GetGatheringExpAttribute()));
|
|
case EProfessionType::FLYING:
|
|
return GameSettings->GetProfessionLevelForExp(ASC->GetNumericAttribute(UPrimaryAttributeSet::GetFlyingExpAttribute()));
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void UEleriAbilitySystemComponent::BeginPlay() {
|
|
Super::BeginPlay();
|
|
|
|
GetGameplayAttributeValueChangeDelegate(UPrimaryAttributeSet::GetEnergyAttribute()).AddUObject(this, &UEleriAbilitySystemComponent::AttributeChanged);
|
|
GetGameplayAttributeValueChangeDelegate(UPrimaryAttributeSet::GetHungerSatiationAttribute()).AddUObject(this, &UEleriAbilitySystemComponent::AttributeChanged);
|
|
GetGameplayAttributeValueChangeDelegate(UPrimaryAttributeSet::GetGatherDoubleDropChanceAttribute()).AddUObject(this, &UEleriAbilitySystemComponent::AttributeChanged);
|
|
GetGameplayAttributeValueChangeDelegate(UPrimaryAttributeSet::GetGatherHqDropChanceAttribute()).AddUObject(this, &UEleriAbilitySystemComponent::AttributeChanged);
|
|
GetGameplayAttributeValueChangeDelegate(UPrimaryAttributeSet::GetFriendPointsMultiplierAttribute()).AddUObject(this, &UEleriAbilitySystemComponent::AttributeChanged);
|
|
|
|
|
|
for (auto Effect : InitialEffects) {
|
|
BP_ApplyGameplayEffectToSelf(Effect, 1.f, MakeEffectContext());
|
|
}
|
|
for (auto ProfModEffect : ProfessionModifierEffects) {
|
|
FActiveGameplayEffectHandle EffectHandle = BP_ApplyGameplayEffectToSelf(ProfModEffect.Value, 1.f, MakeEffectContext());
|
|
ProfessionModifierEffectsContainer.Add(ProfModEffect.Key, EffectHandle);
|
|
}
|
|
}
|
|
|
|
void UEleriAbilitySystemComponent::AttributeChanged(const FOnAttributeChangeData& AttributeChangeData) {
|
|
OnAttributeChange.Broadcast(AttributeChangeData.Attribute, AttributeChangeData.NewValue, AttributeChangeData.OldValue);
|
|
}
|
|
|
|
FGameplayAttribute UEleriAbilitySystemComponent::GetGameplayAttributeForProfession(EProfessionType Profession) {
|
|
switch (Profession) {
|
|
case EProfessionType::ALCHEMY:
|
|
return UPrimaryAttributeSet::GetAlchemyExpAttribute();
|
|
case EProfessionType::BOTANY:
|
|
return UPrimaryAttributeSet::GetBotanyExpAttribute();
|
|
case EProfessionType::GATHERING:
|
|
return UPrimaryAttributeSet::GetGatheringExpAttribute();
|
|
case EProfessionType::FLYING:
|
|
return UPrimaryAttributeSet::GetFlyingExpAttribute();
|
|
default:
|
|
break;
|
|
}
|
|
return FGameplayAttribute();
|
|
}
|