/// <summary>
        ///     Destroys the Owner <see cref="IEntity"/>, setting
        ///     <see cref="IDamageableComponent.CurrentState"/> to
        ///     <see cref="Shared.GameObjects.Components.Damage.DamageState.Dead"/>
        /// </summary>
        protected void PerformDestruction()
        {
            CurrentState = DamageState.Dead;

            if (!Owner.Deleted)
            {
                var    pos   = Owner.Transform.Coordinates;
                string sound = string.Empty;
                if (DestroySoundCollection != string.Empty)
                {
                    sound = AudioHelpers.GetRandomFileFromSoundCollection(DestroySoundCollection);
                }
                else if (DestroySound != string.Empty)
                {
                    sound = DestroySound;
                }
                if (sound != string.Empty)
                {
                    Logger.Debug("Playing destruction sound");
                    EntitySystem.Get <AudioSystem>().PlayAtCoords(sound, pos, AudioHelpers.WithVariation(0.125f));
                }
            }

            DestructionBehavior();
        }
Exemple #2
0
        private void TurnOn(IEntity user)
        {
            if (_activated)
            {
                return;
            }

            var sprite = Owner.GetComponent <SpriteComponent>();
            var item   = Owner.GetComponent <ItemComponent>();
            var cell   = Cell;

            if (cell == null)
            {
                _entitySystemManager.GetEntitySystem <AudioSystem>().Play("/Audio/machines/button.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));

                _notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Cell missing..."));
                return;
            }

            if (cell.Charge < EnergyPerUse)
            {
                _entitySystemManager.GetEntitySystem <AudioSystem>().Play("/Audio/machines/button.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
                _notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Dead cell..."));
                return;
            }

            _entitySystemManager.GetEntitySystem <AudioSystem>().Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));

            item.EquippedPrefix = "on";
            sprite.LayerSetState(0, "stunbaton_on");
            _activated = true;
        }
