protected override void Initialize()
 {
     base.Initialize();
     DamageType = IoCManager.Resolve <IPrototypeManager>().Index <DamageTypePrototype>(_damageTypeID);
     if (Owner.TryGetComponent(out AppearanceComponent? appearance))
     {
         appearance.SetData(AsteroidRockVisuals.State, _random.Pick(SpriteStates));
     }
 }
        void ILand.Land(LandEventArgs eventArgs)
        {
            var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>("GlassBreak");
            var file            = _random.Pick(soundCollection.PickFiles);

            EntitySystem.Get <AudioSystem>().PlayFromEntity(file, Owner);

            State = LightBulbState.Broken;
        }
예제 #3
0
 public void PlayFootstep()
 {
     if (!string.IsNullOrWhiteSpace(_soundCollectionName))
     {
         var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollectionName);
         var file            = _footstepRandom.Pick(soundCollection.PickFiles);
         EntitySystem.Get <AudioSystem>().PlayFromEntity(file, Owner, AudioParams.Default.WithVolume(-2f));
     }
 }
예제 #4
0
 public void PlaySqueakEffect()
 {
     if (!string.IsNullOrWhiteSpace(_soundCollectionName))
     {
         var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollectionName);
         var file            = _random.Pick(soundCollection.PickFiles);
         EntitySystem.Get <AudioSystem>().PlayFromEntity(file, Owner, AudioParams.Default);
     }
 }
예제 #5
0
 public void PlaySqueakEffect()
 {
     if (!string.IsNullOrWhiteSpace(_soundCollectionName))
     {
         var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollectionName);
         var file            = _random.Pick(soundCollection.PickFiles);
         SoundSystem.Play(Filter.Pvs(Owner), file, Owner, AudioParams.Default);
     }
 }
예제 #6
0
 public void PlayDiceEffect()
 {
     if (!string.IsNullOrWhiteSpace(_soundCollectionName))
     {
         var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollectionName);
         var file            = _random.Pick(soundCollection.PickFiles);
         Owner.GetComponent <SoundComponent>().Play(file, AudioParams.Default);
     }
 }
        private void Spawn(ConditionalSpawnerComponent component)
        {
            if (component.Chance != 1.0f && !_robustRandom.Prob(component.Chance))
            {
                return;
            }

            if (component.Prototypes.Count == 0)
            {
                Logger.Warning($"Prototype list in ConditionalSpawnComponent is empty! Entity: {component.Owner}");
                return;
            }

            if (!Deleted(component.Owner))
            {
                EntityManager.SpawnEntity(_robustRandom.Pick(component.Prototypes), Transform(component.Owner).Coordinates);
            }
        }
 public void PlayFootstep()
 {
     if (!string.IsNullOrWhiteSpace(_soundCollectionName))
     {
         var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollectionName);
         var file            = _footstepRandom.Pick(soundCollection.PickFiles);
         SoundSystem.Play(Filter.Pvs(Owner), file, Owner.Transform.Coordinates, AudioParams.Default.WithVolume(-2f));
     }
 }
        /// <summary>
        /// Ejects a random item if present.
        /// </summary>
        private void EjectRandom()
        {
            var availableItems = Inventory.Where(x => x.Amount > 0).ToList();

            if (availableItems.Count <= 0)
            {
                return;
            }
            TryEject(_random.Pick(availableItems).ID);
        }
예제 #10
0
        public string Accentuate(string message)
        {
            foreach (var(word, repl) in SpecialWords)
            {
                message = message.Replace(word, repl);
            }

            return(message.Replace("!", _random.Pick(Faces))
                   .Replace("r", "w").Replace("R", "W")
                   .Replace("l", "w").Replace("L", "W"));
        }
예제 #11
0
        /// <summary>
        ///     Ejects contents when they come from the same direction the entry is facing.
        /// </summary>
        public override Direction NextDirection(DisposalHolderComponent holder)
        {
            if (holder.PreviousTube != null && DirectionTo(holder.PreviousTube) == ConnectableDirections()[0])
            {
                var invalidDirections = new[] { ConnectableDirections()[0], Direction.Invalid };
                var directions        = Enum.GetValues(typeof(Direction))
                                        .Cast <Direction>().Except(invalidDirections).ToList();
                return(_random.Pick(directions));
            }

            return(ConnectableDirections()[0]);
        }
 public override void Initialize()
 {
     base.Initialize();
     if (_spriteStates == null)
     {
         return;
     }
     if (!Owner.TryGetComponent(out SpriteComponent spriteComponent))
     {
         return;
     }
     spriteComponent.LayerSetState(_spriteLayer, _random.Pick(_spriteStates));
 }
