Exemple #1
0
        /// <summary>
        /// Updates a warpplates dimension destination
        /// </summary>
        /// <param name="args">The command arguments</param>
        public async void SetWarpplateDimension(CommandArgs args)
        {
            string region = "";

            if (args.Parameters.Count == 3)
            {
                region = args.Parameters[1];
            }
            else if (args.Parameters.Count == 2)
            {
                region = Manager.InAreaWarpplateName(args.Player.TileX, args.Player.TileY);
            }
            else
            {
                args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /wp dim [<warpplate name>] <dimension name>");
                args.Player.SendErrorMessage("Type /wp dim [<warpplate name>] \"\" to set dimension to none");
                return;
            }

            Warpplate warpplate = Manager.GetWarpplateByName(region);

            if (warpplate == null)
            {
                args.Player.SendErrorMessage("No such warpplate");
                return;
            }

            // Get Dimension Name from parameters
            string dimension = args.Parameters[args.Parameters.Count - 1];

            warpplate.Destination = dimension;

            // Set type to 0 (non-dimensional) if the specified name was empty
            if (dimension.Length == 0)
            {
                warpplate.Type = 0;
            }
            else
            {
                warpplate.Type = 1;
            }

            // Update warpplate in DB
            if (await Manager.SetDestination(warpplate.Name, dimension, warpplate.Type))
            {
                if (warpplate.Type == 0)
                {
                    args.Player.SendSuccessMessage(String.Format("Removed Dimension Destination from {0}", warpplate.Name));
                }
                else
                {
                    args.Player.SendSuccessMessage(String.Format("Set Dimension Destination of {0} to {1}", warpplate.Name, dimension));
                }
            }
            else
            {
                args.Player.SendErrorMessage("Something went wrong");
            }
        }
        public async Task <bool> SetDestination(Warpplate warpplate, string warpplateDestination, int type = 0)
        {
            int result = await Query("UPDATE Warpplates SET WarpplateDestination=@0, Type=@3 WHERE WarpplateName=@1 AND WorldID=@2;", warpplateDestination, warpplate.Name, Main.worldID.ToString(), type);

            warpplate.Destination = warpplateDestination;

            return(result > 0);
        }
        public async Task <bool> DeleteWarpplate(Warpplate warpplate)
        {
            if (warpplate != null)
            {
                int result = await Query("DELETE FROM Warpplates WHERE WarpplateName=@0 AND WorldID=@1", warpplate.Name, Main.worldID.ToString());

                return(result > 0);
            }
            return(false);
        }
        /// <summary>
        /// Sets a warpplates destination
        /// </summary>
        /// <param name="name">The name of the warpplate to set the destination of</param>
        /// <returns>Whether or not setting the destination was successful</returns>
        public async Task <bool> SetDestination(string warpplateName, string warpplateDestination, int type = 0)
        {
            Warpplate warpplate = GetWarpplateByName(warpplateName);

            if (warpplate != null)
            {
                return(await Database.SetDestination(warpplate, warpplateDestination, type));
            }

            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Resizes a warpplate
        /// </summary>
        /// <param name="args">The command arguments</param>
        public async void SetWarpplateSize(CommandArgs args)
        {
            string region = "";

            if (args.Parameters.Count == 4)
            {
                region = args.Parameters[1];
            }
            else if (args.Parameters.Count == 3)
            {
                region = Manager.InAreaWarpplateName(args.Player.TileX, args.Player.TileY);
            }
            else
            {
                args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /wp resize [<warpplate name>] <width> <height>");
                return;
            }

            Warpplate warpplate = Manager.GetWarpplateByName(region);

            if (warpplate == null)
            {
                args.Player.SendErrorMessage("No such warpplate");
                return;
            }

            int Width, Height;

            if (Int32.TryParse(args.Parameters[args.Parameters.Count - 2], out Width) &&
                Int32.TryParse(args.Parameters[args.Parameters.Count - 1], out Height))
            {
                Rectangle area;
                area           = warpplate.Area;
                area.Width     = Width;
                area.Height    = Height;
                warpplate.Area = area;

                await Manager.UpdateWarpplate(warpplate.Name);

                if (await Manager.UpdateWarpplate(warpplate.Name))
                {
                    args.Player.SendSuccessMessage("Set size of {0} to {1}x{2}", warpplate.Name, Width, Height);
                }
                else
                {
                    args.Player.SendErrorMessage("Something went wrong");
                }
            }
            else
            {
                args.Player.SendErrorMessage("Bad number specified");
            }
        }
        /// <summary>
        /// Gets the label of the given warpplate
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetLabel(String name)
        {
            Warpplate warpplate = GetWarpplateByName(name);

            if (String.IsNullOrEmpty(warpplate.Label))
            {
                return(name);
            }
            else
            {
                return(warpplate.Label);
            }
        }
        /// <summary>
        /// Resizes a warpplates height
        /// </summary>
        /// <param name="args">The command arguments</param>
        public async void SetWarpplateHeight(CommandArgs args)
        {
            string region = "";

            if (args.Parameters.Count == 2)
            {
                region = args.Parameters[0];
            }
            else if (args.Parameters.Count == 1)
            {
                region = Manager.InAreaWarpplateName(args.Player.TileX, args.Player.TileY);
            }
            else
            {
                args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /swph [<warpplate name>] <height in blocks>");
                return;
            }

            Warpplate warpplate = Manager.GetWarpplateByName(region);

            if (warpplate == null)
            {
                args.Player.SendErrorMessage("No such warpplate");
                return;
            }

            int Height;

            if (Int32.TryParse(args.Parameters[args.Parameters.Count - 1], out Height))
            {
                Rectangle area;
                area           = warpplate.Area;
                area.Height    = Height;
                warpplate.Area = area;

                await Manager.UpdateWarpplate(warpplate.Name);

                if (await Manager.UpdateWarpplate(warpplate.Name))
                {
                    args.Player.SendSuccessMessage("Set height of {0} to {1} blocks", warpplate.Name, Height);
                }
                else
                {
                    args.Player.SendErrorMessage("Something went wrong");
                }
            }
            else
            {
                args.Player.SendErrorMessage("Bad number specified");
            }
        }
Exemple #8
0
        /// <summary>
        /// Updates or gives a warpplate a delay
        /// </summary>
        /// <param name="args">The command arguments</param>
        public async void SetWarpplateDelay(CommandArgs args)
        {
            // Use the given warpplate name or find the warpplate they are standing in
            string region = "";

            if (args.Parameters.Count == 3)
            {
                region = args.Parameters[1];
            }
            else if (args.Parameters.Count == 2)
            {
                region = Manager.InAreaWarpplateName(args.Player.TileX, args.Player.TileY);
            }
            else
            {
                args.Player.SendErrorMessage("Invalid syntax! Proper synatx: /wp delay [<warpplate name>] <delay in seconds>");
                args.Player.SendErrorMessage("Set 0 for immediate warp");
                return;
            }

            // Check if the warpplate exists
            Warpplate warpplate = Manager.GetWarpplateByName(region);

            if (warpplate == null)
            {
                args.Player.SendErrorMessage("No such warpplate");
                return;
            }

            // Update the delay of the given warpplate
            int Delay;

            if (int.TryParse(args.Parameters[args.Parameters.Count - 1], out Delay))
            {
                warpplate.Delay = Delay + 1;
                if (await Manager.UpdateWarpplate(warpplate.Name))
                {
                    args.Player.SendSuccessMessage("Set delay of {0} to {1} seconds", warpplate.Name, Delay);
                }
                else
                {
                    args.Player.SendErrorMessage("Something went wrong");
                }
            }
            else
            {
                args.Player.SendErrorMessage("Bad number specified");
            }
        }
        public async Task <bool> SetWarpplateState(Warpplate warpplate, bool state)
        {
            try
            {
                int result = await Query("UPDATE Warpplates SET Protected=@0 WHERE WarpplateName=@1 AND WorldID=@2", state? 1 : 0, warpplate.Name, Main.worldID.ToString());

                return(result > 0);
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }

            return(false);
        }
Exemple #10
0
 /// <summary>
 /// Checks whether the user can warp and warps them to the dimension of the warpplate
 /// </summary>
 /// <param name="warpplate">The warpplate they are attempting to use</param>
 private void CheckAndUseDimensionWarpplate(Warpplate warpplate)
 {
     TimeStandingOnWarpplate++;
     if ((warpplate.Delay - TimeStandingOnWarpplate) > 0)
     {
         TSPlayer.SendInfoMessage("Shifting to " + warpplate.Label + " in " + (warpplate.Delay - TimeStandingOnWarpplate) + " seconds");
     }
     else
     {
         SendToDimension(warpplate.Destination);
         TimeStandingOnWarpplate = 0;
         HasJustUsedWarpplate    = true;
         WarpplateUseCooldown    = 3;
     }
 }
Exemple #11
0
        /// <summary>
        /// Resizes a warpplate's width
        /// </summary>
        /// <param name="args">The command arguments</param>
        public async void SetWarpplateWidth(CommandArgs args)
        {
            string region = "";

            if (args.Parameters.Count == 3)
            {
                region = args.Parameters[1];
            }
            else if (args.Parameters.Count == 2)
            {
                region = Manager.InAreaWarpplateName(args.Player.TileX, args.Player.TileY);
            }
            else
            {
                args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /wp width [<warpplate name>] <width in blocks>");
                return;
            }

            Warpplate warpplate = Manager.GetWarpplateByName(region);

            if (warpplate == null)
            {
                args.Player.SendErrorMessage("No such warpplate");
                return;
            }

            int Width;

            if (Int32.TryParse(args.Parameters[args.Parameters.Count - 1], out Width))
            {
                Rectangle r;
                r              = warpplate.Area;
                r.Width        = Width;
                warpplate.Area = r;
                if (await Manager.UpdateWarpplate(warpplate.Name))
                {
                    args.Player.SendSuccessMessage("Set width of {0} to {1} blocks", warpplate.Name, Width);
                }
                else
                {
                    args.Player.SendErrorMessage("Something went wrong");
                }
            }
            else
            {
                args.Player.SendErrorMessage("Invalid number: " + args.Parameters[args.Parameters.Count - 1]);
            }
        }
        public async Task <bool> UpdateWarpplate(Warpplate warpplate)
        {
            try
            {
                int result = await Query("UPDATE Warpplates SET width=@0, height=@1, Delay=@2, Label=@3 WHERE WarpplateName=@4 AND WorldID=@5",
                                         warpplate.Area.Width, warpplate.Area.Height, warpplate.Delay, warpplate.Label, warpplate.Name, Main.worldID.ToString());

                return(result > 0);
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }

            return(false);
        }
        /// <summary>
        /// Deletes a warpplate from the world
        /// </summary>
        /// <param name="name">The name of the warpplate to delete</param>
        /// <returns>Whether the warpplate was deleted successfully</returns>
        public async Task <bool> DeleteWarpplate(string name)
        {
            Warpplate warpplate = GetWarpplateByName(name);

            if (warpplate != null)
            {
                bool success = await Database.DeleteWarpplate(warpplate);

                if (success)
                {
                    Warpplates.Remove(warpplate);
                }

                return(success);
            }
            return(false);
        }
        /// <summary>
        /// Removes a warpplates destination
        /// </summary>
        /// <param name="name">The name of the warpplate to remove the destination from</param>
        /// <returns>Whether or not the removal of destination was successful</returns>
        public async Task <bool> RemoveDestination(string warpplateName)
        {
            Warpplate warpplate = GetWarpplateByName(warpplateName);

            if (warpplate != null)
            {
                bool success = await Database.RemoveDestination(warpplate);

                if (success)
                {
                    warpplate.Destination = "";
                }

                return(success);
            }

            return(false);
        }
Exemple #15
0
        /// <summary>
        /// Updates a warpplates label
        /// </summary>
        /// <param name="args">The command arguments</param>
        public async void SetWarpplateLabel(CommandArgs args)
        {
            string region = "";

            if (args.Parameters.Count == 3)
            {
                region = args.Parameters[1];
            }
            else if (args.Parameters.Count == 2)
            {
                region = Manager.InAreaWarpplateName(args.Player.TileX, args.Player.TileY);
            }
            else
            {
                args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /wp label [<warpplate name>] <label>");
                args.Player.SendErrorMessage("Type /wp label [<warpplate name>] \"\" to set label to default (warpplate name)");
                return;
            }
            Warpplate warpplate = Manager.GetWarpplateByName(region);

            if (warpplate == null)
            {
                args.Player.SendErrorMessage("No such warpplate");
                return;
            }
            string label = args.Parameters[args.Parameters.Count - 1];

            warpplate.Label = label;
            if (await Manager.UpdateWarpplate(warpplate.Name))
            {
                args.Player.SendSuccessMessage(String.Format("Set label of {0} to {1}", warpplate.Name, warpplate.GetLabelOrDefault()));
            }
            else
            {
                args.Player.SendErrorMessage("Something went wrong");
            }
        }
Exemple #16
0
        /// <summary>
        /// Checks whether the user can warp and warps them to the destination of the warpplate
        /// </summary>
        /// <param name="warpplate">The warpplate they are attempting to use</param>
        /// <param name="destinationWarpplate">The destination warpplate they are attempting to go to</param>
        private void CheckAndUseDestinationWarpplate(Warpplate warpplate, Warpplate destinationWarpplate)
        {
            if (TSPlayer == null)
            {
                TShock.Log.ConsoleError("AdvancedWarpplates: Player is null");
                return;
            }

            TimeStandingOnWarpplate++;
            if ((warpplate.Delay - TimeStandingOnWarpplate) > 0)
            {
                TSPlayer.SendInfoMessage("You will be warped to " + destinationWarpplate.Label + " in " + (warpplate.Delay - TimeStandingOnWarpplate) + " seconds");
            }
            else
            {
                if (TSPlayer.Teleport((int)(destinationWarpplate.WarpplatePos.X * 16) + 2, (int)(destinationWarpplate.WarpplatePos.Y * 16) + 3))
                {
                    TSPlayer.SendInfoMessage("You have been warped to " + destinationWarpplate.Label + " via a Warpplate");
                }
                TimeStandingOnWarpplate = 0;
                HasJustUsedWarpplate    = true;
                WarpplateUseCooldown    = 3;
            }
        }
        public async Task <bool> RemoveDestination(Warpplate warpplate)
        {
            int result = await Query("UPDATE Warpplates SET WarpplateDestination=@0 WHERE WarpplateName=@1 AND WorldID=@2", "", warpplate.Name, Main.worldID.ToString());

            return(result > 0);
        }
        public async Task <List <Warpplate> > ReloadAllWarpplates()
        {
            List <Warpplate> warpplates = new List <Warpplate>();

            try
            {
                using (var reader = await QueryReader("SELECT * FROM Warpplates WHERE WorldID=@0", Main.worldID.ToString()))
                {
                    while (reader.Read())
                    {
                        int    X1        = reader.Get <int>("X1");
                        int    Y1        = reader.Get <int>("Y1");
                        int    height    = reader.Get <int>("height");
                        int    width     = reader.Get <int>("width");
                        int    Protected = reader.Get <int>("Protected");
                        string mergedids = reader.Get <string>("UserIds");
                        string name      = reader.Get <string>("WarpplateName");
                        int    type      = reader.Get <int>("Type");
                        string warpdest  = reader.Get <string>("WarpplateDestination");
                        int    Delay     = reader.Get <int>("Delay");
                        string label     = reader.Get <string>("Label");

                        string[] splitids = mergedids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        Warpplate r = new Warpplate(new Vector2(X1, Y1), new Rectangle(X1, Y1, width, height), name, warpdest, Protected != 0, Main.worldID.ToString(), label, type);
                        r.Delay = Delay;

                        try
                        {
                            for (int i = 0; i < splitids.Length; i++)
                            {
                                int id;

                                if (Int32.TryParse(splitids[i], out id)) // if unparsable, it's not an int, so silently skip
                                {
                                    r.AllowedIDs.Add(id);
                                }
                                else
                                {
                                    TShock.Log.Warn("One of your UserIDs is not a usable integer: " + splitids[i]);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            TShock.Log.Error("Your database contains invalid UserIDs (they should be ints).");
                            TShock.Log.Error("A lot of things will fail because of this. You must manually delete and re-create the allowed field.");
                            TShock.Log.Error(e.ToString());
                            TShock.Log.Error(e.StackTrace);
                        }

                        warpplates.Add(r);
                    }
                }
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }

            return(warpplates);
        }