package de.steamwar.lobby.particle.elements.custom;

import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import de.steamwar.lobby.particle.elements.DelegatingParticleElement;
import org.bukkit.util.Vector;

public class PulseShimmer extends DelegatingParticleElement {

    private int speed;
    private int rotationSpeed;

    private double x(double time) {
        if (time < 0.45) {
            return Math.pow(2, -Math.pow((time - 0.45) * 6, 2)) * 0.8;
        } else {
            return Math.pow(2, -Math.pow((time - 0.45) * 4, 2)) * 0.8;
        }
    }

    private double y(double time) {
        return (8 * Math.pow(time, 2.2) - time) / (6.5 / 3.5) -0.1;
    }

    public PulseShimmer(ParticleElement particleElement, int speed, int rotationSpeed) {
        super(particleElement);
        this.speed = speed;
        this.rotationSpeed = rotationSpeed;
    }

    @Override
    public String attribute() {
        return null;
    }

    @Override
    public void tick(ParticleTickData particleTickData) {
        double time = ((particleTickData.getDeg() * speed) % 360) / 360.0;
        double x = x(time);
        double y = y(time);
        Vector vector = new Vector(x, y, 0);
        vector.rotateAroundY((particleTickData.getDeg() * rotationSpeed) % 360);

        particleElement.tick(particleTickData.withLocation(particleTickData.getLocation().clone().add(vector)));
        vector.rotateAroundY(90);
        particleElement.tick(particleTickData.withLocation(particleTickData.getLocation().clone().add(vector)));
        vector.rotateAroundY(90);
        particleElement.tick(particleTickData.withLocation(particleTickData.getLocation().clone().add(vector)));
    }
}
