Skip to content

Commit

Permalink
Create ItemActions. Move JunkItem from MapActions to ItemActions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Mar 29, 2022
1 parent 06e6c29 commit 4491547
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
4 changes: 3 additions & 1 deletion EOBot/TrainerBot.cs
Expand Up @@ -40,6 +40,7 @@ internal class TrainerBot : BotBase

private ICharacterActions _characterActions;
private IMapActions _mapActions;
private IItemActions _itemActions;

private ICharacterRepository _characterRepository;

Expand Down Expand Up @@ -77,6 +78,7 @@ protected override async Task DoWorkAsync(CancellationToken ct)
var c = DependencyMaster.TypeRegistry[_index];

_mapActions = c.Resolve<IMapActions>();
_itemActions = c.Resolve<IItemActions>();
_characterRepository = c.Resolve<ICharacterRepository>();
_characterActions = c.Resolve<ICharacterActions>();
var mapCellStateProvider = c.Resolve<IMapCellStateProvider>();
Expand Down Expand Up @@ -312,7 +314,7 @@ private async Task PickUpItem(IItem item)
private async Task JunkItem(IItem item)
{
ConsoleHelper.WriteMessage(ConsoleHelper.Type.JunkItem, $"{item.Amount,7} - {_itemData.Single(x => x.ID == item.ItemID).Name}");
await TrySend(() => _mapActions.JunkItem(item));
await TrySend(() => _itemActions.JunkItem(item));
await Task.Delay(TimeSpan.FromMilliseconds(ATTACK_BACKOFF_MS));
}

Expand Down
33 changes: 33 additions & 0 deletions EOLib/Domain/Item/ItemActions.cs
@@ -0,0 +1,33 @@
using AutomaticTypeMapper;
using EOLib.Domain.Map;
using EOLib.Net;
using EOLib.Net.Communication;

namespace EOLib.Domain.Item
{
[AutoMappedType]
public class ItemActions : IItemActions
{
private readonly IPacketSendService _packetSendService;

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

public void JunkItem(IItem item)
{
var packet = new PacketBuilder(PacketFamily.Item, PacketAction.Junk)
.AddShort(item.ItemID)
.AddInt(item.Amount)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IItemActions
{
void JunkItem(IItem item);
}
}
13 changes: 0 additions & 13 deletions EOLib/Domain/Map/MapActions.cs
Expand Up @@ -42,25 +42,12 @@ public ItemPickupResult PickUpItem(IItem item)

return pickupResult;
}

// todo: item stuff probably belongs in its own action class
public void JunkItem(IItem item)
{
var packet = new PacketBuilder(PacketFamily.Item, PacketAction.Junk)
.AddShort(item.ItemID)
.AddInt(item.Amount)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IMapActions
{
void RequestRefresh();

ItemPickupResult PickUpItem(IItem item);

void JunkItem(IItem item);
}
}

0 comments on commit 4491547

Please sign in to comment.