-
Notifications
You must be signed in to change notification settings - Fork 0
/
TerminalCommands.cs
88 lines (69 loc) · 3.57 KB
/
TerminalCommands.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
using HarmonyLib;
// ReSharper disable VariableHidesOuterVariable ObjectCreationAsStatement
namespace ChallengeChest;
[HarmonyPatch]
public static class TerminalCommands
{
[HarmonyPatch(typeof(Terminal), nameof(Terminal.InitTerminal))]
[HarmonyPostfix]
private static void AddCommands()
{
new Terminal.ConsoleCommand(ModName,
"Info", args => RunCommand(args =>
{
args.Context.AddString($"{ModName} by {ModAuthor} v{ModVersion}");
args.Context.AddString($"Available commands:");
foreach (var commandName in new List<string>
{
ModName.ToLower(), "startchallenge", "startchallengehere", "finishchallengehere",
"finishchallengeall"
})
{
var command = Terminal.commands[commandName.ToLower()];
args.Context.AddString($"\t{commandName.ToLower()} - {command.Description}");
}
args.Context.AddString("Done");
}, args), true);
new Terminal.ConsoleCommand("startchallenge",
"Start the Challenge Chest at randomly generated position", args => RunCommand(args =>
{
if (!IsAdmin) throw new ConsoleCommandException("You are not an admin on this server");
ZRoutedRpc.instance.InvokeRoutedRPC("cc_SpawnBossTerminalNoPos");
args.Context.AddString("Done");
}, args), true);
new Terminal.ConsoleCommand("startchallengehere",
"Start the Challenge Chest at current player position", args => RunCommand(args =>
{
if (!IsAdmin) throw new ConsoleCommandException("You are not an admin on this server");
var pos = m_localPlayer.transform.position.RoundCords();
ZRoutedRpc.instance.InvokeRoutedRPC("cc_SpawnBossTerminal", (double)pos.x, (double)pos.z);
args.Context.AddString("Done");
}, args), true);
new Terminal.ConsoleCommand("finishchallengeall",
"Finish all Challenge Chests in world", args => RunCommand(async args =>
{
if (!IsAdmin) throw new ConsoleCommandException("You are not an admin on this server");
while (EventSpawn.EventDatas.Count > 0)
{
var data = EventSpawn.EventDatas.FirstOrDefault();
if (data is null) break;
args.Context.AddString($"Processing event \"{data}\"");
var eventPos = data.pos.ToVector2();
ZRoutedRpc.instance.InvokeRoutedRPC("cc_HandleChallengeDone", (double)eventPos.x,
(double)eventPos.y);
var oldCount = EventSpawn.EventDatas.Count;
do await Task.Delay(100);
while (EventSpawn.EventDatas.Count == oldCount);
}
args.Context.AddString("Done");
}, args), true);
new Terminal.ConsoleCommand("finishchallengehere",
"Finish the Challenge Chest in the current player zone/chunk/sector", args => RunCommand(args =>
{
if (!IsAdmin) throw new ConsoleCommandException("You are not an admin on this server");
var pos = m_localPlayer.transform.position.ToV2();
ZRoutedRpc.instance.InvokeRoutedRPC("cc_HandleChallengeDone", (double)pos.x, (double)pos.y);
args.Context.AddString("Done");
}, args), true);
}
}