1
0
Fork 0

Cleanup/prep for calculating crystal/shard rewards

master
Liza 2023-09-30 18:53:48 +02:00
parent 05b5654f84
commit 3475ce6c10
Signed by: liza
GPG Key ID: 7199F8D727D55F67
5 changed files with 191 additions and 158 deletions

View File

@ -74,7 +74,7 @@
<ItemGroup> <ItemGroup>
<Folder Include="External\" /> <Folder Include="External\"/>
</ItemGroup> </ItemGroup>
<Target Name="RenameLatestZip" AfterTargets="PackagePlugin"> <Target Name="RenameLatestZip" AfterTargets="PackagePlugin">

View File

@ -0,0 +1,105 @@
using System.Linq;
using Dalamud.Logging;
namespace ARControl;
partial class AutoRetainerControlPlugin
{
private void Sync()
{
bool save = false;
// FIXME This should have a way to get blacklisted character ids
foreach (ulong registeredCharacterId in _autoRetainerApi.GetRegisteredCharacters())
{
PluginLog.Information($"ch → {registeredCharacterId:X}");
var offlineCharacterData = _autoRetainerApi.GetOfflineCharacterData(registeredCharacterId);
if (offlineCharacterData.ExcludeRetainer)
continue;
var character = _configuration.Characters.SingleOrDefault(x => x.LocalContentId == registeredCharacterId);
if (character == null)
{
character = new Configuration.CharacterConfiguration
{
LocalContentId = registeredCharacterId,
CharacterName = offlineCharacterData.Name,
WorldName = offlineCharacterData.World,
Managed = false,
};
save = true;
_configuration.Characters.Add(character);
}
if (character.GatheredItems != offlineCharacterData.UnlockedGatheringItems)
{
character.GatheredItems = offlineCharacterData.UnlockedGatheringItems;
save = true;
}
foreach (var retainerData in offlineCharacterData.RetainerData)
{
var retainer = character.Retainers.SingleOrDefault(x => x.Name == retainerData.Name);
if (retainer == null)
{
retainer = new Configuration.RetainerConfiguration
{
Name = retainerData.Name,
Managed = false,
};
save = true;
character.Retainers.Add(retainer);
}
if (retainer.DisplayOrder != retainerData.DisplayOrder)
{
retainer.DisplayOrder = retainerData.DisplayOrder;
save = true;
}
if (retainer.Level != retainerData.Level)
{
retainer.Level = retainerData.Level;
save = true;
}
if (retainer.Job != retainerData.Job)
{
retainer.Job = retainerData.Job;
save = true;
}
if (retainer.LastVenture != retainerData.VentureID)
{
retainer.LastVenture = retainerData.VentureID;
save = true;
}
var additionalData =
_autoRetainerApi.GetAdditionalRetainerData(registeredCharacterId, retainerData.Name);
if (retainer.ItemLevel != additionalData.Ilvl)
{
retainer.ItemLevel = additionalData.Ilvl;
save = true;
}
if (retainer.Gathering != additionalData.Gathering)
{
retainer.Gathering = additionalData.Gathering;
save = true;
}
if (retainer.Perception != additionalData.Perception)
{
retainer.Perception = additionalData.Perception;
save = true;
}
}
}
if (save)
_pluginInterface.SavePluginConfig(_configuration);
}
}

View File

