1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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);
}
}
}
|