/* */ package NET.worlds.scape; /* */ /* */ import java.io.DataInputStream; /* */ import java.io.DataOutputStream; /* */ import java.io.IOException; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class RollingAttribute /* */ extends Attribute /* */ { /* 26 */ RollBehavior rb = new RollBehavior(); /* */ /* */ /* */ /* */ /* 31 */ public float initialKickVel = 200.0F; /* */ /* */ public RollingAttribute(int attrID) { /* 34 */ super(attrID); /* 35 */ this.rb.linearDamp = 0.95F; /* 36 */ this.rb.rollFactor = 1.0F; /* 37 */ this.rb.setNotifyAttribute(this); /* */ } /* */ /* */ public RollingAttribute() /* */ { /* 42 */ this.rb.linearDamp = 0.8F; /* 43 */ this.rb.setNotifyAttribute(this); /* */ } /* */ /* */ /* 47 */ private Point3 kp = new Point3(); /* 48 */ private float kv = 0.0F; /* 49 */ private Point3 kd = new Point3(); /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void set(Point3Temp p, float v, Point3Temp d) /* */ { /* 59 */ if ((this.kp.x == p.x) && (this.kp.y == p.y) && (this.kp.x == p.z)) { /* 60 */ return; /* */ } /* 62 */ this.kp.x = p.x; /* 63 */ this.kp.y = p.y; /* 64 */ this.kp.z = p.z; /* 65 */ this.kv = v; /* 66 */ this.kd.x = d.x; /* 67 */ this.kd.y = d.y; /* 68 */ this.kd.z = d.z; /* */ /* 70 */ ((WObject)getOwner().getOwner()).moveTo(this.kp); /* 71 */ this.rb.linearVel = this.kv; /* 72 */ this.rb.setDir(this.kd); /* */ /* 74 */ noteChange(); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void notifyStopped() /* */ { /* 84 */ WObject ball = (WObject)((Sharer)getOwner()).getOwner(); /* 85 */ Point3Temp pos = ball.getPosition(); /* */ /* 87 */ set(pos, 0.0F, Point3Temp.make(0.0F, 0.0F, 0.0F)); /* */ } /* */ /* */ /* */ /* */ public void get(Point3Temp p, float v, Point3Temp d) /* */ { /* 94 */ p.x = this.kp.x; /* 95 */ p.y = this.kp.y; /* 96 */ p.z = this.kp.z; /* 97 */ v = this.kv; /* 98 */ d.x = this.kd.x; /* 99 */ d.y = this.kd.y; /* 100 */ d.z = this.kd.z; /* */ } /* */ /* */ protected void noteAddingTo(SuperRoot owner) /* */ { /* 105 */ WObject parent = (WObject)owner.getOwner(); /* 106 */ parent.addHandler(this.rb); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public boolean handle(BumpEventTemp b) /* */ { /* 130 */ if ((b.target != b.receiver) || /* 131 */ (this.rb.linearVel > 0.0F)) /* */ { /* */ /* 134 */ if ((b.target instanceof Camera)) /* */ { /* */ /* 137 */ double dx = this.rb.dir.x; /* 138 */ double dy = this.rb.dir.y; /* 139 */ Math.atan2(dx, dy); /* */ /* 141 */ double theta = dy + 60.0D * Math.random() - 30.0D; /* 142 */ double r = dx; /* 143 */ dx = r * Math.cos(theta * 3.141592653589793D / 180.0D); /* 144 */ dy = r * Math.sin(theta * 3.141592653589793D / 180.0D); /* */ /* 146 */ this.rb.dir.x = ((float)dx); /* 147 */ this.rb.dir.y = ((float)dy); /* */ } /* 149 */ this.rb.processBumpEvent(b); /* */ /* */ /* */ /* */ /* */ /* */ /* 156 */ if (((b.target instanceof Camera)) || ((b.source instanceof Camera))) { /* 157 */ Point3Temp pos = ((WObject)((Sharer)getOwner()).getOwner()) /* 158 */ .getWorldPosition(); /* 159 */ set(pos, this.rb.linearVel, this.rb.dir); /* */ } /* */ } /* 162 */ else if (this.rb.linearVel == 0.0F) /* */ { /* */ /* 165 */ Point3Temp pos = b.target.getWorldPosition(); /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 175 */ WObject kicker = (WObject)b.source; /* 176 */ float alpha = kicker.getYaw(); /* 177 */ Point3Temp kpos = kicker.getWorldPosition(); /* 178 */ double dx = kpos.x - pos.x; /* 179 */ double dy = kpos.y - pos.y; /* 180 */ Math.atan2(dx, dy); /* */ /* */ /* */ /* 184 */ float kickang = (float)((360.0F - alpha + 90.0F) * 3.141592653589793D / 180.0D); /* */ /* 186 */ Point3Temp kickdir = Point3Temp.make((float)Math.cos(kickang), /* 187 */ (float)Math.sin(kickang), 0.0F); /* */ /* */ /* */ /* 191 */ pos.x += kickdir.x; /* 192 */ pos.y += kickdir.y; /* */ /* */ /* 195 */ set(pos, this.initialKickVel, kickdir); /* */ } /* */ /* 198 */ return true; /* */ } /* */ /* */ public void generateNetData(DataOutputStream s) throws IOException /* */ { /* 203 */ s.writeFloat(this.kp.x); /* 204 */ s.writeFloat(this.kp.y); /* 205 */ s.writeFloat(this.kp.z); /* 206 */ s.writeFloat(this.kv); /* 207 */ s.writeFloat(this.kd.x); /* 208 */ s.writeFloat(this.kd.y); /* 209 */ s.writeFloat(this.kd.z); /* */ } /* */ /* */ public void setFromNetData(DataInputStream ds, int len) throws IOException /* */ { /* 214 */ Point3Temp pos = Point3Temp.make(); /* 215 */ float vel = 0.0F; /* 216 */ Point3Temp dir = Point3Temp.make(); /* */ /* 218 */ pos.x = ds.readFloat(); /* 219 */ pos.y = ds.readFloat(); /* 220 */ pos.z = ds.readFloat(); /* 221 */ vel = ds.readFloat(); /* 222 */ dir.x = ds.readFloat(); /* 223 */ dir.y = ds.readFloat(); /* 224 */ dir.z = ds.readFloat(); /* 225 */ set(pos, vel, dir); /* */ } /* */ /* */ /* */ /* */ /* */ public Object properties(int index, int offset, int mode, Object value) /* */ throws NoSuchPropertyException /* */ { /* 234 */ Object ret = null; /* 235 */ switch (index - offset) { /* */ case 0: /* 237 */ if (mode == 0) { /* 238 */ ret = FloatPropertyEditor.make(new Property(this, index, /* 239 */ "Roll Factor")); /* 240 */ } else if (mode == 1) { /* 241 */ ret = new Float(this.rb.rollFactor); /* 242 */ } else if (mode == 2) /* 243 */ this.rb.rollFactor = ((Float)value).floatValue(); /* 244 */ break; /* */ case 1: /* 246 */ if (mode == 0) { /* 247 */ ret = FloatPropertyEditor.make(new Property(this, index, /* 248 */ "Initial Kick Velocity")); /* 249 */ } else if (mode == 1) { /* 250 */ ret = new Float(this.initialKickVel); /* 251 */ } else if (mode == 2) /* 252 */ this.initialKickVel = ((Float)value).floatValue(); /* 253 */ break; /* */ default: /* 255 */ ret = super.properties(index, offset + 2, mode, value); /* */ } /* 257 */ return ret; /* */ } /* */ /* */ /* 261 */ private static Object classCookie = new Object(); /* */ /* */ public void saveState(Saver s) throws IOException /* */ { /* 265 */ s.saveVersion(1, classCookie); /* 266 */ super.saveState(s); /* */ /* 268 */ s.saveFloat(this.initialKickVel); /* 269 */ s.saveFloat(this.rb.rollFactor); /* */ } /* */ /* */ public void restoreState(Restorer r) throws IOException, TooNewException { /* */ float threshold; /* 274 */ switch (r.restoreVersion(classCookie)) { /* */ case 0: /* 276 */ super.restoreState(r); /* 277 */ this.initialKickVel = r.restoreFloat(); /* 278 */ threshold = r.restoreFloat(); /* 279 */ break; /* */ case 1: /* 281 */ super.restoreState(r); /* 282 */ this.initialKickVel = r.restoreFloat(); /* 283 */ this.rb.rollFactor = r.restoreFloat(); /* 284 */ break; /* */ default: /* 286 */ throw new TooNewException(); /* */ } /* */ } /* */ /* */ public String toString() /* */ { /* 292 */ return /* 293 */ super.toString() + " [From " + this.kp + " with velocity " + this.kv + " toward " + this.kd + "] "; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\RollingAttribute.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */