Skip to content

Commit

Permalink
Address todo items related to party/group
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Jun 14, 2022
1 parent 6181881 commit 4b4b866
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 0 additions & 1 deletion EOLib/Domain/Character/CharacterActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public void CastSpell(int spellId, ISpellTargetable target)

if (data.Target == IO.SpellTarget.Group)
{
// todo: implement packet handling for group target spells
builder = builder
.AddShort((short)spellId)
.AddThree(DateTime.Now.ToEOTimeStamp());
Expand Down
11 changes: 9 additions & 2 deletions EOLib/Domain/Chat/ChatActions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Party;
using EOLib.Net;
using EOLib.Net.Builders;
using EOLib.Net.Communication;
Expand All @@ -15,13 +16,15 @@ public enum ChatResult
HideSpeechBubble,
Command,
AdminAnnounce,
HideAll,
}

[AutoMappedType]
public class ChatActions : IChatActions
{
private readonly IChatRepository _chatRepository;
private readonly ICharacterProvider _characterProvider;
private readonly IPartyDataProvider _partyDataProvider;
private readonly IChatTypeCalculator _chatTypeCalculator;
private readonly IChatPacketBuilder _chatPacketBuilder;
private readonly IPacketSendService _packetSendService;
Expand All @@ -30,6 +33,7 @@ public class ChatActions : IChatActions

public ChatActions(IChatRepository chatRepository,
ICharacterProvider characterProvider,
IPartyDataProvider partyDataProvider,
IChatTypeCalculator chatTypeCalculator,
IChatPacketBuilder chatPacketBuilder,
IPacketSendService packetSendService,
Expand All @@ -38,6 +42,7 @@ public ChatActions(IChatRepository chatRepository,
{
_chatRepository = chatRepository;
_characterProvider = characterProvider;
_partyDataProvider = partyDataProvider;
_chatTypeCalculator = chatTypeCalculator;
_chatPacketBuilder = chatPacketBuilder;
_packetSendService = packetSendService;
Expand All @@ -47,8 +52,6 @@ public ChatActions(IChatRepository chatRepository,

public (ChatResult, string) SendChatToServer(string chat, string targetCharacter)
{
// todo: if not in a group, don't do group chat

var chatType = _chatTypeCalculator.CalculateChatType(chat);

if (chatType == ChatType.Command)
Expand All @@ -66,6 +69,10 @@ public ChatActions(IChatRepository chatRepository,
else if (string.IsNullOrEmpty(_chatRepository.PMTarget2))
_chatRepository.PMTarget2 = targetCharacter;
}
else if (chatType == ChatType.Party && !_partyDataProvider.Members.Any())
{
return (ChatResult.HideAll, String.Empty);
}

chat = _chatProcessor.RemoveFirstCharacterIfNeeded(chat, chatType, targetCharacter);
var (ok, filtered) = _chatProcessor.FilterCurses(chat);
Expand Down
1 change: 1 addition & 0 deletions EndlessClient/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void SendChatAndClearTextBox()
break;
case ChatResult.AdminAnnounce: _sfxPlayer.PlaySfx(SoundEffectID.AdminAnnounceReceived); break;
case ChatResult.HideSpeechBubble: break; // no-op
case ChatResult.HideAll: break; // no-op
}
}

Expand Down
9 changes: 8 additions & 1 deletion EndlessClient/HUD/Chat/ChatBubbleActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using EndlessClient.Rendering.Chat;
using EndlessClient.Rendering.NPC;
using EOLib.Domain.Chat;
using EOLib.Domain.Party;
using Optional;
using System.Linq;

namespace EndlessClient.HUD.Chat
{
Expand All @@ -14,30 +16,35 @@ public class ChatBubbleActions : IChatBubbleActions
private readonly IChatTypeCalculator _chatTypeCalculator;
private readonly ICharacterRendererProvider _characterRendererProvider;
private readonly INPCRendererProvider _npcRendererProvider;
private readonly IPartyDataProvider _partyDataProvider;
private readonly IChatBubbleFactory _chatBubbleFactory;

public ChatBubbleActions(IChatProcessor chatProcessor,
IChatTypeCalculator chatTypeCalculator,
ICharacterRendererProvider characterRendererProvider,
INPCRendererProvider npcRendererProvider,
IPartyDataProvider partyDataProvider,
IChatBubbleFactory chatBubbleFactory)
{
_chatProcessor = chatProcessor;
_chatTypeCalculator = chatTypeCalculator;
_characterRendererProvider = characterRendererProvider;
_npcRendererProvider = npcRendererProvider;
_partyDataProvider = partyDataProvider;
_chatBubbleFactory = chatBubbleFactory;
}

public void ShowChatBubbleForMainCharacter(string input)
{
//todo: don't show chat bubble if group chat and character is not in a group (party)
_characterRendererProvider.MainCharacterRenderer.MatchSome(r =>
{
_chatTypeCalculator.CalculateChatType(input)
.SomeWhen(x => x == ChatType.Local || x == ChatType.Party || x == ChatType.Announce)
.MatchSome(chatType =>
{
if (!_partyDataProvider.Members.Any() && chatType == ChatType.Party)
return;

var text = _chatProcessor.RemoveFirstCharacterIfNeeded(input, chatType, string.Empty);
r.ShowChatBubble(text, chatType == ChatType.Party);
});
Expand Down

0 comments on commit 4b4b866

Please sign in to comment.