@ -19,7 +19,7 @@ using ImGuiNET;
namespace ARControl; namespace ARControl;
[SuppressMessage("ReSharper", "UnusedType.Global")] [SuppressMessage("ReSharper", "UnusedType.Global")]
public sealed class AutoRetainerControlPlugin : IDalamudPlugin public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
{ {
private readonly WindowSystem _windowSystem = new(nameof(AutoRetainerControlPlugin)); private readonly WindowSystem _windowSystem = new(nameof(AutoRetainerControlPlugin));
@ -30,6 +30,7 @@ public sealed class AutoRetainerControlPlugin : IDalamudPlugin
private readonly Configuration _configuration; private readonly Configuration _configuration;
private readonly GameCache _gameCache; private readonly GameCache _gameCache;
private readonly VentureResolver _ventureResolver;
private readonly ConfigWindow _configWindow; private readonly ConfigWindow _configWindow;
private readonly AutoRetainerApi _autoRetainerApi; private readonly AutoRetainerApi _autoRetainerApi;
@ -44,6 +45,7 @@ public sealed class AutoRetainerControlPlugin : IDalamudPlugin
_configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration();
_gameCache = new GameCache(dataManager); _gameCache = new GameCache(dataManager);
_ventureResolver = new VentureResolver(_gameCache);
_configWindow = new ConfigWindow(_pluginInterface, _configuration, _gameCache, _clientState, _commandManager); _configWindow = new ConfigWindow(_pluginInterface, _configuration, _gameCache, _clientState, _commandManager);
_windowSystem.AddWindow(_configWindow); _windowSystem.AddWindow(_configWindow);
@ -92,64 +94,25 @@ public sealed class AutoRetainerControlPlugin : IDalamudPlugin
foreach (var queuedItem in _configuration.QueuedItems.Where(x => x.RemainingQuantity > 0)) foreach (var queuedItem in _configuration.QueuedItems.Where(x => x.RemainingQuantity > 0))
{ {
PluginLog.Information($"Checking venture info for itemId {queuedItem.ItemId}"); PluginLog.Information($"Checking venture info for itemId {queuedItem.ItemId}");
var venture = _gameCache.Ventures
.Where(x => retainer.Level >= x.Level) var (venture, reward) = _ventureResolver.ResolveVenture(ch, retainer, queuedItem);
.FirstOrDefault(x => x.ItemId == queuedItem.ItemId && x.MatchesJob(retainer.Job)); if (reward == null)
if (venture == null)
{ {
PluginLog.Information($"No applicable venture found for itemId {queuedItem.ItemId}"); PluginLog.Information("Retainer can't complete venture");
} }
else else
{ {
var itemToGather = _gameCache.ItemsToGather.FirstOrDefault(x => x.ItemId == queuedItem.ItemId); _chatGui.Print(
if (itemToGather != null && !ch.GatheredItems.Contains(itemToGather.GatheredItemId)) $"ARC → Overriding venture to collect {reward.Quantity}x {venture!.Name}.");
{ PluginLog.Information(
PluginLog.Information($"Character hasn't gathered {venture.Name} yet"); $"Setting AR to use venture {venture.RowId}, which should retrieve {reward.Quantity}x {venture.Name}");
} _autoRetainerApi.SetVenture(venture.RowId);
else
{
PluginLog.Information(
$"Found venture {venture.Name}, row = {venture.RowId}, checking if it is suitable");
VentureReward? reward = null;
if (venture.CategoryName is "MIN" or "BTN")
{
if (retainer.Gathering >= venture.RequiredGathering)
reward = venture.Rewards.Last(
x => retainer.Perception >= x.PerceptionMinerBotanist);
}
else if (venture.CategoryName == "FSH")
{
if (retainer.Gathering >= venture.RequiredGathering)
reward = venture.Rewards.Last(
x => retainer.Perception >= x.PerceptionFisher);
}
else
{
if (retainer.ItemLevel >= venture.ItemLevelCombat)
reward = venture.Rewards.Last(
x => retainer.ItemLevel >= x.ItemLevelCombat);
}
if (reward == null) retainer.LastVenture = venture.RowId;
{ queuedItem.RemainingQuantity =
PluginLog.Information( Math.Max(0, queuedItem.RemainingQuantity - reward.Quantity);
"Retainer doesn't have enough stats for the venture and would return no items"); _pluginInterface.SavePluginConfig(_configuration);
} return;
else
{
_chatGui.Print(
$"ARC → Overriding venture to collect {reward.Quantity}x {venture.Name}.");
PluginLog.Information(
$"Setting AR to use venture {venture.RowId}, which should retrieve {reward.Quantity}x {venture.Name}");
_autoRetainerApi.SetVenture(venture.RowId);
retainer.LastVenture = venture.RowId;
queuedItem.RemainingQuantity =
Math.Max(0, queuedItem.RemainingQuantity - reward.Quantity);
_pluginInterface.SavePluginConfig(_configuration);
return;
}
}
} }
} }
@ -171,11 +134,13 @@ public sealed class AutoRetainerControlPlugin : IDalamudPlugin
private void RetainerTaskButtonDraw(ulong characterId, string retainerName) private void RetainerTaskButtonDraw(ulong characterId, string retainerName)
{ {
Configuration.CharacterConfiguration? characterConfiguration = _configuration.Characters.FirstOrDefault(x => x.LocalContentId == characterId); Configuration.CharacterConfiguration? characterConfiguration =
_configuration.Characters.FirstOrDefault(x => x.LocalContentId == characterId);
if (characterConfiguration is not { Managed: true }) if (characterConfiguration is not { Managed: true })
return; return;
Configuration.RetainerConfiguration? retainer = characterConfiguration.Retainers.FirstOrDefault(x => x.Name == retainerName); Configuration.RetainerConfiguration? retainer =
characterConfiguration.Retainers.FirstOrDefault(x => x.Name == retainerName);
if (retainer is not { Managed: true }) if (retainer is not { Managed: true })
return; return;
@ -185,104 +150,6 @@ public sealed class AutoRetainerControlPlugin : IDalamudPlugin
private void TerritoryChanged(object? sender, ushort e) => Sync(); private void TerritoryChanged(object? sender, ushort e) => Sync();
private void Sync()
{
bool save = false;
// FIXME This should have a way to get blacklisted character ids
foreach (ulong registeredCharacterId in _autoRetainerApi.GetRegisteredCharacters())
{
PluginLog.Information($"ch → {registeredCharacterId:X}");
var offlineCharacterData = _autoRetainerApi.GetOfflineCharacterData(registeredCharacterId);
if (offlineCharacterData.ExcludeRetainer)
continue;
var character = _configuration.Characters.SingleOrDefault(x => x.LocalContentId == registeredCharacterId);
if (character == null)
{
character = new Configuration.CharacterConfiguration
{
LocalContentId = registeredCharacterId,
CharacterName = offlineCharacterData.Name,
WorldName = offlineCharacterData.World,
Managed = false,
};
save = true;
_configuration.Characters.Add(character);
}
if (character.GatheredItems != offlineCharacterData.UnlockedGatheringItems)
{
character.GatheredItems = offlineCharacterData.UnlockedGatheringItems;
save = true;
}
foreach (var retainerData in offlineCharacterData.RetainerData)
{
var retainer = character.Retainers.SingleOrDefault(x => x.Name == retainerData.Name);
if (retainer == null)
{
retainer = new Configuration.RetainerConfiguration
{
Name = retainerData.Name,
Managed = false,
};
save = true;
character.Retainers.Add(retainer);
}
if (retainer.DisplayOrder != retainerData.DisplayOrder)
{
retainer.DisplayOrder = retainerData.DisplayOrder;
save = true;
}
if (retainer.Level != retainerData.Level)
{
retainer.Level = retainerData.Level;
save = true;
}
if (retainer.Job != retainerData.Job)
{
retainer.Job = retainerData.Job;
save = true;
}
if (retainer.LastVenture != retainerData.VentureID)
{
retainer.LastVenture = retainerData.VentureID;
save = true;
}
var additionalData =
_autoRetainerApi.GetAdditionalRetainerData(registeredCharacterId, retainerData.Name);
if (retainer.ItemLevel != additionalData.Ilvl)
{
retainer.ItemLevel = additionalData.Ilvl;
save = true;
}
if (retainer.Gathering != additionalData.Gathering)
{
retainer.Gathering = additionalData.Gathering;
save = true;
}
if (retainer.Perception != additionalData.Perception)
{
retainer.Perception = additionalData.Perception;
save = true;
}
}
}
if (save)
_pluginInterface.SavePluginConfig(_configuration);
}
private void ProcessCommand(string command, string arguments) private void ProcessCommand(string command, string arguments)
{ {
if (arguments == "sync") if (arguments == "sync")
@ -302,6 +169,5 @@ public sealed class AutoRetainerControlPlugin : IDalamudPlugin
_autoRetainerApi.Dispose(); _autoRetainerApi.Dispose();
ECommonsMain.Dispose(); ECommonsMain.Dispose();
} }
} }

View File

@ -0,0 +1,59 @@
using System;
using System.Linq;
using Dalamud.Logging;
namespace ARControl.GameData;
internal sealed class VentureResolver
{
private readonly GameCache _gameCache;
public VentureResolver(GameCache gameCache)
{
_gameCache = gameCache;
}
public (Venture?, VentureReward?) ResolveVenture(Configuration.CharacterConfiguration character,
Configuration.RetainerConfiguration retainer, Configuration.QueuedItem queuedItem)
{
var venture = _gameCache.Ventures
.Where(x => retainer.Level >= x.Level)
.FirstOrDefault(x => x.ItemId == queuedItem.ItemId && x.MatchesJob(retainer.Job));
if (venture == null)
{
PluginLog.Information($"No applicable venture found for itemId {queuedItem.ItemId}");
return (null, null);
}
var itemToGather = _gameCache.ItemsToGather.FirstOrDefault(x => x.ItemId == queuedItem.ItemId);
if (itemToGather != null && !character.GatheredItems.Contains(itemToGather.GatheredItemId))
{
PluginLog.Information($"Character hasn't gathered {venture.Name} yet");
return (null, null);
}
PluginLog.Information(
$"Found venture {venture.Name}, row = {venture.RowId}, checking if it is suitable");
VentureReward? reward = null;
if (venture.CategoryName is "MIN" or "BTN")
{
if (retainer.Gathering >= venture.RequiredGathering)
reward = venture.Rewards.Last(
x => retainer.Perception >= x.PerceptionMinerBotanist);
}
else if (venture.CategoryName == "FSH")
{
if (retainer.Gathering >= venture.RequiredGathering)
reward = venture.Rewards.Last(
x => retainer.Perception >= x.PerceptionFisher);
}
else
{
if (retainer.ItemLevel >= venture.ItemLevelCombat)
reward = venture.Rewards.Last(
x => retainer.ItemLevel >= x.ItemLevelCombat);
}
return (venture, reward);
}
}

View File

@ -187,7 +187,8 @@ internal sealed class ConfigWindow : Window
.OrderBy(x => x.LocalContentId) .OrderBy(x => x.LocalContentId)
.GroupBy(x => x.WorldName)) .GroupBy(x => x.WorldName))
{ {
ImGui.CollapsingHeader(world.Key, ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.Bullet); ImGui.CollapsingHeader(world.Key,
ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.Bullet);
foreach (var character in world) foreach (var character in world)
{ {
ImGui.PushID($"Char{character.LocalContentId}"); ImGui.PushID($"Char{character.LocalContentId}");
@ -286,7 +287,8 @@ internal sealed class ConfigWindow : Window
if (ImGuiComponents.IconButton($"SwitchCharacters{ch.Character.LocalContentId}", if (ImGuiComponents.IconButton($"SwitchCharacters{ch.Character.LocalContentId}",
FontAwesomeIcon.DoorOpen)) FontAwesomeIcon.DoorOpen))
{ {
_commandManager.ProcessCommand($"/ays relog {ch.Character.CharacterName}@{ch.Character.WorldName}"); _commandManager.ProcessCommand(
$"/ays relog {ch.Character.CharacterName}@{ch.Character.WorldName}");
} }
ImGui.EndDisabled(); ImGui.EndDisabled();
@ -329,6 +331,7 @@ internal sealed class ConfigWindow : Window
{ {
ImGui.Text(item.GatheredItem.Name); ImGui.Text(item.GatheredItem.Name);
} }
ImGui.PopStyleColor(); ImGui.PopStyleColor();
} }
} }