using Godot;
using Newlon.Components.Zombies;

namespace Newlon.Systems.Effects;

public partial class GarlicEffect : Effect
{
	[Export] private float tilesWalked = 0.2f;
	RandomNumberGenerator RandomNumberGenerator;
	
    public override void Enter(Node target)
    {
		if(RandomNumberGenerator == null)
		{
			RandomNumberGenerator = new RandomNumberGenerator();
			RandomNumberGenerator.Randomize();
		}
		if(target is RuntimeZombieData zombieData)
			zombieData.AbleToEat = false;
        //Animation call
    }

    public override void Exit(Node target)
    {
        if(target is RuntimeZombieData zombieData)
		{
			int mult;
			if((int)zombieData.GlobalPosition.Y/Utility.TileHeight <= 2)
			{
				mult = 1;
			}
			else if((int)zombieData.GlobalPosition.Y/Utility.TileHeight >= 6)
			{
				mult = -1;
			}
			else
			{
				if(RandomNumberGenerator.RandiRange(0,1) == 0)
				{
					mult = 1;
				}
				else
				{
					mult = -1;
				}
			}
			zombieData.AbleToEat = false;
			var tween = zombieData.CreateTween();
			tween.TweenProperty(zombieData,"position:y",zombieData.GlobalPosition.Y + Utility.TileHeight * mult, Duration);
			tween.Parallel().TweenProperty(zombieData, "position:x", zombieData.GlobalPosition.X - Utility.TileHeight * tilesWalked, Duration);
			tween.TweenCallback(Callable.From(() => {zombieData.AbleToEat = true;}));
		}
    }

    public override void Process(Node target)
    {

    }
}
