forked from liza/ARControl
Use RetainerId instead of Name as id trait
This commit is contained in:
parent
9477be08d7
commit
31cbb118a4
@ -44,14 +44,43 @@ partial class AutoRetainerControlPlugin
|
|||||||
save = true;
|
save = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> seenRetainers = new();
|
// migrate legacy retainers
|
||||||
|
foreach (var legacyRetainer in character.Retainers.Where(x => x.RetainerContentId == 0))
|
||||||
|
{
|
||||||
|
var retainerData =
|
||||||
|
offlineCharacterData.RetainerData.SingleOrDefault(x => legacyRetainer.Name == x.Name);
|
||||||
|
if (retainerData != null)
|
||||||
|
{
|
||||||
|
_pluginLog.Information(
|
||||||
|
$"Assigning contentId {retainerData.RetainerID} to retainer {retainerData.Name}");
|
||||||
|
legacyRetainer.RetainerContentId = retainerData.RetainerID;
|
||||||
|
save = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var retainersWithoutContentId = character.Retainers.Where(c => c.RetainerContentId == 0).ToList();
|
||||||
|
if (retainersWithoutContentId.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var retainer in retainersWithoutContentId)
|
||||||
|
{
|
||||||
|
_pluginLog.Warning($"Removing retainer {retainer.Name} without contentId");
|
||||||
|
character.Retainers.Remove(retainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
save = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ulong> unknownRetainerIds = offlineCharacterData.RetainerData.Select(x => x.RetainerID).Where(x => x != 0).ToList();
|
||||||
foreach (var retainerData in offlineCharacterData.RetainerData)
|
foreach (var retainerData in offlineCharacterData.RetainerData)
|
||||||
{
|
{
|
||||||
var retainer = character.Retainers.SingleOrDefault(x => x.Name == retainerData.Name);
|
unknownRetainerIds.Remove(retainerData.RetainerID);
|
||||||
|
|
||||||
|
var retainer = character.Retainers.SingleOrDefault(x => x.RetainerContentId == retainerData.RetainerID);
|
||||||
if (retainer == null)
|
if (retainer == null)
|
||||||
{
|
{
|
||||||
retainer = new Configuration.RetainerConfiguration
|
retainer = new Configuration.RetainerConfiguration
|
||||||
{
|
{
|
||||||
|
RetainerContentId = retainerData.RetainerID,
|
||||||
Name = retainerData.Name,
|
Name = retainerData.Name,
|
||||||
Managed = false,
|
Managed = false,
|
||||||
};
|
};
|
||||||
@ -60,7 +89,11 @@ partial class AutoRetainerControlPlugin
|
|||||||
character.Retainers.Add(retainer);
|
character.Retainers.Add(retainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
seenRetainers.Add(retainer.Name);
|
if (retainer.Name != retainerData.Name)
|
||||||
|
{
|
||||||
|
retainer.Name = retainerData.Name;
|
||||||
|
save = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (retainer.DisplayOrder != retainerData.DisplayOrder)
|
if (retainer.DisplayOrder != retainerData.DisplayOrder)
|
||||||
{
|
{
|
||||||
@ -113,9 +146,17 @@ partial class AutoRetainerControlPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.Retainers.RemoveAll(x => !seenRetainers.Contains(x.Name)) > 0)
|
if (unknownRetainerIds.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var retainerId in unknownRetainerIds)
|
||||||
|
{
|
||||||
|
_pluginLog.Warning($"Removing unknown retainer with contentId {retainerId}");
|
||||||
|
character.Retainers.RemoveAll(c => c.RetainerContentId == retainerId);
|
||||||
|
}
|
||||||
|
|
||||||
save = true;
|
save = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (save)
|
if (save)
|
||||||
_pluginInterface.SavePluginConfig(_configuration);
|
_pluginInterface.SavePluginConfig(_configuration);
|
||||||
|
@ -374,7 +374,10 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
|
|||||||
if (s.Length > 1)
|
if (s.Length > 1)
|
||||||
retainerName = ch.Retainers.SingleOrDefault(x => x.Name.EqualsIgnoreCase(s[1]))?.Name;
|
retainerName = ch.Retainers.SingleOrDefault(x => x.Name.EqualsIgnoreCase(s[1]))?.Name;
|
||||||
else
|
else
|
||||||
retainerName = ch.Retainers.MinBy(x => x.DisplayOrder)?.Name;
|
retainerName = ch.Retainers
|
||||||
|
.OrderBy(x => x.DisplayOrder)
|
||||||
|
.ThenBy(x => x.RetainerContentId)
|
||||||
|
.FirstOrDefault()?.Name;
|
||||||
|
|
||||||
if (retainerName == null)
|
if (retainerName == null)
|
||||||
{
|
{
|
||||||
|
@ -97,6 +97,7 @@ internal sealed class Configuration : IPluginConfiguration
|
|||||||
|
|
||||||
public sealed class RetainerConfiguration
|
public sealed class RetainerConfiguration
|
||||||
{
|
{
|
||||||
|
public ulong RetainerContentId { get; set; }
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
public required bool Managed { get; set; }
|
public required bool Managed { get; set; }
|
||||||
public int DisplayOrder { get; set; }
|
public int DisplayOrder { get; set; }
|
||||||
|
@ -635,7 +635,8 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
if (ImGui.BeginTabItem("Retainers"))
|
if (ImGui.BeginTabItem("Retainers"))
|
||||||
{
|
{
|
||||||
foreach (var retainer in character.Retainers.Where(x => x.Job > 0)
|
foreach (var retainer in character.Retainers.Where(x => x.Job > 0)
|
||||||
.OrderBy(x => x.DisplayOrder))
|
.OrderBy(x => x.DisplayOrder)
|
||||||
|
.ThenBy(x => x.RetainerContentId))
|
||||||
{
|
{
|
||||||
ImGui.BeginDisabled(retainer.Level < MinLevel);
|
ImGui.BeginDisabled(retainer.Level < MinLevel);
|
||||||
|
|
||||||
@ -649,7 +650,7 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui.Checkbox(
|
if (ImGui.Checkbox(
|
||||||
$"{retainer.Name}###Retainer{retainer.Name}{retainer.DisplayOrder}",
|
$"{retainer.Name}###Retainer{retainer.Name}{retainer.RetainerContentId}",
|
||||||
ref managed))
|
ref managed))
|
||||||
{
|
{
|
||||||
retainer.Managed = managed;
|
retainer.Managed = managed;
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 7cb54772e3a4a60ad02520e898d1ed0e82b2a751
|
Subproject commit 7ff15133ac0d48e9aa57f69524bd9daf36c609bc
|
Loading…
Reference in New Issue
Block a user