public static bool drawInMenu_Prefix(GreenhouseBuilding __instance) { try { __instance.texture = new Lazy <Texture2D>(delegate { Texture2D texture2D = Game1.content.Load <Texture2D>("Buildings\\Greenhouse"); if (__instance.paintedTexture != null) { __instance.paintedTexture.Dispose(); __instance.paintedTexture = null; } __instance.paintedTexture = BuildingPainter.Apply(texture2D, "Buildings\\Greenhouse" + "_PaintMask", __instance.netBuildingPaintColor.Value); if (__instance.paintedTexture != null) { texture2D = __instance.paintedTexture; } return(texture2D); }); } catch (Exception ex) { Monitor.Log($"Failed in {nameof(drawInMenu_Prefix)}:\n{ex}", LogLevel.Error); } return(true); }
/// <summary>Stores the upgrade level on GreenhouseBuilding modData and notify the upgrade when needed.</summary> /// <param name="__instance">The Building Upgraded</param> /// <returns></returns> public static bool Upgrade_Prefix(GreenhouseBuilding __instance) { try { if (__instance.buildingType == "Greenhouse") { if (__instance.daysUntilUpgrade.Value == 1) { __instance.daysUntilUpgrade.Value = 0; int newLevel = (ModEntry.GetUpgradeLevel(__instance) + 1); __instance.modData[ModEntry.DataKey] = newLevel.ToString(); if (MoveEnabled) { FruitTreeMover.Upgraded(); } } } return(true); } catch (Exception ex) { Monitor.Log($"Failed in {nameof(Upgrade_Prefix)}:\n{ex}", LogLevel.Error); return(true); } }
public static bool Greenhouse_DrawGenericShadow_Prefix(GreenhouseBuilding __instance, SpriteBatch b, int localX = -1, int localY = -1) { if (!Config.HideGreenhouseShadow && Config.GreenhouseSoftShadow) { const int entryTilesWide = 3; float alpha = Instance.Helper.Reflection.GetField <NetFloat>(__instance, "alpha").GetValue(); Vector2 basePosition = (localX == -1) ? Game1.GlobalToLocal(new Vector2(__instance.tileX.Value * Game1.tileSize, (__instance.tileY.Value + __instance.tilesHigh.Value) * Game1.tileSize)) : new Vector2(localX, localY + (__instance.getSourceRectForMenu().Height * 4)); Vector2 topPosition = Game1.GlobalToLocal(new Vector2(__instance.tileX.Value * Game1.tileSize, __instance.tileY.Value * Game1.tileSize)); Color colour = Color.White * ((localX == -1) ? alpha : 1f); // Draw shadow underneath greenhouse (visible at the sides of the vanilla sprite and may be visible in custom sprites) // '1E-05f' layerDepth value is an artefact from decompiled game code b.Draw( texture: Game1.mouseCursors, destinationRectangle: new Rectangle( (int)topPosition.X, (int)topPosition.Y, __instance.tilesWide.Value * Game1.tileSize, __instance.tilesHigh.Value * Game1.tileSize), sourceRectangle: new Rectangle(Building.leftShadow.X, Building.leftShadow.Y, 1, 1), color: colour, rotation: 0f, origin: Vector2.Zero, SpriteEffects.None, layerDepth: 1E-05f); // Shadow start b.Draw( texture: Game1.mouseCursors, position: basePosition, sourceRectangle: Building.leftShadow, color: colour, rotation: 0f, origin: Vector2.Zero, scale: Game1.pixelZoom, SpriteEffects.None, layerDepth: 1E-05f); for (int x = 1; x < __instance.tilesWide.Value - 1; x++) { // Avoid drawing over entry tiles if enabled if (!Config.HideGreenhouseTiles && x > (__instance.tilesWide.Value - entryTilesWide) / 2 && x < __instance.tilesWide.Value - ((__instance.tilesWide.Value - entryTilesWide) / 2)) { continue; } // Shadow middle b.Draw( texture: Game1.mouseCursors, position: basePosition + new Vector2(x * 64, 0f), sourceRectangle: Building.middleShadow, color: colour, rotation: 0f, origin: Vector2.Zero, scale: Game1.pixelZoom, SpriteEffects.None, layerDepth: 1E-05f); } // Shadow end b.Draw( texture: Game1.mouseCursors, position: basePosition + new Vector2((__instance.tilesWide.Value - 1) * 64, 0f), sourceRectangle: Building.rightShadow, color: colour, rotation: 0f, origin: Vector2.Zero, scale: Game1.pixelZoom, SpriteEffects.None, layerDepth: 1E-05f); return(false); } return(true); }
public static void applyGreenhouseUpgradesCompatibility() { if (Helper.ModRegistry.IsLoaded("Cecidelus.GreenhouseUpgrades")) { Monitor.Log("Applying GreenhouseUpgrades Compatibility"); GreenhouseBuilding greenhouse = Game1.getFarm().buildings.OfType <GreenhouseBuilding>().FirstOrDefault(); string s; greenhouse.modData.TryGetValue("Cecidelus.GreenhouseUpgrades/upgrade-level", out s); if (s == null) { return; } int upgradeLevel = int.Parse(s); if (upgradeLevel == 2) { waterGreenhouse(); } } }
public static bool Upgrade_Prefix(GreenhouseBuilding __instance, int dayOfMonth) { try { if (__instance.buildingType.Value == "Greenhouse") { if (__instance.daysUntilUpgrade.Value == 1) { Monitor.Log("Greenhouse Upgrade completed, moving to next level", LogLevel.Info); __instance.daysUntilUpgrade.Value = 0; __instance.modData[ModDataKey] = (ModEntry.GetUpgradeLevel(__instance) + 1).ToString(); if (Config.ShowVisualUpgrades) { Helper.Content.InvalidateCache("Buildings/Greenhouse"); } } } return(true); //We only touched the "count down days" portion, we don't care about the rest of it } catch (Exception ex) { Monitor.Log($"Failed in {nameof(Upgrade_Prefix)}:\n{ex}", LogLevel.Error); return(true); // run original logic } }
public static int GetUpgradeLevel(GreenhouseBuilding greenhouse) { return(greenhouse.modData.TryGetValue(ModDataKey, out string level) ? int.Parse(level) : 0); }
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); }