-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHelpers.cs
More file actions
385 lines (304 loc) · 10.1 KB
/
Copy pathHelpers.cs
File metadata and controls
385 lines (304 loc) · 10.1 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
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
374
375
376
377
378
379
380
381
382
383
384
385
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
using Dalamud.Game.ClientState.Party;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Info;
using Lumina.Excel.Sheets;
using Lumina.Text;
using Lumina.Text.ReadOnly;
using WTSync.Models;
namespace WTSync;
internal static class Helpers {
public static readonly Vector4 BLACK = new Vector4(0, 0, 0, 1f);
public static readonly Vector4 BAR_GREEN = new Vector4(0x00, 0xCC / 255f, 0x22 / 255f, 0xFF / 255f);
public static readonly Vector4 BAR_ORANGE = new Vector4(0xFF / 255f, 0x7B / 255f, 0x1A / 255f, 1f);
private static bool HasLoggedAVE;
internal static string? ToSha256(this string input) {
if (string.IsNullOrEmpty(input))
return string.Empty;
try {
byte[] buffer = Encoding.UTF8.GetBytes(input);
byte[] digest = SHA256.HashData(buffer);
return Convert.ToHexString(digest);
} catch (AccessViolationException ex) {
if (!HasLoggedAVE) {
Service.Logger.Error($"There was an error while trying to hash a string. Details:\n{ex}");
HasLoggedAVE = true;
}
return null;
}
}
internal static string? ToId(this FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember member) {
return $"{member.NameString}@{member.HomeWorld}".ToSha256();
}
internal static string? ToId(this IPartyMember member) {
return $"{member.Name}@{member.World.RowId}".ToSha256();
}
internal static string? ToId(this CrossRealmMember member) {
return $"{member.NameString}@{member.HomeWorld}".ToSha256();
}
internal static string ToInstanceNumber(this int input) {
if (input < 0) return $"{input}";
return ToInstanceNumber((uint) input);
}
internal static string ToInstanceNumber(this uint input) {
if (input == 0 || input > 9)
return $"{input}";
char converted = Convert.ToChar(0xE0B0 + input);
return converted.ToString();
}
internal static string ToBoxedNumber(this int input) {
if (input < 0) return $"{input}";
return ToBoxedNumber((uint) input);
}
internal static string ToBoxedNumber(this uint input) {
if (input > 31)
return $"{input}";
char converted = Convert.ToChar(0xE08F + input);
return converted.ToString();
}
internal static string Abbreviate(string input, uint mode) {
if (mode == 0)
return input;
string[] names = input.Split(' ');
if (names[1].Length > 1 && (mode == 1 || mode == 3))
names[1] = string.Concat(names[1][..1], ".");
if (names[0].Length > 1 && (mode == 2 || mode == 3))
names[0] = string.Concat(names[0][..1], ".");
return string.Concat(names[0], " ", names[1]);
}
internal static string ToTitleCase(this string input) {
if (input.StartsWith("the "))
return string.Concat("T", input[1..]);
return input;
// While we could do this, we only want to capitalize any initial "The"
//return CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(input);
}
internal static string ToTitleCase(this ReadOnlySeString input) {
return input.ToString().ToTitleCase();
}
internal static string ToTitleCase(this Dalamud.Game.Text.SeStringHandling.SeString input) {
return input.ToString().ToTitleCase();
}
internal static Dictionary<uint, List<ContentFinderCondition>> OrderConditions { get; } = [];
internal static Dictionary<uint, (byte, byte)> OrderLevelRanges { get; } = [];
private static List<ContentFinderCondition>? Dungeons { get; set; }
private static List<ContentFinderCondition>? Alliances { get; set; }
private static List<ContentFinderCondition>? Raids { get; set; }
private static List<ContentFinderCondition>? Trials { get; set; }
private static Dictionary<uint, ContentFinderCondition>? ConditionByInstance { get; set; }
[MemberNotNull(nameof(ConditionByInstance))]
[MemberNotNull(nameof(Dungeons))]
[MemberNotNull(nameof(Alliances))]
[MemberNotNull(nameof(Raids))]
[MemberNotNull(nameof(Trials))]
private static void LoadConditionsByInstance() {
if (ConditionByInstance != null && Dungeons != null && Alliances != null && Raids != null && Trials != null)
return;
ConditionByInstance = [];
Dungeons = [];
Alliances = [];
Raids = [];
Trials = [];
var conditionSheet = Service.DataManager.GetExcelSheet<ContentFinderCondition>();
if (conditionSheet == null)
return;
foreach (var cond in conditionSheet) {
if (cond.ContentType.RowId == 2)
Dungeons.Add(cond);
//if (cond.ContentType.RowId == 5) {
if (cond.AllianceRoulette)
Alliances.Add(cond);
else if (cond.NormalRaidRoulette)
// TODO: Check for Binding of Coil?
Raids.Add(cond);
//}
//if (cond.ContentType.RowId == 4 && cond.ContentMemberType.RowId == 3) {
if (cond.TrialRoulette)
Trials.Add(cond);
//}
if (cond.ContentLinkType != 1)
continue;
ConditionByInstance.TryAdd(cond.Content.RowId, cond);
}
}
internal static (WeeklyBingoOrderData, PlayerState.WeeklyBingoTaskStatus)? GetMatchingEntry(WTStatus status) {
var sheet = Service.DataManager.GetExcelSheet<WeeklyBingoOrderData>();
if (sheet == null)
return null;
uint current = Service.ClientState.TerritoryType;
foreach (var duty in status.Duties) {
if (!sheet.TryGetRow(duty.Id, out var row))
continue;
var conds = GetConditionsForEntry(row);
foreach (var cond in conds) {
if (cond.TerritoryType.RowId == current)
return (row, duty.Status);
}
}
return null;
}
internal static List<ContentFinderCondition> GetConditionsForEntry(WeeklyBingoOrderData entry) {
if (OrderConditions.TryGetValue(entry.RowId, out List<ContentFinderCondition>? conditions))
return conditions;
conditions = [];
var sheet = Service.DataManager.GetExcelSheet<ContentFinderCondition>();
if (sheet == null)
return conditions;
LoadConditionsByInstance();
uint min;
uint max;
switch (entry.Type) {
case 0:
// Specific Thing
if (ConditionByInstance.TryGetValue(entry.Data.RowId, out var cond))
conditions.Add(cond);
break;
case 1:
// Dungeons (exact level)
foreach (var dungeon in Dungeons) {
if (dungeon.ClassJobLevelRequired == entry.Data.RowId)
conditions.Add(dungeon);
}
break;
case 2:
// Dungeons (preceeding levels)
max = entry.Data.RowId;
min = entry.Unknown2;
min = entry.Data.RowId - 8;
//max = entry.Data.RowId - 0;
//if (max == 49)
// min = 1;
foreach (var dungeon in Dungeons) {
uint lvl = dungeon.ClassJobLevelRequired;
if (lvl >= min && lvl <= max)
conditions.Add(dungeon);
}
break;
case 3:
// Special Instances
switch (entry.Data.RowId) {
case 5: // Crystaline Conflict
foreach (var thing in sheet) {
if (thing.ContentType.RowId == 6 && (thing.ContentMemberType.RowId == 29 || thing.ContentMemberType.RowId == 30))
conditions.Add(thing);
}
break;
case 6: // Frontline
foreach (var thing in sheet) {
if (thing.ContentType.RowId == 6 && thing.ContentMemberType.RowId == 7)
conditions.Add(thing);
}
break;
case 9: // Deep Dungeons
foreach (var thing in sheet) {
if (thing.ContentType.RowId == 21)
conditions.Add(thing);
}
break;
case 10: // Treasure Dungeons
foreach (var thing in sheet) {
if (thing.ContentType.RowId == 9)
conditions.Add(thing);
}
break;
case 12: // Rival Wings
foreach (var thing in sheet) {
if (thing.ContentType.RowId == 6 && thing.ContentMemberType.RowId == 18)
conditions.Add(thing);
}
break;
}
break;
case 4:
// Multiple Order Data
var orderSheet = Service.DataManager.GetExcelSheet<WeeklyBingoMultipleOrder>();
if (orderSheet != null && orderSheet.TryGetRow(entry.Data.RowId, out var orderData)) {
conditions.AddRange(
orderData.Content
.Where(x => x.IsValid && x.RowId != 0)
.Select(x => x.Value.ContentFinderCondition)
.Where(x => x.IsValid && x.RowId != 0)
.Select(x => x.Value)
);
}
break;
case 5:
// Leveling Dungeons (preceeding levels)
max = entry.Data.RowId;
min = entry.Unknown2;
foreach (var dungeon in Dungeons) {
uint lvl = dungeon.ClassJobLevelRequired;
// Any dungeon in the level range in leveling roulette.
if (lvl >= min && lvl <= max && dungeon.LevelingRoulette)
conditions.Add(dungeon);
}
break;
case 6:
// High-Level Dungeons
max = entry.Data.RowId;
min = entry.Unknown2;
foreach (var dungeon in Dungeons) {
uint lvl = dungeon.ClassJobLevelRequired;
// Any dungeon within that level range in the high-level roulette.
if (lvl >= min && lvl <= max && (dungeon.HighLevelRoulette || dungeon.ExpertRoulette))
conditions.Add(dungeon);
}
break;
case 7:
// Trials
max = entry.Data.RowId;
min = entry.Unknown2;
foreach (var trial in Trials) {
uint lvl = trial.ClassJobLevelRequired;
// Any trial within that level range
if (lvl >= min && lvl <= max)
conditions.Add(trial);
}
break;
case 8:
// Alliances
max = entry.Data.RowId;
min = entry.Unknown2;
foreach (var alliance in Alliances) {
uint lvl = alliance.ClassJobLevelRequired;
if (lvl >= min && lvl <= max)
conditions.Add(alliance);
}
break;
case 9:
// Raids
max = entry.Data.RowId;
min = entry.Unknown2;
foreach (var raid in Raids) {
uint lvl = raid.ClassJobLevelRequired;
if (lvl >= min && lvl <= max)
conditions.Add(raid);
}
break;
}
byte minLevel = byte.MaxValue;
byte maxLevel = byte.MinValue;
foreach (var cond in conditions) {
byte lvl = cond.ContentType.RowId == 9 ? cond.ClassJobLevelSync : cond.ClassJobLevelRequired;
if (lvl > maxLevel)
maxLevel = lvl;
if (lvl < minLevel)
minLevel = lvl;
}
conditions.Sort((a, b) => {
if (a.ClassJobLevelRequired != b.ClassJobLevelRequired)
return a.ClassJobLevelRequired.CompareTo(b.ClassJobLevelRequired);
return a.SortKey.CompareTo(b.SortKey);
});
OrderConditions[entry.RowId] = conditions;
OrderLevelRanges[entry.RowId] = (minLevel, maxLevel);
return conditions;
}
}