diff --git a/EOBot/TrainerBot.cs b/EOBot/TrainerBot.cs index df891dc26..c7d516962 100644 --- a/EOBot/TrainerBot.cs +++ b/EOBot/TrainerBot.cs @@ -343,7 +343,7 @@ private async Task UseHealItem(IEnumerable healItems) ConsoleHelper.WriteMessage(ConsoleHelper.Type.UseItem, $"{itemToUse.Name} - {itemToUse.HP} HP - inventory: {amount - 1} - (other heal item types: {healItems.Count() - 1})"); - await TrySend(() => _characterActions.UseItem(itemToUse.ID)); + await TrySend(() => _characterActions.UseItem((short)itemToUse.ID)); await Task.Delay(ATTACK_BACKOFF_MS); } diff --git a/EOLib/Domain/Character/CharacterActions.cs b/EOLib/Domain/Character/CharacterActions.cs index e0a0b9095..3bb0fcad5 100644 --- a/EOLib/Domain/Character/CharacterActions.cs +++ b/EOLib/Domain/Character/CharacterActions.cs @@ -79,10 +79,30 @@ public void ToggleSit() _packetSendService.SendPacket(packet); } - public void UseItem(int itemId) + public void UseItem(short itemId) { var packet = new PacketBuilder(PacketFamily.Item, PacketAction.Use) - .AddShort((short)itemId) + .AddShort(itemId) + .Build(); + + _packetSendService.SendPacket(packet); + } + + public void EquipItem(short itemId, bool alternateLocation) + { + var packet = new PacketBuilder(PacketFamily.PaperDoll, PacketAction.Add) + .AddShort(itemId) + .AddChar((byte)(alternateLocation ? 1 : 0)) + .Build(); + + _packetSendService.SendPacket(packet); + } + + public void UnequipItem(short itemId, bool alternateLocation) + { + var packet = new PacketBuilder(PacketFamily.PaperDoll, PacketAction.Remove) + .AddShort(itemId) + .AddChar((byte)(alternateLocation ? 1 : 0)) .Build(); _packetSendService.SendPacket(packet); @@ -159,7 +179,11 @@ public interface ICharacterActions void ToggleSit(); - void UseItem(int itemId); + void UseItem(short itemId); + + void EquipItem(short itemId, bool alternateLocation); + + void UnequipItem(short itemId, bool alternateLocation); void PrepareCastSpell(int spellId); diff --git a/EOLib/Net/API/Avatar.cs b/EOLib/Net/API/Avatar.cs deleted file mode 100644 index cab84a81a..000000000 --- a/EOLib/Net/API/Avatar.cs +++ /dev/null @@ -1,54 +0,0 @@ -using EOLib.Domain.Character; - -namespace EOLib.Net.API -{ - public struct AvatarData - { - private readonly short boots, armor, hat, shield, weapon; - private readonly bool sound; - private readonly byte hairstyle, haircolor; - private readonly AvatarSlot slot; - private readonly short pid; - - public short ID => pid; - public AvatarSlot Slot => slot; - - public bool Sound => sound; - - public short Boots => boots; - public short Armor => armor; - public short Hat => hat; - public short Shield => shield; - public short Weapon => weapon; - - public byte HairStyle => hairstyle; - public byte HairColor => haircolor; - - internal AvatarData(short id, AvatarSlot slot, bool sound, short boots, short armor, short hat, short weapon, short shield) - { - pid = id; - this.slot = slot; - - this.sound = sound; - this.boots = boots; - this.armor = armor; - this.hat = hat; - this.shield = shield; - this.weapon = weapon; - - hairstyle = haircolor = 0; - } - - internal AvatarData(short id, AvatarSlot slot, byte hairStyle, byte hairColor) - { - pid = id; - this.slot = slot; - - hairstyle = hairStyle; - haircolor = hairColor; - - sound = false; - boots = armor = hat = shield = weapon = 0; - } - } -} diff --git a/EOLib/Net/API/PacketAPI.cs b/EOLib/Net/API/PacketAPI.cs index 8c307faf7..438f4074c 100644 --- a/EOLib/Net/API/PacketAPI.cs +++ b/EOLib/Net/API/PacketAPI.cs @@ -28,7 +28,6 @@ public PacketAPI(EOClient client) _createLockerMembers(); _createMessageMembers(); _createMusicMembers(); - _createPaperdollMembers(); _createPartyMembers(); _createNPCMembers(); _createQuestMembers(); diff --git a/EOLib/Net/API/Paperdoll.cs b/EOLib/Net/API/Paperdoll.cs deleted file mode 100644 index 88acd1130..000000000 --- a/EOLib/Net/API/Paperdoll.cs +++ /dev/null @@ -1,152 +0,0 @@ -using EOLib.Domain.Character; -using EOLib.Net.Handlers; - -namespace EOLib.Net.API -{ - public struct PaperdollEquipData - { - private readonly bool itemRemoved; - private readonly short itemID; - private readonly int characterAmount; - private readonly byte subLoc; - private readonly short maxhp, maxtp, disp_str, disp_int, disp_wis, - disp_agi, disp_con, disp_cha, mindam, maxdam, accuracy, evade, armor; - - /// - /// This structure contains data about an item that was unequipped - /// - public bool ItemWasUnequipped => itemRemoved; - - /// - /// Item ID of Item that was equipped - /// - public short ItemID => itemID; - - /// - /// Amount of item remaining in inventory - /// - public int ItemAmount => characterAmount; - - public byte SubLoc => subLoc; - - public short MaxHP => maxhp; - public short MaxTP => maxtp; - public short Str => disp_str; - public short Int => disp_int; - public short Wis => disp_wis; - public short Agi => disp_agi; - public short Con => disp_con; - public short Cha => disp_cha; - - public short MinDam => mindam; - public short MaxDam => maxdam; - public short Accuracy => accuracy; - public short Evade => evade; - public short Armor => armor; - - internal PaperdollEquipData(OldPacket pkt, bool itemUnequipped) - { - itemRemoved = itemUnequipped; - - itemID = pkt.GetShort(); - characterAmount = itemUnequipped ? 1 : pkt.GetThree(); - subLoc = pkt.GetChar(); - - maxhp = pkt.GetShort(); - maxtp = pkt.GetShort(); - disp_str = pkt.GetShort(); - disp_int = pkt.GetShort(); - disp_wis = pkt.GetShort(); - disp_agi = pkt.GetShort(); - disp_con = pkt.GetShort(); - disp_cha = pkt.GetShort(); - mindam = pkt.GetShort(); - maxdam = pkt.GetShort(); - accuracy = pkt.GetShort(); - evade = pkt.GetShort(); - armor = pkt.GetShort(); - } - } - - partial class PacketAPI - { - public delegate void PaperdollChangeEvent(PaperdollEquipData data); - public event PaperdollChangeEvent OnPlayerPaperdollChange; - - private void _createPaperdollMembers() - { - m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.PaperDoll, PacketAction.Agree), _handlePaperdollAgree, true); - m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.PaperDoll, PacketAction.Remove), _handlePaperdollRemove, true); - } - - public bool EquipItem(short id, byte subLoc = 0) - { - if (!m_client.ConnectedAndInitialized || !Initialized) return false; - - OldPacket pkt = new OldPacket(PacketFamily.PaperDoll, PacketAction.Add); - pkt.AddShort(id); - pkt.AddChar(subLoc); - - return m_client.SendPacket(pkt); - } - - public bool UnequipItem(short id, byte subLoc = 0) - { - if (!m_client.ConnectedAndInitialized || !Initialized) return false; - - OldPacket pkt = new OldPacket(PacketFamily.PaperDoll, PacketAction.Remove); - pkt.AddShort(id); - pkt.AddChar(subLoc); - - return m_client.SendPacket(pkt); - } - - //this is only ever sent to MainPlayer (avatar handles other players) - private void _handlePaperdollAgree(OldPacket pkt) - { - if (OnPlayerPaperdollChange == null) return; - - //see PlayerAvatarChangeHandler - //_handleAvatarAgree(pkt); //same logic in the beginning of the packet - - PaperdollEquipData data = new PaperdollEquipData(pkt, false); - OnPlayerPaperdollChange(data); - } - - //this is only ever sent to MainPlayer (avatar handles other players) - private void _handlePaperdollRemove(OldPacket pkt) - { - if (OnPlayerPaperdollChange == null) return; - - //the $strip command does this wrong (adding 0's in), somehow the original client is smart enough to figure it out - //normally would put this block in the _handleAvatarAgree - short playerID = pkt.GetShort(); - AvatarSlot slot = (AvatarSlot) pkt.GetChar(); - bool sound = pkt.GetChar() == 0; //sound : 0 - - short boots = pkt.GetShort(); - if (pkt.Length != 45) pkt.Skip(sizeof(short) * 3); //three 0s - short armor = pkt.GetShort(); - if (pkt.Length != 45) pkt.Skip(sizeof(short)); // one 0 - short hat = pkt.GetShort(); - short shield, weapon; - if (pkt.Length != 45) - { - shield = pkt.GetShort(); - weapon = pkt.GetShort(); - } - else - { - weapon = pkt.GetShort(); - shield = pkt.GetShort(); - } - - AvatarData renderData = new AvatarData(playerID, slot, sound, boots, armor, hat, weapon, shield); - //if (OnPlayerAvatarChange != null) //see PlayerAvatarChangeHandler - // OnPlayerAvatarChange(renderData); - - PaperdollEquipData data = new PaperdollEquipData(pkt, true); - OnPlayerPaperdollChange(data); - } - } -} diff --git a/EOLib/PacketHandlers/ItemEquipHandler.cs b/EOLib/PacketHandlers/ItemEquipHandler.cs new file mode 100644 index 000000000..abdd49227 --- /dev/null +++ b/EOLib/PacketHandlers/ItemEquipHandler.cs @@ -0,0 +1,159 @@ +using AutomaticTypeMapper; +using EOLib.Domain.Character; +using EOLib.Domain.Login; +using EOLib.Domain.Map; +using EOLib.IO.Extensions; +using EOLib.IO.Repositories; +using EOLib.Net; +using Optional; +using Optional.Collections; +using System.Linq; + +namespace EOLib.PacketHandlers +{ + public abstract class ItemEquipHandler : PlayerAvatarChangeHandler + { + private readonly IPaperdollRepository _paperdollRepository; + private readonly ICharacterInventoryRepository _characterInventoryRepository; + + protected ItemEquipHandler(IPlayerInfoProvider playerInfoProvider, + ICurrentMapStateRepository currentMapStateRepository, + ICharacterRepository characterRepository, + IEIFFileProvider eifFileProvider, + IPaperdollRepository paperdollRepository, + ICharacterInventoryRepository characterInventoryRepository) + : base(playerInfoProvider, currentMapStateRepository, characterRepository, eifFileProvider) + { + _paperdollRepository = paperdollRepository; + _characterInventoryRepository = characterInventoryRepository; + } + + protected bool HandlePaperdollPacket(IPacket packet, bool itemUnequipped) + { + var playerId = packet.PeekShort(); + + if (!base.HandlePacket(packet)) + return false; + + var itemId = packet.ReadShort(); + var amount = itemUnequipped ? 1 : packet.ReadThree(); + var subLoc = packet.ReadChar(); + + var maxhp = packet.ReadShort(); + var maxtp = packet.ReadShort(); + var disp_str = packet.ReadShort(); + var disp_int = packet.ReadShort(); + var disp_wis = packet.ReadShort(); + var disp_agi = packet.ReadShort(); + var disp_con = packet.ReadShort(); + var disp_cha = packet.ReadShort(); + var mindam = packet.ReadShort(); + var maxdam = packet.ReadShort(); + var accuracy = packet.ReadShort(); + var evade = packet.ReadShort(); + var armor = packet.ReadShort(); + + if (_paperdollRepository.VisibleCharacterPaperdolls.ContainsKey(playerId)) + { + var paperdollData = _paperdollRepository.VisibleCharacterPaperdolls[playerId]; + + var itemRec = _eifFileProvider.EIFFile[itemId]; + var paperdollSlot = itemRec.GetEquipLocation() + subLoc; + + var paperdollEquipData = paperdollData.Paperdoll.ToDictionary(k => k.Key, v => v.Value); + paperdollEquipData[paperdollSlot] = itemUnequipped ? (short)0 : itemId; + + _paperdollRepository.VisibleCharacterPaperdolls[playerId] = paperdollData.WithPaperdoll(paperdollEquipData); + } + + var update = _characterRepository.MainCharacter.ID == playerId + ? Option.Some(_characterRepository.MainCharacter) + : _currentMapStateRepository.Characters.ContainsKey(playerId) + ? Option.Some(_currentMapStateRepository.Characters[playerId]) + : Option.None(); + + update.MatchSome(c => + { + var stats = c.Stats + .WithNewStat(CharacterStat.MaxHP, maxhp) + .WithNewStat(CharacterStat.MaxTP, maxtp) + .WithNewStat(CharacterStat.Strength, disp_str) + .WithNewStat(CharacterStat.Intelligence, disp_int) + .WithNewStat(CharacterStat.Wisdom, disp_wis) + .WithNewStat(CharacterStat.Agility, disp_agi) + .WithNewStat(CharacterStat.Constituion, disp_con) + .WithNewStat(CharacterStat.Charisma, disp_cha) + .WithNewStat(CharacterStat.MinDam, mindam) + .WithNewStat(CharacterStat.MaxDam, maxdam) + .WithNewStat(CharacterStat.Accuracy, accuracy) + .WithNewStat(CharacterStat.Evade, evade) + .WithNewStat(CharacterStat.Armor, armor); + + if (c == _characterRepository.MainCharacter) + { + _characterRepository.MainCharacter = c.WithStats(stats); + + var updatedItem = _characterInventoryRepository.ItemInventory + .SingleOrNone(x => x.ItemID == itemId) + .Match(some: invItem => invItem.WithAmount(itemUnequipped ? invItem.Amount + amount : amount), + none: () => new InventoryItem(itemId, amount)); + + _characterInventoryRepository.ItemInventory.RemoveAll(x => x.ItemID == itemId); + _characterInventoryRepository.ItemInventory.Add(updatedItem); + } + else + { + _currentMapStateRepository.Characters[playerId] = c.WithStats(stats); + } + }); + + return true; + } + } + + [AutoMappedType] + public class PaperdollAgreeHandler : ItemEquipHandler + { + public override PacketFamily Family => PacketFamily.PaperDoll; + + public override PacketAction Action => PacketAction.Agree; + + public PaperdollAgreeHandler(IPlayerInfoProvider playerInfoProvider, + ICurrentMapStateRepository currentMapStateRepository, + ICharacterRepository characterRepository, + IEIFFileProvider eifFileProvider, + IPaperdollRepository paperdollRepository, + ICharacterInventoryRepository characterInventoryRepository) + : base(playerInfoProvider, currentMapStateRepository, characterRepository, eifFileProvider, paperdollRepository, characterInventoryRepository) + { + } + + public override bool HandlePacket(IPacket packet) + { + return HandlePaperdollPacket(packet, itemUnequipped: false); + } + } + + [AutoMappedType] + public class PaperdollRemoveHandler : ItemEquipHandler + { + public override PacketFamily Family => PacketFamily.PaperDoll; + + public override PacketAction Action => PacketAction.Remove; + + public PaperdollRemoveHandler(IPlayerInfoProvider playerInfoProvider, + ICurrentMapStateRepository currentMapStateRepository, + ICharacterRepository characterRepository, + IEIFFileProvider eifFileProvider, + IPaperdollRepository paperdollRepository, + ICharacterInventoryRepository characterInventoryRepository) + : base(playerInfoProvider, currentMapStateRepository, characterRepository, eifFileProvider, paperdollRepository, characterInventoryRepository) + { + } + + public override bool HandlePacket(IPacket packet) + { + return HandlePaperdollPacket(packet, itemUnequipped: true); + } + } +} diff --git a/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs b/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs index 4ef5d4775..6c74a4ef1 100644 --- a/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs +++ b/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs @@ -12,9 +12,9 @@ namespace EOLib.PacketHandlers [AutoMappedType] public class PlayerAvatarChangeHandler : InGameOnlyPacketHandler { - private readonly ICurrentMapStateRepository _currentMapStateRepository; - private readonly ICharacterRepository _characterRepository; - private readonly IEIFFileProvider _eifFileProvider; + protected readonly ICurrentMapStateRepository _currentMapStateRepository; + protected readonly ICharacterRepository _characterRepository; + protected readonly IEIFFileProvider _eifFileProvider; public override PacketFamily Family => PacketFamily.Avatar; diff --git a/EndlessClient/Dialogs/Factories/PaperdollDialogFactory.cs b/EndlessClient/Dialogs/Factories/PaperdollDialogFactory.cs index 44796f724..bb073576f 100644 --- a/EndlessClient/Dialogs/Factories/PaperdollDialogFactory.cs +++ b/EndlessClient/Dialogs/Factories/PaperdollDialogFactory.cs @@ -2,6 +2,7 @@ using EndlessClient.Dialogs.Services; using EndlessClient.GameExecution; using EndlessClient.HUD; +using EndlessClient.HUD.Inventory; using EOLib.Domain.Character; using EOLib.Graphics; using EOLib.IO.Repositories; @@ -13,25 +14,31 @@ public class PaperdollDialogFactory : IPaperdollDialogFactory { private readonly IGameStateProvider _gameStateProvider; private readonly IEODialogButtonService _eoDialogButtonService; + private readonly IInventorySpaceValidator _inventorySpaceValidator; private readonly IEOMessageBoxFactory _eoMessageBoxFactory; private readonly IStatusLabelSetter _statusLabelSetter; private readonly IPaperdollProvider _paperdollProvider; private readonly IPubFileProvider _pubFileProvider; private readonly INativeGraphicsManager _nativeGraphicsManager; + private readonly ICharacterActions _characterActions; public PaperdollDialogFactory(IGameStateProvider gameStateProvider, INativeGraphicsManager nativeGraphicsManager, + ICharacterActions characterActions, IPaperdollProvider paperdollProvider, IPubFileProvider pubFileProvider, IEODialogButtonService eoDialogButtonService, + IInventorySpaceValidator inventorySpaceValidator, IEOMessageBoxFactory eoMessageBoxFactory, IStatusLabelSetter statusLabelSetter) { _paperdollProvider = paperdollProvider; _pubFileProvider = pubFileProvider; _nativeGraphicsManager = nativeGraphicsManager; + _characterActions = characterActions; _gameStateProvider = gameStateProvider; _eoDialogButtonService = eoDialogButtonService; + _inventorySpaceValidator = inventorySpaceValidator; _eoMessageBoxFactory = eoMessageBoxFactory; _statusLabelSetter = statusLabelSetter; } @@ -40,9 +47,11 @@ public PaperdollDialog Create(ICharacter character, bool isMainCharacter) { return new PaperdollDialog(_gameStateProvider, _nativeGraphicsManager, + _characterActions, _paperdollProvider, _pubFileProvider, _eoDialogButtonService, + _inventorySpaceValidator, _eoMessageBoxFactory, _statusLabelSetter, character, diff --git a/EndlessClient/Dialogs/PaperdollDialog.cs b/EndlessClient/Dialogs/PaperdollDialog.cs index e35ca9e26..bc6c73731 100644 --- a/EndlessClient/Dialogs/PaperdollDialog.cs +++ b/EndlessClient/Dialogs/PaperdollDialog.cs @@ -2,6 +2,7 @@ using EndlessClient.Dialogs.Services; using EndlessClient.GameExecution; using EndlessClient.HUD; +using EndlessClient.HUD.Inventory; using EOLib; using EOLib.Domain.Character; using EOLib.Domain.Online; @@ -25,8 +26,10 @@ public class PaperdollDialog : BaseEODialog private static readonly Rectangle _iconDrawRect = new Rectangle(227, 258, 44, 21); private readonly INativeGraphicsManager _nativeGraphicsManager; + private readonly ICharacterActions _characterActions; private readonly IPaperdollProvider _paperdollProvider; private readonly IPubFileProvider _pubFileProvider; + private readonly IInventorySpaceValidator _inventorySpaceValidator; private readonly IEOMessageBoxFactory _eoMessageBoxFactory; private readonly IStatusLabelSetter _statusLabelSetter; private readonly bool _isMainCharacter; @@ -48,9 +51,11 @@ public class PaperdollDialog : BaseEODialog public PaperdollDialog(IGameStateProvider gameStateProvider, INativeGraphicsManager nativeGraphicsManager, + ICharacterActions characterActions, IPaperdollProvider paperdollProvider, IPubFileProvider pubFileProvider, IEODialogButtonService eoDialogButtonService, + IInventorySpaceValidator inventorySpaceValidator, IEOMessageBoxFactory eoMessageBoxFactory, IStatusLabelSetter statusLabelSetter, ICharacter character, bool isMainCharacter) @@ -58,9 +63,11 @@ public PaperdollDialog(IGameStateProvider gameStateProvider, { _paperdollProvider = paperdollProvider; _pubFileProvider = pubFileProvider; + _inventorySpaceValidator = inventorySpaceValidator; _eoMessageBoxFactory = eoMessageBoxFactory; _statusLabelSetter = statusLabelSetter; _nativeGraphicsManager = nativeGraphicsManager; + _characterActions = characterActions; Character = character; _isMainCharacter = isMainCharacter; _characterIconSheet = _nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 32, true); @@ -115,19 +122,6 @@ public PaperdollDialog(IGameStateProvider gameStateProvider, _paperdollData = Option.None(); } - // todo: equip/unequip - //public void SetItem(EquipLocation loc, EIFRecord info) - //{ - // PaperdollDialogItem itemToUpdate = (PaperdollDialogItem)children.Find(_ctrl => - // { - // PaperdollDialogItem item = _ctrl as PaperdollDialogItem; - // if (item == null) return false; - // return item.EquipLoc == loc; - // }); - // if (itemToUpdate != null) - // itemToUpdate.SetInfo(_getEquipLocRectangle(loc), info); - //} - protected override void OnUpdateControl(GameTime gameTime) { base.OnUpdateControl(gameTime); @@ -200,7 +194,9 @@ private void UpdateDisplayedData(IPaperdollData paperdollData) _guild.Text = Capitalize(paperdollData.Guild); _rank.Text = Capitalize(paperdollData.Rank); - foreach (var control in ChildControls.OfType()) + var paperdollDialogItems = ChildControls.OfType().ToList(); + + foreach (var control in paperdollDialogItems) { control.SetControlUnparented(); control.Dispose(); @@ -256,25 +252,22 @@ private void UpdateDisplayedData(IPaperdollData paperdollData) var msgBox = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.ITEM_IS_CURSED_ITEM, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader); msgBox.ShowDialog(); } - // todo: unequip to inventory if it fits - //else if (!((EOGame)Game).Hud.InventoryFits((short)m_info.ID)) - //{ - // ((EOGame)Game).Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_ITEM_UNEQUIP_NO_SPACE_LEFT); - //} - //else - //{ - // _setSize(m_area.Width, m_area.Height); - // DrawLocation = new Vector2(m_area.X + (m_area.Width / 2 - DrawArea.Width / 2), - // m_area.Y + (m_area.Height / 2 - DrawArea.Height / 2)); - - // //put back in the inventory by the packet handler response - // string locName = Enum.GetName(typeof(EquipLocation), EquipLocation); - // if (!string.IsNullOrEmpty(locName)) - // m_api.UnequipItem((short)m_info.ID, (byte)(locName.Contains("2") ? 1 : 0)); - - // m_info = null; - // m_gfx = null; - //} + else + { + eifRecord.MatchSome(rec => + { + if (!_inventorySpaceValidator.ItemFits(rec.Size)) + { + _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_ITEM_UNEQUIP_NO_SPACE_LEFT); + } + else + { + // packet reply handles updating the paperdoll for the character which will unrender the equipment + string locName = Enum.GetName(typeof(EquipLocation), equipLocation); + _characterActions.UnequipItem((short)rec.ID, alternateLocation: locName.Contains("2")); + } + }); + } }; paperdollItem.SetParentControl(this); diff --git a/EndlessClient/HUD/Inventory/InventorySpaceValidator.cs b/EndlessClient/HUD/Inventory/InventorySpaceValidator.cs index b26897063..6dcfd18c5 100644 --- a/EndlessClient/HUD/Inventory/InventorySpaceValidator.cs +++ b/EndlessClient/HUD/Inventory/InventorySpaceValidator.cs @@ -1,5 +1,6 @@ using AutomaticTypeMapper; using EOLib.Domain.Map; +using EOLib.IO; using EOLib.IO.Repositories; namespace EndlessClient.HUD.Inventory @@ -16,7 +17,11 @@ public InventorySpaceValidator(IEIFFileProvider eifFileProvider) public bool ItemFits(IItem item) { - var itemSize = _eifFileProvider.EIFFile[item.ItemID].Size; + return ItemFits(_eifFileProvider.EIFFile[item.ItemID].Size); + } + + public bool ItemFits(ItemSize itemSize) + { // todo: inventory grid management return true; } @@ -25,5 +30,7 @@ public bool ItemFits(IItem item) public interface IInventorySpaceValidator { bool ItemFits(IItem item); + + bool ItemFits(ItemSize itemSize); } } diff --git a/EndlessClient/HUD/Inventory/OldEOInventoryItem.cs b/EndlessClient/HUD/Inventory/OldEOInventoryItem.cs index 99f6750f0..3368771a8 100644 --- a/EndlessClient/HUD/Inventory/OldEOInventoryItem.cs +++ b/EndlessClient/HUD/Inventory/OldEOInventoryItem.cs @@ -496,8 +496,8 @@ private void _handleDoubleClick() if (c.EquipItem(m_itemData.Type, (short)m_itemData.ID, (short)m_itemData.DollGraphic)) { - if (!m_api.EquipItem((short)m_itemData.ID, subLoc)) - EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu(); + //if (!m_api.EquipItem((short)m_itemData.ID, subLoc)) + // EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu(); } else EOGame.Instance.Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_INFORMATION, diff --git a/EndlessClient/Old/OldCharacter.cs b/EndlessClient/Old/OldCharacter.cs index 7e23f0388..e6cd59f00 100644 --- a/EndlessClient/Old/OldCharacter.cs +++ b/EndlessClient/Old/OldCharacter.cs @@ -516,25 +516,6 @@ public void SetDisplayItemsFromRenderData(CharRenderData newRenderData) EquipItem(ItemType.Weapon, (short)(OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Weapon && x.DollGraphic == newRenderData.weapon) ?? new EIFRecord()).ID, newRenderData.weapon, true); } - public void UpdateStatsAfterEquip(PaperdollEquipData data) - { - Stats.MaxHP = data.MaxHP; - Stats.MaxTP = data.MaxTP; - - Stats.Str = data.Str; - Stats.Int = data.Int; - Stats.Wis = data.Wis; - Stats.Agi = data.Agi; - Stats.Con = data.Con; - Stats.Cha = data.Cha; - - Stats.MinDam = data.MinDam; - Stats.MaxDam = data.MaxDam; - Stats.Accuracy = data.Accuracy; - Stats.Evade = data.Evade; - Stats.Armor = data.Armor; - } - public ChestKey CanOpenChest(ChestSpawnMapEntity chest) { ChestKey permission = chest.Key; diff --git a/EndlessClient/Old/PacketAPICallbackManager.cs b/EndlessClient/Old/PacketAPICallbackManager.cs index 4c440b08e..1ceb34037 100644 --- a/EndlessClient/Old/PacketAPICallbackManager.cs +++ b/EndlessClient/Old/PacketAPICallbackManager.cs @@ -1,15 +1,12 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using EndlessClient.Audio; using EndlessClient.Dialogs; using EndlessClient.Dialogs.Old; using EOLib.Domain.Character; using EOLib.Domain.Chat; using EOLib.Domain.Map; -using EOLib.IO; -using EOLib.IO.Extensions; using EOLib.Localization; using EOLib.Net.API; using XNAControls.Old; @@ -29,8 +26,6 @@ public PacketAPICallbackManager(PacketAPI apiObj, EOGame game) public void AssignCallbacks() { - m_packetAPI.OnPlayerPaperdollChange += _playerPaperdollChange; - //chest related m_packetAPI.OnChestOpened += _chestOpen; m_packetAPI.OnChestAgree += _chestAgree; @@ -103,31 +98,6 @@ public void AssignCallbacks() m_packetAPI.OnCastSpellTargetGroup += _playerCastGroupSpell; } - private void _playerPaperdollChange(PaperdollEquipData _data) - { - OldCharacter c; - if (!_data.ItemWasUnequipped) - { - var rec = OldWorld.Instance.EIF[_data.ItemID]; - //update inventory - (c = OldWorld.Instance.MainPlayer.ActiveCharacter).UpdateInventoryItem(_data.ItemID, _data.ItemAmount); - //equip item - c.EquipItem(rec.Type, (short) rec.ID, (short) rec.DollGraphic, true, (sbyte) _data.SubLoc); - //add to paperdoll dialog - //if (EOPaperdollDialog.Instance != null) - // EOPaperdollDialog.Instance.SetItem(rec.GetEquipLocation() + _data.SubLoc, rec); - } - else - { - c = OldWorld.Instance.MainPlayer.ActiveCharacter; - //update inventory - c.UpdateInventoryItem(_data.ItemID, 1, true); //true: add to existing quantity - //unequip item - c.UnequipItem(OldWorld.Instance.EIF[_data.ItemID].Type, _data.SubLoc); - } - c.UpdateStatsAfterEquip(_data); - } - private void _chestOpen(ChestData data) { if (ChestDialog.Instance == null || data.X != ChestDialog.Instance.CurrentChestX ||