Skip to content

Commit

Permalink
Fix skin/equipment rendering offsets for floor sitting
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Jan 29, 2021
1 parent 9a470c3 commit b0d4b12
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 13 deletions.
16 changes: 11 additions & 5 deletions EndlessClient/Rendering/CharacterProperties/ArmorRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,25 @@ private Vector2 GetOffsets(Vector2 parentCharacterSize)
}
else if (_renderProperties.SitState != SitState.Standing)
{
// todo: floor sitting offsets
resX -= 1;
if (_renderProperties.SitState == SitState.Chair)
{
resX -= 1;
resY += _renderProperties.IsFacing(EODirection.Left, EODirection.Up) ? 2 : 0;
}
else
{
resX += _renderProperties.IsFacing(EODirection.Left) ? _renderProperties.Gender : _renderProperties.IsFacing(EODirection.Up) ? -_renderProperties.Gender : 0;
resX -= _renderProperties.IsFacing(EODirection.Down, EODirection.Up) ? (2 - _renderProperties.Gender) : _renderProperties.Gender;
resY += _renderProperties.IsFacing(EODirection.Left, EODirection.Up) ? 12 : 9;
}
}
else
{
resX += 2;
}

// todo: floor sitting offsets
if (_renderProperties.SitState == SitState.Standing)
resY -= (_renderProperties.IsActing(CharacterActionState.Walking) ? 4 : 3) + _renderProperties.Gender;
else
resY += _renderProperties.IsFacing(EODirection.Left, EODirection.Up) ? 2 : 0;

return new Vector2(resX, resY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public abstract class BaseCharacterPropertyRenderer : ICharacterPropertyRenderer

public float LayerDepth { get; set; }

protected virtual bool ShouldFlip => _renderProperties.IsFacing(EODirection.Up, EODirection.Right);

protected BaseCharacterPropertyRenderer(ICharacterRenderProperties renderProperties)
{
_renderProperties = renderProperties;
Expand All @@ -26,7 +28,7 @@ protected BaseCharacterPropertyRenderer(ICharacterRenderProperties renderPropert
protected virtual void Render(SpriteBatch spriteBatch, ISpriteSheet sheet, Vector2 drawLoc, int alpha = 255)
{
spriteBatch.Draw(sheet.SheetTexture, drawLoc, sheet.SourceRectangle, Color.FromNonPremultiplied(255, 255, 255, alpha), 0.0f, Vector2.Zero, 1.0f,
_renderProperties.IsFacing(EODirection.Up, EODirection.Right) ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
ShouldFlip ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
LayerDepth);
}
}
Expand Down
17 changes: 16 additions & 1 deletion EndlessClient/Rendering/CharacterProperties/BootsRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,24 @@ private Vector2 GetOffsets(Rectangle parentCharacterDrawArea)
}
else if (_renderProperties.SitState != SitState.Standing)
{
// todo: floor sitting offsets
resX -= 3;
resY += _renderProperties.IsFacing(EODirection.Left, EODirection.Up) ? -3 : 2;

if (_renderProperties.SitState == SitState.Floor)
{
var factor = _renderProperties.IsFacing(EODirection.Left, EODirection.Down) ? -1 : 1;

if (_renderProperties.Gender == 0)
{
resX += (_renderProperties.IsFacing(EODirection.Right, EODirection.Down) ? 1 : -1) * factor;
resY += _renderProperties.IsFacing(EODirection.Right, EODirection.Down) ? 2 : 3;
}
else if (_renderProperties.Gender == 1)
{
resX += (_renderProperties.IsFacing(EODirection.Right, EODirection.Down) ? 0 : -1) * factor;
resY += 4;
}
}
}

return new Vector2(resX, resY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,23 @@ public Vector2 CalculateDrawLocationOfCharacterHair(Rectangle hairRectangle, Rec
}
else if (_renderProperties.SitState != SitState.Standing)
{
// todo: floor sitting offsets
resX -= 3;
resY += (_renderProperties.IsFacing(EODirection.Right, EODirection.Down) ? 9 : 11) + _renderProperties.Gender;

var flootSitFactor = _renderProperties.SitState == SitState.Floor ? 2 : 1;
if (_renderProperties.IsFacing(EODirection.Right, EODirection.Down))
{
resY += (9 + _renderProperties.Gender) * flootSitFactor;
}
else
{
if (_renderProperties.SitState == SitState.Floor)
{
resX += _renderProperties.IsFacing(EODirection.Left) ? 2 : -2;
resY -= 1;
}

resY += (11 + _renderProperties.Gender) * flootSitFactor;
}
}

var flippedOffset = isFlipped ? 2 : 0;
Expand Down
27 changes: 24 additions & 3 deletions EndlessClient/Rendering/CharacterProperties/ShieldRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class ShieldRenderer : BaseCharacterPropertyRenderer

public override bool CanRender => _shieldSheet.HasTexture && _renderProperties.ShieldGraphic != 0;

// NOTE: The original client flips the arrows when facing left or up from the standing frame.
// I'm guessing this is a Vult bug. The offsets are wonky if this is enabled and I don't feel like figuring them out.
//protected override bool ShouldFlip => _renderProperties.SitState == SitState.Floor
//? _isShieldOnBack && _renderProperties.IsFacing(EODirection.Left, EODirection.Right)
//: base.ShouldFlip;

public ShieldRenderer(ICharacterRenderProperties renderProperties,
ISpriteSheet shieldSheet,
bool isShieldOnBack)
Expand Down Expand Up @@ -53,10 +59,25 @@ private Vector2 GetOffsets(Rectangle parentCharacterDrawArea)
}
else if (_renderProperties.SitState != SitState.Standing)
{
// todo: floor sitting offsets
// todo: this looks like the same offset as for hair?
// These are the same offsets as hair

resX -= 3;
resY += (_renderProperties.IsFacing(EODirection.Up, EODirection.Left) ? 11 : 9) + _renderProperties.Gender;

var flootSitFactor = _renderProperties.SitState == SitState.Floor ? 2 : 1;
if (_renderProperties.IsFacing(EODirection.Right, EODirection.Down))
{
resY += (9 + _renderProperties.Gender) * flootSitFactor;
}
else
{
if (_renderProperties.SitState == SitState.Floor)
{
resX += _renderProperties.IsFacing(EODirection.Left) ? 2 : -2;
resY -= 1;
}

resY += (11 + _renderProperties.Gender) * flootSitFactor;
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public Vector2 CalculateDrawLocationOfCharacterSkin(Rectangle skinRectangle, Rec
}
else if (_renderProperties.SitState != SitState.Standing)
{
// todo: floor sitting offsets
var factor = _renderProperties.IsFacing(EODirection.Down, EODirection.Left) ? -1 : 1;

resX = -(int)Math.Floor((float)(skinRectangle.Width - parentCharacterDrawArea.Width));
Expand All @@ -55,6 +54,12 @@ public Vector2 CalculateDrawLocationOfCharacterSkin(Rectangle skinRectangle, Rec
resX += parentCharacterDrawArea.X + (genderAdjustFactor * factor);

resY += (_renderProperties.IsFacing(EODirection.Left, EODirection.Up) ? 7 : 5) - _renderProperties.Gender;

if (_renderProperties.SitState == SitState.Floor)
{
resX += _renderProperties.IsFacing(EODirection.Left, EODirection.Up) ? -factor : 0;
resY += _renderProperties.IsFacing(EODirection.Left, EODirection.Up) ? 1 : 0;
}
}
else
{
Expand Down

0 comments on commit b0d4b12

Please sign in to comment.