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

Commit

Permalink
style: fixed the code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Feb 4, 2024
1 parent 4926315 commit 99c7da3
Show file tree
Hide file tree
Showing 45 changed files with 255 additions and 224 deletions.
4 changes: 2 additions & 2 deletions DefaultRotations/Healer/AST_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected override bool HealSingleGCD(out IAction? act)
{
if (AspectedBeneficPvE.CanUse(out act)
&& (IsMoving
|| AspectedBeneficPvE.Target!.Value.Target.GetHealthRatio() > 0.4)) return true;
|| AspectedBeneficPvE.Target!.Value.Target?.GetHealthRatio() > 0.4)) return true;

if (BeneficIiPvE.CanUse(out act)) return true;
if (BeneficPvE.CanUse(out act)) return true;
Expand Down Expand Up @@ -166,7 +166,7 @@ protected override bool HealSingleAbility(out IAction? act)
}

[RotationDesc(ActionID.CelestialOppositionPvE, ActionID.EarthlyStarPvE, ActionID.HoroscopePvE)]
protected override bool HealAreaAbility(out IAction act)
protected override bool HealAreaAbility(out IAction? act)
{
if (CelestialOppositionPvE.CanUse(out act)) return true;

Expand Down
9 changes: 5 additions & 4 deletions RotationSolver.Basic/Actions/ActionTargetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private readonly bool CheckTimeToKill(GameObject gameObject)
if (Svc.Targets.Target != null && Svc.Targets.Target.DistanceToPlayer() < range)
{
var target = Svc.Targets.Target as BattleChara;
return new(target, [.. GetAffects(target.Position, canAffects)], target.Position);
return new(target, [.. GetAffects(target?.Position, canAffects)], target?.Position);
}
break;
}
Expand Down Expand Up @@ -341,11 +341,12 @@ private readonly bool CheckTimeToKill(GameObject gameObject)
}
}

private readonly IEnumerable<BattleChara> GetAffects(Vector3 point, IEnumerable<BattleChara> canAffects)
private readonly IEnumerable<BattleChara> GetAffects(Vector3? point, IEnumerable<BattleChara> canAffects)
{
if (point == null) yield break;
foreach (var t in canAffects)
{
if (Vector3.Distance(point, t.Position) - t.HitboxRadius <= EffectRange)
if (Vector3.Distance(point.Value, t.Position) - t.HitboxRadius <= EffectRange)
{
yield return t;
}
Expand Down Expand Up @@ -780,4 +781,4 @@ public enum TargetType : byte

}

public readonly record struct TargetResult(BattleChara Target, BattleChara[] AffectedTargets, Vector3 Position);
public readonly record struct TargetResult(BattleChara? Target, BattleChara[] AffectedTargets, Vector3? Position);
5 changes: 3 additions & 2 deletions RotationSolver.Basic/Actions/BaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,19 @@ public unsafe bool Use()
if (TargetInfo.TargetArea)
{
if (adjustId != ID) return false;
if (!target.Position.HasValue) return false;

var loc = (FFXIVClientStructs.FFXIV.Common.Math.Vector3)target.Position;

return ActionManager.Instance()->UseActionLocation(ActionType.Action, ID, Player.Object.ObjectId, &loc);
}
else if (Svc.Objects.SearchById(target.Target.ObjectId) == null)
else if (Svc.Objects.SearchById(target.Target?.ObjectId ?? GameObject.InvalidGameObjectId) == null)
{
return false;
}
else
{
return ActionManager.Instance()->UseAction(ActionType.Action, adjustId, target.Target.ObjectId);
return ActionManager.Instance()->UseAction(ActionType.Action, adjustId, target.Target?.ObjectId ?? GameObject.InvalidGameObjectId);
}
}
}
6 changes: 3 additions & 3 deletions RotationSolver.Basic/Attributes/AssemblyLinkAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class AssemblyLinkAttribute : Attribute
/// <summary>
/// A link for donate.
/// </summary>
public string Donate { get; set; }
public string? Donate { get; set; }

/// <summary>
/// A link for your user name in GitHub.
/// </summary>
public string UserName { get; set; }
public string? UserName { get; set; }

/// <summary>
/// A link for the repo in your GitHub.
/// </summary>
public string Repository { get; set; }
public string? Repository { get; set; }
}
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Attributes/AuthorHashAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public class AuthorHashAttribute : Attribute
/// <summary>
/// The hash of your character.
/// </summary>
public string Hash { get; set; }
public string? Hash { get; set; }
}
8 changes: 4 additions & 4 deletions RotationSolver.Basic/Attributes/RotationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace RotationSolver.Basic.Attributes;
[AttributeUsage(AttributeTargets.Class)]
public class RotationAttribute : Attribute
{
public string Name { get; set; }
public string Description { get; set; }
public CombatType Type { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public CombatType Type { get; set; } = CombatType.None;

public string GameVersion { get; set; }
public string? GameVersion { get; set; }
}
4 changes: 2 additions & 2 deletions RotationSolver.Basic/Attributes/RotationDescAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ private RotationDescAttribute()

}

