Skip to content

Commit

Permalink
Merge pull request #32 from patri0t86/viewRefactor
Browse files Browse the repository at this point in the history
View refactor
  • Loading branch information
patri0t86 authored Jul 6, 2020
2 parents 0b70e9f + 70061bb commit b61d9e4
Show file tree
Hide file tree
Showing 30 changed files with 2,335 additions and 1,882 deletions.
7 changes: 6 additions & 1 deletion ACManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ComponentChecker.cs" />
<Compile Include="StateMachine\ComponentChecker.cs" />
<Compile Include="ExpTracker.cs" />
<Compile Include="FellowshipControl.cs" />
<Compile Include="InventoryTracker.cs" />
Expand Down Expand Up @@ -113,6 +113,11 @@
<Compile Include="Views\ExpTrackerView.cs" />
<Compile Include="Views\MainView.cs" />
<Compile Include="Views\BotManagerView.cs" />
<Compile Include="Views\Tabs\AdvertisementsTab.cs" />
<Compile Include="Views\Tabs\ConfigTab.cs" />
<Compile Include="Views\Tabs\GemsTab.cs" />
<Compile Include="Views\Tabs\InventoryTab.cs" />
<Compile Include="Views\Tabs\PortalsTab.cs" />
<Compile Include="VirindiViews\ViewSystemSelector.cs" />
<Compile Include="VirindiViews\Wrapper.cs" />
<Compile Include="VirindiViews\Wrapper_Decal.cs" />
Expand Down
40 changes: 29 additions & 11 deletions ExpTracker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Decal.Adapter;
using ACManager.Views;
using Decal.Adapter;
using System;
using System.Collections.Generic;
using System.Timers;
Expand All @@ -8,7 +9,9 @@ namespace ACManager
internal class ExpTracker : IDisposable
{
private FilterCore Filter { get; set; }
private CoreManager Core { get; set; }
internal CoreManager Core { get; set; }
internal ExpTrackerView ExpTrackerView { get; set; }
internal bool ViewVisible { get; set; } = true;
private Timer CalcXpTimer { get; set; }
private List<long> Rolling5Min { get; set; }
private DateTime LoginTime { get; set; }
Expand All @@ -27,11 +30,25 @@ public ExpTracker(FilterCore parent, CoreManager core)
{
Filter = parent;
Core = core;

LoadSettings();

ExpTrackerView = new ExpTrackerView(this);
Rolling5Min = new List<long>();
LoginTime = DateTime.Now;
StartTracking();
}

private void LoadSettings()
{
ViewVisible = Filter.Machine.Utility.GUISettings.ExpTrackerVisible;
}

public void ToggleView(bool isVisible)
{
ExpTrackerView.View.ShowInBar = isVisible;
}

public void Report()
{
string xpSinceReset = string.Format("{0:n0}", XpEarnedSinceReset);
Expand Down Expand Up @@ -96,7 +113,7 @@ public void Reset()
private void StartTracking()
{
TotalXpAtLogon = XpAtReset = Core.CharacterFilter.TotalXP;
Filter.ExpTrackerView.XpAtLogonText.Text = string.Format("{0:n0}", Core.CharacterFilter.TotalXP);
ExpTrackerView.XpAtLogonText.Text = string.Format("{0:n0}", Core.CharacterFilter.TotalXP);
LastResetTime = DateTime.Now;

CalcXpTimer = CreateTimer(1000);
Expand All @@ -119,29 +136,29 @@ private void UpdateXpOnInterval(object sender, ElapsedEventArgs e)

#region XP Event Triggers
XpPerHourLong = XpEarnedSinceReset / (long)TimeSinceReset.TotalSeconds * 3600;
Filter.ExpTrackerView.XpPerHourText.Text = string.Format("{0:n0}", XpPerHourLong);
ExpTrackerView.XpPerHourText.Text = string.Format("{0:n0}", XpPerHourLong);

Rolling5Min.Add(Core.CharacterFilter.TotalXP);
if (Rolling5Min.Count > 300) Rolling5Min.RemoveAt(0);

XpLast5Long = (Core.CharacterFilter.TotalXP - Rolling5Min[0]) / Rolling5Min.Count * 3600;
Filter.ExpTrackerView.XpLast5Text.Text = string.Format("{0:n0}", XpLast5Long);
ExpTrackerView.XpLast5Text.Text = string.Format("{0:n0}", XpLast5Long);

Filter.ExpTrackerView.XpSinceLogonText.Text = string.Format("{0:n0}", Core.CharacterFilter.TotalXP - TotalXpAtLogon);
ExpTrackerView.XpSinceLogonText.Text = string.Format("{0:n0}", Core.CharacterFilter.TotalXP - TotalXpAtLogon);

Filter.ExpTrackerView.XpSinceResetText.Text = string.Format("{0:n0}", XpEarnedSinceReset);
ExpTrackerView.XpSinceResetText.Text = string.Format("{0:n0}", XpEarnedSinceReset);
#endregion

#region Time Event Triggers
TimeSpan t = TimeSpan.FromSeconds((long)(Now - LoginTime).TotalSeconds);
Filter.ExpTrackerView.TimeLoggedInText.Text = string.Format("{0:D2}d {1:D2}h {2:D2}m {3:d2}s", t.Days, t.Hours, t.Minutes, t.Seconds);
ExpTrackerView.TimeLoggedInText.Text = string.Format("{0:D2}d {1:D2}h {2:D2}m {3:d2}s", t.Days, t.Hours, t.Minutes, t.Seconds);

t = TimeSpan.FromSeconds((long)TimeSinceReset.TotalSeconds);
Filter.ExpTrackerView.TimeSinceResetText.Text = string.Format("{0:D2}d {1:D2}h {2:D2}m {3:d2}s", t.Days, t.Hours, t.Minutes, t.Seconds);
ExpTrackerView.TimeSinceResetText.Text = string.Format("{0:D2}d {1:D2}h {2:D2}m {3:d2}s", t.Days, t.Hours, t.Minutes, t.Seconds);

TimeLeftToLevel = TimeSpan.FromSeconds((double)Core.CharacterFilter.XPToNextLevel / XpLast5Long * 3600);
t = TimeSpan.FromSeconds((long)TimeLeftToLevel.TotalSeconds);
Filter.ExpTrackerView.TimeToNextLevelText.Text = string.Format("{0:D2}d {1:D2}h {2:D2}m {3:d2}s", t.Days, t.Hours, t.Minutes, t.Seconds);
ExpTrackerView.TimeToNextLevelText.Text = string.Format("{0:D2}d {1:D2}h {2:D2}m {3:d2}s", t.Days, t.Hours, t.Minutes, t.Seconds);
#endregion
}

Expand All @@ -151,7 +168,8 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
CalcXpTimer.Close();
ExpTrackerView?.Dispose();
CalcXpTimer?.Close();
}
DisposedValue = true;
}
Expand Down
83 changes: 57 additions & 26 deletions FellowshipControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,65 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Timers;

