Ejemplo n.º 1
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//expand"))
            {
                return(false);
            }

            if (!CommandHelper.CheckCommand(player))
            {
                return(true);
            }

            if (1 >= splits.Count)
            {
                Chat.Send(player, "<color=orange>Wrong Arguments</color>");
                return(true);
            }

            if (!int.TryParse(splits[1], out int quantity))
            {
                Chat.Send(player, "<color=orange>Not number</color>");
                return(true);
            }

            string sdirection;

            if (2 == splits.Count)    //Default: Expand ? FORWARD
            {
                sdirection = "forward";
            }
            else
            {
                sdirection = splits[2];
            }

            AdvancedWand wand      = AdvancedWand.GetAdvancedWand(player);
            Vector3Int   direction = CommandHelper.GetDirection(player.Forward, sdirection);

            Vector3Int start = wand.area.corner1;
            Vector3Int end   = wand.area.corner2;

            if (1 == direction.x || 1 == direction.y || 1 == direction.z)
            {
                end += (direction * quantity);
            }
            else
            {
                start += (direction * quantity);
            }

            wand.area.SetCorner1(start, player);
            wand.area.SetCorner2(end, player);

            Chat.Send(player, string.Format("<color=lime>Area expanded {0} block {1}</color>", quantity, sdirection));

            return(true);
        }
Ejemplo n.º 2
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//set"))
            {
                return(false);
            }

            if (!CommandHelper.CheckCommand(player))
            {
                return(true);
            }

            if (0 >= splits.Count)
            {
                Chat.Send(player, "<color=orange>Wrong Arguments</color>");
                return(true);
            }

            if (!CommandHelper.CheckLimit(player))
            {
                return(true);
            }

            ushort blockIndex = BlockTypes.BuiltinBlocks.Indices.air;  //Default: Set 0

            if (2 <= splits.Count)
            {
                if (!CommandHelper.GetBlockIndex(player, splits[1], out blockIndex))
                {
                    return(true);
                }
            }

            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            Vector3Int start = wand.area.corner1;
            Vector3Int end   = wand.area.corner2;

            for (int x = end.x; x >= start.x; x--)
            {
                for (int y = end.y; y >= start.y; y--)
                {
                    for (int z = end.z; z >= start.z; z--)
                    {
                        Vector3Int newPos = new Vector3Int(x, y, z);
                        if (!World.TryGetTypeAt(newPos, out ushort actualType) || actualType != blockIndex)
                        {
                            AdvancedWand.AddAction(newPos, blockIndex, player);
                        }
                    }
                }
            }

            Chat.Send(player, string.Format("<color=lime>Set: {0}</color>", blockIndex));

            return(true);
        }
Ejemplo n.º 3
0
        public static void OnRightClickWith(Players.Player player, Shared.PlayerClickedData boxedData)
        {
            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            if (!wand.active || boxedData.HitType != EHitType.Block || boxedData.GetVoxelHit().TypeHit == BlockTypes.BuiltinBlocks.Indices.air)
            {
                return;
            }

            wand.area.SetCorner2(boxedData.GetVoxelHit().BlockHit, player);

            Chat.Send(player, string.Format("<color=lime>Pos 2: {0}</color>", boxedData.GetVoxelHit().BlockHit));
        }
Ejemplo n.º 4
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//cut"))
            {
                return(false);
            }

            if (!CommandHelper.CheckCommand(player))
            {
                return(true);
            }

            if (0 >= splits.Count)
            {
                Chat.Send(player, "<color=orange>Wrong Arguments</color>");
                return(true);
            }

            if (!CommandHelper.CheckLimit(player))
            {
                return(true);
            }

            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            wand.copy = new Helper.Blueprint(wand.area, player);

            Vector3Int start = wand.area.corner1;
            Vector3Int end   = wand.area.corner2;

            for (int x = end.x; x >= start.x; x--)
            {
                for (int y = end.y; y >= start.y; y--)
                {
                    for (int z = end.z; z >= start.z; z--)
                    {
                        Vector3Int newPos = new Vector3Int(x, y, z);
                        if (!World.TryGetTypeAt(newPos, out ushort actualType) || actualType != BlockTypes.BuiltinBlocks.Indices.air)
                        {
                            AdvancedWand.AddAction(newPos, BlockTypes.BuiltinBlocks.Indices.air, player);
                        }
                    }
                }
            }

            Chat.Send(player, string.Format("<color=lime>Cutted the selected area</color>"));


            return(true);
        }
