private void Fire(EmitterComponent component)
        {
            var projectile = EntityManager.SpawnEntity(component.BoltType, EntityManager.GetComponent <TransformComponent>(component.Owner).Coordinates);

            if (!EntityManager.TryGetComponent <PhysicsComponent?>(projectile, out var physicsComponent))
            {
                Logger.Error("Emitter tried firing a bolt, but it was spawned without a PhysicsComponent");
                return;
            }

            physicsComponent.BodyStatus = BodyStatus.InAir;

            if (!EntityManager.TryGetComponent <ProjectileComponent?>(projectile, out var projectileComponent))
            {
                Logger.Error("Emitter tried firing a bolt, but it was spawned without a ProjectileComponent");
                return;
            }

            projectileComponent.IgnoreEntity(component.Owner);

            physicsComponent
            .LinearVelocity = EntityManager.GetComponent <TransformComponent>(component.Owner).WorldRotation.ToWorldVec() * 20f;
            EntityManager.GetComponent <TransformComponent>(projectile).WorldRotation = EntityManager.GetComponent <TransformComponent>(component.Owner).WorldRotation;

            // TODO: Move to projectile's code.
            Timer.Spawn(3000, () => EntityManager.DeleteEntity(projectile));

            SoundSystem.Play(Filter.Pvs(component.Owner), component.FireSound.GetSound(), component.Owner,
                             AudioHelpers.WithVariation(EmitterComponent.Variation).WithVolume(EmitterComponent.Volume).WithMaxDistance(EmitterComponent.Distance));
        }
Esempio n. 2
0
 private static void ClickLatchSound(ItemCabinetComponent comp)
 {
     if (comp.DoorSound == null)
     {
         return;
     }
     SoundSystem.Play(Filter.Pvs(comp.Owner), comp.DoorSound, comp.Owner, AudioHelpers.WithVariation(0.15f));
 }
Esempio n. 3
0
 protected override void OnSlip()
 {
     if (!string.IsNullOrEmpty(SlipSound))
     {
         EntitySystem.Get <AudioSystem>()
         .PlayFromEntity(SlipSound, Owner, AudioHelpers.WithVariation(0.2f));
     }
 }
        private void Rustle(EntityUid uid, PottedPlantHideComponent?component = null)
        {
            if (!Resolve(uid, ref component))
            {
                return;
            }

            SoundSystem.Play(Filter.Pvs(uid), component.RustleSound.GetSound(), uid, AudioHelpers.WithVariation(0.25f));
        }
Esempio n. 5
0
        public void DoTargetEntityAction(TargetEntityActionEventArgs args)
        {
            var disarmedActs = args.Target.GetAllComponents <IDisarmedAct>().ToArray();

            if (disarmedActs.Length == 0 || !args.Performer.InRangeUnobstructed(args.Target))
            {
                return;
            }
            if (!args.Performer.TryGetComponent <SharedActionsComponent>(out var actions))
            {
                return;
            }
            if (args.Target == args.Performer || !args.Performer.CanAttack())
            {
                return;
            }

            var random = IoCManager.Resolve <IRobustRandom>();
            var audio  = EntitySystem.Get <AudioSystem>();
            var system = EntitySystem.Get <MeleeWeaponSystem>();

            var angle = new Angle(args.Target.Transform.MapPosition.Position - args.Performer.Transform.MapPosition.Position);

            actions.Cooldown(ActionType.Disarm, Cooldowns.SecondsFromNow(_cooldown));

            if (random.Prob(_failProb))
            {
                audio.PlayFromEntity("/Audio/Weapons/punchmiss.ogg", args.Performer,
                                     AudioHelpers.WithVariation(0.025f));
                args.Performer.PopupMessageOtherClients(Loc.GetString("{0} fails to disarm {1}!", args.Performer.Name, args.Target.Name));
                args.Performer.PopupMessageCursor(Loc.GetString("You fail to disarm {0}!", args.Target.Name));
                system.SendLunge(angle, args.Performer);
                return;
            }

            system.SendAnimation("disarm", angle, args.Performer, args.Performer, new [] { args.Target });

            var eventArgs = new DisarmedActEventArgs()
            {
                Target = args.Target, Source = args.Performer, PushProbability = _pushProb
            };

            // Sort by priority.
            Array.Sort(disarmedActs, (a, b) => a.Priority.CompareTo(b.Priority));

            foreach (var disarmedAct in disarmedActs)
            {
                if (disarmedAct.Disarmed(eventArgs))
                {
                    return;
                }
            }

            audio.PlayFromEntity("/Audio/Effects/thudswoosh.ogg", args.Performer,
                                 AudioHelpers.WithVariation(0.025f));
        }
        void IBodyPartAdded.BodyPartAdded(BodyPartAddedEventArgs args)
        {
            if (args.Part.PartType != BodyPartType.Hand)
            {
                return;
            }

            // If this annoys you, which it should.
            // Ping Smugleaf.
            var location = args.Part.Symmetry switch
            {
                BodyPartSymmetry.None => HandLocation.Middle,
                BodyPartSymmetry.Left => HandLocation.Left,
                BodyPartSymmetry.Right => HandLocation.Right,
                _ => throw new ArgumentOutOfRangeException()
            };

            AddHand(args.Slot, location);
        }

        void IBodyPartRemoved.BodyPartRemoved(BodyPartRemovedEventArgs args)
        {
            if (args.Part.PartType != BodyPartType.Hand)
            {
                return;
            }

            RemoveHand(args.Slot);
        }

        bool IDisarmedAct.Disarmed(DisarmedActEvent @event)
        {
            if (BreakPulls())
            {
                return(false);
            }

            var source = @event.Source;
            var target = @event.Target;

            SoundSystem.Play(Filter.Pvs(source), _disarmedSound.GetSound(), source, AudioHelpers.WithVariation(0.025f));

            if (ActiveHand != null && Drop(ActiveHand, false))
            {
                source.PopupMessageOtherClients(Loc.GetString("hands-component-disarm-success-others-message", ("disarmer", Name: _entities.GetComponent <MetaDataComponent>(source).EntityName), ("disarmed", Name: _entities.GetComponent <MetaDataComponent>(target).EntityName)));
                source.PopupMessageCursor(Loc.GetString("hands-component-disarm-success-message", ("disarmed", Name: _entities.GetComponent <MetaDataComponent>(target).EntityName)));
            }
            else
            {
                source.PopupMessageOtherClients(Loc.GetString("hands-component-shove-success-others-message", ("shover", Name: _entities.GetComponent <MetaDataComponent>(source).EntityName), ("shoved", Name: _entities.GetComponent <MetaDataComponent>(target).EntityName)));
                source.PopupMessageCursor(Loc.GetString("hands-component-shove-success-message", ("shoved", Name: _entities.GetComponent <MetaDataComponent>(target).EntityName)));
            }

            return(true);
        }
Esempio n. 7
0
        public async Task PerformAction(IEntity entity, IEntity?user)
        {
            var sound = GetSound();

            if (string.IsNullOrEmpty(sound))
            {
                return;
            }

            EntitySystem.Get <AudioSystem>().PlayFromEntity(sound, entity, AudioHelpers.WithVariation(0.125f));
        }
Esempio n. 8
0
        public void Trigger(IEntity owner, DestructibleSystem system)
        {
            if (string.IsNullOrEmpty(Sound))
            {
                return;
            }

            var pos = owner.Transform.Coordinates;

            system.AudioSystem.PlayAtCoords(Sound, pos, AudioHelpers.WithVariation(0.125f));
        }
        private void PlaySound(EntityUid uid, SoundSpecifier sound, float varyPitch = 0f,
                               NukeComponent?component = null)
        {
            if (!Resolve(uid, ref component))
            {
                return;
            }

            SoundSystem.Play(Filter.Pvs(uid), sound.GetSound(),
                             uid, AudioHelpers.WithVariation(varyPitch).WithVolume(-5f));
        }
        public void Execute(IEntity owner, DestructibleSystem system)
        {
            if (string.IsNullOrEmpty(Sound))
            {
                return;
            }

            var pos = owner.Transform.Coordinates;

            SoundSystem.Play(Filter.Pvs(pos), Sound, pos, AudioHelpers.WithVariation(0.125f));
        }
