-
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.
Add packets for requesting shop and handling data about shop
- Loading branch information
1 parent
6eddceb
commit 8820813
Showing
12 changed files
with
301 additions
and
63 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,29 @@ | ||
using EOLib.Net; | ||
using EOLib.Net.Communication; | ||
|
||
namespace EOLib.Domain.Interact | ||
{ | ||
public class MapNPCActions : IMapNPCActions | ||
{ | ||
private readonly IPacketSendService _packetSendService; | ||
|
||
public MapNPCActions(IPacketSendService packetSendService) | ||
{ | ||
_packetSendService = packetSendService; | ||
} | ||
|
||
public void RequestShop(byte index) | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Shop, PacketAction.Open) | ||
.AddShort(index) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
} | ||
|
||
public interface IMapNPCActions | ||
{ | ||
void RequestShop(byte index); | ||
} | ||
} |
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,22 @@ | ||
namespace EOLib.Domain.Interact.Shop | ||
{ | ||
public class ShopCraftIngredient : IShopCraftIngredient | ||
{ | ||
public int ID { get; } | ||
|
||
public int Amount { get; } | ||
|
||
public ShopCraftIngredient(int id, int amount) | ||
{ | ||
ID = id; | ||
Amount = amount; | ||
} | ||
} | ||
|
||
public interface IShopCraftIngredient | ||
{ | ||
int ID { get; } | ||
|
||
int Amount { get; } | ||
} | ||
} |
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,24 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Interact.Shop | ||
{ | ||
public class ShopCraftItem : IShopCraftItem | ||
{ | ||
public int ID { get; } | ||
|
||
public IReadOnlyList<IShopCraftIngredient> Ingredients { get; } | ||
|
||
public ShopCraftItem(int id, IEnumerable<IShopCraftIngredient> ingredients) | ||
{ | ||
ID = id; | ||
Ingredients = new List<IShopCraftIngredient>(ingredients); | ||
} | ||
} | ||
|
||
public interface IShopCraftItem | ||
{ | ||
int ID { get; } | ||
|
||
IReadOnlyList<IShopCraftIngredient> Ingredients { get; } | ||
} | ||
} |
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,55 @@ | ||
using AutomaticTypeMapper; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Interact.Shop | ||
{ | ||
public interface IShopDataRepository | ||
{ | ||
int ShopID { get; set; } | ||
|
||
string ShopName { get; set; } | ||
|
||
List<IShopItem> TradeItems { get; set; } | ||
|
||
List<IShopCraftItem> CraftItems { get; set; } | ||
} | ||
|
||
public interface IShopDataProvider | ||
{ | ||
int ShopID { get; } | ||
|
||
string ShopName { get; } | ||
|
||
IReadOnlyList<IShopItem> TradeItems { get; } | ||
|
||
IReadOnlyList<IShopCraftItem> CraftItems { get; } | ||
} | ||
|
||
[AutoMappedType(IsSingleton = true)] | ||
public class ShopDataRepository : IShopDataProvider, IShopDataRepository, IResettable | ||
{ | ||
public int ShopID { get; set; } | ||
public string ShopName { get; set; } | ||
|
||
public List<IShopItem> TradeItems { get; set; } | ||
|
||
public List<IShopCraftItem> CraftItems { get; set; } | ||
|
||
IReadOnlyList<IShopItem> IShopDataProvider.TradeItems => TradeItems; | ||
|
||
IReadOnlyList<IShopCraftItem> IShopDataProvider.CraftItems => CraftItems; | ||
|
||
public ShopDataRepository() | ||
{ | ||
ResetState(); | ||
} | ||
|
||
public void ResetState() | ||
{ | ||
ShopID = 0; | ||
ShopName = string.Empty; | ||
TradeItems = new List<IShopItem>(); | ||
CraftItems = new List<IShopCraftItem>(); | ||
} | ||
} | ||
} |
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,32 @@ | ||
namespace EOLib.Domain.Interact.Shop | ||
{ | ||
public class ShopItem : IShopItem | ||
{ | ||
public int ID { get; } | ||
|
||
public int Buy { get; } | ||
|
||
public int Sell { get; } | ||
|
||
public int MaxBuy { get; } | ||
|
||
public ShopItem(int id, int buyPrice, int sellPrice, int maxBuy) | ||
{ | ||
ID = id; | ||
Buy = buyPrice; | ||
Sell = sellPrice; | ||
MaxBuy = maxBuy; | ||
} | ||
} | ||
|
||
public interface IShopItem | ||
{ | ||
int ID { get; } | ||
|
||
int Buy { get; } | ||
|
||
int Sell { get; } | ||
|
||
int MaxBuy { get; } | ||
} | ||
} |
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,66 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Interact.Shop; | ||
using EOLib.Domain.Login; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.Interact.Shop | ||
{ | ||
[AutoMappedType] | ||
public class ShopOpenHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly IShopDataRepository _shopDataRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Shop; | ||
|
||
public override PacketAction Action => PacketAction.Open; | ||
|
||
public ShopOpenHandler(IPlayerInfoProvider playerInfoProvider, | ||
IShopDataRepository shopDataRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_shopDataRepository = shopDataRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
_shopDataRepository.ShopID = packet.ReadShort(); | ||
_shopDataRepository.ShopName = packet.ReadBreakString(); | ||
|
||
var tradeItems = new List<IShopItem>(); | ||
while (packet.PeekByte() != 255) | ||
{ | ||
var nextItem = new ShopItem( | ||
id: packet.ReadShort(), | ||
buyPrice: packet.ReadThree(), | ||
sellPrice: packet.ReadThree(), | ||
maxBuy: packet.ReadChar()); | ||
tradeItems.Add(nextItem); | ||
} | ||
packet.ReadByte(); | ||
|
||
_shopDataRepository.TradeItems = tradeItems; | ||
|
||
var craftItems = new List<IShopCraftItem>(); | ||
while (packet.PeekByte() != 255) | ||
{ | ||
var id = packet.ReadShort(); | ||
var ingreds = new List<IShopCraftIngredient>(); | ||
|
||
for (int i = 0; i < 4; ++i) | ||
{ | ||
ingreds.Add(new ShopCraftIngredient( | ||
id: packet.ReadShort(), | ||
amount: packet.ReadChar())); | ||
} | ||
craftItems.Add(new ShopCraftItem(id, ingreds)); | ||
} | ||
packet.ReadByte(); | ||
|
||
_shopDataRepository.CraftItems = craftItems; | ||
|
||
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
Oops, something went wrong.