-
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.
Implement item drop. Drop supported via drag to map renderer or drop …
…item button.
- Loading branch information
1 parent
6cebd7b
commit 3f6ee12
Showing
19 changed files
with
323 additions
and
314 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
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,71 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Domain.Notifiers; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.Items | ||
{ | ||
[AutoMappedType] | ||
public class DropItemHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICharacterRepository _characterRepository; | ||
private readonly ICharacterInventoryRepository _inventoryRepository; | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
private readonly IEnumerable<IMainCharacterEventNotifier> _mainCharacterEventNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.Item; | ||
|
||
public override PacketAction Action => PacketAction.Drop; | ||
|
||
public DropItemHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterRepository characterRepository, | ||
ICharacterInventoryRepository inventoryRepository, | ||
ICurrentMapStateRepository currentMapStateRepository, | ||
IEnumerable<IMainCharacterEventNotifier> mainCharacterEventNotifiers) | ||
: base(playerInfoProvider) | ||
{ | ||
_characterRepository = characterRepository; | ||
_inventoryRepository = inventoryRepository; | ||
_currentMapStateRepository = currentMapStateRepository; | ||
_mainCharacterEventNotifiers = mainCharacterEventNotifiers; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var id = packet.ReadShort(); | ||
var amountDropped = packet.ReadThree(); | ||
var amountRemaining = packet.ReadInt(); | ||
|
||
var uid = packet.ReadShort(); | ||
var dropX = packet.ReadChar(); | ||
var dropY = packet.ReadChar(); | ||
|
||
var weight = packet.ReadChar(); | ||
var maxWeight = packet.ReadChar(); | ||
|
||
_inventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == id); | ||
if (amountRemaining > 0 || id == 1) | ||
_inventoryRepository.ItemInventory.Add(new InventoryItem(id, amountRemaining)); | ||
|
||
var stats = _characterRepository.MainCharacter.Stats; | ||
stats = stats.WithNewStat(CharacterStat.Weight, weight) | ||
.WithNewStat(CharacterStat.MaxWeight, maxWeight); | ||
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats); | ||
|
||
var mapItem = new Item(uid, id, dropX, dropY) | ||
.WithAmount(amountDropped) | ||
.WithDropTime(DateTime.Now.AddSeconds(-5)); | ||
_currentMapStateRepository.MapItems.Add(mapItem); | ||
|
||
foreach (var notifier in _mainCharacterEventNotifiers) | ||
notifier.DropItem(id, amountDropped); | ||
|
||
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,43 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System; | ||
|
||
namespace EOLib.PacketHandlers.Items | ||
{ | ||
[AutoMappedType] | ||
public class OtherPlayerDropItemHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Item; | ||
|
||
public override PacketAction Action => PacketAction.Add; | ||
|
||
public OtherPlayerDropItemHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICurrentMapStateRepository currentMapStateRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_currentMapStateRepository = currentMapStateRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var id = packet.ReadShort(); | ||
var uid = packet.ReadShort(); | ||
|
||
var amountDropped = packet.ReadThree(); | ||
var dropX = packet.ReadChar(); | ||
var dropY = packet.ReadChar(); | ||
|
||
var mapItem = new Item(uid, id, dropX, dropY) | ||
.WithAmount(amountDropped) | ||
.WithDropTime(DateTime.Now); | ||
_currentMapStateRepository.MapItems.Add(mapItem); | ||
|
||
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,32 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
|
||
namespace EOLib.PacketHandlers.Items | ||
{ | ||
[AutoMappedType] | ||
public class RemoveItemFromMapHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Item; | ||
|
||
public override PacketAction Action => PacketAction.Remove; | ||
|
||
public RemoveItemFromMapHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICurrentMapStateRepository currentMapStateRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_currentMapStateRepository = currentMapStateRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var uid = packet.ReadShort(); | ||
_currentMapStateRepository.MapItems.RemoveWhere(x => x.UniqueID == uid); | ||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.