summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/AnimatedAction.java
blob: bb05fd08a90413b665d4ef3b50cf3e3c97b4cf8f (plain) (blame)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.console.DefaultConsole;
import NET.worlds.core.Timer;
import NET.worlds.core.TimerCallback;
import NET.worlds.network.URL;
import java.util.Vector;

public class AnimatedAction implements AnimatedActionCallback, TimerCallback {
   static final int noAction = 0;
   static final int addToInventory = 1;
   static final int removeObject = 2;
   static final int animateObject = 3;
   static final int moveObjectTo = 4;
   static final int playSound = 5;
   static final int obtainConsent = 0;
   static final int zoomOut = 1;
   static final int moveToObject = 2;
   static final int preAnimateAction = 3;
   static final int actOnObject1 = 4;
   static final int simulAnimateAction = 5;
   static final int postAnimateAction = 6;
   static final int actOnObject2 = 7;
   static final int zoomBack = 8;
   static String[] actions = new String[]{"noAction", "addToInventory", "removeObject", "animateObject", "moveObjectTo", "playSound"};
   String actionName;
   Vector avatarNames;
   Vector targetObjects;
   Shape _targetShape = null;
   boolean consentRequired;
   Point2 targetRelPosition;
   Point2 targetPosition;
   double targetRelYaw;
   float targetYaw;
   int preAnimationAction;
   String preAnimationParameter;
   String actionName1;
   int simultaneousAction;
   String simultaneousParameter;
   int postAnimationAction;
   String postAnimationParameter;
   String actionName2;
   int _oldMode;
   int _oldSpeed;
   private int _state;
   private HoloPilot _pilot;
   private float _waitTime;

   AnimatedAction() {
      this.avatarNames = new Vector();
      this.targetObjects = new Vector();
   }

   public static int getAction(String action) {
      for (int i = 0; i < actions.length; i++) {
         if (action.equals(actions[i])) {
            return i;
         }
      }

      return 0;
   }

   void setTargetShape(Shape s) {
      this._targetShape = s;
      Point3Temp objVec = Point3Temp.make(this.targetRelPosition.x, this.targetRelPosition.y, 0.0F);
      this.targetYaw = this._targetShape.getObjectToWorldMatrix().getYaw();
      Transform t = new Transform();
      t.yaw(-this.targetYaw);
      objVec.vectorTimes(t);
      t.recycle();
      Point3Temp shapePos = this._targetShape.getWorldPosition();
      objVec.plus(shapePos);
      this.targetPosition = new Point2(objVec.x, objVec.y);
   }

   public void execute(HoloPilot pilot) {
      if (this._targetShape == null) {
         System.out.println("No target shape for action " + this.actionName);
      } else {
         this._targetShape.setBumpable(false);
         this._pilot = pilot;
         this._state = 0;
         this.stateChanged();
      }
   }

   @Override
   public void motionComplete(int completionCode) {
      this._state++;
      this.stateChanged();
   }

   @Override
   public void timerDone() {
      this.motionComplete(0);
   }

   private void stateChanged() {
      switch (this._state) {
         case 0:
            this.motionComplete(0);
            break;
         case 1:
            Console c = Console.getActive();
            if (c instanceof DefaultConsole) {
               Pilot p = Pilot.getActive();
               this._oldMode = p.getOutsideCameraMode();
               this._oldSpeed = p.getOutsideCameraSpeed();
               p.setOutsideCameraMode(8, 1);
            }

            this.motionComplete(0);
            break;
         case 2:
            double newYaw = this.targetYaw + this.targetRelYaw;
            this._pilot.addCallback(this);
            this._pilot.walkTo(new Point2(this.targetPosition.x, this.targetPosition.y), (float)newYaw);
            break;
         case 3:
            this._pilot.removeSmoothDriver();
            this._pilot.returnHandsOffDriver();
            this.doAction(this.preAnimationAction, this.preAnimationParameter);
            this.motionComplete(0);
            break;
         case 4:
         case 7:
            String actionName;
            if (this._state == 4) {
               actionName = this.actionName1;
            } else {
               actionName = this.actionName2;
            }

            this._waitTime = this._pilot.animate(actionName);
            this.motionComplete(0);
            break;
         case 5:
            this.doAction(this.simultaneousAction, this.simultaneousParameter + "|sender|" + this.actionName1);
            Timer tm = new Timer(this._waitTime, this);
            tm.start();
            break;
         case 6:
            this.doAction(this.postAnimationAction, this.postAnimationParameter);
            this.motionComplete(0);
            break;
         case 8:
            c = Console.getActive();
            if (c instanceof DefaultConsole) {
               Pilot p = Pilot.getActive();
               p.setOutsideCameraMode(this._oldMode, this._oldSpeed);
            }

            this._pilot.removeHandsOffDriver();
            this._pilot.returnSmoothDriver();
            AnimatedActionManager.get().actionCompleted(this);
            this.motionComplete(0);
      }
   }

   public void abort() {
      this._state = 8;
      this.stateChanged();
   }

   private void doAction(int action, String parameter) {
      switch (action) {
         case 5:
            Sound s = new Sound(URL.make(parameter));
            this._pilot.add(s);
            s.trigger(null, null);
         case 3:
            Drone targetDrone = null;
            if (this._targetShape != null && this._targetShape instanceof PosableShape) {
               SuperRoot owner = this._targetShape.getOwner();
               if (owner instanceof Drone) {
                  targetDrone = (Drone)owner;
               }
            }

            if (targetDrone != null) {
               Pilot.sendText(targetDrone.getLongID(), "&|+action2>" + parameter);
            }

            if (this._targetShape instanceof PosableShape) {
               String actionName = null;
               int idx = parameter.indexOf("|sender|");
               if (idx != -1) {
                  actionName = parameter.substring(0, idx);
               } else {
                  actionName = parameter;
               }

               ((PosableShape)this._targetShape).animate(actionName);
            }
         case 0:
         case 1:
         case 2:
         case 4:
      }
   }
}