Exemplo n.º 1
0
        protected override async UniTask OnExecuteAsync()
        {
            var user = (UnturnedUser)Context.Actor;
            var look = user.Player.Player.look;

            await UniTask.SwitchToMainThread();

            if (!PhysicsUtility.raycast(new(look.getEyesPosition(), look.aim.forward),
                                        out var hit, 8f, RayMasks.BARRICADE | RayMasks.STRUCTURE | RayMasks.VEHICLE))
            {
                return;
            }

            var vehicle = hit.collider.GetComponent <InteractableVehicle>();

            if (vehicle != null)
            {
                VehicleManager.askVehicleDestroy(vehicle);
                return;
            }

            if (BarricadeManager.tryGetInfo(hit.transform, out var x, out var y, out var plant, out var index, out var region))
            {
                BarricadeManager.destroyBarricade(region, x, y, plant, index);
                return;
            }

            if (StructureManager.tryGetInfo(hit.transform, out x, out y, out index, out var structureRegion))
            {
                StructureManager.destroyStructure(structureRegion, x, y, index, Vector3.zero);
                return;
            }

            await PrintAsync(m_StringLocalizer["destroy:invalid"]);
        }
Exemplo n.º 2
0
        public static bool DestroyObject(this Transform transform)
        {
            if (transform == null)
            {
                return(false);
            }

            var vehicle = transform.GetComponent <InteractableVehicle>();

            if (vehicle != null)
            {
                VehicleManager.askVehicleDestroy(vehicle);
                return(true);
            }

            if (transform.GetComponent <InteractableDoorHinge>() != null)
            {
                transform = transform.parent;
            }

            if (BarricadeManager.tryGetInfo(transform, out var x, out var y, out var plant, out var index, out var r))
            {
                BarricadeManager.destroyBarricade(r, x, y, plant, index);
                return(true);
            }

            if (!StructureManager.tryGetInfo(transform, out x, out y, out index, out var s))
            {
                return(false);
            }

            StructureManager.destroyStructure(s, x, y, index, transform.position);

            return(true);
        }
Exemplo n.º 3
0
        public void Execute(IRocketPlayer caller, string[] command)
        {
            UnturnedPlayer player   = (UnturnedPlayer)caller;
            string         homeName = command.ElementAtOrDefault(0);

            if (homeName == null)
            {
                UnturnedChat.Say(caller, pluginInstance.Translate("DestroyHomeFormat"), pluginInstance.MessageColor);
                return;
            }

            PlayerHome home = HomesHelper.GetPlayerHome(player.CSteamID, homeName);

            if (home == null)
            {
                UnturnedChat.Say(caller, pluginInstance.Translate("HomeNotFound", home.Name), pluginInstance.MessageColor);
                return;
            }

            if (!HomesHelper.TryRemoveHome(player.CSteamID, home.InteractableBed) || home.InteractableBed == null)
            {
                return;
            }



            BarricadeManager.tryGetInfo(home.InteractableBed.transform, out var x, out var y, out var plant, out var index, out var region);
            if (home.InteractableBed != null)
            {
                BarricadeManager.destroyBarricade(region, x, y, plant, index);
            }

            UnturnedChat.Say(caller, pluginInstance.Translate("DestroyHomeSuccess", home.Name), pluginInstance.MessageColor);
        }
Exemplo n.º 4
0
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        #endregion

        #region Coroutines

        private IEnumerator C4DetonateCoroutine()
        {
            EffectManager.sendEffect(45, byte.MaxValue, byte.MaxValue, byte.MaxValue, Drop.model.position);
            ExplosionParameters parameters = new ExplosionParameters(Drop.model.position, 150f, EDeathCause.KILL, CSteamID.Nil);

            parameters.penetrateBuildables = true;
            parameters.playerDamage        = 150;
            parameters.damageRadius        = 64;
            parameters.barricadeDamage     = 1000;
            List <EPlayerKill> deadPlayers = new List <EPlayerKill>();

            DamageTool.explode(parameters, out deadPlayers);

            byte            x;
            byte            y;
            ushort          plant;
            ushort          index;
            BarricadeRegion region;

            if (!BarricadeManager.tryGetInfo(Drop.model.transform, out x, out y, out plant, out index, out region))
            {
                yield return(null);
            }

            BarricadeManager.destroyBarricade(region, x, y, plant, index);
            Defused = true; // quick fix to prevent time ticking
            C4Manager.ActiveC4.Remove(this);

            yield return(null);
        }
Exemplo n.º 5
0
        public void Destroy()
        {
            if (!BarricadeManager.tryGetInfo(InteractableBed.transform, out var x, out var y, out var plant, out var index, out var region))
            {
                return;
            }

            BarricadeManager.destroyBarricade(region, x, y, plant, index);
        }
