1.
打开FightComponent,增加升级方法
public:
void UpdateLevel(AMMOARPGCharacterBase* InUpdateLevelPawn);
void UpdateLevel(float InLevel, TSubclassOf<UGameplayEffect> InNewReward);
进行实现
void UFightComponent::UpdateLevel(AMMOARPGCharacterBase* InUpdateLevelPawn)
{
if (InUpdateLevelPawn->IsUpdateLevel())
{
//升级
InUpdateLevelPawn->UpdateLevel(InUpdateLevelPawn->GetCharacterLevel() + 1);
//递归判定升级,用于连升多级
UpdateLevel(InUpdateLevelPawn);
}
}
void UFightComponent::UpdateLevel(float InLevel, TSubclassOf<UGameplayEffect> InNewReward)
{
if (AbilitySystemComponent.IsValid())
{
//检查升级效果GE必须有值
checkf(InNewReward, TEXT("This value needs to be configured in the blueprint."));
//应用升级奖励效果
AbilitySystemComponent->ApplyGameplayEffectToSelf(Cast<UGameplayEffect>(InNewReward->GetDefaultObject()),InLevel, AbilitySystemComponent->MakeEffectContext());
}
}
2.
在HandleHealth,调用UpdateLevel方法,传入要升级的对象
void UFightComponent::HandleHealth(AMMOARPGCharacterBase* InstigatorPawn, AActor* DamageCauser, const struct FGameplayTagContainer& InTags, float InNewValue)
{
if (MMOARPGCharacterBase.IsValid())
{
if (MMOARPGCharacterBase->IsDie())
{
//经验贡献和升级
InstigatorPawn->RewardEffect(MMOARPGCharacterBase->GetCharacterLevel(),MMOARPGCharacterBase->GetDeathRewardEffect(), [&]()
{
//角色升级
UpdateLevel(InstigatorPawn);
});
MMOARPGCharacterBase->PlayDie();
}
3.
升级方法内会调用CharacterBase内的升级接口,然后会再调用FightComponent内的升级接口,同时传入等级和升级效果
void AMMOARPGCharacterBase::UpdateLevel(float InLevel)
{
if (FightComponent)
{
FightComponent->UpdateLevel(InLevel, UpgradeRewardEffect);
}
}
然后应用升级效果到自身
void UFightComponent::UpdateLevel(float InLevel, TSubclassOf<UGameplayEffect> InNewReward)
{
if (AbilitySystemComponent.IsValid())
{
//检查升级效果GE必须有值
checkf(InNewReward, TEXT("This value needs to be configured in the blueprint."));
//应用升级奖励效果
AbilitySystemComponent->ApplyGameplayEffectToSelf(Cast<UGameplayEffect>(InNewReward->GetDefaultObject()),InLevel, AbilitySystemComponent->MakeEffectContext());
}
}