-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Barber Dialog and packets (#355)
Co-authored-by: Ethan Moffat <[email protected]>
- Loading branch information
1 parent
83b3fd4
commit 7c88f02
Showing
20 changed files
with
580 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Net; | ||
using EOLib.Net.Communication; | ||
using System.Diagnostics; | ||
using EOLib.Domain.Character; | ||
namespace EOLib.Domain.Interact.Barber | ||
{ | ||
[AutoMappedType] | ||
public class BarberActions : IBarberActions | ||
{ | ||
private readonly IPacketSendService _packetSendService; | ||
private readonly IBarberDataRepository _barberDataRepository; | ||
|
||
public BarberActions(IPacketSendService packetSendService, | ||
IBarberDataRepository barberDataRepository) | ||
{ | ||
_packetSendService = packetSendService; | ||
_barberDataRepository = barberDataRepository; | ||
} | ||
|
||
public void Purchase(int hairStyle, int hairColor) | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Barber, PacketAction.Buy) | ||
.AddChar((char)hairStyle) | ||
.AddChar((char)hairColor) | ||
.AddInt(_barberDataRepository.SessionID) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
} | ||
|
||
public interface IBarberActions | ||
{ | ||
void Purchase(int hairStyle, int hairColor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using AutomaticTypeMapper; | ||
|
||
namespace EOLib.Domain.Interact.Barber | ||
{ | ||
public interface IBarberDataRepository : IResettable | ||
{ | ||
int SessionID { get; set; } | ||
} | ||
|
||
public interface IBarberDataProvider : IResettable | ||
{ | ||
int SessionID { get; } | ||
} | ||
|
||
[AutoMappedType(IsSingleton = true)] | ||
public class BarberDataRepository : IBarberDataRepository, IBarberDataProvider | ||
{ | ||
public int SessionID { get; set; } | ||
|
||
public BarberDataRepository() | ||
{ | ||
ResetState(); | ||
} | ||
|
||
public void ResetState() | ||
{ | ||
SessionID = 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Interact; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
using EOLib.Domain.Interact.Barber; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Domain.Notifiers; | ||
|
||
namespace EOLib.PacketHandlers.Barber | ||
{ | ||
[AutoMappedType] | ||
public class BarberAgreeHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly IBarberDataRepository _barberDataRepository; | ||
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers; | ||
private readonly ICharacterRepository _characterRepository; | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
private readonly ICharacterInventoryRepository _characterInventoryRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Barber; | ||
public override PacketAction Action => PacketAction.Agree; | ||
|
||
public BarberAgreeHandler( | ||
IPlayerInfoProvider playerInfoProvider, | ||
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers, | ||
IBarberDataRepository barberDataRepository, | ||
ICharacterRepository characterRepository, | ||
ICurrentMapStateRepository currentMapStateRepository, | ||
ICharacterInventoryRepository characterInventoryRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_npcInteractionNotifiers = npcInteractionNotifiers; | ||
_barberDataRepository = barberDataRepository; | ||
_characterRepository = characterRepository; | ||
_currentMapStateRepository = currentMapStateRepository; | ||
_characterInventoryRepository = characterInventoryRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var amount = packet.ReadInt(); | ||
var gold = new InventoryItem(1, amount); | ||
var playerID = packet.ReadShort(); | ||
|
||
_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1); | ||
_characterInventoryRepository.ItemInventory.Add(gold); | ||
|
||
var currentCharacter = _characterRepository.MainCharacter.ID == playerID | ||
? _characterRepository.MainCharacter | ||
: null; | ||
|
||
if (currentCharacter == null) | ||
{ | ||
return false; | ||
} | ||
|
||
var currentRenderProps = currentCharacter.RenderProperties; | ||
var slot = (AvatarSlot)packet.ReadChar(); | ||
|
||
switch (slot) | ||
{ | ||
case AvatarSlot.Hair: | ||
if (packet.ReadChar() != 0) | ||
throw new MalformedPacketException("Missing expected 0 byte in updating hair packet", packet); | ||
|
||
currentRenderProps = currentRenderProps | ||
.WithHairStyle(packet.ReadChar()) | ||
.WithHairColor(packet.ReadChar()); | ||
break; | ||
|
||
case AvatarSlot.HairColor: | ||
if (packet.ReadChar() != 0) | ||
throw new MalformedPacketException("Missing expected 0 byte in updating hair color packet", packet); | ||
|
||
currentRenderProps = currentRenderProps | ||
.WithHairColor(packet.ReadChar()); | ||
break; | ||
} | ||
|
||
var updatedCharacter = currentCharacter.WithRenderProperties(currentRenderProps); | ||
|
||
if (_characterRepository.MainCharacter.ID == playerID) | ||
{ | ||
_characterRepository.MainCharacter = updatedCharacter; | ||
} | ||
else | ||
{ | ||
_currentMapStateRepository.Characters.Update(currentCharacter, updatedCharacter); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Interact; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
using EOLib.Domain.Interact.Barber; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
|
||
namespace EOLib.PacketHandlers.Barber | ||
{ | ||
[AutoMappedType] | ||
public class BarberOpenHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly IBarberDataRepository _barberDataRepository; | ||
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.Barber; | ||
public override PacketAction Action => PacketAction.Open; | ||
|
||
public BarberOpenHandler( | ||
IPlayerInfoProvider playerInfoProvider, | ||
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers, | ||
IBarberDataRepository barberDataRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_npcInteractionNotifiers = npcInteractionNotifiers; | ||
_barberDataRepository = barberDataRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var sessionId = packet.ReadInt(); | ||
_barberDataRepository.SessionID = sessionId; | ||
|
||
foreach (var notifier in _npcInteractionNotifiers) | ||
{ | ||
notifier.NotifyInteractionFromNPC(IO.NPCType.Barber); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.