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

Commit

Permalink
fix: add territory conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Oct 30, 2023
1 parent 319753c commit de4ad60
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 25 deletions.
9 changes: 8 additions & 1 deletion Resources/HostileCastingArea.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,5 +444,12 @@
3809,
3812,
14433,
14548
14548,
19328,
3437,
19538,
35680,
35695,
35696,
35870
]
2 changes: 1 addition & 1 deletion Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ClickingCount": 28821,
"ClickingCount": 37671,
"SaidUsers": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ protected override ICondition Create(JObject jObject)
{
return new NamedCondition();
}
else if (FieldExists(nameof(TerritoryCondition.TerritoryConditionType), jObject))
{
return new TerritoryCondition();
}
else
{
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace RotationSolver.Basic.Configuration.Conditions;

internal class TerritoryCondition : DelayCondition
{
public TerritoryConditionType TerritoryConditionType = TerritoryConditionType.TerritoryContentType;

public int Param1 = 0;
public string Name;
public int Condition;

protected override bool IsTrueInside(ICustomRotation rotation)
{
bool result = TerritoryConditionType switch
{
TerritoryConditionType.TerritoryContentType => (int)DataCenter.TerritoryContentType == Param1,
TerritoryConditionType.DutyName => Name == DataCenter.ContentFinderName,
TerritoryConditionType.TeritoryName => Name == DataCenter.TerritoryName,
_ => false,
};
return Condition > 0 ? !result : result;
}
}

internal enum TerritoryConditionType : byte
{
TerritoryContentType,
TeritoryName,
DutyName,
}
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public enum PluginConfigBool : byte

public enum PluginConfigFloat : byte
{
[Default(8f, 0f, 600f)] AutoOffAfterCombatTime,
[Default(30f, 0f, 600f)] AutoOffAfterCombatTime,
[Default(3f, 0f, 8f)] DrawingHeight,
[Default(0.2f, 0.005f, 0.05f)] SampleLength,
[Default(0.1f)] KeyBoardNoiseTimeMin,
Expand Down
14 changes: 12 additions & 2 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ECommons.GameHelpers;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.Fate;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic.Configuration;
using RotationSolver.Basic.Configuration.Conditions;
using Action = Lumina.Excel.GeneratedSheets.Action;
Expand Down Expand Up @@ -72,8 +73,17 @@ internal static bool HasApplyStatus(uint id, StatusID[] ids)
}
return false;
}
public static bool IsInHighEndDuty { get; set; } = false;
public static TerritoryContentType TerritoryContentType { get; set; } = TerritoryContentType.None;

public static TerritoryType Territory { get; set; }

public static string TerritoryName => Territory?.Name?.RawString ?? "Territory";

public static ContentFinderCondition ContentFinder => Territory?.ContentFinderCondition?.Value;

public static string ContentFinderName => ContentFinder?.Name?.RawString ?? "Duty";

public static bool IsInHighEndDuty => ContentFinder?.HighEndDuty ?? false;
public static TerritoryContentType TerritoryContentType => (TerritoryContentType)(ContentFinder?.ContentType?.Value?.RowId ?? 0);

public static AutoStatus AutoStatus { get; private set; } = AutoStatus.None;
public static bool SetAutoStatus(AutoStatus status, bool keep)
Expand Down
1 change: 1 addition & 0 deletions RotationSolver.Basic/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static bool IsBoss(this BattleChara obj)
{
if (obj == null) return false;
if (obj.IsDummy() && !Service.Config.GetValue(Configuration.PluginConfigBool.ShowTargetTimeToKill)) return true;

return obj.GetTimeToKill(true) >= Service.Config.GetValue(Configuration.PluginConfigFloat.BossTimeToKill)
|| !(obj.GetObjectNPC()?.IsTargetLine ?? true);
}
Expand Down
8 changes: 8 additions & 0 deletions RotationSolver/Localization/EnumTranslations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ internal static class EnumTranslations
_ => string.Empty,
};

internal static string ToName(this TerritoryConditionType type) => type switch
{
TerritoryConditionType.TerritoryContentType => LocalizationManager.RightLang.TerritoryConditionType_TerritoryContentType,
TerritoryConditionType.TeritoryName => LocalizationManager.RightLang.TerritoryConditionType_TeritoryName,
TerritoryConditionType.DutyName => LocalizationManager.RightLang.TerritoryConditionType_DutyName,
_ => string.Empty,
};

