private void OnRenderedWorld(object?sender, RenderedWorldEventArgs e) { if (SprinklerCoverageAlpha <= 0f) { return; } GameLocation location = Game1.currentLocation; if (location is null) { return; } var sprinklerTilesWithSteps = SprinklerBehavior.GetSprinklerTilesWithSteps(new GameLocationMap(location, CustomWaterableTileProviders)); var alreadyShown = new HashSet <IntPoint>(); foreach (var step in sprinklerTilesWithSteps) { if (Config.CoverageAnimationInSeconds > 0f && step.Item2 * Config.CoverageAnimationInSeconds > SprinklerCoverageCurrentAnimationTime) { break; } foreach (var sprinklerTile in step.Item1) { if (!Config.CoverageOverlayDuplicates) { if (alreadyShown.Contains(sprinklerTile)) { continue; } alreadyShown.Add(sprinklerTile); } var position = new Vector2(sprinklerTile.X * Game1.tileSize, sprinklerTile.Y * Game1.tileSize); e.SpriteBatch.Draw( Game1.mouseCursors, Game1.GlobalToLocal(position), new Rectangle(194, 388, 16, 16), Color.White * Math.Clamp(SprinklerCoverageAlpha, 0f, 1f), 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 0.01f ); } } }
private bool PrivateIsTileInRangeOfSprinklers(IEnumerable <SObject> sprinklers, GameLocation location, Vector2 tileLocation, bool isForAllSprinklers) { var sprinklersList = sprinklers.ToList(); foreach (var sprinkler in sprinklersList) { if (!sprinkler.IsSprinkler()) { continue; } var info = GetSprinklerInfo(sprinkler); var manhattanDistance = ((int)tileLocation.X - (int)sprinkler.TileLocation.X) + ((int)tileLocation.Y - (int)sprinkler.TileLocation.Y); if (manhattanDistance > GetFloodFillSprinklerRange(info.Power)) { if (SprinklerBehavior is not ISprinklerBehavior.Independent || !info.Layout.Contains(tileLocation - sprinkler.TileLocation)) { continue; } } goto afterSimpleCheck; } return(false); afterSimpleCheck :; if (isForAllSprinklers) { return(SprinklerBehavior.GetSprinklerTiles( new GameLocationMap(location, CustomWaterableTileProviders) ).Contains(new IntPoint((int)tileLocation.X, (int)tileLocation.Y))); } else if (SprinklerBehavior is ISprinklerBehavior.Independent independent) { return(independent.GetSprinklerTiles( new GameLocationMap(location, CustomWaterableTileProviders), sprinklersList .Where(s => s.IsSprinkler()) .Select(s => (position: new IntPoint((int)s.TileLocation.X, (int)s.TileLocation.Y), info: GetSprinklerInfo(s))) ).Contains(new IntPoint((int)tileLocation.X, (int)tileLocation.Y))); } else { throw new InvalidOperationException("Current sprinkler behavior does not allow independent sprinkler activation."); } }
public void ActivateSprinklersInLocation(GameLocation location) { if (location.IsOutdoors && Game1.IsRainingHere(location)) { return; } if (Game1.player.team.SpecialOrderRuleActive("NO_SPRINKLER")) { return; } IMap map = new GameLocationMap(location, CustomWaterableTileProviders); var sprinklerTiles = SprinklerBehavior.GetSprinklerTiles(map); foreach (var sprinklerTile in sprinklerTiles) { map.WaterTile(sprinklerTile); } foreach (var sprinkler in location.Objects.Values.Where(o => o.IsSprinkler())) { sprinkler.ApplySprinklerAnimation(location); } }
private void OnObjectListChanged(object?sender, ObjectListChangedEventArgs e) { SprinklerBehavior.ClearCacheForMap(new GameLocationMap(e.Location, CustomWaterableTileProviders)); if (!e.Added.Where(o => o.Value.IsSprinkler()).Any() && !e.Removed.Where(o => o.Value.IsSprinkler()).Any()) { return; } if (Config.ActivateOnPlacement && SprinklerBehavior is ISprinklerBehavior.Independent) { foreach (var(_, @object) in e.Added) { if (@object.IsSprinkler()) { ActivateSprinkler(@object, e.Location); } } } if (Config.ShowCoverageOnPlacement) { DisplaySprinklerCoverage(); } }
private void OnLargeTerrainFeatureListChanged(object?sender, LargeTerrainFeatureListChangedEventArgs e) { SprinklerBehavior.ClearCacheForMap(new GameLocationMap(e.Location, CustomWaterableTileProviders)); }
private void OnSaveLoaded(object?sender, SaveLoadedEventArgs e) { SprinklerBehavior.ClearCache(); SprinklerCoverageAlpha = 0f; SprinklerCoverageCurrentAnimationTime = 0f; }