internal static IEnumerable<RotationDescAttribute[]> Merge(IEnumerable<RotationDescAttribute> rotationDescAttributes)
internal static IEnumerable<RotationDescAttribute[]> Merge(IEnumerable<RotationDescAttribute?> rotationDescAttributes)
=> from r in rotationDescAttributes
where r is not null
group r by r.Type into gr
orderby gr.Key
select gr.ToArray();

internal static RotationDescAttribute MergeToOne(IEnumerable<RotationDescAttribute> rotationDescAttributes)
internal static RotationDescAttribute? MergeToOne(IEnumerable<RotationDescAttribute> rotationDescAttributes)
{
var result = new RotationDescAttribute();
foreach (var attr in rotationDescAttributes)
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Attributes/SourceCodeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public class SourceCodeAttribute : Attribute
/// <summary>
/// The link to the source code.
/// </summary>
public string Path { get; set; }
public string? Path { get; set; }
}
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Attributes/YoutubeLinkAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public class YoutubeLinkAttribute : Attribute
/// <summary>
/// The youtube link Id
/// </summary>
public string ID { get; set; }
public string? ID { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[Description("Action Condition")]
internal class ActionCondition : DelayCondition
{
internal IBaseAction _action = null!;
internal IBaseAction? _action = null;

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

Expand All @@ -20,6 +20,8 @@ public override bool CheckBefore(ICustomRotation rotation)

protected override bool IsTrueInside(ICustomRotation rotation)
{
if (_action == null) return false;

switch (ActionConditionType)
{
case ActionConditionType.Elapsed:
Expand Down
10 changes: 5 additions & 5 deletions RotationSolver.Basic/Configuration/Conditions/DelayCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal abstract class DelayCondition : ICondition
public bool Not = false;

[ThreadStatic]
private static Stack<ICondition> _callingStack;
private static Stack<ICondition>? _callingStack;

public bool IsTrue(ICustomRotation? rotation)
{
Expand Down Expand Up @@ -60,7 +60,7 @@ internal static bool CheckBaseAction(ICustomRotation rotation, ActionID id, ref
return true;
}

internal static bool CheckMemberInfo<T>(ICustomRotation? rotation, ref string name, ref T value) where T : MemberInfo
internal static bool CheckMemberInfo<T>(ICustomRotation? rotation, ref string name, ref T? value) where T : MemberInfo
{
if (rotation == null) return false;

Expand All @@ -69,17 +69,17 @@ internal static bool CheckMemberInfo<T>(ICustomRotation? rotation, ref string na
var memberName = name;
if (typeof(T).IsAssignableFrom(typeof(PropertyInfo)))
{
value = (T)GetAllMembers(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeProperties).FirstOrDefault(m => m.Name == memberName);
value = (T?)GetAllMembers(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeProperties).FirstOrDefault(m => m.Name == memberName);
}
else if (typeof(T).IsAssignableFrom(typeof(MethodInfo)))
{
value = (T)GetAllMembers(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeMethods).FirstOrDefault(m => m.Name == memberName);
value = (T?)GetAllMembers(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeMethods).FirstOrDefault(m => m.Name == memberName);
}
}
return true;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override bool IsTrueInside(ICustomRotation rotation)
case ComboConditionType.Last:
try
{
if (_method?.Invoke(rotation, new object[] { Param1 > 0, new IAction[] { _action } }) is bool boo)
if (_method?.Invoke(rotation, new object[] { Param1 > 0, new IAction?[] { _action } }) is bool boo)
{
return boo;
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Configuration/MacroInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public MacroInfo()
IsShared = false;
}

public unsafe bool AddMacro(GameObject tar = null)
public unsafe bool AddMacro(GameObject? tar = null)
{
if (MacroIndex < 0 || MacroIndex > 99) return false;

Expand Down
6 changes: 3 additions & 3 deletions RotationSolver.Basic/Configuration/OtherConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private static void InitOne<T>(ref T value, string name, bool download = true)
{
try
{
value = JsonConvert.DeserializeObject<T>(File.ReadAllText(path));
value = JsonConvert.DeserializeObject<T>(File.ReadAllText(path))!;
}
catch (Exception ex)
{
Expand All @@ -244,8 +244,8 @@ private static void InitOne<T>(ref T value, string name, bool download = true)
Error = delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
{
args.ErrorContext.Handled = true;
}
});
}!
})!;
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ namespace RotationSolver.Basic.Configuration.RotationConfig
{
internal class RotationConfigComparer : IEqualityComparer<IRotationConfig>
{
public bool Equals(IRotationConfig x, IRotationConfig y) => x.Name.Equals(y.Name);
public bool Equals(IRotationConfig? x, IRotationConfig? y)
{
if (x == null || y == null) return false;
return x.Name.Equals(y.Name);
}

public int GetHashCode([DisallowNull] IRotationConfig obj) => obj.Name.GetHashCode();
}
Expand Down
9 changes: 5 additions & 4 deletions RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public static bool GetTexture(this IAction? action, out IDalamudTextureWrap text
if (!_actionIcons.TryGetValue(id, out iconId))
{
iconId = id == action.ID ? action.IconID : action is IBaseAction
? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(id).Icon
: Service.GetSheet<Item>().GetRow(id).Icon;
? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(id)!.Icon
: Service.GetSheet<Item>().GetRow(id)!.Icon;

_actionIcons[id] = iconId;
}
Expand All @@ -172,8 +172,8 @@ public static bool GetTexture(this ActionID actionID, out IDalamudTextureWrap te
if (!_actionIcons.TryGetValue(id, out var iconId))
{
iconId = isAction
? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(id).Icon
: Service.GetSheet<Item>().GetRow(id).Icon;
? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(id)!.Icon
: Service.GetSheet<Item>().GetRow(id)!.Icon;

_actionIcons[id] = iconId;
}
Expand Down Expand Up @@ -296,6 +296,7 @@ public static bool GetTexture(this ActionID actionID, out IDalamudTextureWrap te
/// <summary>
/// Get job Icon from rotation.
/// </summary>
/// <param name="role"></param>
/// <param name="job"></param>
/// <returns></returns>
public static uint GetJobIcon(JobRole role, Job job)
Expand Down
24 changes: 9 additions & 15 deletions RotationSolver.Basic/Data/MacroItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,26 @@ namespace RotationSolver.Basic.Data;
/// <summary>
/// The class to handle the event of macro.
/// </summary>
public unsafe class MacroItem
/// <remarks>
/// Constructer
/// </remarks>
/// <param name="target"></param>
/// <param name="macro"></param>
public unsafe class MacroItem(GameObject? target, RaptureMacroModule.Macro* macro)
{
private GameObject _lastTarget;
RaptureMacroModule.Macro* _macro;
private GameObject? _lastTarget;
readonly RaptureMacroModule.Macro* _macro = macro;

/// <summary>
/// The target of this macro.
/// </summary>
public GameObject Target { get; }
public GameObject? Target { get; } = target;

/// <summary>
/// Is macro running.
/// </summary>
public bool IsRunning { get; private set; }

/// <summary>
/// Constructer
/// </summary>
/// <param name="target"></param>
/// <param name="macro"></param>
public MacroItem(GameObject target, RaptureMacroModule.Macro* macro)
{
_macro = macro;
Target = target;
}

/// <summary>
/// Start running the macro.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions RotationSolver.Basic/Helpers/MarkingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class MarkingHelper

internal static bool HaveAttackChara(IEnumerable<BattleChara> charas) => GetAttackMarkChara(charas) != null;

internal static BattleChara GetAttackMarkChara(IEnumerable<BattleChara> charas)
internal static BattleChara? GetAttackMarkChara(IEnumerable<BattleChara> charas)
{
for (uint i = 0; i < 5; i++)
{
Expand All @@ -18,9 +18,9 @@ internal static BattleChara GetAttackMarkChara(IEnumerable<BattleChara> charas)
return null;
}

private static BattleChara GetChara(IEnumerable<BattleChara> charas, long id)
private static BattleChara? GetChara(IEnumerable<BattleChara> charas, long id)
{
if (id == 0xE0000000) return null;
if (id == GameObject.InvalidGameObjectId) return null;
return charas.FirstOrDefault(item => item.ObjectId == id);
}

Expand Down
6 changes: 3 additions & 3 deletions RotationSolver.Basic/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ public static unsafe bool CanSee(this GameObject b)
}

/// <summary>
/// Get the <paramref name="b"/>'s current HP percentage.
/// Get the <paramref name="g"/>'s current HP percentage.
/// </summary>
/// <param name="b"></param>
/// <param name="g"></param>
/// <returns></returns>
public static float GetHealthRatio(this GameObject g)
{
Expand Down Expand Up @@ -479,7 +479,7 @@ public static double AngleTo(this Vector2 vec1, Vector2 vec2)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static float DistanceToPlayer(this GameObject obj)
public static float DistanceToPlayer(this GameObject? obj)
{
if (obj == null) return float.MaxValue;
var player = Player.Object;
Expand Down
Loading

0 comments on commit 99c7da3

Please sign in to comment.