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

Commit

Permalink
fix: add beneficial positions preset.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 15, 2023
1 parent d217cf5 commit 930a42c
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 109 deletions.
5 changes: 5 additions & 0 deletions Resources/BeneficialPositions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"0": [],
"641": [],
"837": []
}
24 changes: 21 additions & 3 deletions RotationSolver.Basic/Actions/BaseAction_Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,29 @@ private bool TargetAreaFriend(float range, bool mustUse, PlayerCharacter player)
{
if (!Service.Config.GetValue(PluginConfigBool.UseGroundBeneficialAbility)) return false;

if (Service.Config.GetValue(PluginConfigBool.BeneficialAreaOnTarget) && Svc.Targets.Target != null)
switch (Service.Config.GetValue(PluginConfigInt.BeneficialAreaStrategy))
{
Position = Svc.Targets.Target.Position;
case 0: // Find from list
if (OtherConfiguration.BeneficialPositions.TryGetValue(Svc.ClientState.TerritoryType, out var pts))
{
var closest = pts.MinBy(p => Vector3.Distance(player.Position, p));
if(Vector3.Distance(player.Position, closest) < player.HitboxRadius + EffectRange)
{
Position = closest;
return true;
}
}
break;
case 1: // Target
if(Svc.Targets.Target != null && Svc.Targets.Target.DistanceToPlayer() < range)
{
Position = Svc.Targets.Target.Position;
return true;
}
break;
}
else if (Svc.Targets.Target is BattleChara b && b.DistanceToPlayer() < range &&

if (Svc.Targets.Target is BattleChara b && b.DistanceToPlayer() < range &&
b.IsBoss() && b.HasPositional() && b.HitboxRadius <= 8)
{
Position = b.Position;
Expand Down
13 changes: 11 additions & 2 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class PluginConfig : IPluginConfiguration
{
public static PluginConfig Create()
{
PluginLog.Warning("You created a new configuration!");
var result = new PluginConfig();
result.SetValue(Job.WAR, JobConfigInt.HostileType, 0);
result.SetValue(Job.DRK, JobConfigInt.HostileType, 0);
Expand Down Expand Up @@ -132,7 +133,11 @@ public void Save()
#if DEBUG
PluginLog.Information("Saved configurations.");
#endif
Svc.PluginInterface.SavePluginConfig(this);
File.WriteAllText(Svc.PluginInterface.ConfigFile.FullName,
JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.None,
}));
}
}

Expand Down Expand Up @@ -177,6 +182,7 @@ [Serializable] public class GlobalConfig
{
{ PluginConfigVector4.TeachingModeColor, new (0f, 1f, 0.8f, 1f)},
{ PluginConfigVector4.MovingTargetColor, new (0f, 1f, 0.8f, 0.6f)},
{ PluginConfigVector4.BeneficialPositionColor, new (0.5f, 0.9f, 0.1f, 0.7f)},
{ PluginConfigVector4.TargetColor, new (1f, 0.2f, 0f, 0.8f)},
{ PluginConfigVector4.SubTargetColor, new (1f, 0.9f, 0f, 0.8f)},
{ PluginConfigVector4.ControlWindowLockBg, new (0, 0, 0, 0.6f)},
Expand Down Expand Up @@ -210,6 +216,7 @@ public enum PluginConfigInt : byte
[Default(3)] KeyBoardNoiseMax,

[Default(0)] TargetingIndex,
[Default(0)] BeneficialAreaStrategy,

[Obsolete]
[Default(15, 1, 30)] CooldownActionOneLine,
Expand Down Expand Up @@ -272,7 +279,6 @@ public enum PluginConfigBool : byte
[Default(false)] EsunaAll,
[Default(false)] OnlyAttackInView,
[Default(false)] OnlyHotOnTanks,
[Default(false)] BeneficialAreaOnTarget,

[Default(false)] InDebug,
[Default(true)] AutoUpdateLibs,
Expand Down Expand Up @@ -320,6 +326,8 @@ public enum PluginConfigBool : byte
[Default(false)] AutoOpenChest,
[Default(true)] AutoCloseChestWindow,
[Default(true)] AutoOffAfterCombat,

[Default(true)] ShowBeneficialPositions,
}

public enum PluginConfigFloat : byte
Expand Down Expand Up @@ -401,6 +409,7 @@ public enum PluginConfigVector4 : byte
MovingTargetColor,
TargetColor,
SubTargetColor,
BeneficialPositionColor,
ControlWindowLockBg,
ControlWindowUnlockBg,
InfoWindowBg,
Expand Down
8 changes: 8 additions & 0 deletions RotationSolver.Basic/Configuration/OtherConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class OtherConfiguration
public static SortedList<uint, float> AnimationLockTime = new();

public static Dictionary<uint, string[]> NoHostileNames = new();
public static Dictionary<uint, Vector3[]> BeneficialPositions = new();

public static HashSet<uint> DangerousStatus = new();

Expand All @@ -37,6 +38,7 @@ public static void Init()

Task.Run(() => InitOne(ref HostileCastingTank, nameof(HostileCastingTank)));

Task.Run(() => InitOne(ref BeneficialPositions, nameof(BeneficialPositions)));
}

