Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement jukebox dialog #312

Merged
merged 8 commits into from
May 19, 2023
11 changes: 10 additions & 1 deletion EOLib.Localization/EOResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public enum EOResourceID
DIALOG_SHOP_CRAFT_MISSING_INGREDIENTS = 158,
DIALOG_SHOP_CRAFT_PUT_INGREDIENTS_TOGETHER = 159,

DIALOG_WORD_CURRENT = 163,

DIALOG_TRADE_BOTH_PLAYERS_OFFER_ONE_ITEM = 165,

DIALOG_TRANSFER_TRANSFER = 176,
Expand All @@ -172,6 +174,14 @@ public enum EOResourceID

STATUS_LABEL_KEEP_MOVING_THROUGH_PLAYER = 278,

JUKEBOX_NOW_VIEWED = 279,
JUKEBOX_BROWSE_THROUGH_SONGS = 280,
JUKEBOX_PLAY_SONG = 281,
JUKEBOX_REQUEST_SONG = 282,
JUKEBOX_REQUEST_SONG_FOR = 283,
JUKEBOX_PLAYING_REQUEST = 284,
JUKEBOX_IS_READY = 285,

DIALOG_TITLE_PERFORMANCE = 286,
DIALOG_PERFORMANCE_TOTALEXP = 287,
DIALOG_PERFORMANCE_NEXT_LEVEL = 288,
Expand All @@ -185,7 +195,6 @@ public enum EOResourceID
IDLE_TOO_LONG = 295,
IDLE_PLEASE_START_MOVING = 296,


SKILLMASTER_WORD_SPELL = 297,
SKILLMASTER_WORD_SKILL = 298,
SPELL_WAS_SELECTED = 299,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Map;
using EOLib.IO;
using EOLib.IO.Repositories;
using EOLib.Net;
using EOLib.Net.Communication;
using Optional.Collections;
using System;

namespace EOLib.Domain.Jukebox
namespace EOLib.Domain.Interact.Jukebox
{
[AutoMappedType]
public class JukeboxActions : IJukeboxActions
Expand Down Expand Up @@ -42,10 +43,23 @@ public void PlayNote(int noteIndex)
_packetSendService.SendPacket(packet);
});
}

public void RequestSong(MapCoordinate coordinate, int songIndex)
{
var packet = new PacketBuilder(PacketFamily.JukeBox, PacketAction.Message)
.AddChar(coordinate.X)
.AddChar(coordinate.Y)
.AddShort(songIndex)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IJukeboxActions
{
void PlayNote(int noteIndex);

void RequestSong(MapCoordinate coordinate, int songIndex);
}
}
32 changes: 32 additions & 0 deletions EOLib/Domain/Interact/Jukebox/JukeboxDataRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using AutomaticTypeMapper;
using EOLib.Domain.Map;
using Optional;

namespace EOLib.Domain.Interact.Jukebox
{
public interface IJukeboxRepository
{
Option<string> PlayingRequestName { get; set; }
}

public interface IJukeboxProvider
{
Option<string> PlayingRequestName { get; }
}

[AutoMappedType(IsSingleton = true)]
public class JukeboxDataRepository : IJukeboxRepository, IJukeboxProvider, IResettable
{
public Option<string> PlayingRequestName { get; set; }

public JukeboxDataRepository()
{
ResetState();
}

public void ResetState()
{
PlayingRequestName = Option.None<string>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Amadevus.RecordGenerator;
using EOLib.IO.Map;

namespace EOLib.Domain.Interact.Board
namespace EOLib.Domain.Interact
{
[Record]
public sealed partial class BoardMapEntity : IMapEntity
public sealed partial class TileSpecMapEntity : IMapEntity
{
public int X { get; }

Expand Down
12 changes: 12 additions & 0 deletions EOLib/Domain/Map/MapActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public void OpenBoard(TileSpec boardSpec)

_packetSendService.SendPacket(packet);
}

public void OpenJukebox(MapCoordinate location)
{
var packet = new PacketBuilder(PacketFamily.JukeBox, PacketAction.Open)
.AddChar(location.X)
.AddChar(location.Y)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IMapActions
Expand All @@ -106,5 +116,7 @@ public interface IMapActions
void OpenLocker(MapCoordinate location);

void OpenBoard(TileSpec boardSpec);

void OpenJukebox(MapCoordinate location);
}
}
4 changes: 4 additions & 0 deletions EOLib/Domain/Notifiers/ISoundNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ namespace EOLib.Domain.Notifiers
public interface ISoundNotifier
{
void NotifySoundEffect(int soundEffectId);

void NotifyMusic(int musicEffectId, bool isJukebox);
}

[AutoMappedType]
public class NoOpSoundNotifier : ISoundNotifier
{
public void NotifySoundEffect(int soundEffectId) { }

public void NotifyMusic(int musicEffectId, bool isJukebox) { }
}
}
39 changes: 39 additions & 0 deletions EOLib/PacketHandlers/Jukebox/JukeboxAgreeHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Net;
using EOLib.Net.Handlers;
using Optional.Collections;

namespace EOLib.PacketHandlers.Jukebox
{
/// <summary>
/// Sent to update character's remaining gold after requesting a song
/// </summary>
[AutoMappedType]
public class JukeboxAgreeHandler : InGameOnlyPacketHandler
{
private readonly ICharacterInventoryRepository _characterInventoryRepository;

public override PacketFamily Family => PacketFamily.JukeBox;

public override PacketAction Action => PacketAction.Agree;

public JukeboxAgreeHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterInventoryRepository characterInventoryRepository)
: base(playerInfoProvider)
{
_characterInventoryRepository = characterInventoryRepository;
}

public override bool HandlePacket(IPacket packet)
{
var goldRemaining = packet.ReadInt();

_characterInventoryRepository.ItemInventory.SingleOrNone(x => x.ItemID == 1).MatchSome(x => _characterInventoryRepository.ItemInventory.Remove(x));
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(1, goldRemaining));

return true;
}
}
}
51 changes: 51 additions & 0 deletions EOLib/PacketHandlers/Jukebox/JukeboxOpenHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using AutomaticTypeMapper;
using EOLib.Domain.Interact.Jukebox;
using EOLib.Domain.Login;
using EOLib.Domain.Notifiers;
using EOLib.Net;
using EOLib.Net.Handlers;
using Optional;
using System.Collections.Generic;
using System.IO;

