Skip to content

Commit

Permalink
Packets for bank account open, deposit, withdraw and locker storage u…
Browse files Browse the repository at this point in the history
…pgrade
  • Loading branch information
ethanmoffat committed Apr 10, 2022
1 parent 45b097f commit 96c2cce
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 155 deletions.
52 changes: 52 additions & 0 deletions EOLib/Domain/Interact/Bank/BankActions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using AutomaticTypeMapper;
using EOLib.Net;
using EOLib.Net.Communication;

namespace EOLib.Domain.Interact.Bank
{
[AutoMappedType]
public class BankActions : IBankActions
{
private readonly IPacketSendService _packetSendService;

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

public void Deposit(int amount)
{
var packet = new PacketBuilder(PacketFamily.Bank, PacketAction.Add)
.AddInt(amount)
.Build();

_packetSendService.SendPacket(packet);
}

public void Withdraw(int amount)
{
var packet = new PacketBuilder(PacketFamily.Bank, PacketAction.Take)
.AddInt(amount)
.Build();

_packetSendService.SendPacket(packet);
}

public void BuyStorageUpgrade()
{
var packet = new PacketBuilder(PacketFamily.Locker, PacketAction.Buy)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IBankActions
{
void Deposit(int amount);

void Withdraw(int amount);

void BuyStorageUpgrade();
}
}
45 changes: 45 additions & 0 deletions EOLib/Domain/Interact/Bank/BankDataRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using AutomaticTypeMapper;
using Optional;

namespace EOLib.Domain.Interact.Bank
{
public interface IBankDataRepository : IResettable
{
int AccountValue { get; set; }

int SessionID { get; set; }

Option<int> LockerUpgrades { get; set; }
}

public interface IBankDataProvider : IResettable
{
int AccountValue { get; }

int SessionID { get; }

Option<int> LockerUpgrades { get; }
}

[AutoMappedType(IsSingleton = true)]
public class BankDataRepository : IBankDataRepository, IBankDataProvider
{
public int AccountValue { get; set; }

public int SessionID { get; set; }

public Option<int> LockerUpgrades { get; set; }

public BankDataRepository()
{
ResetState();
}

public void ResetState()
{
AccountValue = 0;
SessionID = 0;
LockerUpgrades = Option.None<int>();
}
}
}
11 changes: 11 additions & 0 deletions EOLib/Domain/Interact/MapNPCActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,23 @@ public void RequestQuest(INPC npc)

_packetSendService.SendPacket(packet);
}

public void RequestBank(INPC npc)
{
var packet = new PacketBuilder(PacketFamily.Bank, PacketAction.Open)
.AddShort(npc.Index)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IMapNPCActions
{
void RequestShop(INPC npc);

void RequestQuest(INPC npc);

void RequestBank(INPC npc);
}
}
71 changes: 0 additions & 71 deletions EOLib/Net/API/Bank.cs

This file was deleted.

26 changes: 0 additions & 26 deletions EOLib/Net/API/Locker.cs

This file was deleted.

2 changes: 0 additions & 2 deletions EOLib/Net/API/PacketAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public PacketAPI(EOClient client)
m_client = client;

//each of these sets up members of the partial PacketAPI class relevant to a particular packet family
_createBankMembers();
_createInitMembers();
_createLockerMembers();
_createMusicMembers();
_createPartyMembers();
_createNPCMembers();
Expand Down
35 changes: 35 additions & 0 deletions EOLib/PacketHandlers/Bank/BankOpenHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using AutomaticTypeMapper;
using EOLib.Domain.Interact.Bank;
using EOLib.Domain.Login;
using EOLib.Net;
using EOLib.Net.Handlers;
using Optional;

namespace EOLib.PacketHandlers.Bank
{
[AutoMappedType]
public class BankOpenHandler : InGameOnlyPacketHandler
{
private readonly IBankDataRepository _bankDataRepository;

public override PacketFamily Family => PacketFamily.Bank;

public override PacketAction Action => PacketAction.Open;

public BankOpenHandler(IPlayerInfoProvider playerInfoProvider,
IBankDataRepository bankDataRepository)
: base(playerInfoProvider)
{
_bankDataRepository = bankDataRepository;
}

public override bool HandlePacket(IPacket packet)
{
_bankDataRepository.AccountValue = packet.ReadInt();
_bankDataRepository.SessionID = packet.ReadThree();
_bankDataRepository.LockerUpgrades = Option.Some<int>(packet.ReadChar());

return true;
}
}
}
40 changes: 40 additions & 0 deletions EOLib/PacketHandlers/Bank/BankReplyHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Interact.Bank;
using EOLib.Domain.Login;
using EOLib.Net;
using EOLib.Net.Handlers;

namespace EOLib.PacketHandlers.Bank
{
[AutoMappedType]
public class BankReplyHandler : InGameOnlyPacketHandler
{
private readonly IBankDataRepository _bankDataRepository;
private readonly ICharacterInventoryRepository _characterInventoryRepository;

public override PacketFamily Family => PacketFamily.Bank;

public override PacketAction Action => PacketAction.Reply;

public BankReplyHandler(IPlayerInfoProvider playerInfoProvider,
IBankDataRepository bankDataRepository,
ICharacterInventoryRepository characterInventoryRepository)
: base(playerInfoProvider)
{
_bankDataRepository = bankDataRepository;
_characterInventoryRepository = characterInventoryRepository;
}

public override bool HandlePacket(IPacket packet)
{
var characterGold = packet.ReadInt();
_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1);
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(1, characterGold));

_bankDataRepository.AccountValue = packet.ReadInt();

return true;
}
}
}
41 changes: 41 additions & 0 deletions EOLib/PacketHandlers/Locker/LockerBuyHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Interact.Bank;
using EOLib.Domain.Login;
using EOLib.Net;
using EOLib.Net.Handlers;
using Optional;

namespace EOLib.PacketHandlers.Locker
{
[AutoMappedType]
public class LockerBuyHandler : InGameOnlyPacketHandler
{
private readonly IBankDataRepository _bankDataRepository;
private readonly ICharacterInventoryRepository _characterInventoryRepository;

public override PacketFamily Family => PacketFamily.Locker;

public override PacketAction Action => PacketAction.Buy;

public LockerBuyHandler(IPlayerInfoProvider playerInfoProvider,
IBankDataRepository bankDataRepository,
ICharacterInventoryRepository characterInventoryRepository)
: base(playerInfoProvider)
{
_bankDataRepository = bankDataRepository;
_characterInventoryRepository = characterInventoryRepository;
}

public override bool HandlePacket(IPacket packet)
{
var inventoryGold = packet.ReadInt();
_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1);
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(1, inventoryGold));

_bankDataRepository.LockerUpgrades = Option.Some<int>(packet.ReadChar());

return true;
}
}
}
Loading

0 comments on commit 96c2cce

Please sign in to comment.