42 lines
1.3 KiB
C#
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);
|
|
} |