Esempio n. 1
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);
        }
Esempio n. 2
0
        /* This is called every time a ship passes the mid line. r is the reference to the ship that has passed. */
        public override void OnShipTriggerMidLine(ShipRefs r)
        {
            // validate the lap so it can be updated next time the player triggers the start line
            r.LapValidated  = true;
            r.MiddleSection = r.CurrentSection;

            if (r.IsPlayer && !r.PassedValidationGate)
            {
                AudioHelpers.PlayOneShot(AudioHelpers.UI_Checkpoint, AudioHelpers.E_AUDIOCHANNEL.INTERFACE, 1.0f, 1.0f);
                CalculateAndDisplayRelativeTime(r);

                r.PassedValidationGate = true;
            }
        }
        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));
        }
 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. 5
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. 6
0
        public override bool Process()
        {
            var stats = Player.Stats.Details;

            if (stats == null)
            {
                return(false);
            }

            if (stats.ActualSourceVideoIntervalUsec < 1e-8)
            {
                return(false); // audio only - no need to reclock
            }
            var refclk = stats.RefClockDeviation;

            if (refclk > 10 || refclk < -10) // no data
            {
                return(false);
            }

            const int oneSecond = 1000000;
            var       videoHz   = oneSecond / stats.ActualSourceVideoIntervalUsec;
            var       displayHz = oneSecond / stats.DisplayRefreshIntervalUsec;
            var       ratio     = displayHz / videoHz;

            if (ratio > (100 + MAX_PERCENT_ADJUST) / 100 || ratio < (100 - MAX_PERCENT_ADJUST) / 100)
            {
                return(false);
            }

            var input  = Audio.Input;
            var output = Audio.Output;

            // passthrough from input to output
            AudioHelpers.CopySample(input, output, true);

            // Use of 0.999999 is to allow a tiny amount of measurement error in displayHz
            // This allows us to adjust refclk to just a fraction under the displayHz
            var  adjust = ratio * (0.999999 - refclk);
            long start, end;

            output.GetTime(out start, out end);
            long endDelta = end - start;

            start = (long)(start * adjust);
            output.SetTime(start, endDelta);

            return(true);
        }
Esempio n. 7
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. 8
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;
        }
        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;
        }
Esempio n. 10
0
            protected override bool Process(IAudioOutput input, IAudioOutput output)
            {
                if (!CalculateRatio(input))
                {
                    m_SampleIndex = -8 * RATIO_ADJUST_INTERVAL;
                    m_Ratio       = 1;
                    return(false);
                }

                // Passthrough from input to output
                AudioHelpers.CopySample(input.Sample, output.Sample, true);

                PerformReclock(output);

                return(true);
            }
Esempio n. 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));
            }
        }
        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. 13
0
        /*-----------------------------------------------------------------------------------------------------------------------
         * Assuming the prefab is setup correctly with the environment collider being solid and the ship collider being a trigger,
         *      this will trigger when the environment collider starts to collide with something.
         * ----------------------------------------------------------------------------------------------------------------------*/
        private void OnCollisionEnter(Collision other)
        {
            int otherLayer = other.gameObject.layer;

            /*------------------------------------------------------
             * Determine if we've hit the track or floor.
             * We could also determine if we hit a wall by using:
             *
             * bool hitwall = otherLayer == LayerIDs.TrackWall;
             * -----------------------------------------------------*/
            bool hitFloor = otherLayer == LayerIDs.SmoothFloor || other.gameObject.layer == LayerIDs.FakeFloor || other.gameObject.layer == LayerIDs.TrackFloor;

            // reflect the grenade
            if (hitFloor)
            {
                Vector3 bounceNormal = other.contacts[0].normal;

                // reflect the forward vector of the grenade
                Vector3 forward = transform.forward;
                forward           = Vector3.Reflect(forward, bounceNormal);
                transform.forward = forward;

                Body.AddForce(bounceNormal * StatBounceForce, ForceMode.VelocityChange);
                StatBounceForce *= 0.9f;

                // play Impact Sound
                AudioHelpers.PlayOneShot(AudioHelpers.GetAudioClip(AudioHelpers.Ship_FloorHit), AudioHelpers.E_AUDIOCHANNEL.SFX, 0.4f, 1.0f, transform.position, null, 15.0f, 30.0f);

                if (BounceCount > StatMaxBounces)
                {
                    DestroyProjectile(null);
                }

                // temporary bounce count immunity
                if (Lifetime > 0.5f)
                {
                    ++BounceCount;
                }
            }
            else
            {
                DestroyProjectile(null);
            }
        }