Esempio n. 11
0
 public void PlaySoundEffect()
 {
     if (!string.IsNullOrWhiteSpace(_soundName))
     {
         if (_pitchVariation > 0.0)
         {
             SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioHelpers.WithVariation(_pitchVariation).WithVolume(-2f));
         }
         SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioParams.Default.WithVolume(-2f));
     }
 }
Esempio n. 12
0
        public async Task PerformAction(IEntity entity, IEntity?user)
        {
            var sound = GetSound();

            if (string.IsNullOrEmpty(sound))
            {
                return;
            }

            SoundSystem.Play(Filter.Pvs(entity), sound, entity, AudioHelpers.WithVariation(0.125f));
        }
        /// <summary>
        ///     Toggles the ItemCabinet's state.
        /// </summary>
        private void ToggleItemCabinet(EntityUid uid, ItemCabinetComponent?cabinet = null)
        {
            if (!Resolve(uid, ref cabinet))
            {
                return;
            }

            cabinet.Opened = !cabinet.Opened;
            SoundSystem.Play(Filter.Pvs(uid), cabinet.DoorSound.GetSound(), uid, AudioHelpers.WithVariation(0.15f));

            UpdateAppearance(uid, cabinet);
        }
Esempio n. 14
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));
        }
Esempio n. 15
0
 /// <summary>
 /// This fires when the rider presses the honk action
 /// </summary>
 private void OnHonk(EntityUid uid, VehicleComponent vehicle, HonkActionEvent args)
 {
     if (args.Handled)
     {
         return;
     }
     if (vehicle.HornSound != null)
     {
         SoundSystem.Play(vehicle.HornSound.GetSound(), Filter.Pvs(uid), uid, AudioHelpers.WithVariation(0.1f).WithVolume(8f));
         args.Handled = true;
     }
 }
        public void ToggleToiletSeat(EntityUid uid, ToiletComponent?component = null)
        {
            if (!Resolve(uid, ref component))
            {
                return;
            }

            component.IsSeatUp = !component.IsSeatUp;
            SoundSystem.Play(component.ToggleSound.GetSound(), Filter.Pvs(uid),
                             uid, AudioHelpers.WithVariation(0.05f));

            UpdateSprite(uid, component);
        }
    public void ToggleSafety(EntityUid uid, EntityUid user,
                             FireExtinguisherComponent?extinguisher = null)
    {
        if (!Resolve(uid, ref extinguisher))
        {
            return;
        }

        extinguisher.Safety = !extinguisher.Safety;
        SoundSystem.Play(Filter.Pvs(uid), extinguisher.SafetySound.GetSound(), uid,
                         AudioHelpers.WithVariation(0.125f).WithVolume(-4f));
        UpdateAppearance(uid, extinguisher);
    }
Esempio n. 18
0
        public void Roll(EntityUid uid, DiceComponent?die = null)
        {
            if (!Resolve(uid, ref die))
            {
                return;
            }

            var roll = _random.Next(1, die.Sides / die.Step + 1) * die.Step;

            SetCurrentSide(uid, roll, die);

            die.Owner.PopupMessageEveryone(Loc.GetString("dice-component-on-roll-land", ("die", die.Owner), ("currentSide", die.CurrentSide)));
            SoundSystem.Play(Filter.Pvs(die.Owner), die.Sound.GetSound(), die.Owner, AudioHelpers.WithVariation(0.05f));
        }
Esempio n. 19
0
        public void DoInstantAction(InstantActionEventArgs args)
        {
            if (!EntitySystem.Get <ActionBlockerSystem>().CanSpeak(args.Performer))
            {
                return;
            }
            if (!args.Performer.TryGetComponent <HumanoidAppearanceComponent>(out var humanoid))
            {
                return;
            }
            if (!args.Performer.TryGetComponent <SharedActionsComponent>(out var actions))
            {
                return;
            }

            if (_random.Prob(.01f) && !string.IsNullOrWhiteSpace(_wilhelm))
            {
                SoundSystem.Play(Filter.Pvs(args.Performer), _wilhelm, args.Performer, AudioParams.Default.WithVolume(Volume));
            }
            else
            {
                switch (humanoid.Sex)
                {
                case Sex.Male:
                    if (_male == null)
                    {
                        break;
                    }
                    SoundSystem.Play(Filter.Pvs(args.Performer), _random.Pick(_male), args.Performer,
                                     AudioHelpers.WithVariation(Variation).WithVolume(Volume));
                    break;

                case Sex.Female:
                    if (_female == null)
                    {
                        break;
                    }
                    SoundSystem.Play(Filter.Pvs(args.Performer), _random.Pick(_female), args.Performer,
                                     AudioHelpers.WithVariation(Variation).WithVolume(Volume));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }



            actions.Cooldown(args.ActionType, Cooldowns.SecondsFromNow(_cooldown));
        }
Esempio n. 20
0
    private void OnCrayonAfterInteract(EntityUid uid, CrayonComponent component, AfterInteractEvent args)
    {
        if (args.Handled || !args.CanReach)
        {
            return;
        }

        if (component.Charges <= 0)
        {
            if (component.DeleteEmpty)
            {
                UseUpCrayon(uid, args.User);
            }
            else
            {
                _popup.PopupEntity(Loc.GetString("crayon-interact-not-enough-left-text"), uid, Filter.Entities(args.User));
            }

            args.Handled = true;
            return;
        }

        if (!args.ClickLocation.IsValid(EntityManager))
        {
            _popup.PopupEntity(Loc.GetString("crayon-interact-invalid-location"), uid, Filter.Entities(args.User));
            args.Handled = true;
            return;
        }

        if (!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f, -0.5f)), out _, Color.FromName(component._color), cleanable: true))
        {
            return;
        }

        if (component.UseSound != null)
        {
            SoundSystem.Play(Filter.Pvs(uid), component.UseSound.GetSound(), uid, AudioHelpers.WithVariation(0.125f));
        }

        // Decrease "Ammo"
        component.Charges--;
        Dirty(component);
        _logs.Add(LogType.CrayonDraw, LogImpact.Low, $"{EntityManager.ToPrettyString(args.User):user} drew a {component._color:color} {component.SelectedState}");
        args.Handled = true;

        if (component.DeleteEmpty && component.Charges <= 0)
        {
            UseUpCrayon(uid, args.User);
        }
    }
        private void OnActivated(EntityUid uid, SignalSwitchComponent component, ActivateInWorldEvent args)
        {
            if (args.Handled)
            {
                return;
            }

            component.State = !component.State;
            _signalSystem.InvokePort(uid, component.State ? component.OnPort : component.OffPort);
            SoundSystem.Play(component.ClickSound.GetSound(), Filter.Pvs(component.Owner), component.Owner,
                             AudioHelpers.WithVariation(0.125f).WithVolume(8f));

            args.Handled = true;
        }
Esempio n. 22
0
        public void Roll(EntityUid uid, DiceComponent die)
        {
            die.CurrentSide = _random.Next(1, (die.Sides / die.Step) + 1) * die.Step;

            SoundSystem.Play(Filter.Pvs(die.Owner), die.Sound.GetSound(), die.Owner, AudioHelpers.WithVariation(0.05f));

            if (!ComponentManager.TryGetComponent(uid, out SpriteComponent? sprite))
            {
                return;
            }

            // TODO DICE: Use a visualizer instead.
            sprite.LayerSetState(0, $"d{die.Sides}{die.CurrentSide}");
        }
 bool IUse.UseEntity(UseEntityEventArgs eventArgs)
 {
     if (!string.IsNullOrWhiteSpace(_soundName))
     {
         if (_pitchVariation > 0.0)
         {
             Owner.GetComponent <SoundComponent>().Play(_soundName, AudioHelpers.WithVariation(_pitchVariation).WithVolume(-2f));
             return(true);
         }
         Owner.GetComponent <SoundComponent>().Play(_soundName, AudioParams.Default.WithVolume(-2f));
         return(true);
     }
     return(false);
 }
