private void UpdateObjectInfoList(AnimalHouse animalHouse) { this.ObjectInfoList.RemoveAll(soi => soi.Location == animalHouse); foreach (KeyValuePair <Vector2, StardewValley.Object> o in animalHouse.Objects.Pairs) { if (o.Value.Name.Equals("Hay")) { var soi = new StardewObjectInfo(); soi.Coordinate = o.Key * Game1.tileSize + new Vector2(Game1.tileSize / 2, Game1.tileSize / 2); soi.Location = animalHouse; } } var houseWidth = animalHouse.map.Layers[0].LayerWidth; var houseHeight = animalHouse.map.Layers[0].LayerHeight; for (int tileX = 0; tileX < houseWidth; tileX++) { for (int tileY = 0; tileY < houseWidth; tileY++) { bool tileIsTrough = animalHouse.doesTileHaveProperty(tileX, tileY, "Trough", "Back") != null; if (tileIsTrough) { bool tileHasHay = animalHouse.Objects.ContainsKey(new Vector2(tileX, tileY)); var soi = new StardewObjectInfo(); soi.Coordinate = new Vector2((tileX + 0.5f) * Game1.tileSize, (tileY + 0.5f) * Game1.tileSize); soi.Location = animalHouse; soi.NeedAction = !tileHasHay; this.ObjectInfoList.Add(soi); } } } }
/// <summary>Get the feed metrics for an animal building.</summary> /// <param name="building">The animal building to check.</param> /// <param name="total">The total number of feed trough spaces.</param> /// <param name="filled">The number of feed trough spaces which contain hay.</param> private void GetFeedMetrics(AnimalHouse building, out int total, out int filled) { var map = building.Map; total = 0; filled = 0; for (int x = 0; x < map.Layers[0].LayerWidth; x++) { for (int y = 0; y < map.Layers[0].LayerHeight; y++) { if (building.doesTileHaveProperty(x, y, "Trough", "Back") != null) { total++; if (building.objects.TryGetValue(new Vector2(x, y), out SObject obj) && obj.ParentSheetIndex == 178) { filled++; } } } } }
private static IList <Vector2> GetAnimalTroughs(AnimalHouse animalHouse) { var animalTroughs = new List <Vector2>(); for (var xTile = 0; xTile < animalHouse.map.Layers[0].LayerWidth; ++xTile) { for (var yTile = 0; yTile < animalHouse.map.Layers[0].LayerHeight; ++yTile) { if (animalHouse.doesTileHaveProperty(xTile, yTile, "Trough", "Back") == null) { continue; } var key = new Vector2(xTile, yTile); animalTroughs.Add(key); if (animalTroughs.Count >= animalHouse.animalLimit) { return(animalTroughs); } } } return(animalTroughs); }