parrying projectiles
This commit is contained in:
@@ -1,36 +1,44 @@
|
||||
using Gamesmiths.Forge.Abilities;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Godot.Resources;
|
||||
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
||||
using Godot;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.tools;
|
||||
|
||||
namespace Movementtests.forge.abilities;
|
||||
|
||||
public record OnProjectileSpawned(Vector3 Direction, float SpeedMultiplier, Vector3? SpawnOffset = null, uint? CollisionOverride = null);
|
||||
|
||||
public class SpawnProjectileBehavior(PackedScene projectileScene) : IAbilityBehavior
|
||||
public class SpawnProjectileBehavior(PackedScene projectileScene) : IAbilityBehavior<OnProjectileSpawned>
|
||||
{
|
||||
public void OnStarted(AbilityBehaviorContext context)
|
||||
public void OnStarted(AbilityBehaviorContext context, OnProjectileSpawned data)
|
||||
{
|
||||
if (context.Target is not Node3D target || context.Source is not Node3D source)
|
||||
if (context.Source is not Node3D source || projectileScene.Instantiate() is not Projectile projectile)
|
||||
{
|
||||
context.InstanceHandle.End();
|
||||
return;
|
||||
}
|
||||
|
||||
var sourceLocation = source.GlobalPosition;
|
||||
|
||||
if (projectileScene.Instantiate() is not Projectile projectile)
|
||||
{
|
||||
context.InstanceHandle.End();
|
||||
return;
|
||||
}
|
||||
|
||||
source.GetTree().GetCurrentScene().AddChild(projectile);
|
||||
|
||||
var startPos = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : sourceLocation;
|
||||
projectile.GlobalPosition = startPos + Vector3.Up;
|
||||
source.GetTree().GetCurrentScene().AddChild(projectile);
|
||||
|
||||
// Computing projectile properties
|
||||
var offset = data.SpawnOffset ?? Vector3.Zero;
|
||||
var startPos = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : source.GlobalPosition;
|
||||
var target = context.Target as Node3D;
|
||||
var magnitude = context.Magnitude != 0 ? context.Magnitude : 1;
|
||||
var impulse = data.Direction * data.SpeedMultiplier * magnitude;
|
||||
var collisionOverride = data.CollisionOverride ?? projectile.CollisionMask;
|
||||
|
||||
GD.Print(impulse);
|
||||
|
||||
// Setting up projectile
|
||||
projectile.GlobalPosition = startPos + offset;
|
||||
projectile.Target = target;
|
||||
projectile.ImpulseDirection = impulse;
|
||||
projectile.CollisionMask = collisionOverride;
|
||||
|
||||
if (projectile is ISpawnable spawnable) spawnable.Init();
|
||||
|
||||
context.AbilityHandle.CommitAbility();
|
||||
|
||||
Reference in New Issue
Block a user