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

Commit

Permalink
fix: timeline drawing testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 5, 2024
1 parent 0ebc6b0 commit d9b08e6
Show file tree
Hide file tree
Showing 21 changed files with 306 additions and 258 deletions.
2 changes: 1 addition & 1 deletion Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ClickingCount": 98903,
"ClickingCount": 98904,
"SayingHelloCount": 165,
"SaidUsers": []
}
8 changes: 1 addition & 7 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Dalamud.Configuration;
using ECommons.DalamudServices;
using ECommons.ExcelServices;
using RotationSolver.Basic.Configuration.Omens;
using RotationSolver.Basic.Configuration.Timeline;

namespace RotationSolver.Basic.Configuration;
Expand Down Expand Up @@ -393,9 +392,6 @@ public const string
Filter = AutoActionCondition, Section = 1)]
private static readonly bool _healWhenNothingTodo = true;

[ConditionBool, UI("Show The Omen things.", Filter = Extra)]
private static readonly bool _showOmen = false;

[ConditionBool, UI("Say hello to all users of Rotation Solver.",
Filter =BasicParams)]
private static readonly bool _sayHelloToAll = true;
Expand Down Expand Up @@ -741,9 +737,7 @@ public const string
public Dictionary<uint, string> DutyRotationChoice { get; set; } = [];

[JobConfig]
private readonly Dictionary<uint, Dictionary<float, List<ITimelineItem>>> _timeline = [];

public Dictionary<uint, CastingOmenConfig> OmenCastingConfig { get; set; } = [];
private readonly Dictionary<uint, Dictionary<float, List<BaseTimelineItem>>> _timeline = [];