Ejemplo n.º 5
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//wand"))
            {
                return(false);
            }

            //Player exists
            if (null == player || NetworkID.Server == player.ID)
            {
                return(true);
            }

            //Check permissions
            if (!PermissionsManager.CheckAndWarnPermission(player, "khanx.wand"))
            {
                return(true);
            }


            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            //Change the status of the wand
            wand.active = !wand.active;

            if (wand.active)
            {
                Chat.Send(player, "<color=lime>Wand ON</color>");
            }
            else
            {
                Chat.Send(player, "<color=lime>Wand OFF</color>");
                AdvancedWand.RemoveAdvancedWand(player);
            }

            return(true);
        }
Ejemplo n.º 6
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//copy"))
            {
                return(false);
            }

            if (!CommandHelper.CheckCommand(player))
            {
                return(true);
            }

            if (0 >= splits.Count)
            {
                Chat.Send(player, "<color=orange>Wrong Arguments</color>");
                return(true);
            }

            if (!CommandHelper.CheckLimit(player))
            {
                return(true);
            }

            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            wand.copy = new Blueprint(wand.area, player);

            Chat.Send(player, "<color=olive>Copied area:</color>");
            Chat.Send(player, string.Format("<color=lime>X: {0}</color>", wand.copy.xSize));
            Chat.Send(player, string.Format("<color=lime>Y: {0}</color>", wand.copy.ySize));
            Chat.Send(player, string.Format("<color=lime>Z: {0}</color>", wand.copy.zSize));
            Chat.Send(player, string.Format("<color=lime>Total: {0}</color>", wand.copy.xSize * wand.copy.ySize * wand.copy.zSize));

            Chat.Send(player, string.Format("<color=lime>Copied the selected area</color>"));

            return(true);
        }
Ejemplo n.º 7
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//replace"))
            {
                return(false);
            }

            if (!CommandHelper.CheckCommand(player))
            {
                return(true);
            }

            if (1 >= splits.Count)
            {
                Chat.Send(player, "<color=orange>Wrong Arguments</color>");
                return(true);
            }

            if (!CommandHelper.CheckLimit(player))
            {
                return(true);
            }

            if (2 == splits.Count) //Default replace ALL ?
            {
                if (!CommandHelper.GetBlockIndex(player, splits[1], out ushort newBlock))
                {
                    return(true);
                }

                AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

                Vector3Int start = wand.area.corner1;
                Vector3Int end   = wand.area.corner2;

                for (int x = end.x; x >= start.x; x--)
                {
                    for (int y = end.y; y >= start.y; y--)
                    {
                        for (int z = end.z; z >= start.z; z--)
                        {
                            Vector3Int newPos = new Vector3Int(x, y, z);
                            if (!World.TryGetTypeAt(newPos, out ushort actualType) || (actualType != BlockTypes.BuiltinBlocks.Indices.air))
                            {
                                AdvancedWand.AddAction(newPos, newBlock, player);
                            }
                        }
                    }
                }

                Chat.Send(player, string.Format("<color=lime>ALL -> {0}</color>", splits[1]));
            }
            else
            {
                if (!CommandHelper.GetBlockIndex(player, splits[1], out ushort oldBlock))
                {
                    return(true);
                }

                if (!CommandHelper.GetBlockIndex(player, splits[2], out ushort newBlock))
                {
                    return(true);
                }

                AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

                Vector3Int start = wand.area.corner1;
                Vector3Int end   = wand.area.corner2;

                for (int x = end.x; x >= start.x; x--)
                {
                    for (int y = end.y; y >= start.y; y--)
                    {
                        for (int z = end.z; z >= start.z; z--)
                        {
                            Vector3Int newPos = new Vector3Int(x, y, z);
                            if (!World.TryGetTypeAt(newPos, out ushort actualType) || actualType == oldBlock)
                            {
                                AdvancedWand.AddAction(newPos, newBlock, player);
                            }
                        }
                    }
                }

                Chat.Send(player, string.Format("<color=lime>{0} -> {1}</color>", splits[1], splits[2]));
            }

            return(true);
        }
