57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using Gamesmiths.Forge.Abilities;
|
|
using Gamesmiths.Forge.Core;
|
|
using Gamesmiths.Forge.Godot.Nodes;
|
|
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
|
using Godot;
|
|
|
|
namespace Movementtests.forge.abilities;
|
|
|
|
public class ExplodingSwordBehavior(PackedScene explosion) : IAbilityBehavior
|
|
{
|
|
public void OnStarted(AbilityBehaviorContext context)
|
|
{
|
|
if (context.Owner is not Node3D owner)
|
|
{
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
|
|
if (explosion.Instantiate() is not Explosion explo)
|
|
{
|
|
GD.Print("Cannot instantiate");
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
if (!owner.IsInsideTree())
|
|
{
|
|
GD.Print("Not inside tree");
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
|
|
GD.Print("EXPLOSION");
|
|
|
|
explo.Radius = 6f;
|
|
|
|
owner.GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, explo);
|
|
explo.CallDeferred(Node3D.MethodName.SetGlobalPosition, owner.GlobalPosition);
|
|
|
|
context.AbilityHandle.CommitAbility();
|
|
context.InstanceHandle.End();
|
|
}
|
|
|
|
public void OnEnded(AbilityBehaviorContext context)
|
|
{
|
|
}
|
|
}
|
|
|
|
[Tool]
|
|
[GlobalClass]
|
|
public partial class ForgeExplodingSwordBehavior : ForgeAbilityBehavior
|
|
{
|
|
[Export] public PackedScene Explosion { get; set; }
|
|
public override IAbilityBehavior GetBehavior()
|
|
{
|
|
return new ExplodingSwordBehavior(Explosion);
|
|
}
|
|
} |