public static void Save()
Expand All @@ -47,6 +49,12 @@ public static void Save()
SaveAnimationLockTime();
SaveHostileCastingArea();
SaveHostileCastingTank();
SaveBeneficialPositions();
}

public static void SaveBeneficialPositions()
{
Task.Run(() => Save(BeneficialPositions, nameof(BeneficialPositions)));
}

public static void SaveHostileCastingArea()
Expand Down
4 changes: 3 additions & 1 deletion RotationSolver/Localization/ConfigTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal static class ConfigTranslation
PluginConfigBool.UseStopCasting => LocalizationManager.RightLang.ConfigWindow_Param_UseStopCasting,

// UI
PluginConfigBool.DrawIconAnimation => LocalizationManager.RightLang.ConfigWindow_UI_DrawIconAnimation,
PluginConfigBool.UseOverlayWindow => LocalizationManager.RightLang.ConfigWindow_Param_UseOverlayWindow,
PluginConfigBool.TeachingMode => LocalizationManager.RightLang.ConfigWindow_Param_TeachingMode,
PluginConfigBool.ShowMoveTarget => LocalizationManager.RightLang.ConfigWindow_Param_ShowMoveTarget,
Expand All @@ -61,6 +62,7 @@ internal static class ConfigTranslation
PluginConfigBool.UseOriginalCooldown => LocalizationManager.RightLang.ConfigWindow_Control_UseOriginalCooldown,
PluginConfigBool.ShowControlWindow => LocalizationManager.RightLang.ConfigWindow_Control_ShowControlWindow,
PluginConfigBool.IsControlWindowLock => LocalizationManager.RightLang.ConfigWindow_Control_IsInfoWindowNoMove,
PluginConfigBool.ShowBeneficialPositions => LocalizationManager.RightLang.ConfigWindow_UI_ShowBeneficialPosition,

// auto
PluginConfigBool.UseAOEAction => LocalizationManager.RightLang.ConfigWindow_Param_UseAOEAction,
Expand All @@ -86,7 +88,6 @@ internal static class ConfigTranslation
PluginConfigBool.EsunaAll => LocalizationManager.RightLang.ConfigWindow_Param_EsunaAll,
PluginConfigBool.HealOutOfCombat => LocalizationManager.RightLang.ConfigWindow_Param_HealOutOfCombat,
PluginConfigBool.OnlyHotOnTanks => LocalizationManager.RightLang.ConfigWindow_Param_OnlyHotOnTanks,
PluginConfigBool.BeneficialAreaOnTarget => LocalizationManager.RightLang.ConfigWindow_Param_BeneficialAreaOnTarget,
PluginConfigBool.RecordCastingArea => "Record AOE actions",
// target
PluginConfigBool.AddEnemyListToHostile => LocalizationManager.RightLang.ConfigWindow_Param_AddEnemyListToHostile,
Expand Down Expand Up @@ -180,6 +181,7 @@ internal static class ConfigTranslation
PluginConfigVector4.InfoWindowBg => LocalizationManager.RightLang.ConfigWindow_Control_InfoWindowBg,
PluginConfigVector4.ControlWindowLockBg => LocalizationManager.RightLang.ConfigWindow_Control_LockBackgroundColor,
PluginConfigVector4.ControlWindowUnlockBg => LocalizationManager.RightLang.ConfigWindow_Control_UnlockBackgroundColor,
PluginConfigVector4.BeneficialPositionColor => LocalizationManager.RightLang.ConfigWindow_UI_BeneficialPositionColor,
_ => string.Empty,
};

