-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZoneSystemExtension.cs
80 lines (67 loc) · 2.85 KB
/
ZoneSystemExtension.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
using System.Threading.Tasks;
namespace JFUtils;
public static class ZoneSystemExtension
{
internal static List<Vector3> tempPoints = new();
internal static bool creatingValidPlacesForLocation;
internal static string creatingPlacesFor = "";
public static void SetGlobalKey(this ZoneSystem zoneSystem, string key, object value) =>
zoneSystem.SetGlobalKey($"{key} {value}");
public static string GetGlobalKeyValue(this ZoneSystem zoneSystem, string key)
{
zoneSystem.GetGlobalKey(key, out var value);
return value;
}
public static string GetOrAddGlobalKey(this ZoneSystem zoneSystem, string key, string defaultValue)
{
if (zoneSystem.GetGlobalKey(key, out var value)) return value;
zoneSystem.SetGlobalKey(key, defaultValue);
return defaultValue;
}
public static (Vector2i, LocationInstance)[] GetGeneratedLocationsByName(this ZoneSystem zoneSystem,
string key) =>
instance.m_locationInstances
.Where(x => x.Value.m_location.m_prefabName == key)
.Select(x => (x.Key, x.Value))
.ToArray();
public static List<Vector3> CreateValidPlacesForLocation(this ZoneSystem zoneSystem, string key, int count)
{
tempPoints.Clear();
var location = instance.GetLocation(key);
if (location == null)
{
DebugWarning($"Could not find location with name '{key}'");
return null;
}
creatingPlacesFor = location.m_prefabName;
creatingValidPlacesForLocation = true;
var haldorLocationsVanillaCount = location.m_quantity;
location.m_quantity = count;
var isUnique = location.m_unique;
location.m_unique = false;
instance.GenerateLocations(location);
location.m_quantity = haldorLocationsVanillaCount;
location.m_unique = isUnique;
creatingPlacesFor = string.Empty;
creatingValidPlacesForLocation = false;
return tempPoints;
}
public static Task<List<ZDO>> GetWorldObjectsAsync(this ZoneSystem zoneSystem,
params Func<ZDO, bool>[] customFilters)
{
List<ZDO> zdos = new List<ZDO>(ZDOMan.instance.m_objectsByID.Values);
return Task.Run(() =>
{
if (customFilters != null && customFilters.Length != 0)
zdos = zdos.Where(x => customFilters.All(filter => filter?.Invoke(x) ?? true)).ToList();
return zdos;
});
}
public static async Task<List<ZDO>> GetWorldObjectsAsync(this ZoneSystem zoneSystem, string prefabName,
params Func<ZDO, bool>[] customFilters)
{
int prefabHash = prefabName.GetStableHashCode();
Func<ZDO, bool> prefabFilter = zdo => zdo.GetPrefab() == prefabHash;
return await zoneSystem.GetWorldObjectsAsync(customFilters.Concat(new[] { prefabFilter }).ToArray());
}
}