From 033566a3a060107f7594566e99f5c69e5e31c08c Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Tue, 25 Jun 2024 15:51:17 +0200 Subject: [PATCH] Dynamically determine max sub rank --- Mariner/MarinerPlugin.cs | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/Mariner/MarinerPlugin.cs b/Mariner/MarinerPlugin.cs index 6785015..71e05cc 100644 --- a/Mariner/MarinerPlugin.cs +++ b/Mariner/MarinerPlugin.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.CodeAnalysis; +using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using AutoRetainerAPI; using AutoRetainerAPI.Configuration; @@ -6,6 +7,7 @@ using Dalamud.Game.Command; using Dalamud.Plugin; using Dalamud.Plugin.Services; using ECommons; +using Lumina.Excel.GeneratedSheets; namespace Mariner; @@ -18,14 +20,24 @@ public sealed class MarinerPlugin : IDalamudPlugin private readonly IPluginLog _pluginLog; private readonly AutoRetainerApi _autoRetainerApi; + private readonly int _maxRank; + public MarinerPlugin(DalamudPluginInterface pluginInterface, IClientState clientState, IFramework framework, - ICommandManager commandManager, IChatGui chatGui, IPluginLog pluginLog) + ICommandManager commandManager, IChatGui chatGui, IPluginLog pluginLog, IDataManager dataManager) { + ArgumentNullException.ThrowIfNull(dataManager); + _clientState = clientState; _framework = framework; _commandManager = commandManager; _pluginLog = pluginLog; + _maxRank = dataManager.GetExcelSheet()! + .Where(x => x.RowId > 0 && x.Capacity > 0) + .Select(x => (int)x.RowId) + .Max(); + _pluginLog.Information($"Max submersible rank: {_maxRank}"); + ECommonsMain.Init(pluginInterface, this); _autoRetainerApi = new AutoRetainerApi(); @@ -66,8 +78,8 @@ public sealed class MarinerPlugin : IDalamudPlugin return "Not updating subs, not all subs are enabled"; if (offlineCharacterData.AdditionalSubmarineData.All(x => - x.Value.Level >= 115 && x.Value.VesselBehavior == VesselBehavior.Use_plan)) - return "Not updating subs, all subs are level 115+ and use plans"; + x.Value.Level >= _maxRank && x.Value.VesselBehavior == VesselBehavior.Use_plan)) + return $"Not updating subs, all subs are level {_maxRank}+ and use plans"; var subs = offlineCharacterData.AdditionalSubmarineData.Values .OrderBy(x => x.Level) @@ -76,13 +88,17 @@ public sealed class MarinerPlugin : IDalamudPlugin for (int i = 0; i < subs.Count; ++i) { var sub = subs[i]; - sub.VesselBehavior = sub.Level switch + if (sub.Level >= _maxRank) + sub.VesselBehavior = VesselBehavior.Use_plan; + else { - < 101 => VesselBehavior.Unlock, - >= 115 => VesselBehavior.Use_plan, - _ when i == 0 => VesselBehavior.Unlock, - _ => VesselBehavior.Use_plan - }; + sub.VesselBehavior = sub.Level switch + { + < 101 => VesselBehavior.Unlock, + _ when i == 0 => VesselBehavior.Unlock, + _ => VesselBehavior.Use_plan + }; + } } _autoRetainerApi.WriteOfflineCharacterData(offlineCharacterData);