// Copyright Echo Devgroup #include "Character/AuraEnemy.h" #include "AuraGameplayTags.h" #include "AbilitySystem/AuraAbilitySystemComponent.h" #include "AbilitySystem/AuraAbilitySystemLibrary.h" #include "AbilitySystem/AuraAttributeSet.h" #include "Aura/Aura.h" #include "Components/WidgetComponent.h" #include "GameFramework/CharacterMovementComponent.h" #include "UI/Widget/AuraUserWidget.h" AAuraEnemy::AAuraEnemy() { GetMesh()->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); AbilitySystemComponent = CreateDefaultSubobject("AbilitySystemComponent"); AbilitySystemComponent->SetIsReplicated(true); AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Minimal); AttributeSet = CreateDefaultSubobject("AttributeSet"); HealthBar = CreateDefaultSubobject("HealthBar"); HealthBar->SetupAttachment(GetRootComponent()); } void AAuraEnemy::HighlightActor() { GetMesh()->SetRenderCustomDepth(true); GetMesh()->SetCustomDepthStencilValue(CUSTOM_DEPTH_RED); Weapon->SetRenderCustomDepth(true); Weapon->SetCustomDepthStencilValue(CUSTOM_DEPTH_RED); } void AAuraEnemy::UnHighlightActor() { GetMesh()->SetRenderCustomDepth(false); Weapon->SetRenderCustomDepth(false); } int32 AAuraEnemy::GetPlayerLevel() { return Level; } void AAuraEnemy::Die() { SetLifeSpan(LifeSpan); Super::Die(); } void AAuraEnemy::BeginPlay() { Super::BeginPlay(); GetCharacterMovement()->MaxWalkSpeed = BaseWalkSpeed; InitAbilityActorInfo(); UAuraAbilitySystemLibrary::GiveStartupAbilities(this, AbilitySystemComponent); if (UAuraUserWidget* AuraUserWidget = Cast(HealthBar->GetUserWidgetObject())) { AuraUserWidget->SetWidgetController(this); } if (const UAuraAttributeSet* AuraAS = Cast(AttributeSet)) { AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(AuraAS->GetHealthAttribute()).AddLambda( [this](const FOnAttributeChangeData& Data){ OnHealthChanged.Broadcast(Data.NewValue); } ); AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(AuraAS->GetMaxHealthAttribute()).AddLambda( [this](const FOnAttributeChangeData& Data) { OnMaxHealthChanged.Broadcast(Data.NewValue); } ); AbilitySystemComponent->RegisterGameplayTagEvent(FAuraGameplayTags::Get().Combat_HitReact, EGameplayTagEventType::NewOrRemoved).AddUObject( this, &AAuraEnemy::HitReactTagChanged ); OnHealthChanged.Broadcast(AuraAS->GetHealth()); OnMaxHealthChanged.Broadcast(AuraAS->GetMaxHealth()); } } void AAuraEnemy::HitReactTagChanged(const FGameplayTag CallbackTag, int32 NewCount) { bHitReacting = NewCount > 0; GetCharacterMovement()->MaxWalkSpeed = bHitReacting ? 0.f : BaseWalkSpeed; } void AAuraEnemy::InitAbilityActorInfo() { AbilitySystemComponent->InitAbilityActorInfo(this, this); Cast(AbilitySystemComponent)->AbilityActorInfoSet(); InitializeDefaultAttributes(); } void AAuraEnemy::InitializeDefaultAttributes() const { UAuraAbilitySystemLibrary::InitializeDefaultAttributes(this, CharacterClass, Level, AbilitySystemComponent); }