Skip to content

Instantly share code, notes, and snippets.

@macalinao
Created December 20, 2011 06:37
Show Gist options
  • Save macalinao/1500554 to your computer and use it in GitHub Desktop.
Save macalinao/1500554 to your computer and use it in GitHub Desktop.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.crimsonrpg.magicrpg.spell;
import com.crimsonrpg.magicrpg.MagicRPG;
import com.crimsonrpg.magicrpg.SpellInfo;
import com.crimsonrpg.magicrpg.VisualFX;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
*
* @author simplyianm
*/
@SpellInfo(id = "tornado",
name = "Tornado")
public class SpellTornado implements Spell {
private MagicRPG rpg;
public SpellTornado(MagicRPG rpg) {
this.rpg = rpg;
}
public void cast(Player caster) {
Tornado tornado = new Tornado(caster.getLocation(), 10, 20);
tornado.runFor(1000);
}
private static double lengthSq(double x, double z) {
return (x * x) + (z * z);
}
public class Tornado {
private Location center;
private int bottomRadius;
private int topRadius;
private int task = -1;
private int iterations = 0;
private int maxIterations = 0;
public Tornado(Location center, int bottomRadius, int topRadius) {
this.center = center;
this.bottomRadius = bottomRadius;
this.topRadius = topRadius;
}
public void runFor(int iterations) {
maxIterations = iterations;
start();
}
public void start() {
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(rpg, new TornadoOne(), 1L, 1L);
}
public void stop() {
if (task < 0) {
throw new IllegalStateException("Not tornadoing!");
}
Bukkit.getScheduler().cancelTask(task);
task = -1;
}
private class TornadoOne implements Runnable {
public void run() {
System.out.println("Iteration " + iterations);
if (iterations >= maxIterations) {
System.out.println("Tornado over");
stop();
return;
}
int ymin = center.getBlockY();
int ymax = 127;
int bottomRadius = 10;
int topRadius = 20;
int height = (ymax - ymin);
double slope = height / (topRadius - bottomRadius);
for (int i = 0; i < height; i++) {
int dist = (int) (i / slope);
if (iterations % 2 == 0) {
VisualFX.deploySmoke(center.add(0, i, dist), 10);
VisualFX.deploySmoke(center.add(0, i, -dist), 10);
VisualFX.deploySmoke(center.add(dist, i, 0), 10);
VisualFX.deploySmoke(center.add(-dist, i, 0), 10);
} else {
VisualFX.deploySmoke(center.add(dist, i, dist), 10);
VisualFX.deploySmoke(center.add(-dist, i, -dist), 10);
VisualFX.deploySmoke(center.add(dist, i, -dist), 10);
VisualFX.deploySmoke(center.add(-dist, i, dist), 10);
}
}
iterations++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment