Exemplo n.º 1
0
    public bool TryGetPuddle(TileRef tileRef, [NotNullWhen(true)] out PuddleComponent?puddle)
    {
        foreach (var entity in _entityLookup.GetEntitiesIntersecting(tileRef))
        {
            if (EntityManager.TryGetComponent(entity, out PuddleComponent? p))
            {
                puddle = p;
                return(true);
            }
        }

        puddle = null;
        return(false);
    }
        private void PerformHotspotExposure(TileAtmosphere tile)
        {
            if (tile.Air == null || !tile.Hotspot.Valid)
            {
                return;
            }

            tile.Hotspot.Bypassing = tile.Hotspot.SkippedFirstProcess && tile.Hotspot.Volume > tile.Air.Volume * 0.95f;

            if (tile.Hotspot.Bypassing)
            {
                tile.Hotspot.Volume      = tile.Air.ReactionResults[GasReaction.Fire] * Atmospherics.FireGrowthRate;
                tile.Hotspot.Temperature = tile.Air.Temperature;
            }
            else
            {
                var affected = tile.Air.RemoveRatio(tile.Hotspot.Volume / tile.Air.Volume);
                affected.Temperature = tile.Hotspot.Temperature;
                React(affected, tile);
                tile.Hotspot.Temperature = affected.Temperature;
                tile.Hotspot.Volume      = affected.ReactionResults[GasReaction.Fire] * Atmospherics.FireGrowthRate;
                Merge(tile.Air, affected);
            }

            var fireEvent = new TileFireEvent(tile.Hotspot.Temperature, tile.Hotspot.Volume);

            foreach (var entity in _lookup.GetEntitiesIntersecting(tile.GridIndex, tile.GridIndices))
            {
                RaiseLocalEvent(entity, ref fireEvent, false);
            }
        }
        public IEnumerable <(EntityUid, TransformComponent)> GetEntitiesToMove(ConveyorComponent comp, TransformComponent xform)
        {
            if (!_mapManager.TryGetGrid(xform.GridID, out var grid) ||
                !grid.TryGetTileRef(xform.Coordinates, out var tile))
            {
                yield break;
            }

            var tileAABB   = _lookup.GetLocalBounds(tile, grid.TileSize).Enlarged(0.01f);
            var gridMatrix = Transform(grid.GridEntityId).InvWorldMatrix;

            foreach (var entity in _lookup.GetEntitiesIntersecting(tile))
            {
                if (entity == comp.Owner ||
                    Deleted(entity) ||
                    HasComp <IMapGridComponent>(entity))
                {
                    continue;
                }

                if (!TryComp(entity, out PhysicsComponent? physics) ||
                    physics.BodyType == BodyType.Static ||
                    physics.BodyStatus == BodyStatus.InAir ||
                    entity.IsWeightless(physics, entityManager: EntityManager))
                {
                    continue;
                }

                if (_container.IsEntityInContainer(entity))
                {
                    continue;
                }

                // Yes there's still going to be the occasional rounding issue where it stops getting conveyed
                // When you fix the corner issue that will fix this anyway.
                var transform = Transform(entity);
                var gridPos   = gridMatrix.Transform(transform.WorldPosition);
                var gridAABB  = new Box2(gridPos - 0.1f, gridPos + 0.1f);

                if (!tileAABB.Intersects(gridAABB))
                {
                    continue;
                }

                yield return(entity, transform);
            }
        }
    private void SellPallets(CargoShuttleComponent component, StationBankAccountComponent bank)
    {
        double amount     = 0;
        var    toSell     = new HashSet <EntityUid>();
        var    xformQuery = GetEntityQuery <TransformComponent>();

        foreach (var pallet in GetCargoPallets(component))
        {
            // Containers should already get the sell price of their children so can skip those.
            foreach (var ent in _lookup.GetEntitiesIntersecting(pallet.Owner, LookupFlags.Anchored))
            {
                // Don't re-sell anything, sell anything anchored (e.g. light fixtures), or anything blacklisted
                // (e.g. players).
                if (toSell.Contains(ent) ||
                    (xformQuery.TryGetComponent(ent, out var xform) && xform.Anchored))
                {
                    continue;
                }

                var price = _pricing.GetPrice(ent);
                if (price == 0)
                {
                    continue;
                }
                toSell.Add(ent);
                amount += price;
            }
        }

        bank.Balance += (int)amount;
        _sawmill.Debug($"Cargo sold {toSell.Count} entities for {amount}");

        foreach (var ent in toSell)
        {
            Del(ent);
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Called where you want the user to start blocking
    /// Creates a new hard fixture to bodyblock
    /// Also makes the user static to prevent prediction issues
    /// </summary>
    /// <param name="uid"> The entity with the blocking component</param>
    /// <param name="component"> The <see cref="BlockingComponent"/></param>
    /// <param name="user"> The entity who's using the item to block</param>
    /// <returns></returns>
    public bool StartBlocking(EntityUid item, BlockingComponent component, EntityUid user)
    {
        if (component.IsBlocking)
        {
            return(false);
        }

        var xform = Transform(user);

        var shieldName = Name(item);

        var blockerName = Identity.Entity(user, EntityManager);
        var msgUser     = Loc.GetString("action-popup-blocking-user", ("shield", shieldName));
        var msgOther    = Loc.GetString("action-popup-blocking-other", ("blockerName", blockerName), ("shield", shieldName));

        if (component.BlockingToggleAction != null)
        {
            //Don't allow someone to block if they're in a container.
            if (_containerSystem.IsEntityInContainer(user) || !_mapManager.TryFindGridAt(xform.MapPosition, out var grid))
            {
                CantBlockError(user);
                return(false);
            }

            //Don't allow someone to block if someone else is on the same tile or if they're inside of a doorway
            var playerTileRef = xform.Coordinates.GetTileRef();
            if (playerTileRef != null)
            {
                var intersecting = _lookup.GetEntitiesIntersecting(playerTileRef.Value);
                var mobQuery     = GetEntityQuery <MobStateComponent>();
                var doorQuery    = GetEntityQuery <DoorComponent>();
                var xformQuery   = GetEntityQuery <TransformComponent>();

                foreach (var uid in intersecting)
                {
                    if (uid != user && mobQuery.HasComponent(uid) || xformQuery.GetComponent(uid).Anchored&& doorQuery.HasComponent(uid))
                    {
                        TooCloseError(user);
                        return(false);
                    }
                }
            }

            //Don't allow someone to block if they're somehow not anchored.
            _transformSystem.AnchorEntity(xform);
            if (!xform.Anchored)
            {
                CantBlockError(user);
                return(false);
            }
            _actionsSystem.SetToggled(component.BlockingToggleAction, true);
            _popupSystem.PopupEntity(msgUser, user, Filter.Entities(user));
            _popupSystem.PopupEntity(msgOther, user, Filter.Pvs(user).RemoveWhereAttachedEntity(e => e == user));
        }

        if (TryComp <PhysicsComponent>(user, out var physicsComponent))
        {
            var fixture = new Fixture(physicsComponent, component.Shape)
            {
                ID             = BlockingComponent.BlockFixtureID,
                Hard           = true,
                CollisionLayer = (int)CollisionGroup.WallLayer
            };

            _fixtureSystem.TryCreateFixture(physicsComponent, fixture);
        }

        component.IsBlocking = true;

        return(true);
    }
    public override void Update(float frameTime)
    {
        base.Update(frameTime);

        if (!Enabled || !_gameTiming.IsFirstTimePredicted)
        {
            return;
        }

        var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);

        if (state != BoundKeyState.Down)
        {
            StopDragging();
            return;
        }

        var mouseScreenPos = _inputManager.MouseScreenPosition;
        var mousePos       = _eyeManager.ScreenToMap(mouseScreenPos);

        if (_dragging == null)
        {
            var bodyQuery = GetEntityQuery <PhysicsComponent>();
            var lowest    = new List <(int DrawDepth, uint RenderOrder, EntityUid Entity)>();

            foreach (var ent in _lookup.GetEntitiesIntersecting(mousePos, LookupFlags.Approximate | LookupFlags.Anchored))
            {
                if (!bodyQuery.HasComponent(ent) ||
                    !TryComp <ClickableComponent>(ent, out var clickable) ||
                    !clickable.CheckClick(mousePos.Position, out var drawDepth, out var renderOrder))
                {
                    continue;
                }

                lowest.Add((drawDepth, renderOrder, ent));
            }

            lowest.Sort((x, y) => y.DrawDepth == x.DrawDepth ? y.RenderOrder.CompareTo(x.RenderOrder) : y.DrawDepth.CompareTo(x.DrawDepth));

            foreach (var ent in lowest)
            {
                StartDragging(ent.Entity, mousePos);
                break;
            }

            if (_dragging == null)
            {
                return;
            }
        }

        if (!TryComp <TransformComponent>(_dragging !.Value, out var xform) ||
            _lastMousePosition !.Value.MapId != xform.MapID ||
            !TryComp <PhysicsComponent>(_dragging, out var body))
        {
            StopDragging();
            return;
        }

        body.Predict = true;

        if (TryComp <PhysicsComponent>(_tether, out var tetherBody))
        {
            tetherBody.Predict = true;
        }

        if (_lastMousePosition.Value.Position.EqualsApprox(mousePos.Position))
        {
            return;
        }

        _lastMousePosition = mousePos;

        RaiseNetworkEvent(new TetherMoveEvent()
        {
            Coordinates = _lastMousePosition !.Value,
        });