Esempio n. 24
0
 bool IUse.UseEntity(UseEntityEventArgs eventArgs)
 {
     if (!string.IsNullOrWhiteSpace(_soundName))
     {
         if (_pitchVariation > 0.0)
         {
             EntitySystem.Get <AudioSystem>().Play(_soundName, Owner, AudioHelpers.WithVariation(_pitchVariation).WithVolume(-2f));
             return(true);
         }
         EntitySystem.Get <AudioSystem>().Play(_soundName, Owner, AudioParams.Default.WithVolume(-2f));
         return(true);
     }
     return(false);
 }
Esempio n. 25
0
        bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
        {
            if (_rateLimitedKnocking && _gameTiming.CurTime < _lastKnockTime + _knockDelay)
            {
                return(false);
            }

            SoundSystem.Play(Filter.Pvs(eventArgs.Target), "/Audio/Effects/glass_knock.ogg",
                             eventArgs.Target.Transform.Coordinates, AudioHelpers.WithVariation(0.05f));
            eventArgs.Target.PopupMessageEveryone(Loc.GetString("comp-window-knock"));

            _lastKnockTime = _gameTiming.CurTime;

            return(true);
        }
Esempio n. 26
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));
            }
        }
        public bool InteractHand(InteractHandEventArgs eventArgs)
        {
            if (!_canHelp || !KnockedDown)
            {
                return(false);
            }

            _canHelp = false;
            Timer.Spawn(((int)_helpInterval * 1000), () => _canHelp = true);

            EntitySystem.Get <AudioSystem>()
            .PlayFromEntity("/Audio/effects/thudswoosh.ogg", Owner, AudioHelpers.WithVariation(0.25f));

            _knockdownTimer -= _helpKnockdownRemove;

            return(true);
        }
Esempio n. 28
0
        private void HighPressureMovements(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile)
        {
            // TODO ATMOS finish this

            if (tile.PressureDifference > 15)
            {
                if (_spaceWindSoundCooldown == 0)
                {
                    var coordinates = tile.GridIndices.ToEntityCoordinates(tile.GridIndex, _mapManager);
                    if (!string.IsNullOrEmpty(SpaceWindSound))
                    {
                        SoundSystem.Play(Filter.Pvs(coordinates), SpaceWindSound, coordinates,
                                         AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(tile.PressureDifference / 10, 10, 100)));
                    }
                }
            }

            foreach (var entity in Get <GridTileLookupSystem>().GetEntitiesIntersecting(tile.GridIndex, tile.GridIndices))
            {
                if (!entity.TryGetComponent(out IPhysBody? physics) ||
                    !entity.IsMovedByPressure(out var pressure) ||
                    entity.IsInContainer())
                {
                    continue;
                }

                var pressureMovements = physics.Owner.EnsureComponent <MovedByPressureComponent>();
                if (pressure.LastHighPressureMovementAirCycle < gridAtmosphere.UpdateCounter)
                {
                    pressureMovements.ExperiencePressureDifference(gridAtmosphere.UpdateCounter, tile.PressureDifference, tile.PressureDirection, 0, tile.PressureSpecificTarget?.GridIndices.ToEntityCoordinates(tile.GridIndex, _mapManager) ?? EntityCoordinates.Invalid);
                }
            }

            if (tile.PressureDifference > 100)
            {
                // TODO ATMOS Do space wind graphics here!
            }

            _spaceWindSoundCooldown++;
            if (_spaceWindSoundCooldown > 75)
            {
                _spaceWindSoundCooldown = 0;
            }
        }
Esempio n. 29
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));
            }
        }
Esempio n. 30
0
        bool IDisarmedAct.Disarmed(DisarmedActEventArgs eventArgs)
        {
            if (!IoCManager.Resolve <IRobustRandom>().Prob(eventArgs.PushProbability))
            {
                return(false);
            }

            Paralyze(4f);

            var source = eventArgs.Source;

            EntitySystem.Get <AudioSystem>().PlayFromEntity("/Audio/Effects/thudswoosh.ogg", source,
                                                            AudioHelpers.WithVariation(0.025f));

            source.PopupMessageOtherClients(Loc.GetString("{0} pushes {1}!", source.Name, eventArgs.Target.Name));
            source.PopupMessageCursor(Loc.GetString("You push {0}!", eventArgs.Target.Name));

            return(true);
        }