more encapsulated effect application
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Gamesmiths.Forge.Abilities;
|
using Gamesmiths.Forge.Abilities;
|
||||||
|
using Gamesmiths.Forge.Core;
|
||||||
using Gamesmiths.Forge.Cues;
|
using Gamesmiths.Forge.Cues;
|
||||||
using Gamesmiths.Forge.Effects;
|
using Gamesmiths.Forge.Effects;
|
||||||
using Gamesmiths.Forge.Effects.Components;
|
using Gamesmiths.Forge.Effects.Components;
|
||||||
@@ -71,3 +72,24 @@ public class ExplodingSwordThrowBehavior<TPayload>(Node3D owner, PackedScene? ex
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -242,9 +242,7 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
|||||||
|
|
||||||
Events.Subscribe<WeaponEventPayload>(WeaponStoppedFlyingEventTag, data =>
|
Events.Subscribe<WeaponEventPayload>(WeaponStoppedFlyingEventTag, data =>
|
||||||
{
|
{
|
||||||
GD.Print("This is removing the periodic effect to the flying weapon");
|
_weaponFlyingAbility.Cancel();
|
||||||
GD.Print(data.Payload.Message);
|
|
||||||
if (_flyingWeaponEffectHandle is { IsValid: true }) EffectsManager.RemoveEffect(_flyingWeaponEffectHandle);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private ActiveEffectHandle? _flyingWeaponEffectHandle;
|
private ActiveEffectHandle? _flyingWeaponEffectHandle;
|
||||||
@@ -266,15 +264,12 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
|||||||
abilityTags: WeaponFlyingAbilityTag.GetSingleTagContainer(),
|
abilityTags: WeaponFlyingAbilityTag.GetSingleTagContainer(),
|
||||||
instancingPolicy: AbilityInstancingPolicy.PerEntity,
|
instancingPolicy: AbilityInstancingPolicy.PerEntity,
|
||||||
abilityTriggerData: AbilityTriggerData.ForEvent<WeaponEventPayload>(WeaponStartedFlyingEventTag),
|
abilityTriggerData: AbilityTriggerData.ForEvent<WeaponEventPayload>(WeaponStartedFlyingEventTag),
|
||||||
behaviorFactory: () => new ClosureBehavior<WeaponEventPayload>((ctx, payload) =>
|
behaviorFactory: () => new FlyingSwordBehavior(this, flyingWeaponEffectData));
|
||||||
{
|
_weaponFlyingAbility = Abilities.GrantAbilityPermanently(weaponHandToFlyingAbilityData, 1, LevelComparison.None, this);
|
||||||
GD.Print("This is applying the periodic effect to the flying weapon");
|
|
||||||
GD.Print(payload.Message);
|
|
||||||
_flyingWeaponEffectHandle = EffectsManager.ApplyEffect(new Effect(flyingWeaponEffectData, new EffectOwnership(this, this)));
|
|
||||||
}));
|
|
||||||
Abilities.GrantAbilityPermanently(weaponHandToFlyingAbilityData, 1, LevelComparison.None, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AbilityHandle _weaponFlyingAbility;
|
||||||
|
|
||||||
public void GrantNewAbilityForWeaponFly(RExplodingSword ability)
|
public void GrantNewAbilityForWeaponFly(RExplodingSword ability)
|
||||||
{
|
{
|
||||||
var weaponFlyingAbilityData = new AbilityData(
|
var weaponFlyingAbilityData = new AbilityData(
|
||||||
|
|||||||
Reference in New Issue
Block a user