Ejemplo n.º 8
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//tree"))
            {
                return(false);
            }

            if (!CommandHelper.CheckCommand(player))
            {
                return(true);
            }

            if (0 >= splits.Count)
            {
                Chat.Send(player, "<color=orange>Wrong Arguments</color>");
                return(true);
            }

            if (!CommandHelper.CheckLimit(player))
            {
                return(true);
            }

            if (!chat.Contains(" "))
            {
                Chat.Send(player, "<color=orange>Wrong Arguments: //tree _treename_</color>");
                return(true);
            }

            string filename = chat.Substring(chat.IndexOf(" ") + 1).Trim();

            filename = filename.Replace(" ", "_");

            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            Dictionary <string, List <Vector3Int> > tree = new Dictionary <string, List <Vector3Int> >();


            if (wand.area == null)
            {
                Chat.Send(player, "<color=orange>Area not detected</color>");
                return(true);
            }

            if (!wand.area.IsPos1Initialized() || !wand.area.IsPos2Initialized())
            {
                Chat.Send(player, "<color=orange>The positions of the area have not beed initialized</color>");
                return(true);
            }

            Vector3Int start = wand.area.corner1;
            Vector3Int end   = wand.area.corner2;


            Vector3Int center = new Vector3Int((int)System.Math.Ceiling((start.x + end.x) / 2.0), start.y, (int)System.Math.Ceiling((start.z + end.z) / 2.0));

            Chat.Send(player, "<color=blue>Center: " + center + "</color>");

            for (int x = start.x; x <= end.x; x++)
            {
                for (int y = start.y; y <= end.y; y++)
                {
                    for (int z = start.z; z <= end.z; z++)
                    {
                        Vector3Int newPos = new Vector3Int(x, y, z);
                        if (World.TryGetTypeAt(newPos, out ItemTypes.ItemType type))
                        {
                            if (tree.ContainsKey(type.Name))
                            {
                                List <Vector3Int> l = tree[type.Name];
                                l.Add(newPos - center);
                                tree.Remove(type.Name);
                                tree.Add(type.Name, l);
                            }
                            else
                            {
                                List <Vector3Int> l = new List <Vector3Int>();
                                l.Add(newPos - center);
                                tree.Add(type.Name, l);
                            }
                        }
                    }
                }
            }

            JSONNode json        = new JSONNode(NodeType.Array);
            JSONNode jsonTree    = new JSONNode(NodeType.Object);
            JSONNode jsonBlocks1 = new JSONNode(NodeType.Array);

            foreach (var i in tree.Keys)
            {
                if (i.Equals("air"))
                {
                    continue;
                }

                JSONNode jsonNodeTree2 = new JSONNode(NodeType.Object);
                JSONNode jsonBlocks    = new JSONNode(NodeType.Array);

                foreach (var j in tree[i])
                {
                    JSONNode vector = new JSONNode(NodeType.Object);
                    vector.SetAs("x", j.x);
                    vector.SetAs("y", j.y);
                    vector.SetAs("z", j.z);

                    jsonBlocks.AddToArray(vector);
                }

                jsonNodeTree2.SetAs("blocks", jsonBlocks);
                jsonNodeTree2.SetAs("type", i);
                jsonBlocks1.AddToArray(jsonNodeTree2);
            }

            jsonTree.SetAs("blocks", jsonBlocks1);
            json.AddToArray(jsonTree);

            JSON.Serialize(BlueprintManager.MODPATH + "/blueprints/" + filename + ".json", json, 2);

            Chat.Send(player, "<color=olive>Saved tree: " + filename + "</color>");

            return(true);
        }
