-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUtils.cs
More file actions
116 lines (106 loc) · 3.98 KB
/
Copy pathUtils.cs
File metadata and controls
116 lines (106 loc) · 3.98 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
using System.Text;
using System.Text.RegularExpressions;
using lib.remnant2.analyzer.Enums;
using lib.remnant2.analyzer.Model;
namespace lib.remnant2.analyzer;
public partial class Utils
{
public static string Capitalize(string word)
{
return string.Join(' ', word.Split('_').Select(x => x[..1].ToUpper() + x[1..].ToLower()));
}
public static string FormatCamelAsWords(string word)
{
return string.Join(' ', RegexSplitAtCapitals().Split(word).Select(x => x.Trim('_')));
}
public static string GetNameFromProfileId(string profileId)
{
int dot = profileId.LastIndexOf('.');
if (dot > -0)
{
profileId = profileId[..dot];
}
int slash = profileId.LastIndexOf('/');
if (slash == -1)
{
return profileId;
}
return profileId.Substring(slash + 1, profileId.Length - slash - 1);
}
public static bool IsKnownInventoryItem(string item)
{
string[] patterns = [
"^GemContainer_.*",
"^Item_DragonHeartUpgrade$",
"^Item_Flashlight$",
//"^Item_HiddenContainer_.*",
"^Item_HiddenContainer_(?!Material_Engram_).*",
"^Material_HiddenContainer_Simulacrum$",
"^Material_TomeOfKnowledge$",
"^Perk_.*",
"^PrimePerk_.*",
"^Quest_Hidden_Item_.*",
"^Quest_Item_DLC_DreamLevel$",
"^SkillTrait_.*",
"^Weapon_Unarmed$",
"^Relic_Charge_Pickup$",
"^Armor_.*_Default$"
];
Regex r = new(string.Join('|', patterns));
return r.IsMatch(item);
}
public static string FormatPlaytime(TimeSpan? tp)
{
return tp.HasValue ? $"{(int)tp.Value.TotalHours}:{tp.Value.Minutes:D2}:{tp.Value.Seconds:D2}" : "Unknown";
}
public static string FormatRelicFragmentLevel(string name, int level)
{
int quality = (level - 1) / 5;
int modifier = (level - 1) % 5;
RelicFragmentLevel rfl = (RelicFragmentLevel)quality;
string modSting = modifier == 0 ? "" : $" +{modifier}";
return $"{rfl} {name}{modSting}";
}
// This is used for formatting long guns, handguns, melee weapons and relics and their attachments
public static string FormatEquipmentSlot(
string slotType, // Long Gun, Handgun, Melee Weapon or Relic
string itemType, // weapon, mod, specialmod (e.g. built-in), mutator, fragment or prism
int itemLevel,
string itemName
)
{
slotType = FormatCamelAsWords(slotType);
StringBuilder sb = new();
sb.Append(slotType);
if (!string.IsNullOrEmpty(slotType)) sb.Append(' ');
if (itemType == "specialmod" || itemType == "mod" || itemType == "mutator" || itemType == "fragment" || itemType == "prism")
{
// If this is an attachment, add the attachment type to the slot type
string formatted = itemType == "specialmod" ? "Special Mod" : Capitalize(itemType);
sb.Append($"{formatted}");
}
sb.Append(": ");
if (itemType == "fragment")
{
sb.Append(FormatRelicFragmentLevel(itemName, itemLevel));
sb.Append($" (lvl {itemLevel})");
return sb.ToString();
}
sb.Append(itemName);
if ((itemType == "mutator" || itemType == "weapon") && itemLevel > 0)
{
sb.Append($" +{itemLevel}");
}
return sb.ToString();
}
public static bool ItemAcquiredFilter(string profileId)
{
LootItem? l = ItemDb.GetItemByProfileId(profileId);
if (l == null) return false;
if (l.Type == "trait") return true;
if (!Analyzer.InventoryTypes.Contains(l.Type)) return false;
return true;
}
[GeneratedRegex("(?<!^)(?=[A-Z])")]
private static partial Regex RegexSplitAtCapitals();
}