Files
MovementTests/forge/abilities/ForgeExplodingSwordBehavior.cs
Minimata 7a787a36d6
Some checks failed
Create tag and build when new code gets to main / BumpTag (push) Successful in 24s
Create tag and build when new code gets to main / Export (push) Failing after 3m55s
Moved the exploding sword forge object from the code only hardcoded stuff to the resource based stuff
2026-04-04 12:06:48 +02:00

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);
}
}