Exemplo n.º 1
0
        public void Update(float delta)
        {
            if (Stunned)
            {
                _stunnedTimer -= delta;

                if (_stunnedTimer <= 0)
                {
                    _stunnedTimer = 0f;
                    Dirty();
                }
            }

            if (KnockedDown)
            {
                _knockdownTimer -= delta;

                if (_knockdownTimer <= 0f)
                {
                    StandingStateHelper.Standing(Owner);

                    _knockdownTimer = 0f;
                    Dirty();
                }
            }

            if (SlowedDown)
            {
                _slowdownTimer -= delta;

                if (_slowdownTimer <= 0f)
                {
                    _slowdownTimer = 0f;

                    if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
                    {
                        movement.RefreshMovementSpeedModifiers();
                    }
                    Dirty();
                }
            }

            if (!StunStart.HasValue || !StunEnd.HasValue ||
                !Owner.TryGetComponent(out ServerStatusEffectsComponent status))
            {
                return;
            }

            var start = StunStart.Value;
            var end   = StunEnd.Value;

            var length   = (end - start).TotalSeconds;
            var progress = (_gameTiming.CurTime - start).TotalSeconds;

            if (progress >= length)
            {
                Timer.Spawn(250, () => status.RemoveStatusEffect(StatusEffect.Stun), _statusRemoveCancellation.Token);
                _lastStun = null;
            }
        }
        public void ExitState(IEntity entity)
        {
            StandingStateHelper.Standing(entity);

            if (entity.TryGetComponent(out ICollidableComponent collidable))
            {
                collidable.CanCollide = true;
            }
        }
Exemplo n.º 3
0
        public void ExitState(IEntity entity)
        {
            StandingStateHelper.Standing(entity);

            if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlay))
            {
                overlay.ClearOverlays();
            }
        }
Exemplo n.º 4
0
        public void ResetStuns()
        {
            _stunnedTimer  = 0f;
            _slowdownTimer = 0f;

            if (KnockedDown)
            {
                StandingStateHelper.Standing(Owner);
            }

            _knockdownTimer = 0f;
        }
Exemplo n.º 5
0
        public void ExitState(IEntity entity)
        {
            StandingStateHelper.Standing(entity);

            if (entity.TryGetComponent(out CollidableComponent collidable))
            {
                collidable.CanCollide = true;
            }

            if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlay))
            {
                overlay.ClearOverlays();
            }
        }
        private void CalculateSpeed()
        {
            if (!Owner.TryGetComponent(out MovementSpeedModifierComponent? playerMover))
            {
                return;
            }

            float speedSum = 0;

            foreach (var part in _activeLegs.Keys)
            {
                if (!part.HasProperty <LegProperty>())
                {
                    _activeLegs.Remove(part);
                }
            }

            foreach (var(key, value) in _activeLegs)
            {
                if (key.TryGetProperty(out LegProperty legProperty))
                {
                    // Speed of a leg = base speed * (1+log1024(leg length))
                    speedSum += legProperty.Speed * (1 + (float)Math.Log(value, 1024.0));
                }
            }

            if (speedSum <= 0.001f || _activeLegs.Count <= 0)
            {
                // Case: no way of moving. Fall down.
                StandingStateHelper.Down(Owner);
                playerMover.BaseWalkSpeed   = 0.8f;
                playerMover.BaseSprintSpeed = 2.0f;
            }
            else
            {
                // Case: have at least one leg. Set move speed.
                StandingStateHelper.Standing(Owner);

                // Extra legs stack diminishingly.
                // Final speed = speed sum/(leg count-log4(leg count))
                playerMover.BaseWalkSpeed =
                    speedSum / (_activeLegs.Count - (float)Math.Log(_activeLegs.Count, 4.0));

                playerMover.BaseSprintSpeed = playerMover.BaseWalkSpeed * 1.75f;
            }
        }
 public void ExitState(IEntity entity)
 {
     StandingStateHelper.Standing(entity);
 }
        public void Update(float delta)
        {
            if (Stunned)
            {
                _stunnedTimer -= delta;

                if (_stunnedTimer <= 0)
                {
                    _stunnedTimer = 0f;
                }
            }

            if (KnockedDown)
            {
                _knockdownTimer -= delta;

                if (_knockdownTimer <= 0f)
                {
                    StandingStateHelper.Standing(Owner);

                    _knockdownTimer = 0f;
                }
            }

            if (SlowedDown)
            {
                _slowdownTimer -= delta;

                if (_slowdownTimer <= 0f)
                {
                    _slowdownTimer = 0f;

                    if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
                    {
                        movement.RefreshMovementSpeedModifiers();
                    }
                }
            }

            if (!_lastStun.HasValue || !StunEnd.HasValue || !Owner.TryGetComponent(out ServerStatusEffectsComponent status))
            {
                return;
            }

            var start = _lastStun.Value;
            var end   = StunEnd.Value;

            var length   = (end - start).TotalSeconds;
            var progress = (_gameTiming.CurTime - start).TotalSeconds;
            var ratio    = (float)(progress / length);

            var textureIndex = CalculateStunLevel(ratio);

            if (textureIndex == StunLevels)
            {
                _lastStun = null;
                status.RemoveStatus(StatusEffect.Stun);
            }
            else
            {
                status.ChangeStatus(StatusEffect.Stun, _texturesStunOverlay[textureIndex]);
            }
        }
