-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoorsSystem.cs
More file actions
162 lines (141 loc) · 5.46 KB
/
DoorsSystem.cs
File metadata and controls
162 lines (141 loc) · 5.46 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
extern alias UnityEngineCoreModule;
using HordeServer;
using Rocket.Core.Logging;
using Rocket.Core.Utils;
using Rocket.Unturned.Player;
using SDG.Unturned;
class DoorSystem
{
/// <summary>
/// All doors will change ownership to the most proximity player
/// THIS IS NECESSARY BECAUSE ONLY THE GOD DAMN OWNER CAN SALVAGE THE F**** BARRICADE
/// </summary>
static public void RefreshOwnerships()
{
BarricadeRegion[,] regions = BarricadeManager.regions;
int sizeX = regions.GetLength(0);
int sizeY = regions.GetLength(1);
for (int x = 0; x < sizeX; x++)
{
for (int y = 0; y < sizeY; y++)
{
BarricadeRegion region = regions[x, y];
foreach (var drop in region.drops)
{
var barricade = drop.asset;
var transform = drop.model?.transform;
if (transform == null)
continue;
UnturnedPlayer? nearestPlayer = null;
float nearestDistance = float.MaxValue;
if (HordeServerPlugin.instance!.Configuration.Instance.DebugBarricadesPosition)
Logger.Log($"{transform.position} / {transform.rotation}");
foreach (UnturnedPlayer player in HordeServerPlugin.alivePlayers)
{
float actualDistance = UnityEngineCoreModule.UnityEngine.Vector3.Distance(transform.position, player.Position);
if (actualDistance < nearestDistance)
{
nearestPlayer = player;
nearestDistance = actualDistance;
}
}
if (nearestPlayer != null)
{
TaskDispatcher.QueueOnMainThread(() =>
{
BarricadeManager.changeOwnerAndGroup(transform, nearestPlayer.CSteamID.m_SteamID, 0);
});
}
}
}
}
}
static public void TryOpenDoor(BarricadeDrop barricade, SteamPlayer instigatorClient, ref bool shouldAllow)
{
UnityEngineCoreModule.UnityEngine.Vector3? position = barricade.model?.transform?.position;
UnturnedPlayer player = UnturnedPlayer.FromSteamPlayer(instigatorClient);
if (position == null || player == null) return;
Door? door = null;
foreach (Door mapDoor in HordeServerPlugin.instance!.Configuration.Instance.AvailableDoorsToPurchase)
{
if (mapDoor.pos == position && mapDoor.assetId == barricade.asset.id)
{
door = mapDoor;
break;
}
}
if (door == null) return;
if (player.Experience < door.cost)
{
shouldAllow = false;
ChatManager.serverSendMessage(
HordeServerPlugin.instance!.Translate("not_enough_money", door.cost),
new UnityEngineCoreModule.UnityEngine.Color(0, 255, 0),
null,
player.SteamPlayer(),
EChatMode.SAY,
HordeServerPlugin.instance!.Configuration.Instance.ChatIconURL,
true
);
return;
}
player.Experience -= (uint)door.cost;
foreach (UnturnedPlayer onlinePlayer in HordeServerPlugin.onlinePlayers)
{
if (onlinePlayer.CSteamID.m_SteamID == player.CSteamID.m_SteamID)
{
ChatManager.serverSendMessage(
HordeServerPlugin.instance!.Translate("door_open", door.cost),
new UnityEngineCoreModule.UnityEngine.Color(0, 255, 0),
null,
onlinePlayer.SteamPlayer(),
EChatMode.SAY,
HordeServerPlugin.instance!.Configuration.Instance.ChatIconURL,
true
);
}
else
{
ChatManager.serverSendMessage(
HordeServerPlugin.instance!.Translate("door_opened", player.DisplayName, door.cost),
new UnityEngineCoreModule.UnityEngine.Color(0, 255, 0),
null,
onlinePlayer.SteamPlayer(),
EChatMode.SAY,
HordeServerPlugin.instance!.Configuration.Instance.ChatIconURL,
true
);
}
}
}
static public void RespawnDoors()
{
BarricadeManager.askClearAllBarricades();
foreach (var door in HordeServerPlugin.instance!.Configuration.Instance.AvailableDoorsToPurchase)
{
if (Assets.find(EAssetType.ITEM, door.assetId) is not ItemBarricadeAsset asset)
{
Rocket.Core.Logging.Logger.LogError($"Asset {door.assetId} not found.");
continue;
}
Barricade barricade = new(asset)
{
health = ushort.MaxValue
};
BarricadeManager.dropNonPlantedBarricade(
barricade,
door.pos,
door.rotation,
0,
0
);
}
}
}
public class Door
{
public UnityEngineCoreModule.UnityEngine.Vector3 pos;
public UnityEngineCoreModule.UnityEngine.Quaternion rotation;
public int cost;
public ushort assetId = 30;
}