1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Diagnostics . CodeAnalysis ;
4+ using System . Linq ;
5+ using System . Windows . Media ;
6+ using ff14bot . Managers ;
7+ using ff14bot . Objects ;
8+ using ff14bot . Pathing . Avoidance ;
9+ using LlamaLibrary . Logging ;
10+
11+ namespace LlamaLibrary . Helpers ;
12+
13+ [ SuppressMessage ( "StyleCop.CSharp.OrderingRules" , "SA1214:Readonly fields should appear before non-readonly fields" ) ]
14+ public class SideStep
15+ {
16+
17+ private static readonly LLogger Log = new ( "SideStepHelper" , Color . FromRgb ( 255 , 177 , 109 ) ) ;
18+
19+ private static object ? _sideStep ;
20+
21+ private static Action ? _loadAvoidanceFunction ;
22+ private static Action < ulong , uint , Func < BattleCharacter , float , IEnumerable < AvoidInfo > > , float > ? _addHandlerFunction ;
23+ private static Func < ulong , uint , bool > ? _removeHandlerFunction ;
24+
25+ static SideStep ( )
26+ {
27+ FindSideStep ( ) ;
28+ }
29+
30+ private static void FindSideStep ( )
31+ {
32+ var loader = PluginManager . Plugins
33+ . FirstOrDefault ( c => string . Equals ( c . Plugin . Name , "SideStep" , StringComparison . Ordinal ) ) ;
34+
35+ if ( loader == null )
36+ {
37+ Log . Information ( "SideStepHelper: No SideStep found." ) ;
38+ return ;
39+ }
40+
41+ _sideStep = loader . Plugin ;
42+
43+
44+ if ( _sideStep != null )
45+ {
46+ try
47+ {
48+
49+ _loadAvoidanceFunction = ( Action ) Delegate . CreateDelegate ( typeof ( Action ) , _sideStep , "LoadAvoidanceObjects" ) ;
50+ _addHandlerFunction = ( Action < ulong , uint , Func < BattleCharacter , float , IEnumerable < AvoidInfo > > , float > ) Delegate . CreateDelegate ( typeof ( Action < ulong , uint , Func < BattleCharacter , float , IEnumerable < AvoidInfo > > , float > ) , _sideStep , "AddHandler" ) ;
51+ _removeHandlerFunction = ( Func < ulong , uint , bool > ) Delegate . CreateDelegate ( typeof ( Action < ulong , uint , Func < BattleCharacter , float , IEnumerable < AvoidInfo > > , float > ) , _sideStep , "RemoveHandler" ) ;
52+ }
53+ catch ( Exception e )
54+ {
55+ Log . Error ( e . ToString ( ) ) ;
56+ }
57+ }
58+
59+ Log . Information ( "SideStep found." ) ;
60+ }
61+
62+ public void LoadAvoidanceObjects ( )
63+ {
64+ if ( _loadAvoidanceFunction == null )
65+ {
66+ Log . Information ( "SideStepHelper: No LoadAvoidanceObjects found." ) ;
67+ return ;
68+ }
69+
70+ _loadAvoidanceFunction . Invoke ( ) ;
71+ }
72+
73+ public bool RemoveHandler ( ulong type , uint key )
74+ {
75+ if ( _removeHandlerFunction == null )
76+ {
77+ Log . Information ( "SideStepHelper: no RemoveHandler found." ) ;
78+ return false ;
79+ }
80+ return _removeHandlerFunction . Invoke ( type , key ) ;
81+ }
82+
83+ public void AddHandler ( ulong type , uint key , Func < BattleCharacter , float , IEnumerable < AvoidInfo > > handler , float range = float . NaN )
84+ {
85+ if ( _addHandlerFunction == null )
86+ {
87+ Log . Information ( "SideStepHelper: no AddHandler found." ) ;
88+ return ;
89+ }
90+ _addHandlerFunction ? . Invoke ( type , key , handler , range ) ;
91+ }
92+ }
0 commit comments