private bool TryPryTile(EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation) { if (component.CancelToken != null) { return(true); } if (!TryComp <ToolComponent?>(component.Owner, out var tool) && component.ToolComponentNeeded) { return(false); } if (!_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid)) { return(false); } var tile = mapGrid.GetTileRef(clickLocation); var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false)) { return(false); } var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; if (!tileDef.CanCrowbar) { return(false); } var token = new CancellationTokenSource(); component.CancelToken = token; bool success = UseTool( component.Owner, user, null, 0f, component.Delay, new [] { component.QualityNeeded }, new TilePryingCompleteEvent { Coordinates = clickLocation, }, new TilePryingCancelledEvent(), toolComponent: tool, doAfterEventTarget: component.Owner, cancelToken: token.Token); if (!success) { component.CancelToken = null; } return(true); }
private void ReleaseToFloor(EntityCoordinates clickLocation, AbsorbentComponent absorbent, Solution?absorbedSolution) { if ((_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid)) && // needs valid grid absorbedSolution is not null) // needs a solution to place on the tile { TileRef tile = mapGrid.GetTileRef(clickLocation); // Drop some of the absorbed liquid onto the ground var releaseAmount = FixedPoint2.Min(absorbent.ResidueAmount, absorbedSolution.CurrentVolume); // The release amount specified on the absorbent component, or the amount currently absorbed (whichever is less). var releasedSolution = _solutionSystem.SplitSolution(absorbent.Owner, absorbedSolution, releaseAmount); // Remove releaseAmount of solution from the absorbent component _spillableSystem.SpillAt(tile, releasedSolution, puddlePrototypeId); // And spill it onto the tile. } }
/// <summary> /// Spills solution at the specified grid coordinates. /// </summary> /// <param name="solution">Initial solution for the prototype.</param> /// <param name="coordinates">The coordinates to spill the solution at.</param> /// <param name="prototype">The prototype to use.</param> /// <param name="overflow">If the puddle overflow will be calculated. Defaults to true.</param> /// <param name="sound">Whether or not to play the spill sound.</param> /// <param name="combine">Whether to attempt to merge with existing puddles</param> /// <returns>The puddle if one was created, null otherwise.</returns> public PuddleComponent?SpillAt(Solution solution, EntityCoordinates coordinates, string prototype, bool overflow = true, bool sound = true, bool combine = true) { if (solution.TotalVolume == 0) { return(null); } if (!_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid)) { return(null); // Let's not spill to space. } return(SpillAt(mapGrid.GetTileRef(coordinates), solution, prototype, overflow, sound, combine: combine)); }
public static IEnumerable <EntityUid> GetEntitiesInRange(EntityCoordinates grid, Type component, float range) { var entityManager = IoCManager.Resolve <IEntityManager>(); foreach (var entity in entityManager.GetAllComponents(component).Select(c => c.Owner)) { var transform = entityManager.GetComponent <TransformComponent>(entity); if (transform.Coordinates.GetGridUid(entityManager) != grid.GetGridUid(entityManager)) { continue; } if ((transform.Coordinates.Position - grid.Position).Length <= range) { yield return(entity); } } }