package de.steamwar.lobby.particle.elements;

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

public class Wing extends DelegatingParticleElement {

    private double size;
    private WingDesign wingDesign;

    public Wing(ParticleElement particleElement, double size, WingDesign wingDesign) {
        super(particleElement);
        this.size = size;
        this.wingDesign = wingDesign;
    }

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

    @Override
    public void tick(ParticleTickData particleTickData) {
        for (Vector dVector : wingDesign.getVectors()) {
            Vector vector = new Vector(dVector.getX() * size, 0.6 + dVector.getY() * size - (particleTickData.getPlayer().isSneaking() ? 0.5 : 0), 0.5);
            vector.rotateAroundY(Math.toRadians(particleTickData.getPlayer().getLocation().getYaw() * -1));
            vector.setX(-vector.getX());
            vector.setZ(-vector.getZ());
            Location location = particleTickData.getPlayer().getLocation().clone().add(vector);
            ParticleTickData current = particleTickData.withLocation(location);
            particleElement.tick(current);
        }
    }
}
