Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: make No hostile as a dictionary about the territory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 30, 2023
1 parent 81147c1 commit 5d28272
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 39 deletions.
9 changes: 4 additions & 5 deletions RotationSolver.Basic/Configuration/OtherConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Dalamud.Logging;
using System.Xml.Linq;

namespace RotationSolver.Basic.Configuration;

public class OtherConfiguration
{
public static string[] NoHostileNames = Array.Empty<string>();
public static Dictionary<uint, string[]> NoHostileNames = new Dictionary<uint, string[]>();

public static SortedSet<uint> DangerousStatus = new SortedSet<uint>()
{
Expand Down Expand Up @@ -76,10 +77,8 @@ private static void SavePath<T>(T value, string path)
}

private static void InitOne<T>(ref T value, string name)
=> InitOnePath(ref value, GetFilePath(name));

private static void InitOnePath<T>(ref T value, string path)
{
var path = GetFilePath(name);
if (File.Exists(path))
{
try
Expand All @@ -88,7 +87,7 @@ private static void InitOnePath<T>(ref T value, string path)
}
catch (Exception ex)
{
PluginLog.Warning(ex, "Failed to load Dangerous Status List.");
PluginLog.Warning(ex, $"Failed to load {name}.");
}
}
else SavePath(value, path);
Expand Down
9 changes: 5 additions & 4 deletions RotationSolver/ActionSequencer/TargetCondition.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using RotationSolver.Localization;
using RotationSolver.TextureItems;
using RotationSolver.UI;

namespace RotationSolver.ActionSequencer;

internal class TargetCondition : ICondition
{
private static BaseStatus[] _allStatus = null;
private static BaseStatus[] AllStatus
private static StatusTexture[] _allStatus = null;
private static StatusTexture[] AllStatus
{
get
{
if (_allStatus == null)
{
_allStatus = Enum.GetValues<StatusID>().Select(id => new BaseStatus(id)).ToArray();
_allStatus = Enum.GetValues<StatusID>().Select(id => new StatusTexture(id)).ToArray();
}
return _allStatus;
}
Expand All @@ -23,7 +24,7 @@ private static BaseStatus[] AllStatus

public bool Condition;
public bool FromSelf;
private BaseStatus _status { get; set; }
private StatusTexture _status { get; set; }
public StatusID Status { get; set; }
public bool IsTarget;
public TargetConditionType TargetConditionType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
using Lumina.Excel.GeneratedSheets;

namespace RotationSolver.ActionSequencer;
namespace RotationSolver.TextureItems;

internal class BaseStatus : ITexture
internal class StatusTexture : ITexture
{
public Status _status;
readonly Status _status;
public uint IconID => _status.Icon;
public StatusID ID => (StatusID)_status.RowId;
public string Name => $"{_status.Name} ({_status.RowId})";

public string Description => string.Empty;

public bool IsEnabled { get; set; }
public bool IsEnabled { get; set; } = true;

public BaseStatus(StatusID id)
public StatusTexture(StatusID id)
: this((uint)id)
{
}

public BaseStatus(uint id)
public StatusTexture(uint id)
: this(Service.GetSheet<Status>().GetRow(id))
{
}

public BaseStatus(Status status)
public StatusTexture(Status status)
{
_status = status;
}
Expand Down
24 changes: 24 additions & 0 deletions RotationSolver/TextureItems/TerritoryTypeTexture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Lumina.Excel.GeneratedSheets;

namespace RotationSolver.TextureItems;

internal class TerritoryTypeTexture : ITexture
{
readonly TerritoryType _territory;
public uint IconID => _territory?.ContentFinderCondition?.Value?.ContentType?.Value?.Icon ?? 0;
public uint ID => _territory?.RowId ?? 0;
public string Name => $"{_territory.PlaceName?.Value?.Name} ({_territory.RowId})";

public string Description => string.Empty;
public bool IsEnabled { get; set; } = true;

public TerritoryTypeTexture(uint id)
: this(Service.GetSheet<TerritoryType>().GetRow(id))
{
}

public TerritoryTypeTexture(TerritoryType status)
{
_territory = status;
}
}
8 changes: 4 additions & 4 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ internal static void SetNextWidthWithName(string name)
ImGui.SetNextItemWidth(ImGui.CalcTextSize(name).X + 30);
}

internal static void SearchCombo<T>(string popId, string name, ref string searchTxt, T[] actions, Action<T> selectAction) where T : ITexture
internal static void SearchCombo<T>(string popId, string name, ref string searchTxt, T[] data, Action<T> selectAction) where T : ITexture
{
if (ImGui.BeginCombo(popId, name, ImGuiComboFlags.HeightLargest))
{
SearchItems(ref searchTxt, actions, selectAction);
SearchItems(ref searchTxt, data, selectAction);
ImGui.EndCombo();
}
}

internal static void SearchItems<T>(ref string searchTxt, IEnumerable<T> actions, Action<T> selectAction) where T : ITexture
internal static void SearchItems<T>(ref string searchTxt, IEnumerable<T> data, Action<T> selectAction) where T : ITexture
{
SearchItems(ref searchTxt, actions, i => i.Name, selectAction, i => ImGui.Image(i.GetTexture().ImGuiHandle, new Vector2(24, 24)));
SearchItems(ref searchTxt, data, i => i.Name, selectAction, i => ImGui.Image(i.GetTexture().ImGuiHandle, new Vector2(24, 24)));
}

internal static void SearchItemsReflection<T>(string popId, string name, ref string searchTxt, T[] actions, Action<T> selectAction) where T : MemberInfo
Expand Down
78 changes: 60 additions & 18 deletions RotationSolver/UI/RotationConfigWindow_List.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
using Dalamud.Utility;
using Lumina.Data.Parsing;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.ActionSequencer;
using RotationSolver.Basic.Configuration;
using RotationSolver.Basic.Data;
using RotationSolver.Localization;
using RotationSolver.TextureItems;
using RotationSolver.Updaters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace RotationSolver.UI;

internal partial class RotationConfigWindow
{
private static BaseStatus[] _allDispelStatus = null;
public static BaseStatus[] AllDispelStatus
private static uint _territoryId = 0;
private static TerritoryTypeTexture[] _allTerritories = null;
public static TerritoryTypeTexture[] AllTerritories
{
get
{
if (_allTerritories == null)
{
_allTerritories = Service.GetSheet<TerritoryType>()
.Where(t => t!= null
&& t.ContentFinderCondition?.Value?.ContentType?.Value?.RowId != 0)
.OrderBy(t => t.ContentFinderCondition?.Value?.ContentType?.Value?.RowId)
.Select(t => new TerritoryTypeTexture(t))
.ToArray();
}
return _allTerritories;
}
}

private static StatusTexture[] _allDispelStatus = null;
public static StatusTexture[] AllDispelStatus
{
get
{
if (_allDispelStatus == null)
{
_allDispelStatus = Service.GetSheet<Status>()
.Where(s => s.CanDispel)
.Select(s => new BaseStatus(s))
.Select(s => new StatusTexture(s))
.ToArray();
}
return _allDispelStatus;
}
}

private static BaseStatus[] _allInvStatus = null;
public static BaseStatus[] AllInvStatus
private static StatusTexture[] _allInvStatus = null;
public static StatusTexture[] AllInvStatus
{
get
{
Expand All @@ -41,7 +56,7 @@ public static BaseStatus[] AllInvStatus
_allInvStatus = Service.GetSheet<Status>()
.Where(s => !s.CanDispel && !s.LockMovement && !s.IsPermanent && !s.IsGaze && !s.IsFcBuff && s.HitEffect.Row == 16 && s.ClassJobCategory.Row == 1 && s.StatusCategory == 1
&& !string.IsNullOrEmpty(s.Name.ToString()) && s.Icon != 0)
.Select(s => new BaseStatus(s))
.Select(s => new StatusTexture(s))
.ToArray();
}
return _allInvStatus;
Expand Down Expand Up @@ -69,9 +84,32 @@ private void DrawListTab()

DrawParamTabItem(LocalizationManager.RightLang.ConfigWindow_List_NoHostile, DrawParamNoHostile, () =>
{
ImGui.SetNextItemWidth(200);

if (ImGui.BeginCombo("##AddNoHostileNames",
Service.GetSheet<TerritoryType>().GetRow(_territoryId)?.PlaceName?.Value?.Name.ToString() ?? "Everywhere", ImGuiComboFlags.HeightLargest))
{
if (ImGui.Selectable("Everywhere"))
{
_territoryId = 0;
}

ImGuiHelper.SearchItems(ref searchText, AllTerritories, s =>
{
_territoryId = s.ID;
});

ImGui.EndCombo();
}

ImGui.SameLine();
ImGuiHelper.Spacing();

if (ImGui.Button(LocalizationManager.RightLang.ConfigWindow_Param_AddOne))
{
OtherConfiguration.NoHostileNames = OtherConfiguration.NoHostileNames.Append(string.Empty).ToArray();
if(!OtherConfiguration.NoHostileNames.TryGetValue(_territoryId, out var hostileNames))
hostileNames = Array.Empty<string>();
OtherConfiguration.NoHostileNames[_territoryId] = hostileNames.Append(string.Empty).ToArray();
}
ImGui.SameLine();
ImGuiHelper.Spacing();
Expand Down Expand Up @@ -317,10 +355,14 @@ private void DrawRotationDevTab()
private void DrawParamNoHostile()
{
int removeIndex = -1;
for (int i = 0; i < OtherConfiguration.NoHostileNames.Length; i++)

if (!OtherConfiguration.NoHostileNames.TryGetValue(_territoryId, out var names)) names = Array.Empty<string>();

for (int i = 0; i < names.Length; i++)
{
if (ImGui.InputText($"##NoHostileNames{i}", ref OtherConfiguration.NoHostileNames[i], 1024))
if (ImGui.InputText($"##NoHostileNames{i}", ref names[i], 1024))
{
OtherConfiguration.NoHostileNames[_territoryId] = names;
OtherConfiguration.SaveNoHostileNames();
}
ImGui.SameLine();
Expand All @@ -333,9 +375,9 @@ private void DrawParamNoHostile()
}
if (removeIndex > -1)
{
var list = OtherConfiguration.NoHostileNames.ToList();
var list = names.ToList();
list.RemoveAt(removeIndex);
OtherConfiguration.NoHostileNames = list.ToArray();
OtherConfiguration.NoHostileNames[_territoryId] = list.ToArray();
OtherConfiguration.SaveNoHostileNames();
}
}
Expand Down
10 changes: 9 additions & 1 deletion RotationSolver/Updaters/TargetUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,15 @@ private static IEnumerable<BattleChara> GetHostileTargets(IEnumerable<BattleChar

allAttackableTargets = allAttackableTargets.Where(b =>
{
if (OtherConfiguration.NoHostileNames.Any(n => new Regex(n).Match(b.Name.ToString()).Success)) return false;
IEnumerable<string> names = Array.Empty<string>();
if(OtherConfiguration.NoHostileNames.TryGetValue(Service.ClientState.TerritoryType, out var ns1))
names = names.Union(ns1);

if (OtherConfiguration.NoHostileNames.TryGetValue(0, out var ns2))
names = names.Union(ns2);

if (names.Any(n => new Regex(n).Match(b.Name.ToString()).Success)) return false;

return fateId > 0 ? b.FateId() == fateId : true;
});

Expand Down

0 comments on commit 5d28272

Please sign in to comment.