Skip to content

Commit

Permalink
fix: entity animation texture (#2334)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arufonsu authored Jul 21, 2024
1 parent 7b524eb commit 15f9e77
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions Intersect.Client/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,7 @@ public virtual void DrawEquipment(string filename, Color renderColor)

// Equipment's custom paperdoll texture.
if (SpriteAnimation is SpriteAnimations.Attack or
SpriteAnimations.Cast or
SpriteAnimations.Weapon)
SpriteAnimations.Cast or SpriteAnimations.Weapon or SpriteAnimations.Shoot)
{
// Extract animation name from the AnimatedTextures list.
var animationName = Path.GetFileNameWithoutExtension(AnimatedTextures[SpriteAnimation].Name);
Expand Down Expand Up @@ -1980,7 +1979,7 @@ private void UpdateSpriteAnimation()
case SpriteAnimations.Shoot:
case SpriteAnimations.Weapon:
default:
SpriteFrame = (int)Math.Floor((timeInAttack / (CalculateAttackTime() / (float)SpriteFrames)));
SpriteFrame = (int)Math.Floor(timeInAttack / (CalculateAttackTime() / (float)SpriteFrames));
break;
}
}
Expand Down Expand Up @@ -2009,7 +2008,7 @@ private void UpdateSpriteAnimation()
}
}

SpriteFrame = (int)Math.Floor((timeInCast / (duration / (float)SpriteFrames)));
SpriteFrame = (int)Math.Floor(timeInCast / (duration / (float)SpriteFrames));
}

LastActionTime = timingMilliseconds;
Expand Down Expand Up @@ -2059,14 +2058,17 @@ public virtual void LoadTextures(string textureName)
protected virtual void LoadAnimationTexture(string textureName, SpriteAnimations spriteAnimation)
{
SpriteAnimations spriteAnimationOveride = spriteAnimation;
string? textureOverride = default;
var textureOverride = string.Empty;
var weaponId = Equipment[Options.WeaponIndex];

switch (spriteAnimation)
{
// No override for this
case SpriteAnimations.Normal: break;
// No override for these animations.
case SpriteAnimations.Normal:
case SpriteAnimations.Idle:

break;

case SpriteAnimations.Idle: break;
case SpriteAnimations.Attack:
if (this is Player player && ClassBase.TryGet(player.Class, out var classDescriptor))
{
Expand All @@ -2076,22 +2078,19 @@ protected virtual void LoadAnimationTexture(string textureName, SpriteAnimations
break;

case SpriteAnimations.Shoot:
if (Equipment.Length <= Options.WeaponIndex)
{
if (Equipment.Length <= Options.WeaponIndex)
{
break;
}
break;
}

var weaponId = Equipment[Options.WeaponIndex];
if (ItemBase.TryGet(weaponId, out var itemDescriptor))
{
textureOverride = itemDescriptor.WeaponSpriteOverride;
}
if (ItemBase.TryGet(weaponId, out var shootItemDescriptor))
{
textureOverride = shootItemDescriptor.WeaponSpriteOverride;
}

if (!string.IsNullOrWhiteSpace(textureOverride))
{
spriteAnimationOveride = SpriteAnimations.Weapon;
}
if (!string.IsNullOrWhiteSpace(textureOverride))
{
spriteAnimationOveride = SpriteAnimations.Shoot;
}

break;
Expand All @@ -2102,20 +2101,27 @@ protected virtual void LoadAnimationTexture(string textureName, SpriteAnimations
textureOverride = spellDescriptor.CastSpriteOverride;
}

if (!string.IsNullOrWhiteSpace(textureOverride))
{
spriteAnimationOveride = SpriteAnimations.Cast;
}

break;

case SpriteAnimations.Weapon:
if (Equipment.Length <= Options.WeaponIndex)
{
if (Equipment.Length <= Options.WeaponIndex)
{
break;
}
break;
}

var weaponId = Equipment[Options.WeaponIndex];
if (ItemBase.TryGet(weaponId, out var itemDescriptor))
{
textureOverride = itemDescriptor.WeaponSpriteOverride;
}
if (ItemBase.TryGet(weaponId, out var weaponItemDescriptor))
{
textureOverride = weaponItemDescriptor.WeaponSpriteOverride;
}

if (!string.IsNullOrWhiteSpace(textureOverride))
{
spriteAnimationOveride = SpriteAnimations.Weapon;
}

break;
Expand All @@ -2124,7 +2130,7 @@ protected virtual void LoadAnimationTexture(string textureName, SpriteAnimations
throw new ArgumentOutOfRangeException(nameof(spriteAnimation));
}

if (!string.IsNullOrEmpty(textureOverride) && TryGetAnimationTexture(textureName, spriteAnimationOveride, textureOverride, out var texture))
if (TryGetAnimationTexture(textureName, spriteAnimationOveride, textureOverride, out var texture))
{
AnimatedTextures[spriteAnimation] = texture;
}
Expand Down

0 comments on commit 15f9e77

Please sign in to comment.