Ejemplo n.º 1
0
        public void EnterState(IEntity entity)
        {
            if (entity.TryGetComponent(out AppearanceComponent appearance))
            {
                appearance.SetData(DamageStateVisuals.State, DamageState.Critical);
            }

            if (entity.TryGetComponent(out ServerStatusEffectsComponent status))
            {
                status.ChangeStatusEffectIcon(StatusEffect.Health,
                                              "/Textures/Interface/StatusEffects/Human/humancrit-0.png"); //Todo: combine humancrit-0 and humancrit-1 into a gif and display it
            }

            if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlay))
            {
                overlay.AddOverlay(SharedOverlayID.GradientCircleMaskOverlay);
            }

            if (entity.TryGetComponent(out StunnableComponent stun))
            {
                stun.CancelAll();
            }

            StandingStateHelper.Down(entity);
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        public void EnterState(IEntity entity)
        {
            if (entity.TryGetComponent(out AppearanceComponent appearance))
            {
                appearance.SetData(DamageStateVisuals.State, DamageState.Dead);
            }

            if (entity.TryGetComponent(out ServerStatusEffectsComponent status))
            {
                status.ChangeStatusEffectIcon(StatusEffect.Health,
                                              "/Textures/Interface/StatusEffects/Human/humandead.png");
            }

            if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlayComponent))
            {
                overlayComponent.AddOverlay(SharedOverlayID.CircleMaskOverlay);
            }

            if (entity.TryGetComponent(out StunnableComponent stun))
            {
                stun.CancelAll();
            }

            StandingStateHelper.Down(entity);

            if (entity.TryGetComponent(out CollidableComponent collidable))
            {
                collidable.CanCollide = false;
            }
        }
Ejemplo n.º 4
0
        public void ExitState(IEntity entity)
        {
            StandingStateHelper.Standing(entity);

            if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlay))
            {
                overlay.ClearOverlays();
            }
        }
Ejemplo n.º 5
0
        public void EnterState(IEntity entity)
        {
            if (entity.TryGetComponent(out StunnableComponent stun))
            {
                stun.CancelAll();
            }

            StandingStateHelper.Down(entity);
        }
Ejemplo n.º 6
0
        public void ExitState(IEntity entity)
        {
            StandingStateHelper.Standing(entity);

            if (entity.TryGetComponent(out ICollidableComponent collidable))
            {
                collidable.CanCollide = true;
            }
        }
Ejemplo n.º 7
0
        public void EnterState(IEntity entity)
        {
            if (entity.TryGetComponent(out StunnableComponent stun))
            {
                stun.CancelAll();
            }

            entity.TryGetComponent(out AppearanceComponent appearanceComponent);
            appearanceComponent?.SetData(DamageStateVisuals.State, DamageStateVisualData.Crit);
            StandingStateHelper.Down(entity);
        }
Ejemplo n.º 8
0
        public void ResetStuns()
        {
            _stunnedTimer  = 0f;
            _slowdownTimer = 0f;

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

            _knockdownTimer = 0f;
        }
Ejemplo n.º 9
0
        public void EnterState(IEntity entity)
        {
            if (entity.TryGetComponent(out StunnableComponent stun))
            {
                stun.CancelAll();
            }

            StandingStateHelper.Down(entity);

            if (entity.TryGetComponent(out ICollidableComponent collidable))
            {
                collidable.CanCollide = false;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Stuns the entity, disallowing it from doing many interactions temporarily.
        /// </summary>
        /// <param name="seconds">How many seconds the mob will stay stunned</param>
        public void Stun(float seconds)
        {
            seconds = MathF.Min(_stunnedTimer + (seconds * StunTimeModifier), _stunCap);

            if (seconds <= 0f)
            {
                return;
            }

            StandingStateHelper.DropAllItemsInHands(Owner, false);

            _stunnedTimer = seconds;
            _lastStun     = _gameTiming.CurTime;
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     Knocks down the mob, making it fall to the ground.
        /// </summary>
        /// <param name="seconds">How many seconds the mob will stay on the ground</param>
        public void Knockdown(float seconds)
        {
            seconds = MathF.Min(_knockdownTimer + (seconds * KnockdownTimeModifier), _knockdownCap);

            if (seconds <= 0f)
            {
                return;
            }

            StandingStateHelper.Down(Owner);

            _knockdownTimer = seconds;
            _lastStun       = _gameTiming.CurTime;
        }
Ejemplo n.º 12
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();
            }
        }
Ejemplo n.º 13
0
        public void EnterState(IEntity entity)
        {
            if (entity.TryGetComponent(out StunnableComponent stun))
            {
                stun.CancelAll();
            }

            StandingStateHelper.Down(entity);
            entity.TryGetComponent(out AppearanceComponent appearanceComponent);
            appearanceComponent?.SetData(DamageStateVisuals.State, DamageStateVisualData.Dead);

            if (entity.TryGetComponent(out ICollidableComponent collidable))
            {
                collidable.CanCollide = false;
            }
        }
Ejemplo n.º 14
0
        public bool TryUnbuckle(IEntity user, bool force = false)
        {
            if (BuckledTo == null)
            {
                return(false);
            }

            if (!force)
            {
                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 (BuckledTo.Owner.TryGetComponent(out StrapComponent strap))
            {
                strap.Remove(this);
                _entitySystem.GetEntitySystem <AudioSystem>()
                .PlayFromEntity(strap.UnbuckleSound, Owner);
            }

            Owner.Transform.DetachParent();
            Owner.Transform.WorldRotation = BuckledTo.Owner.Transform.WorldRotation;
            BuckledTo = null;

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

            if (Owner.TryGetComponent(out StunnableComponent stunnable) && stunnable.KnockedDown)
            {
                StandingStateHelper.Down(Owner);
            }
        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;
            }
        }
Ejemplo n.º 16
0
        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]);
            }
        }
Ejemplo n.º 17
0
 public void ExitState(IEntity entity)
 {
     StandingStateHelper.Standing(entity);
 }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
#pragma warning restore 649

        protected override void OnKnockdown()
        {
            StandingStateHelper.Down(Owner);
        }