Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import june.*;
- import java.util.*;
- public class RunPortals extends Spell
- {
- ArrayList<Enchanted> nonTele = new ArrayList<Enchanted>();
- public void cast()
- {
- Enchanted p1 = getByName("Area 1");
- Enchanted p2 = getByName("Area 2");
- A2P(p1);
- A2P(p2);
- Location p1lo = p1.getLocation();
- Location p2lo = p2.getLocation();
- Direction p1d = Direction.between(p1lo,p2lo);
- Double p1l = p1lo.distanceBetween(p2lo);
- Direction p2d = Direction.between(p2lo,p1lo);
- Double p2l = p2lo.distanceBetween(p1lo);
- while (true) {
- EnchantedList p1list = p1.findWithin();
- EnchantedList p2list = p2.findWithin();
- runPortal(p1list, p1d, p1l);
- runPortal(p2list, p2d, p2l);
- int i = 0;
- int countTo = nonTele.size();
- while (i < countTo) {
- if (!isIn(nonTele.get(i), p1list) && !isIn(nonTele.get(i),p2list)) {
- nonTele.remove(i);
- countTo--;
- }
- i++;
- }
- }
- }
- public boolean isIn(Enchanted obj, ArrayList<Enchanted> objs) {
- int index = 0;
- for (Enchanted e : objs) {
- if ((e.getId()).equals(obj.getId())) {
- return true;
- }
- index++;
- }
- return false;
- }
- public boolean isIn(Enchanted obj, EnchantedList objs) {
- int index = 0;
- for (Enchanted e : objs) {
- if ((e.getId()).equals(obj.getId())) {
- return true;
- }
- index++;
- }
- return false;
- }
- public void runPortal(EnchantedList l, Direction d, Double ds) {
- for (Enchanted e: l) {
- if (!isIn(e, nonTele)) {
- e.move(d, ds);
- nonTele.add(e);
- }
- }
- }
- public void A2P(Enchanted obj) {
- obj.setLocation(obj.getLocation().adjust(Direction.up(),3));
- flatten(obj, -0.9);
- squash(obj, -0.75);
- rotateZ(obj, 90);
- }
- public void flatten(Enchanted obj, double amount) {
- String temp = interpolateId(obj, "$target.transform.localScale = $target.transform.localScale + (new Vector3(0,"+amount+",0))");
- obj.executeCommand(temp);
- }
- public void squash(Enchanted obj, double amount) {
- String temp = interpolateId(obj, "$target.transform.localScale = $target.transform.localScale + (new Vector3(0,0,"+amount+"))");
- obj.executeCommand(temp);
- }
- public void rotateZ(Enchanted obj, double amount) {
- String temp = interpolateId(obj, "$target.transform.Rotate(new Vector3(0,0,"+amount+"))");
- obj.executeCommand(temp);
- }
- public String interpolateId(Enchanted obj, String command)
- {
- String new_command = "";
- if(command.indexOf("$target") > -1)
- {
- new_command = command.replaceAll("\\$target","objects[\""+obj.getId()+"\"]");
- } else {
- new_command = "objects[\""+obj.getId()+"\"]."+command+";";
- }
- return new_command;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement