public bool buildStructure(BluePrint structureForPlacement, Vector2 tileLocation, Farmer who, bool magicalConstruction = false, bool skipSafetyChecks = false) { if (!skipSafetyChecks) { for (int y5 = 0; y5 < structureForPlacement.tilesHeight; y5++) { for (int x2 = 0; x2 < structureForPlacement.tilesWidth; x2++) { pokeTileForConstruction(new Vector2(tileLocation.X + (float)x2, tileLocation.Y + (float)y5)); } } foreach (Point additionalPlacementTile in structureForPlacement.additionalPlacementTiles) { int x5 = additionalPlacementTile.X; int y4 = additionalPlacementTile.Y; pokeTileForConstruction(new Vector2(tileLocation.X + (float)x5, tileLocation.Y + (float)y4)); } for (int y3 = 0; y3 < structureForPlacement.tilesHeight; y3++) { for (int x3 = 0; x3 < structureForPlacement.tilesWidth; x3++) { Vector2 currentGlobalTilePosition2 = new Vector2(tileLocation.X + (float)x3, tileLocation.Y + (float)y3); if (!isBuildable(currentGlobalTilePosition2)) { return(false); } foreach (Farmer farmer in farmers) { if (farmer.GetBoundingBox().Intersects(new Microsoft.Xna.Framework.Rectangle(x3 * 64, y3 * 64, 64, 64))) { return(false); } } } } foreach (Point additionalPlacementTile2 in structureForPlacement.additionalPlacementTiles) { int x4 = additionalPlacementTile2.X; int y2 = additionalPlacementTile2.Y; Vector2 currentGlobalTilePosition3 = new Vector2(tileLocation.X + (float)x4, tileLocation.Y + (float)y2); if (!isBuildable(currentGlobalTilePosition3)) { return(false); } foreach (Farmer farmer2 in farmers) { if (farmer2.GetBoundingBox().Intersects(new Microsoft.Xna.Framework.Rectangle(x4 * 64, y2 * 64, 64, 64))) { return(false); } } } if (structureForPlacement.humanDoor != new Point(-1, -1)) { Vector2 doorPos = tileLocation + new Vector2(structureForPlacement.humanDoor.X, structureForPlacement.humanDoor.Y + 1); if (!isBuildable(doorPos) && !isPath(doorPos)) { return(false); } } } Building b; switch (structureForPlacement.name) { case "Stable": b = new Stable(StardewValley.Util.GuidHelper.NewGuid(), structureForPlacement, tileLocation); break; case "Coop": case "Big Coop": case "Deluxe Coop": b = new Coop(structureForPlacement, tileLocation); break; case "Barn": case "Big Barn": case "Deluxe Barn": b = new Barn(structureForPlacement, tileLocation); break; case "Mill": b = new Mill(structureForPlacement, tileLocation); break; case "Junimo Hut": b = new JunimoHut(structureForPlacement, tileLocation); break; case "Shipping Bin": b = new ShippingBin(structureForPlacement, tileLocation); break; case "Fish Pond": b = new FishPond(structureForPlacement, tileLocation); break; case "Greenhouse": b = new GreenhouseBuilding(structureForPlacement, tileLocation); break; default: b = new Building(structureForPlacement, tileLocation); break; } b.owner.Value = who.UniqueMultiplayerID; if (!skipSafetyChecks) { string finalCheckResult = b.isThereAnythingtoPreventConstruction(this, tileLocation); if (finalCheckResult != null) { Game1.addHUDMessage(new HUDMessage(finalCheckResult, Color.Red, 3500f)); return(false); } } for (int y = 0; y < structureForPlacement.tilesHeight; y++) { for (int x = 0; x < structureForPlacement.tilesWidth; x++) { Vector2 currentGlobalTilePosition = new Vector2(tileLocation.X + (float)x, tileLocation.Y + (float)y); terrainFeatures.Remove(currentGlobalTilePosition); } } buildings.Add(b); b.performActionOnConstruction(this); if (magicalConstruction) { Game1.multiplayer.globalChatInfoMessage("BuildingMagicBuild", Game1.player.Name, Utility.AOrAn(structureForPlacement.displayName), structureForPlacement.displayName, Game1.player.farmName); } else { Game1.multiplayer.globalChatInfoMessage("BuildingBuild", Game1.player.Name, Utility.AOrAn(structureForPlacement.displayName), structureForPlacement.displayName, Game1.player.farmName); } return(true); }
public void tryToUpgrade(Building toUpgrade, BluePrint blueprint) { if (toUpgrade != null && blueprint.name != null && toUpgrade.buildingType.Equals(blueprint.nameOfBuildingToUpgrade)) { if (toUpgrade.indoors.Value.farmers.Any()) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\Locations:BuildableLocation_CantUpgrade_SomeoneInside"), Color.Red, 3500f)); return; } toUpgrade.indoors.Value.map = Game1.game1.xTileContent.Load <Map>("Maps\\" + blueprint.mapToWarpTo); toUpgrade.indoors.Value.name.Value = blueprint.mapToWarpTo; toUpgrade.indoors.Value.isStructure.Value = true; toUpgrade.buildingType.Value = blueprint.name; toUpgrade.resetTexture(); if (toUpgrade.indoors.Value is AnimalHouse) { ((AnimalHouse)(GameLocation)toUpgrade.indoors).resetPositionsOfAllAnimals(); } playSound("axe"); blueprint.consumeResources(); toUpgrade.performActionOnUpgrade(this); toUpgrade.color.Value = Color.White; Game1.exitActiveMenu(); Game1.multiplayer.globalChatInfoMessage("BuildingBuild", Game1.player.Name, Utility.AOrAn(blueprint.displayName), blueprint.displayName, Game1.player.farmName); } else if (toUpgrade != null) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\Locations:BuildableLocation_CantUpgrade_IncorrectBuildingType"), Color.Red, 3500f)); } }