Ejemplo n.º 9
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//move"))
            {
                return(false);
            }

            if (!CommandHelper.CheckCommand(player))
            {
                return(true);
            }

            if (1 >= splits.Count)
            {
                Chat.Send(player, "<color=orange>Wrong Arguments</color>");
                return(true);
            }

            if (!CommandHelper.CheckLimit(player))
            {
                return(true);
            }

            if (!int.TryParse(splits[1], out int quantity))
            {
                Chat.Send(player, "<color=orange>Not number</color>");
                return(true);
            }

            string sdirection;

            if (2 == splits.Count)    //Default: Contract ? FORWARD
            {
                sdirection = "forward";
            }
            else
            {
                sdirection = splits[2];
            }

            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            //Create a temporal copy
            Blueprint tmpCopy = new Blueprint(wand.area, player);

            //Remove the selected area
            Vector3Int start = wand.area.corner1;
            Vector3Int end   = wand.area.corner2;

            for (int x = end.x; x >= start.x; x--)
            {
                for (int y = end.y; y >= start.y; y--)
                {
                    for (int z = end.z; z >= start.z; z--)
                    {
                        Vector3Int newPos = new Vector3Int(x, y, z);
                        if (!World.TryGetTypeAt(newPos, out ushort actualType) || actualType != BlockTypes.BuiltinBlocks.Indices.air)
                        {
                            AdvancedWand.AddAction(newPos, BlockTypes.BuiltinBlocks.Indices.air, player);
                        }
                    }
                }
            }

            //Paste the temporal copy
            Vector3Int direction = (CommandHelper.GetDirection(player.Forward, sdirection) * quantity);

            for (int x = 0; x < tmpCopy.xSize; x++)
            {
                for (int y = 0; y < tmpCopy.ySize; y++)
                {
                    for (int z = 0; z < tmpCopy.zSize; z++)
                    {
                        Vector3Int newPosition = new Vector3Int(player.Position) - tmpCopy.playerMod + direction + new Vector3Int(x, y, z);
                        //DONT USE THIS IF CAN CAUSE PROBLEMS!!!
                        //if(!World.TryGetTypeAt(newPosition, out ushort actualType) || actualType != tmpCopy.blocks[x, y, z])
                        AdvancedWand.AddAction(newPosition, tmpCopy.blocks[x, y, z], player);
                    }
                }
            }

            Chat.Send(player, string.Format("<color=lime>Moved {0} {1} the selected area</color>", quantity, sdirection));

            return(true);
        }
Ejemplo n.º 10
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> splits)
        {
            if (!chat.Trim().ToLower().StartsWith("//paste"))
            {
                return(false);
            }

            if (null == player || NetworkID.Server == player.ID)
            {
                return(false);
            }

            //Player has permission
            if (!PermissionsManager.CheckAndWarnPermission(player, "khanx.wand"))
            {
                return(true);
            }

            AdvancedWand wand = AdvancedWand.GetAdvancedWand(player);

            //Wand is OFF
            if (!wand.active)
            {
                Chat.Send(player, "<color=orange>Wand is OFF, use //wand to activate</color>");
                return(true);
            }

            Blueprint blueprint = null;

            if (chat.Trim().Equals("//paste"))  //Paste from copy
            {
                blueprint = wand.copy;

                if (blueprint == null)
                {
                    Chat.Send(player, string.Format("<color=orange>There is nothing copied</color>"));
                    return(true);
                }
            }
            else    //Paste from loaded blueprint
            {
                string blueprintName = chat.Substring(chat.IndexOf(" ") + 1).Trim();

                if (!BlueprintManager._blueprints.TryGetValue(blueprintName, out blueprint))
                {
                    Chat.Send(player, string.Format("<color=orange>There is not a bluerpint with that name.</color>"));
                    return(true);
                }
            }

            Chat.Send(player, string.Format("<color=lime>Pasting...</color>"));

            for (int x = 0; x < blueprint.xSize; x++)
            {
                for (int y = 0; y < blueprint.ySize; y++)
                {
                    for (int z = 0; z < blueprint.zSize; z++)
                    {
                        Vector3Int newPosition = new Vector3Int(player.Position) - blueprint.playerMod + new Vector3Int(x, y, z);
                        if (!World.TryGetTypeAt(newPosition, out ushort actualType) || actualType != blueprint.blocks[x, y, z])
                        {
                            AdvancedWand.AddAction(newPosition, blueprint.blocks[x, y, z], player);
                        }
                    }
                }
            }

            return(true);
        }