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
19 changes: 10 additions & 9 deletions documentation/dat/monster.dat.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
HP/MP {monsterMaxHpBonus} {monsterMaxMpBonus}
ITEM {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop} {Drop}
LEVEL {monsterLevel}
MODE 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 {AlwaysActive} {Limiter} {HpThreshold} {RangeThreshold} {CModeVNum} {CellMinRange} {Midgard}
MODE 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 {AlwaysActive} {Limiter} {HpThreshold} {RangeThreshold} {CModeVNum} {CellMinRange} {Midgard}
NAME {NameI18NKey}
PARTNER {partnerUnused}
PETINFO {petInfoVal1} {petInfoVal2} {PetInfoVal3} {PetInfoVal4} {BaseStarRating}
Expand Down Expand Up @@ -314,14 +314,15 @@
| 23 | Unknown | | | |
| 24 | Unknown | | | |
| 25 | Unknown | | | |
| 26 | Parsed | AlwaysActive | Boolean | Mode always active when non-zero |
| 27 | Parsed | Limiter | Byte | Mode limiter |
| 28 | Parsed | HpThreshold | Int16 | HP% threshold that swaps the mode / item vnum |
| 29 | Parsed | RangeThreshold | Int16 | Range threshold for mode swap |
| 30 | Parsed | CModeVNum | Int16 | c_mode vnum (transform target) |
| 31 | Parsed | CellMinRange | Int16 | Minimum cells before the mode engages |
| 32 | Parsed | Midgard | Int32 | Midgard-specific data |
| 32 | Parsed | OwnerBlessingCardId | Int16 | Negative on a pet: the card it grants its owner |
| 26 | Unknown | | | |
| 27 | Parsed | AlwaysActive | Boolean | Mode always active when non-zero |
| 28 | Parsed | Limiter | Byte | Mode limiter |
| 29 | Parsed | HpThreshold | Int16 | HP% threshold that swaps the mode / item vnum |
| 30 | Parsed | RangeThreshold | Int16 | Range threshold for mode swap |
| 31 | Parsed | CModeVNum | Int16 | c_mode vnum (transform target) |
| 32 | Parsed | CellMinRange | Int16 | Minimum cells before the mode engages |
| 33 | Parsed | Midgard | Int32 | Midgard-specific data |
| 33 | Parsed | OwnerBlessingCardId | Int16 | Negative on a pet: the card it grants its owner |

## NAME

Expand Down
8 changes: 8 additions & 0 deletions documentation/manual-test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,14 @@ A character with a few Halloween Costume Scrolls (1913) in the Main bag, and a s
- [ ] At champion level 10, double-click it: "You've learned a new skill", the book is used up,
no gold is taken and the boost appears under Skill Info > Training
- [ ] Double-click a second copy: "You've already learned" and the book stays
- [ ] At the tome's champion level, read a Bear Loa Tome (2468) with Character Info (`p`) open: the
maximum HP rises by 7000. An Eagle Loa Tome (2469) raises ranged attack by 120, ranged
defence by 60, hit rate by 240 and dodge by 120
- [ ] Read a Vitality Guide (2721): the maximum HP and MP each rise by 3000
- [ ] With Aurelius Roshu's Primordial History (1) known, a kill gives 5% more experience than
the same kill without it
- [ ] Run the parser again, then send a Golden Gloopy Cake (709) out without touching the database:
the owner gets card 840 and its icon shows in the buff bar

