diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/AnimatingDoor.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/scape/AnimatingDoor.java')
| -rw-r--r-- | NET/worlds/scape/AnimatingDoor.java | 414 |
1 files changed, 414 insertions, 0 deletions
diff --git a/NET/worlds/scape/AnimatingDoor.java b/NET/worlds/scape/AnimatingDoor.java new file mode 100644 index 0000000..9007d0b --- /dev/null +++ b/NET/worlds/scape/AnimatingDoor.java @@ -0,0 +1,414 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.core.Std; +/* */ import NET.worlds.network.URL; +/* */ import java.io.IOException; +/* */ import java.net.MalformedURLException; +/* */ import java.util.StringTokenizer; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class AnimatingDoor +/* */ extends Portal +/* */ implements FrameHandler +/* */ { +/* */ public AnimatingDoor() +/* */ { +/* 36 */ this.flags |= 0x40040; +/* */ } +/* */ +/* */ +/* 40 */ public String frameList = ""; +/* 41 */ protected transient Material[] frames = null; +/* 42 */ float perFrame = 100.0F; +/* */ +/* */ private URL openSound; +/* */ +/* */ private URL closeSound; +/* */ private transient float state; +/* */ private transient int lastUpdate; +/* */ private transient boolean wasSameRoom; +/* 50 */ private transient int lastFrame = -1; +/* */ +/* 52 */ private Point3 start = new Point3(-0.5F, -1.0F, 0.0F); +/* 53 */ private Point3 end = new Point3(1.5F, 0.0F, 1.0F); +/* */ +/* */ +/* */ +/* */ public void detach() +/* */ { +/* 59 */ if (this.frames != null) { +/* 60 */ int i = this.frames.length; +/* 61 */ do { this.frames[i].setKeepLoaded(false);i--; +/* 60 */ } while (i >= 0); +/* */ +/* 62 */ this.frames = null; +/* */ } +/* 64 */ super.detach(); +/* */ } +/* */ +/* */ public boolean handle(FrameEvent e) +/* */ { +/* 69 */ Pilot pilot = Pilot.getActive(); +/* 70 */ Room pilotRoom = pilot.getRoom(); +/* 71 */ boolean sameRoom = pilotRoom == getRoom(); +/* 72 */ boolean inRange = false; +/* 73 */ Point3Temp pos = pilot.getPosition(); +/* */ +/* 75 */ if (sameRoom) +/* */ { +/* 77 */ BoundBoxTemp bbt = BoundBoxTemp.make( +/* 78 */ Point3Temp.make(this.start).times(this), +/* 79 */ Point3Temp.make(this.end).times(this)); +/* */ +/* 81 */ inRange = bbt.contains(pos); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 92 */ Portal far = farSide(); +/* 93 */ if ((far != null) && ((far instanceof AnimatingDoor))) { +/* 94 */ AnimatingDoor afar = (AnimatingDoor)far; +/* */ +/* */ +/* 97 */ if (!inRange) { +/* 98 */ Room farRoom = afar.getRoom(); +/* 99 */ if (farRoom == null) { +/* 100 */ animate(sameRoom, inRange); +/* 101 */ return true; +/* */ } +/* */ +/* 104 */ if (afar.getRoom() == pilotRoom) { +/* 105 */ if (!sameRoom) +/* */ { +/* */ +/* 108 */ return true; +/* */ } +/* */ +/* */ +/* 112 */ BoundBoxTemp bbt = BoundBoxTemp.make( +/* 113 */ Point3Temp.make(afar.start).times(afar), +/* 114 */ Point3Temp.make(afar.end).times(afar)); +/* */ +/* 116 */ inRange = bbt.contains(pos); +/* */ } +/* */ } +/* */ +/* 120 */ afar.animate(sameRoom, inRange); +/* */ } +/* */ +/* 123 */ animate(sameRoom, inRange); +/* */ +/* 125 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ private void animate(boolean sameRoom, boolean inRange) +/* */ { +/* 133 */ int now = Std.getFastTime(); +/* 134 */ float oldState = this.state; +/* */ +/* */ +/* 137 */ if (this.frames == null) { +/* 138 */ this.frames = namesToMaterialArray(this, this.frameList); +/* 139 */ this.lastFrame = -1; +/* */ } +/* */ +/* 142 */ int numMovingFrames = this.frames.length - 2; +/* 143 */ boolean wasSameRoom = this.wasSameRoom; +/* 144 */ this.wasSameRoom = sameRoom; +/* */ +/* 146 */ if (!sameRoom) +/* */ { +/* 148 */ this.state = 0.0F; +/* 149 */ } else if (!wasSameRoom) +/* */ { +/* */ +/* */ +/* */ +/* */ +/* */ +/* 156 */ this.state = (inRange ? 1.0F : 0.0F); +/* 157 */ } else if (this.state == 0.0F) { +/* 158 */ if (!inRange) { +/* 159 */ return; +/* */ } +/* */ +/* */ +/* */ +/* 164 */ this.state = 1.0E-4F; +/* 165 */ } else if (this.state == 1.0F) { +/* 166 */ if (inRange) { +/* 167 */ return; +/* */ } +/* */ +/* 170 */ playSound(this.closeSound); +/* */ +/* 172 */ this.state = 0.999F; +/* */ } else { +/* 174 */ if ((this.state == 1.0E-4F) && (inRange)) { +/* 175 */ if (active()) +/* */ { +/* 177 */ playSound(this.openSound); +/* 178 */ this.state = 2.0E-4F; +/* */ } +/* */ else { +/* 181 */ this.lastUpdate = now; +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* 187 */ float totalTime = numMovingFrames * this.perFrame; +/* 188 */ if ((totalTime > 0.0F) && (now != this.lastUpdate)) { +/* 189 */ float distMoved = (now - this.lastUpdate) / totalTime; +/* 190 */ if (inRange) { +/* 191 */ if (this.state += distMoved >= 1.0F) { +/* 192 */ this.state = 1.0F; +/* */ } +/* 194 */ } else if (this.state -= distMoved <= 0.0F) { +/* 195 */ this.state = 0.0F; +/* */ } +/* */ } +/* */ } +/* */ +/* 200 */ if ((oldState != 0.0F) && (this.state == 0.0F)) +/* */ { +/* 202 */ this.flags |= 0x40000; +/* 203 */ reset(); +/* 204 */ } else if ((oldState == 0.0F) && (this.state != 0.0F)) +/* */ { +/* 206 */ this.flags &= 0xFFFBFFFF; +/* 207 */ reset(); +/* */ +/* */ +/* 210 */ triggerLoad(); +/* */ } +/* */ +/* 213 */ this.lastUpdate = now; +/* */ +/* */ +/* 216 */ int frame = 0; +/* */ +/* 218 */ if (numMovingFrames >= 0) { +/* 219 */ if (this.state <= 2.0E-4F) { +/* 220 */ frame = 0; +/* 221 */ } else if (this.state == 1.0F) { +/* 222 */ frame = numMovingFrames + 1; +/* */ } else +/* 224 */ frame = 1 + (int)(this.state * numMovingFrames); +/* 225 */ } else if (numMovingFrames == -2) { +/* 226 */ return; +/* */ } +/* 228 */ setFrame(frame); +/* */ } +/* */ +/* */ private void setFrame(int frame) { +/* 232 */ if ((frame != this.lastFrame) && (this.frames != null) && (this.frames.length > frame)) +/* */ { +/* 234 */ setMaterial(this.frames[frame]); +/* 235 */ this.lastFrame = frame; +/* */ } +/* */ } +/* */ +/* */ +/* */ private void playSound(URL url) +/* */ { +/* 242 */ if ((url == null) || (getRoom() != Pilot.getActive().getRoom())) { +/* 243 */ return; +/* */ } +/* 245 */ WavSoundPlayer wavPlayer = new WavSoundPlayer(null); +/* 246 */ wavPlayer.open(1.0F, 0.0F, false, false); +/* 247 */ wavPlayer.start(url); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static Material[] namesToMaterialArray(SuperRoot base, String str) +/* */ { +/* 257 */ Vector<String> v = new Vector(); +/* 258 */ StringTokenizer st = new StringTokenizer(str); +/* 259 */ while (st.hasMoreTokens()) { +/* 260 */ v.addElement(st.nextToken()); +/* */ } +/* */ +/* 263 */ int count = v.size(); +/* */ +/* 265 */ Material[] mats = new Material[count]; +/* 266 */ int i = count; +/* 267 */ do { String s = (String)v.elementAt(i); +/* */ URL url; +/* */ try { +/* 270 */ url = new URL(base, s); +/* */ } catch (MalformedURLException e) { URL url; +/* 272 */ url = URL.make("error:\"" + s + '"'); +/* */ } +/* 274 */ mats[i] = new Material(url); +/* */ +/* */ +/* */ +/* 278 */ mats[i].setKeepLoaded(true);i--; +/* 266 */ } while (i >= 0); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 281 */ return mats; +/* */ } +/* */ +/* */ +/* */ public Object properties(int index, int offset, int mode, Object value) +/* */ throws NoSuchPropertyException +/* */ { +/* 288 */ Object ret = null; +/* 289 */ switch (index - offset) { +/* */ case 0: +/* 291 */ if (mode == 0) { +/* 292 */ ret = StringPropertyEditor.make( +/* 293 */ new Property(this, index, "Frame List")); +/* 294 */ } else if (mode == 1) { +/* 295 */ ret = this.frameList; +/* 296 */ } else if (mode == 2) { +/* 297 */ this.frameList = ((String)value).toString().trim(); +/* 298 */ this.frames = null; +/* */ } +/* 300 */ break; +/* */ case 1: +/* 302 */ if (mode == 0) { +/* 303 */ ret = Point3PropertyEditor.make(new Property(this, index, +/* 304 */ "Start")); +/* 305 */ } else if (mode == 1) { +/* 306 */ ret = new Point3(this.start); +/* 307 */ } else if (mode == 2) +/* 308 */ this.start = ((Point3)value); +/* 309 */ break; +/* */ case 2: +/* 311 */ if (mode == 0) { +/* 312 */ ret = Point3PropertyEditor.make(new Property(this, index, +/* 313 */ "End")); +/* 314 */ } else if (mode == 1) { +/* 315 */ ret = new Point3(this.end); +/* 316 */ } else if (mode == 2) +/* 317 */ this.end = ((Point3)value); +/* 318 */ break; +/* */ case 3: +/* 320 */ if (mode == 0) { +/* 321 */ ret = FloatPropertyEditor.make( +/* 322 */ new Property(this, index, "Time Per Frame")); +/* 323 */ } else if (mode == 1) { +/* 324 */ ret = new Float(this.perFrame); +/* 325 */ } else if (mode == 2) +/* 326 */ this.perFrame = ((Float)value).floatValue(); +/* 327 */ break; +/* */ case 4: +/* 329 */ if (mode == 0) { +/* 330 */ ret = URLPropertyEditor.make( +/* 331 */ new Property(this, index, "Open Sound URL") +/* 332 */ .allowSetNull(), +/* 333 */ "wav;mid;ram;ra;rm"); +/* 334 */ } else if (mode == 1) { +/* 335 */ ret = this.openSound; +/* 336 */ } else if (mode == 2) +/* 337 */ this.openSound = ((URL)value); +/* 338 */ break; +/* */ case 5: +/* 340 */ if (mode == 0) { +/* 341 */ ret = URLPropertyEditor.make( +/* 342 */ new Property(this, index, "Close Sound URL") +/* 343 */ .allowSetNull(), +/* 344 */ "wav;mid;ram;ra;rm"); +/* 345 */ } else if (mode == 1) { +/* 346 */ ret = this.closeSound; +/* 347 */ } else if (mode == 2) +/* 348 */ this.closeSound = ((URL)value); +/* 349 */ break; +/* */ default: +/* 351 */ ret = super.properties(index, offset + 6, mode, value); +/* */ } +/* 353 */ return ret; +/* */ } +/* */ +/* */ +/* 357 */ private static Object classCookie = new Object(); +/* */ +/* */ public void saveState(Saver s) throws IOException +/* */ { +/* 361 */ setFrame(0); +/* */ +/* 363 */ s.saveVersion(0, classCookie); +/* 364 */ int f = this.flags; +/* 365 */ this.flags |= 0x40000; +/* 366 */ super.saveState(s); +/* 367 */ this.flags = f; +/* */ +/* 369 */ s.saveString(this.frameList); +/* 370 */ s.saveFloat(this.perFrame); +/* 371 */ s.save(this.start); +/* 372 */ s.save(this.end); +/* 373 */ URL.save(s, this.openSound); +/* 374 */ URL.save(s, this.closeSound); +/* */ } +/* */ +/* */ public void restoreState(Restorer r) throws IOException, TooNewException { +/* 378 */ switch (r.restoreVersion(classCookie)) { +/* */ case 0: +/* 380 */ super.restoreState(r); +/* 381 */ this.frameList = r.restoreString(); +/* 382 */ this.perFrame = r.restoreFloat(); +/* 383 */ this.start = ((Point3)r.restore()); +/* 384 */ this.end = ((Point3)r.restore()); +/* 385 */ this.openSound = URL.restore(r); +/* 386 */ this.closeSound = URL.restore(r); +/* 387 */ break; +/* */ +/* */ default: +/* 390 */ throw new TooNewException(); +/* */ } +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\AnimatingDoor.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |