Skip to content

Commit

Permalink
Implement drunk action from using beer types items. Implement drunk t…
Browse files Browse the repository at this point in the history
…ext transformation
  • Loading branch information
ethanmoffat committed Mar 31, 2022
1 parent 32d71e5 commit ac42e7c
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 71 deletions.
2 changes: 2 additions & 0 deletions EOBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public void JunkItem(short id, int amountRemoved)
var maxWeight = _characterProvider.MainCharacter.Stats[CharacterStat.MaxWeight];
ConsoleHelper.WriteMessage(ConsoleHelper.Type.JunkItem, $"{weight,3}/{maxWeight,3} - weight - {inventoryCount?.Amount ?? 0} in inventory");
}

public void MakeDrunk() { }
}

[AutoMappedType]
Expand Down
12 changes: 12 additions & 0 deletions EOLib/Domain/Character/CharacterRenderProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CharacterRenderProperties : ICharacterRenderProperties

public bool IsHidden { get; private set; }
public bool IsDead { get; private set; }
public bool IsDrunk { get; private set; }

public bool IsRangedWeapon { get; private set; }

Expand Down Expand Up @@ -232,6 +233,13 @@ public ICharacterRenderProperties WithAlive()
return props;
}

public ICharacterRenderProperties WithIsDrunk(bool drunk)
{
var props = MakeCopy(this);
props.IsDrunk = drunk;
return props;
}

public object Clone()
{
return MakeCopy(this);
Expand Down Expand Up @@ -269,6 +277,8 @@ private static CharacterRenderProperties MakeCopy(ICharacterRenderProperties oth

IsHidden = other.IsHidden,
IsDead = other.IsDead,
IsDrunk = other.IsDrunk,

IsRangedWeapon = other.IsRangedWeapon
};
}
Expand Down Expand Up @@ -298,6 +308,7 @@ public override bool Equals(object obj)
Emote == properties.Emote &&
IsHidden == properties.IsHidden &&
IsDead == properties.IsDead &&
IsDrunk == properties.IsDrunk &&
IsRangedWeapon == properties.IsRangedWeapon;
}

Expand Down Expand Up @@ -326,6 +337,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + Emote.GetHashCode();
hashCode = hashCode * -1521134295 + IsHidden.GetHashCode();
hashCode = hashCode * -1521134295 + IsDead.GetHashCode();
hashCode = hashCode * -1521134295 + IsDrunk.GetHashCode();
hashCode = hashCode * -1521134295 + IsRangedWeapon.GetHashCode();
return hashCode;
}
Expand Down
3 changes: 3 additions & 0 deletions EOLib/Domain/Character/ICharacterRenderProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public interface ICharacterRenderProperties : ICloneable

bool IsHidden { get; }
bool IsDead { get; }
bool IsDrunk { get; }

bool IsRangedWeapon { get; }

Expand Down Expand Up @@ -63,5 +64,7 @@ public interface ICharacterRenderProperties : ICloneable
ICharacterRenderProperties WithIsHidden(bool hidden);
ICharacterRenderProperties WithDead();
ICharacterRenderProperties WithAlive();

ICharacterRenderProperties WithIsDrunk(bool drunk);
}
}
13 changes: 9 additions & 4 deletions EOLib/Domain/Chat/ChatActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public ChatActions(IChatRepository chatRepository,
_chatProcessor = chatProcessor;
}

public async Task SendChatToServer(string chat, string targetCharacter)
public string SendChatToServer(string chat, string targetCharacter)
{
var chatType = _chatTypeCalculator.CalculateChatType(chat);

if (chatType == ChatType.Command)
{
if (HandleCommand(chat))
return;
return chat;

//treat unhandled command as local chat
chatType = ChatType.Local;
Expand All @@ -59,10 +59,15 @@ public async Task SendChatToServer(string chat, string targetCharacter)

chat = _chatProcessor.RemoveFirstCharacterIfNeeded(chat, chatType, targetCharacter);

if (_characterProvider.MainCharacter.RenderProperties.IsDrunk)
chat = _chatProcessor.MakeDrunk(chat);

var chatPacket = _chatPacketBuilder.BuildChatPacket(chatType, chat, targetCharacter);
await _packetSendService.SendPacketAsync(chatPacket);
_packetSendService.SendPacket(chatPacket);

AddChatForLocalDisplay(chatType, chat, targetCharacter);

return chat;
}

/// <summary>
Expand Down Expand Up @@ -126,6 +131,6 @@ private void AddChatForLocalDisplay(ChatType chatType, string chat, string targe

public interface IChatActions
{
Task SendChatToServer(string chat, string targetCharacter);
string SendChatToServer(string chat, string targetCharacter);
}
}
30 changes: 30 additions & 0 deletions EOLib/Domain/Chat/ChatProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.Linq;
using System.Text;
using AutomaticTypeMapper;

namespace EOLib.Domain.Chat
{
[AutoMappedType]
public class ChatProcessor : IChatProcessor
{
private readonly Random _random = new Random();

public string RemoveFirstCharacterIfNeeded(string chat, ChatType chatType, string targetCharacter)
{
switch (chatType)
Expand Down Expand Up @@ -33,10 +37,36 @@ public string RemoveFirstCharacterIfNeeded(string chat, ChatType chatType, strin
throw new ArgumentOutOfRangeException(nameof(chatType));
}
}

public string MakeDrunk(string input)
{
// implementation from Phorophor::notepad (thanks Apollo)
// https://discord.com/channels/723989119503696013/785190349026492437/791376941822246953
var ret = new StringBuilder();

foreach (var c in input)
{
var repeats = _random.Next(0, 8) < 6 ? 1 : 2;
ret.Append(c, repeats);

if ((c == 'a' || c == 'e') && _random.NextDouble() / 1.0 < 0.555)
ret.Append('j');

if ((c == 'u' || c == 'o') && _random.NextDouble() / 1.0 < 0.444)
ret.Append('w');

if ((c == ' ') && _random.NextDouble() / 1.0 < 0.333)
ret.Append(" *hic*");
}

return ret.ToString();
}
}

public interface IChatProcessor
{
string RemoveFirstCharacterIfNeeded(string input, ChatType chatType, string targetCharacter);

string MakeDrunk(string input);
}
}
4 changes: 4 additions & 0 deletions EOLib/Domain/Notifiers/IEmoteNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ namespace EOLib.Domain.Notifiers
public interface IEmoteNotifier
{
void NotifyEmote(short playerId, Emote emote);

void MakeMainPlayerDrunk();
}

[AutoMappedType]
public class NoOpEmoteNotifier : IEmoteNotifier
{
public void NotifyEmote(short playerId, Emote emote) { }

public void MakeMainPlayerDrunk() { }
}
}
7 changes: 3 additions & 4 deletions EOLib/PacketHandlers/Items/UseItemHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ public override bool HandlePacket(IPacket packet)
renderProps = renderProps.WithHairColor(hairColor);
break;
case ItemType.Beer:
// todo: drunk
// old logic:
// OldWorld.Instance.ActiveCharacterRenderer.MakeDrunk();
// m_game.Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_ITEM_USE_DRUNK);
renderProps = renderProps.WithIsDrunk(true);
foreach (var notifier in _emoteNotifiers)
notifier.MakeMainPlayerDrunk();
break;
case ItemType.EffectPotion:
var potionId = packet.ReadShort();
Expand Down
27 changes: 4 additions & 23 deletions EndlessClient/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,45 @@ public class ChatController : IChatController
private readonly IChatTextBoxActions _chatTextBoxActions;
private readonly IChatActions _chatActions;
private readonly IPrivateMessageActions _privateMessageActions;
private readonly IGameStateActions _gameStateActions;
private readonly IErrorDialogDisplayAction _errorDisplayAction;
private readonly IChatBubbleActions _chatBubbleActions;
private readonly ISafeNetworkOperationFactory _safeNetworkOperationFactory;
private readonly IHudControlProvider _hudControlProvider;

public ChatController(IChatTextBoxActions chatTextBoxActions,
IChatActions chatActions,
IPrivateMessageActions privateMessageActions,
IGameStateActions gameStateActions,
IErrorDialogDisplayAction errorDisplayAction,
IChatBubbleActions chatBubbleActions,
ISafeNetworkOperationFactory safeNetworkOperationFactory,
IHudControlProvider hudControlProvider)
{
_chatTextBoxActions = chatTextBoxActions;
_chatActions = chatActions;
_privateMessageActions = privateMessageActions;
_gameStateActions = gameStateActions;
_errorDisplayAction = errorDisplayAction;
_chatBubbleActions = chatBubbleActions;
_safeNetworkOperationFactory = safeNetworkOperationFactory;
_hudControlProvider = hudControlProvider;
}

public async Task SendChatAndClearTextBox()
public void SendChatAndClearTextBox()
{
var localTypedText = ChatTextBox.Text;
var targetCharacter = _privateMessageActions.GetTargetCharacter(localTypedText);
var sendChatOperation = _safeNetworkOperationFactory.CreateSafeAsyncOperation(
async () => await _chatActions.SendChatToServer(localTypedText, targetCharacter),
SetInitialStateAndShowError);

if (!await sendChatOperation.Invoke())
return;
var updatedChat = _chatActions.SendChatToServer(localTypedText, targetCharacter);

_chatTextBoxActions.ClearChatText();

_chatBubbleActions.ShowChatBubbleForMainCharacter(localTypedText);
_chatBubbleActions.ShowChatBubbleForMainCharacter(updatedChat);
}

