124 lines
4.0 KiB
C#
124 lines
4.0 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.systems;
|
|
|
|
namespace Movementtests.forge.abilities;
|
|
|
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_projectile.png")]
|
|
public partial class RExplodingSword(PackedScene? explosion, float cost, float cooldown) : RAbilityBase(cost, cooldown)
|
|
{
|
|
[Export] public PackedScene? Explosion { get; set; } = explosion;
|
|
|
|
public RExplodingSword() : this(null, 20.0f, 0.0f)
|
|
{
|
|
}
|
|
|
|
public override AbilityData Ability(TagsManager tagsManager, TagContainer? tags, Node3D owner)
|
|
{
|
|
return new AbilityData(
|
|
name: "Exploding Sword Throw",
|
|
costEffect: CostEffect(tagsManager),
|
|
cooldownEffects: [CooldownEffect(tagsManager)],
|
|
abilityTags: tags,
|
|
instancingPolicy: AbilityInstancingPolicy.PerEntity,
|
|
behaviorFactory: () => new ExplodingSwordThrowBehavior<WeaponLeftPayload>(owner, Explosion));
|
|
}
|
|
|
|
public override EffectData CostEffect(TagsManager tagsManager)
|
|
{
|
|
return new(
|
|
"Exploding Sword Throw Mana Cost",
|
|
new DurationData(DurationType.Instant),
|
|
new[]
|
|
{
|
|
new Modifier(
|
|
"PlayerAttributeSet.Mana",
|
|
ModifierOperation.FlatBonus,
|
|
new ModifierMagnitude(
|
|
MagnitudeCalculationType.ScalableFloat,
|
|
new ScalableFloat(-Cost)
|
|
)
|
|
)
|
|
},
|
|
cues: new []
|
|
{
|
|
new CueData(
|
|
CueTags: Tag.RequestTag(tagsManager, "cues.resources.mana").GetSingleTagContainer(),
|
|
MinValue: 0,
|
|
MaxValue: 100,
|
|
MagnitudeType: CueMagnitudeType.AttributeValueChange,
|
|
MagnitudeAttribute: "PlayerAttributeSet.Mana"
|
|
)
|
|
});
|
|
}
|
|
|
|
|
|
public override EffectData CooldownEffect(TagsManager tagsManager)
|
|
{
|
|
return new(
|
|
"Exploding Sword Throw Cooldown",
|
|
new DurationData(
|
|
DurationType.HasDuration,
|
|
new ModifierMagnitude(
|
|
MagnitudeCalculationType.ScalableFloat,
|
|
new ScalableFloat(Cooldown))),
|
|
effectComponents: new[]
|
|
{
|
|
new ModifierTagsEffectComponent(
|
|
tagsManager.RequestTagContainer(new[] { "cooldown.empoweredSwordThrow" })
|
|
)
|
|
});
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
GD.Print(payload);
|
|
if (_explosion?.Instantiate() is not Explosion explosion)
|
|
{
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
if (!_owner.IsInsideTree())
|
|
{
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
|
|
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)
|
|
{
|
|
}
|
|
}
|
|
|
|
public class TestBehavior<TPayload>(
|
|
Action<AbilityBehaviorContext, TPayload> callback) : IAbilityBehavior<TPayload>
|
|
{
|
|
public void OnStarted(AbilityBehaviorContext context, TPayload data)
|
|
{
|
|
callback(context, data);
|
|
context.InstanceHandle.End();
|
|
}
|
|
|
|
public void OnEnded(AbilityBehaviorContext context){}
|
|
} |