public static int CheckClearance(GameLocation location, Rectangle rect) { int j = 0; for (j = 0; j < 5; j++) { bool fail = false; for (int x = rect.Left; x < rect.Right; x++) { for (int y = rect.Top; y < rect.Bottom; y++) { Object tile_object = location.getObjectAtTile(x, y); if (tile_object != null && !tile_object.isPassable()) { fail = true; break; } } } if (fail) { return(j); } } return(j); }
private static bool isPassableTile(GameLocation location, int x, int y) { var tile = new Vector2(x, y); Location displayLoc = new Location(x * Game1.tileSize, y * Game1.tileSize); StardewValley.Object obj = null; location.objects.TryGetValue(tile, out obj); TerrainFeature terrainObj = null; location.terrainFeatures.TryGetValue(tile, out terrainObj); Building building = null; if (location is BuildableGameLocation) { building = ((BuildableGameLocation)location).getBuildingAt(tile); } return(location.isPointPassable(displayLoc, Game1.viewport) && building == null && (obj == null || obj.isPassable()) && (terrainObj == null || terrainObj.isPassable())); }
public static int GetFarmTileWeight(GameLocation location, int x, int y, Dictionary <Vector2, int> weight_map) { Vector2 tile_position = new Vector2(x, y); if (weight_map.ContainsKey(tile_position)) { return(weight_map[tile_position]); } int weight = 0; Object tile_object = location.getObjectAtTile(x, y); Fence fence; if (tile_object != null && !tile_object.isPassable() && ((fence = (tile_object as Fence)) == null || !fence.isGate)) { weight = 9999; } if (location.terrainFeatures.TryGetValue(tile_position, out TerrainFeature feature) && feature is Flooring) { weight -= 50; } weight_map[tile_position] = weight; return(weight); }
/// <summary> /// Shows the cursor as green when hovering over a tile that can be /// fertilized using this mod /// </summary> /// <param name="__instance"></param> /// <param name="tileLocation"></param> /// <param name="toPlace"></param> /// <param name="__result"></param> public static void isTileOccupiedForPlacement_Postfix(GameLocation __instance, Vector2 tileLocation, StardewValley.Object toPlace, ref bool __result) { try { // Replicated logic from the original method __instance.objects.TryGetValue(tileLocation, out StardewValley.Object o); Rectangle tileLocationRect = new Rectangle((int)tileLocation.X * 64, (int)tileLocation.Y * 64, 64, 64); for (int i = 0; i < __instance.characters.Count; i++) { if (__instance.characters[i] != null && __instance.characters[i].GetBoundingBox().Intersects(tileLocationRect)) { return; } } if (__instance.isTileOccupiedByFarmer(tileLocation) != null && (toPlace == null || !toPlace.isPassable())) { return; } if (__instance.largeTerrainFeatures != null) { foreach (LargeTerrainFeature largeTerrainFeature in __instance.largeTerrainFeatures) { if (largeTerrainFeature.getBoundingBox().Intersects(tileLocationRect)) { return; } } } // New logic - show the cursor as green if fertilizer can be placed there if (toPlace is Item && IsValidTileAndItem(__instance, tileLocation, toPlace, out _)) { __result = false; } } catch (Exception ex) { Monitor.Log($"Failed in {nameof(isTileOccupiedForPlacement_Postfix)}:\n{ex}", LogLevel.Error); } }
private static void Draw(SObject instance, SpriteBatch spriteBatch, int x, int y, float alpha, Texture2D spriteSheet, Rectangle position) { if (instance.isTemporarilyInvisible) { return; } if ((bool)(instance.bigCraftable)) { Vector2 vector2 = instance.getScale() * 4f; Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64), (float)(y * 64 - 64))); Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)local.X - (double)vector2.X / 2.0) + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)local.Y - (double)vector2.Y / 2.0) + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)(64.0 + (double)vector2.X), (int)(128.0 + (double)vector2.Y / 2.0)); float layerDepth = Math.Max(0.0f, (float)((y + 1) * 64 - 24) / 10000f) + (float)x * 1E-05f; if (instance.ParentSheetIndex == 105) { layerDepth = Math.Max(0.0f, (float)((y + 1) * 64 + 2) / 10000f) + (float)x / 1000000f; } spriteBatch.Draw(Game1.bigCraftableSpriteSheet, destinationRectangle, new Microsoft.Xna.Framework.Rectangle?(SObject.getSourceRectForBigCraftable((bool)(instance.showNextIndex) ? instance.ParentSheetIndex + 1 : instance.ParentSheetIndex)), Color.White * alpha, 0.0f, Vector2.Zero, SpriteEffects.None, layerDepth); if (instance.Name.Equals("Loom") && (int)(instance.minutesUntilReady) > 0) { spriteBatch.Draw(Game1.objectSpriteSheet, instance.getLocalPosition(Game1.viewport) + new Vector2(32f, 0.0f), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 435, 16, 16)), Color.White * alpha, instance.scale.X, new Vector2(8f, 8f), 4f, SpriteEffects.None, Math.Max(0.0f, (float)((double)((y + 1) * 64) / 10000.0 + 9.99999974737875E-05 + (double)x * 9.99999974737875E-06))); } if ((bool)(instance.isLamp) && Game1.isDarkOut()) { spriteBatch.Draw(Game1.mouseCursors, local + new Vector2(-32f, -32f), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(88, 1779, 32, 32)), Color.White * 0.75f, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, Math.Max(0.0f, (float)((y + 1) * 64 - 20) / 10000f) + (float)x / 1000000f); } if ((int)(instance.parentSheetIndex) == 126 && (int)(instance.quality) != 0) { spriteBatch.Draw(FarmerRenderer.hatsTexture, local + new Vector2(-3f, -6f) * 4f, new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(((int)(instance.quality) - 1) * 20 % FarmerRenderer.hatsTexture.Width, ((int)(instance.quality) - 1) * 20 / FarmerRenderer.hatsTexture.Width * 20 * 4, 20, 20)), Color.White * alpha, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, Math.Max(0.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) { SpriteBatch spriteBatch1 = spriteBatch; Texture2D mouseCursors = Game1.mouseCursors; Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32 + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)), (float)(y * 64 + 32 + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)))); Microsoft.Xna.Framework.Rectangle?sourceRectangle = new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(368 + (Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 1200.0 <= 400.0 ? (int)(Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 400.0 / 100.0) * 16 : 0), 32, 16, 16)); Color color = Color.White * alpha; Vector2 origin = new Vector2(8f, 8f); Vector2 scale = instance.scale; double num1 = (double)instance.scale.Y > 1.0 ? (double)instance.getScale().Y : 4.0; int num2 = (bool)(instance.flipped) ? 1 : 0; double num3 = (instance.isPassable() ? (double)instance.getBoundingBox(new Vector2((float)x, (float)y)).Top : (double)instance.getBoundingBox(new Vector2((float)x, (float)y)).Bottom) / 10000.0; spriteBatch1.Draw(mouseCursors, local, sourceRectangle, color, 0.0f, origin, (float)num1, (SpriteEffects)num2, (float)num3); return; } Microsoft.Xna.Framework.Rectangle rectangle; if ((int)(instance.fragility) != 2) { SpriteBatch spriteBatch1 = spriteBatch; Texture2D shadowTexture = Game1.shadowTexture; Vector2 local = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32), (float)(y * 64 + 51 + 4))); Microsoft.Xna.Framework.Rectangle?sourceRectangle = new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds); Color color = Color.White * alpha; rectangle = Game1.shadowTexture.Bounds; double x1 = (double)rectangle.Center.X; rectangle = Game1.shadowTexture.Bounds; double y1 = (double)rectangle.Center.Y; Vector2 origin = new Vector2((float)x1, (float)y1); rectangle = instance.getBoundingBox(new Vector2((float)x, (float)y)); double num = (double)rectangle.Bottom / 15000.0; spriteBatch1.Draw(shadowTexture, local, sourceRectangle, color, 0.0f, origin, 4f, SpriteEffects.None, (float)num); } SpriteBatch spriteBatch2 = spriteBatch; Texture2D objectSpriteSheet = Game1.objectSpriteSheet; Vector2 local1 = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32 + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)), (float)(y * 64 + 32 + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)))); Microsoft.Xna.Framework.Rectangle?sourceRectangle1 = new Microsoft.Xna.Framework.Rectangle?(GameLocation.getSourceRectForObject(instance.ParentSheetIndex)); Color color1 = Color.White * alpha; Vector2 origin1 = new Vector2(8f, 8f); Vector2 scale1 = instance.scale; double num4 = (double)instance.scale.Y > 1.0 ? (double)instance.getScale().Y : 4.0; int num5 = (bool)(instance.flipped) ? 1 : 0; int num6; if (!instance.isPassable()) { rectangle = instance.getBoundingBox(new Vector2((float)x, (float)y)); num6 = rectangle.Bottom; } else { rectangle = instance.getBoundingBox(new Vector2((float)x, (float)y)); num6 = rectangle.Top; } double num7 = (double)num6 / 10000.0; spriteBatch2.Draw(spriteSheet, local1, position, color1, 0.0f, origin1, (float)num4, (SpriteEffects)num5, (float)num7); } if (!(bool)(instance.readyForHarvest)) { return; } float num8 = (float)(4.0 * Math.Round(Math.Sin(DateTime.UtcNow.TimeOfDay.TotalMilliseconds / 250.0), 2)); spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 - 8), (float)(y * 64 - 96 - 16) + num8)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(141, 465, 20, 24)), Color.White * 0.75f, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)((double)((y + 1) * 64) / 10000.0 + 9.99999997475243E-07 + (double)instance.tileLocation.X / 10000.0 + ((int)(instance.parentSheetIndex) == 105 ? 0.00150000001303852 : 0.0))); if (instance.heldObject.Value == null) { return; } spriteBatch.Draw(spriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32), (float)(y * 64 - 64 - 8) + num8)), position, Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, (float)((double)((y + 1) * 64) / 10000.0 + 9.99999974737875E-06 + (double)instance.tileLocation.X / 10000.0 + ((int)(instance.parentSheetIndex) == 105 ? 0.00150000001303852 : 0.0))); if (!(instance.heldObject.Value is ColoredObject)) { return; } spriteBatch.Draw(spriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32), (float)(y * 64 - 64 - 8) + num8)), position, (instance.heldObject.Value as ColoredObject).color.Value * 0.75f, 0.0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, (float)((double)((y + 1) * 64) / 10000.0 + 9.99999974737875E-06 + (double)instance.tileLocation.X / 10000.0 + ((int)(instance.parentSheetIndex) == 105 ? 0.00150000001303852 : 9.99999974737875E-06))); }
private static bool Object_draw_Prefix(Object __instance, SpriteBatch spriteBatch, int x, int y, float alpha) { if (!(Game1.currentLocation is MineShaft)) { return(true); } if (rocks.Contains(__instance.parentSheetIndex) || treasures.Contains(__instance.parentSheetIndex)) { if (!flippedObjects.ContainsKey(new Vector2(x, y))) { flippedObjects[new Vector2(x, y)] = Game1.random.NextDouble() < 0.5; } bool flip = flippedObjects[new Vector2(x, y)]; Vector2 origin = new Vector2(8f, 8f); GetTileInfo(Game1.currentLocation.objects, x, y, __instance.parentSheetIndex, flip, out int tileIndex); if (tileIndex == -1) { return(true); } Rectangle sourceRect = new Rectangle(tileIndex * 16 % (sheetWidth * 16), tileIndex * 16 / (sheetWidth * 16) * 16, 16, 16); Vector2 position = 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))); spriteBatch.Draw(tilesheet, position, sourceRect, Color.White, 0, origin, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f); if (treasures.Contains(__instance.parentSheetIndex)) { Rectangle treasureRect = new Rectangle((treasures.IndexOf(__instance.parentSheetIndex) % sheetWidth) * 16, (10 + treasures.IndexOf(__instance.parentSheetIndex) / sheetWidth) * 16, 16, 16); spriteBatch.Draw(tilesheet, position, treasureRect, Color.White, 0, origin, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f + 0.001f); } return(false); } return(true); }
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); }
private void moveCharacter(GameTime time) { Point peek = pathToEndPoint.Peek(); Rectangle targetTile = new Rectangle(peek.X * 64, peek.Y * 64, 64, 64); targetTile.Inflate(-2, 0); Rectangle bbox = character.GetBoundingBox(); if ((targetTile.Contains(bbox) || (bbox.Width > targetTile.Width && targetTile.Contains(bbox.Center))) && targetTile.Bottom - bbox.Bottom >= 2) { timerSinceLastCheckPoint = 0; pathToEndPoint.Pop(); character.stopWithoutChangingFrame(); if (pathToEndPoint.Count == 0) { character.Halt(); if (finalFacingDirection != -1) { character.faceDirection(finalFacingDirection); } if (NPCSchedule) { NPC npc = character as NPC; npc.DirectionsToNewLocation = null; npc.endOfRouteMessage.Value = npc.nextEndOfRouteMessage; } if (endBehaviorFunction != null) { endBehaviorFunction(character, location); } } return; } Farmer farmer = character as Farmer; if (farmer != null) { farmer.movementDirections.Clear(); } else if (!(location is MovieTheater)) { string name = character.Name; foreach (NPC c in location.characters) { if (!c.Equals(character) && c.GetBoundingBox().Intersects(bbox) && c.isMoving() && string.Compare(c.Name, name, StringComparison.Ordinal) < 0) { character.Halt(); return; } } } if (bbox.Left < targetTile.Left && bbox.Right < targetTile.Right) { character.SetMovingRight(b: true); } else if (bbox.Right > targetTile.Right && bbox.Left > targetTile.Left) { character.SetMovingLeft(b: true); } else if (bbox.Top <= targetTile.Top) { character.SetMovingDown(b: true); } else if (bbox.Bottom >= targetTile.Bottom - 2) { character.SetMovingUp(b: true); } character.MovePosition(time, Game1.viewport, location); if (nonDestructivePathing) { if (targetTile.Intersects(character.nextPosition(character.facingDirection))) { Vector2 next_position = character.nextPositionVector2(); Object next_tile_object = location.getObjectAt((int)next_position.X, (int)next_position.Y); if (next_tile_object != null) { Fence fence; if ((fence = (next_tile_object as Fence)) != null && (bool)fence.isGate) { fence.toggleGate(location, open: true); } else if (!next_tile_object.isPassable()) { character.Halt(); character.controller = null; return; } } } handleWarps(character.nextPosition(character.getDirection())); } else if (NPCSchedule) { handleWarps(character.nextPosition(character.getDirection())); } }
private static bool Object_draw_Prefix(Object __instance, SpriteBatch spriteBatch, int x, int y, float alpha = 1f) { CustomOreNode node = customOreNodesList.Find(n => n.parentSheetIndex == __instance.ParentSheetIndex); if (node == null) { return(true); } if (__instance.Fragility != 2) { spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32, y * 64 + 51 + 4)), new Rectangle?(Game1.shadowTexture.Bounds), Color.White * alpha, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, __instance.getBoundingBox(new Vector2(x, y)).Bottom / 15000f); } 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))); Rectangle?sourceRectangle2 = new Rectangle(node.spriteX, node.spriteY, node.spriteW, node.spriteH); Color color2 = Color.White * alpha; float rotation2 = 0f; Vector2 origin2 = new Vector2(8f, 8f); Vector2 vector2 = __instance.scale; spriteBatch.Draw(node.texture, position3, sourceRectangle2, color2, rotation2, origin2, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, __instance.Flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f); return(false); }