### Mini pets

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public sealed class RewardService(
IBuffService buffService,
IEquipmentStatsService equipmentStatsService,
ICardCatalog cardCatalog,
SkillService.IPassiveSkillService passiveSkillService,
IQuestDropService questDropService,
IScriptedInstanceService scriptedInstanceService,
IItemDeliveryService itemDeliveryService,
Expand Down Expand Up @@ -228,7 +229,8 @@ private bool DropRolls(DropDto drop, Services.MapInstanceGenerationService.MapIn
int doubleChance = 0, noDropChance = 0;
var cards = buffService.GetActiveBuffs(player).SelectMany(b => b.BCards)
.Concat(equipmentStatsService.Resolve(player).BCards ?? [])
.Concat(player.MedalBCards(itemCatalog, cardCatalog));
.Concat(player.MedalBCards(itemCatalog, cardCatalog))
.Concat(passiveSkillService.GetBCards(player));
foreach (var bCard in cards)
{
switch (bCard.Effect())
Expand All @@ -250,7 +252,8 @@ private int GoldBonusPercent(PlayerComponentBundle player)
var percent = 0;
var cards = buffService.GetActiveBuffs(player).SelectMany(b => b.BCards)
.Concat(equipmentStatsService.Resolve(player).BCards ?? [])
.Concat(player.MedalBCards(itemCatalog, cardCatalog));
.Concat(player.MedalBCards(itemCatalog, cardCatalog))
.Concat(passiveSkillService.GetBCards(player));
foreach (var bCard in cards)
{
switch (bCard.Effect())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
namespace NosCore.GameObject.Services.ExperienceService
{
public sealed class ExperienceBonusService(IBuffService buffService, IEquipmentStatsService equipmentStatsService,
IItemCatalog itemCatalog, ICardCatalog cardCatalog) : IExperienceBonusService
IItemCatalog itemCatalog, ICardCatalog cardCatalog, SkillService.IPassiveSkillService passiveSkillService) : IExperienceBonusService
{
public ExperienceBonus GetBonus(PlayerComponentBundle player)
{
int experience = 0, jobExperience = 0, heroExperience = 0, reputation = 0;
var cards = buffService.GetActiveBuffs(player).SelectMany(b => b.BCards)
.Concat(equipmentStatsService.Resolve(player).BCards ?? [])
.Concat(player.MedalBCards(itemCatalog, cardCatalog));
.Concat(player.MedalBCards(itemCatalog, cardCatalog))
.Concat(passiveSkillService.GetBCards(player));
foreach (var bCard in cards)
{
var value = BattleStatsProvider.ScaleByLevel(bCard, player.Level);
Expand Down
16 changes: 8 additions & 8 deletions src/NosCore.Parser/Parsers/NpcMonsterParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ public FluentParserBuilder<NpcMonsterDto> BuildParser(string folder)
.Field(x => x.CanOnlyBeDmgedByJajamaruLastSkill, "ETC", 0, 5, s => s != "0", "Only damageable by Jajamaru's final skill (Namaju)")
.Field(x => x.VisibleOnMinimapAsGreenDot, "ETC", 0, 7, s => s != "0", "Renders as a green dot on the minimap")
.Field(x => x.IsValhallaPartner, "ETC", 0, 9, s => s != "0", "Marks Valhalla raid partner mobs")
.Field(x => x.AlwaysActive, "MODE", 0, 26, s => s != "0", "Mode always active when non-zero")
.Field(x => x.Limiter, "MODE", 0, 27, s => Convert.ToByte(s), "Mode limiter")
.Field(x => x.HpThreshold, "MODE", 0, 28, s => Convert.ToInt16(s), "HP% threshold that swaps the mode / item vnum")
.Field(x => x.RangeThreshold, "MODE", 0, 29, s => Convert.ToInt16(s), "Range threshold for mode swap")
.Field(x => x.CModeVNum, "MODE", 0, 30, s => Convert.ToInt16(s), "c_mode vnum (transform target)")
.Field(x => x.CellMinRange, "MODE", 0, 31, s => Convert.ToInt16(s), "Minimum cells before the mode engages")
.Field(x => x.Midgard, "MODE", 0, 32, s => Convert.ToInt32(s), "Midgard-specific data")
.Field(x => x.OwnerBlessingCardId, "MODE", 0, 32, s => Convert.ToInt32(s) < 0 ? (short)-Convert.ToInt32(s) : (short)0, "Negative on a pet: the card it grants its owner")
.Field(x => x.AlwaysActive, "MODE", 0, 27, s => s != "0", "Mode always active when non-zero")
.Field(x => x.Limiter, "MODE", 0, 28, s => Convert.ToByte(s), "Mode limiter")
.Field(x => x.HpThreshold, "MODE", 0, 29, s => Convert.ToInt16(s), "HP% threshold that swaps the mode / item vnum")
.Field(x => x.RangeThreshold, "MODE", 0, 30, s => Convert.ToInt16(s), "Range threshold for mode swap")
.Field(x => x.CModeVNum, "MODE", 0, 31, s => Convert.ToInt16(s), "c_mode vnum (transform target)")
.Field(x => x.CellMinRange, "MODE", 0, 32, s => Convert.ToInt16(s), "Minimum cells before the mode engages")
.Field(x => x.Midgard, "MODE", 0, 33, s => Convert.ToInt32(s), "Midgard-specific data")
.Field(x => x.OwnerBlessingCardId, "MODE", 0, 33, s => Convert.ToInt32(s) < 0 ? (short)-Convert.ToInt32(s) : (short)0, "Negative on a pet: the card it grants its owner")
.Field(x => x.Level, chunk => Level(chunk),
reads: new[] { ("LEVEL", 0, 2) },
source: "LEVEL[2]", description: "Parsed by Level(chunk) helper")
Expand Down
109 changes: 83 additions & 26 deletions src/NosCore.Parser/Parsers/SkillParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,77 @@ public class SkillParser(IDao<BCardDto, int> bCardDao, IDao<ComboDto, int> combo

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

// A training course has no BASIC line. Its kind is the TYPE cast id and its amount the
// first DATA field; the client's own tooltip names what each kind raises.
private static readonly Dictionary<short, BCardEffect> CourseEffects = new()
private const int DataC1 = 2;
private const int DataC2 = 3;
private const int DataC3 = 4;

private sealed record CourseCard(BCardEffect Effect, int DataField, int Multiplier = 1, int Divisor = 1);

private static readonly CourseCard[] MeleeTome =
[
new(BCardEffect.AttackPowerMeleeAttacksIncreased, DataC2),
new(BCardEffect.DefenceMeleeIncreased, DataC2, Divisor: 2),
];

private static readonly CourseCard[] RangedTome =
[
new(BCardEffect.AttackPowerRangedAttacksIncreased, DataC2),
new(BCardEffect.DefenceRangedIncreased, DataC2, Divisor: 2),
new(BCardEffect.TargetAllHitRateIncreased, DataC2, Multiplier: 2),
new(BCardEffect.DodgeAndDefencePercentDodgeIncreased, DataC2),
];

private static readonly CourseCard[] MagicTome =
[
new(BCardEffect.AttackPowerMagicalAttacksIncreased, DataC2),
new(BCardEffect.DefenceMagicalIncreased, DataC2, Divisor: 2),
];

private static readonly CourseCard[] AttackAndDefenceTome =
[
new(BCardEffect.AttackPowerAllAttacksIncreased, DataC2),
new(BCardEffect.DefenceAllIncreased, DataC3),
];

// A training course or tome has no BASIC line: its TYPE cast id names what it raises and
// its DATA fields carry the amounts. Courses 4 to 9 keep the amount in DATA c1; the tomes
// from 19 on keep their tier there, the amount in c2 and a second amount in c3. Where a
// tome raises several stats from one amount, the ratios are the ones its tooltip lists.
private static readonly Dictionary<short, CourseCard[]> CourseEffects = new()
{
[4] = BCardEffect.MaxHpmpMaximumHpIncreased,
[5] = BCardEffect.MaxHpmpMaximumMpIncreased,
[6] = BCardEffect.AttackPowerAllAttacksIncreased,
[7] = BCardEffect.DefenceAllIncreased,
[8] = BCardEffect.RecoveryHpRecoveryIncreased,
[9] = BCardEffect.RecoveryMpRecoveryIncreased,
[4] = [new(BCardEffect.MaxHpmpMaximumHpIncreased, DataC1)],
[5] = [new(BCardEffect.MaxHpmpMaximumMpIncreased, DataC1)],
[6] = [new(BCardEffect.AttackPowerAllAttacksIncreased, DataC1)],
[7] = [new(BCardEffect.DefenceAllIncreased, DataC1)],
[8] = [new(BCardEffect.RecoveryHpRecoveryIncreased, DataC1)],
[9] = [new(BCardEffect.RecoveryMpRecoveryIncreased, DataC1)],
[19] = [new(BCardEffect.LeonaPassiveSkillAttackIncreasedInPvp, DataC2)],
[20] = [new(BCardEffect.LeonaPassiveSkillDefenceIncreasedInPvp, DataC2)],
[21] = MeleeTome,
[22] = RangedTome,
[23] = MagicTome,
[24] = [new(BCardEffect.MaxHpmpMaximumHpIncreased, DataC2)],
[25] = [new(BCardEffect.MaxHpmpMaximumMpIncreased, DataC2)],
[26] = [new(BCardEffect.DefenceAllIncreased, DataC2)],
[27] = [new(BCardEffect.AttackPowerAllAttacksIncreased, DataC2)],
[28] = [new(BCardEffect.ElementResistanceAllIncreased, DataC2)],
[29] = [new(BCardEffect.ItemExpIncreased, DataC2)],
[30] = [new(BCardEffect.ItemIncreaseEarnedGold, DataC2)],
[31] = [new(BCardEffect.MaxHpmpMaximumHpIncreased, DataC2)],
[32] = RangedTome,
[33] = MagicTome,
[34] = MeleeTome,
[35] = [new(BCardEffect.MaxHpmpMaximumMpIncreased, DataC2)],
[36] = AttackAndDefenceTome,
[37] = AttackAndDefenceTome,
[38] = AttackAndDefenceTome,
[40] = [new(BCardEffect.MaxHpmpMaximumHpIncreased, DataC2), new(BCardEffect.MaxHpmpMaximumMpIncreased, DataC3)],
[41] = AttackAndDefenceTome,
[42] = AttackAndDefenceTome,
[43] = AttackAndDefenceTome,
[44] = [new(BCardEffect.IncreaseFairyElement, DataC2)],
[45] = [new(BCardEffect.MultAttackAllAttackIncreased, DataC2)],
[46] = [new(BCardEffect.DropX2Chance, DataC2)],
};
// VNUM {VNum}
// NAME {Name}
Expand Down Expand Up @@ -118,23 +179,6 @@ public async Task InsertSkillsAsync(string folder)
skill.LevelMinimum = (byte)((skill.CastId - SkillsUnlockedAtOnce) * LevelsPerUnlock);
}

foreach (var course in skills.Where(s => s.SkillType == 0 && (s.BCards == null || s.BCards.Count == 0)))
{
if (CourseEffects.TryGetValue(course.CastId, out var effect))
{
course.BCards = new List<BCardDto>
{
new()
{
SkillVNum = course.SkillVNum,
Type = effect.Type(),
SubType = effect.SubType(),
FirstData = course.UpgradeSkill
}
};
}
}

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 Expand Up @@ -173,6 +217,19 @@ private List<BCardDto> AddBCards(Dictionary<string, string[][]> chunks)
list.Add(comb);
}

if (list.Count == 0 && chunks["TYPE"][0][2] == "0"
&& CourseEffects.TryGetValue(Convert.ToInt16(chunks["TYPE"][0][3]), out var courseCards))
{
var skillVNum = Convert.ToInt16(chunks["VNUM"][0][2]);
list.AddRange(courseCards.Select(c => new BCardDto
{
SkillVNum = skillVNum,
Type = c.Effect.Type(),
SubType = c.Effect.SubType(),
FirstData = (short)(int.Parse(chunks["DATA"][0][c.DataField]) * c.Multiplier / c.Divisor)
}));
}

return list;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NosCore.Data.Enumerations.Buff;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Networking.ClientSession;
using NosCore.GameObject.Services.BattleService;
using NosCore.GameObject.Services.ExperienceService;
using NosCore.GameObject.Services.SkillService;
using NosCore.Tests.Shared;

namespace NosCore.GameObject.Tests.Services.SkillService
{
[TestClass]
public class PassiveTomeBonusTests
{
private TestWorld World;
private ClientSession _session;
private ExperienceBonusService _bonus;

private static readonly SkillDto PrimordialHistory = new() { SkillVNum = 104, SkillType = 0, CastId = 29 };

[TestInitialize]
public async Task SetupAsync()
{
World = await TestWorld.CreateAsync();
_session = await World.CreateSessionAsync();
var catalog = World.Freeze<Mock<INpcCombatCatalog>>();
catalog.Setup(c => c.GetSkillBCards(It.IsAny<short>())).Returns(Array.Empty<BCardDto>());
catalog.Setup(c => c.GetSkillBCards(104)).Returns(new[]
{
new BCardDto
{
SkillVNum = 104, Type = BCardEffect.ItemExpIncreased.Type(),
SubType = BCardEffect.ItemExpIncreased.SubType(), FirstData = 5
}
});
World.UseReal<IPassiveSkillService, PassiveSkillService>();
_bonus = World.Create<ExperienceBonusService>();
}

[TestMethod]
public void AnExperienceTomeRaisesTheExperienceEarned()
{
var before = _bonus.GetBonus(_session.Character).Experience;

_session.Character.Skills[PrimordialHistory.SkillVNum] =
new CharacterSkill { SkillVNum = PrimordialHistory.SkillVNum, Skill = PrimordialHistory };

Assert.AreEqual(before + 5, _bonus.GetBonus(_session.Character).Experience);
}
}
}
23 changes: 22 additions & 1 deletion test/NosCore.Parser.Tests/NpcMonsterParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,29 @@ public async Task NpcMonsterParser_ImportsABossWhoseSizeAndRangesOutgrowAByte()
var monster = _savedMonsters.Single();
Assert.AreEqual(250, monster.SpriteSize);
Assert.AreEqual(1000, monster.NoticeRange);
Assert.AreEqual(462, monster.CellMinRange);
Assert.AreEqual(462, monster.CModeVNum);
Assert.AreEqual(0, monster.CriticalChance);
}

// MODE ends with seven settings after four BCard groups and five empty columns; the last
// one is negative on a pet that blesses its owner.
[TestMethod]
public async Task NpcMonsterParser_ReadsTheModeSettingsFromTheirOwnColumns()
{
var mode = string.Join("\t", Enumerable.Repeat("0", 25).Concat(["1", "2", "50", "3", "482", "4", "-840"]));
File.WriteAllText(Path.Combine(_tempFolder, "monster.dat"), BuildMonster(709, "zts709e", 1, mode: mode));
var parser = new NpcMonsterParser(_skillDaoMock.Object, _bCardDaoMock.Object, _dropDaoMock.Object,
_npcMonsterSkillDaoMock.Object, _npcMonsterDaoMock.Object, NullLoggerFactory.Instance, _logLanguageMock.Object, MonsterStats);
await parser.InsertNpcMonstersAsync(_tempFolder);

var monster = _savedMonsters.Single();
Assert.IsTrue(monster.AlwaysActive);
Assert.AreEqual(2, monster.Limiter);
Assert.AreEqual(50, monster.HpThreshold);
Assert.AreEqual(3, monster.RangeThreshold);
Assert.AreEqual(482, monster.CModeVNum);
Assert.AreEqual(4, monster.CellMinRange);
Assert.AreEqual(840, monster.OwnerBlessingCardId);
}
}
}
Loading