104 lines
3.5 KiB
C#
104 lines
3.5 KiB
C#
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;
|
|
|
|
namespace Movementtests.forge.abilities;
|
|
|
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_projectile.png")]
|
|
public partial class RExplodingSwordThrow(PackedScene? explosion, float cost, float cooldown) : RAbilityBase(cost, cooldown)
|
|
{
|
|
[Export] public PackedScene? Explosion { get; set; } = explosion;
|
|
|
|
public RExplodingSwordThrow() : this(null, 20.0f, 0.0f)
|
|
{
|
|
}
|
|
|
|
public override AbilityData Ability(TagsManager tagsManager, Node3D owner)
|
|
{
|
|
return new AbilityData(
|
|
name: "Exploding Sword Throw",
|
|
costEffect: CostEffect(tagsManager),
|
|
cooldownEffects: [CooldownEffect(tagsManager)],
|
|
abilityTags: Tag.RequestTag(tagsManager, "abilities.weapon.land").GetSingleTagContainer(),
|
|
instancingPolicy: AbilityInstancingPolicy.PerEntity,
|
|
behaviorFactory: () => new ExplodingSwordThrowBehavior(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(Node3D owner, PackedScene? explosion) : IAbilityBehavior
|
|
{
|
|
private Node3D _owner = owner;
|
|
private PackedScene? _explosion = explosion;
|
|
public void OnStarted(AbilityBehaviorContext context)
|
|
{
|
|
if (_explosion?.Instantiate() is not Explosion explosion)
|
|
{
|
|
context.InstanceHandle.End();
|
|
return;
|
|
}
|
|
|
|
explosion.Radius = 10f;
|
|
_owner.GetTree().GetRoot().AddChild(explosion);
|
|
explosion.GlobalPosition = _owner.GlobalPosition;
|
|
|
|
context.AbilityHandle.CommitAbility();
|
|
context.InstanceHandle.End();
|
|
}
|
|
|
|
public void OnEnded(AbilityBehaviorContext context)
|
|
{
|
|
|
|
}
|
|
} |