-
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.
Packets for bank account open, deposit, withdraw and locker storage u…
…pgrade
- Loading branch information
1 parent
45b097f
commit 96c2cce
Showing
11 changed files
with
250 additions
and
155 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
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(); | ||
} | ||
} |
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,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>(); | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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; | ||
} | ||
} | ||
} |
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,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; | ||
} | ||
} | ||
} |
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 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; | ||
} | ||
} | ||
} |
Oops, something went wrong.