Skip to content

Commit

Permalink
Implement inventory panel skeleton. No inventory items are rendered yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Mar 25, 2022
1 parent 5fa705f commit 04d7450
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 17 deletions.
20 changes: 10 additions & 10 deletions EOLib/Domain/Character/CharacterInventoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ namespace EOLib.Domain.Character
{
public interface ICharacterInventoryRepository
{
List<IInventoryItem> ItemInventory { get; set; }
HashSet<IInventoryItem> ItemInventory { get; set; }

List<IInventorySpell> SpellInventory { get; set; }
HashSet<IInventorySpell> SpellInventory { get; set; }
}

public interface ICharacterInventoryProvider
{
IReadOnlyList<IInventoryItem> ItemInventory { get; }
IReadOnlyCollection<IInventoryItem> ItemInventory { get; }

IReadOnlyList<IInventorySpell> SpellInventory { get; }
IReadOnlyCollection<IInventorySpell> SpellInventory { get; }
}

[AutoMappedType(IsSingleton = true)]
public class CharacterInventoryRepository : ICharacterInventoryRepository, ICharacterInventoryProvider
{
public List<IInventoryItem> ItemInventory { get; set; }
public List<IInventorySpell> SpellInventory { get; set; }
public HashSet<IInventoryItem> ItemInventory { get; set; }
public HashSet<IInventorySpell> SpellInventory { get; set; }

IReadOnlyList<IInventoryItem> ICharacterInventoryProvider.ItemInventory => ItemInventory;
IReadOnlyList<IInventorySpell> ICharacterInventoryProvider.SpellInventory => SpellInventory;
IReadOnlyCollection<IInventoryItem> ICharacterInventoryProvider.ItemInventory => ItemInventory;
IReadOnlyCollection<IInventorySpell> ICharacterInventoryProvider.SpellInventory => SpellInventory;

public CharacterInventoryRepository()
{
ItemInventory = new List<IInventoryItem>(32);
SpellInventory = new List<IInventorySpell>(32);
ItemInventory = new HashSet<IInventoryItem>();
SpellInventory = new HashSet<IInventorySpell>();
}
}
}
15 changes: 15 additions & 0 deletions EOLib/Domain/Character/InventoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ public IInventoryItem WithAmount(int newAmount)
{
return new InventoryItem(ItemID, newAmount);
}

public override bool Equals(object obj)
{
var other = obj as InventoryItem;
if (other == null) return false;
return other.ItemID == ItemID && other.Amount == Amount;
}

public override int GetHashCode()
{
int hashCode = 1754760722;
hashCode = hashCode * -1521134295 + ItemID.GetHashCode();
hashCode = hashCode * -1521134295 + Amount.GetHashCode();
return hashCode;
}
}

public interface IInventoryItem
Expand Down
15 changes: 15 additions & 0 deletions EOLib/Domain/Character/InventorySpell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ public IInventorySpell WithLevel(short newLevel)
{
return new InventorySpell(ID, newLevel);
}

public override bool Equals(object obj)
{
var other = obj as InventorySpell;
if (other == null) return false;
return other.ID == ID && other.Level == Level;
}

public override int GetHashCode()
{
int hashCode = 1754760722;
hashCode = hashCode * -1521134295 + ID.GetHashCode();
hashCode = hashCode * -1521134295 + Level.GetHashCode();
return hashCode;
}
}

public interface IInventorySpell
Expand Down
4 changes: 2 additions & 2 deletions EOLib/Domain/Login/LoginActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ public async Task<CharacterLoginReply> CompleteCharacterLogin()
.WithStats(stats)
.WithRenderProperties(mainCharacter.RenderProperties);

_characterInventoryRepository.ItemInventory = data.CharacterItemInventory.ToList();
_characterInventoryRepository.SpellInventory = data.CharacterSpellInventory.ToList();
_characterInventoryRepository.ItemInventory = new HashSet<IInventoryItem>(data.CharacterItemInventory);
_characterInventoryRepository.SpellInventory = new HashSet<IInventorySpell>(data.CharacterSpellInventory);

