-
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 API/handling for junking items. Junk picked up items in TrainerBo…
…t if specified.
- Loading branch information
1 parent
f3dc5ef
commit 60194d8
Showing
7 changed files
with
121 additions
and
65 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
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
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,60 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Extensions; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
|
||
namespace EOLib.PacketHandlers.Items | ||
{ | ||
[AutoMappedType] | ||
public class JunkItemHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICharacterRepository _characterRepository; | ||
private readonly ICharacterInventoryRepository _inventoryRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Item; | ||
|
||
public override PacketAction Action => PacketAction.Junk; | ||
|
||
public JunkItemHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterRepository characterRepository, | ||
ICharacterInventoryRepository inventoryRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_characterRepository = characterRepository; | ||
_inventoryRepository = inventoryRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var id = packet.ReadShort(); | ||
var amountRemoved = packet.ReadThree(); | ||
var amountRemaining = packet.ReadInt(); | ||
var weight = packet.ReadChar(); | ||
var maxWeight = packet.ReadChar(); | ||
|
||
var inventoryItem = _inventoryRepository.ItemInventory.OptionalSingle(x => x.ItemID == id); | ||
if (inventoryItem.HasValue) | ||
{ | ||
_inventoryRepository.ItemInventory.Remove(inventoryItem.Value); | ||
|
||
if (amountRemaining > 0) | ||
{ | ||
var updatedItem = inventoryItem.Value.WithAmount(amountRemaining); | ||
_inventoryRepository.ItemInventory.Add(updatedItem); | ||
} | ||
} | ||
|
||
var stats = _characterRepository.MainCharacter.Stats; | ||
stats = stats.WithNewStat(CharacterStat.Weight, weight) | ||
.WithNewStat(CharacterStat.MaxWeight, maxWeight); | ||
|
||
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats); | ||
|
||
// todo: notify client for status message (see commented out _junkItem() in PacketApiCallbackManager) | ||
|
||
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