-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtil.cs
More file actions
168 lines (133 loc) · 5.55 KB
/
Util.cs
File metadata and controls
168 lines (133 loc) · 5.55 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
namespace Pluton.Rust
{
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using Pluton.Core;
using Objects;
using Serialize;
using Logger = Core.Logger;
using System.Collections;
public class Util : Core.Util
{
public Dictionary<string, Zone2D> zones = new Dictionary<string, Zone2D>();
public DataStore ZoneStore;
public DirectoryInfo UtilPath;
public Zone2D GetZone(string name)
{
if (zones.ContainsKey(name))
return zones[name];
return null;
}
public void SetZone(Zone2D zone)
{
if (zone == null)
throw new NullReferenceException("SetZone( zone )");
zones[zone.Name] = zone;
}
public Zone2D CreateZone(string name)
{
try {
GameObject obj = new GameObject(name);
GameObject gobj = UnityEngine.Object.Instantiate(obj, Vector3.zero, Quaternion.identity) as GameObject;
Zone2D zone = gobj.AddComponent<Zone2D>();
zone.Name = name;
zones[name] = zone;
return zone;
} catch (Exception ex) {
Logger.LogException(ex);
return null;
}
}
public void LoadZones()
{
try {
Logger.LogWarning("Loading zones.");
zones = new Dictionary<string, Zone2D>();
Hashtable zht = ZoneStore.GetTable("Zones");
if (zht == null)
return;
foreach (object zone in zht.Values) {
SerializedZone2D z = zone as SerializedZone2D;
if (z == null)
continue;
Logger.LogWarning("Zone found with name: " + z.Name);
z.ToZone2D();
}
} catch (Exception ex) {
Debug.LogException(ex);
}
}
public void SaveZones()
{
try {
Logger.LogWarning("Saving " + zones.Count + " zone.");
foreach (Zone2D zone in zones.Values) {
ZoneStore.Add("Zones", zone.Name, zone.Serialize());
}
} catch (Exception ex) {
Debug.LogException(ex);
}
}
public void ChangeTriggerRadius(TriggerBase trigger, float newRadius)
{
if (newRadius < 0f)
throw new InvalidOperationException(String.Format("Radius can't be less then zero. ChangeTriggerRadius({0}, {1})",
trigger,
newRadius));
trigger.GetComponent<SphereCollider>().radius = newRadius;
trigger.SendMessage("OnValidate", SendMessageOptions.DontRequireReceiver);
}
public void ConsoleLog(string str, bool adminOnly = false)
{
try {
foreach (Player player in Server.GetInstance().Players.Values) {
if (!adminOnly || (adminOnly && player.Admin))
player.ConsoleMessage(str);
}
} catch (Exception ex) {
Logger.LogDebug("ConsoleLog ex");
Logger.LogException(ex);
}
}
public LoadOut CreateLoadOut(string name) => new LoadOut(name);
public string GetLoadoutFolder() => Path.Combine(GetPublicFolder(), "LoadOuts");
public string GetStructuresFolder() => Path.Combine(GetPublicFolder(), "Structures");
public override string GetPublicFolder() => Path.Combine(GetIdentityFolder(), "Pluton");
public string GetIdentityFolder() => Path.Combine(GetRootFolder(), Path.Combine("server", ConVar.Server.identity));
public void DestroyEntity(BaseEntity ent) => ent.GetComponent<BaseNetworkable>().KillMessage();
public void DestroyEntityGib(BaseEntity ent) => ent.GetComponent<BaseNetworkable>().Kill(BaseNetworkable.DestroyMode.Gib);
public Vector3 Infront(Player p, float length) => p.Location + ((Vector3.forward * length));
new public void Initialize()
{
UtilPath = new DirectoryInfo(Path.Combine(GetPublicFolder(), "Util"));
ZoneStore = new DataStore("Zones.ds");
ZoneStore.Load();
LoadZones();
}
public IEnumerable<string> Prefabs()
{
if (Server.GetInstance().Loaded) {
foreach (string entity in FileSystem.FindAll("assets", ".prefab"))
yield return entity;
} else {
Logger.LogError("Util.Prefabs() should be only called after the server is loaded.");
}
}
public void Items()
{
string path = Path.Combine(GetPublicFolder(), "Items.ini");
if (!File.Exists(path))
File.AppendAllText(path, "");
IniParser ini = new IniParser(path);
foreach (ItemDefinition item in ItemManager.itemList) {
ini.AddSetting(item.displayName.english, "itemid", item.itemid.ToString());
ini.AddSetting(item.displayName.english, "category", item.category.ToString());
ini.AddSetting(item.displayName.english, "shortname", item.shortname);
ini.AddSetting(item.displayName.english, "description", item.displayDescription.english);
}
ini.Save();
}
}
}