Skip to content

Commit

Permalink
only index mobs that actually belong to the hunts
Browse files Browse the repository at this point in the history
the notorious monster sheet is the list of hunt marks
  • Loading branch information
dit-zy committed Feb 12, 2024
1 parent 8c5b8ae commit 711c87f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
10 changes: 8 additions & 2 deletions ScoutHelper/Managers/MobManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using CSharpFunctionalExtensions;
using Dalamud;
Expand Down Expand Up @@ -30,17 +31,22 @@ public MobManager(IPluginLog log, IDataManager dataManager) {
IDataManager dataManager
) {
_log.Debug("Building mob data from game files...");

var notoriousMonsters = dataManager.GetExcelSheet<NotoriousMonster>(ClientLanguage.English)!
.Select(monster => monster.BNpcName.Row)
.ToImmutableHashSet();

var nameToId = dataManager.GetExcelSheet<BNpcName>(ClientLanguage.English)!
.Select(name => (name.Singular.ToString().Lower(), name.RowId))
.Select(name => (name: name.Singular.ToString().Lower(), mobId: name.RowId))
.Where(name => notoriousMonsters.Contains(name.mobId))
.GroupBy(entry => entry.Item1)
.Select(
grouping => {
if (1 < grouping.Count()) {
_log.Debug(
"Duplicate mobs found for name [{0:l}]: {1:l}",
grouping.Key,
grouping.Select(entry => entry.RowId.ToString()).Join(", ")
grouping.Select(entry => entry.mobId.ToString()).Join(", ")
);
}
return grouping.First();
Expand Down
17 changes: 13 additions & 4 deletions ScoutHelperTests/Managers/MobManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ public Property IndexContainsAllElements() => ForAll(
// DATA
var npcNameSheet = MockExcelSheet.Create<BNpcName>()
.AddRows(npcNames.Select(name => MockBNpcName.Create(name.Item1, name.Item2)));
var notoriousMonsterSheet = MockExcelSheet.Create<NotoriousMonster>()
.AddRows(npcNames.Select(name => MockNotoriousMonster.Create(name.Item1, name.Item1)));
// GIVEN
_log.Setup(log => log.Debug(It.IsAny<string>()));
_dataManager.Setup(dm => dm.GetExcelSheet<BNpcName>(It.IsAny<ClientLanguage>()))
.Returns(npcNameSheet);
_dataManager.Setup(dm => dm.GetExcelSheet<NotoriousMonster>(It.IsAny<ClientLanguage>()))
.Returns(notoriousMonsterSheet);
// WHEN
var mobManager = new MobManager(_log.Object, _dataManager.Object);
// THEN
_dataManager.Verify(manager => manager.GetExcelSheet<BNpcName>(ClientLanguage.English));
_dataManager.Verify(manager => manager.GetExcelSheet<NotoriousMonster>(ClientLanguage.English));
_log.Verify(log => log.Debug("Building mob data from game files..."));
_log.Verify(log => log.Debug("Mob data built."));
_dataManager.VerifyNoOtherCalls();
Expand All @@ -49,8 +54,8 @@ public Property IndexContainsAllElements() => ForAll(
entry => {
var mobId = entry.Item1;
var mobName = entry.Item2;
mobManager.GetMobName(mobId).Should().Be(mobName.Lower());
mobManager.GetMobId(mobName).Should().Be(mobId);
mobManager.GetMobName(mobId).Should().Be(Maybe.From(mobName.Lower()));
mobManager.GetMobId(mobName).Should().Be(Maybe.From(mobId));
}
);
}
Expand All @@ -66,9 +71,10 @@ public Property IndexHandlesDuplicates() => ForAll(
.AsList();
var numDupNames = inputs.dupNames.DistinctBy(name => name.mobName).Count();
var npcNameSheet = MockExcelSheet
.Create<BNpcName>()
var npcNameSheet = MockExcelSheet .Create<BNpcName>()
.AddRows(npcNames.Select(name => MockBNpcName.Create(name.mobId, name.mobName)));
var notoriousMonsterSheet = MockExcelSheet.Create<NotoriousMonster>()
.AddRows(npcNames.Select(name => MockNotoriousMonster.Create(name.mobId, name.mobId)));
// GIVEN
_log.Reset();
Expand All @@ -78,12 +84,15 @@ public Property IndexHandlesDuplicates() => ForAll(
_log.Setup(log => log.Debug(It.IsAny<string>(), It.IsAny<object[]>()));
_dataManager.Setup(dm => dm.GetExcelSheet<BNpcName>(It.IsAny<ClientLanguage>()))
.Returns(npcNameSheet);
_dataManager.Setup(dm => dm.GetExcelSheet<NotoriousMonster>(It.IsAny<ClientLanguage>()))
.Returns(notoriousMonsterSheet);
// WHEN
var mobManager = new MobManager(_log.Object, _dataManager.Object);
// THEN
_dataManager.Verify(manager => manager.GetExcelSheet<BNpcName>(ClientLanguage.English));
_dataManager.Verify(manager => manager.GetExcelSheet<NotoriousMonster>(ClientLanguage.English));
_log.Verify(log => log.Debug("Building mob data from game files..."));
_log.Verify(log => log.Debug("Mob data built."));
_log.Verify(
Expand Down
18 changes: 18 additions & 0 deletions ScoutHelperTests/TestUtils/MoqHelpers/MockNotoriousMonster.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Lumina.Data;
using Lumina.Excel;
using Lumina.Excel.GeneratedSheets2;
using ScoutHelper.Utils;
using static ScoutHelperTests.TestUtils.MoqHelpers.MoqUtils;

namespace ScoutHelperTests.TestUtils.MoqHelpers;

public class MockNotoriousMonster : NotoriousMonster, IMockExcelRow {
private MockNotoriousMonster(uint rowId, uint bnpcNameId) {
RowId = rowId;
this.SetProperty("BNpcName", MockLazyRow<BNpcName>(bnpcNameId));
}

public static MockNotoriousMonster Create(uint rowId, uint bnpcNameId) {
return new MockNotoriousMonster(rowId, bnpcNameId);
}
}
5 changes: 4 additions & 1 deletion ScoutHelperTests/TestUtils/MoqHelpers/MoqUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lumina.Excel;
using Lumina.Data;
using Lumina.Excel;

namespace ScoutHelperTests.TestUtils.MoqHelpers;

Expand All @@ -15,5 +16,7 @@ public static void SetProperty<T>(this T excelRow, string propertyName, object?
.Invoke(excelRow, new object?[] { value });
}

public static LazyRow<T> MockLazyRow<T>(uint rowId) where T : ExcelRow => new(null, rowId, Language.English);

Check warning on line 19 in ScoutHelperTests/TestUtils/MoqHelpers/MoqUtils.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 19 in ScoutHelperTests/TestUtils/MoqHelpers/MoqUtils.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

#endregion
}

0 comments on commit 711c87f

Please sign in to comment.