Skip to content

Commit

Permalink
Merge pull request #392 from ethanmoffat/render_bugs
Browse files Browse the repository at this point in the history
Fix remaining rendering bugs
  • Loading branch information
ethanmoffat authored Oct 30, 2024
2 parents b8ee542 + ad19a8f commit 1ceb620
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 182 deletions.
19 changes: 10 additions & 9 deletions EOBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,20 @@ public void ShowNPCSpeechBubble(int npcIndex, string message)
{
}

public void StartNPCAttackAnimation(int npcIndex)
public void StartNPCAttackAnimation(int npcIndex, EODirection direction)
{
}

public void StartNPCWalkAnimation(int npcIndex)
public void StartNPCWalkAnimation(int npcIndex, MapCoordinate coordinate, EODirection direction)
{
// immediately walk the NPC to the destination index
var npc = _currentMapStateRepository.NPCs.SingleOrDefault(x => x.Index == npcIndex);
if (npc == null) return;

var newNpc = npc.WithX(npc.GetDestinationX()).WithY(npc.GetDestinationY()).WithFrame(NPCFrame.Standing);
_currentMapStateRepository.NPCs.Remove(npc);
_currentMapStateRepository.NPCs.Add(newNpc);
if (_currentMapStateRepository.NPCs.TryGetValue(npcIndex, out var npc))
{
// immediately walk the NPC to the destination index
_currentMapStateRepository.NPCs.Update(
npc,
npc.WithDirection(direction).WithX(coordinate.X).WithY(coordinate.Y)
);
}
}

public void NPCDropItem(MapItem item)
Expand Down
10 changes: 10 additions & 0 deletions EOLib/Domain/Extensions/MapCoordinateExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using EOLib.Domain.Map;
using Moffat.EndlessOnline.SDK.Protocol;