namespace EOLib.PacketHandlers.Jukebox
{
[AutoMappedType]
public class JukeboxOpenHandler : InGameOnlyPacketHandler
{
private readonly IJukeboxRepository _jukeboxRepository;
private readonly IEnumerable<IUserInterfaceNotifier> _userInterfaceNotifiers;

public override PacketFamily Family => PacketFamily.JukeBox;

public override PacketAction Action => PacketAction.Open;

public JukeboxOpenHandler(IPlayerInfoProvider playerInfoProvider,
IJukeboxRepository jukeboxRepository,
IEnumerable<IUserInterfaceNotifier> userInterfaceNotifiers)
: base(playerInfoProvider)
{
_jukeboxRepository = jukeboxRepository;
_userInterfaceNotifiers = userInterfaceNotifiers;
}

public override bool HandlePacket(IPacket packet)
{
packet.Seek(2, SeekOrigin.Current);

if (packet.ReadPosition < packet.Length)
{
_jukeboxRepository.PlayingRequestName = Option.Some(packet.ReadEndString());
}
else
{
_jukeboxRepository.PlayingRequestName = Option.None<string>();
}

foreach (var notifier in _userInterfaceNotifiers)
notifier.NotifyPacketDialog(PacketFamily.JukeBox);

return true;
}
}
}
37 changes: 37 additions & 0 deletions EOLib/PacketHandlers/Jukebox/JukeboxPlayerHandler.cs
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.Jukebox
{
/// <summary>
/// Sent when background music should be changed (currently only in weddings)
/// </summary>
[AutoMappedType]
public class JukeboxPlayerHandler : InGameOnlyPacketHandler
{
private readonly IEnumerable<ISoundNotifier> _soundNotifiers;

public override PacketFamily Family => PacketFamily.JukeBox;

public override PacketAction Action => PacketAction.Player;

public JukeboxPlayerHandler(IPlayerInfoProvider playerInfoProvider,
IEnumerable<ISoundNotifier> soundNotifiers)
: base(playerInfoProvider)
{
_soundNotifiers = soundNotifiers;
}

public override bool HandlePacket(IPacket packet)
{
var id = packet.ReadChar();
foreach (var notifier in _soundNotifiers)
notifier.NotifyMusic(id, isJukebox: false);
return true;
}
}
}
46 changes: 46 additions & 0 deletions EOLib/PacketHandlers/Jukebox/JukeboxUseHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using AutomaticTypeMapper;
using EOLib.Domain.Interact.Jukebox;
using EOLib.Domain.Login;
using EOLib.Domain.Notifiers;
using EOLib.Net;
using EOLib.Net.Handlers;
using Optional;
using System.Collections.Generic;

namespace EOLib.PacketHandlers.Jukebox
{
/// <summary>
/// Sent when a Jukebox track should be played
/// </summary>
[AutoMappedType]
public class JukeboxUseHandler : InGameOnlyPacketHandler
{
private readonly IJukeboxRepository _jukeboxRepository;
private readonly IEnumerable<ISoundNotifier> _soundNotifiers;

public override PacketFamily Family => PacketFamily.JukeBox;

public override PacketAction Action => PacketAction.Use;

public JukeboxUseHandler(IPlayerInfoProvider playerInfoProvider,
IJukeboxRepository jukeboxRepository,
IEnumerable<ISoundNotifier> soundNotifiers)
: base(playerInfoProvider)
{
_jukeboxRepository = jukeboxRepository;
_soundNotifiers = soundNotifiers;
}

public override bool HandlePacket(IPacket packet)
{
var id = packet.ReadShort();

_jukeboxRepository.PlayingRequestName = Option.Some(string.Empty);

foreach (var notifier in _soundNotifiers)
notifier.NotifyMusic(id, isJukebox: true);

return true;
}
}
}
1 change: 1 addition & 0 deletions EOLib/misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static class Constants

public const string SfxDirectory = "sfx";
public const string MfxDirectory = "mfx";
public const string JboxDirectory = "jbox";

public const string FriendListFile = "config/friends.ini";
public const string IgnoreListFile = "config/ignore.ini";
Expand Down
6 changes: 6 additions & 0 deletions EndlessClient/Audio/AudioActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EOLib.Config;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.IO.Map;

namespace EndlessClient.Audio
{
Expand Down Expand Up @@ -59,6 +60,11 @@ public void NotifySoundEffect(int soundEffectId)
{
_sfxPlayer.PlaySfx((SoundEffectID)soundEffectId);
}

public void NotifyMusic(int musicEffectId, bool isJukebox)
{
_mfxPlayer.PlayBackgroundMusic(musicEffectId, MusicControl.InterruptIfDifferentPlayOnce, isJukebox);
}
}

public interface IAudioActions
Expand Down