-
Notifications
You must be signed in to change notification settings - Fork 381
feat: added reasources states based on resource health #2684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
70e59cc
483c1bd
ceba4ea
32698cf
5a595ea
bc2c657
a589b8e
daeec45
220f35b
c5a24a0
893ef01
70332a1
df02af0
69bb298
bb694de
5547c9e
6d90722
acad5a9
e8d181a
edd6367
8becfb8
2a3bf37
cdae5a4
031b8e3
cf5c44b
8207c29
3101642
1c22193
e2081df
3abb611
d4411f5
69bab12
ccdd892
65f458f
805cc7b
4ecf199
ad72114
dd0fb5d
f65f900
63a3905
1b48080
276e6cf
70bae59
53a9c39
830c6c4
9c2ef67
12b45f6
891d7e4
320dc8e
db49e0a
f057779
21bb25a
80bc57b
ef8bb4e
4ef0ad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,6 @@ public ResourceDescriptor? Descriptor | |
| get => _descriptor; | ||
| set | ||
| { | ||
| _descriptor = value; | ||
| if (value is { } descriptor) | ||
| { | ||
| _maximumHealthForStates = (int)(descriptor.UseExplicitMaxHealthForResourceStates | ||
|
|
@@ -60,6 +59,14 @@ public ResourceDescriptor? Descriptor | |
| { | ||
| _maximumHealthForStates = 0; | ||
| } | ||
|
|
||
| if (value == _descriptor) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| _descriptor = value; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This stuff needs to be before anything else in the setter, it shouldn't be after the new value is being used |
||
| UpdateCurrentState(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -109,7 +116,7 @@ private void ReloadSpriteTexture() | |
| case ResourceTextureSource.Tileset: | ||
| if (GameContentManager.Current.TilesetsLoaded) | ||
| { | ||
| Texture = GameContentManager.Current.GetTexture(TextureType.Tileset, _sprite); | ||
| Texture = GameContentManager.Current.GetTexture(TextureType.Tileset, _currentState?.TextureName); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -118,7 +125,7 @@ private void ReloadSpriteTexture() | |
| break; | ||
|
|
||
| case ResourceTextureSource.Resource: | ||
| Texture = GameContentManager.Current.GetTexture(TextureType.Resource, _sprite); | ||
| Texture = GameContentManager.Current.GetTexture(TextureType.Resource, _currentState?.TextureName); | ||
| break; | ||
|
|
||
| case ResourceTextureSource.Animation: | ||
|
|
@@ -189,7 +196,6 @@ public override void Load(EntityPacket? packet) | |
| } | ||
|
|
||
| Descriptor = descriptor; | ||
| UpdateCurrentState(); | ||
|
|
||
| if (!justDied) | ||
| { | ||
|
|
@@ -240,8 +246,8 @@ public void UpdateCurrentState() | |
| var currentHealthPercentage = Math.Floor((float)Vital[(int)Enums.Vital.Health] / _maximumHealthForStates * 100); | ||
|
|
||
| if (_currentState is { } currentState && | ||
| currentHealthPercentage >= _currentState?.MinimumHealth && | ||
| currentHealthPercentage <= _currentState?.MaximumHealth | ||
| currentHealthPercentage >= currentState?.MinimumHealth && | ||
| currentHealthPercentage <= currentState?.MaximumHealth | ||
| ) | ||
| { | ||
| return; | ||
|
|
@@ -255,16 +261,14 @@ public void UpdateCurrentState() | |
| // but the previous state was an animation | ||
| if ( | ||
| _currentState?.TextureType == ResourceTextureSource.Animation && | ||
| _stateAnimation != default && | ||
| currentState?.TextureType != ResourceTextureSource.Animation | ||
| ) | ||
| ) | ||
| { | ||
| _stateAnimation.Dispose(); | ||
| _stateAnimation?.Dispose(); | ||
| _stateAnimation = default; | ||
| } | ||
|
|
||
| _currentState = currentState; | ||
| _sprite = _currentState?.TextureName ?? string.Empty; | ||
|
|
||
| if (currentState is { TextureType: ResourceTextureSource.Animation } && currentState.AnimationId != Guid.Empty) | ||
| { | ||
|
|
@@ -299,7 +303,6 @@ public override bool Update() | |
| { | ||
| _ = ResourceDescriptor.TryGet(deletedDescriptor.Id, out var descriptor); | ||
| Descriptor = descriptor; | ||
| UpdateCurrentState(); | ||
| } | ||
|
|
||
| if (!Maps.MapInstance.TryGet(MapId, out var map) || !map.InView()) | ||
|
|
@@ -338,7 +341,7 @@ public override bool Update() | |
|
|
||
| public override HashSet<Entity>? DetermineRenderOrder(HashSet<Entity>? renderList, IMapInstance? map) | ||
| { | ||
| if (Descriptor == default || CurrentState is not { } graphicState || !graphicState.RenderBelowEntities) | ||
| if (CurrentState is not { } graphicState || !graphicState.RenderBelowEntities) | ||
| { | ||
| return base.DetermineRenderOrder(renderList, map); | ||
| } | ||
|
|
@@ -463,35 +466,29 @@ private void CalculateRenderBounds() | |
| break; | ||
|
|
||
| case ResourceTextureSource.Tileset: | ||
| if (IsDead) | ||
| ResourceStateDescriptor? selectedGraphic = null; | ||
|
|
||
| if (IsDead && graphicState is { MaximumHealth: 0 } deadGraphic) | ||
| { | ||
| if (graphicState is { MaximumHealth: 0 } deadGraphic) | ||
| { | ||
| _renderBoundsSrc = new( | ||
| deadGraphic.X * _tileWidth, | ||
| deadGraphic.Y * _tileHeight, | ||
| (deadGraphic.Width + 1) * _tileWidth, | ||
| (deadGraphic.Height + 1) * _tileHeight | ||
| ); | ||
| } | ||
| else | ||
| { | ||
| _renderBoundsSrc = new(); | ||
| } | ||
| selectedGraphic = deadGraphic; | ||
| } | ||
| else if (graphicState is { MinimumHealth: > 0 } aliveGraphic) | ||
| else if (!IsDead && graphicState is { MinimumHealth: > 0 } aliveGraphic) | ||
|
||
| { | ||
| _renderBoundsSrc = new( | ||
| aliveGraphic.X * _tileWidth, | ||
| aliveGraphic.Y * _tileHeight, | ||
| (aliveGraphic.Width + 1) * _tileWidth, | ||
| (aliveGraphic.Height + 1) * _tileHeight | ||
| ); | ||
| selectedGraphic = aliveGraphic; | ||
| } | ||
|
|
||
| _renderBoundsSrc = selectedGraphic is null | ||
| ? default | ||
| : new ( | ||
| selectedGraphic.X * _tileWidth, | ||
| selectedGraphic.Y * _tileHeight, | ||
| (selectedGraphic.Width + 1) * _tileWidth, | ||
| (selectedGraphic.Height + 1) * _tileHeight | ||
| ); | ||
| break; | ||
|
|
||
| case ResourceTextureSource.Animation: | ||
| _renderBoundsSrc = new(); | ||
| _renderBoundsSrc = default; | ||
| break; | ||
|
|
||
| default: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1348,7 +1348,9 @@ bool alternate | |
| var x2 = Options.Instance.Map.MapWidth; | ||
|
||
| var y1 = 0; | ||
| var y2 = Options.Instance.Map.MapHeight; | ||
| var xoffset = CurrentView.Left + gridX * Options.Instance.Map.TileWidth * Options.Instance.Map.MapWidth; | ||
| var tileWidth = Options.Instance.Map.TileWidth; | ||
| var tileHeight = Options.Instance.Map.TileHeight; | ||
| var xoffset = CurrentView.Left + gridX * tileWidth * Options.Instance.Map.MapWidth; | ||
|
||
| var yoffset = CurrentView.Top + gridY * Options.Instance.Map.TileHeight * Options.Instance.Map.MapHeight; | ||
|
||
|
|
||
| if (screenShotting) | ||
|
|
@@ -1402,8 +1404,11 @@ bool alternate | |
| continue; | ||
| } | ||
|
|
||
| float xpos = x * tileWidth + xoffset; | ||
| float ypos = y * Options.Instance.Map.TileHeight + yoffset; | ||
|
||
|
|
||
| // we have the graphic, now lets build based on type | ||
| switch(resourceGraphic.TextureType) | ||
| switch (resourceGraphic.TextureType) | ||
| { | ||
| case ResourceTextureSource.Resource: | ||
| { | ||
|
|
@@ -1416,21 +1421,25 @@ bool alternate | |
| continue; | ||
| } | ||
|
|
||
| float xpos = x * Options.Instance.Map.TileWidth + xoffset; | ||
| float ypos = y * Options.Instance.Map.TileHeight + yoffset; | ||
|
|
||
| if (texture.Height > Options.Instance.Map.TileHeight) | ||
|
||
| { | ||
| ypos -= texture.Height - Options.Instance.Map.TileHeight; | ||
|
||
| } | ||
|
|
||
| if (texture.Width > Options.Instance.Map.TileWidth) | ||
| if (texture.Width > tileWidth) | ||
| { | ||
| xpos -= (texture.Width - Options.Instance.Map.TileWidth) / 2; | ||
| xpos -= (texture.Width - tileWidth) / 2; | ||
| } | ||
|
|
||
| DrawTexture( | ||
| texture, xpos, ypos, 0, 0, texture.Width, texture.Height, renderTarget | ||
| texture, | ||
| xpos, | ||
| ypos, | ||
| 0, | ||
| 0, | ||
| texture.Width, | ||
| texture.Height, | ||
| renderTarget | ||
| ); | ||
| } | ||
| break; | ||
|
|
@@ -1446,24 +1455,25 @@ bool alternate | |
| continue; | ||
| } | ||
|
|
||
| float xpos = x * Options.Instance.Map.TileWidth + xoffset; | ||
| float ypos = y * Options.Instance.Map.TileHeight + yoffset; | ||
|
|
||
| if ((resourceGraphic.Height + 1) * Options.Instance.Map.TileHeight > Options.Instance.Map.TileHeight) | ||
|
||
| { | ||
| ypos -= (resourceGraphic.Height + 1) * Options.Instance.Map.TileHeight - Options.Instance.Map.TileHeight; | ||
|
||
| } | ||
|
|
||
| if ((resourceGraphic.Width + 1) * Options.Instance.Map.TileWidth > Options.Instance.Map.TileWidth) | ||
| if ((resourceGraphic.Width + 1) * tileWidth > tileWidth) | ||
| { | ||
| xpos -= ((resourceGraphic.Width + 1) * Options.Instance.Map.TileWidth - Options.Instance.Map.TileWidth) / 2; | ||
| xpos -= ((resourceGraphic.Width + 1) * tileWidth - tileWidth) / 2; | ||
| } | ||
|
|
||
| DrawTexture( | ||
| texture, xpos, ypos, resourceGraphic.X * Options.Instance.Map.TileWidth, | ||
| texture, | ||
| xpos, | ||
| ypos, | ||
| resourceGraphic.X * tileWidth, | ||
| resourceGraphic.Y * Options.Instance.Map.TileHeight, | ||
|
||
| (resourceGraphic.Width + 1) * Options.Instance.Map.TileWidth, | ||
| (resourceGraphic.Height + 1) * Options.Instance.Map.TileHeight, renderTarget | ||
| (resourceGraphic.Width + 1) * tileWidth, | ||
| (resourceGraphic.Height + 1) * Options.Instance.Map.TileHeight, | ||
|
||
| renderTarget | ||
| ); | ||
| } | ||
| break; | ||
|
|
@@ -1475,8 +1485,8 @@ bool alternate | |
| continue; | ||
| } | ||
|
|
||
| float xpos = x * Options.Instance.Map.TileWidth + xoffset + Options.Instance.Map.TileWidth / 2f; | ||
| float ypos = y * Options.Instance.Map.TileHeight + yoffset + Options.Instance.Map.TileHeight / 2f; | ||
| xpos += tileWidth / 2f; | ||
| ypos += Options.Instance.Map.TileHeight / 2f; | ||
|
||
|
|
||
| var animationInstance = tmpMap.GetAttributeAnimation(tmpMap.Attributes[x, y], animation.Id); | ||
|
|
||
|
|
@@ -1514,7 +1524,7 @@ bool alternate | |
|
|
||
| if (animation != null) | ||
| { | ||
| float xpos = x * Options.Instance.Map.TileWidth + xoffset + Options.Instance.Map.TileWidth / 2; | ||
| float xpos = x * tileWidth + xoffset + tileWidth / 2; | ||
| float ypos = y * Options.Instance.Map.TileHeight + yoffset + Options.Instance.Map.TileHeight / 2; | ||
|
||
| if (tmpMap.Attributes[x, y] != null) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.