public TypedChestWithDistance(TypedChest chest, double distance) { TypedChest = chest; Distance = distance; }
private static List <TypedChest> GetNearbyTypedChests(Point originTile, int range, GameLocation gameLocation) { var tChests = new List <TypedChest>((2 * range + 1) * (2 * range + 1)); // Chests for (int dx = -range; dx <= range; dx++) { for (int dy = -range; dy <= range; dy++) { Vector2 tileLocation = new Vector2(originTile.X + dx, originTile.Y + dy); if (gameLocation.objects.TryGetValue(tileLocation, out StardewValley.Object obj) && obj is Chest chest) { if (chest.GetMutex().IsLocked()) { continue; } ChestType chestType = TypedChest.GetChestType(chest); tChests.Add(new TypedChest(chest, chestType)); } } } // Kitchen fridge if (gameLocation is FarmHouse farmHouse && farmHouse.upgradeLevel >= 1) //Lvl 1,2,3 is where you have fridge upgrade { Point kitchenStandingSpot = farmHouse.getKitchenStandingSpot(); Point fridgeTileLocation = new Point(kitchenStandingSpot.X + 2, kitchenStandingSpot.Y - 1); //Fridge spot relative to kitchen spot if (IsTileWithinRange(originTile, fridgeTileLocation, range)) { if (farmHouse.fridge.Value != null && !farmHouse.fridge.Value.GetMutex().IsLocked()) { tChests.Add(new TypedChest(farmHouse.fridge.Value, ChestType.Fridge)); } } } // Island kitchen fridge if (gameLocation is IslandFarmHouse islandFarmHouse) { Point fridgeTileLocation = islandFarmHouse.fridgePosition; if (IsTileWithinRange(originTile, fridgeTileLocation, range)) { if (islandFarmHouse.fridge.Value != null && !islandFarmHouse.fridge.Value.GetMutex().IsLocked()) { tChests.Add(new TypedChest(islandFarmHouse.fridge.Value, ChestType.Fridge)); } } } // Buildings if (ModEntry.Config.IsQuickStackIntoBuildingsWithInventories) { if (gameLocation is BuildableGameLocation buildableGameLocation) { foreach (Building building in buildableGameLocation.buildings) { if (IsTileWithinRange(originTile, building.tileX.Value, building.tileY.Value, range)) { if (building is JunimoHut junimoHut) { if (junimoHut.output.Value.GetMutex().IsLocked()) { continue; } tChests.Add(new TypedChest(junimoHut.output.Value, ChestType.JunimoHut)); } else if (building is Mill mill) { if (mill.input.Value.GetMutex().IsLocked()) { continue; } tChests.Add(new TypedChest(mill.input.Value, ChestType.Mill)); } } } } } return(tChests); }
private static List <TypedChestWithDistance> GetNearbyTypedChestsWithDistance(Vector2 origin, int range, GameLocation gameLocation) { var tdChests = new List <TypedChestWithDistance>((2 * range + 1) * (2 * range + 1)); Vector2 originTileCenterPosition = GetTileCenterPosition(GetTileLocation(origin)); Vector2 tileLocation = Vector2.Zero; int tx, ty, dx, dy; // Chests (includes mini fridge, stone chest, mini shipping bin, junimo chest, ...) for (int x = -range; x <= range; x++) { for (int y = -range; y <= range; y++) { tx = (int)originTileCenterPosition.X + (x * Game1.tileSize); ty = (int)originTileCenterPosition.Y + (y * Game1.tileSize); tileLocation.X = tx / Game1.tileSize; tileLocation.Y = ty / Game1.tileSize; if (gameLocation.objects.TryGetValue(tileLocation, out StardewValley.Object obj) && obj is Chest chest) { // Make sure chest is not in-use by another player (easy fix to avoid item deletion) if (chest.GetMutex().IsLocked()) { continue; } dx = tx - (int)origin.X; dy = ty - (int)origin.Y; ChestType chestType = TypedChest.GetChestType(chest); var typedChest = new TypedChest(chest, chestType); tdChests.Add(new TypedChestWithDistance(typedChest, Math.Sqrt(dx * dx + dy * dy))); } } } // Kitchen fridge if (gameLocation is FarmHouse farmHouse && farmHouse.upgradeLevel > 0) // Kitchen only exists when upgradeLevel > 0 { Vector2 fridgeTileCenterPosition = GetTileCenterPosition(farmHouse.fridgePosition); if (IsPositionWithinRange(origin, fridgeTileCenterPosition, range)) { if (farmHouse.fridge.Value != null && !farmHouse.fridge.Value.GetMutex().IsLocked()) { dx = (int)fridgeTileCenterPosition.X - (int)origin.X; dy = (int)fridgeTileCenterPosition.Y - (int)origin.Y; var typedChest = new TypedChest(farmHouse.fridge.Value, ChestType.Fridge); tdChests.Add(new TypedChestWithDistance(typedChest, Math.Sqrt(dx * dx + dy * dy))); } } } // Island kitchen fridge if (gameLocation is IslandFarmHouse islandFarmHouse) { Vector2 fridgeTileCenterPosition = GetTileCenterPosition(islandFarmHouse.fridgePosition); if (IsPositionWithinRange(origin, fridgeTileCenterPosition, range)) { if (islandFarmHouse.fridge.Value != null && !islandFarmHouse.fridge.Value.GetMutex().IsLocked()) { dx = (int)fridgeTileCenterPosition.X - (int)origin.X; dy = (int)fridgeTileCenterPosition.Y - (int)origin.Y; var typedChest = new TypedChest(islandFarmHouse.fridge.Value, ChestType.Fridge); tdChests.Add(new TypedChestWithDistance(typedChest, Math.Sqrt(dx * dx + dy * dy))); } } } // Buildings if (ModEntry.Config.IsQuickStackIntoBuildingsWithInventories) { if (gameLocation is BuildableGameLocation buildableGameLocation) { foreach (Building building in buildableGameLocation.buildings) { Vector2 buildingTileCenterPosition = GetTileCenterPosition(building.tileX.Value, building.tileY.Value); if (IsPositionWithinRange(origin, buildingTileCenterPosition, range)) { if (building is JunimoHut junimoHut) { if (junimoHut.output.Value.GetMutex().IsLocked()) { continue; } dx = (int)buildingTileCenterPosition.X - (int)origin.X; dy = (int)buildingTileCenterPosition.Y - (int)origin.Y; var typedChest = new TypedChest(junimoHut.output.Value, ChestType.JunimoHut); tdChests.Add(new TypedChestWithDistance(typedChest, Math.Sqrt(dx * dx + dy * dy))); } else if (building is Mill mill) { if (mill.isUnderConstruction() || mill.input.Value.GetMutex().IsLocked()) { continue; } dx = (int)buildingTileCenterPosition.X - (int)origin.X; dy = (int)buildingTileCenterPosition.Y - (int)origin.Y; var typedChest = new TypedChest(mill.input.Value, ChestType.Mill); tdChests.Add(new TypedChestWithDistance(typedChest, Math.Sqrt(dx * dx + dy * dy))); } } } } } return(tdChests); }