-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement EFFECT_AGREE handler for rendering an effect at given coord…
…inates
- Loading branch information
1 parent
4be483c
commit c9bb922
Showing
12 changed files
with
292 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Notifiers; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.Effects | ||
{ | ||
[AutoMappedType] | ||
public class EffectAgreeHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly IEnumerable<IEffectNotifier> _effectNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.Effect; | ||
public override PacketAction Action => PacketAction.Agree; | ||
|
||
public EffectAgreeHandler(IPlayerInfoProvider playerInfoProvider, | ||
IEnumerable<IEffectNotifier> effectNotifiers) | ||
: base(playerInfoProvider) | ||
{ | ||
_effectNotifiers = effectNotifiers; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var x = packet.ReadChar(); | ||
var y = packet.ReadChar(); | ||
var effectId = packet.ReadShort(); | ||
|
||
foreach (var notifier in _effectNotifiers) | ||
notifier.NotifyEffectAtLocation(x, y, effectId); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
|
||
namespace EndlessClient.Rendering.Effects | ||
{ | ||
public class CustomEffectSpriteInfo : EffectSpriteInfo | ||
{ | ||
public CustomEffectSpriteInfo(int numberOfFrames, int repeats, bool onTopOfCharacter, int alpha, Texture2D graphic) | ||
: base(numberOfFrames, repeats, onTopOfCharacter, alpha, graphic) | ||
{ | ||
} | ||
|
||
protected override Vector2 GetDrawLocation(Rectangle textureSourceRectangle, Rectangle targetActorRectangle) | ||
{ | ||
var targetX = targetActorRectangle.X + (targetActorRectangle.Width - textureSourceRectangle.Width) / 2 - targetActorRectangle.Width / 2; | ||
var targetY = targetActorRectangle.Y - textureSourceRectangle.Height; | ||
|
||
return new Vector2(targetX, targetY); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
EndlessClient/Rendering/Factories/MapGridEffectTargetFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using AutomaticTypeMapper; | ||
using EndlessClient.Audio; | ||
using EndlessClient.Rendering.Character; | ||
using EndlessClient.Rendering.Effects; | ||
using EndlessClient.Rendering.Map; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Map; | ||
using EOLib.Graphics; | ||
|
||
namespace EndlessClient.Rendering.Factories | ||
{ | ||
[AutoMappedType] | ||
public class MapGridEffectTargetFactory : IMapGridEffectTargetFactory | ||
{ | ||
private readonly INativeGraphicsManager _nativeGraphicsManager; | ||
private readonly ISfxPlayer _sfxPlayer; | ||
private readonly IRenderOffsetCalculator _renderOffsetCalculator; | ||
private readonly ICharacterRendererProvider _characterRendererProvider; | ||
private readonly ICharacterTextures _characterTextures; | ||
|
||
public MapGridEffectTargetFactory(INativeGraphicsManager nativeGraphicsManager, | ||
ISfxPlayer sfxPlayer, | ||
IRenderOffsetCalculator renderOffsetCalculator, | ||
ICharacterRendererProvider characterRendererProvider, | ||
ICharacterTextures characterTextures) | ||
{ | ||
_nativeGraphicsManager = nativeGraphicsManager; | ||
_sfxPlayer = sfxPlayer; | ||
_renderOffsetCalculator = renderOffsetCalculator; | ||
_characterRendererProvider = characterRendererProvider; | ||
_characterTextures = characterTextures; | ||
} | ||
|
||
public IMapGridEffectTarget Create(byte x, byte y) | ||
{ | ||
if (_characterTextures.Skin == null) | ||
_characterTextures.Refresh(new CharacterRenderProperties.Builder().ToImmutable()); | ||
|
||
return new MapGridEffectTarget( | ||
_nativeGraphicsManager, | ||
_sfxPlayer, | ||
_renderOffsetCalculator, | ||
_characterRendererProvider, | ||
_characterTextures, | ||
new MapCoordinate(x, y)); | ||
} | ||
} | ||
|
||
public interface IMapGridEffectTargetFactory | ||
{ | ||
IMapGridEffectTarget Create(byte x, byte y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using EndlessClient.Audio; | ||
using EndlessClient.Rendering.Character; | ||
using EndlessClient.Rendering.Effects; | ||
using EOLib.Domain.Map; | ||
using EOLib.Graphics; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
|
||
namespace EndlessClient.Rendering.Map | ||
{ | ||
public class MapGridEffectTarget : IMapGridEffectTarget | ||
{ | ||
private IEffectRenderer _renderer; | ||
private readonly IRenderOffsetCalculator _renderOffsetCalculator; | ||
private readonly ICharacterRendererProvider _characterRendererProvider; | ||
private readonly ICharacterTextures _characterTextures; | ||
private readonly MapCoordinate _location; | ||
|
||
public Rectangle EffectTargetArea { get; private set; } | ||
|
||
public MapGridEffectTarget(INativeGraphicsManager nativeGraphicsManager, | ||
ISfxPlayer sfxPlayer, | ||
IRenderOffsetCalculator renderOffsetCalculator, | ||
ICharacterRendererProvider characterRendererProvider, | ||
ICharacterTextures characterTextures, | ||
MapCoordinate location) | ||
{ | ||
_renderer = new EffectRenderer(nativeGraphicsManager, sfxPlayer, this); | ||
_renderOffsetCalculator = renderOffsetCalculator; | ||
_characterRendererProvider = characterRendererProvider; | ||
_characterTextures = characterTextures; | ||
_location = location; | ||
} | ||
|
||
public bool EffectIsPlaying() => _renderer.State == EffectState.Playing; | ||
|
||
public void ShowPotionAnimation(int potionId) { } | ||
|
||
public void ShowSpellAnimation(int spellGraphic) | ||
{ | ||
_renderer.PlayEffect(EffectType.Spell, spellGraphic); | ||
} | ||
|
||
public void ShowWarpArrive() { } | ||
|
||
public void ShowWarpLeave() { } | ||
|
||
public void ShowWaterSplashies() { } | ||
|
||
public void Update() | ||
{ | ||
EffectTargetArea = _characterRendererProvider.MainCharacterRenderer | ||
.Match( | ||
some: mainRenderer => | ||
{ | ||
var offsetX = _renderOffsetCalculator.CalculateOffsetX(_location); | ||
var offsetY = _renderOffsetCalculator.CalculateOffsetY(_location); | ||
|
||
var mainOffsetX = _renderOffsetCalculator.CalculateOffsetX(mainRenderer.Character.RenderProperties); | ||
var mainOffsetY = _renderOffsetCalculator.CalculateOffsetY(mainRenderer.Character.RenderProperties); | ||
|
||
return new Rectangle( | ||
offsetX + 320 - mainOffsetX, | ||
offsetY + 168 - mainOffsetY, | ||
_characterTextures.Skin.SourceRectangle.Width, | ||
_characterTextures.Skin.SourceRectangle.Height); | ||
}, | ||
none: () => new Rectangle(0, 0, 1, 1)); | ||
|
||
_renderer.Update(); | ||
} | ||
|
||
public void Draw(SpriteBatch sb, bool beginHasBeenCalled = true) | ||
{ | ||
_renderer.DrawBehindTarget(sb, beginHasBeenCalled); | ||
_renderer.DrawInFrontOfTarget(sb, beginHasBeenCalled); | ||
} | ||
} | ||
|
||
public interface IMapGridEffectTarget : IEffectTarget | ||
{ | ||
void Update(); | ||
|
||
void Draw(SpriteBatch sb, bool beginHasBeenCalled = true); | ||
} | ||
} |
Oops, something went wrong.