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

Commit

Permalink
Merge pull request #462 from ArchiDog1998/main
Browse files Browse the repository at this point in the history
RP
  • Loading branch information
ArchiDog1998 authored Oct 22, 2023
2 parents 9a0812d + 22cc975 commit f36188a
Show file tree
Hide file tree
Showing 239 changed files with 2,307 additions and 1,937 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Authors>ArchiTed</Authors>
<Version>3.3.6</Version>
<Version>3.4.0</Version>
<PlatformTarget>x64</PlatformTarget>
<Platforms>AnyCPU</Platforms>

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
12 changes: 11 additions & 1 deletion Resources/HostileCastingArea.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,5 +420,15 @@
35385,
36093,
35420,
36091
36091,
30981,
30961,
30974,
35274,
35268,
35284,
35279,
35312,
35280,
35269
]
2 changes: 1 addition & 1 deletion Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ClickingCount": 12212,
"ClickingCount": 17599,
"SaidUsers": []
}
80 changes: 80 additions & 0 deletions RotationSolver.Basic/Configuration/Conditions/ActionCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace RotationSolver.Basic.Configuration.Conditions;

internal class ActionCondition : DelayCondition
{
internal IBaseAction _action;

public ActionID ID { get; set; } = ActionID.None;

public ActionConditionType ActionConditionType = ActionConditionType.Elapsed;

public bool Condition { get; set; }

public int Param1;
public int Param2;
public float Time;

public override bool CheckBefore(ICustomRotation rotation)
{
return CheckBaseAction(rotation, ID, ref _action) && base.CheckBefore(rotation);
}

public override bool IsTrueInside(ICustomRotation rotation)
{
var result = false;

switch (ActionConditionType)
{
case ActionConditionType.Elapsed:
result = _action.ElapsedOneChargeAfter(Time); // Bigger
break;

case ActionConditionType.ElapsedGCD:
result = _action.ElapsedOneChargeAfterGCD((uint)Param1, Param2); // Bigger
break;

case ActionConditionType.Remain:
result = !_action.WillHaveOneCharge(Time); //Smaller
break;

case ActionConditionType.RemainGCD:
result = !_action.WillHaveOneChargeGCD((uint)Param1, Param2); // Smaller
break;

case ActionConditionType.CanUse:
result = _action.CanUse(out _, (CanUseOption)Param1, (byte)Param2);
break;

case ActionConditionType.EnoughLevel:
result = _action.EnoughLevel;
break;

case ActionConditionType.IsCoolDown:
result = _action.IsCoolingDown;
break;

case ActionConditionType.CurrentCharges:
result = _action.CurrentCharges > Param1;
break;

case ActionConditionType.MaxCharges:
result = _action.MaxCharges > Param1;
break;
}

return Condition ? !result : result;
}
}

internal enum ActionConditionType : byte
{
Elapsed,
ElapsedGCD,
Remain,
RemainGCD,
CanUse,
EnoughLevel,
IsCoolDown,
CurrentCharges,
MaxCharges,
}
30 changes: 30 additions & 0 deletions RotationSolver.Basic/Configuration/Conditions/ConditionSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace RotationSolver.Basic.Configuration.Conditions;

internal class ConditionSet : DelayCondition
{
public List<ICondition> Conditions { get; set; } = new List<ICondition>();

public LogicalType Type;

public override bool IsTrueInside(ICustomRotation rotation)
{
if (Conditions.Count == 0) return false;

return Type switch
{
LogicalType.And => Conditions.All(c => c.IsTrue(rotation)),
LogicalType.Or => Conditions.Any(c => c.IsTrue(rotation)),
LogicalType.NotAnd => !Conditions.All(c => c.IsTrue(rotation)),
LogicalType.NotOr => !Conditions.Any(c => c.IsTrue(rotation)),
_ => false,
};
}
}

internal enum LogicalType : byte
{
And,
Or,
NotAnd,
NotOr,
}
63 changes: 63 additions & 0 deletions RotationSolver.Basic/Configuration/Conditions/DelayCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using ECommons.GameHelpers;

namespace RotationSolver.Basic.Configuration.Conditions;

internal abstract class DelayCondition : ICondition
{
public float DelayMin = 0;
public float DelayMax = 0;

RandomDelay _delay = default;

public bool IsTrue(ICustomRotation rotation)
{
if (_delay.GetRange == null)
{
_delay = new(() => (DelayMin, DelayMax));
}

return _delay.Delay(CheckBefore(rotation) && IsTrueInside(rotation));
}

public abstract bool IsTrueInside(ICustomRotation rotation);

public virtual bool CheckBefore(ICustomRotation rotation)
{
return Player.Available;
}

internal static bool CheckBaseAction(ICustomRotation rotation, ActionID id, ref IBaseAction action)
{
if (id != ActionID.None && (action == null || (ActionID)action.ID != id))
{
action = rotation.AllBaseActions.FirstOrDefault(a => (ActionID)a.ID == id);
}
if (action == null) return false;
return true;
}

internal static bool CheckMemberInfo<T>(ICustomRotation rotation, ref string name, ref T value) where T : MemberInfo
{
if (!string.IsNullOrEmpty(name) && (value == null || value.Name != name))
{
var memberName = name;
if (typeof(T).IsAssignableFrom(typeof(PropertyInfo)))
{
value = (T)GetAllMethods(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeProperties).FirstOrDefault(m => m.Name == memberName);
}
else if (typeof(T).IsAssignableFrom(typeof(MethodInfo)))
{
value = (T)GetAllMethods(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeMethods).FirstOrDefault(m => m.Name == memberName);
}
}
return true;
}

private static IEnumerable<MemberInfo> GetAllMethods(Type type, Func<Type, IEnumerable<MemberInfo>> getFunc)
{
if (type == null || getFunc == null) return Array.Empty<MemberInfo>();

var methods = getFunc(type);
return methods.Union(GetAllMethods(type.BaseType, getFunc));
}
}
7 changes: 7 additions & 0 deletions RotationSolver.Basic/Configuration/Conditions/ICondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace RotationSolver.Basic.Configuration.Conditions;

