/// <summary> /// Remove the cell from this component. If a user is specified, the cell will be put in their hands /// or failing that, at their feet. If no user is specified the cell will be put at the location of /// the parent of this component. /// </summary> /// <param name="user">(optional) the user to give the removed cell to.</param> /// <param name="playSound">Should <see cref="CellRemoveSound"/> be played upon removal?</param> /// <returns>The cell component of the entity that was removed, or null if removal failed.</returns> public PowerCellComponent?EjectCell(IEntity?user, bool playSound = true) { var cell = Cell; if (cell == null || !CanRemoveCell) { return(null); } if (!_cellContainer.Remove(cell.Owner)) { return(null); } //Dirty(); if (user != null) { if (!user.TryGetComponent(out HandsComponent? hands) || !hands.PutInHand(cell.Owner.GetComponent <ItemComponent>())) { cell.Owner.Transform.Coordinates = user.Transform.Coordinates; } } else { cell.Owner.Transform.Coordinates = Owner.Transform.Coordinates; } if (playSound) { SoundSystem.Play(Filter.Pvs(Owner), CellRemoveSound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f)); } Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new PowerCellChangedEvent(true), false); return(cell); }
/// <summary> /// Remove the cell from this component. If a user is specified, the cell will be put in their hands /// or failing that, at their feet. If no user is specified the cell will be put at the location of /// the parent of this component. /// </summary> /// <param name="user">(optional) the user to give the removed cell to.</param> /// <param name="playSound">Should <see cref="CellRemoveSound"/> be played upon removal?</param> /// <returns>The cell component of the entity that was removed, or null if removal failed.</returns> public PowerCellComponent?EjectCell(EntityUid?user = null, bool playSound = true) { var cell = Cell; if (cell == null || !CanRemoveCell) { return(null); } if (!_cellContainer.Remove(cell.Owner)) { return(null); } //Dirty(); if (user != null) { if (!_entities.TryGetComponent(user, out HandsComponent? hands) || !hands.PutInHand(_entities.GetComponent <SharedItemComponent>(cell.Owner))) { _entities.GetComponent <TransformComponent>(cell.Owner).Coordinates = _entities.GetComponent <TransformComponent>(user.Value).Coordinates; } } else { _entities.GetComponent <TransformComponent>(cell.Owner).Coordinates = _entities.GetComponent <TransformComponent>(Owner).Coordinates; } if (playSound) { SoundSystem.Play(Filter.Pvs(Owner), CellRemoveSound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f)); } _entities.EventBus.RaiseLocalEvent(Owner, new PowerCellChangedEvent(true), false); return(cell); }