Expand Down
13 changes: 8 additions & 5 deletions RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
"ConfigWindow_Param_InterruptibleMoreCheck": "Interrupt the action with action type check.",
"ConfigWindow_Param_HealOutOfCombat": "Heal party members outside of combat.",
"ConfigWindow_Param_OnlyHotOnTanks": "Use single target healing over time actions only on tanks",
"ConfigWindow_Param_BeneficialAreaOnTarget": "Use Beneficial Area abilities on target.",
"ConfigWindow_Param_BeneficialAreaOnLocations": "On Listed Position",
"ConfigWindow_Param_BeneficialAreaOnTarget": "On target",
"ConfigWindow_Param_BeneficialAreaOnCalculated": "On the calculated Position",
"ConfigWindow_Param_HealthDifference": "HP%% for standard deviation for using AOE heal.",
"ConfigWindow_Param_HealthAreaAbility": "HP%% for AOE healing OGCDs",
"ConfigWindow_Param_HealthAreaSpell": "HP%% for AOE healing GCDs",
Expand Down Expand Up @@ -158,7 +160,7 @@
"ConfigWindow_Param_MoveAreaActionFarthestDesc": "Move to the furthest position from character's face direction.",
"ConfigWindow_Param_HostileDesc": "You can set the logic of hostile target selection to allow flexibility in switching the logic of selecting hostile in battle.",
"ConfigWindow_Param_HostileCondition": "Hostile target selection condition",
"ConfigWindow_Control_OnlyShowWithHostileOrInDuty": "Only shown if there are enemies in or in duty",
"ConfigWindow_Control_OnlyShowWithHostileOrInDuty": "Only show these windows if there are enemies in or in duty",
"ConfigWindow_Control_ShowNextActionWindow": "Show Next Action Window",
"ConfigWindow_Control_ShowControlWindow": "Show Control Window",
"ConfigWindow_Control_ShowCooldownWindow": "Show Cooldown Window",
Expand Down Expand Up @@ -433,8 +435,6 @@
"ConfigWindow_List_Remove": "Remove",
"ConfigWindow_List_ActionNameOrId": "Action name or id",
"ConfigWindow_List_AddAction": "Add Action",
"ConfigWindow_List_TerritoryEverywhere": "Everywhere",
"ConfigWindow_List_AddTerritory": "Territory name or id",
"ConfigWindow_List_BeneficialLocations": "Beneficial locations",
"ConfigWindow_List_NoHostilesName": "The name of object that you don't want to attack",
"ConfigWindow_Basic_AutoSwitch": "Auto Switch",
Expand All @@ -450,5 +450,8 @@
"ConfigWindow_Auto_ActionCondition": "Action Condition",
"ConfigWindow_Auto_ActionCondition_Description": "This will change the strategy of Rotation Solver to use these actions.",
"ConfigWindow_Target_Config": "Configuration",
"ConfigWindow_Search_Result": "Searching Result"
"ConfigWindow_Search_Result": "Searching Result",
"ConfigWindow_UI_DrawIconAnimation": "Show animation about Icon",
"ConfigWindow_UI_ShowBeneficialPosition": "Show beneficial positions.",
"ConfigWindow_UI_BeneficialPositionColor": "The colors of beneficial positions"
}
17 changes: 11 additions & 6 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ internal partial class Strings

public string ConfigWindow_Param_OnlyHotOnTanks { get; set; } = "Use single target healing over time actions only on tanks";

