Advertisement
Xavion

CS Portals

Apr 20th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.89 KB | None | 0 0
  1. import june.*;
  2. import java.util.*;
  3.  
  4. public class RunPortals extends Spell
  5. {
  6.   ArrayList<Enchanted> nonTele = new ArrayList<Enchanted>();
  7.   public void cast()
  8.   {
  9.     Enchanted p1 = getByName("Area 1");            
  10.     Enchanted p2 = getByName("Area 2");
  11.     A2P(p1);
  12.     A2P(p2);
  13.  
  14.     Location p1lo = p1.getLocation();
  15.     Location p2lo = p2.getLocation();
  16.     Direction p1d = Direction.between(p1lo,p2lo);
  17.     Double p1l = p1lo.distanceBetween(p2lo);
  18.     Direction p2d = Direction.between(p2lo,p1lo);
  19.     Double p2l = p2lo.distanceBetween(p1lo);
  20.            
  21.     while (true) {
  22.       EnchantedList p1list = p1.findWithin();
  23.       EnchantedList p2list = p2.findWithin();
  24.      
  25.       runPortal(p1list, p1d, p1l);
  26.       runPortal(p2list, p2d, p2l);
  27.  
  28.       int i = 0;
  29.       int countTo = nonTele.size();
  30.       while (i < countTo) {
  31.         if (!isIn(nonTele.get(i), p1list) && !isIn(nonTele.get(i),p2list)) {
  32.           nonTele.remove(i);
  33.           countTo--;
  34.         }
  35.         i++;
  36.       }
  37.      
  38.     }
  39.   }
  40.  
  41.   public boolean isIn(Enchanted obj, ArrayList<Enchanted> objs) {
  42.     int index = 0;
  43.     for (Enchanted e : objs) {
  44.         if ((e.getId()).equals(obj.getId())) {
  45.             return true;
  46.         }
  47.         index++;
  48.     }
  49.     return false;
  50.   }
  51.  
  52.   public boolean isIn(Enchanted obj, EnchantedList objs) {
  53.     int index = 0;
  54.     for (Enchanted e : objs) {
  55.         if ((e.getId()).equals(obj.getId())) {
  56.             return true;
  57.         }
  58.         index++;
  59.     }
  60.     return false;
  61.   }
  62.  
  63.   public void runPortal(EnchantedList l, Direction d, Double ds) {
  64.     for (Enchanted e: l) {
  65.         if (!isIn(e, nonTele)) {
  66.           e.move(d, ds);
  67.           nonTele.add(e);
  68.         }
  69.       }
  70.     }
  71.  
  72.   public void A2P(Enchanted obj) {
  73.     obj.setLocation(obj.getLocation().adjust(Direction.up(),3));
  74.     flatten(obj, -0.9);
  75.     squash(obj, -0.75);
  76.     rotateZ(obj, 90);
  77.     }
  78.  
  79.   public void flatten(Enchanted obj, double amount) {
  80.     String temp = interpolateId(obj, "$target.transform.localScale = $target.transform.localScale + (new Vector3(0,"+amount+",0))");
  81.     obj.executeCommand(temp);  
  82.    }
  83.  
  84.   public void squash(Enchanted obj, double amount) {
  85.     String temp = interpolateId(obj, "$target.transform.localScale = $target.transform.localScale + (new Vector3(0,0,"+amount+"))");
  86.     obj.executeCommand(temp);  
  87.    }
  88.  
  89.    public void rotateZ(Enchanted obj, double amount) {
  90.     String temp = interpolateId(obj, "$target.transform.Rotate(new Vector3(0,0,"+amount+"))");
  91.     obj.executeCommand(temp);  
  92.    }
  93.  
  94.   public String interpolateId(Enchanted obj, String command)
  95.     {
  96.       String new_command = "";
  97.             if(command.indexOf("$target") > -1)
  98.             {
  99.                 new_command = command.replaceAll("\\$target","objects[\""+obj.getId()+"\"]");
  100.             } else {
  101.                 new_command = "objects[\""+obj.getId()+"\"]."+command+";";
  102.             }
  103.  
  104.       return new_command;
  105.   }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement