Files
MovementTests/forge/abilities/ForgeSpawnProjectileBehavior.cs
Minimata 150e007b22
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 26s
Create tag and build when new code gets to main / Export (push) Successful in 5m9s
basic projectiles
2026-05-07 14:53:30 +02:00

42 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;
using Movementtests.interfaces;
namespace Movementtests.forge.abilities;
public class SpawnProjectileBehavior(PackedScene projectileScene) : IAbilityBehavior
{
public void OnStarted(AbilityBehaviorContext context)
{
if (context.Target is not Node3D target || context.Source is not Node3D source) return;
var sourceLocation = source.GlobalPosition;
if (projectileScene.Instantiate() is not Projectile projectile) return;
source.GetTree().GetCurrentScene().AddChild(projectile);
projectile.GlobalPosition = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : sourceLocation;
projectile.Target = target;
if (projectile is ISpawnable spawnable) spawnable.Init();
context.AbilityHandle.CommitAbility();
context.InstanceHandle.End();
}
public void OnEnded(AbilityBehaviorContext context)
{
}
}
[Tool]
[GlobalClass]
public partial class ForgeSpawnProjectileBehavior : ForgeAbilityBehavior
{
[Export] public required PackedScene Projectile { get; set; }
public override IAbilityBehavior GetBehavior() => new SpawnProjectileBehavior(Projectile);
}