forked from JackCeparou/JackCeparouCompass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRiftInfoPlugin.cs
373 lines (306 loc) · 13.4 KB
/
RiftInfoPlugin.cs
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
namespace Turbo.Plugins.Jack
{
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using Turbo.Plugins.Default;
public class RiftInfoPlugin : BasePlugin, IInGameTopPainter, IAfterCollectHandler, ICustomizer
{
public IFont ProgressBarTimerFont { get; set; }
public IFont ObjectiveProgressFont { get; set; }
public string ObjectiveProgressSymbol { get; set; }
public string GuardianAliveSymbol { get; set; }
public string GuardianDeadSymbol { get; set; }
public string SecondsFormat { get; set; }
public string MinutesSecondsFormat { get; set; }
public string ProgressPercentFormat { get; set; }
public string ClosingSecondsFormat { get; set; }
public bool GreaterRiftCountdown { get; set; }
public bool ShowGreaterRiftTimer { get; set; }
public bool ShowGreaterRiftCompletedTimer { get; set; }
public bool ShowClosingTimer { get; set; }
public int CompletionDisplayLimit { get; set; }
public Func<string> RiftCompletionTitleFunc { get; set; }
public TopLabelWithTitleDecorator CompletionLabelDecorator { get; set; }
public bool IsGuardianAlive
{
get
{
return riftQuest != null && (riftQuest.QuestStepId == 3 || riftQuest.QuestStepId == 16);
}
}
public bool IsGuardianDead
{
get
{
if (Hud.Game.Monsters.Any(m => m.Rarity == ActorRarity.Boss && !m.IsAlive))
return true;
return riftQuest != null && (riftQuest.QuestStepId == 5 || riftQuest.QuestStepId == 10 || riftQuest.QuestStepId == 34 || riftQuest.QuestStepId == 46);
}
}
public bool IsNephalemRift
{
get
{
return riftQuest != null && (riftQuest.QuestStepId == 1 || riftQuest.QuestStepId == 3 || riftQuest.QuestStepId == 10);
}
}
public bool IsGreaterRift
{
get
{
return riftQuest != null &&
(riftQuest.QuestStepId == 13 || riftQuest.QuestStepId == 16 || riftQuest.QuestStepId == 34 ||
riftQuest.QuestStepId == 46);
}
}
private bool show
{
get
{
if (riftQuest == null) return false;
if (riftQuest.State == QuestState.none) return false;
if (Hud.Inventory.InventoryMainUiElement.Visible) return false;
return true;
}
}
private const uint riftClosingMilliseconds = 30000;
private SpecialArea? currentRun;
private IQuest riftQuest
{
get
{
return Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 337492) ?? // rift
Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 382695); // gr
}
}
private IUiElement uiProgressBar
{
get
{
return IsNephalemRift ? Hud.Render.NephalemRiftBarUiElement : Hud.Render.GreaterRiftBarUiElement;
}
}
private IWatch riftTimer;
private IWatch guardianTimer;
private IWatch pauseTimer;
private const long greaterRiftMaxTime = 15 * 60 * 1000;
private readonly StringBuilder textBuilder;
public RiftInfoPlugin()
{
Enabled = true;
textBuilder = new StringBuilder();
}
private IBrush brus;
public override void Load(IController hud)
{
base.Load(hud);
brus = Hud.Render.CreateBrush(255, 0, 0, 0, 0);
ShowClosingTimer = false;
GreaterRiftCountdown = false;
ShowGreaterRiftTimer = true;
ShowGreaterRiftCompletedTimer = true;
CompletionDisplayLimit = 90;
ObjectiveProgressSymbol = "\u2694"; //⚔
GuardianAliveSymbol = "\uD83D\uDC7F"; //👿
GuardianDeadSymbol = "\uD83D\uDC80"; //💀
ObjectiveProgressSymbol = "";
GuardianAliveSymbol = "\uD83D\uDC7F"; //??
GuardianDeadSymbol = "\uD83D\uDC80"; //??uDC80"; //??
MinutesSecondsFormat = "{0:%m}:{0:ss}";
SecondsFormat = "{0:%s}";
ProgressPercentFormat = "({0:F1}%)";
ClosingSecondsFormat = "({0:%s})";
ProgressBarTimerFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 210, 150, true, false, 160, 0, 0, 0, true);
ObjectiveProgressFont = Hud.Render.CreateFont("tahoma", 8, 224, 240, 240, 240, false, false, false);
ObjectiveProgressFont.SetShadowBrush(222, 0, 0, 0, true);
RiftCompletionTitleFunc = () => riftQuest.QuestStep.SplashLocalized.Trim();
CompletionLabelDecorator = new TopLabelWithTitleDecorator(Hud)
{
BorderBrush = Hud.Render.CreateBrush(255, 180, 147, 109, -1),
BackgroundBrush = Hud.Render.CreateBrush(128, 0, 0, 0, 0),
TextFont = Hud.Render.CreateFont("tahoma", 9, 255, 255, 210, 150, true, false, false),
TitleFont = Hud.Render.CreateFont("tahoma", 6, 255, 180, 147, 109, true, false, false),
};
pauseTimer = Hud.CreateWatch();
riftTimer = Hud.CreateWatch();
guardianTimer = Hud.CreateWatch();
}
public void Customize()
{
Hud.TogglePlugin<NotifyAtRiftPercentagePlugin>(false);
}
public void PaintTopInGame(ClipState clipState)
{
if (clipState != ClipState.BeforeClip) return;
if (!show) return;
if (currentRun == null)
{
currentRun = IsNephalemRift ? SpecialArea.Rift : SpecialArea.GreaterRift;
}
if (Hud.Game.RiftPercentage >= CompletionDisplayLimit && Hud.Game.RiftPercentage < 100)
{
var text = Hud.Game.RiftPercentage.ToString("F1", CultureInfo.InvariantCulture) + "%";
var title = RiftCompletionTitleFunc.Invoke();
var layout = CompletionLabelDecorator.TextFont.GetTextLayout(title);
var w = layout.Metrics.Width * 0.8f;
var h = Hud.Window.Size.Height * 0.04f;
CompletionLabelDecorator.Paint(Hud.Window.Size.Width * 0.5f - w / 2, Hud.Window.Size.Height * 0.18f - h / 2, w, h, text, title);
}
if (IsNephalemRift && uiProgressBar.Visible)
{
var layout = ProgressBarTimerFont.GetTextLayout(GetText(true));
var x = uiProgressBar.Rectangle.Left - layout.Metrics.Width / 2 + uiProgressBar.Rectangle.Width * (float)Hud.Game.RiftPercentage / 100.0f;
var y = uiProgressBar.Rectangle.Bottom + uiProgressBar.Rectangle.Height * 0.1f;
ProgressBarTimerFont.DrawText(layout, x, y);
}
else
{
var layout = ObjectiveProgressFont.GetTextLayout(GetText(false));
var x = Hud.Render.MinimapUiElement.Rectangle.Right - layout.Metrics.Width - Hud.Window.Size.Height * 0.033f;
var y = Hud.Render.MinimapUiElement.Rectangle.Bottom + Hud.Window.Size.Height * 0.0033f;
//brus.DrawRectangle(x, y, 100, 100);
ObjectiveProgressFont.DrawText(layout, x, y);
var texture = Hud.Texture.GetTexture(currentRun == SpecialArea.Rift ? 1528804216 : 3075014090);
texture.Draw(x - texture.Width * 0.75f, Hud.Render.MinimapUiElement.Rectangle.Bottom - texture.Height/4, texture.Width, texture.Height);
}
}
public void AfterCollect()
{
if (ResetTimers()) return;
GuardianTimers();
if (GamePauseTimers()) return;
RestartStopTimers();
}
private void RestartStopTimers()
{
// (re)start/stop timers if needed
if (!riftTimer.IsRunning && !IsGuardianDead)
riftTimer.Start();
if (!guardianTimer.IsRunning && IsGuardianAlive)
guardianTimer.Start();
if (pauseTimer.IsRunning)
pauseTimer.Stop();
if (IsGreaterRift && IsGuardianDead && riftTimer.IsRunning)
riftTimer.Stop();
if (IsNephalemRift && riftQuest.State == QuestState.completed && riftTimer.IsRunning)
riftTimer.Stop();
}
private bool GamePauseTimers()
{
// game pause
if (Hud.Game.IsPaused || (IsGreaterRift && Hud.Game.NumberOfPlayersInGame == 1 && Hud.Game.IsLoading))
{
if (!pauseTimer.IsRunning)
pauseTimer.Start();
if (riftTimer.IsRunning)
riftTimer.Stop();
if (guardianTimer.IsRunning)
guardianTimer.Stop();
return true;
}
return false;
}
private void GuardianTimers()
{
// guardian
if (IsGuardianAlive)
{
if (!guardianTimer.IsRunning)
guardianTimer.Start();
}
else if (IsGuardianDead && guardianTimer.IsRunning)
{
guardianTimer.Stop();
}
}
private bool ResetTimers()
{
// reset states if needed
if (riftQuest == null || (riftQuest != null && riftQuest.State == QuestState.none))
{
if (riftTimer.IsRunning || riftTimer.ElapsedMilliseconds > 0)
{
riftTimer.Reset();
}
if (guardianTimer.IsRunning || guardianTimer.ElapsedMilliseconds > 0)
{
guardianTimer.Reset();
}
if (pauseTimer.IsRunning || pauseTimer.ElapsedMilliseconds > 0)
{
pauseTimer.Reset();
}
currentRun = null;
return true;
}
return false;
}
private string GetText(bool onlyTimer)
{
textBuilder.Clear();
SetTimerText(onlyTimer);
if (onlyTimer)
return textBuilder.ToString();
SetProgessText();
SetClosingTimerText();
return textBuilder.ToString();
}
private void SetClosingTimerText()
{
if (!ShowClosingTimer || IsGreaterRift || riftQuest.State != QuestState.completed) return;
textBuilder.Append(" ");
textBuilder.AppendFormat(ClosingSecondsFormat, TimeSpan.FromMilliseconds(riftClosingMilliseconds - riftQuest.CompletedOn.ElapsedMilliseconds));
}
private void SetProgessText()
{
if (Hud.Game.RiftPercentage < 100)
{
if ((!IsNephalemRift && uiProgressBar.Visible) || !(Hud.Game.RiftPercentage > 0.1)) return;
textBuilder.Append(" ");
textBuilder.AppendFormat(CultureInfo.InvariantCulture, ProgressPercentFormat, Hud.Game.RiftPercentage);
}
else if (IsGuardianAlive || IsGuardianDead || !guardianTimer.IsRunning)
{
textBuilder.Append(" ");
textBuilder.Append(IsGuardianAlive ? GuardianAliveSymbol : GuardianDeadSymbol);
var guardianTimeSpan = TimeSpan.FromMilliseconds(guardianTimer.ElapsedMilliseconds);
textBuilder.Append(" ");
textBuilder.AppendFormat(CultureInfo.InvariantCulture, (guardianTimeSpan.Minutes < 1) ? SecondsFormat : MinutesSecondsFormat, guardianTimeSpan);
}
}
private void SetTimerText(bool onlyTimer)
{
if (!onlyTimer && !string.IsNullOrWhiteSpace(ObjectiveProgressSymbol))
{
if (currentRun == SpecialArea.Rift)
{
textBuilder.Append(ObjectiveProgressSymbol);
textBuilder.Append(" ");
}
else if (currentRun == SpecialArea.GreaterRift &&
(ShowGreaterRiftTimer || !uiProgressBar.Visible || (ShowGreaterRiftCompletedTimer && IsGuardianDead)))
{
textBuilder.Append(ObjectiveProgressSymbol);
textBuilder.Append(" ");
}
}
if (currentRun == SpecialArea.GreaterRift)
{
if (ShowGreaterRiftTimer || !uiProgressBar.Visible || (ShowGreaterRiftCompletedTimer && IsGuardianDead))
{
var timeSpan = GreaterRiftCountdown && !IsGuardianDead
? TimeSpan.FromMilliseconds(greaterRiftMaxTime - riftTimer.ElapsedMilliseconds)
: TimeSpan.FromMilliseconds(riftTimer.ElapsedMilliseconds);
textBuilder.AppendFormat(CultureInfo.InvariantCulture, (timeSpan.Minutes < 1) ? SecondsFormat : MinutesSecondsFormat, timeSpan);
}
}
else
{
var timeSpan = TimeSpan.FromMilliseconds(riftQuest.StartedOn.ElapsedMilliseconds - riftQuest.CompletedOn.ElapsedMilliseconds - pauseTimer.ElapsedMilliseconds);
textBuilder.AppendFormat(CultureInfo.InvariantCulture, (timeSpan.Minutes < 1) ? SecondsFormat : MinutesSecondsFormat, timeSpan);
}
}
}
}