-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCommandDestroy.cs
More file actions
77 lines (63 loc) · 2.83 KB
/
CommandDestroy.cs
File metadata and controls
77 lines (63 loc) · 2.83 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
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using SDG.Framework.Utilities;
using SDG.Unturned;
using System.Collections.Generic;
using UnityEngine;
namespace ExtraConcentratedJuice.BreakAndEnter
{
public class CommandDestroy : IRocketCommand
{
#region Properties
public AllowedCaller AllowedCaller => AllowedCaller.Player;
public string Name => "destroy";
public string Help => "Destroys the barricade or structure that you are looking at.";
public string Syntax => "/destroy";
public List<string> Aliases => new List<string>();
public List<string> Permissions => new List<string> { "breakandenter.destroy" };
#endregion
public void Execute(IRocketPlayer caller, string[] args)
{
Player player = ((UnturnedPlayer)caller).Player;
PlayerLook look = player.look;
if (PhysicsUtility.raycast(new Ray(look.aim.position, look.aim.forward), out RaycastHit hit, Mathf.Infinity, RayMasks.BARRICADE_INTERACT | RayMasks.STRUCTURE))
{
Interactable2SalvageBarricade barri = hit.transform.GetComponent<Interactable2SalvageBarricade>();
Interactable2SalvageStructure struc = hit.transform.GetComponent<Interactable2SalvageStructure>();
if (barri != null)
{
BarricadeDrop barr = BarricadeManager.FindBarricadeByRootTransform(barri.root);
var br = BarricadeManager.tryGetRegion(barri.root, out var x, out var y, out var plant, out _);
if (!br)
{
UnturnedChat.Say(caller, Util.Translate("invalid_destroy"));
return;
}
BarricadeManager.destroyBarricade(barr, x, y, plant);
UnturnedChat.Say(caller, Util.Translate("barricade_removed"));
}
else if (struc != null)
{
StructureDrop SD = StructureManager.FindStructureByRootTransform(hit.transform);
StructureManager.tryGetRegion(hit.transform, out var x, out var y, out StructureRegion sr);
if (sr == null)
{
UnturnedChat.Say(caller, Util.Translate("invalid_destroy"));
return;
}
StructureManager.destroyStructure(SD, x, y, Vector3.up);
UnturnedChat.Say(caller, Util.Translate("structure_removed"));
}
else
{
UnturnedChat.Say(caller, Util.Translate("invalid_destroy"));
}
}
else
{
UnturnedChat.Say(caller, Util.Translate("no_object"));
}
}
}
}