-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.cs
More file actions
146 lines (127 loc) · 4.74 KB
/
Copy pathAPI.cs
File metadata and controls
146 lines (127 loc) · 4.74 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
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Thor;
using UnderCheat;
using UnityEngine;
using BepInEx;
namespace Undercheat
{
internal class API
{
public static GameData Data => GameData.Instance;
private static Game Game => Game.Instance;
private static Simulation Simulation => Game.Simulation;
static readonly int MinPage = 1;
static readonly int MaxPage = 4;
public static int CurrentPage = MinPage;
public static int DiscoverTabItemIndex = 0;
public static bool IsProton = BepInEx.Paths.ConfigPath.Contains("Z:\\");
public static int next_page()
{
int page = CurrentPage;
page++;
if (MaxPage < page || MinPage > page)
{
page = MinPage;
}
return page;
}
public static string CapitalizedSpace(string text)
{
bool firstMatch = true;
string result = Regex.Replace(text, @"[A-Z]", match =>
{
if (firstMatch)
{
firstMatch = false;
return $"{match.Value}";
}
else
{
return $" {match.Value}";
}
});
return result;
}
public static int wrap_index(int index, int maxIndex)
{
return ((index % maxIndex) + maxIndex) % maxIndex;
}
public static ItemData GetItemDataIndex(int index)
{
var relics = Data.RelicCollection;
index = wrap_index(index, relics.Count);
var item = relics[index];
if (item is ItemData itemData)
{
return itemData;
}
return null;
}
public static void PrintRelicList(bool discoveredOnly)
{
foreach (var item in Data.RelicCollection)
{
if (!(item is ItemData itemData)) { break; }
if (discoveredOnly)
{
if (!itemData.IsDiscovered) { break; }
Debug.Log($"{UnderCheatBase.ModGuid}: Relic: {itemData.name}");
}
else
{
Debug.Log($"{UnderCheatBase.ModGuid}: Relic: {itemData.name}");
}
}
}
public static Entity SpawnRelic(ItemData data, Vector3 position)
{
try
{
if (data == null)
{
Debug.LogWarning($"{UnderCheatBase.ModGuid}: Item's Data cannot be null!");
return null;
}
var prefab = Data.GetItemTemplate(data);
if (prefab == null)
{
Debug.LogWarning($"{UnderCheatBase.ModGuid}: Could not find item template for: " + data.name);
return null;
}
using (new ItemExt.ItemDataScope(data))
{
var entity = Simulation.SpawnEntity(prefab, position, Quaternion.identity, -1, null);
Debug.Log($"{UnderCheatBase.ModGuid}: Created new relic with name : `{data.name}`");
var mover = entity.GetExtension<MoverExt>();
if (mover == null)
return entity;
entity.transform.position += Vector3.up;
var normalized = Rand.InsideUnitCircle.normalized;
var point = new Vector3(normalized.x * Rand.Range(2f, 6f), 0.0f, normalized.y * Rand.Range(2f, 4f));
var walkable = Simulation.GetNearestWalkablePosition(entity.transform.LocalToWorldPoint(point), entity.AgentTypeID);
mover.Launch(walkable, Rand.Range(4, 5), 75f, false);
return entity;
}
}
catch (Exception e)
{
Debug.LogError($"{UnderCheatBase.ModGuid}: Error occurred while spawning relic: " + e);
return null;
}
}
public static ItemData GetRelic(string name)
{
var dataObject = Data.RelicCollection.FirstOrDefault(i => i.name.Equals(name, StringComparison.OrdinalIgnoreCase));
if (dataObject == null)
{
Debug.LogWarning($"{UnderCheatBase.ModGuid}: Item with name '{name}' not found.");
return null;
}
if (dataObject is ItemData itemData) { return itemData; }
Debug.LogWarning($"{UnderCheatBase.ModGuid}: DataObject '{name}' is not an ItemData.");
return null;
}
}
}