-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerminalCommands.cs
107 lines (96 loc) · 3.99 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using HarmonyLib;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
namespace Dark_Age_of_Valheim;
public static class TerminalCommands
{
private static bool isServer => SystemInfo.graphicsDeviceType
== GraphicsDeviceType.Null;
private static string modName => DarkAgeOfValheim.MOD_NAME;
private static Localization local => DarkAgeOfValheim.localization;
[HarmonyPatch(typeof(ZNetScene), nameof(ZNetScene.Awake))]
private static class ZrouteMethodsServerFeedback
{
private static void Postfix()
{
if (isServer) return;
//Increase player EXP by set amount.
ZRoutedRpc.instance.Register($"{modName} terminal_AddExperience",
new Action<long, int>(RPC_AddExperience));
}
}
private static void RPC_AddExperience(long sender, int amount)
{
terminalAddExperience(amount);
//Chat.instance.RPC_ChatMessage(200, Vector3.zero, 0, local["$notify"], String.Format(local["$terminal_add_experience"], amount), PrivilegeManager.GetNetworkUserId());
}
public static void terminalAddExperience(int amount)
{
EpicMMOSystem.LevelSystem.Instance.AddExp(amount);
}
[HarmonyPatch(typeof(Terminal), nameof(Terminal.InitTerminal))]
public class AddChatCommands
{
[HarmonyPriority(Priority.Low)]
private static void Postfix()
{
long? getPlayerId(string name)
{
var clearName = name.Replace('&', ' ');
var players = ZNet.instance.GetPlayerList();
foreach (var playerInfo in players)
{
if (playerInfo.m_name == clearName)
{
return playerInfo.m_characterID.m_userID;
}
}
return null;
}
_ = new Terminal.ConsoleCommand("DarkAgeOfValheim", "Manages admin commands for DAoV.",
(Terminal.ConsoleEvent)(
args =>
{
//if (!DarkAgeOfValheim.ConfigSync.IsAdmin)
//{
// if (ZNet.instance.IsServer())
// {
// }
// else
// {
// args.Context.AddString("You are not an admin on this server.");
// return;
// }
//}
switch (args[1])
{
case "add_exp":
{
int amount = Int32.Parse(args[2]);
string name = args[3];
if (args.Length > 4)
{
for (var i = 4; i < args.Length; i++)
{
name += " " + args[i];
}
}
var userId = getPlayerId(name);
if (userId == null)
{
DarkAgeOfValheim.print("Player is not found");
}
ZRoutedRpc.instance.InvokeRoutedRPC(userId ?? 200, $"{modName} terminal_AddExperience", amount);
break;
}
default: break;
}
args.Context.AddString("set_exp [value] [name] - add experience to player character");
}),
optionsFetcher: () => new List<string>
{ "add_exp" });
}
}
}