basic projectiles
This commit is contained in:
42
forge/abilities/ForgeSpawnProjectileBehavior.cs
Normal file
42
forge/abilities/ForgeSpawnProjectileBehavior.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user