Moved the exploding sword forge object from the code only hardcoded stuff to the resource based stuff
This commit is contained in:
42
forge/abilities/ForgeEffectApplicationBehavior.cs
Normal file
42
forge/abilities/ForgeEffectApplicationBehavior.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
|
||||
namespace Movementtests.forge.abilities;
|
||||
|
||||
|
||||
public class EffectApplicationBehavior(EffectData effectData) : IAbilityBehavior
|
||||
{
|
||||
private ActiveEffectHandle? _effectHandle;
|
||||
public void OnStarted(AbilityBehaviorContext context)
|
||||
{
|
||||
GD.Print("This is applying the periodic effect to the flying weapon");
|
||||
_effectHandle = context.Owner.EffectsManager.ApplyEffect(new Effect(effectData, new EffectOwnership(context.Owner, context.Owner)));
|
||||
context.AbilityHandle.CommitAbility();
|
||||
}
|
||||
|
||||
public void OnEnded(AbilityBehaviorContext context)
|
||||
{
|
||||
GD.Print("This is removing the periodic effect from the flying weapon");
|
||||
if (_effectHandle is not null)
|
||||
context.Owner.EffectsManager.RemoveEffect(_effectHandle);
|
||||
context.InstanceHandle.End();
|
||||
}
|
||||
}
|
||||
|
||||
[Tool]
|
||||
[GlobalClass]
|
||||
public partial class ForgeEffectApplicationBehavior : ForgeAbilityBehavior
|
||||
{
|
||||
[Export] public ForgeEffectData? EffectData { get; set; }
|
||||
|
||||
public override IAbilityBehavior GetBehavior()
|
||||
{
|
||||
if (EffectData == null)
|
||||
throw new System.ArgumentException("EffectData is null");
|
||||
return new EffectApplicationBehavior(EffectData.GetEffectData());
|
||||
}
|
||||
}
|
||||
1
forge/abilities/ForgeEffectApplicationBehavior.cs.uid
Normal file
1
forge/abilities/ForgeEffectApplicationBehavior.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cl5hudinl1rex
|
||||
59
forge/abilities/ForgeExplodingSwordBehavior.cs
Normal file
59
forge/abilities/ForgeExplodingSwordBehavior.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Gamesmiths.Forge.Abilities;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Godot.Nodes;
|
||||
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
||||
using Godot;
|
||||
|
||||
namespace Movementtests.forge.abilities;
|
||||
|
||||
public class ExplodingSwordBehavior(PackedScene explosion) : IAbilityBehavior
|
||||
{
|
||||
public void OnStarted(AbilityBehaviorContext context)
|
||||
{
|
||||
if (context.Owner is not Node3D owner)
|
||||
{
|
||||
context.InstanceHandle.End();
|
||||
return;
|
||||
}
|
||||
|
||||
if (explosion.Instantiate() is not Explosion explosion1)
|
||||
{
|
||||
GD.Print("Cannot instantiate");
|
||||
context.InstanceHandle.End();
|
||||
return;
|
||||
}
|
||||
if (!owner.IsInsideTree())
|
||||
{
|
||||
GD.Print("Not inside tree");
|
||||
context.InstanceHandle.End();
|
||||
return;
|
||||
}
|
||||
|
||||
GD.Print("EXPLOSION");
|
||||
|
||||
explosion1.Radius = 6f;
|
||||
|
||||
owner.GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, explosion1);
|
||||
explosion1.CallDeferred(Node3D.MethodName.SetGlobalPosition, owner.GlobalPosition);
|
||||
|
||||
context.AbilityHandle.CommitAbility();
|
||||
context.InstanceHandle.End();
|
||||
}
|
||||
|
||||
public void OnEnded(AbilityBehaviorContext context)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Tool]
|
||||
[GlobalClass]
|
||||
public partial class ForgeExplodingSwordBehavior : ForgeAbilityBehavior
|
||||
{
|
||||
[Export] public PackedScene? Explosion { get; set; }
|
||||
public override IAbilityBehavior GetBehavior()
|
||||
{
|
||||
if (Explosion == null)
|
||||
throw new System.ArgumentException("Explosion is null");
|
||||
return new ExplodingSwordBehavior(Explosion);
|
||||
}
|
||||
}
|
||||
1
forge/abilities/ForgeExplodingSwordBehavior.cs.uid
Normal file
1
forge/abilities/ForgeExplodingSwordBehavior.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bnee6amtc2bhj
|
||||
@@ -1,95 +0,0 @@
|
||||
using System;
|
||||
using Gamesmiths.Forge.Abilities;
|
||||
using Gamesmiths.Forge.Core;
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class FlyingSwordBehavior(IForgeEntity owner, EffectData effectData) : IAbilityBehavior
|
||||
{
|
||||
private ActiveEffectHandle? _effectHandle;
|
||||
public void OnStarted(AbilityBehaviorContext context)
|
||||
{
|
||||
GD.Print("This is applying the periodic effect to the flying weapon");
|
||||
_effectHandle = owner.EffectsManager.ApplyEffect(new Effect(effectData, new EffectOwnership(owner, owner)));
|
||||
context.AbilityHandle.CommitAbility();
|
||||
}
|
||||
|
||||
public void OnEnded(AbilityBehaviorContext context)
|
||||
{
|
||||
GD.Print("This is removing the periodic effect from the flying weapon");
|
||||
if (_effectHandle is not null)
|
||||
owner.EffectsManager.RemoveEffect(_effectHandle);
|
||||
context.InstanceHandle.End();
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://rux15j7q78e8
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Gamesmiths.Forge.Attributes;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Effects.Calculator;
|
||||
using Gamesmiths.Forge.Effects.Magnitudes;
|
||||
using Gamesmiths.Forge.Effects.Modifiers;
|
||||
using Gamesmiths.Forge.Events;
|
||||
using Godot;
|
||||
using Movementtests.systems;
|
||||
|
||||
namespace Movementtests.tools.calculators;
|
||||
|
||||
|
||||
public class FlyingWeaponExecution(WeaponSystem weaponSystem) : CustomExecution
|
||||
{
|
||||
public override ModifierEvaluatedData[] EvaluateExecution(Effect effect, IForgeEntity target, EffectEvaluatedData? effectEvaluatedData)
|
||||
{
|
||||
GD.Print("Custom execution executed");
|
||||
weaponSystem.Events.Raise(new EventData<WeaponEventPayload>
|
||||
{
|
||||
EventTags = weaponSystem.WeaponFlyingTickEventTag.GetSingleTagContainer()!,
|
||||
Source = weaponSystem,
|
||||
EventMagnitude = 12f,
|
||||
Payload = new WeaponEventPayload(Message: "flying")
|
||||
});
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
48
forge/calculators/ForgeRaiseEventTagExecution.cs
Normal file
48
forge/calculators/ForgeRaiseEventTagExecution.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Gamesmiths.Forge.Attributes;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Effects.Calculator;
|
||||
using Gamesmiths.Forge.Effects.Magnitudes;
|
||||
using Gamesmiths.Forge.Effects.Modifiers;
|
||||
using Gamesmiths.Forge.Events;
|
||||
using Gamesmiths.Forge.Godot.Resources;
|
||||
using Gamesmiths.Forge.Godot.Resources.Calculators;
|
||||
using Gamesmiths.Forge.Tags;
|
||||
using Godot;
|
||||
using Movementtests.systems;
|
||||
|
||||
namespace Movementtests.tools.calculators;
|
||||
|
||||
|
||||
public class FlyingWeaponExecution(TagContainer eventTags) : CustomExecution
|
||||
{
|
||||
public override ModifierEvaluatedData[] EvaluateExecution(Effect effect, IForgeEntity target, EffectEvaluatedData? effectEvaluatedData)
|
||||
{
|
||||
GD.Print("Custom execution executed");
|
||||
var owner = effect.Ownership.Owner;
|
||||
if (owner == null) return [];
|
||||
|
||||
owner.Events.Raise(new EventData
|
||||
{
|
||||
EventTags = eventTags,
|
||||
Source = owner,
|
||||
EventMagnitude = 12f
|
||||
});
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ForgeRaiseEventTagExecution : ForgeCustomExecution
|
||||
{
|
||||
[Export] ForgeTagContainer EventTags { get; set; } = new();
|
||||
|
||||
public override CustomExecution GetExecutionClass()
|
||||
{
|
||||
return new FlyingWeaponExecution(EventTags.GetTagContainer());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user