package com.skelril.aurora.items.specialattack.attacks.melee.guild.rogue;

import com.skelril.aurora.items.specialattack.EntityAttack;
import com.skelril.aurora.items.specialattack.attacks.melee.MeleeSpecial;
import com.skelril.aurora.util.ChanceUtil;
import com.skelril.aurora.util.LocationUtil;
import com.skelril.aurora.util.timer.IntegratedRunnable;
import com.skelril.aurora.util.timer.TimedRunnable;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Snowball;
import org.bukkit.metadata.FixedMetadataValue;

/**
 * Created by wyatt on 12/26/13.
 */
public class Nightmare extends EntityAttack implements MeleeSpecial {

    public Nightmare(LivingEntity owner, LivingEntity target) {
        super(owner, target);
    }

    @Override
    public void activate() {

        inform("You unleash a nightmare upon the plane.");

        final Location[] loctions = LocationUtil.getNearbyLocations(target.getLocation().add(0, 5, 0), 12);

        IntegratedRunnable hellFire = new IntegratedRunnable() {
            @Override
            public boolean run(int times) {
                for (Location location : loctions) {
                    if (ChanceUtil.getChance(6)) {
                        Snowball snowball = (Snowball) location.getWorld().spawnEntity(location, EntityType.SNOWBALL);
                        snowball.setMetadata("rogue-snowball", new FixedMetadataValue(inst, true));
                        snowball.setMetadata("nightmare", new FixedMetadataValue(inst, true));
                        snowball.setShooter(owner);
                    }
                }
                return true;
            }

            @Override
            public void end() {
                inform("Your nightmare fades away...");
            }
        };

        TimedRunnable runnable = new TimedRunnable(hellFire, 40);
        runnable.setTask(server.getScheduler().runTaskTimer(inst, runnable, 50, 10));
    }
}

@@ -249,53 +249,8 @@
 il;%0A
-import com.skelril.aurora.util.LocationUtil;%0A
 impo
@@ -298,24 +298,24 @@
 edRunnable;%0A
+
 import com.s
@@ -541,16 +541,90 @@
 Value;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Random;%0Aimport java.util.Set;%0A%0A
 /**%0A * C
@@ -723,24 +723,47 @@
 eSpecial %7B%0A%0A
+    private Random r;%0A%0A
     public N
@@ -844,16 +844,68 @@
 arget);%0A
+        r = new Random(System.currentTimeMillis());%0A
     %7D%0A%0A 
@@ -1021,24 +1021,28 @@
   final 
+Set%3C
 Location
 %5B%5D locti
@@ -1037,22 +1037,22 @@
 tion
-%5B%5D
+%3E
  loc
+a
 tions = 
 Loca
@@ -1051,79 +1051,445 @@
 s = 
-LocationUtil.getNearbyLocations(target.getL
+new HashSet%3C%3E();%0A%0A        Location origin = target.getLocation().add(0, 5, 0);%0A%0A        for (int i = 0; i %3C 100; i++) %7B%0A%0A            double angle = r.nextDouble() * Math.PI * 2;%0A            double radius = r.nextDouble() * 12;%0A%0A            Location pt = origin.clone();%0A            pt.setX(origin.getX() + radius * Math.cos(angle));%0A            pt.setZ(origin.getZ() + radius * Math.sin(angle));%0A%0A            l
 ocation
-()
+s
 .add(
-0, 5, 0), 12);
+pt);%0A        %7D
 %0A%0A  
@@ -1661,16 +1661,17 @@
 on : loc
+a
 tions) %7B
@@ -1716,17 +1716,17 @@
 tChance(
-6
+3
 )) %7B%0A   

Use real random location calculations for the Rogue nightmare