UE5/C++ 基于GAS的角色升级 7.3.2 应用击杀敌人获得的经验值奖励

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();
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_45500363/article/details/122144665