예제 #13
0
        /// <summary>
        /// Drops a single cartridge / shell
        /// Made as a static function just because multiple places need it
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="playSound"></param>
        /// <param name="robustRandom"></param>
        /// <param name="prototypeManager"></param>
        /// <param name="ejectDirections"></param>
        public static void EjectCasing(
            IEntity entity,
            bool playSound                     = true,
            IRobustRandom robustRandom         = null,
            IPrototypeManager prototypeManager = null,
            Direction[] ejectDirections        = null)
        {
            if (robustRandom == null)
            {
                robustRandom = IoCManager.Resolve <IRobustRandom>();
            }

            if (ejectDirections == null)
            {
                ejectDirections = new[] { Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West };
            }

            const float ejectOffset = 1.8f;
            var         ammo        = entity.GetComponent <AmmoComponent>();
            var         offsetPos   = ((robustRandom.NextFloat() - 0.5f) * ejectOffset, (robustRandom.NextFloat() - 0.5f) * ejectOffset);

            entity.Transform.Coordinates   = entity.Transform.Coordinates.Offset(offsetPos);
            entity.Transform.LocalRotation = robustRandom.Pick(ejectDirections).ToAngle();

            if (ammo.SoundCollectionEject == null || !playSound)
            {
                return;
            }

            if (prototypeManager == null)
            {
                prototypeManager = IoCManager.Resolve <IPrototypeManager>();
            }

            var soundCollection = prototypeManager.Index <SoundCollectionPrototype>(ammo.SoundCollectionEject);
            var randomFile      = robustRandom.Pick(soundCollection.PickFiles);

            SoundSystem.Play(Filter.Broadcast(), randomFile, entity.Transform.Coordinates, AudioParams.Default.WithVolume(-1));
        }
예제 #14
0
        private void OnMapInit(EntityUid uid, BarSignComponent component, MapInitEvent args)
        {
            if (component.CurrentSign != null)
            {
                return;
            }

            var prototypes = _prototypeManager.EnumeratePrototypes <BarSignPrototype>().Where(p => !p.Hidden)
                             .ToList();
            var prototype = _random.Pick(prototypes);

            component.CurrentSign = prototype.ID;
        }
예제 #15
0
        public override Direction NextDirection(DisposalHolderComponent holder)
        {
            var next       = Owner.Transform.LocalRotation.GetDir();
            var directions = ConnectableDirections().Skip(1).ToArray();

            if (holder.PreviousTube == null ||
                DirectionTo(holder.PreviousTube) == next)
            {
                return(_random.Pick(directions));
            }

            return(next);
        }
 protected override void Initialize()
 {
     base.Initialize();
     if (_spriteStates == null)
     {
         return;
     }
     if (!IoCManager.Resolve <IEntityManager>().TryGetComponent(Owner, out SpriteComponent? spriteComponent))
     {
         return;
     }
     spriteComponent.LayerSetState(_spriteLayer, _random.Pick(_spriteStates));
 }
        /// <summary>
        /// Makes sure this artifact is assigned a disease
        /// </summary>
        private void OnMapInit(EntityUid uid, DiseaseArtifactComponent component, MapInitEvent args)
        {
            if (component.SpawnDisease == string.Empty && component.ArtifactDiseases.Count != 0)
            {
                var diseaseName = _random.Pick(component.ArtifactDiseases);

                component.SpawnDisease = diseaseName;
            }

            if (_prototypeManager.TryIndex(component.SpawnDisease, out DiseasePrototype? disease) && disease != null)
            {
                component.ResolveDisease = disease;
            }
        }
예제 #18
0
        public void Land(LandEventArgs eventArgs)
        {
            if (State == LightBulbState.Broken)
            {
                return;
            }

            var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>("glassbreak");
            var file            = _random.Pick(soundCollection.PickFiles);

            EntitySystem.Get <AudioSystem>().PlayFromEntity(file, Owner);

            State = LightBulbState.Broken;
        }
예제 #19
0
    private void OnMapInit(EntityUid uid, GasArtifactComponent component, MapInitEvent args)
    {
        if (component.SpawnGas == null && component.PossibleGases.Length != 0)
        {
            var gas = _random.Pick(component.PossibleGases);
            component.SpawnGas = gas;
        }

        if (component.SpawnTemperature == null)
        {
            var temp = _random.NextFloat(component.MinRandomTemperature, component.MaxRandomTemperature);
            component.SpawnTemperature = temp;
        }
    }
예제 #20
0
        bool IUse.UseEntity(UseEntityEventArgs args)
        {
            if (!Opened)
            {
                //Do the opening stuff like playing the sounds.
                var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollection);
                var file            = _random.Pick(soundCollection.PickFiles);

                EntitySystem.Get <AudioSystem>().PlayFromEntity(file, args.User, AudioParams.Default);
                Opened = true;
                return(false);
            }
            return(TryUseDrink(args.User));
        }
