示例#1
0
        bool isValidHousePosition(House house)
        {
            foreach (House other in houses.Values)
            {
                bool xIntersects = false;
                bool yIntersects = false;

                if (house.x >= other.x && house.x < other.x + other.width)
                    xIntersects = true;

                if (other.x >= house.x && other.x < house.x + house.width)
                    xIntersects = true;

                if (house.y >= other.y && house.y < other.y + other.width)
                    yIntersects = true;

                if (other.y >= house.y && other.y < house.y + house.width)
                    yIntersects = true;

                if (xIntersects && yIntersects)
                {
                    IPlayer player = bot.Room.getPlayer(house.builder);
                    if (player != null)
                    {
                        string builder = house.builder;
                        string neighbor = other.builder;

                        player.Reply("Your house would be too close to " + neighbor + "'s house.");
                        player.Reply("The size of the house is " + house.width + "x" + house.height + " blocks.");
                    }

                    return false;
                }
            }

            for (int x = 0; x < house.width; ++x)
            {
                for (int y = 0; y < house.height; ++y)
                {
                    int bx = house.x + x;
                    int by = house.y + y;

                    int blockId = bot.Room.getBlock(0, bx, by).Id;

                    if (!house.houseType.isGroundBlockAllowed(blockId))
                    {
                        IPlayer player = bot.Room.getPlayer(house.builder);
                        if (player != null)
                        {
                            player.Reply("You must build the house on empty space without dirt and ores!");
                            player.Reply("The size of the house is " + house.width + "x" + house.height + " blocks.");
                        }
                        return false;
                    }
                }
            }

            foreach (var isValidPos in isValidPosEvent)
            {
                if (!isValidPos(house))
                    return false;
            }

            return true;
        }
示例#2
0
        public void DrawHouse(House house, IPlayer builder = null)
        {
            for (int xx = 0; xx < house.houseType.Width; ++xx)
            {
                for (int yy = 0; yy < house.houseType.Height; ++yy)
                {
                    int blockId = 22;
                    int backgroundBlock = house.houseType.BackgroundBlock;

                    if (xx == 0 || xx == house.houseType.Width - 1 || yy == 0 || yy == house.houseType.Height - 1)
                        blockId = house.houseType.WallBlock;
                    else
                        blockId = house.houseType.BaseBlock;

                    if (builder == null || (builder.BlockX != house.x + xx || builder.BlockY != house.y + yy))
                    {
                        if (!house.Furniture.ContainsKey(new BlockPos(0, xx + house.x, yy + house.y)))
                            this.bot.Room.setBlock(xx + house.x, yy + house.y, new Room.Block.NormalBlock(blockId));
                    }

                    this.bot.Room.setBlock(xx + house.x, yy + house.y, new Room.Block.NormalBlock(backgroundBlock));

                }
            }

            foreach (var v in house.Furniture)
                bot.Room.setBlock(v.Key.X, v.Key.Y, v.Value.getBlock(bot, builder, house));
        }
示例#3
0
        public void Load()
        {
            houses.Clear();
            SaveFile saveFile = new SaveFile("data/houses");
            saveFile.Load();
            Dictionary<string, Node> nodes = saveFile.Nodes;
            if (nodes.ContainsKey("houses"))
            {
                Node houses2 = nodes["houses"];
                foreach (KeyValuePair<string, Node> house in houses2.Nodes)
                {
                    int x = int.Parse(house.Value.Nodes["x"].Value);
                    int y = int.Parse(house.Value.Nodes["y"].Value);
                    string type = house.Value.Nodes["type"].Value;

                    House newhouse = new House(houseTypes[type], house.Key, x, y, houseTypes[type].Width, houseTypes[type].Height);

                    if (house.Value.Nodes.ContainsKey("furniture"))						// <furniture>
                    {
                        Node furniture = house.Value.Nodes["furniture"];
                        foreach (KeyValuePair<string, Node> furnitures in furniture.Nodes)
                        {
                            // <x|y>
                            int furniturex = int.Parse(furnitures.Value.Nodes["x"].Value);
                            int furniturey = int.Parse(furnitures.Value.Nodes["y"].Value);
                            string furnituretype = furnitures.Value.Nodes["type"].Value;

                            Furniture newFurniture = FurnitureManager.FurnitureTypes[furnituretype].FromNode(furnitures.Value);
                            newhouse.Furniture.Add(new BlockPos(0, furniturex, furniturey), newFurniture);
                        }
                    }
                    this.houses.Add(newhouse.builder, newhouse);
                    DrawHouse(newhouse);
                }
            }
        }
示例#4
0
        public bool BuildHouse(IPlayer builder, string houseTypeStr)
        {
            if (buildingHouses.ContainsKey(builder))
            {
                builder.Reply("You are already building a house, use !finishhouse to finish it.");
                return false;
            }

            if (houses.ContainsKey(builder.Name))
            {
                builder.Reply("You already have a house. Use !destroyhouse to delete it. ;)");
                return false;
            }

            HouseType houseType = null;

            if (!houseTypes.ContainsKey(houseTypeStr))
            {
                builder.Reply("There is no building called '" + houseTypeStr + "'!");
                ShowHouses(builder);
                return false;
            }

            houseType = houseTypes[houseTypeStr];

            // Make sure the player cna buy the house!
            if (!houseType.CanBuy(builder))
            {
                //builder.Reply("You don't have enough resources to build " + houseType.Name + ".");
                //houseType.PrintCost(builder);
                return false;
            }

            int x = builder.BlockX - houseType.Width / 2;
            int y = builder.BlockY - houseType.Height / 2;

            House house = new House(houseType, builder.Name, x, y, houseType.Width, houseType.Height, HouseState.Building);
            if (!isValidHousePosition(house))
                return false;
            buildingHouses.Add(builder, house);
            houses.Add(builder.Name, house);
            DrawHouse(house, builder);
            bot.ChatSayer.Command("/tp " + builder.Name + " " + builder.BlockX + " " + builder.BlockY);

            // Nothing went wrong, let the player pay for his house.
            houseType.Buy(builder);

            return true;
        }