internal interface ICondition
{
bool IsTrue(ICustomRotation rotation);
bool CheckBefore(ICustomRotation rotation);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json.Linq;

namespace RotationSolver.ActionSequencer;
namespace RotationSolver.Basic.Configuration.Conditions;

internal class IConditionConverter : JsonCreationConverter<ICondition>
{
Expand Down Expand Up @@ -38,7 +38,7 @@ private static bool FieldExists(string fieldName, JObject jObject)
}
}

public abstract class JsonCreationConverter<T> : JsonConverter
internal abstract class JsonCreationConverter<T> : JsonConverter
{
protected abstract T Create(JObject jObject);

Expand Down
135 changes: 135 additions & 0 deletions RotationSolver.Basic/Configuration/Conditions/MajorConditionSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using ECommons.DalamudServices;
using ECommons.ExcelServices;

namespace RotationSolver.Basic.Configuration.Conditions;

internal class MajorConditionSet
{
const string conditionName = "Unnamed";

[JsonIgnore]
public bool IsUnnamed => Name == conditionName;

/// <summary>
/// Key for action id.
/// </summary>
public Dictionary<Job, Dictionary<uint, ConditionSet>> Conditions { get; } = new();

[JsonIgnore]
public Dictionary<uint, ConditionSet> ConditionDict
{
get
{
if (!Conditions.TryGetValue(DataCenter.Job, out var dict))
{
dict = Conditions[DataCenter.Job] = new();
}
return dict;
}
}

public Dictionary<Job, Dictionary<uint, ConditionSet>> DisabledConditions { get; } = new();

[JsonIgnore]
public Dictionary<uint, ConditionSet> DisableConditionDict
{
get
{
if (!DisabledConditions.TryGetValue(DataCenter.Job, out var dict))
{
dict = DisabledConditions[DataCenter.Job] = new();
}
return dict;
}
}

public Dictionary<PluginConfigBool, ConditionSet> ForceEnableConditions { get; private set; }
= new();

public Dictionary<PluginConfigBool, ConditionSet> ForceDisableConditions { get; private set; }
= new();

public ConditionSet HealAreaConditionSet { get; set; } = new ConditionSet();
public ConditionSet HealSingleConditionSet { get; set; } = new ConditionSet();
public ConditionSet DefenseAreaConditionSet { get; set; } = new ConditionSet();
public ConditionSet DefenseSingleConditionSet { get; set; } = new ConditionSet();
public ConditionSet EsunaStanceNorthConditionSet { get; set; } = new ConditionSet();
public ConditionSet RaiseShirkConditionSet { get; set; } = new ConditionSet();
public ConditionSet MoveForwardConditionSet { get; set; } = new ConditionSet();
public ConditionSet MoveBackConditionSet { get; set; } = new ConditionSet();
public ConditionSet AntiKnockbackConditionSet { get; set; } = new ConditionSet();
public ConditionSet BurstConditionSet { get; set; } = new ConditionSet();
public ConditionSet SpeedConditionSet { get; set; } = new ConditionSet();

public string Name;

public ConditionSet GetCondition(uint id)
{
if (!ConditionDict.TryGetValue(id, out var conditionSet))
{
conditionSet = ConditionDict[id] = new ConditionSet();
}
return conditionSet;
}

public ConditionSet GetDisabledCondition(uint id)
{
if (!DisableConditionDict.TryGetValue(id, out var conditionSet))
{
conditionSet = DisableConditionDict[id] = new ConditionSet();
}
return conditionSet;
}

public ConditionSet GetEnableCondition(PluginConfigBool config)
{
if (!ForceEnableConditions.TryGetValue(config, out var conditionSet))
{
conditionSet = ForceEnableConditions[config] = new ConditionSet();
}
return conditionSet;
}

public ConditionSet GetDisableCondition(PluginConfigBool config)
{
if (!ForceDisableConditions.TryGetValue(config, out var conditionSet))
{
conditionSet = ForceDisableConditions[config] = new ConditionSet();
}
return conditionSet;
}

public MajorConditionSet(string name = conditionName)
{
Name = name;
}

public void Save(string folder)
{
if (!Directory.Exists(folder)) return;
var path = Path.Combine(folder, Name + ".json");

var str = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(path, str);
}

public static MajorConditionSet[] Read(string folder)
{
if (!Directory.Exists(folder)) return Array.Empty<MajorConditionSet>();

return Directory.EnumerateFiles(folder, "*.json").Select(p =>
{
var str = File.ReadAllText(p);

try
{
return JsonConvert.DeserializeObject<MajorConditionSet>(str, new IConditionConverter());
}
catch
{
Svc.Chat.Print($"Failed to load the conditionSet from {p}");
return null;
}
}).Where(set => set != null && !string.IsNullOrEmpty(set.Name)).ToArray();
}
}
Loading

0 comments on commit f36188a

Please sign in to comment.