namespace EOLib.Domain.Extensions
{
public static class MapCoordinateExtensions
{
public static MapCoordinate ToCoordinate(this Coords coords) => new MapCoordinate(coords.X, coords.Y);
}
}
8 changes: 4 additions & 4 deletions EOLib/Domain/Notifiers/INPCActionNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace EOLib.Domain.Notifiers
{
public interface INPCActionNotifier
{
void StartNPCWalkAnimation(int npcIndex);
void StartNPCWalkAnimation(int npcIndex, MapCoordinate coords, EODirection direction);

void StartNPCAttackAnimation(int npcIndex);
void StartNPCAttackAnimation(int npcIndex, EODirection direction);

void RemoveNPCFromView(int npcIndex, int playerId, Option<int> spellId, Option<int> damage, bool showDeathAnimation);

Expand All @@ -22,9 +22,9 @@ public interface INPCActionNotifier
[AutoMappedType]
public class NoOpNPCActionNotifier : INPCActionNotifier
{
public void StartNPCWalkAnimation(int npcIndex) { }
public void StartNPCWalkAnimation(int npcIndex, MapCoordinate coords, EODirection direction) { }

public void StartNPCAttackAnimation(int npcIndex) { }
public void StartNPCAttackAnimation(int npcIndex, EODirection direction) { }

public void RemoveNPCFromView(int npcIndex, int playerId, Option<int> spellId, Option<int> damage, bool showDeathAnimation) { }

Expand Down
4 changes: 2 additions & 2 deletions EOLib/PacketHandlers/NPC/NPCDeathHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ protected void UpdatePlayerExperience(int experienceValue)
foreach (var notifier in _mainCharacterEventNotifiers)
notifier.NotifyGainedExp(expDifference);

UpdateCharacterStat(CharacterStat.Experience, experienceValue);

_characterSessionRepository.LastKillExp = expDifference;
if (expDifference > _characterSessionRepository.BestKillExp)
_characterSessionRepository.BestKillExp = expDifference;
_characterSessionRepository.TodayTotalExp += Convert.ToUInt64(Math.Max(expDifference, 0));
}

UpdateCharacterStat(CharacterStat.Experience, experienceValue);
}

protected void ApplyStats(LevelUpStats levelUpStats)
Expand Down
86 changes: 31 additions & 55 deletions EOLib/PacketHandlers/NPC/NPCPlayerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
using EOLib.Net.Handlers;
using Moffat.EndlessOnline.SDK.Protocol.Net;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;
using Optional;
using Optional.Collections;
using DomainNPC = EOLib.Domain.NPC.NPC;

namespace EOLib.PacketHandlers.NPC
{
Expand Down Expand Up @@ -78,18 +75,15 @@ private void HandleNPCWalk(IReadOnlyList<NpcUpdatePosition> positions)
{
foreach (var position in positions)
{
var npc = GetNPC(position.NpcIndex);
npc.Match(
some: n =>
{
var updated = n.WithDirection((EODirection)position.Direction);
updated = EnsureCorrectXAndY(updated, position.Coords.X, position.Coords.Y);
_currentMapStateRepository.NPCs.Update(n, updated);

foreach (var notifier in _npcAnimationNotifiers)
notifier.StartNPCWalkAnimation(n.Index);
},
none: () => _currentMapStateRepository.UnknownNPCIndexes.Add(position.NpcIndex));
if (_currentMapStateRepository.NPCs.TryGetValue(position.NpcIndex, out var npc))
{
foreach (var notifier in _npcAnimationNotifiers)
notifier.StartNPCWalkAnimation(npc.Index, position.Coords.ToCoordinate(), (EODirection)position.Direction);
}
else
{
_currentMapStateRepository.UnknownNPCIndexes.Add(position.NpcIndex);
}
}
}

Expand Down Expand Up @@ -130,55 +124,37 @@ private void HandleNPCAttack(IReadOnlyList<NpcUpdateAttack> attacks)
_currentMapStateRepository.UnknownPlayerIDs.Add(characterID);
}

var npc = GetNPC(index);
npc.Match(
some: n =>
{
var updated = n.WithDirection(npcDirection);
_currentMapStateRepository.NPCs.Update(n, updated);

foreach (var notifier in _npcAnimationNotifiers)
notifier.StartNPCAttackAnimation(index);
},
none: () => _currentMapStateRepository.UnknownNPCIndexes.Add(index));
if (_currentMapStateRepository.NPCs.TryGetValue(index, out var npc))
{
foreach (var notifier in _npcAnimationNotifiers)
notifier.StartNPCAttackAnimation(index, (EODirection)attack.Direction);
}
else
{
_currentMapStateRepository.UnknownNPCIndexes.Add(index);
}
}
}

