<commit_before>﻿using System;
using EndlessClient.Rendering.Sprites;
using EOLib;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace EndlessClient.Rendering.CharacterProperties
{
    public class WeaponRenderer : BaseCharacterPropertyRenderer
    {
        private readonly ISpriteSheet _weaponSheet;

        public override bool CanRender => _weaponSheet.HasTexture && _renderProperties.WeaponGraphic != 0;

        public WeaponRenderer(ICharacterRenderProperties renderProperties,
                              ISpriteSheet weaponSheet)
            : base(renderProperties)
        {
            _weaponSheet = weaponSheet;
        }

        public override void Render(SpriteBatch spriteBatch, Rectangle parentCharacterDrawArea)
        {
            if (_renderProperties.IsActing(CharacterActionState.Sitting, CharacterActionState.SpellCast))
                return;

            var offsets = GetOffsets(parentCharacterDrawArea);
            var drawLoc = new Vector2(parentCharacterDrawArea.X + offsets.X, parentCharacterDrawArea.Y + offsets.Y);
            Render(spriteBatch, _weaponSheet, drawLoc);
        }

        private Vector2 GetOffsets(Rectangle parentCharacterDrawArea)
        {
            float resX, resY;

            if (_renderProperties.IsRangedWeapon)
            {
                resX = 0;
                resY = 0;
                //resX = -(float)Math.Floor(Math.Abs((float)_shieldSheet.SourceRectangle.Width - parentCharacterDrawArea.Width) / 2);
                //resY = -(float)Math.Floor(parentCharacterDrawArea.Height / 3f) - _renderProperties.Gender;

                //if (_renderProperties.AttackFrame == 2)
                //    resX += _renderProperties.IsFacing(EODirection.Up, EODirection.Right) ? 2 : -2;
            }
            else
            {
                resX = -(float)Math.Floor(Math.Abs((float)_weaponSheet.SourceRectangle.Width - parentCharacterDrawArea.Width) / 2);
                resY = -(float)Math.Floor(Math.Abs((float)_weaponSheet.SourceRectangle.Height - parentCharacterDrawArea.Height) / 2) - 5;

                if (_renderProperties.IsFacing(EODirection.Down, EODirection.Left))
                {
                    resX -= parentCharacterDrawArea.Width / 1.5f;

                    if (_renderProperties.AttackFrame == 2)
                        resX -= 2;

                    resX += 3;
                }
                else
                {
                    resX += parentCharacterDrawArea.Width / 1.5f;

                    if (_renderProperties.AttackFrame == 2)
                        resX += 2;

                    resX -= 3;
                }

                resY -= 1 + _renderProperties.Gender;
                if (_renderProperties.IsActing(CharacterActionState.Walking))
                    resY -= 1;
            }

            return new Vector2(resX, resY);
        }
    }
}<commit_msg>Fix walk/attack frames for ranged weapons<commit_after>﻿using System;
using EndlessClient.Rendering.Sprites;
using EOLib;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace EndlessClient.Rendering.CharacterProperties
{
    public class WeaponRenderer : BaseCharacterPropertyRenderer
    {
        private readonly ISpriteSheet _weaponSheet;

        public override bool CanRender => _weaponSheet.HasTexture && _renderProperties.WeaponGraphic != 0;

        public WeaponRenderer(ICharacterRenderProperties renderProperties,
                              ISpriteSheet weaponSheet)
            : base(renderProperties)
        {
            _weaponSheet = weaponSheet;
        }

        public override void Render(SpriteBatch spriteBatch, Rectangle parentCharacterDrawArea)
        {
            if (_renderProperties.IsActing(CharacterActionState.Sitting, CharacterActionState.SpellCast))
                return;

            var offsets = GetOffsets(parentCharacterDrawArea);
            var drawLoc = new Vector2(parentCharacterDrawArea.X + offsets.X, parentCharacterDrawArea.Y + offsets.Y);
            Render(spriteBatch, _weaponSheet, drawLoc);
        }

        private Vector2 GetOffsets(Rectangle parentCharacterDrawArea)
        {
            float resX, resY;

            resX = -(float)Math.Floor(Math.Abs((float)_weaponSheet.SourceRectangle.Width - parentCharacterDrawArea.Width) / 2);
            resY = -(float)Math.Floor(Math.Abs((float)_weaponSheet.SourceRectangle.Height - parentCharacterDrawArea.Height) / 2) - 5;

            var factor = _renderProperties.IsFacing(EODirection.Down, EODirection.Left) ? -1 : 1;
            var isDownOrRight = _renderProperties.IsFacing(EODirection.Down, EODirection.Right);

            resX += (parentCharacterDrawArea.Width / 1.5f - 3) * factor;
            if (_renderProperties.AttackFrame == 2)
                resX += 2 * factor;
            else if (_renderProperties.AttackFrame == 1 && _renderProperties.IsRangedWeapon)
                resX += (isDownOrRight ? 6 : 4) * factor;

            resY -= 1 + _renderProperties.Gender;
            if (_renderProperties.IsActing(CharacterActionState.Walking))
                resY -= 1;
            else if (_renderProperties.AttackFrame == 1 && _renderProperties.IsRangedWeapon)
                resY += isDownOrRight ? 1 : 0;

            return new Vector2(resX, resY);
        }
    }
}
{'fraction_non_alphanumeric': 0.08555758683729434, 'fraction_numerical': 0.008775137111517367, 'mean_word_length': 2.13704128440367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6612918', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1423, 'n_words': 272}