Moved the exploding sword forge object from the code only hardcoded stuff to the resource based stuff
This commit is contained in:
59
forge/abilities/ForgeExplodingSwordBehavior.cs
Normal file
59
forge/abilities/ForgeExplodingSwordBehavior.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user