package de.slikey.effectlib.effect;

import de.slikey.effectlib.Effect;
import de.slikey.effectlib.EffectManager;
import de.slikey.effectlib.EffectType;
import de.slikey.effectlib.util.ParticleEffect;
import org.bukkit.Location;
import org.bukkit.util.Vector;

public class LineEffect extends Effect {

    /**
     * ParticleType of spawned particle
     */
    public ParticleEffect particle = ParticleEffect.FLAME;

    /**
     * Should it do a zig zag?
     */
    public boolean isZigZag = false;

    /**
     * Number of zig zags in the line
     */
    public int zigZags = 10;

    /**
     * Particles per arc
     */
    public int particles = 100;

    /**
     * Length of arc
     * A non-zero value here will use a length instead of the target endpoint
     */
    public int length = 0;

    /**
     * Internal boolean
     */
    protected boolean zag = false;

    /**
     * Internal counter
     */
    protected int step = 0;

    public LineEffect(EffectManager effectManager) {
        super(effectManager);
        type = EffectType.REPEATING;
        period = 1;
        iterations = 1;
    }

    @Override
    public void onRun() {
        Location location = getLocation();
        Location target = null;
        if (length > 0) {
            target = location.clone().add(location.getDirection().normalize().multiply(length));
        } else {
            target = getTarget();
        }
        double amount = particles / zigZags;
        if (target == null) {
            cancel();
            return;
        }
        Vector link = target.toVector().subtract(location.toVector());
        float length = (float) link.length();
        link.normalize();

        float ratio = length / particles;
        Vector v = link.multiply(ratio);
        Location loc = location.clone().subtract(v);
        for (int i = 0; i < particles; i++) {
            if (isZigZag) {
                if (zag) {
                    loc.add(0, .1, 0);
                } else {
                    loc.subtract(0, .1, 0);
                }
            }
            if (step >= amount) {
                if (zag) {
                    zag = false;
                } else {
                    zag = true;
                }
                step = 0;
            }
            step++;
            loc.add(v);
            display(particle, loc);
        }
    }

}

@@ -577,24 +577,124 @@
 Zags = 10;%0A%0A
+    /**%0A     * Direction of zig-zags%0A     */%0A    public Vector zigZagOffset = new Vector(0,0.1,0);%0A%0A
     /**%0A    
@@ -881,19 +881,22 @@
  public 
-int
+double
  length 
@@ -2052,24 +2052,28 @@
 loc.add(
-0, .1, 0
+zigZagOffset
 );%0A     
@@ -2129,16 +2129,20 @@
 act(
-0, .1, 0
+zigZagOffset
 );%0A 

Add zigZagOffset parameter to LineEffect, make length a double