From c4efc653bada65fb7ac81baadc33004dd4898842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Fri, 31 Dec 2021 23:37:41 +0100 Subject: [PATCH] feat: add in packet with all dependencies --- .../Packets/UpgradeRareSubPacketConverter.cs | 60 ++++++++ Core/NosSmooth.Packets/Enums/Element.cs | 38 +++++ .../Enums/Entities/EntityType.cs | 38 +++++ .../Enums/{ => Entities}/FactionType.cs | 0 .../Enums/Entities/SpawnEffect.cs | 28 ++++ .../Enums/Players/AuthorityType.cs | 47 ++++++ .../Enums/Players/HairColor.cs | 145 ++++++++++++++++++ .../Enums/Players/HairStyle.cs | 38 +++++ .../Enums/Players/PlayerClass.cs | 57 +++++++ .../Enums/Players/SexType.cs | 23 +++ .../Server/Entities/InEquipmentSubPacket.cs | 49 ++++++ .../Server/Entities/InItemSubPacket.cs | 28 ++++ .../Server/Entities/InNonPlayerSubPacket.cs | 88 +++++++++++ .../Packets/Server/Entities/InPacket.cs | 53 +++++++ .../Server/Entities/InPlayerSubPacket.cs | 84 ++++++++++ .../Packets/Server/Entities/MovePacket.cs | 4 +- .../Packets/Server/Groups/PinitPacket.cs | 4 +- .../Packets/Server/Groups/PinitSubPacket.cs | 10 +- .../Packets/Server/Players/FamilySubPacket.cs | 26 ++++ .../Server/Weapons/UpgradeRareSubPacket.cs | 21 +++ .../Packets/MovePacketConverterTests.cs | 6 +- .../Packets/PinitPacketConverterTest.cs | 11 +- 22 files changed, 840 insertions(+), 18 deletions(-) create mode 100644 Core/NosSmooth.Packets/Converters/Packets/UpgradeRareSubPacketConverter.cs create mode 100644 Core/NosSmooth.Packets/Enums/Element.cs create mode 100644 Core/NosSmooth.Packets/Enums/Entities/EntityType.cs rename Core/NosSmooth.Packets/Enums/{ => Entities}/FactionType.cs (100%) create mode 100644 Core/NosSmooth.Packets/Enums/Entities/SpawnEffect.cs create mode 100644 Core/NosSmooth.Packets/Enums/Players/AuthorityType.cs create mode 100644 Core/NosSmooth.Packets/Enums/Players/HairColor.cs create mode 100644 Core/NosSmooth.Packets/Enums/Players/HairStyle.cs create mode 100644 Core/NosSmooth.Packets/Enums/Players/PlayerClass.cs create mode 100644 Core/NosSmooth.Packets/Enums/Players/SexType.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Entities/InEquipmentSubPacket.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Entities/InItemSubPacket.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Entities/InNonPlayerSubPacket.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Entities/InPacket.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Entities/InPlayerSubPacket.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Players/FamilySubPacket.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Weapons/UpgradeRareSubPacket.cs diff --git a/Core/NosSmooth.Packets/Converters/Packets/UpgradeRareSubPacketConverter.cs b/Core/NosSmooth.Packets/Converters/Packets/UpgradeRareSubPacketConverter.cs new file mode 100644 index 0000000000000000000000000000000000000000..df6e9b960b65591af6b4f4ff68371289c12cb385 --- /dev/null +++ b/Core/NosSmooth.Packets/Converters/Packets/UpgradeRareSubPacketConverter.cs @@ -0,0 +1,60 @@ +// +// UpgradeRareSubPacketConverter.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Packets.Errors; +using NosSmooth.Packets.Packets.Server.Weapons; +using Remora.Results; + +namespace NosSmooth.Packets.Converters.Packets; + +/// +/// Converter for . +/// +public class UpgradeRareSubPacketConverter : BaseTypeConverter +{ + /// + public override Result Serialize(UpgradeRareSubPacket? obj, PacketStringBuilder builder) + { + if (obj is null) + { + builder.Append("-"); + return Result.FromSuccess(); + } + builder.Append($"{obj.Upgrade}{obj.Rare}"); + return Result.FromSuccess(); + } + + /// + public override Result Deserialize(PacketStringEnumerator stringEnumerator) + { + var tokenResult = stringEnumerator.GetNextToken(); + if (!tokenResult.IsSuccess) + { + return Result.FromError(tokenResult); + } + + var token = tokenResult.Entity.Token; + if (token.Length != 2) + { + return new CouldNotConvertError(this, token, "The string is not two characters long."); + } + + var upgradeString = token[0].ToString(); + var rareString = token[1].ToString(); + + if (!byte.TryParse(upgradeString, out var upgrade)) + { + return new CouldNotConvertError(this, upgradeString, "Could not parse as byte"); + } + + if (!sbyte.TryParse(rareString, out var rare)) + { + return new CouldNotConvertError(this, rareString, "Could not parse as byte"); + } + + return new UpgradeRareSubPacket(upgrade, rare); + } +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/Element.cs b/Core/NosSmooth.Packets/Enums/Element.cs new file mode 100644 index 0000000000000000000000000000000000000000..72ecc6b1ae60dab63279318d0ff147a4a34bcb11 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Element.cs @@ -0,0 +1,38 @@ +// +// Element.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Packets.Enums; + +/// +/// Element type. +/// +public enum Element +{ + /// + /// No element type. + /// + Neutral, + + /// + /// Fire element. + /// + Fire, + + /// + /// Water element. + /// + Water, + + /// + /// Light element. + /// + Light, + + /// + /// Dark element. + /// + Dark +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/Entities/EntityType.cs b/Core/NosSmooth.Packets/Enums/Entities/EntityType.cs new file mode 100644 index 0000000000000000000000000000000000000000..ea5471bf32a1aa74f3d7ddcb282f3625baa64ec5 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Entities/EntityType.cs @@ -0,0 +1,38 @@ +// +// EntityType.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Packets.Enums; + +/// +/// Type of the entity. +/// +public enum EntityType +{ + /// + /// Unknown. + /// + Map = 0, + + /// + /// The entity is a player. + /// + Player = 1, + + /// + /// The entity is an npc. (can be pets and partners as well). + /// + Npc = 2, + + /// + /// The entity is a monster. + /// + Monster = 3, + + /// + /// The entity is an object, ie. gold or dropped item. + /// + Object = 9 +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/FactionType.cs b/Core/NosSmooth.Packets/Enums/Entities/FactionType.cs similarity index 100% rename from Core/NosSmooth.Packets/Enums/FactionType.cs rename to Core/NosSmooth.Packets/Enums/Entities/FactionType.cs diff --git a/Core/NosSmooth.Packets/Enums/Entities/SpawnEffect.cs b/Core/NosSmooth.Packets/Enums/Entities/SpawnEffect.cs new file mode 100644 index 0000000000000000000000000000000000000000..f4ae39ed100cbfd3c998a1dd5d59caefdf677966 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Entities/SpawnEffect.cs @@ -0,0 +1,28 @@ +// +// SpawnEffect.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Packets.Enums.Entities; + +/// +/// Effect that is shown on the entity spawning. +/// +public enum SpawnEffect +{ + /// + /// Unknown. + /// + Summon = 0, + + /// + /// Unknown. + /// + NoEffect = 1, + + /// + /// Unknown. + /// + FallingFromSky = 2 +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/Players/AuthorityType.cs b/Core/NosSmooth.Packets/Enums/Players/AuthorityType.cs new file mode 100644 index 0000000000000000000000000000000000000000..89099095d211a59ac82878bbd5bbe9ff9fddd7f8 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Players/AuthorityType.cs @@ -0,0 +1,47 @@ +// +// AuthorityType.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Packets.Enums; + +/// +/// Authority of a player. +/// +public enum AuthorityType +{ + /// + /// The player is a regular user. + /// + User = 0, + + /// + /// The player is a moderator. + /// + Moderator = 1, + + /// + /// The player is a game master. + /// + /// + /// Has GM in front of the name. + /// + GameMaster = 2, + + /// + /// The player is an administrator. + /// + /// + /// Has GM in front of the name. + /// + Administrator = 3, + + /// + /// The player is a root. + /// + /// + /// Has GM in front of the name. + /// + Root = 4 +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/Players/HairColor.cs b/Core/NosSmooth.Packets/Enums/Players/HairColor.cs new file mode 100644 index 0000000000000000000000000000000000000000..571fd38326b89f4b460193c428fe7a3d50692475 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Players/HairColor.cs @@ -0,0 +1,145 @@ +// +// HairColor.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#pragma warning disable CS1591 +namespace NosSmooth.Packets.Enums.Players; +#pragma warning disable SA1602 + +/// +/// Hair color of a player. +/// +public enum HairColor +{ + DarkPurple = 0, + Yellow = 1, + Blue = 2, + Purple = 3, + Orange = 4, + Brown = 5, + Green = 6, + DarkGrey = 7, + LightBlue = 8, + PinkRed = 9, + LightYellow = 10, + LightPink = 11, + LightGreen = 12, + LightGrey = 13, + SkyBlue = 14, + Black = 15, + DarkOrange = 16, + DarkOrangeVariant2 = 17, + DarkOrangeVariant3 = 18, + DarkOrangeVariant4 = 19, + DarkOrangeVariant5 = 20, + DarkOrangeVariant6 = 21, + LightOrange = 22, + LightLightOrange = 23, + LightLightLightOrange = 24, + LightLightLightLightOrange = 25, + SuperLightOrange = 26, + DarkYellow = 27, + LightLightYellow = 28, + KakiYellow = 29, + SuperLightYellow = 30, + SuperLightYellow2 = 31, + SuperLightYellow3 = 32, + LittleDarkYellow = 33, + YellowVariant = 34, + YellowVariant1 = 35, + YellowVariant2 = 36, + YellowVariant3 = 37, + YellowVariant4 = 38, + YellowVariant5 = 39, + YellowVariant6 = 40, + YellowVariant7 = 41, + YellowVariant8 = 42, + YellowVariant9 = 43, + GreenVariant = 44, + GreenVariant1 = 45, + DarkGreenVariant = 46, + GreenMoreDarkVariant = 47, + GreenVariant2 = 48, + GreenVariant3 = 49, + GreenVariant4 = 50, + GreenVariant5 = 51, + GreenVariant6 = 52, + GreenVariant7 = 53, + GreenVariant8 = 54, + GreenVariant9 = 55, + GreenVariant10 = 56, + GreenVariant11 = 57, + GreenVariant12 = 58, + GreenVariant13 = 59, + GreenVariant14 = 60, + GreenVariant15 = 61, + GreenVariant16 = 62, + GreenVariant17 = 63, + GreenVariant18 = 64, + GreenVariant19 = 65, + GreenVariant20 = 66, + LightBlueVariant1 = 67, + LightBlueVariant2 = 68, + LightBlueVariant3 = 69, + LightBlueVariant4 = 70, + LightBlueVariant5 = 71, + LightBlueVariant6 = 72, + LightBlueVariant7 = 73, + LightBlueVariant8 = 74, + LightBlueVariant9 = 75, + LightBlueVariant10 = 76, + LightBlueVariant11 = 77, + LightBlueVariant12 = 78, + LightBlueVariant13 = 79, + DarkBlack = 80, + LightBlueVariant14 = 81, + LightBlueVariant15 = 82, + LightBlueVariant16 = 83, + LightBlueVariant17 = 84, + BlueVariant = 85, + BlueVariantDark = 86, + BlueVariantDarkDark = 87, + BlueVariantDarkDark2 = 88, + FlashBlue = 89, + FlashBlueDark = 90, + FlashBlueDark2 = 91, + FlashBlueDark3 = 92, + FlashBlueDark4 = 93, + FlashBlueDark5 = 94, + FlashBlueDark6 = 95, + FlashBlueDark7 = 96, + FlashBlueDark8 = 97, + FlashBlueDark9 = 98, + White = 99, + FlashBlueDark10 = 100, + FlashBlue1 = 101, + FlashBlue2 = 102, + FlashBlue3 = 103, + FlashBlue4 = 104, + FlashBlue5 = 105, + FlashPurple = 106, + FlashLightPurple = 107, + FlashLightPurple2 = 108, + FlashLightPurple3 = 109, + FlashLightPurple4 = 110, + FlashLightPurple5 = 111, + LightPurple = 112, + PurpleVariant1 = 113, + PurpleVariant2 = 114, + PurpleVariant3 = 115, + PurpleVariant4 = 116, + PurpleVariant5 = 117, + PurpleVariant6 = 118, + PurpleVariant7 = 119, + PurpleVariant8 = 120, + PurpleVariant9 = 121, + PurpleVariant10 = 122, + PurpleVariant11 = 123, + PurpleVariant12 = 124, + PurpleVariant13 = 125, + PurpleVariant14 = 126, + PurpleVariant15 = 127 +} +#pragma warning restore SA1602 \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/Players/HairStyle.cs b/Core/NosSmooth.Packets/Enums/Players/HairStyle.cs new file mode 100644 index 0000000000000000000000000000000000000000..f8b37f88c4b7239d36bd8e727f05e24409ab71f0 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Players/HairStyle.cs @@ -0,0 +1,38 @@ +// +// HairStyle.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Packets.Enums.Players; + +/// +/// Hair style of a player. +/// +public enum HairStyle +{ + /// + /// Unknown TODO. + /// + HairStyleA = 0, + + /// + /// Unknown TODO. + /// + HairStyleB = 1, + + /// + /// Unknown TODO. + /// + HairStyleC = 2, + + /// + /// Unknown TODO. + /// + HairStyleD = 3, + + /// + /// The player has no hair. + /// + NoHair = 4 +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/Players/PlayerClass.cs b/Core/NosSmooth.Packets/Enums/Players/PlayerClass.cs new file mode 100644 index 0000000000000000000000000000000000000000..1ee17dd9a6ad162d84e7111cbba18f15f3bd0903 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Players/PlayerClass.cs @@ -0,0 +1,57 @@ +// +// PlayerClass.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Packets.Enums.Players; + +/// +/// The class of the player. +/// +public enum PlayerClass +{ + /// + /// Adventurer class. + /// + /// + /// After creating a character, this is the first class. + /// The player can change the class at level 15, job level 20. + /// + Adventurer = 0, + + /// + /// Swordsman class. + /// + /// + /// Primary weapon is a sword, secondary weapon is a crossbow. + /// + Swordsman = 1, + + /// + /// Archer class. + /// + /// + /// Primary weapon is a bow, + /// secondary weapon is a dagger. + /// + Archer = 2, + + /// + /// Mage class. + /// + /// + /// Primary weapon is a wand, + /// secondary weapon is magical gun. + /// + Mage = 3, + + /// + /// Martial artist class. + /// + /// + /// Can be created after reaching level 80 on any of the characters. + /// Then character with that class can be created on the same account. + /// + MartialArtist = 4 +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/Players/SexType.cs b/Core/NosSmooth.Packets/Enums/Players/SexType.cs new file mode 100644 index 0000000000000000000000000000000000000000..91fce8ebecfea88acd0ca3155898e948fdaf6b77 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Players/SexType.cs @@ -0,0 +1,23 @@ +// +// SexType.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Packets.Enums.Players; + +/// +/// The sex of a player. +/// +public enum SexType +{ + /// + /// The character is male.. + /// + Male = 0, + + /// + /// The character is female. + /// + Female = 1 +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Entities/InEquipmentSubPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Entities/InEquipmentSubPacket.cs new file mode 100644 index 0000000000000000000000000000000000000000..dc70e2f0b361858734aacf2a63360970d5c0768b --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Entities/InEquipmentSubPacket.cs @@ -0,0 +1,49 @@ +// +// InEquipmentSubPacket.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Packets.Attributes; + +namespace NosSmooth.Packets.Packets.Server.Entities; + +/// +/// Sub packet of present if the in packet +/// is for a player. Contains information about the player's +/// weapon. +/// /// +/// The VNum of the hat. +/// The VNum of the armor. +/// The VNum of the main weapon. +/// The VNum of the secondary weapon. +/// The VNum of the mask. +/// Unknown TODO. +/// The VNum of the costume suit. +/// The VNum of the costume hat. +/// The skin of the weapon. +/// The skin of the wings. +[GenerateSerializer] +public record InEquipmentSubPacket +( + [PacketIndex(0)] + long HatVNum, + [PacketIndex(1)] + long ArmorVNum, + [PacketIndex(2)] + long MainWeaponVNum, + [PacketIndex(3)] + long SecondaryWeaponVNum, + [PacketIndex(4)] + long MaskVNum, + [PacketIndex(5)] + long Fairy, + [PacketIndex(6)] + long CostumeSuitVNum, + [PacketIndex(7)] + long CostumeHatVNum, + [PacketIndex(8)] + short WeaponSkin, + [PacketIndex(9)] + short WingSkin +) : IPacket; \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Entities/InItemSubPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Entities/InItemSubPacket.cs new file mode 100644 index 0000000000000000000000000000000000000000..8a33fdbd5a7d9d2967e57d86bc9219eacafc9a61 --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Entities/InItemSubPacket.cs @@ -0,0 +1,28 @@ +// +// InItemSubPacket.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Packets.Attributes; + +namespace NosSmooth.Packets.Packets.Server.Entities; + +/// +/// Sub packet of present if the in packet +/// is for an object. +/// +/// The amount of the gold or drop etc. +/// Whether the item is needed for a quest. +/// The id of the owner of the item. +[PacketHeader(null, PacketSource.Server)] +[GenerateSerializer] +public record InItemSubPacket +( + [PacketIndex(0)] + long Amount, + [PacketIndex(1)] + bool IsQuestRelative, + [PacketIndex(2)] + long OwnerId +) : IPacket; \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Entities/InNonPlayerSubPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Entities/InNonPlayerSubPacket.cs new file mode 100644 index 0000000000000000000000000000000000000000..0a019ac3d8672a4e7d38737ffd48964d9e560053 --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Entities/InNonPlayerSubPacket.cs @@ -0,0 +1,88 @@ +// +// InNonPlayerSubPacket.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Packets.Attributes; +using NosSmooth.Packets.Common; +using NosSmooth.Packets.Enums; +using NosSmooth.Packets.Enums.Entities; + +namespace NosSmooth.Packets.Packets.Server.Entities; + +/// +/// Sub packet of present if the in packet +/// is for a monster or npc. +/// +/// The hp percentage of the entity. +/// The mp percentage of the entity. +/// Unknown TODO +/// The faction of the entity. +/// Unknown TODO +/// The id of the owner entity. +/// The effect the entity does on spawning. +/// Whether the entity is sitting. +/// The id of the morph (for special cards an such). +/// The name of the entity, if any. +/// Unknown. +/// Unknown. +/// Unknown. +/// The first skill VNum of the entity. +/// The second skill VNum of the entity. +/// The third skill VNum of the entity. +/// The rank of the first skill. +/// The rank of the second skill. +/// The rank of the third skill. +/// Whether the entity is invisible. +/// Unknown. +/// Unknown. +[PacketHeader(null, PacketSource.Server)] +[GenerateSerializer] +public record InNonPlayerSubPacket +( + [PacketIndex(0)] + byte HpPercentage, + [PacketIndex(1)] + byte MpPercentage, + [PacketIndex(2)] + short Dialog, + [PacketIndex(3)] + FactionType Faction, + [PacketIndex(4)] + short GroupEffect, + [PacketIndex(5)] + long OwnerId, + [PacketIndex(6)] + SpawnEffect SpawnEffect, + [PacketIndex(7)] + bool IsSitting, + [PacketIndex(8)] + long Morph, + [PacketIndex(9)] + NameString? Name, + [PacketIndex(10)] + string? Unknown, + [PacketIndex(11)] + string? Unknown2, + [PacketIndex(12)] + string? Unknown3, + [PacketIndex(13)] + short Skill1, + [PacketIndex(14)] + short Skill2, + [PacketIndex(15)] + short Skill3, + [PacketIndex(16)] + short SkillRank1, + [PacketIndex(17)] + short SkillRank2, + [PacketIndex(18)] + short SkillRank3, + [PacketIndex(19)] + bool IsInvisible, + [PacketIndex(20)] + string? Unknown4, + [PacketIndex(21)] + string? Unknown5 +) : IPacket; \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Entities/InPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Entities/InPacket.cs new file mode 100644 index 0000000000000000000000000000000000000000..276717c3fdaf831eeea7f87dfd43123ff2af2410 --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Entities/InPacket.cs @@ -0,0 +1,53 @@ +// +// InPacket.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Packets.Attributes; +using NosSmooth.Packets.Common; +using NosSmooth.Packets.Enums; + +namespace NosSmooth.Packets.Packets.Server.Entities; + +/// +/// There is a new entity on the map present. +/// +/// The type of the entity. +/// The name of the entity, present only for players. +/// The vnum of the entity, present only for non players. +/// Unknown value present only for players. It's always "-". +/// The id of the entity. +/// The x coordinate the entity is at. +/// The y coordinate the entity is at. +/// The direction the entity is looking, present only for non-objects. +/// The player data sub packet present only for players. +/// The item data sub packet present only for objects. +/// The non player data sub packet present only for npcs and monsters. +[PacketHeader("in", PacketSource.Server)] +[GenerateSerializer] +public record InPacket +( + [PacketIndex(0)] + EntityType EntityType, + [PacketConditionalIndex(1, "EntityType", false, EntityType.Player)] + NameString? Name, + [PacketConditionalIndex(2, "EntityType", true, EntityType.Player)] + long? VNum, + [PacketConditionalIndex(3, "EntityType", false, EntityType.Player)] + string? Unknown, + [PacketIndex(4)] + long EntityId, + [PacketIndex(5)] + short PositionX, + [PacketIndex(6)] + short PositionY, + [PacketConditionalIndex(7, "EntityType", true, EntityType.Object)] + byte Direction, + [PacketConditionalIndex(8, "EntityType", false, EntityType.Player, InnerSeparator = ' ')] + InPlayerSubPacket? PlayerSubPacket, + [PacketConditionalIndex(9, "EntityType", false, EntityType.Object, InnerSeparator = ' ')] + InItemSubPacket? ItemSubPacket, + [PacketConditionalIndex(10, "EntityType", true, EntityType.Player, EntityType.Object, InnerSeparator = ' ')] + InNonPlayerSubPacket? NonPlayerSubPacket +) : IPacket; \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Entities/InPlayerSubPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Entities/InPlayerSubPacket.cs new file mode 100644 index 0000000000000000000000000000000000000000..20120ba55924ba1100967e90e2afe9c0c20d2e27 --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Entities/InPlayerSubPacket.cs @@ -0,0 +1,84 @@ +// +// InPlayerSubPacket.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Generic; +using NosSmooth.Packets.Attributes; +using NosSmooth.Packets.Enums; +using NosSmooth.Packets.Enums.Players; +using NosSmooth.Packets.Packets.Server.Players; +using NosSmooth.Packets.Packets.Server.Weapons; + +namespace NosSmooth.Packets.Packets.Server.Entities; + +[PacketHeader(null, PacketSource.Server)] +[GenerateSerializer] +public record InPlayerSubPacket +( + [PacketIndex(0)] + AuthorityType Authority, + [PacketIndex(1)] + SexType Sex, + [PacketIndex(2)] + HairStyle HairStyle, + [PacketIndex(3)] + HairColor HairColor, + [PacketIndex(4)] + PlayerClass Class, + [PacketIndex(5, InnerSeparator = '.')] + InEquipmentSubPacket Equipment, + [PacketIndex(6)] + short HpPercentage, + [PacketIndex(7)] + short MpPercentage, + [PacketIndex(8)] + bool IsSitting, + [PacketIndex(9)] + long? GroupId, + [PacketIndex(10)] + short Fairy, + [PacketIndex(11)] + Element FairyElement, + [PacketIndex(12)] + byte Unknown, + [PacketIndex(13)] + long Morph, + [PacketIndex(14)] + byte Unknown2, + [PacketIndex(15)] + byte Unknown3, + [PacketIndex(16)] + UpgradeRareSubPacket WeaponUpgradeRareSubPacket, + [PacketIndex(17)] + UpgradeRareSubPacket ArmorUpgradeRareSubPacket, + [PacketIndex(18)] + FamilySubPacket FamilySubPacket, + [PacketIndex(19)] + string ReputationIcon, + [PacketIndex(20)] + bool IsInvisible, + [PacketIndex(21)] + byte MorphUpgrade, + [PacketIndex(22)] + FactionType Faction, + [PacketIndex(23)] + byte MorphUpgrade2, + [PacketIndex(24)] + byte Level, + [PacketIndex(25)] + byte FamilyLevel, + [PacketListIndex(26, ListSeparator = '|')] + IReadOnlyList FamilyIcons, + [PacketIndex(27)] + bool ArenaWinner, + [PacketIndex(28)] + short Compliment, + [PacketIndex(29)] + byte Size, + [PacketIndex(30)] + byte HeroLevel, + [PacketIndex(31)] + short Title +) : IPacket; \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Entities/MovePacket.cs b/Core/NosSmooth.Packets/Packets/Server/Entities/MovePacket.cs index 2c4fa955fb3794d4ba3c844ee18a943599d25e51..5802c80190375093fc1fb876667e52ac97a2c09d 100644 --- a/Core/NosSmooth.Packets/Packets/Server/Entities/MovePacket.cs +++ b/Core/NosSmooth.Packets/Packets/Server/Entities/MovePacket.cs @@ -4,8 +4,8 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using NosCore.Shared.Enumerations; using NosSmooth.Packets.Attributes; +using NosSmooth.Packets.Enums; namespace NosSmooth.Packets.Packets.Server.Entities; @@ -22,7 +22,7 @@ namespace NosSmooth.Packets.Packets.Server.Entities; public record MovePacket ( [PacketIndex(0)] - VisualType EntityType, + EntityType EntityType, [PacketIndex(1)] long EntityId, [PacketIndex(2)] diff --git a/Core/NosSmooth.Packets/Packets/Server/Groups/PinitPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Groups/PinitPacket.cs index e318b8b56ce3b7b1e606b60ef3a8f85baabfdd76..fbe832517aa3402f00a942b7b95f91726bc02518 100644 --- a/Core/NosSmooth.Packets/Packets/Server/Groups/PinitPacket.cs +++ b/Core/NosSmooth.Packets/Packets/Server/Groups/PinitPacket.cs @@ -15,8 +15,8 @@ namespace NosSmooth.Packets.Packets.Server.Groups; /// /// Contains pet and group information. /// -/// -/// +/// The size of the group. +/// The members of the group. (including pet and partner, if any) [GenerateSerializer] [PacketHeader("pinit", PacketSource.Server)] public record PinitPacket diff --git a/Core/NosSmooth.Packets/Packets/Server/Groups/PinitSubPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Groups/PinitSubPacket.cs index e611d9eac526e61c06e6bcd4413b309494b96d96..3a07a03cd95cb74d8a400457440dfd51454596d1 100644 --- a/Core/NosSmooth.Packets/Packets/Server/Groups/PinitSubPacket.cs +++ b/Core/NosSmooth.Packets/Packets/Server/Groups/PinitSubPacket.cs @@ -4,9 +4,9 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using NosCore.Shared.Enumerations; using NosSmooth.Packets.Attributes; using NosSmooth.Packets.Common; +using NosSmooth.Packets.Enums; namespace NosSmooth.Packets.Packets.Server.Groups; @@ -29,7 +29,7 @@ namespace NosSmooth.Packets.Packets.Server.Groups; public record PinitSubPacket ( [PacketIndex(0)] - VisualType EntityType, + EntityType EntityType, [PacketIndex(1)] long EntityId, [PacketIndex(2)] @@ -46,10 +46,10 @@ public record PinitSubPacket short Race, [PacketIndex(8)] short Morph, - [PacketConditionalIndex(9, "EntityType", false, VisualType.Player)] + [PacketConditionalIndex(9, "EntityType", false, EntityType.Player)] byte? HeroLevel, - [PacketConditionalIndex(10, "EntityType", false, VisualType.Player)] + [PacketConditionalIndex(10, "EntityType", false, EntityType.Player)] int? Unknown1, - [PacketConditionalIndex(11, "EntityType", false, VisualType.Player)] + [PacketConditionalIndex(11, "EntityType", false, EntityType.Player)] int? Unknown2 ) : IPacket; \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Players/FamilySubPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Players/FamilySubPacket.cs new file mode 100644 index 0000000000000000000000000000000000000000..2a61c94d41acde4096759eff6f7b06f4d6bb0519 --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Players/FamilySubPacket.cs @@ -0,0 +1,26 @@ +// +// FamilySubPacket.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Packets.Attributes; + +namespace NosSmooth.Packets.Packets.Server.Players; + +/// +/// Sub packet with family information. +/// +/// The id of the family. +/// The title of the family. +/// The name of the family. +[GenerateSerializer] +public record FamilySubPacket +( + [PacketIndex(0, AfterSeparator = '.')] + string FamilyId, + [PacketIndex(1)] + short Title, + [PacketIndex(2)] + string FamilyName +) : IPacket; \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Weapons/UpgradeRareSubPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Weapons/UpgradeRareSubPacket.cs new file mode 100644 index 0000000000000000000000000000000000000000..0812af55532d0b503a857c3478af86ea137f6484 --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Weapons/UpgradeRareSubPacket.cs @@ -0,0 +1,21 @@ +// +// UpgradeRareSubPacket.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Packets.Attributes; + +namespace NosSmooth.Packets.Packets.Server.Weapons; + +/// +/// Upgrade and rare of a weapon or an armor. +/// +/// The upgrade of the weapon. +/// The rare . +[PacketHeader(null, PacketSource.Server)] +public record UpgradeRareSubPacket +( + byte Upgrade, + sbyte Rare +) : IPacket; \ No newline at end of file diff --git a/Tests/NosSmooth.Packets.Tests/Converters/Packets/MovePacketConverterTests.cs b/Tests/NosSmooth.Packets.Tests/Converters/Packets/MovePacketConverterTests.cs index 7a0a32de8fc7c5592beff1612dd7659e00a8a1cb..ebdec11a19796aa924ab7c0641a6e9ec3c529bf2 100644 --- a/Tests/NosSmooth.Packets.Tests/Converters/Packets/MovePacketConverterTests.cs +++ b/Tests/NosSmooth.Packets.Tests/Converters/Packets/MovePacketConverterTests.cs @@ -5,9 +5,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.Extensions.DependencyInjection; -using NosCore.Shared.Enumerations; using NosSmooth.Packets.Attributes; using NosSmooth.Packets.Converters; +using NosSmooth.Packets.Enums; using NosSmooth.Packets.Extensions; using NosSmooth.Packets.Packets.Server.Entities; using Xunit; @@ -40,7 +40,7 @@ public class MovePacketConverterTests [Fact] public void Converter_Serialization_SerializesCorrectly() { - MovePacket packet = new MovePacket(VisualType.Monster, 122, 15, 20, 10); + MovePacket packet = new MovePacket(EntityType.Monster, 122, 15, 20, 10); var result = _packetSerializer.Serialize(packet); Assert.True(result.IsSuccess); @@ -57,7 +57,7 @@ public class MovePacketConverterTests var result = _packetSerializer.Deserialize(packetString, PacketSource.Server); Assert.True(result.IsSuccess); - MovePacket actualPacket = new MovePacket(VisualType.Monster, 122, 15, 20, 10); + MovePacket actualPacket = new MovePacket(EntityType.Monster, 122, 15, 20, 10); Assert.Equal(result.Entity, actualPacket); } } \ No newline at end of file diff --git a/Tests/NosSmooth.Packets.Tests/Converters/Packets/PinitPacketConverterTest.cs b/Tests/NosSmooth.Packets.Tests/Converters/Packets/PinitPacketConverterTest.cs index ee62ae6efe5a1ce55404b5cae0cf66e9dbd28d0d..fef16b2ef67fb7fcc7966ad2cb43f39a4b85c5c5 100644 --- a/Tests/NosSmooth.Packets.Tests/Converters/Packets/PinitPacketConverterTest.cs +++ b/Tests/NosSmooth.Packets.Tests/Converters/Packets/PinitPacketConverterTest.cs @@ -4,11 +4,10 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; -using NosCore.Shared.Enumerations; using NosSmooth.Packets.Attributes; using NosSmooth.Packets.Converters; +using NosSmooth.Packets.Enums; using NosSmooth.Packets.Extensions; using NosSmooth.Packets.Packets.Server.Groups; using Xunit; @@ -43,8 +42,8 @@ public class PinitPacketConverterTest { var packet = new PinitPacket(2, new[] { - new PinitSubPacket(VisualType.Npc, 345377, 0, 83, "Kliff", -1, 319, 1, 0, null, null, null), - new PinitSubPacket(VisualType.Npc, 345384, 1, 83, "@", -1, 2105, 0, 0, null, null, null) + new PinitSubPacket(EntityType.Npc, 345377, 0, 83, "Kliff", -1, 319, 1, 0, null, null, null), + new PinitSubPacket(EntityType.Npc, 345384, 1, 83, "@", -1, 2105, 0, 0, null, null, null) }); var result = _packetSerializer.Serialize(packet); Assert.True(result.IsSuccess); @@ -66,7 +65,7 @@ public class PinitPacketConverterTest Assert.Equal(2, actualPacket.GroupSize); Assert.Equal(2, actualPacket.PinitSubPackets.Count); - Assert.StrictEqual(new PinitSubPacket(VisualType.Npc, 345377, 0, 83, "Kliff", -1, 319, 1, 0, null, null, null), actualPacket.PinitSubPackets[0]); - Assert.StrictEqual(new PinitSubPacket(VisualType.Npc, 345384, 1, 83, "@", -1, 2105, 0, 0, null, null, null), actualPacket.PinitSubPackets[1]); + Assert.StrictEqual(new PinitSubPacket(EntityType.Npc, 345377, 0, 83, "Kliff", -1, 319, 1, 0, null, null, null), actualPacket.PinitSubPackets[0]); + Assert.StrictEqual(new PinitSubPacket(EntityType.Npc, 345384, 1, 83, "@", -1, 2105, 0, 0, null, null, null), actualPacket.PinitSubPackets[1]); } } \ No newline at end of file