Skip to content

Commit

Permalink
Merge pull request #169 from ethanmoffat/shop
Browse files Browse the repository at this point in the history
Re-implement shop NPC dialog
  • Loading branch information
ethanmoffat committed Apr 5, 2022
2 parents 781de8e + 97a6e1f commit 574fb4f
Show file tree
Hide file tree
Showing 45 changed files with 1,257 additions and 692 deletions.
18 changes: 18 additions & 0 deletions EOLib/Domain/Character/PaperdollData.cs
Expand Up @@ -124,6 +124,24 @@ public override bool Equals(object obj)
Guild == other.Guild && Rank == other.Rank && PlayerID == other.PlayerID &&
Class == other.Class && Gender == other.Gender && Icon == other.Icon && Paperdoll.SequenceEqual(other.Paperdoll);
}

public override int GetHashCode()
{
int hashCode = 170256730;
hashCode = hashCode * -1521134295 + Name.GetHashCode();
hashCode = hashCode * -1521134295 + Home.GetHashCode();
hashCode = hashCode * -1521134295 + Partner.GetHashCode();
hashCode = hashCode * -1521134295 + Title.GetHashCode();
hashCode = hashCode * -1521134295 + Guild.GetHashCode();
hashCode = hashCode * -1521134295 + Rank.GetHashCode();
hashCode = hashCode * -1521134295 + PlayerID.GetHashCode();
hashCode = hashCode * -1521134295 + Class.GetHashCode();
hashCode = hashCode * -1521134295 + Gender.GetHashCode();
hashCode = hashCode * -1521134295 + Paperdoll.Select(x => (int)x.Value)
.Aggregate(hashCode * -1521134295, (a, b) => a * -1521134295 + b.GetHashCode());
hashCode = hashCode * -1521134295 + Icon.GetHashCode();
return hashCode;
}
}

public interface IPaperdollData
Expand Down
31 changes: 31 additions & 0 deletions EOLib/Domain/Interact/MapNPCActions.cs
@@ -0,0 +1,31 @@
using AutomaticTypeMapper;
using EOLib.Net;
using EOLib.Net.Communication;

namespace EOLib.Domain.Interact
{
[AutoMappedType]
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);
}
}
30 changes: 30 additions & 0 deletions EOLib/Domain/Interact/PaperdollActions.cs
@@ -0,0 +1,30 @@
using AutomaticTypeMapper;
using EOLib.Net;
using EOLib.Net.Communication;

namespace EOLib.Domain.Interact
{
[AutoMappedType]
public class PaperdollActions : IPaperdollActions
{
private readonly IPacketSendService _packetSendService;

public PaperdollActions(IPacketSendService packetSendService)
{
_packetSendService = packetSendService;
}

public void RequestPaperdoll(int characterId)
{
var packet = new PacketBuilder(PacketFamily.PaperDoll, PacketAction.Request)
.AddShort((short)characterId)
.Build();
_packetSendService.SendPacket(packet);
}
}

public interface IPaperdollActions
{
void RequestPaperdoll(int characterId);
}
}
55 changes: 55 additions & 0 deletions EOLib/Domain/Interact/Shop/ShopActions.cs
@@ -0,0 +1,55 @@
using AutomaticTypeMapper;
using EOLib.Net;
using EOLib.Net.Communication;

namespace EOLib.Domain.Interact.Shop
{
[AutoMappedType]
public class ShopActions : IShopActions
{
private readonly IPacketSendService _packetSendService;

public ShopActions(IPacketSendService packetSendService)
{
_packetSendService = packetSendService;
}

public void BuyItem(short itemId, int amount)
{
var packet = new PacketBuilder(PacketFamily.Shop, PacketAction.Buy)
.AddShort(itemId)
.AddInt(amount)
.Build();

_packetSendService.SendPacket(packet);
}

public void SellItem(short itemId, int amount)
{
var packet = new PacketBuilder(PacketFamily.Shop, PacketAction.Sell)
.AddShort(itemId)
.AddInt(amount)
.Build();

_packetSendService.SendPacket(packet);
}

public void CraftItem(short itemId)
{
var packet = new PacketBuilder(PacketFamily.Shop, PacketAction.Create)
.AddShort(itemId)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IShopActions
{
void BuyItem(short itemId, int amount);

void SellItem(short itemId, int amount);

void CraftItem(short itemId);
}
}
22 changes: 22 additions & 0 deletions EOLib/Domain/Interact/Shop/ShopCraftIngredient.cs
@@ -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; }
}
}
24 changes: 24 additions & 0 deletions EOLib/Domain/Interact/Shop/ShopCraftItem.cs
@@ -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; }
}
}
55 changes: 55 additions & 0 deletions EOLib/Domain/Interact/Shop/ShopDataRepository.cs
@@ -0,0 +1,55 @@
using AutomaticTypeMapper;
using System.Collections.Generic;

namespace EOLib.Domain.Interact.Shop
{
public interface IShopDataRepository : IResettable
{
int ShopID { get; set; }

string ShopName { get; set; }

List<IShopItem> TradeItems { get; set; }

List<IShopCraftItem> CraftItems { get; set; }
}

public interface IShopDataProvider : IResettable
{
int ShopID { get; }

string ShopName { get; }

IReadOnlyList<IShopItem> TradeItems { get; }

IReadOnlyList<IShopCraftItem> CraftItems { get; }
}

[AutoMappedType(IsSingleton = true)]
public class ShopDataRepository : IShopDataProvider, IShopDataRepository
{
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>();
}
}
}
32 changes: 32 additions & 0 deletions EOLib/Domain/Interact/Shop/ShopItem.cs
@@ -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; }
}
}
1 change: 0 additions & 1 deletion EOLib/Net/API/PacketAPI.cs
Expand Up @@ -29,7 +29,6 @@ public PacketAPI(EOClient client)
_createPartyMembers();
_createNPCMembers();
_createQuestMembers();
_createShopMembers();
_createSpellMembers();
_createStatSkillMembers();
_createTradeMembers();
Expand Down

0 comments on commit 574fb4f

Please sign in to comment.