十七、使用生命药水回复生命值(GA_PotionHealth)

2019-06-24  本文已影响0人  珏_Gray

我们先从最简单的使用回复药Ability开始。



这个技能的具体运作分为几个阶段:


技能生效

GA_PotionHealth

GA_PotionHealth是一个data-only蓝图,它的行为逻辑在父类GA_PotionBase中定义。这里我们看它的data设置。


ClassDefault

我们注意到:

  1. 设定了技能生效时播放的动画Montage:AM_Item_Potion
  2. 在Effect Container Map中添加了一个键值对,并对相应值进行设置:
  1. 这个技能的tag为Ability.Item

从这些设置我们可以解读:这个技能的tag为Ability.Item,生效时会播放动画,并且在动画结束时发出一个tag为Event.Montage.Shared.UseItem的事件来使得GE_PotionHealth生效,这个effect的作用目标为使用者本身。

具体的行为逻辑我们参考GA_PotionBase

GA_PostionBase

通常Ability的激活入口有两个:

这里采用的是ActivateAbility。Commit Ability意味着技能的释放条件已满足,将消耗技能所需的资源来触发技能效果,这里是我们可以中断技能的最后一次机会。通常在Commit之间我们会添加Gameplay Task来完成技能生效的前置需求,如目标选取。


ActivateAbility

由于目标是施放技能者,这里我们直接Commit Ability,接着播放Montage。

Play Montage and Wait for Event
打开Montage动画资源,我们在Notifies中可以看到UseItemNS类型的Anim Notify。
Montage

打开UseItemNS蓝图,发现它就做了一件事,向mesh component的owner actor发送gameplay event。
UseItemNS

当montage发送了该事件后,GameplayTask的Event Received会触发,接着调用ApplyEffectContainer,其内部调用了ApplyGameplayEffectSpecToTarget来触发GameplayEffect。剩下的工作就是将药水从背包中移除。

GE_PotionHealth

GameplayEffect则相当简单:


GE_PotionHealth

该效果立即生效(Instant),修改值为RPGAttributeSet.Health,操作为加法(Add),数值为float,这个值为AttackDamage这张表的HeavyAttack行中读取的值乘以系数2,即预览的值600。


技能结束

在montage blend out或中断后,调用EndAbility


需要特别关注ApplyEffectContainer,我们再重温一下EffectContainer的声明:

/**
 * Struct defining a list of gameplay effects, a tag, and targeting info
 * These containers are defined statically in blueprints or assets and then turn into Specs at runtime
 */
USTRUCT(BlueprintType)
struct FRPGGameplayEffectContainer
{
    GENERATED_BODY()

public:
    FRPGGameplayEffectContainer() {}

    /** Sets the way that targeting happens */
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = GameplayEffectContainer)
    TSubclassOf<URPGTargetType> TargetType;

    /** List of gameplay effects to apply to the targets */
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = GameplayEffectContainer)
    TArray<TSubclassOf<UGameplayEffect>> TargetGameplayEffectClasses;
};
上一篇下一篇

猜你喜欢

热点阅读