Esempio n. 1
0
        // TODO: Now that we have StartCollide and EndCollide this should just use that to track bodies intersecting.
        private void Update(SlipperyComponent component)
        {
            if (!component.Slippery)
            {
                return;
            }

            if (!ComponentManager.TryGetComponent(component.Owner.Uid, out PhysicsComponent? body))
            {
                component.Colliding.Clear();
                return;
            }

            foreach (var uid in component.Colliding.ToArray())
            {
                if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out var entity))
                {
                    component.Colliding.Remove(uid);
                    component.Slipped.Remove(uid);
                    component.Dirty();
                    continue;
                }

                if (!entity.TryGetComponent(out PhysicsComponent? otherPhysics) ||
                    !body.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB()))
                {
                    component.Colliding.Remove(uid);
                    component.Slipped.Remove(uid);
                    component.Dirty();
                    continue;
                }

                if (!component.Slipped.Contains(uid))
                {
                    TrySlip(component, body, otherPhysics);
                }
            }
        }
Esempio n. 2
0
        private bool TrySlip(SlipperyComponent component, IPhysBody ourBody, IPhysBody otherBody)
        {
            if (!component.Slippery ||
                component.Owner.IsInContainer() ||
                component.Slipped.Contains(otherBody.Owner.Uid) ||
                !otherBody.Owner.TryGetComponent(out SharedStunnableComponent? stun))
            {
                return(false);
            }

            if (otherBody.LinearVelocity.Length < component.RequiredSlipSpeed || stun.KnockedDown)
            {
                return(false);
            }

            var percentage = otherBody.GetWorldAABB().IntersectPercentage(ourBody.GetWorldAABB());

            if (percentage < component.IntersectPercentage)
            {
                return(false);
            }

            if (!EffectBlockerSystem.CanSlip(otherBody.Owner))
            {
                return(false);
            }

            otherBody.LinearVelocity *= component.LaunchForwardsMultiplier;

            stun.Paralyze(5);
            component.Slipped.Add(otherBody.Owner.Uid);
            component.Dirty();

            PlaySound(component);

            return(true);
        }