namespace ACManager
{
internal class FellowshipControl
internal class FellowshipControl : IDisposable
{
private FilterCore Filter { get; set; }
private CoreManager Core { get; set; }
private List<Recruit> Recruits { get; set; } = new List<Recruit>();
internal FellowshipEventType FellowStatus { get; set; } = FellowshipEventType.Quit;
internal DateTime LastAttempt { get; set; } = DateTime.MinValue;
private Timer RecruitTimer { get; set; }
private bool disposedValue;

public FellowshipControl(FilterCore parent, CoreManager core)
{
Filter = parent;
Core = core;
Filter.MainView.AutoFellow.Checked = Filter.Machine.CurrentCharacter.AutoFellow;
if (string.IsNullOrEmpty(Filter.Machine.CurrentCharacter.Password))
RecruitTimer = new Timer
{
Filter.MainView.Password.Text = "xp";
Interval = 2000
};
RecruitTimer.Elapsed += RecruitTimer_Tick;
}

private void RecruitTimer_Tick(object sender, EventArgs e)
{
if (Recruits.Count > 0)
{
for (int i = 0; i < Recruits.Count; i++)
{
Recruits[i].Attempts += 1;
if (Recruits[i].Attempts >= 10)
{
Core.Actions.InvokeChatParser(string.Format("/t {0}, I wasn't able to recruit you into the fellowship, or you did not accept the invite.", Recruits[i].Name));
Remove(Recruits[i].Name);
}
else
{
Core.Actions.FellowshipRecruit(Recruits[i].Guid);
}
}
}
else
{
Filter.MainView.Password.Text = Filter.Machine.CurrentCharacter.Password;
StopTimer();
}
}

private void StartTimer()
{
RecruitTimer.Start();
}

private void StopTimer()
{
RecruitTimer.Stop();
}

public void ChatActions(object sender, ChatTextInterceptEventArgs e)
{
string message = Regex.Replace(e.Text, @"[^\w:/ ']", string.Empty);
Expand Down Expand Up @@ -119,6 +152,7 @@ public void ChatActions(object sender, ChatTextInterceptEventArgs e)
int targetGuid = int.Parse(match.Groups["guid"].Value);
Recruit recruit = new Recruit(name, targetGuid);
Recruits.Add(recruit);
StartTimer();
}
}
}
Expand All @@ -136,27 +170,6 @@ public void ChatActions(object sender, ChatTextInterceptEventArgs e)
}
}

public void CheckRecruit()
{
if (Recruits.Count > 0 && DateTime.Now - LastAttempt > TimeSpan.FromMilliseconds(2000))
{
LastAttempt = DateTime.Now;
for (int i = 0; i < Recruits.Count; i++)
{
Recruits[i].Attempts += 1;
if (Recruits[i].Attempts >= 10)
{
Core.Actions.InvokeChatParser(string.Format("/t {0}, I wasn't able to recruit you into the fellowship, or you did not accept the invite.", Recruits[i].Name));
Remove(Recruits[i].Name);
}
else
{
Core.Actions.FellowshipRecruit(Recruits[i].Guid);
}
}
}
}

private void Remove(string name)
{
for (int i = 0; i < Recruits.Count; i++)
Expand All @@ -181,5 +194,23 @@ public Recruit(string name, int guid)
Attempts = 0;
}
}

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
RecruitTimer?.Dispose();
}
disposedValue = true;
}
}

public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
Loading

0 comments on commit b61d9e4

Please sign in to comment.