59 lines
1.6 KiB
C#
59 lines
1.6 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 explosion1)
|
|
{
|
|
GD.Print("Cannot instantiate");
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
if (!owner.IsInsideTree())
|
|
{
|
|
GD.Print("Not inside tree");
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
|
|
GD.Print("EXPLOSION");
|
|
|
|
explosion1.Radius = 6f;
|
|
|
|
owner.GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, explosion1);
|
|
explosion1.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()
|
|
{
|
|
if (Explosion == null)
|
|
throw new System.ArgumentException("Explosion is null");
|
|
return new ExplodingSwordBehavior(Explosion);
|
|
}
|
|
} |