38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Gamesmiths.Forge.Abilities;
|
|
using Gamesmiths.Forge.Effects;
|
|
using Gamesmiths.Forge.Godot.Resources;
|
|
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
|
using Godot;
|
|
|
|
namespace Movementtests.forge.abilities;
|
|
|
|
public record SimpleHitEffectData(Vector3 SourceLocation, Vector3 TargetLocation);
|
|
|
|
public class SimpleHitBehavior(ForgeEffectData? damage) : IAbilityBehavior
|
|
{
|
|
public void OnStarted(AbilityBehaviorContext context)
|
|
{
|
|
if (context.Target == null || damage == null) return;
|
|
|
|
var sourceLocation = (context.Source as Node3D)?.GlobalPosition ?? Vector3.Zero;
|
|
var targetLocation = (context.Target as Node3D)?.GlobalPosition ?? Vector3.Zero;
|
|
|
|
var effect = new Effect(damage.GetEffectData(), new EffectOwnership(context.Owner, context.Owner));
|
|
context.Target.EffectsManager.ApplyEffect(effect, new SimpleHitEffectData(sourceLocation, targetLocation));
|
|
|
|
// context.InstanceHandle.End();
|
|
}
|
|
|
|
public void OnEnded(AbilityBehaviorContext context)
|
|
{
|
|
context.AbilityHandle.CommitAbility();
|
|
}
|
|
}
|
|
|
|
[Tool]
|
|
[GlobalClass]
|
|
public partial class ForgeSimpleHitBehavior : ForgeAbilityBehavior
|
|
{
|
|
[Export] public ForgeEffectData? DamageEffect { get; set; }
|
|
public override IAbilityBehavior GetBehavior() => new SimpleHitBehavior(DamageEffect);
|
|
} |