1
打开FightComponent,HandleHealth中,调用RewardEffect方法
void UFightComponent::HandleHealth(AMMOARPGCharacterBase* InstigatorPawn, AActor* DamageCauser, const struct FGameplayTagContainer& InTags, float InNewValue)
{
if (MMOARPGCharacterBase.IsValid())
{
if (MMOARPGCharacterBase->IsDie())
{
//调用RewardEffect方法,应用击杀经验值奖励
InstigatorPawn->RewardEffect(MMOARPGCharacterBase->GetCharacterLevel(),MMOARPGCharacterBase->GetDeathRewardEffect(), [&]()
{
});
//播放死亡动画
MMOARPGCharacterBase->PlayDie();
}
else
{
if (InstigatorPawn)
{
if (MMOARPGCharacterBase->GetHitID() != INDEX_NONE)
{
//转向攻击者
FRotator TargetRot = (-InstigatorPawn->GetActorForwardVector()).ToOrientationRotator();
MMOARPGCharacterBase->SetActorRotation(TargetRot);
///播放受击
MMOARPGCharacterBase->PlayHit();
}
}
}
}
}
RewardEffect方法,应用GE效果到自身
void UFightComponent::RewardEffect(float InNewLevel, TSubclassOf<UGameplayEffect> InNewReward, TFunction<void()> InFun)
{
if (AbilitySystemComponent.IsValid())
{
checkf(InNewReward, TEXT("This value needs to be configured in the blueprint."));
//应用击杀经验值奖励效果
AbilitySystemComponent->ApplyGameplayEffectToSelf(Cast<UGameplayEffect>(InNewReward->GetDefaultObject()),InNewLevel, AbilitySystemComponent->MakeEffectContext());
InFun();
}
}