diff --git a/Directory.Packages.props b/Directory.Packages.props index a07dfcf1ca..5700805b02 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -43,7 +43,7 @@ - + diff --git a/documentation/manual-test-plan.md b/documentation/manual-test-plan.md index 33373beda0..20cf77bf27 100644 --- a/documentation/manual-test-plan.md +++ b/documentation/manual-test-plan.md @@ -1177,6 +1177,22 @@ Needs two characters on the same channel. The commending one must be level 31 or - [ ] Not verifiable yet: a move onto a taken slot being refused, since the client always picks a free slot itself +### Item info windows + +- [ ] Right-click each of these in the EQUIP tab and confirm an info window opens with its + values: a hat and a mask (defences), a costume suit and a costume hat (remaining time + for a timed one, "permanent" otherwise, tradable until worn), an amulet (remaining + time), a card holder with and without a card (the stored card's level, points and + upgrade), a fairy bead with and without a fairy (the fairy's element rate), a weapon or + wing skin, and a partner card (its three skills) +- [ ] From the ADDITIONAL tab, right-click a card in the card inventory (the specialist window + opens) and a costume in the costume inventory +- [ ] Open a partner's page (P) and right-click its card and its weapon +- [ ] At an NPC shop, right-click an item for sale: its info window opens +- [ ] Open one card's specialist window, close it, then right-click a different card: in the + browser client the second window did not open although its slinfo arrived. Check + whether the game client does the same + ### Potions - [ ] Take some damage, then use a Small Health Potion (`$CreateItem 1002`): the HP bar diff --git a/src/NosCore.Data/Enumerations/Battle/AttackType.cs b/src/NosCore.Data/Enumerations/Battle/AttackType.cs deleted file mode 100644 index d4ac00b191..0000000000 --- a/src/NosCore.Data/Enumerations/Battle/AttackType.cs +++ /dev/null @@ -1,16 +0,0 @@ -// __ _ __ __ ___ __ ___ ___ -// | \| |/__\ /' _/ / _//__\| _ \ __| -// | | ' | \/ |`._`.| \_| \/ | v / _| -// |_|\__|\__/ |___/ \__/\__/|_|_\___| -// - -namespace NosCore.Data.Enumerations.Battle -{ - // The skill file's attack type column, also the profile a character window row shows. - public enum AttackType : byte - { - Melee = 0, - Ranged = 1, - Magical = 2 - } -} diff --git a/src/NosCore.GameObject/Ecs/Extensions/PlayerBundleExtensions.cs b/src/NosCore.GameObject/Ecs/Extensions/PlayerBundleExtensions.cs index 7331570aaf..8347ce5880 100644 --- a/src/NosCore.GameObject/Ecs/Extensions/PlayerBundleExtensions.cs +++ b/src/NosCore.GameObject/Ecs/Extensions/PlayerBundleExtensions.cs @@ -16,7 +16,6 @@ using NosCore.Core.I18N; using NosCore.Data.Dto; using NosCore.Data.Enumerations; -using NosCore.Data.Enumerations.Battle; using NosCore.GameObject.Ecs.Extensions; using NosCore.GameObject.InterChannelCommunication.Hubs.BlacklistHub; using NosCore.GameObject.InterChannelCommunication.Hubs.ChannelHub; @@ -497,9 +496,9 @@ public static FdPacket GenerateFd(this PlayerComponentBundle player) return new FdPacket { Reput = player.Reputation, - ReputIcon = (int)player.ReputIcon, + ReputIcon = player.ReputIcon, Dignity = player.Dignity, - DignityIcon = (int)player.DignityIcon + DignityIcon = player.DignityIcon }; } @@ -528,7 +527,7 @@ public static TcInfoPacket GenerateReqInfo(this PlayerComponentBundle player, FamilyId = player.Family?.FamilyId ?? -1, FamilyName = player.GenerateFamilyTag(localizer, viewerLanguage), ReputationIco = (ExtendedReputationType)player.ReputIcon, - DignityIco = (CharacterDignity)player.DignityIcon, + DignityIco = player.DignityIcon, HaveWeapon = weapon != null ? 1 : 0, WeaponRare = weapon?.Rare ?? 0, WeaponUpgrade = weapon?.Upgrade ?? 0, @@ -708,14 +707,14 @@ public static ScPacket GenerateSc(this PlayerComponentBundle player, IBattleStat }; return new ScPacket { - Type = (byte)mainType, + Type = mainType, MainWeaponUpgrade = (byte)stats.MeleeUpgrade, MinHit = Math.Max(0, stats.MinHit), MaxHit = Math.Max(0, stats.MaxHit), HitRate = stats.HitRate, CriticalHitRate = (short)stats.CriticalChance, CriticalHitMultiplier = stats.CriticalRate, - Type2 = (byte)secondaryType, + Type2 = secondaryType, SecondaryWeaponUpgrade = (short)stats.RangedUpgrade, SecondaryMinHit = (short)Math.Max(0, stats.MinDistance), SecondaryMaxHit = (short)Math.Max(0, stats.MaxDistance), diff --git a/src/NosCore.GameObject/Services/ItemInfoService/ItemInfoService.cs b/src/NosCore.GameObject/Services/ItemInfoService/ItemInfoService.cs index dbf2c81d3f..ea445d3048 100644 --- a/src/NosCore.GameObject/Services/ItemInfoService/ItemInfoService.cs +++ b/src/NosCore.GameObject/Services/ItemInfoService/ItemInfoService.cs @@ -15,11 +15,16 @@ using NosCore.Data.Enumerations.Items; using NosCore.Data.StaticEntities; using NosCore.GameObject.Services.ItemGenerationService.Item; +using NosCore.GameObject.Services.FairyBeadService; +using NosCore.GameObject.Services.MateService; using NosCore.GameObject.Services.SpecialistCardService; +using NosCore.GameObject.Services.SpecialistHolderService; +using NodaTime; using NosCore.Packets.Enumerations; using NosCore.GameObject.Services.SkillService; using NosCore.Packets.Interfaces; using NosCore.Packets.ServerPackets.Inventory; +using NosCore.Packets.ServerPackets.Mates; namespace NosCore.GameObject.Services.ItemInfoService; @@ -28,9 +33,15 @@ public sealed class ItemInfoService( List skills, ISpExperienceService spExperienceService, ISpecialistPointService specialistPointService, - ISpecialistCardService specialistCardService) : IItemInfoService + ISpecialistCardService specialistCardService, + ISpecialistHolderService specialistHolderService, + IFairyBeadService fairyBeadService, + IPartnerSpecialistService partnerSpecialistService, + IClock clock) : IItemInfoService { private const int ListedSpecialistSkills = 10; + private const byte PartnerSpecialistSubType = 4; + private const int PermanentHours = -1; private const byte AdventurerClass = 1; private const byte SwordsmanClass = 2; @@ -41,13 +52,25 @@ public sealed class ItemInfoService( { return itemInstance switch { + SpecialistInstance { Item.ItemSubType: PartnerSpecialistSubType } partnerCard => GeneratePartnerSpecialistInfo(partnerCard), SpecialistInstance specialist => GenerateSpecialistInfo(specialist), + BoxInstance holder when specialistHolderService.IsSpecialistHolder(holder) => GenerateHolderInfo(holder), + BoxInstance bead when fairyBeadService.IsFairyBead(bead) => GenerateFairyBeadInfo(bead), WearableInstance { Item.ItemType: ItemType.Shell } shell => GenerateShellInfo(shell), WearableInstance wearable => wearable.Item.EquipmentSlot switch { EquipmentType.MainWeapon or EquipmentType.SecondaryWeapon => GenerateWeaponInfo(wearable), EquipmentType.Armor => GenerateArmorInfo(wearable), - EquipmentType.Gloves or EquipmentType.Boots => GenerateAccessoryInfo(wearable), + EquipmentType.Gloves or EquipmentType.Boots or EquipmentType.Hat or EquipmentType.Mask => GenerateAccessoryInfo(wearable), + EquipmentType.CostumeSuit => GenerateCostumeInfo(wearable), + EquipmentType.CostumeHat or EquipmentType.WeaponSkin or EquipmentType.WingSkin => GenerateCostumeHatInfo(wearable), + EquipmentType.Amulet => new EInfoAmuletPacket + { + ItemVNum = wearable.ItemVNum, + LevelMinimum = wearable.Item.LevelMinimum, + RemainingTime = RemainingSeconds(wearable) * 10, + Price = wearable.Item.Price, + }, EquipmentType.Necklace or EquipmentType.Ring or EquipmentType.Bracelet => GenerateJewelryInfo(wearable), EquipmentType.Fairy => new EInfoFairyPacket { @@ -139,6 +162,145 @@ private static EInfoAccessoryPacket GenerateAccessoryInfo(WearableInstance acces }; } + private EInfoCostumePacket GenerateCostumeInfo(WearableInstance costume) + { + var item = costume.Item; + return new EInfoCostumePacket + { + ItemVNum = costume.ItemVNum, + Rare = costume.Rare, + Upgrade = costume.Upgrade, + IsFixed = costume.IsFixed ?? false, + LevelMinimum = item.LevelMinimum, + CloseDefence = (short)(item.CloseDefence + (costume.CloseDefence ?? 0)), + DistanceDefence = (short)(item.DistanceDefence + (costume.DistanceDefence ?? 0)), + MagicDefence = (short)(item.MagicDefence + (costume.MagicDefence ?? 0)), + DefenceDodge = (short)(item.DefenceDodge + (costume.DefenceDodge ?? 0)), + Price = item.Price, + IsTradable = IsTradable(costume), + RemainingHours = RemainingHours(costume), + }; + } + + private EInfoCostumeHatPacket GenerateCostumeHatInfo(WearableInstance costume) + { + var item = costume.Item; + return new EInfoCostumeHatPacket + { + ItemVNum = costume.ItemVNum, + LevelMinimum = item.LevelMinimum, + CloseDefence = (short)(item.CloseDefence + (costume.CloseDefence ?? 0)), + DistanceDefence = (short)(item.DistanceDefence + (costume.DistanceDefence ?? 0)), + MagicDefence = (short)(item.MagicDefence + (costume.MagicDefence ?? 0)), + DefenceDodge = (short)(item.DefenceDodge + (costume.DefenceDodge ?? 0)), + FireResistance = (short)(item.FireResistance + (costume.FireResistance ?? 0)), + WaterResistance = (short)(item.WaterResistance + (costume.WaterResistance ?? 0)), + LightResistance = (short)(item.LightResistance + (costume.LightResistance ?? 0)), + DarkResistance = (short)(item.DarkResistance + (costume.DarkResistance ?? 0)), + Price = item.Price, + IsTradable = IsTradable(costume), + RemainingHours = RemainingHours(costume), + }; + } + + private static bool IsTradable(IItemInstance item) => item.Item.IsTradable && item.BoundCharacterId == null; + + // A worn time-limited item counts down from its delete time; one never worn still has its whole validity. + private long RemainingSeconds(IItemInstance item) => item.ItemDeleteTime is { } deleteTime + ? Math.Max(0, (long)(deleteTime - clock.GetCurrentInstant()).TotalSeconds) + : item.Item.ItemValidTime; + + private int RemainingHours(IItemInstance item) => + item.ItemDeleteTime == null && item.Item.ItemValidTime <= 0 ? PermanentHours : (int)(RemainingSeconds(item) / 3600); + + private EInfoSpecialistHolderPacket GenerateHolderInfo(BoxInstance holder) + { + if ((holder.HoldingVNum ?? 0) == 0) + { + return new EInfoSpecialistHolderPacket { ItemVNum = holder.ItemVNum }; + } + + var card = GenerateSpecialistInfo(specialistHolderService.TakeOut(holder)); + return new EInfoSpecialistHolderPacket + { + ItemVNum = holder.ItemVNum, + IsFull = true, + HoldingVNum = card.ItemVnum, + SpLevel = card.SpLevel, + Xp = card.Xp, + XpMaximum = card.SpXpData, + Upgrade = card.Upgrade, + SlHit = card.SlHit, + SlDefence = card.SlDefense, + SlElement = card.SlElement, + SlHp = card.SlHp, + FreePoints = card.FreeSpPoints, + SpStoneUpgrade = card.SpStoneUpgrade, + FireResistance = card.FireResistance, + WaterResistance = card.WaterResistance, + LightResistance = card.LightResistance, + DarkResistance = card.DarkResistance, + AttackPoints = card.AttackPoints, + DefencePoints = card.DefensePoints, + ElementPoints = card.ElementPoints, + HpMpPoints = card.HpMpPoints, + FirePoints = card.SpFireResistance, + WaterPoints = card.SpWaterResistance, + LightPoints = card.SpLightResistance, + DarkPoints = card.SpDarkResistance, + }; + } + + private EInfoFairyBeadPacket GenerateFairyBeadInfo(BoxInstance bead) + { + if ((bead.HoldingVNum ?? 0) == 0) + { + return new EInfoFairyBeadPacket { ItemVNum = bead.ItemVNum }; + } + + var fairy = fairyBeadService.TakeOut(bead); + return new EInfoFairyBeadPacket + { + ItemVNum = bead.ItemVNum, + IsFull = true, + HoldingVNum = fairy.ItemVNum, + ElementRate = (short)(fairy.Item.ElementRate + (fairy.ElementRate ?? 0)), + }; + } + + private PslInfoPacket GeneratePartnerSpecialistInfo(SpecialistInstance card) + { + var item = card.Item; + var cardSkills = partnerSpecialistService.CardSkills(card); + ScnPacket.ScSkillDetails? SkillAt(int slot) => slot < cardSkills.Count + ? new ScnPacket.ScSkillDetails { SkillId = cardSkills[slot].SkillVNum, Rank = SpPartnerRank.NotIdentifiedYet } + : null; + return new PslInfoPacket + { + ItemVNum = card.ItemVNum, + Element = (ElementType)item.Element, + ElementRate = item.ElementRate, + LevelMinimum = item.LevelMinimum, + Speed = item.Speed, + FireResistance = item.FireResistance, + WaterResistance = item.WaterResistance, + LightResistance = item.LightResistance, + DarkResistance = item.DarkResistance, + Skill1 = SkillAt(0), + Skill2 = SkillAt(1), + Skill3 = SkillAt(2), + Upgrade = card.Upgrade, + AttackPoints = card.SpDamage, + DefencePoints = card.SpDefence, + CriticalDamageReductionPoints = card.SpElement, + HpMpPoints = card.SpHp, + FirePoints = card.SpFire, + WaterPoints = card.SpWater, + LightPoints = card.SpLight, + DarkPoints = card.SpDark, + }; + } + private EInfoShellPacket GenerateShellInfo(WearableInstance shell) { var options = LoadShellOptions(shell); diff --git a/src/NosCore.GameObject/Services/MateService/IPartnerSpecialistService.cs b/src/NosCore.GameObject/Services/MateService/IPartnerSpecialistService.cs index e3b4eb52f0..50bc342f8d 100644 --- a/src/NosCore.GameObject/Services/MateService/IPartnerSpecialistService.cs +++ b/src/NosCore.GameObject/Services/MateService/IPartnerSpecialistService.cs @@ -9,6 +9,7 @@ using NosCore.Data.StaticEntities; using NosCore.GameObject.Ecs; using NosCore.GameObject.Ecs.Interfaces; +using NosCore.GameObject.Services.ItemGenerationService.Item; namespace NosCore.GameObject.Services.MateService { @@ -27,6 +28,9 @@ public interface IPartnerSpecialistService /// The skills of the card a transformed partner wears, in skill bar order; none when it is not transformed. IReadOnlyList Skills(PlayerComponentBundle owner, Mate partner); + /// The skills a partner card gives, in skill bar order. + IReadOnlyList CardSkills(SpecialistInstance card); + /// Casts the skill in a slot of a transformed partner's skill bar. Task CastAsync(PlayerComponentBundle owner, long mateTransportId, int slot, IAliveEntity target); } diff --git a/src/NosCore.GameObject/Services/MateService/PartnerSpecialistService.cs b/src/NosCore.GameObject/Services/MateService/PartnerSpecialistService.cs index fafa25d20e..414148e26f 100644 --- a/src/NosCore.GameObject/Services/MateService/PartnerSpecialistService.cs +++ b/src/NosCore.GameObject/Services/MateService/PartnerSpecialistService.cs @@ -16,6 +16,7 @@ using NosCore.GameObject.Ecs.Interfaces; using NosCore.GameObject.Infastructure; using NosCore.GameObject.Services.BattleService; +using NosCore.GameObject.Services.ItemGenerationService.Item; using NosCore.GameObject.Services.SkillService; using NosCore.Networking; using NosCore.Packets.ClientPackets.Mates; @@ -44,9 +45,11 @@ public sealed class PartnerSpecialistService(IClock clock, List skills public IReadOnlyList Skills(PlayerComponentBundle owner, Mate partner) => partner.SpecialistMorph != null && partner.Specialist(owner.InventoryService) is { } specialist - ? _skillsBySet[specialist.Item.PartnerSkillSet].ToList() + ? CardSkills(specialist) : []; + public IReadOnlyList CardSkills(SpecialistInstance card) => _skillsBySet[card.Item.PartnerSkillSet].ToList(); + public async Task CastAsync(PlayerComponentBundle owner, long mateTransportId, int slot, IAliveEntity target) { if (!owner.Mates.TryGetValue(mateTransportId, out var partner) diff --git a/src/NosCore.PacketHandlers/Inventory/EquipmentInfoPacketHandler.cs b/src/NosCore.PacketHandlers/Inventory/EquipmentInfoPacketHandler.cs index 951c0ff5ad..ae41109832 100644 --- a/src/NosCore.PacketHandlers/Inventory/EquipmentInfoPacketHandler.cs +++ b/src/NosCore.PacketHandlers/Inventory/EquipmentInfoPacketHandler.cs @@ -4,40 +4,55 @@ // |_|\__|\__/ |___/ \__/\__/|_|_\___| // +using System.Linq; using System.Threading.Tasks; using NosCore.Data.Enumerations; +using NosCore.GameObject.Ecs.Extensions; using NosCore.GameObject.Infastructure; using NosCore.GameObject.Networking.ClientSession; +using NosCore.GameObject.Services.ItemGenerationService; +using NosCore.GameObject.Services.ItemGenerationService.Item; using NosCore.GameObject.Services.ItemInfoService; using NosCore.Packets.ClientPackets.Player; using NosCore.Packets.Enumerations; +using NosCore.Data.Enumerations.Character; namespace NosCore.PacketHandlers.Inventory { - public class EquipmentInfoPacketHandler(IItemInfoService itemInfoService) + public class EquipmentInfoPacketHandler(IItemInfoService itemInfoService, IItemCatalog itemCatalog, + IItemGenerationService itemProvider) : PacketHandler, IWorldPacketHandler { public override async Task ExecuteAsync(EquipmentInfoPacket packet, ClientSession clientSession) { - NoscorePocketType? pocket = packet.Type switch + if (Find(packet, clientSession) is { } item && itemInfoService.GenerateInfo(item) is { } info) { - EquipmentInfoType.Worn => NoscorePocketType.Wear, - EquipmentInfoType.Equipment => NoscorePocketType.Equipment, - EquipmentInfoType.Specialist => NoscorePocketType.Specialist, - _ => null - }; - if (pocket == null) - { - return; + await clientSession.SendPacketAsync(info); } + } - var item = clientSession.Character.InventoryService.LoadBySlotAndType(packet.Slot, pocket.Value); - if (item == null || itemInfoService.GenerateInfo(item.ItemInstance) is not { } info) + private IItemInstance? Find(EquipmentInfoPacket packet, ClientSession clientSession) + { + var character = clientSession.Character; + return packet.Type switch { - return; - } + EquipmentInfoType.Worn => InPocket(NoscorePocketType.Wear, packet.Slot), + EquipmentInfoType.Equipment => InPocket(NoscorePocketType.Equipment, packet.Slot), + EquipmentInfoType.Specialist => InPocket(NoscorePocketType.Specialist, packet.Slot), + EquipmentInfoType.Costume => InPocket(NoscorePocketType.Costume, packet.Slot), + // The slot is the partner's position counted from 1, the second field its equipment slot. + EquipmentInfoType.PartnerEquipment => character.Mates.Values + .FirstOrDefault(m => m.MateType == MateType.Partner && m.PetSlot == packet.Slot - 1)? + .EquipmentPocket() is { } pocket + ? InPocket(pocket, packet.MateSlot) + : null, + // An NPC shop sends the item's VNum as the slot. + EquipmentInfoType.NpcShop => itemCatalog.GetItem(packet.Slot) == null ? null : itemProvider.Create(packet.Slot), + _ => null + }; - await clientSession.SendPacketAsync(info); + IItemInstance? InPocket(NoscorePocketType pocket, short slot) => + character.InventoryService.LoadBySlotAndType(slot, pocket)?.ItemInstance; } } } diff --git a/test/NosCore.GameObject.Tests/Ecs/Extensions/CharacterStatsPacketTests.cs b/test/NosCore.GameObject.Tests/Ecs/Extensions/CharacterStatsPacketTests.cs index 39cc5a03ff..594a28f742 100644 --- a/test/NosCore.GameObject.Tests/Ecs/Extensions/CharacterStatsPacketTests.cs +++ b/test/NosCore.GameObject.Tests/Ecs/Extensions/CharacterStatsPacketTests.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using NosCore.Data.Enumerations.Battle; +using NosCore.Packets.Enumerations; using NosCore.GameObject.Ecs.Extensions; using NosCore.GameObject.Ecs.Interfaces; using NosCore.GameObject.Networking.ClientSession; @@ -98,8 +98,8 @@ public void EachClassShowsItsOwnAttackRows(CharacterClassType characterClass, At var sc = _session.Character.GenerateSc(_stats.Object); - Assert.AreEqual((byte)main, sc.Type); - Assert.AreEqual((byte)secondary, sc.Type2); + Assert.AreEqual(main, sc.Type); + Assert.AreEqual(secondary, sc.Type2); } } } diff --git a/test/NosCore.GameObject.Tests/Services/ItemInfoService/ItemInfoServiceTests.cs b/test/NosCore.GameObject.Tests/Services/ItemInfoService/ItemInfoServiceTests.cs index b687242ece..fafb8223b4 100644 --- a/test/NosCore.GameObject.Tests/Services/ItemInfoService/ItemInfoServiceTests.cs +++ b/test/NosCore.GameObject.Tests/Services/ItemInfoService/ItemInfoServiceTests.cs @@ -17,7 +17,12 @@ using NosCore.Data.Enumerations.Items; using NosCore.GameObject.Services.ItemGenerationService.Item; using NosCore.GameObject.Services.ItemInfoService; +using NosCore.GameObject.Services.FairyBeadService; +using NosCore.GameObject.Services.MateService; using NosCore.GameObject.Services.SpecialistCardService; +using NosCore.GameObject.Services.SpecialistHolderService; +using NodaTime; +using NodaTime.Testing; using NosCore.Algorithm.SpExperienceService; using NosCore.Algorithm.SpecialistPointService; using NosCore.Data.StaticEntities; @@ -32,6 +37,10 @@ public class ItemInfoServiceTests { private readonly List _options = new(); private readonly List _skills = new(); + private readonly Mock _holders = new(); + private readonly Mock _beads = new(); + private readonly Mock _partnerCards = new(); + private readonly FakeClock _clock = new(Instant.FromUtc(2026, 1, 1, 0, 0)); private GameObject.Services.ItemInfoService.ItemInfoService _service; [TestInitialize] @@ -42,7 +51,8 @@ public void Setup() .Returns((Expression> predicate) => _options.Where(predicate.Compile())); var pointService = new SpecialistPointService(); _service = new GameObject.Services.ItemInfoService.ItemInfoService(optionDao.Object, _skills, - new SpExperienceService(), pointService, new SpecialistCardService(pointService)); + new SpExperienceService(), pointService, new SpecialistCardService(pointService), + _holders.Object, _beads.Object, _partnerCards.Object, _clock); } private static WearableInstance Wearable(Item item) => @@ -239,9 +249,137 @@ public void ARingWithoutCellonsListsNone() [TestMethod] public void AnItemWithoutADetailWindowGetsNoAnswer() { - var costume = Wearable(new Item { VNum = 1, ItemType = ItemType.Fashion, EquipmentSlot = EquipmentType.CostumeSuit }); + var potion = new ItemInstance(new Item { VNum = 1012, ItemType = ItemType.Potion }); - Assert.IsNull(_service.GenerateInfo(costume)); + Assert.IsNull(_service.GenerateInfo(potion)); + } + + [TestMethod] + public void AHatIsShownLikeGloves() + { + var hat = Wearable(new Item { VNum = 200, ItemType = ItemType.Fashion, EquipmentSlot = EquipmentType.Hat, LevelMinimum = 1, CloseDefence = 1, Price = 40 }); + + PacketAssert.AreEqual(new EInfoAccessoryPacket { ItemVNum = 200, LevelMinimum = 1, CloseDefence = 1, Price = 40 }, + Info(hat)); + } + + [TestMethod] + public void AnUnwornCostumeShowsItsWholeValidityAndCanBeTraded() + { + var suit = Wearable(new Item + { + VNum = 187, ItemType = ItemType.Fashion, EquipmentSlot = EquipmentType.CostumeSuit, LevelMinimum = 20, + Price = 2400, ItemValidTime = 2592000, IsTradable = true + }); + + PacketAssert.AreEqual(new EInfoCostumePacket + { + ItemVNum = 187, LevelMinimum = 20, Price = 2400, IsTradable = true, RemainingHours = 720, + }, Info(suit)); + } + + [TestMethod] + public void AWornCostumeCountsDownAndIsBound() + { + var hat = Wearable(new Item + { + VNum = 186, ItemType = ItemType.Fashion, EquipmentSlot = EquipmentType.CostumeHat, ItemValidTime = 2592000, IsTradable = true + }); + hat.BoundCharacterId = 1; + hat.ItemDeleteTime = _clock.GetCurrentInstant().Plus(Duration.FromHours(5)).Plus(Duration.FromMinutes(30)); + + var info = Info(hat); + + Assert.AreEqual(5, info.RemainingHours); + Assert.IsFalse(info.IsTradable); + } + + [TestMethod] + public void APermanentSkinShowsNoRemainingTime() + { + var skin = Wearable(new Item { VNum = 4270, ItemType = ItemType.Fashion, EquipmentSlot = EquipmentType.WeaponSkin }); + + Assert.AreEqual(-1, Info(skin).RemainingHours); + } + + [TestMethod] + public void AnAmuletShowsItsRemainingTimeInTenthsOfASecond() + { + var amulet = Wearable(new Item + { + VNum = 180, ItemType = ItemType.Jewelery, EquipmentSlot = EquipmentType.Amulet, LevelMinimum = 10, ItemValidTime = 1800, Price = 3300 + }); + + PacketAssert.AreEqual(new EInfoAmuletPacket { ItemVNum = 180, LevelMinimum = 10, RemainingTime = 18000, Price = 3300 }, + Info(amulet)); + } + + [TestMethod] + public void AnEmptyHolderOnlySaysItIsEmpty() + { + var holder = new BoxInstance(new Item { VNum = 287, ItemType = ItemType.Box }); + _holders.Setup(h => h.IsSpecialistHolder(holder)).Returns(true); + + PacketAssert.AreEqual(new EInfoSpecialistHolderPacket { ItemVNum = 287 }, Info(holder)); + } + + [TestMethod] + public void AFullHolderShowsTheCardItKeeps() + { + var holder = new BoxInstance(new Item { VNum = 287, ItemType = ItemType.Box }) { HoldingVNum = 901 }; + _holders.Setup(h => h.IsSpecialistHolder(holder)).Returns(true); + _holders.Setup(h => h.TakeOut(holder)).Returns(new SpecialistInstance(new Item + { + VNum = 901, ItemType = ItemType.Specialist, EquipmentSlot = EquipmentType.Sp, Morph = 1, FireResistance = 4 + }) + { + SpLevel = 40, Xp = 1000, SlDamage = 30, SpDamage = 10, + }); + + var info = Info(holder); + + Assert.IsTrue(info.IsFull); + Assert.AreEqual((short)901, info.HoldingVNum); + Assert.AreEqual((byte)40, info.SpLevel); + Assert.AreEqual(19, info.SlHit); + Assert.AreEqual((short)4, info.FireResistance); + Assert.AreEqual((short)10, info.AttackPoints); + } + + [TestMethod] + public void AFairyBeadShowsItsFairyWithTheFairysGrowth() + { + var bead = new BoxInstance(new Item { VNum = 4194, ItemType = ItemType.Box }) { HoldingVNum = 254 }; + _beads.Setup(b => b.IsFairyBead(bead)).Returns(true); + var fairy = Wearable(new Item { VNum = 254, ItemType = ItemType.Jewelery, EquipmentSlot = EquipmentType.Fairy, ElementRate = 10 }); + fairy.ElementRate = 20; + _beads.Setup(b => b.TakeOut(bead)).Returns(fairy); + + PacketAssert.AreEqual(new EInfoFairyBeadPacket { ItemVNum = 4194, IsFull = true, HoldingVNum = 254, ElementRate = 30 }, + Info(bead)); + } + + [TestMethod] + public void APartnerCardListsItsSkillsAndPoints() + { + var card = new SpecialistInstance(new Item + { + VNum = 4324, ItemType = ItemType.Specialist, EquipmentSlot = EquipmentType.Sp, ItemSubType = 4, LevelMinimum = 30, Speed = 2 + }) + { + Upgrade = 1, SpDamage = 2, SpHp = 5, + }; + _partnerCards.Setup(p => p.CardSkills(card)).Returns([new SkillDto { SkillVNum = 1235 }, new SkillDto { SkillVNum = 1237 }]); + + var info = Info(card); + + Assert.AreEqual((byte)30, info.LevelMinimum); + Assert.AreEqual(1235, info.Skill1?.SkillId); + Assert.AreEqual(1237, info.Skill2?.SkillId); + Assert.IsNull(info.Skill3); + Assert.AreEqual((byte)1, info.Upgrade); + Assert.AreEqual((short)2, info.AttackPoints); + Assert.AreEqual((short)5, info.HpMpPoints); } [TestMethod] diff --git a/test/NosCore.PacketHandlers.Tests/Inventory/EquipmentInfoPacketHandlerTests.cs b/test/NosCore.PacketHandlers.Tests/Inventory/EquipmentInfoPacketHandlerTests.cs index f240ec2247..7ec02f773c 100644 --- a/test/NosCore.PacketHandlers.Tests/Inventory/EquipmentInfoPacketHandlerTests.cs +++ b/test/NosCore.PacketHandlers.Tests/Inventory/EquipmentInfoPacketHandlerTests.cs @@ -9,8 +9,10 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using NosCore.Data.Enumerations; +using NosCore.Data.StaticEntities; using NosCore.GameObject.Services.InventoryService; using NosCore.GameObject.Services.ItemInfoService; +using NosCore.GameObject.Services.ItemGenerationService; using NosCore.GameObject.Services.ItemGenerationService.Item; using NosCore.PacketHandlers.Inventory; using NosCore.Packets.ClientPackets.Player; @@ -32,8 +34,10 @@ public override async Task SetupAsync() { await base.SetupAsync(); var itemInfoService = new Mock(); - itemInfoService.Setup(s => s.GenerateInfo(It.Is(i => i.ItemVNum == 1))).Returns(_info); - _handler = new EquipmentInfoPacketHandler(itemInfoService.Object); + itemInfoService.Setup(s => s.GenerateInfo(It.Is(i => i.ItemVNum == 1 || i.ItemVNum == 912))).Returns(_info); + var itemCatalog = new Mock(); + itemCatalog.Setup(c => c.GetItem(1)).Returns(new ItemDto { VNum = 1 }); + _handler = new EquipmentInfoPacketHandler(itemInfoService.Object, itemCatalog.Object, ItemProvider); } [TestMethod] @@ -56,6 +60,44 @@ public async Task RightClickingAWornWeaponShowsItsDetails() .ExecuteAsync(); } + [TestMethod] + public async Task RightClickingAnItemInTheCardInventoryShowsItsDetails() + { + await new Spec("Right clicking an item in the card inventory shows its details") + .Given(Item_IsIn_Slot_, (short)912, NoscorePocketType.Specialist, (short)2) + .WhenAsync(AskingForInfoOn_Slot_, EquipmentInfoType.Specialist, (short)2) + .Then(TheDetailsAreSent) + .ExecuteAsync(); + } + + [TestMethod] + public async Task RightClickingAnItemInTheCostumeInventoryShowsItsDetails() + { + await new Spec("Right clicking an item in the costume inventory shows its details") + .Given(Item_IsIn_Slot_, (short)1, NoscorePocketType.Costume, (short)1) + .WhenAsync(AskingForInfoOn_Slot_, EquipmentInfoType.Costume, (short)1) + .Then(TheDetailsAreSent) + .ExecuteAsync(); + } + + [TestMethod] + public async Task AnNpcShopItemIsLookedUpByItsVNum() + { + await new Spec("An NPC shop item is looked up by its VNum") + .WhenAsync(AskingForInfoOn_Slot_, EquipmentInfoType.NpcShop, (short)1) + .Then(TheDetailsAreSent) + .ExecuteAsync(); + } + + [TestMethod] + public async Task AnUnknownNpcShopItemSendsNothing() + { + await new Spec("An unknown NPC shop item sends nothing") + .WhenAsync(AskingForInfoOn_Slot_, EquipmentInfoType.NpcShop, (short)30000) + .Then(NothingIsSent) + .ExecuteAsync(); + } + [TestMethod] public async Task AnEmptySlotSendsNothing() { @@ -80,6 +122,10 @@ private void AWeaponIsInEquipmentSlot_(short slot) => InventoryItemInstance.Create(ItemProvider.Create(1, 1), Session.Character.CharacterId), NoscorePocketType.Equipment, slot); + private void Item_IsIn_Slot_(short vnum, NoscorePocketType pocket, short slot) => + Session.Character.InventoryService.AddItemToPocket( + InventoryItemInstance.Create(ItemProvider.Create(vnum, 1), Session.Character.CharacterId), pocket, slot); + private void AWeaponIsWorn() => Session.Character.InventoryService.AddItemToPocket( InventoryItemInstance.Create(ItemProvider.Create(1, 1), Session.Character.CharacterId),