Exemple #3
0
        /// <summary>
        ///     Set's the mob standing state to down.
        /// </summary>
        /// <param name="entity">The mob in question</param>
        /// <param name="playSound">Whether to play a sound when falling down or not</param>
        /// <param name="dropItems">Whether to make the mob drop all the items on his hands</param>
        /// <returns>False if the mob was already downed or couldn't set the state</returns>
        public static bool Down(IEntity entity, bool playSound = true, bool dropItems = true)
        {
            if (!entity.TryGetComponent(out AppearanceComponent appearance))
            {
                return(false);
            }

            appearance.TryGetData <SharedSpeciesComponent.MobState>(SharedSpeciesComponent.MobVisuals.RotationState, out var oldState);

            var newState = SharedSpeciesComponent.MobState.Down;

            if (newState == oldState)
            {
                return(false);
            }

            appearance.SetData(SharedSpeciesComponent.MobVisuals.RotationState, newState);

            if (playSound)
            {
                IoCManager.Resolve <IEntitySystemManager>().GetEntitySystem <AudioSystem>()
                .Play(AudioHelpers.GetRandomFileFromSoundCollection("bodyfall"), entity, AudioHelpers.WithVariation(0.25f));
            }

            if (dropItems)
            {
                DropAllItemsInHands(entity);
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        ///     Set's the mob standing state to down.
        /// </summary>
        /// <param name="entity">The mob in question</param>
        /// <param name="playSound">Whether to play a sound when falling down or not</param>
        /// <param name="dropItems">Whether to make the mob drop all the items on his hands</param>
        /// <param name="force">Whether or not to check if the entity can fall.</param>
        /// <returns>False if the mob was already downed or couldn't set the state</returns>
        public static bool Down(IEntity entity, bool playSound = true, bool dropItems = true, bool force = false)
        {
            if (dropItems)
            {
                DropAllItemsInHands(entity, false);
            }

            if (!force && !EffectBlockerSystem.CanFall(entity))
            {
                return(false);
            }

            if (!entity.TryGetComponent(out AppearanceComponent appearance))
            {
                return(false);
            }

            var newState = RotationState.Horizontal;

            appearance.TryGetData <RotationState>(RotationVisuals.RotationState, out var oldState);

            if (newState != oldState)
            {
                appearance.SetData(RotationVisuals.RotationState, newState);
            }

            if (playSound)
            {
                IoCManager.Resolve <IEntitySystemManager>().GetEntitySystem <AudioSystem>()
                .PlayFromEntity(AudioHelpers.GetRandomFileFromSoundCollection("bodyfall"), entity, AudioHelpers.WithVariation(0.25f));
            }

            return(true);
        }
Exemple #5
0
        private void TurnOn(IEntity user)
        {
            if (_activated)
            {
                return;
            }

            var sprite = Owner.GetComponent <SpriteComponent>();
            var item   = Owner.GetComponent <ItemComponent>();

            if (Cell == null)
            {
                EntitySystem.Get <AudioSystem>().PlayAtCoords("/Audio/Machines/button.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));

                Owner.PopupMessage(user, Loc.GetString("Cell missing..."));
                return;
            }

            if (Cell.CurrentCharge < EnergyPerUse)
            {
                EntitySystem.Get <AudioSystem>().PlayAtCoords("/Audio/Machines/button.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
                Owner.PopupMessage(user, Loc.GetString("Dead cell..."));
                return;
            }

            EntitySystem.Get <AudioSystem>().PlayAtCoords(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));

            item.EquippedPrefix = "on";
            sprite.LayerSetState(0, "stunbaton_on");
            _activated = true;
        }
        protected override bool OnHitEntities(IReadOnlyList <IEntity> entities, AttackEvent eventArgs)
        {
            if (!Activated || entities.Count == 0 || Cell == null)
            {
                return(true);
            }

            if (!Cell.TryUseCharge(EnergyPerUse))
            {
                return(true);
            }

            SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Weapons/egloves.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));

            foreach (var entity in entities)
            {
                if (!entity.TryGetComponent(out StunnableComponent? stunnable))
                {
                    continue;
                }

                if (!stunnable.SlowedDown)
                {
                    if (_robustRandom.Prob(_paralyzeChanceNoSlowdown))
                    {
                        stunnable.Paralyze(_paralyzeTime);
                    }
                    else
                    {
                        stunnable.Slowdown(_slowdownTime);
                    }
                }
                else
                {
                    if (_robustRandom.Prob(_paralyzeChanceWithSlowdown))
                    {
                        stunnable.Paralyze(_paralyzeTime);
                    }
                    else
                    {
                        stunnable.Slowdown(_slowdownTime);
                    }
                }
            }

            if (!(Cell.CurrentCharge < EnergyPerUse))
            {
                return(true);
            }

            SoundSystem.Play(Filter.Pvs(Owner), AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
            TurnOff();

            return(true);
        }
Exemple #7
0
        public void Execute(IEntity owner, DestructibleSystem system)
        {
            if (string.IsNullOrEmpty(SoundCollection))
            {
                return;
            }

            var sound = AudioHelpers.GetRandomFileFromSoundCollection(SoundCollection);
            var pos   = owner.Transform.Coordinates;

            system.AudioSystem.PlayAtCoords(sound, pos, AudioHelpers.WithVariation(0.125f));
        }
Exemple #8
0
        public override bool OnHitEntities(IReadOnlyList <IEntity> entities)
        {
            var cell = Cell;

            if (!Activated || entities.Count == 0 || cell == null)
            {
                return(false);
            }
            if (!cell.TryUseCharge(EnergyPerUse))
            {
                return(false);
            }
            EntitySystem.Get <AudioSystem>().PlayAtCoords("/Audio/weapons/egloves.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));

            foreach (var entity in entities)
            {
                if (!entity.TryGetComponent(out StunnableComponent stunnable))
                {
                    continue;
                }

                if (!stunnable.SlowedDown)
                {
                    if (_robustRandom.Prob(_paralyzeChanceNoSlowdown))
                    {
                        stunnable.Paralyze(_paralyzeTime);
                    }
                    else
                    {
                        stunnable.Slowdown(_slowdownTime);
                    }
                }
                else
                if (_robustRandom.Prob(_paralyzeChanceWithSlowdown))
                {
                    stunnable.Paralyze(_paralyzeTime);
                }
                else
                {
                    stunnable.Slowdown(_slowdownTime);
                }
            }
            if (cell.CurrentCharge < EnergyPerUse)
            {
                EntitySystem.Get <AudioSystem>().PlayAtCoords(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
                TurnOff();
            }

            return(false);
        }
        private void TurnOff()
        {
            if (!_activated)
            {
                return;
            }

            var sprite = Owner.GetComponent <SpriteComponent>();
            var item   = Owner.GetComponent <ItemComponent>();

            SoundSystem.Play(Filter.Pvs(Owner), AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));

            item.EquippedPrefix = "off";
            sprite.LayerSetState(0, "stunbaton_off");
            _activated = false;
        }
Exemple #10
0
        private void TurnOff()
        {
            if (!_activated)
            {
                return;
            }

            var sprite = Owner.GetComponent <SpriteComponent>();
            var item   = Owner.GetComponent <ItemComponent>();

            _entitySystemManager.GetEntitySystem <AudioSystem>().Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));

            item.EquippedPrefix = "off";
            sprite.LayerSetState(0, "stunbaton_off");
            _activated = false;
        }
Exemple #11
0
        public void Down(StandingStateComponent component, bool playSound = true, bool dropHeldItems = true)
        {
            if (!component.Standing)
            {
                return;
            }

            var entity = component.Owner;
            var uid    = entity.Uid;

            // This is just to avoid most callers doing this manually saving boilerplate
            // 99% of the time you'll want to drop items but in some scenarios (e.g. buckling) you don't want to.
            // We do this BEFORE downing because something like buckle may be blocking downing but we want to drop hand items anyway
            // and ultimately this is just to avoid boilerplate in Down callers + keep their behavior consistent.
            if (dropHeldItems)
            {
                Get <SharedHandsSystem>().DropHandItems(entity, false);
            }

            var msg = new DownAttemptEvent();

            EntityManager.EventBus.RaiseLocalEvent(uid, msg);

            if (msg.Cancelled)
            {
                return;
            }

            component.Standing = false;
            component.Dirty();
            EntityManager.EventBus.RaiseLocalEvent(uid, new DownedEvent());

            // Seemed like the best place to put it
            if (entity.TryGetComponent(out SharedAppearanceComponent? appearance))
            {
                appearance.SetData(RotationVisuals.RotationState, RotationState.Horizontal);
            }

            // Currently shit is only downed by server but when it's predicted we can probably only play this on server / client
            var sound = component.DownSoundCollection;

            if (playSound && !string.IsNullOrEmpty(sound))
            {
                var file = AudioHelpers.GetRandomFileFromSoundCollection(sound);
                SoundSystem.Play(Filter.Pvs(entity), file, entity, AudioHelpers.WithVariation(0.25f));
            }
        }
Exemple #12
0
        private void PlaySound(IEntity owner)
        {
            var pos         = owner.Transform.Coordinates;
            var actualSound = string.Empty;

            if (SoundCollection != string.Empty)
            {
                actualSound = AudioHelpers.GetRandomFileFromSoundCollection(SoundCollection);
            }
            else if (Sound != string.Empty)
            {
                actualSound = Sound;
            }

            if (actualSound != string.Empty)
            {
                EntitySystem.Get <AudioSystem>().PlayAtCoords(actualSound, pos, AudioHelpers.WithVariation(0.125f));
            }
        }
        private void TurnOff(StunbatonComponent comp)
        {
            if (!comp.Activated)
            {
                return;
            }

            if (!comp.Owner.TryGetComponent <SpriteComponent>(out var sprite) ||
                !comp.Owner.TryGetComponent <ItemComponent>(out var item))
            {
                return;
            }

            SoundSystem.Play(Filter.Pvs(comp.Owner), AudioHelpers.GetRandomFileFromSoundCollection("sparks"), comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
            item.EquippedPrefix = "off";
            // TODO stunbaton visualizer
            sprite.LayerSetState(0, "stunbaton_off");
            comp.Activated = false;
        }
        private void StunEntity(IEntity entity, StunbatonComponent comp)
        {
            if (!entity.TryGetComponent(out StunnableComponent? stunnable) || !comp.Activated)
            {
                return;
            }

            SoundSystem.Play(Filter.Pvs(comp.Owner), "/Audio/Weapons/egloves.ogg", comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
            if (!stunnable.SlowedDown)
            {
                if (_robustRandom.Prob(comp.ParalyzeChanceNoSlowdown))
                {
                    stunnable.Paralyze(comp.ParalyzeTime);
                }
                else
                {
                    stunnable.Slowdown(comp.SlowdownTime);
                }
            }
            else
            {
                if (_robustRandom.Prob(comp.ParalyzeChanceWithSlowdown))
                {
                    stunnable.Paralyze(comp.ParalyzeTime);
                }
                else
                {
                    stunnable.Slowdown(comp.SlowdownTime);
                }
            }


            if (!comp.Owner.TryGetComponent <PowerCellSlotComponent>(out var slot) || slot.Cell == null || !(slot.Cell.CurrentCharge < comp.EnergyPerUse))
            {
                return;
            }

            SoundSystem.Play(Filter.Pvs(comp.Owner), AudioHelpers.GetRandomFileFromSoundCollection("sparks"), comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
            TurnOff(comp);
        }
        private void TurnOn(StunbatonComponent comp, IEntity user)
        {
            if (comp.Activated)
            {
                return;
            }

            if (!comp.Owner.TryGetComponent <SpriteComponent>(out var sprite) ||
                !comp.Owner.TryGetComponent <ItemComponent>(out var item))
            {
                return;
            }

            var playerFilter = Filter.Pvs(comp.Owner);

            if (!comp.Owner.TryGetComponent <PowerCellSlotComponent>(out var slot))
            {
                return;
            }

            if (slot.Cell == null)
            {
                SoundSystem.Play(playerFilter, "/Audio/Machines/button.ogg", comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
                user.PopupMessage(Loc.GetString("comp-stunbaton-activated-missing-cell"));
                return;
            }

            if (slot.Cell != null && slot.Cell.CurrentCharge < comp.EnergyPerUse)
            {
                SoundSystem.Play(playerFilter, "/Audio/Machines/button.ogg", comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
                user.PopupMessage(Loc.GetString("comp-stunbaton-activated-dead-cell"));
                return;
            }

            SoundSystem.Play(playerFilter, AudioHelpers.GetRandomFileFromSoundCollection("sparks"), comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));

            item.EquippedPrefix = "on";
            sprite.LayerSetState(0, "stunbaton_on");
            comp.Activated = true;
        }
Exemple #16
0
        public override void Gib(bool gibParts = false)
        {
            base.Gib(gibParts);

            SoundSystem.Play(Filter.Pvs(Owner), AudioHelpers.GetRandomFileFromSoundCollection("gib"), Owner.Transform.Coordinates,
                             AudioHelpers.WithVariation(0.025f));

            if (Owner.TryGetComponent(out ContainerManagerComponent? container))
            {
                foreach (var cont in container.GetAllContainers())
                {
                    foreach (var ent in cont.ContainedEntities)
                    {
                        cont.ForceRemove(ent);
                        ent.Transform.Coordinates = Owner.Transform.Coordinates;
                        ent.RandomOffset(0.25f);
                    }
                }
            }

            Owner.Delete();
        }
        protected override bool OnDown(IEntity entity, bool playSound = true, bool dropItems = true, bool force = false)
        {
            if (!entity.TryGetComponent(out AppearanceComponent? appearance))
            {
                return(false);
            }

            var newState = RotationState.Horizontal;

            appearance.TryGetData <RotationState>(RotationVisuals.RotationState, out var oldState);

            if (newState != oldState)
            {
                appearance.SetData(RotationVisuals.RotationState, newState);

                if (playSound)
                {
                    var file = AudioHelpers.GetRandomFileFromSoundCollection("bodyfall");
                    Get <AudioSystem>().PlayFromEntity(file, entity, AudioHelpers.WithVariation(0.25f));
                }
            }

            return(true);
        }
 public override string GetSound(IRobustRandom?rand = null, IPrototypeManager?proto = null)
 {
     return(Collection == null ? string.Empty : AudioHelpers.GetRandomFileFromSoundCollection(Collection, rand, proto));
 }
 public override string GetSound()
 {
     return(Collection == null ? string.Empty : AudioHelpers.GetRandomFileFromSoundCollection(Collection));
 }
 public void PlaySound()
 {
     EntitySystem.Get <AudioSystem>()
     .PlayFromEntity(AudioHelpers.GetRandomFileFromSoundCollection("desecration"), Owner,
                     AudioHelpers.WithVariation(0.125f));
 }
 public void PlaySound()
 {
     SoundSystem.Play(Filter.Pvs(Owner), AudioHelpers.GetRandomFileFromSoundCollection("desecration"), Owner,
                      AudioHelpers.WithVariation(0.125f));
 }