@@ -11,49 +11,117 @@ public class Npc extends Actor {
11
11
public ActorDefinition actorDefinition ;
12
12
13
13
public static void parseNpcUpdateMasks (PacketBuffer buffer ) {
14
- for (int i = 0 ; i < actorUpdatingIndex ; i ++) {
15
- int npcIndex = Player .actorUpdatingIndices [i ];
16
- Npc npc = Player .npcs [npcIndex ];
14
+ for (int i = 0 ; i < actorUpdatingIndex ; i ++) {
15
+ int npcIndex = -1 ;
16
+ Npc npc = null ;
17
+
18
+ boolean alreadyGotWorldIndex = false ;
19
+
17
20
int mask = buffer .getUnsignedByte ();
18
- if ((0x1 & mask ) != 0 ) {
21
+ if ((0x1 & mask ) != 0 ) {
19
22
int i_3_ = buffer .getUnsignedByte ();
20
23
int i_4_ = buffer .getUnsignedByte ();
24
+ int remainingHitpoints = buffer .getUnsignedByte ();
25
+ int maximumHitpoints = buffer .getUnsignedByte ();
26
+
27
+ // the NPC's worldIndex bytes won't be included if already
28
+ // sent earlier
29
+ if (!alreadyGotWorldIndex ) {
30
+ npcIndex = buffer .getUnsignedShortBE ();
31
+ npc = Player .npcs [npcIndex ];
32
+ alreadyGotWorldIndex = true ;
33
+ }
34
+
21
35
npc .method785 (i_4_ , MovedStatics .pulseCycle , i_3_ );
22
36
npc .anInt3139 = MovedStatics .pulseCycle + 300 ;
23
- npc .remainingHitpoints = buffer . getUnsignedByte () ;
24
- npc .maximumHitpoints = buffer . getUnsignedByte () ;
37
+ npc .remainingHitpoints = remainingHitpoints ;
38
+ npc .maximumHitpoints = maximumHitpoints ;
25
39
}
26
- if ((0x20 & mask ) != 0 ) {
27
- npc . graphicId = buffer .getUnsignedShortLE ();
40
+ if ((0x20 & mask ) != 0 ) {
41
+ int graphicId = buffer .getUnsignedShortLE ();
28
42
int i_5_ = buffer .getIntBE ();
43
+
44
+ // the NPC's worldIndex bytes won't be included if already
45
+ // sent earlier
46
+ if (!alreadyGotWorldIndex ) {
47
+ npcIndex = buffer .getUnsignedShortBE ();
48
+ npc = Player .npcs [npcIndex ];
49
+ alreadyGotWorldIndex = true ;
50
+ }
51
+ npc .graphicId = graphicId ;
29
52
npc .anInt3129 = 0 ;
30
53
npc .graphicDelay = MovedStatics .pulseCycle + (0xffff & i_5_ );
31
54
npc .graphicHeight = i_5_ >> 16 ;
32
55
npc .anInt3140 = 0 ;
33
- if (npc .graphicDelay > MovedStatics .pulseCycle )
56
+ if (npc .graphicDelay > MovedStatics .pulseCycle )
34
57
npc .anInt3140 = -1 ;
35
- if (npc .graphicId == 65535 )
58
+ if (npc .graphicId == 65535 )
36
59
npc .graphicId = -1 ;
37
60
}
38
- if ((mask & 0x4 ) != 0 ) {
39
- npc .facingActorIndex = buffer .getUnsignedShortBE ();
40
- if (npc .facingActorIndex == 65535 )
61
+ if ((mask & 0x4 ) != 0 ) {
62
+ int facingActorIndex = buffer .getUnsignedShortBE ();
63
+
64
+ // the NPC's worldIndex bytes won't be included if already
65
+ // sent earlier
66
+ if (!alreadyGotWorldIndex ) {
67
+ npcIndex = buffer .getUnsignedShortBE ();
68
+ npc = Player .npcs [npcIndex ];
69
+ alreadyGotWorldIndex = true ;
70
+ }
71
+
72
+ npc .facingActorIndex = facingActorIndex ;
73
+
74
+ if (npc .facingActorIndex == 65535 )
41
75
npc .facingActorIndex = -1 ;
42
76
}
43
- if ((0x2 & mask ) != 0 ) {
77
+ if ((0x2 & mask ) != 0 ) {
44
78
int i_6_ = buffer .getUnsignedByte ();
45
79
int i_7_ = buffer .getUnsignedByte ();
80
+
81
+ int remainingHitpoints = buffer .getUnsignedByte ();
82
+ int maximumHitpoints = buffer .getUnsignedByte ();
83
+
84
+ // the NPC's worldIndex bytes won't be included if already
85
+ // sent earlier
86
+ if (!alreadyGotWorldIndex ) {
87
+ npcIndex = buffer .getUnsignedShortBE ();
88
+ npc = Player .npcs [npcIndex ];
89
+ alreadyGotWorldIndex = true ;
90
+ }
91
+
46
92
npc .method785 (i_7_ , MovedStatics .pulseCycle , i_6_ );
47
93
npc .anInt3139 = MovedStatics .pulseCycle + 300 ;
48
- npc .remainingHitpoints = buffer .getUnsignedByte ();
49
- npc .maximumHitpoints = buffer .getUnsignedByte ();
94
+
95
+ npc .remainingHitpoints = remainingHitpoints ;
96
+ npc .maximumHitpoints = maximumHitpoints ;
50
97
}
51
- if ((0x40 & mask ) != 0 ) {
52
- npc .forcedChatMessage = buffer .getString ();
98
+ if ((0x40 & mask ) != 0 ) {
99
+ String forcedChatMessage = buffer .getString ();
100
+
101
+ // the NPC's worldIndex bytes won't be included if already
102
+ // sent earlier
103
+ if (!alreadyGotWorldIndex ) {
104
+ npcIndex = buffer .getUnsignedShortBE ();
105
+ npc = Player .npcs [npcIndex ];
106
+ alreadyGotWorldIndex = true ;
107
+ }
108
+
109
+ npc .forcedChatMessage = forcedChatMessage ;
110
+
53
111
npc .chatTimer = 100 ;
54
112
}
55
- if ((mask & 0x80 ) != 0 ) {
56
- npc .actorDefinition = ActorDefinition .getDefinition (buffer .getUnsignedShortBE ());
113
+ if ((mask & 0x80 ) != 0 ) {
114
+ int actorDefinition = buffer .getUnsignedShortBE ();
115
+
116
+ // the NPC's worldIndex bytes won't be included if already
117
+ // sent earlier
118
+ if (!alreadyGotWorldIndex ) {
119
+ npcIndex = buffer .getUnsignedShortBE ();
120
+ npc = Player .npcs [npcIndex ];
121
+ alreadyGotWorldIndex = true ;
122
+ }
123
+
124
+ npc .actorDefinition = ActorDefinition .getDefinition (actorDefinition );
57
125
npc .anInt3083 = npc .actorDefinition .rotateRightAnimation ;
58
126
npc .anInt3113 = npc .actorDefinition .degreesToTurn ;
59
127
npc .turnRightAnimationId = npc .actorDefinition .rotate90RightAnimation ;
@@ -64,26 +132,50 @@ public static void parseNpcUpdateMasks(PacketBuffer buffer) {
64
132
npc .turnLeftAnimationId = npc .actorDefinition .rotate90LeftAnimation ;
65
133
npc .turnAroundAnimationId = npc .actorDefinition .rotate180Animation ;
66
134
}
67
- if ((mask & 0x8 ) != 0 ) {
68
- npc .facePositionX = buffer .getUnsignedShortBE ();
69
- npc .facePositionY = buffer .getUnsignedShortLE ();
135
+ if ((mask & 0x8 ) != 0 ) {
136
+ int facePositionX = buffer .getUnsignedShortBE ();
137
+ int facePositionY = buffer .getUnsignedShortLE ();
138
+
139
+ // the NPC's worldIndex bytes won't be included if already
140
+ // sent earlier
141
+ if (!alreadyGotWorldIndex ) {
142
+ npcIndex = buffer .getUnsignedShortBE ();
143
+ npc = Player .npcs [npcIndex ];
144
+ alreadyGotWorldIndex = true ;
145
+ }
146
+
147
+ npc .facePositionX = facePositionX ;
148
+ npc .facePositionY = facePositionY ;
70
149
}
71
- if ((0x10 & mask ) != 0 ) {
150
+ if ((0x10 & mask ) != 0 ) {
72
151
int animationId = buffer .getUnsignedShortBE ();
73
- if (animationId == 65535 )
74
- animationId = -1 ;
75
152
int animationDelay = buffer .getUnsignedByte ();
76
- if (animationId == npc .playingAnimation && animationId != -1 ) {
153
+
154
+ // the NPC's worldIndex bytes won't be included if already
155
+ // sent earlier
156
+ if (!alreadyGotWorldIndex ) {
157
+ npcIndex = buffer .getUnsignedShortBE ();
158
+ npc = Player .npcs [npcIndex ];
159
+ alreadyGotWorldIndex = true ;
160
+ }
161
+
162
+ if (animationId == 65535 ) {
163
+ animationId = -1 ;
164
+ }
165
+
166
+ if (animationId == npc .playingAnimation && animationId != -1 ) {
77
167
int i_10_ = AnimationSequence .getAnimationSequence (animationId ).replyMode ;
78
- if (i_10_ == 1 ) {
168
+ if (i_10_ == 1 ) {
79
169
npc .anInt3115 = 0 ;
80
170
npc .anInt3095 = 0 ;
81
171
npc .anInt3104 = 0 ;
82
172
npc .playingAnimationDelay = animationDelay ;
83
173
}
84
- if (i_10_ == 2 )
174
+ if (i_10_ == 2 )
85
175
npc .anInt3095 = 0 ;
86
- } else if (animationId == -1 || npc .playingAnimation == -1 || AnimationSequence .getAnimationSequence (animationId ).forcedPriority >= AnimationSequence .getAnimationSequence (npc .playingAnimation ).forcedPriority ) {
176
+ } else if (animationId == -1 || npc .playingAnimation == -1
177
+ || AnimationSequence .getAnimationSequence (animationId ).forcedPriority >= AnimationSequence
178
+ .getAnimationSequence (npc .playingAnimation ).forcedPriority ) {
87
179
npc .playingAnimation = animationId ;
88
180
npc .anInt3115 = 0 ;
89
181
npc .playingAnimationDelay = animationDelay ;
0 commit comments