summaryrefslogtreecommitdiff
path: root/NET/worlds/console/BBMoveDroneCommand.java
blob: 464bd1244c39074dcfd6990cf2ebf33681e10f1e (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
package NET.worlds.console;

import NET.worlds.scape.Drone;
import NET.worlds.scape.HoloPilot;
import NET.worlds.scape.Pilot;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class BBMoveDroneCommand extends BlackBoxCommand {
   private short x;
   private short y;
   private short z;
   private short dir;
   private String droneID;

   public BBMoveDroneCommand() {
      this.commandType = 3;
   }

   public BBMoveDroneCommand(String pdroneID, short px, short py, short pz, short pdir) {
      this();
      this.droneID = pdroneID;
      this.x = px;
      this.y = py;
      this.z = pz;
      this.dir = pdir;
   }

   @Override
   public boolean execute() {
      Drone id = null;
      if (this.droneID.equals("@Pilot")) {
         Pilot p = Pilot.getActive();
         if (p != null && p instanceof HoloPilot) {
            HoloPilot hp = (HoloPilot)p;
            id = hp.getInternalDrone();
         }
      } else {
         id = ArmyOfZombies.instance().get(this.droneID);
      }

      if (id != null) {
         short _dir = this.dir;
         _dir = (short)(90 - _dir);
         _dir = (short)(360 - _dir);
         id.longLoc(this.x, this.y, this.z, _dir);
         this.doCallback(true);
         return true;
      } else {
         this.doCallback(true);
         return true;
      }
   }

   @Override
   public void save(DataOutputStream dos) throws IOException {
      super.save(dos);
      dos.writeUTF(this.droneID);
      dos.writeShort(this.x);
      dos.writeShort(this.y);
      dos.writeShort(this.z);
      dos.writeShort(this.dir);
   }

   @Override
   public void load(DataInputStream dis) throws IOException {
      super.load(dis);
      this.droneID = dis.readUTF();
      this.x = dis.readShort();
      this.y = dis.readShort();
      this.z = dis.readShort();
      this.dir = dis.readShort();
   }
}