Esempio n. 14
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. 15
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);
        }
        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;
        }
Esempio n. 17
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. 18
0
 bool IUse.UseEntity(UseEntityEventArgs eventArgs)
 {
     if (!string.IsNullOrWhiteSpace(_soundName))
     {
         if (_pitchVariation > 0.0)
         {
             SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioHelpers.WithVariation(_pitchVariation).WithVolume(-2f));
             return(true);
         }
         if (_semitoneVariation > 0)
         {
             SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioHelpers.WithSemitoneVariation(_semitoneVariation).WithVolume(-2f));
             return(true);
         }
         SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioParams.Default.WithVolume(-2f));
         return(true);
     }
     return(false);
 }
Esempio n. 19
0
        private void WaveIn_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
        {
            (new Thread(() =>
            {
                var sw = new Stopwatch();
                sw.Start();
                AudioHelpers.ByteArrayTo16BITInputFormat(ref receivedData, e.Buffer);
                var input = receivedData.Convert2ChannelsToFloat();

                if (processor.Model.InputSamplesCount != input.Count())
                {
                    processor.Model.InputSamplesCount = input.Count();
                }

                var result = processor.Process(input.ToArray());
                var note = NoteViewModel.GetNote(result);
                sw.Stop();
                Debug.WriteLine(string.Format("Note {0}\tTime elapsed {1}", string.Format(note.Tone.ToString(), note.Base), sw.Elapsed));
            })).Start();
        }
        private void HighPressureMovements(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile)
        {
            // TODO ATMOS finish this

            // Don't play the space wind sound on tiles that are on fire...
            if (tile.PressureDifference > 15 && !tile.Hotspot.Valid)
            {
                if (_spaceWindSoundCooldown == 0 && !string.IsNullOrEmpty(SpaceWindSound))
                {
                    var coordinates = tile.GridIndices.ToEntityCoordinates(tile.GridIndex, _mapManager);
                    SoundSystem.Play(Filter.Pvs(coordinates), SpaceWindSound, coordinates,
                                     AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(tile.PressureDifference / 10, 10, 100)));
                }
            }

            foreach (var entity in _lookup.GetEntitiesIntersecting(tile.GridIndex, tile.GridIndices))
            {
                if (!HasComp <IPhysBody>(entity) ||
                    !entity.IsMovedByPressure(out var pressure) ||
                    entity.IsInContainer())
                {
                    continue;
                }

                var pressureMovements = EnsureComp <MovedByPressureComponent>(entity);
                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!
            }

            if (_spaceWindSoundCooldown++ > SpaceWindSoundCooldownCycles)
            {
                _spaceWindSoundCooldown = 0;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Get Audio details
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public async Task <AudioModel> GetAudioAsync(string fileName)
        {
            var audio = await _dbContext.Audios
                        .FirstOrDefaultAsync(a => a.FileName == fileName);

            if (audio == null)
            {
                return(null);
            }

            return(new AudioModel
            {
                FileName = audio.FileName,
                Issue = audio.Issue,
                Priority = AudioHelpers.GetPriority(audio.Sentiment),
                Transcript = audio.Transcript,
                Created = audio.Created.ToString("dddd, dd MMMM yyyy"),
                Taxonomy = audio.Taxonomy?.Split(','),
                Status = audio.Status
            });
        }
        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, comp.TurnOnFailSound.GetSound(), comp.Owner, 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, comp.TurnOnFailSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
                user.PopupMessage(Loc.GetString("comp-stunbaton-activated-dead-cell"));
                return;
            }

            SoundSystem.Play(playerFilter, comp.SparksSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));

            item.EquippedPrefix = "on";
            sprite.LayerSetState(0, "stunbaton_on");
            comp.Activated = true;
        }
Esempio n. 24
0
        protected override void CloseStorage()
        {
            base.CloseStorage();

            // No contents, we do nothing
            if (Contents.ContainedEntities.Count == 0)
            {
                return;
            }

            var lockers = _entMan.EntityQuery <EntityStorageComponent>().Select(c => c.Owner).ToList();

            if (lockers.Contains(Owner))
            {
                lockers.Remove(Owner);
            }

            if (lockers.Count == 0)
            {
                return;
            }

            var lockerEnt = _robustRandom.Pick(lockers);

            var locker = _entMan.GetComponent <EntityStorageComponent>(lockerEnt);

            if (locker.Open)
            {
                locker.TryCloseStorage(Owner);
            }

            foreach (var entity in Contents.ContainedEntities.ToArray())
            {
                Contents.ForceRemove(entity);
                locker.Insert(entity);
            }

            SoundSystem.Play(Filter.Pvs(Owner), _cursedSound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f));
            SoundSystem.Play(Filter.Pvs(lockerEnt), _cursedLockerSound.GetSound(), lockerEnt, AudioHelpers.WithVariation(0.125f));
        }
