public bool IsWalkableTile(Vector2 tile) { StardewValley.Object o = gl.getObjectAtTile((int)tile.X, (int)tile.Y); StardewValley.Objects.Furniture furn = o as StardewValley.Objects.Furniture; Fence fence = o as Fence; //bool a = gl.isTileOnMap(tile); //bool b = !gl.isTileOccupiedIgnoreFloors(tile, character); //bool c = isTilePassableOverride(new Location((int)tile.X, (int)tile.Y), Game1.viewport); //bool d = (!(gameLocation is Farm) || !((gameLocation as Farm).getBuildingAt(tile) != null)); //bool ea = !(o != null); //bool eba = (o != null); //bool ebba = (o as StardewValley.Objects.Furniture).furniture_type.Value == 12; //bool ebbba = ((o as Fence).isGate.Value); //bool ebbbb = (o as Fence).gatePosition.Value == 88; //bool ebbb = ebbba && ebbbb; //bool ebb = ebba || ebbb; //bool eb = eba && ebb; //bool full = (!(o != null) || (o != null && ((o as StardewValley.Objects.Furniture).furniture_type.Value == 12 || (((o as Fence).isGate.Value) && (o as Fence).gatePosition.Value == 88)))); //bool one = gl.isTileOnMap(tile); //bool two = !isTileOccupiedIgnoreFloorsOverride(tile, character); //bool three = isTilePassableOverride(new Location((int) tile.X, (int) tile.Y), Game1.viewport); //bool four = (!(gameLocation is Farm) || !((gameLocation as Farm).getBuildingAt(tile) != null)); //bool five = (!(o != null) || (furn != null && furn.furniture_type.Value == 12) || // (fence != null && fence.isGate.Value && (o as Fence).gatePosition.Value == 88)); return(gl.isTileOnMap(tile) && !isTileOccupiedIgnoreFloorsOverride(tile) && isTilePassableOverride(new Location((int)tile.X, (int)tile.Y), Game1.viewport) && (!(gameLocation is Farm) || !((gameLocation as Farm).getBuildingAt(tile) != null)) && (!(o != null) || (furn != null && furn.furniture_type.Value == 12) || (fence != null && fence.isGate.Value && (o as Fence).gatePosition.Value == 88))); }
public static bool Prefix(StardewValley.Objects.Furniture __instance, SpriteBatch spriteBatch, int x, int y, float alpha = 1f) { if (!ModEntry.Instance.GetDrawInfo(__instance.heldObject.Value, out Texture2D spriteSheet, out Rectangle bagiPosition, out Rectangle iconPosition)) { return(true); } if (!__instance.isTemporarilyInvisible) { if (StardewValley.Objects.Furniture.isDrawingLocationFurniture) { Vector2 drawPosition = Traverse.Create(__instance).Field <NetVector2>("drawPosition").Value.Value; spriteBatch.Draw(StardewValley.Objects.Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, (Vector2)drawPosition + (__instance.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero)), new Rectangle?((Rectangle)(__instance.sourceRect)), Color.White * alpha, 0.0f, Vector2.Zero, 4f, (bool)(__instance.flipped) ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (int)(__instance.furniture_type) == 12 ? 2E-09f : (float)(__instance.boundingBox.Value.Bottom - ((int)(__instance.furniture_type) == 6 || (int)(__instance.furniture_type) == 13 ? 48 : 8)) / 10000f); } else { spriteBatch.Draw(StardewValley.Objects.Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + (__instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)), (float)(y * 64 - (__instance.sourceRect.Height * 4 - __instance.boundingBox.Height) + (__instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)))), new Rectangle?((Rectangle)(__instance.sourceRect)), Color.White * alpha, 0.0f, Vector2.Zero, 4f, (bool)(__instance.flipped) ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (int)(__instance.furniture_type) == 12 ? 2E-09f : (float)(__instance.boundingBox.Value.Bottom - ((int)(__instance.furniture_type) == 6 || (int)(__instance.furniture_type) == 13 ? 48 : 8)) / 10000f); } if (__instance.heldObject.Value != null) { if (__instance.heldObject.Value is StardewValley.Objects.Furniture) { (__instance.heldObject.Value as StardewValley.Objects.Furniture).drawAtNonTileSpot(spriteBatch, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(__instance.boundingBox.Center.X - 32), (float)(__instance.boundingBox.Center.Y - (__instance.heldObject.Value as StardewValley.Objects.Furniture).sourceRect.Height * 4 - ((bool)(__instance.drawHeldObjectLow) ? -16 : 16)))), (float)(__instance.boundingBox.Bottom - 7) / 10000f, alpha); } else { SpriteBatch spriteBatch1 = spriteBatch; Texture2D shadowTexture = Game1.shadowTexture; Vector2 position = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(__instance.boundingBox.Center.X - 32), (float)(__instance.boundingBox.Center.Y - ((bool)(__instance.drawHeldObjectLow) ? 32 : 85)))) + new Vector2(32f, 53f); Rectangle? sourceRectangle = new Rectangle?(Game1.shadowTexture.Bounds); Color color = Color.White * alpha; Rectangle bounds = Game1.shadowTexture.Bounds; double x1 = (double)bounds.Center.X; bounds = Game1.shadowTexture.Bounds; double y1 = (double)bounds.Center.Y; Vector2 origin = new Vector2((float)x1, (float)y1); double num = (double)__instance.boundingBox.Bottom / 10000.0; spriteBatch1.Draw(shadowTexture, position, sourceRectangle, color, 0.0f, origin, 4f, SpriteEffects.None, (float)num); spriteBatch.Draw(spriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(__instance.boundingBox.Center.X - 32), (float)(__instance.boundingBox.Center.Y - ((bool)(__instance.drawHeldObjectLow) ? 32 : 85)))), bagiPosition, Color.White * alpha, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)(__instance.boundingBox.Bottom + 1) / 10000f); } } if ((bool)(__instance.IsOn) && (int)(__instance.furniture_type.Value) == 14) { spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(__instance.boundingBox.Center.X - 12), (float)(__instance.boundingBox.Center.Y - 64))), new Rectangle?(new Rectangle(276 + (int)((Game1.currentGameTime.TotalGameTime.TotalMilliseconds + (double)(x * 3047) + (double)(y * 88)) % 400.0 / 100.0) * 12, 1985, 12, 11)), Color.White, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)(__instance.getBoundingBox(new Vector2((float)x, (float)y)).Bottom - 2) / 10000f); spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(__instance.boundingBox.Center.X - 32 - 4), (float)(__instance.boundingBox.Center.Y - 64))), new Rectangle?(new Rectangle(276 + (int)((Game1.currentGameTime.TotalGameTime.TotalMilliseconds + (double)(x * 2047) + (double)(y * 98)) % 400.0 / 100.0) * 12, 1985, 12, 11)), Color.White, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)(__instance.getBoundingBox(new Vector2((float)x, (float)y)).Bottom - 1) / 10000f); } if (Game1.debugMode) { Vector2 drawPosition = Traverse.Create(__instance).Field <NetVector2>("drawPosition").Value.Value; spriteBatch.DrawString(Game1.smallFont, string.Concat((object)__instance.ParentSheetIndex), Game1.GlobalToLocal(Game1.viewport, (Vector2)drawPosition), Color.Yellow, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 1f); } } return(false); }
public static void resetOnPlayerEntry_Postfix(StardewValley.Objects.Furniture __instance, GameLocation environment, bool dropDown) { try { if ((__instance.ParentSheetIndex == HutchIdx) && !dropDown) { SpawnButterflies(environment, CountButterflies(environment) - Before, __instance.boundingBox.Value); } } catch (Exception ex) { Log.Error($"Failed in {nameof(resetOnPlayerEntry_Postfix)}:\n{ex}"); } }
public static bool resetOnPlayerEntry_Prefix(StardewValley.Objects.Furniture __instance, GameLocation environment, bool dropDown) { try { if ((__instance.ParentSheetIndex == HutchIdx) && !dropDown) { Before = CountButterflies(environment); } return(true); } catch (Exception ex) { Log.Error($"Failed in {nameof(resetOnPlayerEntry_Prefix)}:\n{ex}"); return(true); } }
public bool IsWalkableTile(Vector2 tile) { StardewValley.Object o = gl.getObjectAtTile((int)tile.X, (int)tile.Y); StardewValley.Objects.Furniture furn = o as StardewValley.Objects.Furniture; Fence fence = o as Fence; Torch torch = o as Torch; return(gl.isTileOnMap(tile) && !isTileOccupiedIgnoreFloorsOverride(tile) && isTilePassableOverride(new Location((int)tile.X, (int)tile.Y), Game1.viewport) && (!(gameLocation is Farm) || !((gameLocation as Farm).getBuildingAt(tile) != null)) && ((o == null) || (furn != null && furn.furniture_type.Value == 12) || (fence != null && fence.isGate.Value) || (torch != null) || (o.ParentSheetIndex == 590))); }
internal bool isCompletelyClear(StardewValley.Objects.Furniture furniture, Vector2 point, FarmHouse house) { for (int x1 = (int)point.X; x1 < point.X + furniture.getTilesWide(); ++x1) { for (int y1 = (int)point.Y; y1 < point.Y + furniture.getTilesHigh(); ++y1) { if (house.doesTileHaveProperty(x1, y1, "NoFurniture", "Back") != null) { return(false); } if (house.getTileIndexAt(x1, y1, "Buildings") != -1) { return(false); } } } return(true); }
internal bool isFurnitureSpotValid(StardewValley.Objects.Furniture furniture, FarmHouse house) { if (furniture.furniture_type == StardewValley.Objects.Furniture.rug) { Logger.Log(furniture.name + " was rug, looking for placement location..."); for (int x = furniture.boundingBox.X; x < furniture.boundingBox.Right; x++) { for (int y = furniture.boundingBox.Y; y < furniture.boundingBox.Bottom; y++) { if (!isTilePassableForRugs(house, new xTile.Dimensions.Location(x, y), Game1.viewport)) { Logger.Log("Tile (" + x + ", " + y + ") was not passable for rugs!"); return(false); } } } Logger.Log("Rug can be placed here."); return(true); } else { Logger.Log(furniture.name + " was not rug, was " + furniture.furniture_type); } Vector2 realLocation = furniture.tileLocation; furniture.tileLocation.Value = Vector2.Zero; reclaculateFurniture(furniture); bool isValid = furniture.canBePlacedHere(house, realLocation); bool isPartiallyStuck = !isCompletelyClear(furniture, realLocation, house); bool isVoid = isTileVoid(house, realLocation); Logger.Log("Spot valid? " + isValid.ToString() + " Partially Stuck? " + isPartiallyStuck.ToString() + " Void? " + isVoid.ToString()); furniture.tileLocation.Value = realLocation; reclaculateFurniture(furniture); return(isValid && !isPartiallyStuck && !isVoid); }
internal void reclaculateFurniture(StardewValley.Objects.Furniture furniture) { furniture.boundingBox.X = (int)furniture.tileLocation.Value.X * 64; furniture.boundingBox.Y = (int)furniture.tileLocation.Value.Y * 64; furniture.updateDrawPosition(); }
internal void fixFurniture(StardewValley.Objects.Furniture furniture, FarmHouse house, ref List <StardewValley.Objects.Furniture> deadFurniture, ref List <Item> itemsToStore, int placementAttempt = 0) { if (house.isTileOnMap(furniture.tileLocation) && (furniture.furniture_type == StardewValley.Objects.Furniture.window || furniture.furniture_type == StardewValley.Objects.Furniture.painting)) { bool wasOnWall = false; foreach (Rectangle wall in house.getWalls()) { if (wall.Contains(new Point((int)furniture.tileLocation.X, (int)furniture.tileLocation.Y))) { wasOnWall = true; break; } } if (!wasOnWall) { Logger.Log("Wall furniture was not on a wall! Moving..."); List <Rectangle> walls = house.getWalls(); int wallToPlace = Game1.random.Next(walls.Count); Vector2 placeSpot = Vector2.Zero; int attempts = 0; while (placeSpot == Vector2.Zero && attempts < 20) { int wallX = Game1.random.Next(walls[wallToPlace].Width) + walls[wallToPlace].X; Vector2 testSpot = new Vector2(wallX, walls[wallToPlace].Y); if (!house.isTileOccupiedForPlacement(testSpot, furniture)) { placeSpot = testSpot; } attempts++; Logger.Log("Suitable wall location not found! Trying again... Attempt #" + attempts); } if (placeSpot == Vector2.Zero) { Logger.Log("Could not find a suitable location for a piece of furniture. Storing it in a gift box."); itemsToStore.Add(furniture); deadFurniture.Add(furniture); } else { furniture.tileLocation.Value = new Vector2(placeSpot.X, placeSpot.Y); reclaculateFurniture(furniture); Logger.Log("Placing furniture at " + furniture.tileLocation.ToString()); } } } else if (!house.isTileOnMap(furniture.tileLocation) || !isFurnitureSpotValid(furniture, house)) { Logger.Log("Furniture was stuck, moving..."); Point newSpot = house.getRandomOpenPointInHouse(Game1.random); int attempts = 0; while ((newSpot == Point.Zero || !furniture.canBePlacedHere(house, new Vector2(newSpot.X, newSpot.Y)) || !isCompletelyClear(furniture, new Vector2(newSpot.X, newSpot.Y), house) || isTileVoid(house, new Vector2(newSpot.X, newSpot.Y)) || (furniture.furniture_type == StardewValley.Objects.Furniture.window)) && attempts < 20) { newSpot = house.getRandomOpenPointInHouse(Game1.random); attempts++; Logger.Log("Failed to find empty open spot in the farmhouse for a piece of furniture. Attempt #" + attempts); } if (newSpot == Point.Zero) { Logger.Log("Could not find a suitable location for a piece of furniture. Storing it in a gift box."); itemsToStore.Add(furniture); deadFurniture.Add(furniture); } else { furniture.tileLocation.Value = new Vector2(newSpot.X, newSpot.Y); reclaculateFurniture(furniture); Logger.Log("Placing furniture at " + furniture.tileLocation.ToString()); } if (!isFurnitureSpotValid(furniture, house) && placementAttempt < 20) { Logger.Log("Placement failed, spot was invalid. Retrying... Attempt #" + placementAttempt); fixFurniture(furniture, house, ref deadFurniture, ref itemsToStore, placementAttempt + 1); } } else { //Logger.Log("Skipping " + furniture.tileLocation.ToString() + " because it " + (house.isTileOnMap(furniture.tileLocation) ? "was on the map, and " : "was not on the map, and ") + (!canBePlaced ? "was not placeable." : "was placeable.")); Logger.Log("Skipping " + furniture.name + " at " + furniture.tileLocation.ToString() + "."); } }