public string ConfigWindow_Param_BeneficialAreaOnTarget { get; set; } = "Use Beneficial Area abilities on target.";
public string ConfigWindow_Param_BeneficialAreaOnLocations { get; set; } = "On Listed Position";
public string ConfigWindow_Param_BeneficialAreaOnTarget { get; set; } = "On target";

public string ConfigWindow_Param_BeneficialAreaOnCalculated { get; set; } = "On the calculated Position";



public string ConfigWindow_Param_HealthDifference { get; set; } = "HP%% for standard deviation for using AOE heal.";
public string ConfigWindow_Param_HealthAreaAbility { get; set; } = "HP%% for AOE healing OGCDs";
Expand Down Expand Up @@ -235,7 +240,7 @@ internal partial class Strings
public string ConfigWindow_Param_HostileDesc { get; set; } = "You can set the logic of hostile target selection to allow flexibility in switching the logic of selecting hostile in battle.";
public string ConfigWindow_Param_HostileCondition { get; set; } = "Hostile target selection condition";

public string ConfigWindow_Control_OnlyShowWithHostileOrInDuty { get; set; } = "Only shown if there are enemies in or in duty";
public string ConfigWindow_Control_OnlyShowWithHostileOrInDuty { get; set; } = "Only show these windows if there are enemies in or in duty";
public string ConfigWindow_Control_ShowNextActionWindow { get; set; } = "Show Next Action Window";

public string ConfigWindow_Control_ShowControlWindow { get; set; } = "Show Control Window";
Expand Down Expand Up @@ -637,10 +642,6 @@ internal partial class Strings
public string ConfigWindow_List_ActionNameOrId { get; set; } = "Action name or id";
public string ConfigWindow_List_AddAction { get; set; } = "Add Action";

public string ConfigWindow_List_TerritoryEverywhere { get; set; } = "Everywhere";

public string ConfigWindow_List_AddTerritory{ get; set; } = "Territory name or id";

public string ConfigWindow_List_BeneficialLocations { get; set; } = "Beneficial locations";
public string ConfigWindow_List_NoHostilesName { get; set; } = "The name of object that you don't want to attack";

Expand All @@ -659,4 +660,8 @@ internal partial class Strings
public string ConfigWindow_Auto_ActionCondition_Description { get; set; } = "This will change the strategy of Rotation Solver to use these actions.";
public string ConfigWindow_Target_Config { get; set; } = "Configuration";
public string ConfigWindow_Search_Result { get; set; } = "Searching Result";
public string ConfigWindow_UI_DrawIconAnimation { get; set; } = "Show animation about Icon";

public string ConfigWindow_UI_ShowBeneficialPosition { get; set; } = "Show beneficial positions.";
public string ConfigWindow_UI_BeneficialPositionColor { get; set; } = "The colors of beneficial positions";
}
7 changes: 3 additions & 4 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
try
{
Service.Config = JsonConvert.DeserializeObject<PluginConfig>(
File.ReadAllText(Svc.PluginInterface.ConfigFile.FullName))
File.ReadAllText(Svc.PluginInterface.ConfigFile.FullName), new JsonSerializerSettings()
{
})
?? PluginConfig.Create();
}
catch(Exception ex)
Expand Down Expand Up @@ -119,10 +121,7 @@ public void Dispose()

ECommonsMain.Dispose();

#if DEBUG
#else
Service.Config.Save();
#endif
}

private void OnOpenConfigUi()
Expand Down
55 changes: 46 additions & 9 deletions RotationSolver/UI/PainterManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using RotationSolver.Basic.Configuration;
using RotationSolver.Updaters;
using XIVPainter;
using XIVPainter.Element3D;
Expand All @@ -9,6 +10,43 @@ namespace RotationSolver.UI;