private void HandleNPCTalk(IReadOnlyList<NpcUpdateChat> chats)
{
foreach (var chat in chats)
{
var npc = GetNPC(chat.NpcIndex);
npc.Match(
some: n =>
{
var npcData = _enfFileProvider.ENFFile[n.ID];

var chatData = new ChatData(ChatTab.Local, npcData.Name, chat.Message, ChatIcon.Note, filter: false);
_chatRepository.AllChat[ChatTab.Local].Add(chatData);

foreach (var notifier in _npcAnimationNotifiers)
notifier.ShowNPCSpeechBubble(chat.NpcIndex, chat.Message);
},
none: () => _currentMapStateRepository.UnknownNPCIndexes.Add(chat.NpcIndex));
}
}
if (_currentMapStateRepository.NPCs.TryGetValue(chat.NpcIndex, out var npc))
{
var npcData = _enfFileProvider.ENFFile[npc.ID];

private Option<DomainNPC> GetNPC(int index)
{
return _currentMapStateRepository.NPCs.SingleOrNone(n => n.Index == index);
}
var chatData = new ChatData(ChatTab.Local, npcData.Name, chat.Message, ChatIcon.Note, filter: false);
_chatRepository.AllChat[ChatTab.Local].Add(chatData);

private static DomainNPC EnsureCorrectXAndY(DomainNPC npc, int destinationX, int destinationY)
{
var opposite = npc.Direction.Opposite();
var tempNPC = npc
.WithDirection(opposite)
.WithX(destinationX)
.WithY(destinationY);
return npc
.WithX(tempNPC.GetDestinationX())
.WithY(tempNPC.GetDestinationY());
foreach (var notifier in _npcAnimationNotifiers)
notifier.ShowNPCSpeechBubble(chat.NpcIndex, chat.Message);
}
else
{
_currentMapStateRepository.UnknownNPCIndexes.Add(chat.NpcIndex);
}
}
}
}
}
47 changes: 10 additions & 37 deletions EndlessClient/Dialogs/QuestDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EndlessClient.Content;
using EndlessClient.Dialogs.Services;
Expand Down Expand Up @@ -170,49 +169,23 @@ private void UpdateDialogDisplayText(QuestDialogData repoData)
{
case State.TalkToNpc:
{
var rows = new List<string>();

var ts = new TextSplitter(repoData.PageText[_pageIndex], _contentProvider.Fonts[Constants.FontSize09]);
if (!ts.NeedsProcessing)
rows.Add(repoData.PageText[_pageIndex]);
else
rows.AddRange(ts.SplitIntoLines());

int index = 0;
foreach (var row in rows)
{
var rowItem = new ListDialogItem(this, ListDialogItem.ListItemStyle.Small, index++)
{
PrimaryText = row,
};

AddItemToList(rowItem, sortList: false);
}
AddTextAsListItems(_contentProvider.Fonts[Constants.FontSize08pt5], insertLineBreaks: true, [], repoData.PageText[_pageIndex].Replace("\n", string.Empty));

// The links are only shown on the last page of the quest dialog
if (_pageIndex < repoData.PageText.Count - 1)
return;

var item = new ListDialogItem(this, ListDialogItem.ListItemStyle.Small, index++) { PrimaryText = " " };
AddItemToList(item, sortList: false);

foreach (var action in repoData.Actions)
var linkClickActions = repoData.Actions.Select(action =>
{
var actionItem = new ListDialogItem(this, ListDialogItem.ListItemStyle.Small, index++)
{
PrimaryText = action.DisplayText
};

var linkIndex = action.ActionID;
actionItem.SetPrimaryClickAction((_, _) =>
{
_questActions.RespondToQuestDialog(DialogReply.Link, linkIndex);
ClickSoundEffect?.Invoke(this, EventArgs.Empty);
Close(XNADialogResult.Cancel);
});

AddItemToList(actionItem, sortList: false);
}
return new Action(() =>
{
_questActions.RespondToQuestDialog(DialogReply.Link, linkIndex);
ClickSoundEffect?.Invoke(this, EventArgs.Empty);
Close(XNADialogResult.Cancel);
});
}).ToList();
AddTextAsListItems(_contentProvider.Fonts[Constants.FontSize08pt5], insertLineBreaks: false, linkClickActions, repoData.Actions.Select(x => $"*{x.DisplayText}").ToArray());
}
break;
case State.SwitchQuest:
Expand Down
12 changes: 6 additions & 6 deletions EndlessClient/Rendering/Map/MapEntityRendererProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ public MapEntityRendererProvider(INativeGraphicsManager nativeGraphicsManager,
currentMapProvider,
characterProvider,
gridDrawCoordinateCalculator,
clientWindowSizeProvider),
new MapItemLayerRenderer(characterProvider,
gridDrawCoordinateCalculator,
clientWindowSizeProvider,
currentMapStateProvider,
mapItemGraphicProvider)
clientWindowSizeProvider)
};