public void SelectChatTextBox()
{
_chatTextBoxActions.FocusChatTextBox();
}

private void SetInitialStateAndShowError(NoDataSentException ex)
{
_gameStateActions.ChangeToState(GameStates.Initial);
_errorDisplayAction.ShowException(ex);
}

private ChatTextBox ChatTextBox => _hudControlProvider.GetComponent<ChatTextBox>(HudControlIdentifier.ChatTextBox);
}

public interface IChatController
{
Task SendChatAndClearTextBox();
void SendChatAndClearTextBox();

void SelectChatTextBox();
}
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Controllers/NumPadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Emote(Emote whichEmote)
var mainRenderer = _characterRendererProvider.MainCharacterRenderer;
mainRenderer.MatchSome(renderer =>
{
if (renderer.Character.RenderProperties.IsActing(CharacterActionState.Emote))
if (!renderer.Character.RenderProperties.IsActing(CharacterActionState.Standing))
return;

_characterActions.Emote(whichEmote);
Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/HUD/Controls/HudControlsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ private ChatTextBox CreateChatTextBox()
Visible = true,
DrawOrder = HUD_CONTROL_LAYER
};
chatTextBox.OnEnterPressed += async (o, e) => await _chatController.SendChatAndClearTextBox();
chatTextBox.OnClicked += (o, e) => _chatController.SelectChatTextBox();
chatTextBox.OnEnterPressed += (_, _) => _chatController.SendChatAndClearTextBox();
chatTextBox.OnClicked += (_, _) => _chatController.SelectChatTextBox();

return chatTextBox;
}
Expand Down
22 changes: 16 additions & 6 deletions EndlessClient/Rendering/Character/CharacterAnimationActions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutomaticTypeMapper;
using EndlessClient.ControlSets;
using EndlessClient.HUD;
using EndlessClient.HUD.Controls;
using EndlessClient.Rendering.Map;
using EOLib;
Expand All @@ -9,6 +10,7 @@
using EOLib.Domain.Notifiers;
using EOLib.IO.Map;
using EOLib.IO.Repositories;
using EOLib.Localization;
using Optional;

namespace EndlessClient.Rendering.Character
Expand All @@ -23,14 +25,16 @@ public class CharacterAnimationActions : ICharacterAnimationActions, IOtherChara
private readonly ICurrentMapProvider _currentMapProvider;
private readonly ISpikeTrapActions _spikeTrapActions;
private readonly IESFFileProvider _esfFileProvider;
private readonly IStatusLabelSetter _statusLabelSetter;

public CharacterAnimationActions(IHudControlProvider hudControlProvider,
ICharacterRepository characterRepository,
ICurrentMapStateProvider currentMapStateProvider,
ICharacterRendererProvider characterRendererProvider,
ICurrentMapProvider currentMapProvider,
ISpikeTrapActions spikeTrapActions,
IESFFileProvider esfFileProvider)
IESFFileProvider esfFileProvider,
IStatusLabelSetter statusLabelSetter)
{
_hudControlProvider = hudControlProvider;
_characterRepository = characterRepository;
Expand All @@ -39,6 +43,7 @@ public CharacterAnimationActions(IHudControlProvider hudControlProvider,
_currentMapProvider = currentMapProvider;
_spikeTrapActions = spikeTrapActions;
_esfFileProvider = esfFileProvider;
_statusLabelSetter = statusLabelSetter;
}

public void Face(EODirection direction)
Expand Down Expand Up @@ -176,6 +181,16 @@ public void NotifyEarthquake(byte strength)
mapRenderer.StartEarthquake(strength);
}

public void NotifyEmote(short playerId, Emote emote)
{
Animator.Emote(playerId, emote);
}

public void MakeMainPlayerDrunk()
{
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_ITEM_USE_DRUNK);
}

private void ShowWaterSplashiesIfNeeded(CharacterActionState action, int characterID)
{
var character = characterID == _characterRepository.MainCharacter.ID
Expand Down Expand Up @@ -211,11 +226,6 @@ private void ShowWaterSplashiesIfNeeded(CharacterActionState action, int charact
});
}

public void NotifyEmote(short playerId, Emote emote)
{
Animator.Emote(playerId, emote);
}

private ICharacterAnimator Animator => _hudControlProvider.GetComponent<ICharacterAnimator>(HudControlIdentifier.CharacterAnimator);
}

Expand Down
Loading

0 comments on commit ac42e7c

Please sign in to comment.