-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathTaskManager.cs
More file actions
145 lines (132 loc) · 5.05 KB
/
TaskManager.cs
File metadata and controls
145 lines (132 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Copyright 2012 HighVoltz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Collections.ObjectModel;
using System.Linq;
using HighVoltz.HBRelog.Honorbuddy;
using HighVoltz.HBRelog.Tasks;
using HighVoltz.HBRelog.WoW;
namespace HighVoltz.HBRelog
{
sealed public class TaskManager : IManager
{
public readonly ObservableCollection<BMTask> Tasks;
public readonly WowManager WowManager;
public readonly HonorbuddyManager HonorbuddyManager;
public CharacterProfile Profile { get; set; }
public bool StartupSequenceIsComplete { get; private set; }
public event EventHandler<ProfileEventArgs> OnStartupSequenceIsComplete;
public bool IsRunning { get; private set; }
public BMTask CurrentTask { get; private set; }
public TaskManager(CharacterProfile profile)
{
Profile = profile;
WowManager = new WowManager(profile);
HonorbuddyManager = new HonorbuddyManager(profile);
Tasks = profile.Tasks;
StartupSequenceIsComplete = IsRunning = false;
HonorbuddyManager.OnStartupSequenceIsComplete += HonorbuddyManager_OnStartupSequenceIsComplete;
}
void HonorbuddyManager_OnStartupSequenceIsComplete(object sender, ProfileEventArgs e)
{
Profile.Log("WoW and HB startup sequence complete");
Profile.Status = "Running";
if (!StartupSequenceIsComplete)
{
StartupSequenceIsComplete = true;
if (OnStartupSequenceIsComplete != null)
OnStartupSequenceIsComplete(this, new ProfileEventArgs(Profile));
}
}
public void Pulse()
{
if (WowManager.IsRunning)
{
WowManager.Pulse();
if (WowManager.InGame && !HonorbuddyManager.IsRunning)
{
if (!StartupSequenceIsComplete)
HonorbuddyManager.SetSettings(Profile.Settings.HonorbuddySettings);
HonorbuddyManager.Start();
}
if (HonorbuddyManager.IsRunning)
HonorbuddyManager.Pulse();
}
// only pulse tasks if StartupSequenceIsComplete is true.
if (StartupSequenceIsComplete)
{
PulseTasks();
}
}
private void PulseTasks()
{
if (!Tasks.Any())
return;
// reset tasks if they're all complete
if (Tasks.All(t => t.IsDone))
{
foreach (var task in Tasks)
task.Reset();
}
// get the 1st task that isn't done and pulse it.
CurrentTask = Tasks.FirstOrDefault(t => !t.IsDone);
if (CurrentTask != null)
{
if (!CurrentTask.IsRunning)
CurrentTask.Start();
CurrentTask.Pulse();
if (CurrentTask is WaitTask && CurrentTask.IsRunning)
Profile.TaskTooltip = CurrentTask.ToolTip;
else if (!string.IsNullOrEmpty(Profile.TaskTooltip))
Profile.TaskTooltip = null;
}
}
public void Start()
{
// display tasks in log for debugin purposes
if (!StartupSequenceIsComplete)
{
Profile.Log("********* Tasks ***********");
foreach (var task in Profile.Tasks)
{
// the tooltip for Logon Task can contain character name so lets just print the name of task to log instead.
if (task is LogonTask)
Profile.Log(task.Name);
else
Profile.Log(task.ToolTip);
}
Profile.Log("********* End of Task list ***********");
}
// check if idle is 1st task.
bool idleIs1stTask = Profile.Tasks.Count > 0 && Profile.Tasks[0] is IdleTask;
if (!WowManager.IsRunning && !idleIs1stTask)
{
WowManager.SetSettings(Profile.Settings.WowSettings);
WowManager.Start();
}
else if (idleIs1stTask)
StartupSequenceIsComplete = true;
IsRunning = true;
}
public void Stop()
{
Profile.Status = "Stopped";
StartupSequenceIsComplete = false;
WowManager.Stop();
HonorbuddyManager.Stop();
foreach (var task in Tasks)
task.Reset();
IsRunning = false;
}
}
}