Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de86fa5
commit 85a0de2
Showing
12 changed files
with
255 additions
and
206 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,26 @@ | ||
using EOLib.Domain.Character; | ||
|
||
namespace EOLib.Domain.Map | ||
{ | ||
public class ChestItem : InventoryItem | ||
{ | ||
public int Slot { get; } | ||
|
||
public ChestItem(short itemID, int amount, int slot) | ||
: base(itemID, amount) | ||
{ | ||
Slot = slot; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
var chestItem = obj as ChestItem; | ||
return base.Equals(chestItem) && Slot == chestItem.Slot; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return base.GetHashCode() * -1521134295 + Slot.GetHashCode(); | ||
} | ||
} | ||
} |
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 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,37 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
|
||
namespace EOLib.PacketHandlers.Chest | ||
{ | ||
[AutoMappedType] | ||
public class ChestAgreeHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly IChestDataRepository _chestDataRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Chest; | ||
|
||
public override PacketAction Action => PacketAction.Agree; | ||
|
||
public ChestAgreeHandler(IPlayerInfoProvider playerInfoProvider, | ||
IChestDataRepository chestDataRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_chestDataRepository = chestDataRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
_chestDataRepository.Items.Clear(); | ||
|
||
int i = 0; | ||
while (packet.ReadPosition < packet.Length) | ||
_chestDataRepository.Items.Add(new ChestItem(packet.ReadShort(), packet.ReadThree(), i++)); | ||
|
||
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,82 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using Optional.Collections; | ||
|
||
namespace EOLib.PacketHandlers.Chest | ||
{ | ||
/// <summary> | ||
/// Handler for CHEST_GET packet, sent as confirmation to character that item is being taken | ||
/// </summary> | ||
[AutoMappedType] | ||
public class ChestGetHandler : ChestAgreeHandler | ||
{ | ||
private readonly ICharacterRepository _characterRepository; | ||
private readonly ICharacterInventoryRepository _characterInventoryRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Chest; | ||
|
||
public override PacketAction Action => PacketAction.Get; | ||
|
||
public ChestGetHandler(IPlayerInfoProvider playerInfoProvider, | ||
IChestDataRepository chestDataRepository, | ||
ICharacterRepository characterRepository, | ||
ICharacterInventoryRepository characterInventoryRepository) | ||
: base(playerInfoProvider, chestDataRepository) | ||
{ | ||
_characterRepository = characterRepository; | ||
_characterInventoryRepository = characterInventoryRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var itemId = packet.ReadShort(); | ||
var amount = Action == PacketAction.Get ? packet.ReadThree() : packet.ReadInt(); | ||
var weight = packet.ReadChar(); | ||
var maxWeight = packet.ReadChar(); | ||
|
||
_characterInventoryRepository.ItemInventory.SingleOrNone(x => x.ItemID == itemId) | ||
.Match( | ||
some: existing => | ||
{ | ||
_characterInventoryRepository.ItemInventory.Remove(existing); | ||
if (amount > 0 || itemId == 1) | ||
{ | ||
_characterInventoryRepository.ItemInventory.Add(existing.WithAmount(existing.Amount + (Action == PacketAction.Get ? amount : -amount))); | ||
} | ||
}, | ||
none: () => | ||
{ | ||
if (amount > 0) | ||
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(itemId, amount)); | ||
}); | ||
|
||
var stats = _characterRepository.MainCharacter.Stats | ||
.WithNewStat(CharacterStat.Weight, weight) | ||
.WithNewStat(CharacterStat.MaxWeight, maxWeight); | ||
|
||
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats); | ||
|
||
return base.HandlePacket(packet); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Handler for CHEST_REPLY packet, sent in response to main player adding an item to a chest | ||
/// </summary> | ||
[AutoMappedType] | ||
public class ChestReplyHandler : ChestGetHandler | ||
{ | ||
public override PacketAction Action => PacketAction.Reply; | ||
|
||
public ChestReplyHandler(IPlayerInfoProvider playerInfoProvider, | ||
IChestDataRepository chestDataRepository, | ||
ICharacterRepository characterRepository, | ||
ICharacterInventoryRepository characterInventoryRepository) | ||
: base(playerInfoProvider, chestDataRepository, characterRepository, characterInventoryRepository) | ||
{ | ||
} | ||
} | ||
} |
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.