@@ -11,49 +11,117 @@ public class Npc extends Actor {
1111 public ActorDefinition actorDefinition ;
1212
1313 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+
1720 int mask = buffer .getUnsignedByte ();
18- if ((0x1 & mask ) != 0 ) {
21+ if ((0x1 & mask ) != 0 ) {
1922 int i_3_ = buffer .getUnsignedByte ();
2023 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+
2135 npc .method785 (i_4_ , MovedStatics .pulseCycle , i_3_ );
2236 npc .anInt3139 = MovedStatics .pulseCycle + 300 ;
23- npc .remainingHitpoints = buffer . getUnsignedByte () ;
24- npc .maximumHitpoints = buffer . getUnsignedByte () ;
37+ npc .remainingHitpoints = remainingHitpoints ;
38+ npc .maximumHitpoints = maximumHitpoints ;
2539 }
26- if ((0x20 & mask ) != 0 ) {
27- npc . graphicId = buffer .getUnsignedShortLE ();
40+ if ((0x20 & mask ) != 0 ) {
41+ int graphicId = buffer .getUnsignedShortLE ();
2842 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 ;
2952 npc .anInt3129 = 0 ;
3053 npc .graphicDelay = MovedStatics .pulseCycle + (0xffff & i_5_ );
3154 npc .graphicHeight = i_5_ >> 16 ;
3255 npc .anInt3140 = 0 ;
33- if (npc .graphicDelay > MovedStatics .pulseCycle )
56+ if (npc .graphicDelay > MovedStatics .pulseCycle )
3457 npc .anInt3140 = -1 ;
35- if (npc .graphicId == 65535 )
58+ if (npc .graphicId == 65535 )
3659 npc .graphicId = -1 ;
3760 }
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 )
4175 npc .facingActorIndex = -1 ;
4276 }
43- if ((0x2 & mask ) != 0 ) {
77+ if ((0x2 & mask ) != 0 ) {
4478 int i_6_ = buffer .getUnsignedByte ();
4579 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+
4692 npc .method785 (i_7_ , MovedStatics .pulseCycle , i_6_ );
4793 npc .anInt3139 = MovedStatics .pulseCycle + 300 ;
48- npc .remainingHitpoints = buffer .getUnsignedByte ();
49- npc .maximumHitpoints = buffer .getUnsignedByte ();
94+
95+ npc .remainingHitpoints = remainingHitpoints ;
96+ npc .maximumHitpoints = maximumHitpoints ;
5097 }
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+
53111 npc .chatTimer = 100 ;
54112 }
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 );
57125 npc .anInt3083 = npc .actorDefinition .rotateRightAnimation ;
58126 npc .anInt3113 = npc .actorDefinition .degreesToTurn ;
59127 npc .turnRightAnimationId = npc .actorDefinition .rotate90RightAnimation ;
@@ -64,26 +132,50 @@ public static void parseNpcUpdateMasks(PacketBuffer buffer) {
64132 npc .turnLeftAnimationId = npc .actorDefinition .rotate90LeftAnimation ;
65133 npc .turnAroundAnimationId = npc .actorDefinition .rotate180Animation ;
66134 }
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 ;
70149 }
71- if ((0x10 & mask ) != 0 ) {
150+ if ((0x10 & mask ) != 0 ) {
72151 int animationId = buffer .getUnsignedShortBE ();
73- if (animationId == 65535 )
74- animationId = -1 ;
75152 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 ) {
77167 int i_10_ = AnimationSequence .getAnimationSequence (animationId ).replyMode ;
78- if (i_10_ == 1 ) {
168+ if (i_10_ == 1 ) {
79169 npc .anInt3115 = 0 ;
80170 npc .anInt3095 = 0 ;
81171 npc .anInt3104 = 0 ;
82172 npc .playingAnimationDelay = animationDelay ;
83173 }
84- if (i_10_ == 2 )
174+ if (i_10_ == 2 )
85175 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 ) {
87179 npc .playingAnimation = animationId ;
88180 npc .anInt3115 = 0 ;
89181 npc .playingAnimationDelay = animationDelay ;
0 commit comments