@@ -49,6 +49,11 @@ public ResourceDescriptor? Descriptor
4949 get => _descriptor ;
5050 set
5151 {
52+ if ( value == _descriptor )
53+ {
54+ return ;
55+ }
56+
5257 _descriptor = value ;
5358 if ( value is { } descriptor )
5459 {
@@ -60,6 +65,8 @@ public ResourceDescriptor? Descriptor
6065 {
6166 _maximumHealthForStates = 0 ;
6267 }
68+
69+ UpdateCurrentState ( ) ;
6370 }
6471 }
6572
@@ -189,7 +196,6 @@ public override void Load(EntityPacket? packet)
189196 }
190197
191198 Descriptor = descriptor ;
192- UpdateCurrentState ( ) ;
193199
194200 if ( ! justDied )
195201 {
@@ -240,8 +246,8 @@ public void UpdateCurrentState()
240246 var currentHealthPercentage = Math . Floor ( ( float ) Vital [ ( int ) Enums . Vital . Health ] / _maximumHealthForStates * 100 ) ;
241247
242248 if ( _currentState is { } currentState &&
243- currentHealthPercentage >= _currentState ? . MinimumHealth &&
244- currentHealthPercentage <= _currentState ? . MaximumHealth
249+ currentHealthPercentage >= currentState ? . MinimumHealth &&
250+ currentHealthPercentage <= currentState ? . MaximumHealth
245251 )
246252 {
247253 return ;
@@ -255,11 +261,10 @@ public void UpdateCurrentState()
255261 // but the previous state was an animation
256262 if (
257263 _currentState ? . TextureType == ResourceTextureSource . Animation &&
258- _stateAnimation != default &&
259264 currentState ? . TextureType != ResourceTextureSource . Animation
260- )
265+ )
261266 {
262- _stateAnimation . Dispose ( ) ;
267+ _stateAnimation ? . Dispose ( ) ;
263268 _stateAnimation = default ;
264269 }
265270
@@ -299,7 +304,6 @@ public override bool Update()
299304 {
300305 _ = ResourceDescriptor . TryGet ( deletedDescriptor . Id , out var descriptor ) ;
301306 Descriptor = descriptor ;
302- UpdateCurrentState ( ) ;
303307 }
304308
305309 if ( ! Maps . MapInstance . TryGet ( MapId , out var map ) || ! map . InView ( ) )
@@ -338,7 +342,7 @@ public override bool Update()
338342
339343 public override HashSet < Entity > ? DetermineRenderOrder ( HashSet < Entity > ? renderList , IMapInstance ? map )
340344 {
341- if ( Descriptor == default || CurrentState is not { } graphicState || ! graphicState . RenderBelowEntities )
345+ if ( CurrentState is not { } graphicState || ! graphicState . RenderBelowEntities )
342346 {
343347 return base . DetermineRenderOrder ( renderList , map ) ;
344348 }
@@ -463,35 +467,29 @@ private void CalculateRenderBounds()
463467 break ;
464468
465469 case ResourceTextureSource . Tileset :
466- if ( IsDead )
470+ ResourceStateDescriptor ? selectedGraphic = null ;
471+
472+ if ( IsDead && graphicState is { MaximumHealth : 0 } deadGraphic )
467473 {
468- if ( graphicState is { MaximumHealth : 0 } deadGraphic )
469- {
470- _renderBoundsSrc = new (
471- deadGraphic . X * _tileWidth ,
472- deadGraphic . Y * _tileHeight ,
473- ( deadGraphic . Width + 1 ) * _tileWidth ,
474- ( deadGraphic . Height + 1 ) * _tileHeight
475- ) ;
476- }
477- else
478- {
479- _renderBoundsSrc = new ( ) ;
480- }
474+ selectedGraphic = deadGraphic ;
481475 }
482- else if ( graphicState is { MinimumHealth : > 0 } aliveGraphic )
476+ else if ( ! IsDead && graphicState is { MinimumHealth : > 0 } aliveGraphic )
483477 {
484- _renderBoundsSrc = new (
485- aliveGraphic . X * _tileWidth ,
486- aliveGraphic . Y * _tileHeight ,
487- ( aliveGraphic . Width + 1 ) * _tileWidth ,
488- ( aliveGraphic . Height + 1 ) * _tileHeight
489- ) ;
478+ selectedGraphic = aliveGraphic ;
490479 }
480+
481+ _renderBoundsSrc = selectedGraphic is null
482+ ? default
483+ : new (
484+ selectedGraphic . X * _tileWidth ,
485+ selectedGraphic . Y * _tileHeight ,
486+ ( selectedGraphic . Width + 1 ) * _tileWidth ,
487+ ( selectedGraphic . Height + 1 ) * _tileHeight
488+ ) ;
491489 break ;
492490
493491 case ResourceTextureSource . Animation :
494- _renderBoundsSrc = new ( ) ;
492+ _renderBoundsSrc = default ;
495493 break ;
496494
497495 default :
0 commit comments