Exemplo n.º 6
0
        public void Execute(IRocketPlayer caller, string[] command)
        {
            if (command.Length >= 1)
            {
                ulong PlayerID;
                if (ulong.TryParse(command[0], out ulong ResID))
                {
                    PlayerID = ResID;
                }
                else
                {
                    UnturnedPlayer uPlayer = UnturnedPlayer.FromName(command[0]);
                    if (uPlayer == null)
                    {
                        UnturnedChat.Say(caller, "Failed to find player");
                        return;
                    }
                    else
                    {
                        PlayerID = uPlayer.CSteamID.m_SteamID;
                    }
                }
                ushort BID = 0;
                if (command.Length >= 2 && ushort.TryParse(command[1], out ushort ResBID))
                {
                    BID = ResBID;
                }

                List <KeyValuePair <BarricadeRegion, BarricadeData> > WipeList = new List <KeyValuePair <BarricadeRegion, BarricadeData> >();
                foreach (BarricadeRegion BRegion in BarricadeManager.regions)
                {
                    foreach (BarricadeData B in BRegion.barricades)
                    {
                        if (B.owner == PlayerID && ((BID == 0) || (B.barricade.id == BID)))
                        {
                            WipeList.Add(new KeyValuePair <BarricadeRegion, BarricadeData>(BRegion, B));
                        }
                    }
                }
                UnturnedChat.Say(caller, $"Found {WipeList.Count} buildables; wiping...");
                foreach (var ent in WipeList)
                {
                    if (Regions.tryGetCoordinate(ent.Value.point, out byte x, out byte y))
                    {
                        ushort plant = ushort.MaxValue;
                        ushort index = (ushort)ent.Key.barricades.IndexOf(ent.Value);
                        BarricadeManager.destroyBarricade(ent.Key, x, y, plant, index);
                    }
                }
                UnturnedChat.Say(caller, $"Destroyed {WipeList.Count} Buildables.");
            }
            else
            {
                UnturnedChat.Say(caller, Syntax);
            }
        }
 public static void RunDestroyTool(UnturnedPlayer Player, RaycastResult Raycast)
 {
     if (Raycast.Vehicle != null)
     {
         bool IsPlayersVehicle = Raycast.Vehicle.lockedOwner == Player.CSteamID || Raycast.Vehicle.lockedGroup == Player.SteamGroupID;
         bool Allow            = IsPlayersVehicle;
         if (!IsPlayersVehicle)
         {
             Allow = PlayerCanDestroyOtherPlayersStuff(Player);
         }
         if (Allow)
         {
             VehicleManager.askVehicleDestroy(Raycast.Vehicle);
         }
         else
         {
             UnturnedChat.Say(Player, "PointTool_Destroy_Denied".Translate());
         }
     }
     if (Raycast.Barricade != null)
     {
         bool IsPlayersBarricade = Raycast.Barricade.owner == Player.CSteamID.m_SteamID || Raycast.Barricade.group == Player.SteamGroupID.m_SteamID;
         bool Allow = IsPlayersBarricade;
         if (!IsPlayersBarricade)
         {
             Allow = PlayerCanDestroyOtherPlayersStuff(Player);
         }
         if (Allow)
         {
             BarricadeManager.destroyBarricade(Raycast.BarricadeRegion, Raycast.BarricadeX, Raycast.BarricadeY, Raycast.BarricadePlant, Raycast.BarricadeIndex);
         }
         else
         {
             UnturnedChat.Say(Player, "PointTool_Destroy_Denied".Translate());
         }
     }
     if (Raycast.Structure != null)
     {
         bool IsPlayersStructure = Raycast.Structure.owner == Player.CSteamID.m_SteamID || Raycast.Structure.group == Player.SteamGroupID.m_SteamID;
         bool Allow = IsPlayersStructure;
         if (!IsPlayersStructure)
         {
             Allow = PlayerCanDestroyOtherPlayersStuff(Player);
         }
         if (Allow)
         {
             StructureManager.destroyStructure(Raycast.StructureRegion, Raycast.StructureX, Raycast.StructureY, Raycast.StructureIndex, new Vector3(0, 0, 0));
         }
         else
         {
             UnturnedChat.Say(Player, "PointTool_Destroy_Denied".Translate());
         }
     }
 }
Exemplo n.º 8
0
        /// <inheritdoc />
        public override void UnsafeDestroy()
        {
            ThreadUtil.assertIsGameThread();
            if (!BarricadeManager.tryGetInfo(Model, out var x, out var y, out var plant, out var index,
                                             out var bRegion))
            {
                return;
            }

            BarricadeManager.destroyBarricade(bRegion, x, y, plant, index);
        }
