From 15f9e77c6f2a11ec57d90d726f968c872db5149a Mon Sep 17 00:00:00 2001 From: Fernando Arzola <17498701+Arufonsu@users.noreply.github.com> Date: Sun, 21 Jul 2024 17:01:54 -0400 Subject: [PATCH] fix: entity animation texture (#2334) --- Intersect.Client/Entities/Entity.cs | 68 ++++++++++++++++------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/Intersect.Client/Entities/Entity.cs b/Intersect.Client/Entities/Entity.cs index 670db2a515..c9b10acaa4 100644 --- a/Intersect.Client/Entities/Entity.cs +++ b/Intersect.Client/Entities/Entity.cs @@ -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); @@ -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; } } @@ -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; @@ -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)) { @@ -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; @@ -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; @@ -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; }