Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/NosCore.Data/Enumerations/Battle/SkillTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

namespace NosCore.Data.Enumerations.Battle
{
// Skills the server casts on its own when a situation arises, rather than from the skill bar.
public enum SkillTrigger : byte
{
None = 0,
HuntingFalconAttack = 1
}
}
5 changes: 5 additions & 0 deletions src/NosCore.Database/Entities/Skill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public Skill()

public SkillKind Kind { get; set; }

public SkillTrigger Trigger { get; set; }

// Skill.dat files the Adventurer's skills under class 0 together with emotes, courses and passives.
public bool IsAdventurerSkill { get; set; }

public short MpCost { get; set; }

[Required]
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ partial class NosCoreContextModelSnapshot : ModelSnapshot
// If you encounter a merge conflict in the line below, it means you need to
// discard one of the migration branches and recreate its migrations on top of
// the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info.
public override string LastMigrationId => "20261201120815_AddMapSpots";
public override string LastMigrationId => "20261201123617_MoveSkillRolesToParser";

protected override void BuildModel(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -71,6 +71,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "respawn_type", new[] { "default_act1", "return_act1", "default_act5", "return_act5", "default_act6", "default_act62", "default_oasis", "act4angel", "act4demon" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "scripted_instance_type", new[] { "time_space", "raid", "raid_act4" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "skill_kind", new[] { "attack", "debuff", "support", "emote" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "skill_trigger", new[] { "none", "hunting_falcon_attack" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "sp_partner_rank", new[] { "not_identified_yet", "f", "e", "d", "c", "b", "a", "s" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "specialist_upgrade_material", new[] { "none", "souls", "dragon_parts", "dragon_parts_and_shards" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "static_bonus_type", new[] { "bazaar_medal_gold", "bazaar_medal_silver", "back_pack", "pet_basket", "pet_back_pack", "inventory_ticket_upgrade", "cuarry_bank_vip", "medal_of_erenia", "adventurers_medal", "medal_of_friendship", "mimis_medal", "family_experience_booster" });
Expand Down Expand Up @@ -3634,6 +3635,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<byte>("HitType")
.HasColumnType("smallint");

b.Property<bool>("IsAdventurerSkill")
.HasColumnType("boolean");

b.Property<short>("ItemVNum")
.HasColumnType("smallint");

Expand Down Expand Up @@ -3684,6 +3688,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<byte>("TargetType")
.HasColumnType("smallint");

b.Property<byte>("Trigger")
.HasColumnType("smallint");

b.Property<byte>("Type")
.HasColumnType("smallint");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System.Threading.Tasks;
using NodaTime;
using NosCore.Data.Enumerations.Battle;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Ecs.Extensions;
using NosCore.GameObject.Ecs.Interfaces;
Expand All @@ -26,14 +27,11 @@ public interface IFalconService
public sealed class FalconService(IBattleService battleService, ISkillCatalog skills, ISkillCastService skillCastService,
ISessionRegistry sessionRegistry, IClock clock) : IFalconService, ISingletonService
{
// The Hunting Falcon's own attack.
private const short HuntingFalconAttackVNum = 1249;

public async Task<bool> StrikeAsync(PlayerComponentBundle player)
{
if (player.FalconTargetId == 0 || !player.CanFight || player.MapInstance is not { } map
|| clock.GetCurrentInstant() < player.FalconReadyAt
|| skills.GetSkill(HuntingFalconAttackVNum) is not { } attack)
|| skills.GetTriggeredSkill(SkillTrigger.HuntingFalconAttack) is not { } attack)
{
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/NosCore.GameObject/Services/SkillService/ISkillCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

using NosCore.Data.Enumerations.Battle;
using NosCore.Data.StaticEntities;

namespace NosCore.GameObject.Services.SkillService;

public interface ISkillCatalog
{
SkillDto? GetSkill(int skillVNum);

SkillDto? GetTriggeredSkill(SkillTrigger trigger);
}
8 changes: 8 additions & 0 deletions src/NosCore.GameObject/Services/SkillService/SkillCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Linq;
using NosCore.Data.Enumerations.Battle;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Infastructure;

Expand All @@ -17,5 +18,12 @@ public sealed class SkillCatalog(List<SkillDto> skills) : ISkillCatalog, ISingle
private readonly FrozenDictionary<int, SkillDto> _skills =
skills.GroupBy(s => (int)s.SkillVNum).ToFrozenDictionary(g => g.Key, g => g.First());

private readonly FrozenDictionary<SkillTrigger, SkillDto> _triggered = skills
.Where(s => s.Trigger != SkillTrigger.None)
.GroupBy(s => s.Trigger)
.ToFrozenDictionary(g => g.Key, g => g.First());

public SkillDto? GetSkill(int skillVNum) => _skills.GetValueOrDefault(skillVNum);

public SkillDto? GetTriggeredSkill(SkillTrigger trigger) => _triggered.GetValueOrDefault(trigger);
}
27 changes: 1 addition & 26 deletions src/NosCore.GameObject/Services/SkillService/SkillService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,35 +89,10 @@ private static void RemoveSpecialistSkills(PlayerComponentBundle character)
private static Task SendSkillListAsync(PlayerComponentBundle character, bool useSpecialist)
=> character.SendPacketAsync(character.GenerateSki(useSpecialist));

/// <summary>
/// The Adventurer's skills, listed one by one.
///
/// <b>They cannot be selected by class like every other one</b>, and that is this table's
/// trap: class 0 does not mean "Adventurer", it is the scrap container where 193 entries
/// end up - the emotes, the stat courses, the shop and rest actions, passives. Filtering
/// by class 0 gave an Adventurer <i>all</i> of them, and the bar filled with icons the
/// client will not cast.
///
/// The range is 200 to 210 inclusive. 209 is in it: Skill.dat gives it class 0, cast id
/// 16, LevelMinimum 1 and the name Capture - it is the Adventurer's pet catcher, which is
/// why CharNewPacketHandler grants it to every new character and why its comment there
/// talks about <c>u_s 16</c>. Left out, an Adventurer cannot catch anything.
///
/// 211 and 212 are excluded on purpose: the file calls them "Ultra Super Cheating Skill"
/// and "Admin Cheating Skill".
///
/// Open, and deliberately not guessed at: 300 to 306 are also class 0, with LevelMinimum
/// 10 to 18 and names like "Strengthen Swing". They look like the upgraded forms of
/// 200-206 and they carry the SAME cast ids, so they cannot simply be added alongside.
/// Nothing in the files says how one replaces the other, so they stay out until it does.
/// </summary>
private static readonly short[] AdventurerSkills =
{ 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210 };

/// <summary>The skills this class can hold.</summary>
private IEnumerable<SkillDto> Learnable(PlayerComponentBundle character) =>
character.Class == CharacterClassType.Adventurer
? skills.Where(s => AdventurerSkills.Contains(s.SkillVNum))
? skills.Where(s => s.IsAdventurerSkill)
: skills.Where(s => s.Class == (byte)character.Class);

/// <summary>
Expand Down
16 changes: 16 additions & 0 deletions src/NosCore.Parser/Parsers/SkillParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public class SkillParser(IDao<BCardDto, int> bCardDao, IDao<ComboDto, int> combo
// DATA c4 holds 999 when the skill's level requirement is a champion level.
private const string ChampionLevelMarker = "999";

// The Adventurer's skills cannot be told apart by class: Skill.dat files them under class 0
// with every emote, course, shop action and passive. 209 is Capture, the pet catcher every
// new character gets. 211 and 212 are excluded on purpose: the file calls them "Ultra Super
// Cheating Skill" and "Admin Cheating Skill". 300 to 306 look like upgraded forms of 200 to
// 206 but carry the same cast ids, and nothing in the files says how one replaces the other,
// so they stay out.
private static readonly HashSet<short> AdventurerSkills = [200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210];

private const short HuntingFalconAttack = 1249;

private readonly ILogger<SkillParser> _logger = loggerFactory.CreateLogger<SkillParser>();

private const int DataC1 = 2;
Expand Down Expand Up @@ -179,6 +189,12 @@ public async Task InsertSkillsAsync(string folder)
skill.LevelMinimum = (byte)((skill.CastId - SkillsUnlockedAtOnce) * LevelsPerUnlock);
}

foreach (var skill in skills)
{
skill.IsAdventurerSkill = AdventurerSkills.Contains(skill.SkillVNum);
skill.Trigger = skill.SkillVNum == HuntingFalconAttack ? SkillTrigger.HuntingFalconAttack : SkillTrigger.None;
}

await skillDao.TryInsertOrUpdateAsync(skills).OrThrowAsync();
var skillVNums = skills.Select(s => s.SkillVNum).ToHashSet();
await comboDao.TryDeleteAsync(comboDao.Where(s => skillVNums.Contains(s.SkillVNum))?.Select(s => s.ComboId).ToList() ?? []).OrThrowAsync();
Expand Down
16 changes: 8 additions & 8 deletions test/NosCore.EndToEnd.Tests/Infrastructure/WorldData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,17 @@ public static async Task SeedAsync(NosCoreContext context)
context.Add(new BCard { ItemVNum = Booster, Type = BCardType.CardType.Buff, SubType = 11, FirstData = 100, SecondData = BoostCard });
context.Add(new Skill
{
SkillVNum = WoundSkill, Name = "skill206", CastId = WoundSkillCastId, SkillType = 1, TargetType = 1, Cooldown = 6,
SkillVNum = WoundSkill, IsAdventurerSkill = true, Name = "skill206", CastId = WoundSkillCastId, SkillType = 1, TargetType = 1, Cooldown = 6,
Effect = -1, AttackAnimation = -1, CastAnimation = -1, CastEffect = -1
});
context.Add(new Skill
{
SkillVNum = StopBleedingSkill, Name = "skill207", CastId = StopBleedingSkillCastId, SkillType = 1, TargetType = 1, Cooldown = 6,
SkillVNum = StopBleedingSkill, IsAdventurerSkill = true, Name = "skill207", CastId = StopBleedingSkillCastId, SkillType = 1, TargetType = 1, Cooldown = 6,
Effect = -1, AttackAnimation = -1, CastAnimation = -1, CastEffect = -1
});
context.Add(new Skill
{
SkillVNum = WingsSkill, Name = "skill208", CastId = WingsSkillCastId, SkillType = 1, TargetType = 1, Cooldown = 6,
SkillVNum = WingsSkill, IsAdventurerSkill = true, Name = "skill208", CastId = WingsSkillCastId, SkillType = 1, TargetType = 1, Cooldown = 6,
Effect = -1, AttackAnimation = -1, CastAnimation = -1, CastEffect = -1
});
context.Add(new Card { CardId = WingsCard, Name = "wings", Level = 1, Duration = WingsCardTime, BuffType = BuffType.Good, HasLastingEffect = true });
Expand Down Expand Up @@ -586,31 +586,31 @@ public static async Task SeedAsync(NosCoreContext context)
// As the client data has them: skill type 1 is an active skill.
context.Add(new Skill
{
SkillVNum = 200, Name = "skill200", CastId = 0, SkillType = 1, Type = 0, Range = 1, CastTime = 2, Cooldown = 6,
SkillVNum = 200, Name = "skill200", IsAdventurerSkill = true, CastId = 0, SkillType = 1, Type = 0, Range = 1, CastTime = 2, Cooldown = 6,
Effect = 200, AttackAnimation = 11, CastAnimation = -1, CastEffect = -1
});
context.Add(new Skill
{
SkillVNum = 201, Name = "skill201", CastId = 1, SkillType = 1, Type = 1, Range = 7, CastTime = 6, Cooldown = 6,
SkillVNum = 201, Name = "skill201", IsAdventurerSkill = true, CastId = 1, SkillType = 1, Type = 1, Range = 7, CastTime = 6, Cooldown = 6,
Effect = 201, AttackAnimation = 23, CastAnimation = 26, CastEffect = -1
});
context.Add(new Skill
{
SkillVNum = 209, Name = "skill209", CastId = 16, SkillType = 1, CastTime = 6, Cooldown = 150, MpCost = 10,
SkillVNum = 209, Name = "skill209", IsAdventurerSkill = true, CastId = 16, SkillType = 1, CastTime = 6, Cooldown = 150, MpCost = 10,
UpgradeSkill = 3, LevelMinimum = 1, Effect = -1, AttackAnimation = -1, CastAnimation = -1, CastEffect = -1
});
// As the client data has them: skill type 2 is an upgrade of the skill its UpgradeSkill names.
context.Add(new Skill
{
SkillVNum = WeakeningUpgrade, Name = "skill202", CastId = 0, SkillType = 2, UpgradeSkill = 200, Effect = -1,
SkillVNum = WeakeningUpgrade, IsAdventurerSkill = true, Name = "skill202", CastId = 0, SkillType = 2, UpgradeSkill = 200, Effect = -1,
AttackAnimation = -1, CastAnimation = -1, CastEffect = -1
});
context.Add(new Card { CardId = WeakeningCard, Name = "weakening", Duration = 300, BuffType = BuffType.Bad });
await context.SaveChangesAsync();
context.Add(new BCard { SkillVNum = WeakeningUpgrade, Type = BCardType.CardType.Buff, SubType = 11, FirstData = 100, SecondData = WeakeningCard });
context.Add(new Skill
{
SkillVNum = SlowSkill, Name = "skill210", CastId = SlowSkillCastId, SkillType = 1, Type = 0, Range = 1, CastTime = 2,
SkillVNum = SlowSkill, IsAdventurerSkill = true, Name = "skill210", CastId = SlowSkillCastId, SkillType = 1, Type = 0, Range = 1, CastTime = 2,
Cooldown = 300, MpCost = SlowSkillMp, Effect = 200, AttackAnimation = 11, CastAnimation = -1, CastEffect = -1
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public async Task SetupAsync()
World.Freeze<Mock<IBuffService>>();

World.Freeze<Mock<ISkillCatalog>>()
.Setup(s => s.GetSkill(HuntingFalconAttackVNum))
.Returns(new SkillDto { SkillVNum = HuntingFalconAttackVNum, Cooldown = 600 });
.Setup(s => s.GetTriggeredSkill(SkillTrigger.HuntingFalconAttack))
.Returns(new SkillDto { SkillVNum = HuntingFalconAttackVNum, Cooldown = 600, Trigger = SkillTrigger.HuntingFalconAttack });
World.Freeze<Mock<ISkillCastService>>()
.Setup(s => s.Cooldown(It.IsAny<PlayerComponentBundle>(), 600))
.Returns(Duration.FromSeconds(60));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class ClassSkillLearningTests

private static readonly List<SkillDto> Catalog = new()
{
// the Adventurer's real skills, listed one by one from the original game
new SkillDto { SkillVNum = 200, Class = 0, LevelMinimum = 0, CastId = 0, SkillType = 1 },
new SkillDto { SkillVNum = 201, Class = 0, LevelMinimum = 0, CastId = 1, SkillType = 1 },
new SkillDto { SkillVNum = 208, Class = 0, LevelMinimum = 0, CastId = 8, SkillType = 1 },
new SkillDto { SkillVNum = 210, Class = 0, LevelMinimum = 0, CastId = 9, SkillType = 1 },
// the Adventurer's skills, flagged by the parser
new SkillDto { SkillVNum = 200, IsAdventurerSkill = true, Class = 0, LevelMinimum = 0, CastId = 0, SkillType = 1 },
new SkillDto { SkillVNum = 201, IsAdventurerSkill = true, Class = 0, LevelMinimum = 0, CastId = 1, SkillType = 1 },
new SkillDto { SkillVNum = 208, IsAdventurerSkill = true, Class = 0, LevelMinimum = 0, CastId = 8, SkillType = 1 },
new SkillDto { SkillVNum = 210, IsAdventurerSkill = true, Class = 0, LevelMinimum = 0, CastId = 9, SkillType = 1 },
// 209 is the Adventurer's Capture: class 0, cast id 16, LevelMinimum 1 in Skill.dat.
new SkillDto { SkillVNum = 209, Class = 0, LevelMinimum = 1, CastId = 16, SkillType = 1 },
new SkillDto { SkillVNum = 209, IsAdventurerSkill = true, Class = 0, LevelMinimum = 1, CastId = 16, SkillType = 1 },
// A cheat skill, class 0 like the rest of the bucket.
new SkillDto { SkillVNum = 211, Class = 0, LevelMinimum = 0, CastId = 10, SkillType = 1 },
// scrap: the same class 0, but they are passives and monster skills
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NosCore.Data.Enumerations.Battle;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Services.SkillService;
using NosCore.Tests.Shared;

namespace NosCore.GameObject.Tests.Services.SkillService
{
[TestClass]
public class SkillCatalogTests
{
private TestWorld World;

[TestInitialize]
public async Task SetupAsync()
{
World = await TestWorld.CreateAsync();
}

[TestMethod]
public void TheSkillForASituationIsFoundByItsTrigger()
{
World.Inject(new List<SkillDto> { new() { SkillVNum = 1249, Trigger = SkillTrigger.HuntingFalconAttack }, new() { SkillVNum = 1 } });

Assert.AreEqual((short)1249, World.Create<SkillCatalog>().GetTriggeredSkill(SkillTrigger.HuntingFalconAttack)?.SkillVNum);
}

[TestMethod]
public void NoSkillAnswersAMissingTrigger()
{
World.Inject(new List<SkillDto> { new() { SkillVNum = 1 } });

Assert.IsNull(World.Create<SkillCatalog>().GetTriggeredSkill(SkillTrigger.HuntingFalconAttack));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class SpecialistSkillTests
private static readonly List<SkillDto> Catalog = new()
{
// the adventurer's class skills
new SkillDto { SkillVNum = 200, Class = 0, LevelMinimum = 1, CastId = 0 },
new SkillDto { SkillVNum = 201, Class = 0, LevelMinimum = 1, CastId = 1 },
new SkillDto { SkillVNum = 200, IsAdventurerSkill = true, Class = 0, LevelMinimum = 1, CastId = 0 },
new SkillDto { SkillVNum = 201, IsAdventurerSkill = true, Class = 0, LevelMinimum = 1, CastId = 1 },
// the Flame Druid's skills, spread over two classes as in the file
new SkillDto { SkillVNum = 900, Class = 70, UpgradeType = MorphOfCard, LevelMinimum = 1, CastId = 0 },
new SkillDto { SkillVNum = 901, Class = 71, UpgradeType = MorphOfCard, LevelMinimum = 5, CastId = 8 },
Expand Down