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); }
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); }
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); }
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); }
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); }
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); }