|
| 1 | +using Rocket.API; |
| 2 | +using Rocket.Unturned.Chat; |
| 3 | +using Rocket.Unturned.Player; |
| 4 | +using SDG.Unturned; |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Linq; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using UnityEngine; |
| 11 | + |
| 12 | +namespace Ekin.EACFOB |
| 13 | +{ |
| 14 | + public class CommandFobDeploy : IRocketCommand |
| 15 | + { |
| 16 | + public AllowedCaller AllowedCaller => AllowedCaller.Player; |
| 17 | + |
| 18 | + public string Name => "fobcreate"; |
| 19 | + |
| 20 | + public string Help => ""; |
| 21 | + |
| 22 | + public string Syntax => ""; |
| 23 | + |
| 24 | + public List<string> Aliases => new List<string>(); |
| 25 | + |
| 26 | + public List<string> Permissions => new List<string>(); |
| 27 | + |
| 28 | + public void Execute(IRocketPlayer caller, string[] command) |
| 29 | + { |
| 30 | + UnturnedPlayer uplayer = (UnturnedPlayer)caller; |
| 31 | + float time = Time.time; |
| 32 | + var INST = EACFOBPlugin.Instance; |
| 33 | + if(INST.CanDeployFob) |
| 34 | + {if (INST.LastFobKurTime.ContainsKey(uplayer)) |
| 35 | + { |
| 36 | + float num = INST.LastFobKurTime[uplayer]; |
| 37 | + if (time - num < (float)INST.Configuration.Instance.createfobcooldown && !uplayer.IsAdmin)// COOLDOWN CONFIGE ATILACAK |
| 38 | + { |
| 39 | + int num2 = (int)(EACFOBPlugin.Instance.Configuration.Instance.createfobcooldown - (time - num)); |
| 40 | + UnturnedChat.Say(caller, string.Format("You have to wait {0} seconds for establishing next fob.", num2)); |
| 41 | + return; |
| 42 | + } |
| 43 | + } |
| 44 | + if (command.Length < 1) |
| 45 | + { |
| 46 | + UnturnedChat.Say(caller, "How to use: /fobcreate <team> <name>"); |
| 47 | + UnturnedChat.Say(caller, "Teams: " + INST.Configuration.Instance.team1type + ", " + INST.Configuration.Instance.team2type ); |
| 48 | + return; |
| 49 | + } |
| 50 | + string text = command[0].ToLower(); |
| 51 | + string key = command[1].ToLower(); |
| 52 | + if (text != INST.Configuration.Instance.team1type.ToLower() && text != INST.Configuration.Instance.team2type.ToLower()) |
| 53 | + { |
| 54 | + UnturnedChat.Say(caller, "Invalid Team"); |
| 55 | + UnturnedChat.Say(caller, "Teams: " + INST.Configuration.Instance.team1type + ", " + INST.Configuration.Instance.team2type); |
| 56 | + return; |
| 57 | + } |
| 58 | + if (!IRocketPlayerExtension.HasPermission(uplayer, text)) // AND A2 TEAM |
| 59 | + { |
| 60 | + UnturnedChat.Say(caller, "You dont have " + text + " Permission."); |
| 61 | + return; |
| 62 | + } |
| 63 | + if (INST.Fobs.ContainsKey(key)) |
| 64 | + { |
| 65 | + UnturnedChat.Say(caller, "There is a FOB with this name."); |
| 66 | + return; |
| 67 | + } |
| 68 | + Vector3 position = uplayer.Position; |
| 69 | + Quaternion rotation = uplayer.Player.transform.rotation; |
| 70 | + |
| 71 | + ItemBarricadeAsset bar1 = (ItemBarricadeAsset)Assets.find((EAssetType)1, INST.Configuration.Instance.fobobjectid); |
| 72 | + if (!INST.Configuration.Instance.samefob) |
| 73 | + { |
| 74 | + if(text == INST.Configuration.Instance.team1type) bar1 = (ItemBarricadeAsset)Assets.find((EAssetType)1, INST.Configuration.Instance.team1fobobjectid); |
| 75 | + if(text == INST.Configuration.Instance.team2type) bar1 = (ItemBarricadeAsset)Assets.find((EAssetType)1, INST.Configuration.Instance.team2fobobjectid); |
| 76 | + |
| 77 | + |
| 78 | + } |
| 79 | + if (bar1 == null) |
| 80 | + { |
| 81 | + UnturnedChat.Say(caller, "Failed to find Flag Asset, check configuration."); |
| 82 | + return; |
| 83 | + } |
| 84 | + Barricade bar2 = new Barricade(bar1); |
| 85 | + Vector3 pos = new Vector3(position.x, position.y + INST.Configuration.Instance.fobobjectYadjust, position.z); |
| 86 | + Transform tran = BarricadeManager.dropBarricade(bar2, null, pos, 0f, 0f, 0f, uplayer.CSteamID.m_SteamID, 99); |
| 87 | + BarricadeDrop barD = null; |
| 88 | + float inf = float.MaxValue; |
| 89 | + BarricadeRegion[,] regions = BarricadeManager.regions; |
| 90 | + foreach (BarricadeRegion uplayer7 in regions) |
| 91 | + { |
| 92 | + foreach (BarricadeDrop drop in uplayer7.drops) |
| 93 | + { |
| 94 | + float dis = Vector3.Distance(drop.model.position, position); |
| 95 | + if (dis < inf) |
| 96 | + { |
| 97 | + inf = dis; |
| 98 | + barD = drop; |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + if (barD != null && inf < 2f + INST.Configuration.Instance.fobobjectYadjust) |
| 103 | + { |
| 104 | + INST.Fobs[key] = new FobData(position, (ushort)barD.instanceID, command[1], uplayer.CharacterName, text.ToUpper()); |
| 105 | + INST.LastFobKurTime[uplayer] = time; |
| 106 | + UnturnedChat.Say(caller, text.ToUpper() + " FOB " + command[1] + " succsefully established!"); |
| 107 | + } |
| 108 | + else |
| 109 | + { |
| 110 | + UnturnedChat.Say(caller, text.ToUpper() + " FOB " + command[1] + " failed to established!"); |
| 111 | + } |
| 112 | + } |
| 113 | + else |
| 114 | + { |
| 115 | + UnturnedChat.Say(caller, "Deploying fob is not active"); |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments