private void ActivateSprinkler(StardewValley.Object sprinkler) { if (sprinkler == null) { return; } if (sprinkler.IsSprinkler() || sprinkler.Name.Contains("Sprinkler")) { if (LineSprinklersIsLoaded && sprinkler.Name.Contains("Line")) { ActivateLineSprinkler(sprinkler); } else if (PrismaticToolsApi != null && sprinkler.Name.Contains("Prismatic")) { ActivatePrismaticSprinkler(sprinkler); } else if (BetterSprinklersApi != null) { ActivateBetterSprinkler(sprinkler); } else if (SimpleSprinklerApi != null) { ActivateSimpleSprinkler(sprinkler); } else { ActivateVanillaSprinkler(sprinkler); } } }
private static void DisableSprinklerFlag_Pre(StardewObject __instance, GameLocation location, int x, int y, ref bool __state) { if (location is Farm && Game1.whichFarm == Farm.beach_layout && HasUnlockedSprinklersInSand) { if (__instance.IsSprinkler() && location.doesTileHavePropertyNoNull(x, y, "NoSprinklers", "Back") == "T") { location.map.GetLayer("Back").PickTile(new Location(x * 64, y * 64), Game1.viewport.Size).Properties["NoSprinklers"] = "F"; __state = true; } } }
// Allow torches to be removed from scarecrows and sprinklers with them in public static bool pressUseToolButton_Prefix(StardewValley.Game1 __instance, ref bool __result) { if (Game1.player.CurrentTool == null && Game1.player.ActiveObject != null && Game1.player.ActiveObject.Name == "Torch") { Vector2 c = Game1.player.GetToolLocation() / 64f; c.X = (int)c.X; c.Y = (int)c.Y; if (Game1.currentLocation.Objects.ContainsKey(c)) { StardewValley.Object o = Game1.currentLocation.Objects[c]; if (o.lightSource == null && (o.Name.Contains("arecrow") || o.IsSprinkler())) { // If config options are disabled then skip if (o.Name.Contains("arecrow") && !ModEntry.config_.place_torches_in_scarecrows) { Monitor.Log($"Skipping adding light to {Game1.currentLocation.Name}: {c.X}, {c.Y} as it's a scarecrow and the config option 'place_torches_in_scarecrows' is disabled", LogLevel.Trace); return(true); } else if (o.IsSprinkler() && !ModEntry.config_.place_torches_in_sprinklers) { Monitor.Log($"Skipping adding light to {Game1.currentLocation.Name}: {c.X}, {c.Y} as it's a sprinkler and the config option 'place_torches_in_sprinklers' is disabled", LogLevel.Trace); return(true); } else { // Add light to map data ModEntry.mapDict.enableLightOnObject(Game1.currentLocation.Name, c); // Take torch from inventory Game1.player.reduceActiveItemByOne(); // Make light source in game Game1.currentLocation.Objects[c].lightSource = (new Torch(c, 1)).lightSource; return(false); } } } } return(true); }
private void ActivateVanillaSprinkler(StardewValley.Object sprinkler) { if (!sprinkler.IsSprinkler()) { return; } foreach (Vector2 current in sprinkler.GetSprinklerTiles()) { sprinkler.ApplySprinkler(Game1.currentLocation, current); } ApplySprinklerAnimation(Game1.currentLocation, sprinkler); }
public void ActivateSprinkler(SObject sprinkler, GameLocation location) { if (SprinklerBehavior is not ISprinklerBehavior.Independent) { throw new InvalidOperationException("Current sprinkler behavior does not allow independent sprinkler activation."); } if (Game1.player.team.SpecialOrderRuleActive("NO_SPRINKLER")) { return; } if (!sprinkler.IsSprinkler()) { return; } foreach (var sprinklerTile in GetModifiedSprinklerCoverage(sprinkler, location)) { sprinkler.ApplySprinkler(location, new Vector2(sprinklerTile.X, sprinklerTile.Y)); } sprinkler.ApplySprinklerAnimation(location); }
/// <summary>Attempts to activate the correct sprinkler.</summary> /// <param name="sprinkler">The sprinkler object.</param> private void ActivateSprinkler(StardewValley.Object sprinkler) { // This function determines which sprinkler was activated if (sprinkler == null) { return; } if (sprinkler.IsSprinkler() || sprinkler.Name.Contains("Sprinkler")) { /* if (LineSprinklersIsLoaded && sprinkler.Name.Contains("Line")) * { * ActivateLineSprinkler(sprinkler); * } * else if (PrismaticToolsApi != null && sprinkler.Name.Contains("Prismatic")) * { * ActivatePrismaticSprinkler(sprinkler); * } * else if (BetterSprinklersApi != null) * { * ActivateBetterSprinkler(sprinkler); * } * else if (SimpleSprinklerApi != null) * { * ActivateSimpleSprinkler(sprinkler); * } */ if (sprinkler.Name.Contains("Qi Sprinkler")) { ActivateQiSprinkler(sprinkler); } else { ActivateVanillaSprinkler(sprinkler); } } }
internal static bool DrawPrefix(Object __instance, SpriteBatch spriteBatch, int x, int y, float alpha = 1f) { if (__instance.modData.ContainsKey("AlternativeTextureName")) { var textureModel = AlternativeTextures.textureManager.GetSpecificTextureModel(__instance.modData["AlternativeTextureName"]); if (textureModel is null) { return(true); } var textureVariation = Int32.Parse(__instance.modData["AlternativeTextureVariation"]); if (textureVariation == -1 || AlternativeTextures.modConfig.IsTextureVariationDisabled(textureModel.GetId(), textureVariation)) { return(true); } var textureOffset = textureModel.GetTextureOffset(textureVariation); // Get the current X index for the source tile var xTileOffset = __instance.modData.ContainsKey("AlternativeTextureSheetId") ? __instance.ParentSheetIndex - Int32.Parse(__instance.modData["AlternativeTextureSheetId"]) : 0; if (__instance.showNextIndex) { xTileOffset += 1; } // Override xTileOffset if AlternativeTextureModel has an animation if (textureModel.HasAnimation(textureVariation)) { if (!__instance.modData.ContainsKey("AlternativeTextureCurrentFrame") || !__instance.modData.ContainsKey("AlternativeTextureFrameDuration") || !__instance.modData.ContainsKey("AlternativeTextureElapsedDuration")) { __instance.modData["AlternativeTextureCurrentFrame"] = "0"; __instance.modData["AlternativeTextureFrameDuration"] = textureModel.GetAnimationDataAtIndex(textureVariation, 0).Duration.ToString(); __instance.modData["AlternativeTextureElapsedDuration"] = "0"; } var currentFrame = Int32.Parse(__instance.modData["AlternativeTextureCurrentFrame"]); var frameDuration = Int32.Parse(__instance.modData["AlternativeTextureFrameDuration"]); var elapsedDuration = Int32.Parse(__instance.modData["AlternativeTextureElapsedDuration"]); if (elapsedDuration >= frameDuration) { currentFrame = currentFrame + 1 >= textureModel.GetAnimationData(textureVariation).Count() ? 0 : currentFrame + 1; __instance.modData["AlternativeTextureCurrentFrame"] = currentFrame.ToString(); __instance.modData["AlternativeTextureFrameDuration"] = textureModel.GetAnimationDataAtIndex(textureVariation, currentFrame).Duration.ToString(); __instance.modData["AlternativeTextureElapsedDuration"] = "0"; } else { __instance.modData["AlternativeTextureElapsedDuration"] = (elapsedDuration + Game1.currentGameTime.ElapsedGameTime.Milliseconds).ToString(); } xTileOffset = currentFrame; } xTileOffset *= textureModel.TextureWidth; if (__instance.bigCraftable) { // Get required draw values Vector2 scaleFactor = __instance.getScale() * 4f; Vector2 position = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64 - 64)); Rectangle destination = new Rectangle((int)(position.X - scaleFactor.X / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(position.Y - scaleFactor.Y / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(64f + scaleFactor.X), (int)(128f + scaleFactor.Y / 2f)); float draw_layer = Math.Max(0f, (float)((y + 1) * 64 - 24) / 10000f) + (float)x * 1E-05f; // Handle outliers for draw if (__instance.ParentSheetIndex == 105 || __instance.ParentSheetIndex == 264) { draw_layer = Math.Max(0f, (float)((y + 1) * 64 + 2) / 10000f) + (float)x / 1000000f; } if (__instance.ParentSheetIndex == 272) { spriteBatch.Draw(textureModel.GetTexture(textureVariation), destination, new Rectangle(16, textureOffset, 16, 32), Color.White * alpha, 0f, Vector2.Zero, SpriteEffects.None, draw_layer); spriteBatch.Draw(textureModel.GetTexture(textureVariation), position + new Vector2(8.5f, 12f) * 4f, new Rectangle(32, textureOffset, 16, 32), Color.White * alpha, (float)Game1.currentGameTime.TotalGameTime.TotalSeconds * -1.5f, new Vector2(7.5f, 15.5f), 4f, SpriteEffects.None, draw_layer + 1E-05f); return(false); } // Perform base game draw logic spriteBatch.Draw(textureModel.GetTexture(textureVariation), destination, new Rectangle(xTileOffset, textureOffset, textureModel.TextureWidth, textureModel.TextureHeight), Color.White * alpha, 0f, Vector2.Zero, SpriteEffects.None, draw_layer); // Replicate the extra draw logic from the base game if (__instance.Name.Equals("Loom") && (int)__instance.minutesUntilReady > 0) { spriteBatch.Draw(textureModel.GetTexture(textureVariation), __instance.getLocalPosition(Game1.viewport) + new Vector2(32f, 0f), new Rectangle(32, textureOffset, 16, 16), Color.White * alpha, __instance.scale.X, new Vector2(8f, 8f), 4f, SpriteEffects.None, Math.Max(0f, (float)((y + 1) * 64) / 10000f + 0.0001f + (float)x * 1E-05f)); } if ((bool)__instance.isLamp && Game1.isDarkOut()) { spriteBatch.Draw(Game1.mouseCursors, position + new Vector2(-32f, -32f), new Rectangle(88, 1779, 32, 32), Color.White * 0.75f, 0f, Vector2.Zero, 4f, SpriteEffects.None, Math.Max(0f, (float)((y + 1) * 64 - 20) / 10000f) + (float)x / 1000000f); } if ((int)__instance.parentSheetIndex == 126 && (int)__instance.quality != 0) { spriteBatch.Draw(FarmerRenderer.hatsTexture, position + new Vector2(-3f, -6f) * 4f, new Rectangle(((int)__instance.quality - 1) * 20 % FarmerRenderer.hatsTexture.Width, ((int)__instance.quality - 1) * 20 / FarmerRenderer.hatsTexture.Width * 20 * 4, 20, 20), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, Math.Max(0f, (float)((y + 1) * 64 - 20) / 10000f) + (float)x * 1E-05f); } } else if (!Game1.eventUp || (Game1.CurrentEvent != null && !Game1.CurrentEvent.isTileWalkedOn(x, y))) { if ((int)__instance.parentSheetIndex == 590) { Vector2 position2 = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), y * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0))); Color color = Color.White * alpha; Vector2 origin = new Vector2(8f, 8f); int artifactOffset = ((Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 1200.0 <= 400.0) ? ((int)(Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 400.0 / 100.0) * 16) : 0); spriteBatch.Draw(textureModel.GetTexture(textureVariation), position2, new Rectangle(artifactOffset, textureOffset, 16, 16), color, 0f, origin, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (float)(__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f); return(false); } if ((int)__instance.fragility != 2) { spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32, y * 64 + 51 + 4)), Game1.shadowTexture.Bounds, Color.White * alpha, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)__instance.getBoundingBox(new Vector2(x, y)).Bottom / 15000f); } Color color2 = Color.White * alpha; Vector2 origin2 = new Vector2(8f, 8f); Vector2 position3 = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), y * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0))); if (__instance.ParentSheetIndex == 746) { origin2 = Vector2.Zero; position3 = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64 - 64)); } spriteBatch.Draw(textureModel.GetTexture(textureVariation), position3, new Rectangle(xTileOffset, textureOffset, textureModel.TextureWidth, textureModel.TextureHeight), color2, 0f, origin2, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (float)(__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f); if (__instance.heldObject.Value != null && __instance.IsSprinkler()) { // Unhandled sprinkler attachments return(false); } } // Check if product is ready to display (if applicable) if (!__instance.readyForHarvest) { return(false); } float base_sort = (float)((y + 1) * 64) / 10000f + __instance.tileLocation.X / 50000f; if ((int)__instance.parentSheetIndex == 105 || (int)__instance.parentSheetIndex == 264) { base_sort += 0.02f; } float yOffset = 4f * (float)Math.Round(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 250.0), 2); spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 - 8, (float)(y * 64 - 96 - 16) + yOffset)), new Microsoft.Xna.Framework.Rectangle(141, 465, 20, 24), Color.White * 0.75f, 0f, Vector2.Zero, 4f, SpriteEffects.None, base_sort + 1E-06f); if (__instance.heldObject.Value != null) { spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32, (float)(y * 64 - 64 - 8) + yOffset)), Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, __instance.heldObject.Value.parentSheetIndex, 16, 16), Color.White * 0.75f, 0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, base_sort + 1E-05f); if (__instance.heldObject.Value is ColoredObject) { spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32, (float)(y * 64 - 64 - 8) + yOffset)), Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, (int)__instance.heldObject.Value.parentSheetIndex + 1, 16, 16), (__instance.heldObject.Value as ColoredObject).color.Value * 0.75f, 0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, base_sort + 1.1E-05f); } } return(false); } return(true); }
public static bool performRemoveAction_Prefix(StardewValley.Object __instance, Vector2 tileLocation, GameLocation environment) { if (__instance.lightSource != null && (__instance.Name.Contains("arecrow") || __instance.IsSprinkler())) { // Get object location (int) Vector2 c = tileLocation; c.X = (int)c.X; c.Y = (int)c.Y; // Remove light from map data ModEntry.mapDict.disableLightOnObject(Game1.currentLocation.Name, c); // Spawn torch int oldCount = Game1.currentLocation.debris.Count; Game1.createItemDebris(new Torch(__instance.TileLocation, 1), tileLocation * 64f, (Game1.player.FacingDirection + 2) % 4); int newCount = Game1.currentLocation.debris.Count; } return(true); }