package de.steamwar.lobby.particle.elements;

import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import de.steamwar.lobby.particle.ParticleTickType;
import org.bukkit.Location;
import org.bukkit.util.Vector;

public class TrippleCircle extends Circle {

    private ParticleElement second;
    private ParticleElement third;

    private double distance;
    private double speed;

    public TrippleCircle(ParticleElement first, ParticleElement second, ParticleElement third) {
        super(first);
        this.second = second;
        this.distance = 1;
        this.speed = 1;
    }

    public TrippleCircle(ParticleElement first, ParticleElement second, ParticleElement third, double distance, double speed) {
        super(first);
        this.second = second;
        this.third = third;
        this.distance = distance;
        this.speed = speed;
    }

    @Override
    public String attribute() {
        return "PARTICLE_ATTRIBUTE_TRI_CIRCLE";
    }

    @Override
    public ParticleTickType tickType() {
        if (particleElement.tickType() == second.tickType() && particleElement.tickType() == third.tickType()) {
            return particleElement.tickType();
        }
        return ParticleTickType.MOVE;
    }

    @Override
    public void tick(ParticleTickData particleTickData) {
        Location location = particleTickData.getLocation();

        Vector vector = new Vector(distance, 0, 0);
        vector.rotateAroundY((particleTickData.getDeg() * speed) % 360);

        particleElement.tick(particleTickData.withLocation(location.clone().add(vector)));

        vector.rotateAroundY(Math.toRadians(120));
        second.tick(particleTickData.withLocation(location.clone().add(vector)));

        vector.rotateAroundY(Math.toRadians(120));
        third.tick(particleTickData.withLocation(location.clone().add(vector)));
    }
}