Exemplo n.º 9
0
        private bool TryBuckle(IEntity user, IEntity to)
        {
            if (user == null || user == to)
            {
                return(false);
            }

            if (!ActionBlockerSystem.CanInteract(user))
            {
                _notifyManager.PopupMessage(user, user,
                                            Loc.GetString("You can't do that!"));
                return(false);
            }

            var strapPosition = Owner.Transform.MapPosition;
            var range         = SharedInteractionSystem.InteractionRange / 2;

            if (!InteractionChecks.InRangeUnobstructed(user, strapPosition, range))
            {
                _notifyManager.PopupMessage(user, user,
                                            Loc.GetString("You can't reach there!"));
                return(false);
            }

            if (!user.TryGetComponent(out HandsComponent hands))
            {
                _notifyManager.PopupMessage(user, user,
                                            Loc.GetString("You don't have hands!"));
                return(false);
            }

            if (hands.GetActiveHand != null)
            {
                _notifyManager.PopupMessage(user, user,
                                            Loc.GetString("Your hand isn't free!"));
                return(false);
            }

            if (BuckledTo != null)
            {
                _notifyManager.PopupMessage(Owner, user,
                                            Loc.GetString(Owner == user
                        ? "You are already buckled in!"
                        : "{0:They} are already buckled in!", Owner));
                return(false);
            }

            if (!to.TryGetComponent(out StrapComponent strap))
            {
                _notifyManager.PopupMessage(Owner, user,
                                            Loc.GetString(Owner == user
                        ? "You can't buckle yourself there!"
                        : "You can't buckle {0:them} there!", Owner));
                return(false);
            }

            var parent = to.Transform.Parent;

            while (parent != null)
            {
                if (parent == user.Transform)
                {
                    _notifyManager.PopupMessage(Owner, user,
                                                Loc.GetString(Owner == user
                            ? "You can't buckle yourself there!"
                            : "You can't buckle {0:them} there!", Owner));
                    return(false);
                }

                parent = parent.Parent;
            }

            if (!strap.HasSpace(this))
            {
                _notifyManager.PopupMessage(Owner, user,
                                            Loc.GetString(Owner == user
                        ? "You can't fit there!"
                        : "{0:They} can't fit there!", Owner));
                return(false);
            }

            _entitySystem.GetEntitySystem <AudioSystem>()
            .PlayFromEntity(strap.BuckleSound, Owner);

            if (!strap.TryAdd(this))
            {
                _notifyManager.PopupMessage(Owner, user,
                                            Loc.GetString(Owner == user
                        ? "You can't buckle yourself there!"
                        : "You can't buckle {0:them} there!", Owner));
                return(false);
            }

            BuckledTo = strap;

            if (Owner.TryGetComponent(out AppearanceComponent appearance))
            {
                appearance.SetData(BuckleVisuals.Buckled, true);
            }

            var ownTransform   = Owner.Transform;
            var strapTransform = strap.Owner.Transform;

            ownTransform.GridPosition = strapTransform.GridPosition;
            ownTransform.AttachParent(strapTransform);

            switch (strap.Position)
            {
            case StrapPosition.None:
                ownTransform.WorldRotation = strapTransform.WorldRotation;
                break;

            case StrapPosition.Stand:
                StandingStateHelper.Standing(Owner);
                ownTransform.WorldRotation = strapTransform.WorldRotation;
                break;

            case StrapPosition.Down:
                StandingStateHelper.Down(Owner);
                ownTransform.WorldRotation = Angle.South;
                break;
            }

            BuckleStatus();

            return(true);
        }