Esempio n. 25
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: false, popup: true,
                                               collisionMask: Shared.Physics.CollisionGroup.MobImpassable))
            {
                return(true);
            }

            if (Charges <= 0)
            {
                eventArgs.User.PopupMessage(Loc.GetString("crayon-interact-not-enough-left-text"));
                return(true);
            }

            if (!eventArgs.ClickLocation.IsValid(Owner.EntityManager))
            {
                eventArgs.User.PopupMessage(Loc.GetString("crayon-interact-invalid-location"));
                return(true);
            }

            var entity = Owner.EntityManager.SpawnEntity("CrayonDecal", eventArgs.ClickLocation);

            if (entity.TryGetComponent(out AppearanceComponent? appearance))
            {
                appearance.SetData(CrayonVisuals.State, SelectedState);
                appearance.SetData(CrayonVisuals.Color, _color);
                appearance.SetData(CrayonVisuals.Rotation, eventArgs.User.Transform.LocalRotation);
            }

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

            // Decrease "Ammo"
            Charges--;
            Dirty();
            return(true);
        }
Esempio n. 26
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();
        }
    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 _, component.Color, cleanable: true))
            return;

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

        // Decrease "Ammo"
        component.Charges--;
        Dirty(component);
        _adminLogger.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);
    }
Esempio n. 28
0
        public static void SpawnFoam(string entityPrototype, EntityCoordinates coords, Solution?contents, int amount, float duration, float spreadDelay,
                                     float removeDelay, SoundSpecifier sound, IEntityManager?entityManager = null)
        {
            entityManager ??= IoCManager.Resolve <IEntityManager>();
            var ent = entityManager.SpawnEntity(entityPrototype, coords.SnapToGrid());

            var areaEffectComponent = entityManager.GetComponentOrNull <FoamSolutionAreaEffectComponent>(ent);

            if (areaEffectComponent == null)
            {
                Logger.Error("Couldn't get AreaEffectComponent from " + entityPrototype);
                IoCManager.Resolve <IEntityManager>().QueueDeleteEntity(ent);
                return;
            }

            if (contents != null)
            {
                areaEffectComponent.TryAddSolution(contents);
            }
            areaEffectComponent.Start(amount, duration, spreadDelay, removeDelay);

            SoundSystem.Play(sound.GetSound(), Filter.Pvs(ent), ent, AudioHelpers.WithVariation(0.125f));
        }
Esempio n. 29
0
            protected sealed override bool Process(IAudioOutput input, IAudioOutput output)
            {
                if (input.Format.IsBitStreaming())
                {
                    return(false);
                }

                // WARNING: We assume input and output formats are the same

                // passthrough from input to output
                AudioHelpers.CopySample(input.Sample, output.Sample, false);

                IntPtr samples;

                input.Sample.GetPointer(out samples);
                var format         = input.Format;
                var bytesPerSample = format.wBitsPerSample / 8;
                var length         = input.Sample.GetActualDataLength() / bytesPerSample;
                var channels       = format.nChannels;
                var sampleFormat   = format.SampleFormat();

                return(Process(input, sampleFormat, samples, channels, length, output.Sample));
            }
        public void CollideWith(IEntity collidedWith)
        {
            if (ContainerHelpers.IsInContainer(Owner) ||
                _slipped.Contains(collidedWith.Uid) ||
                !collidedWith.TryGetComponent(out StunnableComponent stun) ||
                !collidedWith.TryGetComponent(out ICollidableComponent otherBody) ||
                !collidedWith.TryGetComponent(out IPhysicsComponent otherPhysics) ||
                !Owner.TryGetComponent(out ICollidableComponent body))
            {
                return;
            }

            if (otherPhysics.LinearVelocity.Length < RequiredSlipSpeed || stun.KnockedDown)
            {
                return;
            }

            var percentage = otherBody.WorldAABB.IntersectPercentage(body.WorldAABB);

            if (percentage < IntersectPercentage)
            {
                return;
            }

            if (!EffectBlockerSystem.CanSlip(collidedWith))
            {
                return;
            }

            stun.Paralyze(5f);
            _slipped.Add(collidedWith.Uid);

            if (!string.IsNullOrEmpty(SlipSound))
            {
                EntitySystem.Get <AudioSystem>().PlayFromEntity(SlipSound, Owner, AudioHelpers.WithVariation(0.2f));
            }
        }