internal static string ToName(this ActionConditionType type) => type switch
{
ActionConditionType.Elapsed => LocalizationManager.RightLang.ActionConditionType_Elapsed,
Expand Down
11 changes: 11 additions & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ internal class Strings
public string ActionSequencer_TargetCondition { get; set; } = "Target Condition";
public string ActionSequencer_RotationCondition { get; set; } = "Rotation Condition";
public string ActionSequencer_NamedCondition { get; set; } = "Named Condition";
public string ActionSequencer_TerritoryCondition { get; set; } = "Territory Condition";
public string ActionSequencer_TraitCondition { get; set; } = "Trait Condition";
public string ActionSequencer_ActionTarget { get; set; } = "{0}'s target";
public string ActionSequencer_Target { get; set; } = "Target";
Expand Down Expand Up @@ -390,6 +391,12 @@ internal class Strings

#endregion

#region TerritoryConditionType
public string TerritoryConditionType_TerritoryContentType { get; set; } = "Territory Content Type";
public string TerritoryConditionType_TeritoryName { get; set; } = "Teritory Name";
public string TerritoryConditionType_DutyName { get; set; } = "Duty Name";
#endregion

#region DescType
public string DescType_BurstActions { get; set; } = "Burst Actions";
public string DescType_MoveForwardGCD { get; set; } = "Move Forward GCD";
Expand Down Expand Up @@ -798,4 +805,8 @@ internal class Strings
public string ConfigWindow_Condition_NoItemsWarning { get; set; } = "There are no items!";

public string ConfigWindow_Condition_ConditionName { get; set; } = "Condition Name";

public string ConfigWindow_Condition_TeritoryName { get; set; } = "Teritory Name";

public string ConfigWindow_Condition_DutyName { get; set; } = "Duty Name";
}
60 changes: 59 additions & 1 deletion RotationSolver/UI/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Utility;
using ECommons.DalamudServices;
using ECommons.ImGuiMethods;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic.Configuration.Conditions;
Expand Down Expand Up @@ -281,12 +282,15 @@ private static void DrawAfter(this ICondition condition, ICustomRotation rotatio

case NamedCondition namedCondition:
namedCondition.DrawAfter(rotation);
break;

case TerritoryCondition territoryCondition:
territoryCondition.DrawAfter(rotation);
break;
}
}

private static void DrawAfter(this NamedCondition namedCondition, ICustomRotation rotation)
private static void DrawAfter(this NamedCondition namedCondition, ICustomRotation _)
{
SearchItems($"##Comparation{namedCondition.GetHashCode()}", namedCondition.ConditionName, ref searchTxt,
DataCenter.RightSet.NamedConditions.Select(p => p.Name).ToArray(), i => i.ToString(), i =>
Expand Down Expand Up @@ -579,6 +583,7 @@ void AddButton()
AddOneCondition<TargetCondition>(LocalizationManager.RightLang.ActionSequencer_TargetCondition);
AddOneCondition<RotationCondition>(LocalizationManager.RightLang.ActionSequencer_RotationCondition);
AddOneCondition<NamedCondition>(LocalizationManager.RightLang.ActionSequencer_NamedCondition);
AddOneCondition<TerritoryCondition>(LocalizationManager.RightLang.ActionSequencer_TerritoryCondition);
}

void AddOneCondition<T>(string name) where T : ICondition
Expand Down Expand Up @@ -914,5 +919,58 @@ void DrawStatusIcon()
break;
}
}

private static string[] _territoryNames = null;
public static string[] TerritoryNames => _territoryNames ??= Service.GetSheet<TerritoryType>()?
.Select(t => t?.Name?.RawString ?? string.Empty).Where(s => !string.IsNullOrEmpty(s)).ToArray();

private static string[] _dutyNames = null;

public static string[] DutyNames => _dutyNames ??= Service.GetSheet<ContentFinderCondition>()?
.Select(t => t?.Name?.RawString ?? string.Empty).Where(s => !string.IsNullOrEmpty(s)).Reverse().ToArray();

private static void DrawAfter(this TerritoryCondition territoryCondition, ICustomRotation rotation)
{
DrawByteEnum($"##Category{territoryCondition.GetHashCode()}", ref territoryCondition.TerritoryConditionType, EnumTranslations.ToName);

ImGui.SameLine();

ImGuiHelper.SelectableCombo($"##IsNot{territoryCondition.GetHashCode()}", new string[]
{
LocalizationManager.RightLang.ActionSequencer_Is,
LocalizationManager.RightLang.ActionSequencer_Isnot,
}, ref territoryCondition.Condition);

switch (territoryCondition.TerritoryConditionType)
{
case TerritoryConditionType.TerritoryContentType:
ImGui.SameLine();

var type = (TerritoryContentType)territoryCondition.Param1;
DrawByteEnum($"##TerritoryContentType{territoryCondition.GetHashCode()}", ref type, i => i.ToString());
territoryCondition.Param1 = (int)type;
break;

case TerritoryConditionType.TeritoryName:
ImGui.SameLine();

SearchItems($"##TerritoryName{territoryCondition.GetHashCode()}", territoryCondition.Name, ref searchTxt,
TerritoryNames, i => i.ToString(), i =>
{
territoryCondition.Name = i;
}, LocalizationManager.RightLang.ConfigWindow_Condition_TeritoryName);
break;

case TerritoryConditionType.DutyName:
ImGui.SameLine();

SearchItems($"##DutyName{territoryCondition.GetHashCode()}", territoryCondition.Name, ref searchTxt,
DutyNames, i => i.ToString(), i =>
{
territoryCondition.Name = i;
}, LocalizationManager.RightLang.ConfigWindow_Condition_DutyName);
break;
}
}
#endregion
}
10 changes: 4 additions & 6 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,15 +2026,13 @@ private static void DrawListTerritories()
using var color = ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);

