Ejemplo n.º 1
0
    /// <summary>
    /// Called where you want the user to stop blocking.
    /// </summary>
    /// <param name="item"> 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 StopBlocking(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-disabling-user", ("shield", shieldName));
        var msgOther    = Loc.GetString("action-popup-blocking-disabling-other", ("blockerName", blockerName), ("shield", shieldName));

        //If the component blocking toggle isn't null, grab the users SharedBlockingUserComponent and PhysicsComponent
        //then toggle the action to false, unanchor the user, remove the hard fixture
        //and set the users bodytype back to their original type
        if (component.BlockingToggleAction != null && TryComp <BlockingUserComponent>(user, out var blockingUserComponent) &&
            TryComp <PhysicsComponent>(user, out var physicsComponent))
        {
            if (xform.Anchored)
            {
                _transformSystem.Unanchor(xform);
            }

            _actionsSystem.SetToggled(component.BlockingToggleAction, false);
            _fixtureSystem.DestroyFixture(physicsComponent, BlockingComponent.BlockFixtureID);
            physicsComponent.BodyType = blockingUserComponent.OriginalBodyType;
            _popupSystem.PopupEntity(msgUser, user, Filter.Entities(user));
            _popupSystem.PopupEntity(msgOther, user, Filter.Pvs(user).RemoveWhereAttachedEntity(e => e == user));
        }

        component.IsBlocking = false;

        return(true);
    }