-
Notifications
You must be signed in to change notification settings - Fork 16
/
WeaponRenderer.cs
60 lines (49 loc) · 2.53 KB
/
WeaponRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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(CharacterRenderProperties renderProperties,
ISpriteSheet weaponSheet)
: base(renderProperties)
{
_weaponSheet = weaponSheet;
}
public override void Render(SpriteBatch spriteBatch, Rectangle parentCharacterDrawArea)
{
if (_renderProperties.IsActing(CharacterActionState.Sitting, CharacterActionState.SpellCast) ||
(_renderProperties.CurrentAction == CharacterActionState.Emote && _renderProperties.SitState != SitState.Standing))
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.RenderAttackFrame == 2)
resX += 2 * factor;
else if (_renderProperties.RenderAttackFrame == 1 && _renderProperties.IsRangedWeapon)
resX += (isDownOrRight ? 6 : 4) * factor;
resY -= 1 + _renderProperties.Gender;
if (_renderProperties.IsActing(CharacterActionState.Walking))
resY -= 1;
else if (_renderProperties.RenderAttackFrame == 1 && _renderProperties.IsRangedWeapon)
resY += isDownOrRight ? 1 : 0;
return new Vector2(resX, resY);
}
}
}