public void Save()
{
Expand Down
23 changes: 19 additions & 4 deletions RotationSolver.Basic/Configuration/Timeline/ActionTimelineItem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace RotationSolver.Basic.Configuration.Timeline;
using ECommons.DalamudServices;

namespace RotationSolver.Basic.Configuration.Timeline;

[Description("Action Timeline")]
internal class ActionTimelineItem : ITimelineItem
internal class ActionTimelineItem : BaseTimelineItem
{
public ActionID ID { get; set; } = ActionID.None;
public float Time { get; set; } = 3;
public bool InPeriod(TimelineItem item)
public override bool InPeriod(TimelineItem item)
{
var time = item.Time - DataCenter.RaidTimeRaw;

Expand All @@ -14,4 +15,18 @@ public bool InPeriod(TimelineItem item)
if (time > Time || Time - time > 3) return false;
return true;
}

protected override void OnEnable()
{
var act = DataCenter.RightNowRotation?.AllBaseActions.FirstOrDefault(a => (ActionID)a.ID == ID);

if (act == null) return;

DataCenter.AddCommandAction(act, Service.Config.SpecialDuration);

#if DEBUG
Svc.Log.Debug($"Added the action {act} to timeline.");
#endif
base.OnEnable();
}
}
29 changes: 29 additions & 0 deletions RotationSolver.Basic/Configuration/Timeline/BaseTimelineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace RotationSolver.Basic.Configuration.Timeline;

internal abstract class BaseTimelineItem
{
public float Time { get; set; } = 3;
private bool _enable = false;
internal bool Enable
{
get => _enable;
set
{
if (_enable == value) return;
_enable = value;

if (_enable)
{
OnEnable();
}
else
{
OnDisable();
}
}
}
public abstract bool InPeriod(TimelineItem item);

protected virtual void OnEnable() { }
protected virtual void OnDisable() { }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace RotationSolver.Basic.Configuration.Omens;
namespace RotationSolver.Basic.Configuration.Timeline;
public struct CastingOmenConfig
{
public string? OmenPath { get; set; }
public float? X { get; set; }
public float? Y { get; set; }

public float? Rotation { get; set; }
}
195 changes: 195 additions & 0 deletions RotationSolver.Basic/Configuration/Timeline/DrawingTimeline.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
using ECommons.Configuration;
using ECommons.DalamudServices;
using ECommons.GameFunctions;
using RotationSolver.Basic.Configuration.Timeline.TimelineCondition;
using XIVPainter;
using XIVPainter.Element;
using XIVPainter.Vfx;
using Action = Lumina.Excel.GeneratedSheets.Action;


namespace RotationSolver.Basic.Configuration.Timeline;

[Description("Drawing Timeline")]
internal class DrawingTimeline : BaseTimelineItem
{
private IDisposable[] _drawings = [];
public ITimelineCondition Condition { get; set; } = new TrueTimelineCondition();
public StaticVfxConfig StaticVfxConfig { get; set; }
public ObjectVfxConfig ObjectConfig { get; set; }
public ActionVfxConfig ActionConfig { get; set; }
public ObjectGetter ObjectGetter { get; set; } = new();
public DrawingType Type { get; set; }

public uint ActionID { get; set; }
public DrawingTimeline()
{
Time = 5;
}

public override bool InPeriod(TimelineItem item)
{
var time = item.Time - DataCenter.RaidTimeRaw;

if (time < 0) return false;
if (time > Time) return false;

if (!Condition.IsTrue()) return false;

return true;
}

protected override void OnEnable()
{
foreach (var item in _drawings)
{
item.Dispose();
}
_drawings = CreateDrawing();

#if DEBUG
//Svc.Log.Debug($"Added the state {item2.State} to timeline.");
#endif
base.OnEnable();
}

protected override void OnDisable()
{
foreach (var item in _drawings)
{
item.Dispose();
}
_drawings = [];
base.OnDisable();
}

private IDisposable[] CreateDrawing()
{
switch (Type)
{
case DrawingType.Ground:
if (string.IsNullOrEmpty(StaticVfxConfig.Path)) break;

return [new StaticVfx(StaticVfxConfig.Path, StaticVfxConfig.Position, StaticVfxConfig.Rotation, StaticVfxConfig.Scale)];

case DrawingType.Object:
return [..ObjectGetter.GetObjects().Select(GetObjectDrawing)];

case DrawingType.Action:
return [.. ObjectGetter.GetObjects().Select(GetActionDrawing)];
}
return [];
}

private IDisposable? GetObjectDrawing(GameObject obj)
{
switch (ObjectConfig.Type)
{
case ObjectVfxConfig.ObjectType.Single:
return new Single1(obj, ObjectConfig.Radius);

case ObjectVfxConfig.ObjectType.Stack2:
return new Share2(obj, ObjectConfig.Radius);

case ObjectVfxConfig.ObjectType.Stack4:
return new Share4(obj, ObjectConfig.Radius);

case ObjectVfxConfig.ObjectType.General:
if (string.IsNullOrEmpty(StaticVfxConfig.Path)) break;

var result = new StaticVfx(StaticVfxConfig.Path, obj, StaticVfxConfig.Scale)
{
LocationOffset = StaticVfxConfig.Position,
RotateAddition = StaticVfxConfig.Rotation,
};
if (ObjectConfig.TargetOnTarget)
{
result.Target = obj.TargetObject;
}
return result;
}
return null;
}

private IDisposable? GetActionDrawing(GameObject obj)
{
if (ActionID == 0) return null;
var action = Svc.Data.GetExcelSheet<Action>()?.GetRow(ActionID);
if (action == null) return null;
var omen = action.Omen.Value?.Path?.RawString;
omen = string.IsNullOrEmpty(omen) ? StaticVfxConfig.Path : omen.Omen();

var x = ActionConfig.X ?? (action.XAxisModifier > 0 ? action.XAxisModifier / 2 : action.EffectRange);
var y = ActionConfig.Y ?? action.EffectRange;
var scale = new Vector3(x, XIVPainterMain.HeightScale, y);

if (action.TargetArea)
{
var location = StaticVfxConfig.Position;
if (obj is BattleChara battle)
{
unsafe
{
var info = battle.Struct()->GetCastInfo;
if (info->IsCasting != 0)
{
location = info->CastLocation;
}
}
}
return new StaticVfx(omen, location, 0, scale);
}
else
{
return new StaticVfx(omen, obj, scale)
{
RotateAddition = StaticVfxConfig.Rotation / 180 * MathF.PI,
LocationOffset = StaticVfxConfig.Position,
};
}
}
}

public class ObjectGetter
{
public GameObject[] GetObjects()
{
return [];
}
}

public struct ActionVfxConfig
{
public float? X { get; set; }
public float? Y { get; set; }
}

public struct ObjectVfxConfig
{
public enum ObjectType
{
Single,
Stack2,
Stack4,
General,
}

public float Radius { get; set; }
public bool TargetOnTarget { get; set; }
public ObjectType Type { get; set; }
}

public struct StaticVfxConfig
{
public string Path { get; set; }
public Vector3 Position { get; set; }
public float Rotation { get; set; }
public Vector3 Scale { get; set; }
}

public enum DrawingType
{
Ground,
Object,
Action,
}
7 changes: 0 additions & 7 deletions RotationSolver.Basic/Configuration/Timeline/ITimelineItem.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace RotationSolver.Basic.Configuration.Timeline;

internal class ITimelineItemConverter : JsonCreationConverter<ITimelineItem>
internal class ITimelineItemConverter : JsonCreationConverter<BaseTimelineItem>
{
protected override ITimelineItem? Create(JObject jObject)
protected override BaseTimelineItem? Create(JObject jObject)
{
if (FieldExists(nameof(ActionTimelineItem.ID), jObject))
{
Expand All @@ -15,6 +15,11 @@ internal class ITimelineItemConverter : JsonCreationConverter<ITimelineItem>
{
return new StateTimelineItem();
}
else if (FieldExists(nameof(DrawingTimeline.Condition), jObject))
{
return new DrawingTimeline();
}

return null;
}
}
18 changes: 14 additions & 4 deletions RotationSolver.Basic/Configuration/Timeline/StateTimelineItem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace RotationSolver.Basic.Configuration.Timeline;
using ECommons.DalamudServices;

namespace RotationSolver.Basic.Configuration.Timeline;

[Description("State Timeline")]
internal class StateTimelineItem : ITimelineItem
internal class StateTimelineItem : BaseTimelineItem
{
public SpecialCommandType State { get; set; } = SpecialCommandType.DefenseArea;
public float Time { get; set; } = 3;
public bool InPeriod(TimelineItem item)
public override bool InPeriod(TimelineItem item)
{
var time = item.Time - DataCenter.RaidTimeRaw;

Expand All @@ -14,4 +15,13 @@ public bool InPeriod(TimelineItem item)
if (time > Time || Time - time > 3) return false;
return true;
}

protected override void OnEnable()
{
DataCenter.SpecialType = State;
#if DEBUG
Svc.Log.Debug($"Added the state {State} to timeline.");
#endif
base.OnEnable();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace RotationSolver.Basic.Configuration.Timeline.TimelineCondition;
public interface ITimelineCondition
{
bool IsTrue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace RotationSolver.Basic.Configuration.Timeline.TimelineCondition;

public class TrueTimelineCondition : ITimelineCondition
{
public bool IsTrue() => true;
}
2 changes: 2 additions & 0 deletions RotationSolver.Basic/RotationSolver.Basic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@

<ProjectReference Include="..\RotationSolver.SourceGenerators\RotationSolver.SourceGenerators.csproj" OutputItemType="Analyzer" ExcludeAssets="All" />

<ProjectReference Include="..\XIVPainter\XIVPainter\XIVPainter.csproj" />

<None Include="..\COPYING.LESSER">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
Expand Down
Loading

0 comments on commit d9b08e6

Please sign in to comment.