const int iconSize = 32;
var territory = Service.GetSheet<TerritoryType>().GetRow(territoryId);
if (territory == null) return;
var contentFinder = territory?.ContentFinderCondition?.Value;
var territoryName = territory?.PlaceName?.Value?.Name ?? string.Empty;
var contentFinder = DataCenter.ContentFinder;
var territoryName = DataCenter.TerritoryName;
if (contentFinder != null && !string.IsNullOrEmpty(contentFinder.Name))
{
territoryName += $" ({contentFinder.Name})";
territoryName += $" ({DataCenter.ContentFinderName})";
}
var icon = territory?.ContentFinderCondition?.Value?.ContentType?.Value?.Icon ?? 23;
var icon = DataCenter.ContentFinder?.ContentType?.Value?.Icon ?? 23;
if (icon == 0) icon = 23;
var getIcon = IconSet.GetTexture(icon, out var texture);
ImGuiHelper.DrawItemMiddle(() =>
Expand Down
19 changes: 6 additions & 13 deletions RotationSolver/Updaters/SocialUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ internal class SocialUpdater
private static readonly HashSet<string> saidAuthors = new();

static bool _canSaying = false;
public static TerritoryType[] HighEndDuties { get; private set; } = Array.Empty<TerritoryType>();

public static string GetDutyName(TerritoryType territory)
{
return territory.ContentFinderCondition?.Value?.Name?.RawString ?? "High-end Duty";
return territory.ContentFinderCondition?.Value?.Name?.RawString;
}

static bool CanSocial
Expand All @@ -64,10 +63,6 @@ internal static void Enable()
Svc.DutyState.DutyCompleted += DutyState_DutyCompleted;
Svc.ClientState.TerritoryChanged += ClientState_TerritoryChanged;
ClientState_TerritoryChanged(Svc.ClientState.TerritoryType);

HighEndDuties = Service.GetSheet<TerritoryType>()
.Where(t => t?.ContentFinderCondition?.Value?.HighEndDuty ?? false)
.ToArray();
}

static async void DutyState_DutyCompleted(object sender, ushort e)
Expand All @@ -87,9 +82,7 @@ static void ClientState_TerritoryChanged(ushort id)
_canSaying = territory?.ContentFinderCondition?.Value?.RowId != 0;

InPvp = territory?.IsPvpZone ?? false;

DataCenter.TerritoryContentType = (TerritoryContentType)(territory?.ContentFinderCondition?.Value?.ContentType?.Value?.RowId ?? 0);
DataCenter.IsInHighEndDuty = HighEndDuties.Any(t => t.RowId == territory.RowId);
DataCenter.Territory = territory;

try
{
Expand All @@ -106,10 +99,10 @@ static void DutyState_DutyStarted(object sender, ushort e)
if (!Player.Available) return;
if (!Player.Object.IsJobCategory(JobRole.Tank) && !Player.Object.IsJobCategory(JobRole.Healer)) return;

var territory = Service.GetSheet<TerritoryType>().GetRow(e);
if (HighEndDuties.Any(t => t.RowId == territory.RowId))
if (DataCenter.IsInHighEndDuty)
{
string.Format(LocalizationManager.RightLang.HighEndWarning, GetDutyName(territory)).ShowWarning();
string.Format(LocalizationManager.RightLang.HighEndWarning,
DataCenter.ContentFinderName).ShowWarning();
}
}

Expand Down Expand Up @@ -186,7 +179,7 @@ private static async void SayHelloToUsers()
#if DEBUG
#else
Svc.Targets.Target = entity.player;
Chat.Instance.SendMessage($"/{_macroToAuthor[new Random().Next(_macroToAuthor.Count)]} <t>");
ECommons.Automation.Chat.Instance.SendMessage($"/{_macroToAuthor[new Random().Next(_macroToAuthor.Count)]} <t>");
#endif
Svc.Chat.Print(new Dalamud.Game.Text.XivChatEntry()
{
Expand Down

0 comments on commit de4ad60

Please sign in to comment.