internal static class PainterManager
{
class BeneficialPositionDrawing : Drawing3DPoly
{
const float beneficialRadius = 0.6f;
public override void UpdateOnFrame(XIVPainter.XIVPainter painter)
{
SubItems = Array.Empty<IDrawing3D>();

if (!Service.Config.GetValue(PluginConfigBool.ShowBeneficialPositions)) return;

if (Svc.ClientState == null) return;
if (!Player.Available) return;

if(!OtherConfiguration.BeneficialPositions.TryGetValue(Svc.ClientState.TerritoryType, out var pts)) return;

var d = DateTime.Now.Millisecond / 1000f;
var ratio = (float)DrawingExtensions.EaseFuncRemap(EaseFuncType.None, EaseFuncType.Cubic)(d);
List<IDrawing3D> subItems = new List<IDrawing3D>();

var color = ImGui.GetColorU32(Service.Config.GetValue(PluginConfigVector4.BeneficialPositionColor));

foreach (var p in pts)
{
if (Vector3.Distance(Player.Object.Position, p) > 80) continue;

subItems.Add(new Drawing3DCircularSector(p, beneficialRadius * ratio, color, 3)
{
IsFill = false,
});
}

SubItems = subItems.ToArray();

base.UpdateOnFrame(painter);
}

}

class TargetDrawing : Drawing3DPoly
{
Drawing3DCircularSector _target;
Expand Down Expand Up @@ -121,7 +159,7 @@ public override void UpdateOnFrame(XIVPainter.XIVPainter painter)
}
}

internal static XIVPainter.XIVPainter _painter;
static XIVPainter.XIVPainter _painter;
static DrawingHighlightHotbar _highLight = new();

public static HashSet<uint> ActionIds => _highLight.ActionIds;
Expand All @@ -137,12 +175,11 @@ public static void Init()
_painter = XIVPainter.XIVPainter.Create(Svc.PluginInterface, "RotationSolverOverlay");

_highLight = new();

UpdateSettings();

HighlightColor = Service.Config.GetValue(Basic.Configuration.PluginConfigVector4.TeachingModeColor);
HighlightColor = Service.Config.GetValue(PluginConfigVector4.TeachingModeColor);

var annulus = new Drawing3DAnnulusO(Player.Object, 3, 3 + Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.MeleeRangeOffset), 0, 2);
var annulus = new Drawing3DAnnulusO(Player.Object, 3, 3 + Service.Config.GetValue(PluginConfigFloat.MeleeRangeOffset), 0, 2);
annulus.InsideColor = ImGui.ColorConvertFloat4ToU32(new Vector4(0.8f, 0.3f, 0.2f, 0.15f));

annulus.UpdateEveryFrame = () =>
Expand All @@ -158,7 +195,7 @@ public static void Init()
}
};

var color = ImGui.GetColorU32(Service.Config.GetValue(Basic.Configuration.PluginConfigVector4.MovingTargetColor));
var color = ImGui.GetColorU32(Service.Config.GetValue(PluginConfigVector4.MovingTargetColor));
var movingTarget = new Drawing3DHighlightLine(default, default, 0, color, 3);
movingTarget.UpdateEveryFrame = () =>
{
Expand All @@ -178,7 +215,7 @@ public static void Init()
movingTarget.To = tar.Value;
};

_painter.AddDrawings(_highLight, annulus, movingTarget, new TargetDrawing(), new TargetText());
_painter.AddDrawings(_highLight, annulus, movingTarget, new TargetDrawing(), new TargetText(), new BeneficialPositionDrawing());

#if DEBUG
//try
Expand Down Expand Up @@ -216,9 +253,9 @@ public static void Init()

public static void UpdateSettings()
{
_painter.DrawingHeight = Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.DrawingHeight);
_painter.SampleLength = Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.SampleLength);
_painter.Enable = Service.Config.GetValue(Basic.Configuration.PluginConfigBool.UseOverlayWindow);
_painter.DrawingHeight = Service.Config.GetValue(PluginConfigFloat.DrawingHeight);
_painter.SampleLength = Service.Config.GetValue(PluginConfigFloat.SampleLength);
_painter.Enable = Service.Config.GetValue(PluginConfigBool.UseOverlayWindow);
}

public static void Dispose()
Expand Down
Loading

0 comments on commit 930a42c

Please sign in to comment.