예제 #21
0
        private IEntity?RandomNearbyPlayer()
        {
            var players = _playerManager
                          .GetPlayersInRange(Owner.Transform.Coordinates, 15)
                          .Where(player => player.AttachedEntity != null)
                          .ToArray();

            if (players.Length == 0)
            {
                return(null);
            }

            return(_random.Pick(players).AttachedEntity);
        }
    public void AddRandomTrigger(EntityUid uid, ArtifactComponent?component = null)
    {
        if (!Resolve(uid, ref component))
        {
            return;
        }

        var triggerName = _random.Pick(component.PossibleTriggers);
        var trigger     = (Component)_componentFactory.GetComponent(triggerName);

        trigger.Owner = uid;

        EntityManager.AddComponent(uid, trigger);
    }
        private void Spawn()
        {
            if (Chance != 1.0f && !_robustRandom.Prob(Chance))
            {
                return;
            }

            if (Prototypes.Count == 0)
            {
                Logger.Warning($"Prototype list in ConditionalSpawnComponent is empty! Entity: {Owner}");
                return;
            }

            _entityManager.SpawnEntity(_robustRandom.Pick(Prototypes), Owner.Transform.GridPosition);
        }
        private void OnTimerFired()
        {
            if (!_robustRandom.Prob(Chance))
            {
                return;
            }

            var number = _robustRandom.Next(MinimumEntitiesSpawned, MaximumEntitiesSpawned);

            for (int i = 0; i < number; i++)
            {
                var entity = _robustRandom.Pick(Prototypes);
                _entityManager.SpawnEntity(entity, Owner.Transform.GridPosition);
            }
        }
예제 #25
0
 private void OnMapInit(EntityUid uid, SuitSensorComponent component, MapInitEvent args)
 {
     // generate random mode
     if (component.RandomMode)
     {
         //make the sensor mode favor higher levels, except coords.
         var modesDist = new[]
         {
             SuitSensorMode.SensorOff,
             SuitSensorMode.SensorBinary, SuitSensorMode.SensorBinary,
             SuitSensorMode.SensorVitals, SuitSensorMode.SensorVitals, SuitSensorMode.SensorVitals,
             SuitSensorMode.SensorCords, SuitSensorMode.SensorCords
         };
         component.Mode = _random.Pick(modesDist);
     }
 }
예제 #26
0
        public void EjectRandom(EntityUid uid, bool throwItem, VendingMachineComponent?vendComponent = null)
        {
            if (!Resolve(uid, ref vendComponent))
            {
                return;
            }

            var availableItems = vendComponent.Inventory.Where(x => x.Amount > 0).ToList();

            if (availableItems.Count <= 0)
            {
                return;
            }

            TryEjectVendorItem(uid, _random.Pick(availableItems).ID, throwItem, vendComponent);
        }
        /// <summary>
        /// Makes sure this artifact is assigned a disease
        /// </summary>
        private void OnMapInit(EntityUid uid, DiseaseArtifactComponent component, MapInitEvent args)
        {
            if (component.SpawnDisease != null || ArtifactDiseases.Count == 0)
            {
                return;
            }
            var diseaseName = _random.Pick(ArtifactDiseases);

            if (!_prototypeManager.TryIndex <DiseasePrototype>(diseaseName, out var disease))
            {
                Logger.ErrorS("disease", $"Invalid disease {diseaseName} selected from random diseases.");
                return;
            }

            component.SpawnDisease = disease;
        }
        private EntityUid?RandomNearbyPlayer(EntityUid uid, RoguePointingArrowComponent?component = null, TransformComponent?transform = null)
        {
            if (!Resolve(uid, ref component, ref transform))
            {
                return(null);
            }

            var players = Filter.Empty()
                          .AddPlayersByPvs(transform.MapPosition)
                          .RemoveWhereAttachedEntity(euid => !EntityManager.TryGetComponent(euid, out MobStateComponent? mobStateComponent) || mobStateComponent.IsDead())
                          .Recipients
                          .ToArray();

            return(players.Length != 0
                ? _random.Pick(players).AttachedEntity
                : null);
        }
        public void SayAdvertisement(EntityUid uid, bool refresh = true, AdvertiseComponent?advertise = null)
        {
            if (!Resolve(uid, ref advertise))
            {
                return;
            }

            if (_prototypeManager.TryIndex(advertise.PackPrototypeId, out AdvertisementsPackPrototype? advertisements))
            {
                _chatManager.EntitySay(advertise.Owner, Loc.GetString(_random.Pick(advertisements.Advertisements)));
            }

            if (refresh)
            {
                RefreshTimer(uid, true, advertise);
            }
        }
예제 #30
0
        private BarSignPrototype Setup(EntityUid owner, BarSignComponent component)
        {
            var prototypes = _prototypeManager
                             .EnumeratePrototypes <BarSignPrototype>()
                             .Where(p => !p.Hidden)
                             .ToList();

            var newPrototype = _random.Pick(prototypes);

            var meta = Comp <MetaDataComponent>(owner);

            meta.EntityName        = newPrototype.Name != string.Empty ? newPrototype.Name : Loc.GetString("barsign-component-name");
            meta.EntityDescription = newPrototype.Description;

            component.CurrentSign = newPrototype.ID;
            return(newPrototype);
        }