summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/WorldScriptManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/scape/WorldScriptManager.java')
-rw-r--r--NET/worlds/scape/WorldScriptManager.java164
1 files changed, 164 insertions, 0 deletions
diff --git a/NET/worlds/scape/WorldScriptManager.java b/NET/worlds/scape/WorldScriptManager.java
new file mode 100644
index 0000000..b38e832
--- /dev/null
+++ b/NET/worlds/scape/WorldScriptManager.java
@@ -0,0 +1,164 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.console.DefaultConsole;
+import NET.worlds.console.Main;
+import NET.worlds.console.MainCallback;
+import NET.worlds.console.MainTerminalCallback;
+import NET.worlds.console.RenderCanvas;
+import java.awt.PopupMenu;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class WorldScriptManager implements ActionListener, MainCallback, MainTerminalCallback {
+ private static WorldScriptManager instance = new WorldScriptManager();
+ private static WorldScriptLoader loader = new WorldScriptLoader();
+ private WorldScript currentScript = null;
+ private String lastRoom;
+
+ public static WorldScriptManager getInstance() {
+ return instance;
+ }
+
+ private WorldScriptManager() {
+ Main.register(this);
+ }
+
+ @Override
+ public void terminalCallback() {
+ if (this.currentScript != null) {
+ this.currentScript.worldExit();
+ }
+
+ this.currentScript = null;
+ Main.unregister(this);
+ }
+
+ public void worldEntered(String worldName) {
+ if (this.currentScript != null) {
+ this.currentScript.worldExit();
+ }
+
+ this.currentScript = null;
+ if (worldName != null) {
+ worldName = worldName.replace(' ', '_');
+ worldName = worldName.replace('-', '_');
+ worldName = worldName.replace('.', '_');
+ worldName = worldName.replace('/', '_');
+ worldName = worldName.replace('\\', '_');
+
+ try {
+ this.currentScript = (WorldScript)loader.loadClass("WorldScript" + worldName + ".class", true).newInstance();
+ } catch (Exception var3) {
+ System.out.println("Exception constructing world script: " + var3);
+ } catch (Error var4) {
+ System.out.println("Error constructing world script: " + var4);
+ }
+
+ if (this.currentScript != null) {
+ if (this.currentScript.getMinScriptVersion() > 15) {
+ System.out
+ .println("Script requires newer client version. script is ver. " + this.currentScript.getMinScriptVersion() + " and client has ver. " + 15);
+ this.currentScript = null;
+ } else {
+ this.currentScript.worldEnter();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void mainCallback() {
+ if (this.currentScript != null) {
+ this.currentScript.onEachFrame();
+ }
+ }
+
+ public void onPrerender(WObject obj, Camera cam) {
+ if (this.currentScript != null) {
+ Console c = Console.getActive();
+ if (c == null) {
+ return;
+ }
+
+ if (!(c instanceof DefaultConsole)) {
+ return;
+ }
+
+ DefaultConsole dc = (DefaultConsole)c;
+ RenderCanvas rc = dc.getRender();
+ if (rc == null) {
+ return;
+ }
+
+ Camera renderCam = rc.getCamera();
+ if (cam != renderCam) {
+ return;
+ }
+
+ Point3Temp p = obj.inCamSpace(cam);
+ boolean v = p != null && p.z > 1.0F && p.x < p.z && -p.x < p.z;
+ this.currentScript.objectVisibilityNotification(obj, v);
+ }
+ }
+
+ public void action(String message) {
+ if (this.currentScript != null) {
+ this.currentScript.onTriggerAction(message);
+ }
+ }
+
+ public PopupMenu shapeClicked(Shape shape) {
+ if (this.currentScript != null) {
+ SuperRoot ultimateOwner = shape;
+
+ while (ultimateOwner.getOwner() != null) {
+ ultimateOwner = ultimateOwner.getOwner();
+ if (ultimateOwner instanceof PosableShape) {
+ shape = (Shape)ultimateOwner;
+ break;
+ }
+ }
+
+ Vector v = this.currentScript.onShapeClick(shape, shape.getName());
+ if (v != null) {
+ PopupMenu m = new PopupMenu();
+ Enumeration e = v.elements();
+
+ while (e.hasMoreElements()) {
+ m.add((String)e.nextElement());
+ }
+
+ return m;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (this.currentScript != null) {
+ this.currentScript.onMenuClick(e.getActionCommand(), e.getSource());
+ }
+ }
+
+ public void roomEntered(String roomName) {
+ if (this.currentScript != null) {
+ if (this.lastRoom != null) {
+ this.currentScript.roomExit(this.lastRoom);
+ }
+
+ this.currentScript.roomEnter(roomName);
+ this.lastRoom = new String(roomName);
+ }
+ }
+
+ public void onConversation(String who, String what) {
+ if (this.currentScript != null) {
+ this.currentScript.onConversation(who, what);
+ }
+ }
+}