MapEntityRenderers = new List<IMapEntityRenderer>
{
new MapItemLayerRenderer(characterProvider,
gridDrawCoordinateCalculator,
clientWindowSizeProvider,
currentMapStateProvider,
mapItemGraphicProvider),
new ShadowLayerRenderer(nativeGraphicsManager,
currentMapProvider,
characterProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ static BaseMapEntityRenderer()

public abstract MapRenderLayer RenderLayer { get; }

public bool ShouldRenderLast => RenderLayer == MapRenderLayer.Overlay2 || RenderLayer == MapRenderLayer.MainCharacterTransparent;
public bool ShouldRenderLast => RenderLayer == MapRenderLayer.Overlay ||
RenderLayer == MapRenderLayer.Overlay2 ||
RenderLayer == MapRenderLayer.MainCharacterTransparent;

protected abstract int RenderDistance { get; }

Expand Down
32 changes: 26 additions & 6 deletions EndlessClient/Rendering/MapEntityRenderers/RoofLayerRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EndlessClient.Rendering.Map;
using System.Collections.Generic;
using EndlessClient.Rendering.Map;
using EOLib.Domain.Character;
using EOLib.Domain.Map;
using EOLib.Graphics;
Expand Down Expand Up @@ -30,16 +31,35 @@ public RoofLayerRenderer(INativeGraphicsManager nativeGraphicsManager,

protected override bool ElementExistsAt(int row, int col)
{
return CurrentMap.GFX[MapLayer.Roof][row, col] > 0;
if (row == CurrentMap.Properties.Height)
{
return CurrentMap.GFX[MapLayer.Roof][row, col] > 0 ||
CurrentMap.GFX[MapLayer.Roof][row - 1, col] > 0;
}

return row - 1 >= 0 && CurrentMap.GFX[MapLayer.Roof][row - 1, col] > 0;
}

public override void RenderElementAt(SpriteBatch spriteBatch, int row, int col, int alpha, Vector2 additionalOffset = default)
{
int gfxNum = CurrentMap.GFX[MapLayer.Roof][row, col];
var gfx = _nativeGraphicsManager.TextureFromResource(GFXTypes.MapWallTop, gfxNum, true);
var gfxCandidates = new List<int>();
if (CurrentMap.GFX[MapLayer.Roof][row - 1, col] > 0)
{
gfxCandidates.Add(CurrentMap.GFX[MapLayer.Roof][row - 1, col]);
}

if (row == CurrentMap.Properties.Height && CurrentMap.GFX[MapLayer.Roof][row, col] > 0)
{
gfxCandidates.Add(CurrentMap.GFX[MapLayer.Roof][row, col]);
}

foreach (var gfxNum in gfxCandidates)
{
var gfx = _nativeGraphicsManager.TextureFromResource(GFXTypes.MapWallTop, gfxNum, true);

var pos = GetDrawCoordinatesFromGridUnits(col, row);
spriteBatch.Draw(gfx, pos + additionalOffset, Color.FromNonPremultiplied(255, 255, 255, alpha));
var pos = GetDrawCoordinatesFromGridUnits(col, row - 1);
spriteBatch.Draw(gfx, pos + additionalOffset, Color.FromNonPremultiplied(255, 255, 255, alpha));
}
}

private IMapFile CurrentMap => _currentMapProvider.CurrentMap;
Expand Down
9 changes: 5 additions & 4 deletions EndlessClient/Rendering/NPC/NPCActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using EndlessClient.HUD.Chat;
using EndlessClient.HUD.Controls;
using EndlessClient.Rendering.Character;
using EOLib;
using EOLib.Domain.Chat;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
Expand Down Expand Up @@ -50,20 +51,20 @@ public NPCActions(IHudControlProvider hudControlProvider,
_sfxPlayer = sfxPlayer;
}

public void StartNPCWalkAnimation(int npcIndex)
public void StartNPCWalkAnimation(int npcIndex, MapCoordinate coords, EODirection direction)
{
if (!_hudControlProvider.IsInGame)
return;

Animator.StartWalkAnimation(npcIndex);
Animator.StartWalkAnimation(npcIndex, coords, direction);
}

public void StartNPCAttackAnimation(int npcIndex)
public void StartNPCAttackAnimation(int npcIndex, EODirection direction)
{
if (!_hudControlProvider.IsInGame)
return;

Animator.StartAttackAnimation(npcIndex);
Animator.StartAttackAnimation(npcIndex, direction);

_sfxPlayer.PlaySfx(SoundEffectID.PunchAttack);
}
Expand Down
Loading

0 comments on commit 1ceb620

Please sign in to comment.