_currentMapStateRepository.Characters = data.MapCharacters.Except(new[] { mainCharacter }).ToDictionary(k => k.ID, v => v);
_currentMapStateRepository.NPCs = new HashSet<INPC>(data.MapNPCs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public override ILoginRequestCompletedData TranslatePacket(IPacket packet)
var maxWeight = packet.ReadChar();

var inventoryItems = GetInventoryItems(packet).ToList();
if (!inventoryItems.Any(x => x.ItemID == 1))
inventoryItems.Insert(0, new InventoryItem(1, 0));

var inventorySpells = GetInventorySpells(packet).ToList();

if (inventoryItems.All(x => x.ItemID != 1))
Expand Down
2 changes: 1 addition & 1 deletion EOLib/PacketHandlers/ItemEquipHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected bool HandlePaperdollPacket(IPacket packet, bool itemUnequipped)
.Match(some: invItem => invItem.WithAmount(itemUnequipped ? invItem.Amount + amount : amount),
none: () => new InventoryItem(itemId, amount));

_characterInventoryRepository.ItemInventory.RemoveAll(x => x.ItemID == itemId);
_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == itemId);
_characterInventoryRepository.ItemInventory.Add(updatedItem);
}
else
Expand Down
2 changes: 2 additions & 0 deletions EOLib/misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public static class Constants
public const string FriendListFile = "config/friends.ini";
public const string IgnoreListFile = "config/ignore.ini";

public const string InventoryFile = "config/inventory.ini";

//Should be easily customizable between different clients (based on graphics)
//not a config option because this shouldn't be exposed at the user level
public static readonly int[] TrapSpikeGFXObjectIDs = {449, 450, 451, 452};
Expand Down
19 changes: 17 additions & 2 deletions EndlessClient/HUD/Panels/HudPanelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EndlessClient.Content;
using EndlessClient.Controllers;
using EndlessClient.ControlSets;
using EndlessClient.Dialogs.Actions;
using EndlessClient.Dialogs.Factories;
using EndlessClient.Rendering.Chat;
using EndlessClient.Services;
Expand All @@ -20,40 +21,49 @@ public class HudPanelFactory : IHudPanelFactory
private const int HUD_CONTROL_LAYER = 130;

private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IInGameDialogActions _inGameDialogActions;
private readonly IContentProvider _contentProvider;
private readonly IHudControlProvider _hudControlProvider;
private readonly INewsProvider _newsProvider;
private readonly IChatProvider _chatProvider;
private readonly IPlayerInfoProvider _playerInfoProvider;
private readonly ICharacterProvider _characterProvider;
private readonly ICharacterInventoryProvider _characterInventoryProvider;
private readonly IExperienceTableProvider _experienceTableProvider;
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly ITrainingController _trainingController;
private readonly IFriendIgnoreListService _friendIgnoreListService;
private readonly IStatusLabelSetter _statusLabelSetter;

public HudPanelFactory(INativeGraphicsManager nativeGraphicsManager,
IInGameDialogActions inGameDialogActions,
IContentProvider contentProvider,
IHudControlProvider hudControlProvider,
INewsProvider newsProvider,
IChatProvider chatProvider,
IPlayerInfoProvider playerInfoProvider,
ICharacterProvider characterProvider,
ICharacterInventoryProvider characterInventoryProvider,
IExperienceTableProvider experienceTableProvider,
IEOMessageBoxFactory messageBoxFactory,
ITrainingController trainingController,
IFriendIgnoreListService friendIgnoreListService)
IFriendIgnoreListService friendIgnoreListService,
IStatusLabelSetter statusLabelSetter)
{
_nativeGraphicsManager = nativeGraphicsManager;
_inGameDialogActions = inGameDialogActions;
_contentProvider = contentProvider;
_hudControlProvider = hudControlProvider;
_newsProvider = newsProvider;
_chatProvider = chatProvider;
_playerInfoProvider = playerInfoProvider;
_characterProvider = characterProvider;
_characterInventoryProvider = characterInventoryProvider;
_experienceTableProvider = experienceTableProvider;
_messageBoxFactory = messageBoxFactory;
_trainingController = trainingController;
_friendIgnoreListService = friendIgnoreListService;
_statusLabelSetter = statusLabelSetter;
}

public NewsPanel CreateNewsPanel()
Expand All @@ -68,7 +78,12 @@ public NewsPanel CreateNewsPanel()

public InventoryPanel CreateInventoryPanel()
{
return new InventoryPanel(_nativeGraphicsManager) { DrawOrder = HUD_CONTROL_LAYER };
return new InventoryPanel(_nativeGraphicsManager,
_inGameDialogActions,
_statusLabelSetter,
_playerInfoProvider,
_characterProvider,
_characterInventoryProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public ActiveSpellsPanel CreateActiveSpellsPanel()
Expand Down
Loading

0 comments on commit 04d7450

Please sign in to comment.