package NET.worlds.scape; import NET.worlds.console.BBAnimateDroneCommand; import NET.worlds.console.BlackBox; import NET.worlds.console.Console; import NET.worlds.core.IniFile; import NET.worlds.network.ObjID; import NET.worlds.network.URL; import NET.worlds.network.WorldServer; import java.io.IOException; import java.net.MalformedURLException; import java.util.Enumeration; import java.util.Vector; public class PosableDrone extends Drone implements FrameHandler { static PosableDroneLoader droneLoader = new PosableDroneLoader(); public static boolean threadDroneLoads = IniFile.gamma().getIniInt("ThreadDroneLoading", 0) == 1; static boolean droneLoaderStarted = false; private PosableShape pendingShape = null; private static Object classCookie = new Object(); public void SetPendingShape(PosableShape ps) { this.pendingShape = ps; } @Override public boolean handle(FrameEvent evt) { if (this.pendingShape != null) { PosableShape ps = this.getInternalPosableShape(); if (ps != null) { ps.detach(); } this.add(this.pendingShape); this.pendingShape = null; } return super.handle(evt); } public PosableDrone(ObjID objID, WorldServer serv, URL url) { super(objID, serv); this.makeFigure(url); } public PosableDrone(ObjID objID, WorldServer serv) { super(objID, serv); this.loadInit(); } public PosableDrone() { } @Override public void loadInit() { this.makeFigure(PosableShape.getDefaultURL()); } public synchronized URL getPosableShapeURL() { PosableShape ps = this.getInternalPosableShape(); return ps == null ? null : ps.getURL(); } @Override public Drone setAvatarNow(URL url) { if (!this.shouldBeMuted() && (url.endsWith(".rwx") || url.endsWith(".rwg"))) { if (this.shouldBeForcedHuman()) { url = PosableShape.getHuman(url); } url = PosableShape.getPermitted(url, this.getWorld()); PosableShape ps = this.getInternalPosableShape(); if (ps != null) { if (url.equals(ps.getURL())) { return this; } ps.detach(); } this.makeFigure(url); return this; } else { return super.setAvatarNow(url); } } public void makeFigure(URL url) { boolean isPilot = false; if (Console.getActive() != null && Console.getActive().getPilot() != null && Console.getActive().getPilot().hasContents()) { isPilot = Console.getActive().getPilot().contentsContain(this); } if (!isPilot) { isPilot = this.isPilotDrone(url); } boolean loadAsynchronously = false; try { if (!PosableDroneLoader.avatarExistsLocally(url)) { loadAsynchronously = true; } else { loadAsynchronously = !isPilot && !url.toString().equals(PosableShape.getDefaultURL().toString()); } } catch (MalformedURLException var5) { loadAsynchronously = false; } if (loadAsynchronously && threadDroneLoads) { if (!droneLoaderStarted) { droneLoaderStarted = true; Thread t = new Thread(droneLoader, "DroneLoaderDaemon"); t.setDaemon(true); t.setPriority(1); t.start(); } droneLoader.load(this, url); } else { PosableShape ps; if (VehicleShape.isVehicle(url)) { ps = new VehicleShape(url); } else { ps = new PosableShape(url); } ps.setVisible(true); ps.setBumpable(false); if (!this.isPilotDrone(url)) { ps.enableLOD(true); } this.add(ps); } } public PosableShape getInternalPosableShape() { Enumeration e = this.getContents(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof PosableShape) { return (PosableShape)o; } } return null; } public boolean isPilotDrone(URL url) { return Console.getActive() != null && Console.getActive().pendingPilot.equals(url.toString()); } @Override public float animate(String action) { super.animate(action); BlackBox.getInstance().submitEvent(new BBAnimateDroneCommand(this.getName(), action)); PosableShape ps = this.getInternalPosableShape(); return ps != null ? ps.animate(action) : 0.0F; } @Override public Vector getAnimationList() { PosableShape ps = this.getInternalPosableShape(); return ps != null ? ps.getAnimationList() : super.getAnimationList(); } @Override public void saveState(Saver s) throws IOException { s.saveVersion(2, classCookie); super.saveState(s); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { int vers = r.restoreVersion(classCookie); switch (vers) { case 0: case 1: if (vers == 0) { this.restoreStateDrone(r); } else { super.restoreState(r); } r.setOldFlag(); this.makeFigure(URL.make("avatar:" + r.restoreString() + ".rwx")); break; case 2: super.restoreState(r); break; default: throw new TooNewException(); } } }