Exemplo n.º 9
0
        public override Task DestroyAsync()
        {
            async UniTask DestroyTask()
            {
                await UniTask.SwitchToMainThread();

                if (BarricadeManager.tryGetInfo(BarricadeDrop.model, out var x, out var y, out var plant, out var index, out var region))
                {
                    BarricadeManager.destroyBarricade(region, x, y, plant, index);
                }
            }

            return(DestroyTask().AsTask());
        }
Exemplo n.º 10
0
        private IEnumerator HealthStationExpiredCoroutine()
        {
            byte            x;
            byte            y;
            ushort          plant;
            ushort          index;
            BarricadeRegion region;

            if (!BarricadeManager.tryGetInfo(Drop.model.transform, out x, out y, out plant, out index, out region))
            {
                yield return(null);
            }

            BarricadeManager.destroyBarricade(region, x, y, plant, index);
            Expired = true;
            C4Manager.ActiveHealthStations.Remove(this);

            yield return(null);
        }
Exemplo n.º 11
0
        public override Task DestroyAsync()
        {
            async UniTask DestroyTask()
            {
                await UniTask.SwitchToMainThread();

                if (BarricadeDrop.GetNetId().IsNull())
                {
                    return;
                }

                if (BarricadeManager.tryGetRegion(BarricadeDrop.model, out var x, out var y, out var plant, out _))
                {
                    BarricadeManager.destroyBarricade(BarricadeDrop, x, y, plant);
                }
            }

            return(DestroyTask().AsTask());
        }
Exemplo n.º 12
0
        public void Execute(IRocketPlayer caller, string[] command)
        {
            var player      = (UnturnedPlayer)caller;
            var raycastInfo =
                DamageTool.raycast(new Ray(player.Player.look.aim.position, player.Player.look.aim.forward), 10f,
                                   RayMasks.VEHICLE);
            var baseClusteringPlugin = BaseClusteringPlugin.Instance;

            if (baseClusteringPlugin == null)
            {
                throw new NullReferenceException("BaseClusteringPlugin.Instance is null. Cannot execute command.");
            }

            if (raycastInfo.vehicle == null)
            {
                UnturnedChat.Say(caller, baseClusteringPlugin.Translate("no_vehicle_found"));
                return;
            }

            if (raycastInfo.vehicle.isDead)
            {
                UnturnedChat.Say(caller, baseClusteringPlugin.Translate("vehicle_dead"));
                return;
            }

            if (!BarricadeManager.tryGetPlant(raycastInfo.transform, out var x, out var y, out var plant,
                                              out var region))
            {
                UnturnedChat.Say(caller, baseClusteringPlugin.Translate("vehicle_no_plant"));
                return;
            }

            for (var i = region.barricades.Count - 1; i > 0; i--)
            {
                BarricadeManager.destroyBarricade(region, x, y, plant, (ushort)i);
            }

            UnturnedChat.Say(caller,
                             baseClusteringPlugin.Translate("vehicle_wreck",
                                                            raycastInfo.vehicle.asset.vehicleName ?? raycastInfo.vehicle.asset.name,
                                                            raycastInfo.vehicle.id, raycastInfo.vehicle.instanceID,
                                                            raycastInfo.vehicle.lockedOwner.ToString()));
        }
        public static bool Prefix(CSteamID steamID, byte x, byte y, ushort plant, ushort index, BarricadeManager __instance)
        {
            BarricadeRegion region;

            BarricadeManager.tryGetRegion(x, y, plant, out region);
            uint UID = region.barricades[index].instanceID;

            C4Manager.ActiveC4.ToList().ForEach(c4 =>
            {
                if (c4.Drop.instanceID == UID)
                {
                    c4.Defused = true;
                    InterfaceManager.SendEffectLocationUnsafe(61, c4.Drop.model.position);
                    BarricadeManager.destroyBarricade(region, x, y, plant, index);
                    C4Manager.ActiveC4.Remove(c4);
                }
            });
            return(false);
        }
        public bool Destroy()
        {
            var vector = BarricadeLocation.ToVector3();

            if (!Regions.tryGetCoordinate(vector, out byte x, out byte y))
            {
                return(true);
            }
            var region = BarricadeManager.regions[x, y];
            var drop   = region.drops.FirstOrDefault(c => c.instanceID == InstanceId);
            var barr   = region.barricades.FirstOrDefault(c => c.instanceID == InstanceId);

            if (drop == null || barr.barricade.isDead) //Not found
            {
                return(false);
            }

            BarricadeManager.destroyBarricade(region, x, y, ushort.MaxValue, (ushort)region.drops.IndexOf(drop));

            return(true);
        }