Exemple #1
0
    private bool UpdateColliding(StepTriggerComponent component, TransformComponent ownerTransform, EntityUid otherUid, EntityQuery <PhysicsComponent> query)
    {
        if (!query.TryGetComponent(otherUid, out var otherPhysics))
        {
            return(true);
        }

        // TODO: This shouldn't be calculating based on world AABBs.
        var ourAabb   = _entityLookup.GetWorldAABB(component.Owner, ownerTransform);
        var otherAabb = _entityLookup.GetWorldAABB(otherUid);

        if (!ourAabb.Intersects(otherAabb))
        {
            return(true);
        }

        if (otherPhysics.LinearVelocity.Length < component.RequiredTriggerSpeed ||
            component.CurrentlySteppedOn.Contains(otherUid) ||
            otherAabb.IntersectPercentage(ourAabb) < component.IntersectRatio ||
            !CanTrigger(component.Owner, otherUid, component))
        {
            return(false);
        }

        var ev = new StepTriggeredEvent {
            Source = component.Owner, Tripper = otherUid
        };

        RaiseLocalEvent(component.Owner, ref ev, true);

        component.CurrentlySteppedOn.Add(otherUid);
        Dirty(component);
        return(false);
    }
Exemple #2
0
    private bool Update(StepTriggerComponent component, TransformComponent transform, EntityQuery <PhysicsComponent> query)
    {
        if (!component.Active ||
            component.Colliding.Count == 0)
        {
            return(true);
        }

        var remQueue = new ValueList <EntityUid>();

        foreach (var otherUid in component.Colliding)
        {
            var shouldRemoveFromColliding = UpdateColliding(component, transform, otherUid, query);
            if (!shouldRemoveFromColliding)
            {
                continue;
            }

            remQueue.Add(otherUid);
        }

        if (remQueue.Count > 0)
        {
            foreach (var uid in remQueue)
            {
                component.Colliding.Remove(uid);
                component.CurrentlySteppedOn.Remove(uid);
            }

            Dirty(component);
        }

        return(false);
    }
Exemple #3
0
 private static void TriggerGetState(EntityUid uid, StepTriggerComponent component, ref ComponentGetState args)
 {
     args.State = new StepTriggerComponentState(
         component.IntersectRatio,
         component.CurrentlySteppedOn,
         component.Colliding,
         component.RequiredTriggerSpeed,
         component.Active);
 }
Exemple #4
0
    private void HandleCollide(EntityUid uid, StepTriggerComponent component, StartCollideEvent args)
    {
        var otherUid = args.OtherFixture.Body.Owner;

        if (!CanTrigger(uid, otherUid, component))
        {
            return;
        }

        EnsureComp <StepTriggerActiveComponent>(uid);

        component.Colliding.Add(otherUid);
    }
Exemple #5
0
    private bool CanTrigger(EntityUid uid, EntityUid otherUid, StepTriggerComponent component)
    {
        if (!component.Active || component.CurrentlySteppedOn.Contains(otherUid))
        {
            return(false);
        }

        var msg = new StepTriggerAttemptEvent {
            Source = uid, Tripper = otherUid
        };

        RaiseLocalEvent(uid, ref msg, true);

        return(msg.Continue);
    }
Exemple #6
0
    private static void TriggerHandleState(EntityUid uid, StepTriggerComponent component, ref ComponentHandleState args)
    {
        if (args.Current is not StepTriggerComponentState state)
        {
            return;
        }

        component.RequiredTriggerSpeed = state.RequiredTriggerSpeed;
        component.IntersectRatio       = state.IntersectRatio;
        component.Active = state.Active;

        component.CurrentlySteppedOn.Clear();
        component.Colliding.Clear();

        component.CurrentlySteppedOn.UnionWith(state.CurrentlySteppedOn);
        component.Colliding.UnionWith(state.Colliding);
    }