Skip to content

Commit

Permalink
Rename Item -> MapItem and add [Record] attribute. Remove IItem inter…
Browse files Browse the repository at this point in the history
…face.
  • Loading branch information
ethanmoffat committed Apr 28, 2022
1 parent e29c989 commit c1249b6
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 181 deletions.
2 changes: 1 addition & 1 deletion EOBot/Interpreter/BuiltInIdentifierConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private IVariable GetMapStateNPC(NPC npc)
return npcObj;
}

private IVariable GetMapStateItem(IItem item)
private IVariable GetMapStateItem(MapItem item)
{
var itemFile = DependencyMaster.TypeRegistry[_botIndex].Resolve<IPubFileProvider>().EIFFile;

Expand Down
4 changes: 2 additions & 2 deletions EOBot/TrainerBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private async Task PickUpItems(IMapCellState cellState)
}
}

private async Task PickUpItem(IItem item)
private async Task PickUpItem(MapItem item)
{
await TrySend(() =>
{
Expand All @@ -311,7 +311,7 @@ await TrySend(() =>
await Task.Delay(TimeSpan.FromMilliseconds(ATTACK_BACKOFF_MS));
}

private async Task JunkItem(IItem item)
private async Task JunkItem(MapItem item)
{
ConsoleHelper.WriteMessage(ConsoleHelper.Type.JunkItem, $"{item.Amount,7} - {_itemData.Single(x => x.ID == item.ItemID).Name}");
await TrySend(() => _itemActions.JunkItem(item.ItemID, item.Amount));
Expand Down
4 changes: 2 additions & 2 deletions EOLib/Domain/Item/ItemPickupValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ItemPickupValidator(IConfigurationProvider configurationProvider,
_eifFileProvider = eifFileProvider;
}

public ItemPickupResult ValidateItemPickup(Character.Character mainCharacter, IItem item)
public ItemPickupResult ValidateItemPickup(Character.Character mainCharacter, MapItem item)
{
var now = DateTime.Now;

Expand Down Expand Up @@ -58,6 +58,6 @@ public ItemPickupResult ValidateItemPickup(Character.Character mainCharacter, II

public interface IItemPickupValidator
{
ItemPickupResult ValidateItemPickup(Character.Character mainCharacter, IItem item);
ItemPickupResult ValidateItemPickup(Character.Character mainCharacter, MapItem item);
}
}
2 changes: 1 addition & 1 deletion EOLib/Domain/Login/LoginActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public async Task<CharacterLoginReply> CompleteCharacterLogin(short sessionID)

_currentMapStateRepository.Characters = data.MapCharacters.Except(new[] { mainCharacter }).ToDictionary(k => k.ID, v => v);
_currentMapStateRepository.NPCs = new HashSet<NPC.NPC>(data.MapNPCs);
_currentMapStateRepository.MapItems = new HashSet<IItem>(data.MapItems);
_currentMapStateRepository.MapItems = new HashSet<MapItem>(data.MapItems);

_playerInfoRepository.PlayerIsInGame = true;
_characterSessionRepository.ResetState();
Expand Down
2 changes: 1 addition & 1 deletion EOLib/Domain/Login/LoginRequestCompletedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed partial class LoginRequestCompletedData : ITranslatedData

public IReadOnlyList<NPC.NPC> MapNPCs { get; }

public IReadOnlyList<IItem> MapItems { get; }
public IReadOnlyList<MapItem> MapItems { get; }

public CharacterLoginReply Error { get; }
}
Expand Down
11 changes: 5 additions & 6 deletions EOLib/Domain/Map/CurrentMapStateRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using System.Collections.Generic;

namespace EOLib.Domain.Map
Expand All @@ -16,7 +15,7 @@ public interface ICurrentMapStateRepository

HashSet<NPC.NPC> NPCs { get; set; }

HashSet<IItem> MapItems { get; set; }
HashSet<MapItem> MapItems { get; set; }

HashSet<IWarp> OpenDoors { get; set; }

Expand All @@ -43,7 +42,7 @@ public interface ICurrentMapStateProvider

IReadOnlyCollection<NPC.NPC> NPCs { get; }

IReadOnlyCollection<IItem> MapItems { get; }
IReadOnlyCollection<MapItem> MapItems { get; }

IReadOnlyCollection<IWarp> OpenDoors { get; }

Expand Down Expand Up @@ -71,7 +70,7 @@ public class CurrentMapStateRepository : ICurrentMapStateRepository, ICurrentMap

public HashSet<NPC.NPC> NPCs { get; set; }

public HashSet<IItem> MapItems { get; set; }
public HashSet<MapItem> MapItems { get; set; }

public HashSet<IWarp> OpenDoors { get; set; }

Expand All @@ -89,7 +88,7 @@ public class CurrentMapStateRepository : ICurrentMapStateRepository, ICurrentMap

IReadOnlyCollection<NPC.NPC> ICurrentMapStateProvider.NPCs => NPCs;

IReadOnlyCollection<IItem> ICurrentMapStateProvider.MapItems => MapItems;
IReadOnlyCollection<MapItem> ICurrentMapStateProvider.MapItems => MapItems;

IReadOnlyCollection<IWarp> ICurrentMapStateProvider.OpenDoors => OpenDoors;

Expand All @@ -110,7 +109,7 @@ public void ResetState()

Characters = new Dictionary<int, Character.Character>();
NPCs = new HashSet<NPC.NPC>();
MapItems = new HashSet<IItem>();
MapItems = new HashSet<MapItem>();
OpenDoors = new HashSet<IWarp>();
PendingDoors = new HashSet<IWarp>();
VisibleSpikeTraps = new HashSet<MapCoordinate>();
Expand Down
2 changes: 1 addition & 1 deletion EOLib/Domain/Map/IMapCellState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IMapCellState

MapCoordinate Coordinate { get; }

IReadOnlyList<IItem> Items { get; }
IReadOnlyList<MapItem> Items { get; }

TileSpec TileSpec { get; }

Expand Down
127 changes: 0 additions & 127 deletions EOLib/Domain/Map/Item.cs

This file was deleted.

4 changes: 2 additions & 2 deletions EOLib/Domain/Map/MapActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void RequestRefresh()
_packetSendService.SendPacket(packet);
}

public ItemPickupResult PickUpItem(IItem item)
public ItemPickupResult PickUpItem(MapItem item)
{
var pickupResult = _itemPickupValidator.ValidateItemPickup(_characterProvider.MainCharacter, item);
if (pickupResult == ItemPickupResult.Ok)
Expand Down Expand Up @@ -85,7 +85,7 @@ public interface IMapActions
{
void RequestRefresh();

ItemPickupResult PickUpItem(IItem item);
ItemPickupResult PickUpItem(MapItem item);

void OpenDoor(IWarp warp);

Expand Down
4 changes: 2 additions & 2 deletions EOLib/Domain/Map/MapCellState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MapCellState : IMapCellState

public MapCoordinate Coordinate { get; set; }

public IReadOnlyList<IItem> Items { get; set; }
public IReadOnlyList<MapItem> Items { get; set; }

public TileSpec TileSpec { get; set; }

Expand All @@ -28,7 +28,7 @@ public class MapCellState : IMapCellState
public MapCellState()
{
Coordinate = new MapCoordinate(0, 0);
Items = new List<IItem>();
Items = new List<MapItem>();
TileSpec = TileSpec.None;
NPC = Option.None<NPC.NPC>();
Character = Option.None<Character.Character>();
Expand Down
39 changes: 39 additions & 0 deletions EOLib/Domain/Map/MapItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Amadevus.RecordGenerator;
using Optional;
using System;

namespace EOLib.Domain.Map
{
[Record]
public sealed partial class MapItem
{
public short UniqueID { get; }

public short ItemID { get; }

public byte X { get; }

public byte Y { get; }

public int Amount { get; }

public bool IsNPCDrop { get; }

public Option<int> OwningPlayerID { get; }

public Option<DateTime> DropTime { get; }

public static MapItem None => new MapItem();

public MapItem(short uid, short id, byte x, byte y, int amount)
{
UniqueID = uid;
ItemID = id;
X = x;
Y = y;
Amount = amount;
}

private MapItem() { }
}
}
14 changes: 7 additions & 7 deletions EOLib/Domain/Map/RefreshReplyPacketData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class RefreshReplyData : IRefreshReplyData

public IReadOnlyList<NPC.NPC> NPCs { get; private set; }

public IReadOnlyList<IItem> Items { get; private set; }
public IReadOnlyList<MapItem> Items { get; private set; }

public RefreshReplyData()
{
Characters = new List<Character.Character>();
NPCs = new List<NPC.NPC>();
Items = new List<IItem>();
Items = new List<MapItem>();
}

public IRefreshReplyData WithCharacters(IEnumerable<Character.Character> characters)
Expand All @@ -32,10 +32,10 @@ public IRefreshReplyData WithNPCs(IEnumerable<NPC.NPC> npcs)
return newData;
}

public IRefreshReplyData WithItems(IEnumerable<IItem> items)
public IRefreshReplyData WithItems(IEnumerable<MapItem> items)
{
var newData = MakeCopy(this);
newData.Items = new List<IItem>(items);
newData.Items = new List<MapItem>(items);
return newData;
}

Expand All @@ -45,7 +45,7 @@ private static RefreshReplyData MakeCopy(IRefreshReplyData source)
{
Characters = new List<Character.Character>(source.Characters),
NPCs = new List<NPC.NPC>(source.NPCs),
Items = new List<IItem>(source.Items)
Items = new List<MapItem>(source.Items)
};
}
}
Expand All @@ -56,12 +56,12 @@ public interface IRefreshReplyData : ITranslatedData

IReadOnlyList<NPC.NPC> NPCs { get; }

IReadOnlyList<IItem> Items { get; }
IReadOnlyList<MapItem> Items { get; }

IRefreshReplyData WithCharacters(IEnumerable<Character.Character> characters);

IRefreshReplyData WithNPCs(IEnumerable<NPC.NPC> npcs);

IRefreshReplyData WithItems(IEnumerable<IItem> items);
IRefreshReplyData WithItems(IEnumerable<MapItem> items);
}
}
Loading

0 comments on commit c1249b6

Please sign in to comment.