73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
using System;
|
|
using Gamesmiths.Forge.Abilities;
|
|
using Gamesmiths.Forge.Cues;
|
|
using Gamesmiths.Forge.Effects;
|
|
using Gamesmiths.Forge.Effects.Components;
|
|
using Gamesmiths.Forge.Effects.Duration;
|
|
using Gamesmiths.Forge.Effects.Magnitudes;
|
|
using Gamesmiths.Forge.Effects.Modifiers;
|
|
using Gamesmiths.Forge.Tags;
|
|
using Godot;
|
|
using Movementtests.interfaces;
|
|
using Movementtests.systems;
|
|
|
|
namespace Movementtests.forge.abilities;
|
|
|
|
public record struct ExplodingSwordCreation(Node3D Owner);
|
|
|
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_projectile.png")]
|
|
public partial class RExplodingSword(PackedScene? explosion) : Resource, IAbilityBase<ExplodingSwordCreation, WeaponEventPayload>
|
|
{
|
|
[Export] public PackedScene? Explosion { get; set; } = explosion;
|
|
|
|
public RExplodingSword() : this(null) {}
|
|
|
|
public AbilityData Ability(ExplodingSwordCreation creationData, TagContainer? tags)
|
|
{
|
|
return new AbilityData(
|
|
name: "Exploding Sword Throw",
|
|
abilityTags: tags,
|
|
instancingPolicy: AbilityInstancingPolicy.PerEntity,
|
|
behaviorFactory: () => new ExplodingSwordThrowBehavior<WeaponEventPayload>(creationData.Owner, Explosion));
|
|
}
|
|
|
|
public IAbilityBehavior<WeaponEventPayload> Behavior(ExplodingSwordCreation creationData)
|
|
{
|
|
return new ExplodingSwordThrowBehavior<WeaponEventPayload>(creationData.Owner, Explosion);
|
|
}
|
|
}
|
|
|
|
public class ExplodingSwordThrowBehavior<TPayload>(Node3D owner, PackedScene? explosion) : IAbilityBehavior<TPayload>
|
|
{
|
|
private Node3D _owner = owner;
|
|
private PackedScene? _explosion = explosion;
|
|
public void OnStarted(AbilityBehaviorContext context, TPayload payload)
|
|
{
|
|
if (_explosion?.Instantiate() is not Explosion explosion)
|
|
{
|
|
GD.Print("Cannot instantiate");
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
if (!_owner.IsInsideTree())
|
|
{
|
|
GD.Print("Not inside tree");
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
|
|
GD.Print("EXPLOSION");
|
|
|
|
explosion.Radius = 6f;
|
|
|
|
_owner.GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, explosion);
|
|
explosion.CallDeferred(Node3D.MethodName.SetGlobalPosition, _owner.GlobalPosition);
|
|
|
|
context.AbilityHandle.CommitAbility();
|
|
context.InstanceHandle.End();
|
|
}
|
|
|
|
public void OnEnded(AbilityBehaviorContext context)
|
|
{
|
|
}
|
|
} |