Skip to content

Commit

Permalink
Fix timed spikes
Browse files Browse the repository at this point in the history
Timed spike tiles now correctly show the spike object when a timed spike packet is received.
  • Loading branch information
ethanmoffat committed May 31, 2024
1 parent 422564e commit 5c797bc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion EOLib/Domain/Map/CurrentMapStateRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface ICurrentMapStateRepository

HashSet<Warp> PendingDoors { get; set; }

Option<DateTime> LastTimedSpikeEvent { get; set; }

WarpState MapWarpState { get; set; }

Option<int> MapWarpSession { get; set; }
Expand Down Expand Up @@ -60,6 +62,8 @@ public interface ICurrentMapStateProvider

IReadOnlyCollection<Warp> PendingDoors { get; }

Option<DateTime> LastTimedSpikeEvent { get; set; }

WarpState MapWarpState { get; }

Option<int> MapWarpSession { get; }
Expand Down Expand Up @@ -96,7 +100,7 @@ public class CurrentMapStateRepository : ICurrentMapStateRepository, ICurrentMap

public HashSet<Warp> PendingDoors { get; set; }

public HashSet<MapCoordinate> VisibleSpikeTraps { get; set; }
public Option<DateTime> LastTimedSpikeEvent { get; set; }

public WarpState MapWarpState { get; set; }

Expand Down Expand Up @@ -142,6 +146,7 @@ public void ResetState()
MapItems = new MapEntityCollectionHashSet<MapItem>(x => x.UniqueID, x => new MapCoordinate(x.X, x.Y));
OpenDoors = new HashSet<Warp>();
PendingDoors = new HashSet<Warp>();
LastTimedSpikeEvent = Option.None<DateTime>();
UnknownPlayerIDs = new HashSet<int>();
UnknownNPCIndexes = new HashSet<int>();

Expand Down
15 changes: 15 additions & 0 deletions EOLib/PacketHandlers/Effects/MapDebuffHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.Net.Handlers;
using Moffat.EndlessOnline.SDK.Protocol.Net;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;
using Optional;
using System;
using System.Collections.Generic;

Expand All @@ -14,6 +16,8 @@ namespace EOLib.PacketHandlers.Effects
public class MapDebuffHandler : InGameOnlyPacketHandler<EffectSpecServerPacket>
{
private readonly ICharacterRepository _characterRepository;
private readonly ICurrentMapProvider _currentMapProvider;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IEnumerable<IMainCharacterEventNotifier> _mainCharacterEventNotifiers;
private readonly IEnumerable<IEffectNotifier> _effectNotifiers;

Expand All @@ -23,11 +27,15 @@ public class MapDebuffHandler : InGameOnlyPacketHandler<EffectSpecServerPacket>

public MapDebuffHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterRepository characterRepository,
ICurrentMapProvider currentMapProvider,
ICurrentMapStateRepository currentMapStateRepository,
IEnumerable<IMainCharacterEventNotifier> mainCharacterEventNotifiers,
IEnumerable<IEffectNotifier> effectNotifiers)
: base(playerInfoProvider)
{
_characterRepository = characterRepository;
_currentMapProvider = currentMapProvider;
_currentMapStateRepository = currentMapStateRepository;
_mainCharacterEventNotifiers = mainCharacterEventNotifiers;
_effectNotifiers = effectNotifiers;
}
Expand All @@ -53,6 +61,13 @@ public override bool HandlePacket(EffectSpecServerPacket packet)
break;
case MapDamageType.Spikes:
{
if (_currentMapProvider.CurrentMap.Tiles[character.RenderProperties.MapY, character.RenderProperties.MapX] == IO.Map.TileSpec.SpikesTimed)
{
_currentMapStateRepository.LastTimedSpikeEvent = Option.Some(DateTime.Now);
foreach (var notifier in _effectNotifiers)
notifier.NotifyMapEffect(IO.Map.MapEffect.Spikes);
}

var data = (EffectSpecServerPacket.MapDamageTypeDataSpikes)packet.MapDamageTypeData;
character = character.WithStats(originalStats.WithNewStat(CharacterStat.HP, data.Hp)
.WithNewStat(CharacterStat.MaxHP, data.MaxHp));
Expand Down
7 changes: 7 additions & 0 deletions EOLib/PacketHandlers/Effects/TimedSpikeEffectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using EOLib.Net.Handlers;
using Moffat.EndlessOnline.SDK.Protocol.Net;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;
using Optional;
using System;
using System.Collections.Generic;

namespace EOLib.PacketHandlers.Effects
Expand All @@ -17,6 +19,7 @@ public class TimedSpikeEffectHandler : InGameOnlyPacketHandler<EffectReportServe
{
private readonly ICurrentMapProvider _currentMapProvider;
private readonly ICharacterProvider _characterProvider;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IEnumerable<IEffectNotifier> _effectNotifiers;

public override PacketFamily Family => PacketFamily.Effect;
Expand All @@ -26,16 +29,20 @@ public class TimedSpikeEffectHandler : InGameOnlyPacketHandler<EffectReportServe
public TimedSpikeEffectHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapProvider currentMapProvider,
ICharacterProvider characterProvider,
ICurrentMapStateRepository currentMapStateRepository,
IEnumerable<IEffectNotifier> effectNotifiers)
: base(playerInfoProvider)
{
_currentMapProvider = currentMapProvider;
_characterProvider = characterProvider;
_currentMapStateRepository = currentMapStateRepository;
_effectNotifiers = effectNotifiers;
}

public override bool HandlePacket(EffectReportServerPacket packet)
{
_currentMapStateRepository.LastTimedSpikeEvent = Option.Some(DateTime.Now);

var characterPosition = _characterProvider.MainCharacter.RenderProperties.Coordinates();
var distanceToSpikes = _currentMapProvider.CurrentMap.GetDistanceToClosestTileSpec(TileSpec.SpikesTimed, characterPosition);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace EndlessClient.Rendering.MapEntityRenderers
{
public class MapObjectLayerRenderer : BaseMapEntityRenderer
{
private const int TIMED_SPIKE_DURATION_MS = 1000;

private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly ICurrentMapProvider _currentMapProvider;
private readonly ICurrentMapStateProvider _currentMapStateProvider;
Expand Down Expand Up @@ -61,6 +63,14 @@ public override void RenderElementAt(SpriteBatch spriteBatch, int row, int col,
return;
}
}
else if (MapFile.Tiles[row, col] == TileSpec.SpikesTimed)
{
var shouldRender = _currentMapStateProvider.LastTimedSpikeEvent
.Map(time => (DateTime.Now - time).TotalMilliseconds <= TIMED_SPIKE_DURATION_MS)
.ValueOr(false);
if (!shouldRender)
return;
}

int gfxNum = MapFile.GFX[MapLayer.Objects][row, col];
var gfx = _nativeGraphicsManager.TextureFromResource(GFXTypes.MapObjects, gfxNum, true);
Expand Down

0 comments on commit 5c797bc

Please sign in to comment.