bool isValidHousePosition(House house) { foreach (House other in houses) { 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 builder = house.builder; IPlayer neighbor = other.builder; builder.Reply("Your house would be too close to " + neighbor.Name + "'s house."); house.builder.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)) { house.builder.Reply("You must build the house on empty space without dirt and ores!"); house.builder.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; }
public void setHouse(House house) { this.house = house; }
public bool BuildHouse(IPlayer builder, string houseTypeStr) { if (buildingHouses.ContainsKey(builder)) return false; HouseType houseType = null; if (!houseTypes.ContainsKey(houseTypeStr)) { builder.Reply("There is no building called '" + houseTypeStr + "'!"); List<string> houseTypeNames = new List<string>(); foreach(HouseType h in houseTypes.Values) houseTypeNames.Add(h.Name); string text = "You can build this: "; for (int i = 0; i < houseTypeNames.Count; ++i) { if (i == houseTypeNames.Count - 1) text += houseTypeNames[i]; else text += houseTypeNames[i] + ", "; if (i % 4 == 3 || i == 2 || i == houseTypeNames.Count - 1) { builder.Reply(text); text = ""; } } return false; } houseType = houseTypes[houseTypeStr]; //////////TITTA HÄRRRRRRRRRRRRRRRRRR //////////TITTA HÄRRRRRRRRRRRRRRRRRR //////////TITTA HÄRRRRRRRRRRRRRRRRRR //int cost = houseType.Cost; ? MasterDig.DigPlayer digPlayer = MasterDig.DigPlayer.FromPlayer(builder); if (digPlayer.inventory.GetItemCount("stone") > 5) { digPlayer.inventory.RemoveItem("stone", 5); } else { builder.Reply("You do not have enough resources to build this house type!"); return false; } //////////TITTA HÄRRRRRRRRRRRRRRRRRR //////////TITTA HÄRRRRRRRRRRRRRRRRRR //////////TITTA HÄRRRRRRRRRRRRRRRRRR int x = builder.BlockX - houseType.Width/2; int y = builder.BlockY - houseType.Height/2; House house = new House(houseType, builder, x, y, houseType.Width, houseType.Height, HouseState.Building); if (!isValidHousePosition(house)) return false; buildingHouses.Add(builder, house); houses.Add(house); for (int xx = 0; xx < houseType.Width; ++xx) { for (int yy = 0; yy < houseType.Height; ++yy) { int blockId = 22; int backgroundBlock = houseType.BackgroundBlock; if (xx == 0 || xx == houseType.Width - 1 || yy == 0 || yy == houseType.Height - 1) { blockId = houseType.WallBlock; } else { blockId = houseType.BaseBlock; } if (builder.BlockX != x + xx || builder.BlockY != y + yy) { this.bot.Room.BlockDrawer.PlaceBlock( new Room.Block.BlockWithPos(xx + x, yy + y, new Room.Block.NormalBlock(blockId))); } this.bot.Room.BlockDrawer.PlaceBlock( new Room.Block.BlockWithPos(xx + x, yy + y, new Room.Block.NormalBlock(backgroundBlock))); } } bot.Say("/tp " + builder.Name + " " + builder.BlockX + " " + builder.BlockY); return true; }