Ticket #45: BallPosition.java

File BallPosition.java, 3.7 kB (added by Maverick, 8 months ago)

Modified BallPosition packet, should be placed in package twcore.core.events.

Line 
1 package twcore.core.events;
2
3 import twcore.core.util.ByteArray;
4
5 /**
6  * (S2C 0x2E) Event fired when a player picks up a ball and periodically as
7  * the ball moves/changes position.<code><pre>
8  *
9  * +-------------------------+
10  * |Offset Length Description|
11  * +-------------------------+
12  * |0        1    Type Byte  |
13  * |1        1    Ball ID    |
14  * |2        2    X location |
15  * |4        2    Y location |
16  * |6        2    X Velocity |
17  * |8        2    Y Velocity |
18  * |10       2    Player ID  |
19  * |12       4    Timestamp  |
20  * +-------------------------+</code></pre>
21  *
22  * NOTE: The timestamp variable doesn't seem to be the timestamp you expect it to be,
23  * it's probably the timestamp difference with the current timestamp (ms).
24  * The timestamp on the packet is 0 if the ball is carried, it's negative once shot -
25  * I don't know exactly what this means.
26  */
27 public class BallPosition extends SubspaceEvent {
28
29     private byte m_ballID;     // ID of the ball picked up
30     private short m_xLocation; // X location of the ball
31     private short m_yLocation; // Y location of the ball
32     private short m_xVelocity; // X velocity of the ball
33     private short m_yVelocity; // Y velocity of the ball
34     private short m_playerID;  // ID of the player who picked up/has the ball
35     private int m_timeStamp;   // Time stamp of the ball
36    
37     private short carrier;      // TWCore specific variable containing the playerid currently carrying the ball
38                                 // -1 if not carried
39
40     /**
41          * Creates a new instance of BallPosition; this is called by
42          * GamePacketInterpreter when it receives the packet.
43          * @param array the ByteArray containing the packet data
44          */
45     public BallPosition( ByteArray array ) {
46         m_ballID = array.readByte( 1 );
47         m_xLocation = array.readLittleEndianShort( 2 );
48         m_yLocation = array.readLittleEndianShort( 4 );
49         m_xVelocity = array.readLittleEndianShort( 6 );
50         m_yVelocity = array.readLittleEndianShort( 8 );
51         m_playerID = array.readLittleEndianShort( 10 );
52         m_timeStamp = array.readInt( 12 );
53        
54         if(m_timeStamp == 0) {
55             // Ball is being carried
56             carrier = m_playerID;
57         } else {
58             // Ball isn't being carried
59             carrier = -1;
60         }
61     }
62
63     /**
64      * Gets the ID of the ball.
65      * @return BallID
66      */
67     public byte getBallID() {
68         return m_ballID;
69     }
70
71     /**
72      * Gets the X location of the ball.
73      * @return Xlocation
74      */
75     public short getXLocation() {
76         return m_xLocation;
77     }
78
79     /**
80      * Gets the Y location of the ball.
81      * @return Ylocation
82      */
83     public short getYLocation() {
84         return m_yLocation;
85     }
86
87     /**
88      * Gets the X velocity of the ball.
89      * @return Xvelocity
90      */
91     public short getXVelocity() {
92         return m_xVelocity;
93     }
94
95     /**
96      * Gets the Y velocity of the ball.
97      * @return Yvelocity
98      */
99     public short getYVelocity() {
100         return m_yVelocity;
101     }
102
103     /**
104      * Gets the ID of the player who picked up the ball, if a player currently has the ball.
105      * @return PlayerID
106      */
107     public short getPlayerID() {
108         return m_playerID;
109     }
110
111     /**
112      * Gets the Time Stamp of the ball.
113      * @return TimeStamp
114      */
115     public int getTimeStamp() {
116         return m_timeStamp;
117     }
118
119    
120     /**
121      * Gets the carrier of the ball (PlayerID) (TWCore specific variable), -1 if not carried.
122      * @return the carrier
123      */
124     public short getCarrier() {
125         return carrier;
126     }
127 }