new effect system
This commit is contained in:
parent
f3a6f7a05a
commit
22b02c4590
11 changed files with 146 additions and 89 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Newlon.Components;
|
||||
|
||||
namespace Newlon.Systems.Effects;
|
||||
|
||||
|
|
@ -7,7 +8,12 @@ public abstract partial class Effect : Resource
|
|||
{
|
||||
[Export] public float Duration;
|
||||
[Export] public string Slot;
|
||||
public abstract void Enter(Node target);
|
||||
public abstract void Process(Node target);
|
||||
public abstract void Exit(Node target);
|
||||
public abstract void Enter(Entity target);
|
||||
public abstract void Process(Entity target);
|
||||
public abstract void Exit(Entity target);
|
||||
|
||||
private Tween CreateTween(Entity fromEntity)
|
||||
{
|
||||
return fromEntity.CreateTweenEffect(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
48
scripts/systems/effects/EffectHandler.cs
Normal file
48
scripts/systems/effects/EffectHandler.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using Godot;
|
||||
using Newlon.Components;
|
||||
|
||||
namespace Newlon.Systems.Effects;
|
||||
|
||||
public partial class EffectHandler : RefCounted
|
||||
{
|
||||
public Entity handler;
|
||||
public Effect HandledEffect;
|
||||
public Timer EffectTimer;
|
||||
public Tween EffectTween;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
EffectTimer.WaitTime = HandledEffect.Duration;
|
||||
EffectTimer.Start();
|
||||
|
||||
HandledEffect.Enter(handler);
|
||||
}
|
||||
public void End()
|
||||
{
|
||||
HandledEffect.Exit(handler);
|
||||
HandledEffect = null;
|
||||
EffectTimer.Stop();
|
||||
if (EffectTween != null)
|
||||
{
|
||||
LON.ForceFinishTween(EffectTween);
|
||||
EffectTween.Kill();
|
||||
}
|
||||
}
|
||||
public void Process()
|
||||
{
|
||||
HandledEffect.Process(handler);
|
||||
}
|
||||
public void Restart()
|
||||
{
|
||||
HandledEffect.Exit(handler);
|
||||
EffectTimer.Stop();
|
||||
if (EffectTween != null)
|
||||
{
|
||||
LON.ForceFinishTween(EffectTween);
|
||||
EffectTween.Kill();
|
||||
}
|
||||
|
||||
HandledEffect.Enter(handler);
|
||||
EffectTimer.Start();
|
||||
}
|
||||
}
|
||||
1
scripts/systems/effects/EffectHandler.cs.uid
Normal file
1
scripts/systems/effects/EffectHandler.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://csxb8rllqjb1t
|
||||
|
|
@ -8,19 +8,16 @@ public partial class PermanentSpeedEffect : Effect
|
|||
{
|
||||
[Export] public float Multiplier;
|
||||
|
||||
public override void Enter(Node target)
|
||||
public override void Enter(Entity target)
|
||||
{
|
||||
if (target is Entity entity)
|
||||
{
|
||||
entity.LocalTimescale *= Multiplier;
|
||||
}
|
||||
target.LocalTimescale *= Multiplier;
|
||||
}
|
||||
|
||||
public override void Exit(Node target)
|
||||
public override void Exit(Entity target)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Process(Node target)
|
||||
public override void Process(Entity target)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Newlon.Components;
|
||||
using Newlon.Components.Zombies;
|
||||
|
||||
namespace Newlon.Systems.Effects;
|
||||
|
|
@ -7,9 +8,10 @@ namespace Newlon.Systems.Effects;
|
|||
public partial class RandomRedirectEffect : Effect
|
||||
{
|
||||
[Export] private float tilesWalked = 0.2f;
|
||||
[Export] private float travelTime = 1;
|
||||
RandomNumberGenerator RandomNumberGenerator;
|
||||
|
||||
public override void Enter(Node target)
|
||||
public override void Enter(Entity target)
|
||||
{
|
||||
if (RandomNumberGenerator == null)
|
||||
{
|
||||
|
|
@ -19,9 +21,14 @@ public partial class RandomRedirectEffect : Effect
|
|||
if (target is RuntimeZombieData zombieData)
|
||||
zombieData.AbleToEat = false;
|
||||
//Animation call
|
||||
Animation(target);
|
||||
}
|
||||
|
||||
public override void Exit(Node target)
|
||||
public override void Exit(Entity target)
|
||||
{
|
||||
|
||||
}
|
||||
private void Animation(Entity target)
|
||||
{
|
||||
if (target is RuntimeZombieData zombieData)
|
||||
{
|
||||
|
|
@ -46,14 +53,14 @@ public partial class RandomRedirectEffect : Effect
|
|||
}
|
||||
}
|
||||
zombieData.AbleToEat = false;
|
||||
var tween = zombieData.CreateTween();
|
||||
tween.TweenProperty(zombieData, "position:y", zombieData.GlobalPosition.Y + FieldParams.TileHeight * mult, Duration);
|
||||
tween.Parallel().TweenProperty(zombieData, "position:x", zombieData.GlobalPosition.X - FieldParams.TileHeight * tilesWalked, Duration);
|
||||
var tween = zombieData.CreateTweenEffect(this);
|
||||
tween.TweenInterval(Duration-travelTime);
|
||||
tween.TweenProperty(zombieData, "position:y", zombieData.GlobalPosition.Y + FieldParams.TileHeight * mult, travelTime);
|
||||
tween.Parallel().TweenProperty(zombieData, "position:x", zombieData.GlobalPosition.X - FieldParams.TileHeight * tilesWalked, travelTime);
|
||||
tween.TweenCallback(Callable.From(() => { zombieData.AbleToEat = true; }));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Process(Node target)
|
||||
public override void Process(Entity target)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Zombies;
|
||||
using Newlon.Components;
|
||||
|
||||
namespace Newlon.Systems.Effects;
|
||||
|
||||
|
|
@ -9,14 +10,14 @@ public partial class RedirectEffect : Effect
|
|||
[Export] private float tilesWalked = 0.2f;
|
||||
[Export] private bool down = false;
|
||||
|
||||
public override void Enter(Node target)
|
||||
public override void Enter(Entity target)
|
||||
{
|
||||
if (target is RuntimeZombieData zombieData)
|
||||
zombieData.AbleToEat = false;
|
||||
//Animation call
|
||||
}
|
||||
|
||||
public override void Exit(Node target)
|
||||
public override void Exit(Entity target)
|
||||
{
|
||||
if (target is RuntimeZombieData zombieData)
|
||||
{
|
||||
|
|
@ -48,7 +49,7 @@ public partial class RedirectEffect : Effect
|
|||
}
|
||||
}
|
||||
|
||||
public override void Process(Node target)
|
||||
public override void Process(Entity target)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,25 +9,19 @@ public partial class SlownessEffect : Effect
|
|||
[Export] public Color ColorOverride;
|
||||
[Export] public float Multiplier;
|
||||
|
||||
public override void Enter(Node target)
|
||||
public override void Enter(Entity target)
|
||||
{
|
||||
if (target is Entity entity)
|
||||
{
|
||||
entity.LocalTimescale *= Multiplier;
|
||||
entity.Modulate = ColorOverride;
|
||||
}
|
||||
target.LocalTimescale *= Multiplier;
|
||||
target.Modulate = ColorOverride;
|
||||
}
|
||||
|
||||
public override void Exit(Node target)
|
||||
public override void Exit(Entity target)
|
||||
{
|
||||
if (target is Entity entity)
|
||||
{
|
||||
entity.LocalTimescale /= Multiplier;
|
||||
entity.Modulate = Colors.White;
|
||||
}
|
||||
target.LocalTimescale /= Multiplier;
|
||||
target.Modulate = Colors.White;
|
||||
}
|
||||
|
||||
public override void Process(Node target)
|
||||
public override void Process(Entity target)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue