From 662febf4df7cba2b425582af4ebf7fe897343817 Mon Sep 17 00:00:00 2001 From: NotKappa Date: Fri, 10 Feb 2023 23:51:08 +0300 Subject: [PATCH] Add skills to Monster and Npc class --- Core/NosSmooth.Game/Data/Entities/Monster.cs | 6 ++++ Core/NosSmooth.Game/Data/Entities/Npc.cs | 6 ++++ .../PacketHandlers/Map/InResponder.cs | 33 +++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Core/NosSmooth.Game/Data/Entities/Monster.cs b/Core/NosSmooth.Game/Data/Entities/Monster.cs index e86c981f4c52f532cb5f54e521fe6cc59920d88f..393979a0c6a221d7b76ce9d867eeb2521284f09a 100644 --- a/Core/NosSmooth.Game/Data/Entities/Monster.cs +++ b/Core/NosSmooth.Game/Data/Entities/Monster.cs @@ -5,6 +5,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Data.Abstractions.Infos; +using NosSmooth.Game.Data.Characters; using NosSmooth.Game.Data.Info; using NosSmooth.Packets.Enums.Entities; @@ -72,4 +73,9 @@ public class Monster : ILivingEntity /// public IReadOnlyList? EffectsVNums { get; set; } + + /// + /// Gets or sets the skills. + /// + public IReadOnlyList? Skills { get; set; } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Entities/Npc.cs b/Core/NosSmooth.Game/Data/Entities/Npc.cs index e7feddf9773dde233162514a6c4c689f737fdab6..553789ba5378ffbea49463319360e38379c784a3 100644 --- a/Core/NosSmooth.Game/Data/Entities/Npc.cs +++ b/Core/NosSmooth.Game/Data/Entities/Npc.cs @@ -5,6 +5,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Data.Abstractions.Infos; +using NosSmooth.Game.Data.Characters; using NosSmooth.Game.Data.Info; using NosSmooth.Packets.Enums.Entities; @@ -82,4 +83,9 @@ public class Npc : ILivingEntity /// public IReadOnlyList? EffectsVNums { get; set; } + + /// + /// Gets or sets the skills. + /// + public IReadOnlyList? Skills { get; set; } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/PacketHandlers/Map/InResponder.cs b/Core/NosSmooth.Game/PacketHandlers/Map/InResponder.cs index 7c67a786e84bb968151646a37a5c3384860804cc..724e8182766d71434737104915c75e8dc06b3e61 100644 --- a/Core/NosSmooth.Game/PacketHandlers/Map/InResponder.cs +++ b/Core/NosSmooth.Game/PacketHandlers/Map/InResponder.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using NosSmooth.Core.Extensions; using NosSmooth.Core.Packets; using NosSmooth.Data.Abstractions; +using NosSmooth.Game.Data.Characters; using NosSmooth.Game.Data.Entities; using NosSmooth.Game.Data.Info; using NosSmooth.Game.Data.Social; @@ -201,7 +202,13 @@ public class InResponder : IPacketResponder Level = monsterInfo?.Level ?? null, IsSitting = nonPlayerSubPacket.IsSitting, OwnerId = nonPlayerSubPacket.OwnerId, - IsPartner = nonPlayerSubPacket.PartnerMask == 1 + IsPartner = nonPlayerSubPacket.PartnerMask == 1, + Skills = new Skill[] + { + await CreateSkill(nonPlayerSubPacket.Skill1, nonPlayerSubPacket.SkillRank1, ct), + await CreateSkill(nonPlayerSubPacket.Skill2, nonPlayerSubPacket.SkillRank2, ct), + await CreateSkill(nonPlayerSubPacket.Skill3, nonPlayerSubPacket.SkillRank3, ct), + } }; } @@ -237,7 +244,29 @@ public class InResponder : IPacketResponder Position = new Position(packet.PositionX, packet.PositionY), IsInvisible = nonPlayerSubPacket.IsInvisible, Level = monsterInfo?.Level ?? null, - IsSitting = nonPlayerSubPacket.IsSitting + IsSitting = nonPlayerSubPacket.IsSitting, + Skills = new Skill[] + { + await CreateSkill(nonPlayerSubPacket.Skill1, nonPlayerSubPacket.SkillRank1, ct), + await CreateSkill(nonPlayerSubPacket.Skill2, nonPlayerSubPacket.SkillRank2, ct), + await CreateSkill(nonPlayerSubPacket.Skill3, nonPlayerSubPacket.SkillRank3, ct), + } }; } + + private async Task CreateSkill(int vnum, int? level, CancellationToken ct = default) + { + var skillInfoResult = await _infoService.GetSkillInfoAsync(vnum, ct); + if (!skillInfoResult.IsSuccess) + { + _logger.LogWarning + ( + "Could not obtain a skill info for vnum {vnum}: {error}", + vnum, + skillInfoResult.ToFullString() + ); + } + + return new Skill(vnum, level, skillInfoResult.Entity); + } } \ No newline at end of file