-
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.
Merge pull request #320 from ethanmoffat/inn
Innkeeper dialog implementation. Includes citizen registration, unregister, and inn sleeping
- Loading branch information
Showing
29 changed files
with
954 additions
and
55 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,81 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using EOLib.Net.Communication; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Interact.Citizen | ||
{ | ||
[AutoMappedType] | ||
public class CitizenActions : ICitizenActions | ||
{ | ||
private readonly IPacketSendService _packetSendService; | ||
private readonly ICitizenDataProvider _citizenDataProvider; | ||
private readonly ICurrentMapStateProvider _currentMapStateProvider; | ||
|
||
public CitizenActions(IPacketSendService packetSendService, | ||
ICitizenDataProvider citizenDataProvider, | ||
ICurrentMapStateProvider currentMapStateProvider) | ||
{ | ||
_packetSendService = packetSendService; | ||
_citizenDataProvider = citizenDataProvider; | ||
_currentMapStateProvider = currentMapStateProvider; | ||
} | ||
|
||
public void RequestSleep() | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Citizen, PacketAction.Request) | ||
.AddShort(_currentMapStateProvider.MapWarpSession.ValueOr(0)) | ||
.AddShort(_citizenDataProvider.BehaviorID.ValueOr(0)) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
|
||
} | ||
|
||
public void ConfirmSleep() | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Citizen, PacketAction.Accept) | ||
.AddShort(_currentMapStateProvider.MapWarpSession.ValueOr(0)) | ||
.AddShort(_citizenDataProvider.BehaviorID.ValueOr(0)) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
|
||
public void SignUp(IReadOnlyList<string> answers) | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Citizen, PacketAction.Reply) | ||
.AddShort(_currentMapStateProvider.MapWarpSession.ValueOr(0)) | ||
.AddByte(255) | ||
.AddShort(_citizenDataProvider.BehaviorID.ValueOr(0)) | ||
.AddByte(255) | ||
.AddBreakString(answers[0]) | ||
.AddBreakString(answers[1]) | ||
.AddString(answers[2]) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
|
||
public void Unsubscribe() | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Citizen, PacketAction.Remove) | ||
.AddShort(_citizenDataProvider.BehaviorID.ValueOr(0)) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
} | ||
|
||
public interface ICitizenActions | ||
{ | ||
void RequestSleep(); | ||
|
||
void ConfirmSleep(); | ||
|
||
void SignUp(IReadOnlyList<string> answers); | ||
|
||
void Unsubscribe(); | ||
} | ||
} |
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,41 @@ | ||
using AutomaticTypeMapper; | ||
using Optional; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Interact.Citizen | ||
{ | ||
public interface ICitizenDataRepository | ||
{ | ||
Option<int> BehaviorID { get; set; } | ||
|
||
Option<int> CurrentHomeID { get; set; } | ||
|
||
List<string> Questions { get; set; } | ||
} | ||
|
||
public interface ICitizenDataProvider | ||
{ | ||
Option<int> BehaviorID { get; } | ||
|
||
Option<int> CurrentHomeID { get; } | ||
|
||
IReadOnlyList<string> Questions { get; } | ||
} | ||
|
||
[AutoMappedType(IsSingleton = true)] | ||
public class CitizenDataRepository : ICitizenDataRepository, ICitizenDataProvider | ||
{ | ||
public Option<int> BehaviorID { get; set; } | ||
|
||
public Option<int> CurrentHomeID { get; set; } | ||
|
||
public List<string> Questions { get; set; } | ||
|
||
IReadOnlyList<string> ICitizenDataProvider.Questions => Questions; | ||
|
||
public CitizenDataRepository() | ||
{ | ||
Questions = new List<string>(); | ||
} | ||
} | ||
} |
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,8 @@ | ||
namespace EOLib.Domain.Interact.Citizen | ||
{ | ||
public enum CitizenUnsubscribeReply | ||
{ | ||
NotACitizen = 0, | ||
Unsubscribed = 1 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
|
||
namespace EOLib.PacketHandlers.Citizen | ||
{ | ||
/// <summary> | ||
/// Sent when the player has accepted the cost of sleeping at an inn | ||
/// </summary> | ||
[AutoMappedType] | ||
public class CitizenAcceptHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICharacterInventoryRepository _characterInventoryRepository; | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
private readonly ICharacterRepository _characterRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Citizen; | ||
|
||
public override PacketAction Action => PacketAction.Accept; | ||
|
||
public CitizenAcceptHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterInventoryRepository characterInventoryRepository, | ||
ICurrentMapStateRepository currentMapStateRepository, | ||
ICharacterRepository characterRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_characterInventoryRepository = characterInventoryRepository; | ||
_currentMapStateRepository = currentMapStateRepository; | ||
_characterRepository = characterRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var goldRemaining = packet.ReadInt(); | ||
_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1); | ||
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(1, goldRemaining)); | ||
|
||
var stats = _characterRepository.MainCharacter.Stats; | ||
stats = stats.WithNewStat(CharacterStat.HP, stats[CharacterStat.MaxHP]) | ||
.WithNewStat(CharacterStat.TP, stats[CharacterStat.MaxTP]); | ||
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats); | ||
|
||
_currentMapStateRepository.IsSleepWarp = true; | ||
|
||
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,59 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Interact; | ||
using EOLib.Domain.Interact.Citizen; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using Optional; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.Citizen | ||
{ | ||
/// <summary> | ||
/// Sent when opening an Innkeeper dialog | ||
/// </summary> | ||
[AutoMappedType] | ||
public class CitizenOpenHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICitizenDataRepository _citizenDataRepository; | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.Citizen; | ||
|
||
public override PacketAction Action => PacketAction.Open; | ||
|
||
public CitizenOpenHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICitizenDataRepository citizenDataRepository, | ||
ICurrentMapStateRepository currentMapStateRepository, | ||
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers) | ||
: base(playerInfoProvider) | ||
{ | ||
_citizenDataRepository = citizenDataRepository; | ||
_currentMapStateRepository = currentMapStateRepository; | ||
_npcInteractionNotifiers = npcInteractionNotifiers; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
_citizenDataRepository.BehaviorID = Option.Some(packet.ReadThree()); | ||
_citizenDataRepository.CurrentHomeID = packet.ReadChar().SomeWhen(x => x > 0); | ||
_currentMapStateRepository.MapWarpSession = Option.Some(packet.ReadShort()); | ||
|
||
if (packet.ReadByte() != 255) | ||
return false; | ||
|
||
var question1 = packet.ReadBreakString(); | ||
var question2 = packet.ReadBreakString(); | ||
var question3 = packet.ReadEndString(); | ||
|
||
_citizenDataRepository.Questions = new List<string> { question1, question2, question3 }; | ||
|
||
foreach (var notifier in _npcInteractionNotifiers) | ||
notifier.NotifyInteractionFromNPC(IO.NPCType.Inn); | ||
|
||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.