public FireTileOverlay()
        {
            IoCManager.InjectDependencies(this);

            _gasTileOverlaySystem = EntitySystem.Get <GasTileOverlaySystem>();
            _shader = _prototypeManager.Index <ShaderPrototype>("unshaded").Instance().Duplicate();
            ZIndex  = GasTileOverlaySystem.GasOverlayZIndex + 1;
        }
        private void PlayKeyboardSound()
        {
            var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollectionName);
            var file            = _random.Pick(soundCollection.PickFiles);
            var audioSystem     = _entitySystemManager.GetEntitySystem <AudioSystem>();

            audioSystem.Play(file);
        }
 public void PlayFootstep()
 {
     if (!string.IsNullOrWhiteSpace(_soundCollectionName))
     {
         var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollectionName);
         var file            = _footstepRandom.Pick(soundCollection.PickFiles);
         Owner.GetComponent <SoundComponent>().Play(file, AudioParams.Default.WithVolume(-2f));
     }
 }
Exemple #4
0
        public override void Initialize()
        {
            base.Initialize();

            for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
            {
                GasPrototypes[i] = _prototypeManager.Index <GasPrototype>(i.ToString());
            }
        }
Exemple #5
0
 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, AudioParams.Default.WithVolume(-2f));
     }
 }
        public void Land(LandEventArgs eventArgs)
        {
            var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>("GlassBreak");
            var file            = _random.Pick(soundCollection.PickFiles);

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

            State = LightBulbState.Broken;
        }
Exemple #7
0
        private ShaderInstance MakeNewShader(bool inRange, int renderScale)
        {
            var shaderName = inRange ? ShaderInRange : ShaderOutOfRange;

            var instance = _prototypeManager.Index <ShaderPrototype>(shaderName).InstanceUnique();

            instance.SetParameter("outline_width", DefaultWidth * renderScale);
            return(instance);
        }
 public EffectOverlay(EffectSystem owner, IPrototypeManager protoMan, IMapManager mapMan, IPlayerManager playerMan, IEntityManager entityManager) : base(
         "EffectSystem")
 {
     _owner          = owner;
     _unshadedShader = protoMan.Index <ShaderPrototype>("unshaded").Instance();
     _mapManager     = mapMan;
     _playerManager  = playerMan;
     _entityManager  = entityManager;
 }
Exemple #9
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);
     }
 }
 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);
     }
 }
Exemple #11
0
        public override void Initialize()
        {
            base.Initialize();

            var shaderProto = _prototypeManager.Index <ShaderPrototype>(HairShaderName);

            _facialHairShader = shaderProto.InstanceUnique();
            _hairShader       = shaderProto.InstanceUnique();
        }
 public void PlayDiceEffect()
 {
     if (!string.IsNullOrWhiteSpace(_soundCollectionName))
     {
         var soundCollection = _prototypeManager.Index <SoundCollectionPrototype>(_soundCollectionName);
         var file            = _random.Pick(soundCollection.PickFiles);
         EntitySystem.Get <AudioSystem>().PlayFromEntity(file, Owner, AudioParams.Default);
     }
 }
Exemple #13
0
    //TODO: Figure out if everything in the player spawning region belongs somewhere else.
    #region Player spawning helpers

    /// <summary>
    /// Spawns in a player's mob according to their job and character information at the given coordinates.
    /// Used by systems that need to handle spawning players.
    /// </summary>
    /// <param name="coordinates">Coordinates to spawn the character at.</param>
    /// <param name="job">Job to assign to the character, if any.</param>
    /// <param name="profile">Appearance profile to use for the character.</param>
    /// <param name="station">The station this player is being spawned on.</param>
    /// <returns>The spawned entity</returns>
    public EntityUid SpawnPlayerMob(
        EntityCoordinates coordinates,
        Job?job,
        HumanoidCharacterProfile?profile,
        EntityUid?station)
    {
        // If we're not spawning a humanoid, we're gonna exit early without doing all the humanoid stuff.
        if (job?.JobEntity != null)
        {
            var jobEntity = EntityManager.SpawnEntity(job.JobEntity, coordinates);
            MakeSentientCommand.MakeSentient(jobEntity, EntityManager);
            DoJobSpecials(job, jobEntity);
            _identity.QueueIdentityUpdate(jobEntity);
            return(jobEntity);
        }

        var entity = EntityManager.SpawnEntity(
            _prototypeManager.Index <SpeciesPrototype>(profile?.Species ?? SpeciesManager.DefaultSpecies).Prototype,
            coordinates);

        if (job?.StartingGear != null)
        {
            var startingGear = _prototypeManager.Index <StartingGearPrototype>(job.StartingGear);
            EquipStartingGear(entity, startingGear, profile);
            if (profile != null)
            {
                EquipIdCard(entity, profile.Name, job.Prototype, station);
            }
        }

        if (profile != null)
        {
            _humanoidAppearanceSystem.UpdateFromProfile(entity, profile);
            EntityManager.GetComponent <MetaDataComponent>(entity).EntityName = profile.Name;
            if (profile.FlavorText != "" && _configurationManager.GetCVar(CCVars.FlavorText))
            {
                EntityManager.AddComponent <DetailExaminableComponent>(entity).Content = profile.FlavorText;
            }
        }

        DoJobSpecials(job, entity);
        _identity.QueueIdentityUpdate(entity);
        return(entity);
    }
        /// <summary>
        ///     Called every tick when this event is running.
        ///     Events are responsible for their own lifetime, so this handles starting and ending after time.
        /// </summary>
        public override void Update(float frameTime)
        {
            if (!RuleAdded || Configuration is not StationEventRuleConfiguration data)
            {
                return;
            }

            Elapsed += frameTime;

            if (!RuleStarted && Elapsed >= data.StartAfter)
            {
                GameTicker.StartGameRule(PrototypeManager.Index <GameRulePrototype>(Prototype));
            }

            if (RuleStarted && Elapsed >= data.EndAfter)
            {
                GameTicker.EndGameRule(PrototypeManager.Index <GameRulePrototype>(Prototype));
            }
        }
Exemple #15
0
        private void OnStartup(EntityUid uid, LoadoutComponent component, ComponentStartup args)
        {
            if (component.Prototype == string.Empty)
            {
                return;
            }

            var proto = _protoMan.Index <StartingGearPrototype>(component.Prototype);

            _station.EquipStartingGear(uid, proto, null);
        }
        /// <summary>
        ///     Tries to add a status effect to an entity with a certain timer.
        /// </summary>
        /// <param name="uid">The entity to add the effect to.</param>
        /// <param name="key">The status effect ID to add.</param>
        /// <param name="time">How long the effect should last for.</param>
        /// <param name="status">The status effects component to change, if you already have it.</param>
        /// <param name="alerts">The alerts component to modify, if the status effect has an alert.</param>
        /// <returns>False if the effect could not be added, or if the effect already existed.</returns>
        /// <remarks>
        ///     This obviously does not add any actual 'effects' on its own. Use the generic overload,
        ///     which takes in a component type, if you want to automatically add and remove a component.
        ///
        ///     If the effect already exists, it will simply replace the cooldown with the new one given.
        ///     If you want special 'effect merging' behavior, do it your own damn self!
        /// </remarks>
        public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time,
                                       StatusEffectsComponent?status = null,
                                       SharedAlertsComponent?alerts  = null)
        {
            if (!Resolve(uid, ref status, false))
            {
                return(false);
            }
            if (!CanApplyEffect(uid, key, status))
            {
                return(false);
            }

            Resolve(uid, ref alerts, false);

            // we already checked if it has the index in CanApplyEffect so a straight index and not tryindex here
            // is fine
            var proto = _prototypeManager.Index <StatusEffectPrototype>(key);

            (TimeSpan, TimeSpan)cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + time);

            // If they already have this status effect, just bulldoze its cooldown in favor of the new one
            // and keep the relevant component the same.
            if (HasStatusEffect(uid, key, status))
            {
                status.ActiveEffects[key] = new StatusEffectState(cooldown, status.ActiveEffects[key].RelevantComponent);
            }
            else
            {
                status.ActiveEffects.Add(key, new StatusEffectState(cooldown, null));
            }

            if (proto.Alert != null && alerts != null)
            {
                alerts.ShowAlert(proto.Alert.Value, cooldown: GetAlertCooldown(uid, proto.Alert.Value, status));
            }

            status.Dirty();
            // event?
            return(true);
        }
        private void RandomizeName()
        {
            if (Profile == null)
            {
                return;
            }
            var firstName = _random.Pick(Profile.Sex.FirstNames(_prototypeManager).Values);
            var lastName  = _random.Pick(_prototypeManager.Index <DatasetPrototype>("names_last"));

            SetName($"{firstName} {lastName}");
            UpdateNameEdit();
        }
Exemple #18
0
        public FlashOverlay() : base(nameof(SharedOverlayID.FlashOverlay))
        {
            IoCManager.InjectDependencies(this);
            _shader = _prototypeManager.Index <ShaderPrototype>("FlashedEffect").Instance().Duplicate();

            _startTime = _gameTiming.CurTime.TotalMilliseconds;
            _displayManager.Screenshot(ScreenshotType.BeforeUI, image =>
            {
                var rgba32Image    = image.CloneAs <Rgba32>(Configuration.Default);
                _screenshotTexture = _displayManager.LoadTextureFromImage(rgba32Image);
            });
        }
Exemple #19
0
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            if (args.Length != 2)
            {
                shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
                return;
            }

            var player = shell.Player as IPlayerSession;

            if (player == null)
            {
                return;
            }

            var ticker        = EntitySystem.Get <GameTicker>();
            var stationSystem = EntitySystem.Get <StationSystem>();
            var stationJobs   = EntitySystem.Get <StationJobsSystem>();

            if (!ticker.PlayersInLobby.ContainsKey(player) || ticker.PlayersInLobby[player] == LobbyPlayerStatus.Observer)
            {
                Logger.InfoS("security", $"{player.Name} ({player.UserId}) attempted to latejoin while in-game.");
                shell.WriteError($"{player.Name} is not in the lobby.   This incident will be reported.");
                return;
            }

            if (ticker.RunLevel == GameRunLevel.PreRoundLobby)
            {
                shell.WriteLine("Round has not started.");
                return;
            }
            else if (ticker.RunLevel == GameRunLevel.InRound)
            {
                string id = args[0];

                if (!int.TryParse(args[1], out var sid))
                {
                    shell.WriteError(Loc.GetString("shell-argument-must-be-number"));
                }

                var station      = new EntityUid(sid);
                var jobPrototype = _prototypeManager.Index <JobPrototype>(id);
                if (stationJobs.TryGetJobSlot(station, jobPrototype, out var slots) == false || slots == 0)
                {
                    shell.WriteLine($"{jobPrototype.Name} has no available slots.");
                    return;
                }
                ticker.MakeJoinGame(player, station, id);
                return;
            }

            ticker.MakeJoinGame(player, EntityUid.Invalid);
        }
        private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args)
        {
            // This is so entities that shouldn't get a collision are ignored.
            if (!args.OtherFixture.Hard || component.DamagedEntity)
            {
                return;
            }

            var otherEntity = args.OtherFixture.Body.Owner;

            var coordinates  = args.OtherFixture.Body.Owner.Transform.Coordinates;
            var playerFilter = Filter.Pvs(coordinates);

            if (!otherEntity.Deleted && component.SoundHitSpecies != null &&
                otherEntity.HasComponent <SharedBodyComponent>())
            {
                SoundSystem.Play(playerFilter, component.SoundHitSpecies.GetSound(), coordinates);
            }
            else
            {
                var soundHit = component.SoundHit?.GetSound();

                if (!string.IsNullOrEmpty(soundHit))
                {
                    SoundSystem.Play(playerFilter, soundHit, coordinates);
                }
            }

            if (!otherEntity.Deleted && otherEntity.TryGetComponent(out IDamageableComponent? damage))
            {
                EntityManager.TryGetEntity(component.Shooter, out var shooter);

                foreach (var(damageTypeID, amount) in component.Damages)
                {
                    damage.TryChangeDamage(_prototypeManager.Index <DamageTypePrototype>(damageTypeID), amount);
                }

                component.DamagedEntity = true;
            }

            // Damaging it can delete it
            if (!otherEntity.Deleted && otherEntity.TryGetComponent(out CameraRecoilComponent? recoilComponent))
            {
                var direction = args.OurFixture.Body.LinearVelocity.Normalized;
                recoilComponent.Kick(direction);
            }

            if (component.DeleteOnCollide)
            {
                EntityManager.QueueDeleteEntity(uid);
            }
        }
Exemple #21
0
        public override void ExposeData(ObjectSerializer serializer)
        {
            base.ExposeData(serializer);

            serializer.DataReadFunction <string>("seed", null,
                                                 (s) =>
            {
                if (!string.IsNullOrEmpty(s))
                {
                    Seed = _prototypeManager.Index <Seed>(s);
                }
            });
        }
        public void SetOrders(List <CargoOrderData> orders)
        {
            Orders.DisposeAllChildren();

            foreach (var order in orders)
            {
                var product     = _protoManager.Index <CargoProductPrototype>(order.ProductId);
                var productName = product.Name;

                var row = new CargoOrderRow
                {
                    Order       = order,
                    Icon        = { Texture = _spriteSystem.Frame0(product.Icon) },
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            if (args.Length != 2)
            {
                shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
                return;
            }

            var player = shell.Player as IPlayerSession;

            if (player == null)
            {
                return;
            }

            var ticker        = EntitySystem.Get <GameTicker>();
            var stationSystem = EntitySystem.Get <StationSystem>();

            if (!ticker.PlayersInLobby.ContainsKey(player))
            {
                shell.WriteError($"{player.Name} is not in the lobby.   This incident will be reported.");
                return;
            }

            if (ticker.RunLevel == GameRunLevel.PreRoundLobby)
            {
                shell.WriteLine("Round has not started.");
                return;
            }
            else if (ticker.RunLevel == GameRunLevel.InRound)
            {
                string id = args[0];

                if (!uint.TryParse(args[1], out var sid))
                {
                    shell.WriteError(Loc.GetString("shell-argument-must-be-number"));
                }

                var stationId    = new StationId(sid);
                var jobPrototype = _prototypeManager.Index <JobPrototype>(id);
                if (!stationSystem.IsJobAvailableOnStation(stationId, jobPrototype))
                {
                    shell.WriteLine($"{jobPrototype.Name} has no available slots.");
                    return;
                }
                ticker.MakeJoinGame(player, stationId, id);
                return;
            }

            ticker.MakeJoinGame(player, StationId.Invalid);
        }
        public void Update(float frameTime)
        {
            if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
            {
                return;
            }

            if (!_running)
            {
                return;
            }

            _timer      += frameTime;
            _reactTimer += frameTime;

            if (_reactTimer >= ReactTime && Owner.TryGetComponent(out IPhysicsComponent physics))
            {
                _reactTimer = 0;
                var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID);

                var tile = mapGrid.GetTileRef(Owner.Transform.Coordinates.ToVector2i(Owner.EntityManager, _mapManager));
                foreach (var reagentQuantity in contents.ReagentList.ToArray())
                {
                    if (reagentQuantity.Quantity == ReagentUnit.Zero)
                    {
                        continue;
                    }
                    var reagent = _prototypeManager.Index <ReagentPrototype>(reagentQuantity.ReagentId);
                    contents.TryRemoveReagent(reagentQuantity.ReagentId, reagent.ReactionTile(tile, (reagentQuantity.Quantity / _transferAmount) * 0.25f));
                }
            }

            // Check if we've reached our target.
            if (!_reached && _target.TryDistance(Owner.EntityManager, Owner.Transform.Coordinates, out var distance) && distance <= 0.5f)
            {
                _reached = true;

                if (Owner.TryGetComponent(out IPhysicsComponent coll))
                {
                    var controller = coll.EnsureController <VaporController>();
                    controller.Stop();
                }
            }

            if (contents.CurrentVolume == 0 || _timer > _aliveTime)
            {
                // Delete this
                Owner.Delete();
            }
        }
        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));
        }
Exemple #26
0
        public ParallaxOverlay()
        {
            IoCManager.InjectDependencies(this);
            _shader = _prototypeManager.Index <ShaderPrototype>("unshaded").Instance();

            if (_parallaxManager.ParallaxTexture == null)
            {
                _parallaxManager.OnTextureLoaded += texture => _parallaxTexture = texture;
            }
            else
            {
                _parallaxTexture = _parallaxManager.ParallaxTexture;
            }
        }
        /// <inheritdoc />
        public bool TrySpawnEntityAt(string EntityType, LocalCoordinates coordinates, out IEntity entity)
        {
            var prototype = _protoManager.Index <EntityPrototype>(EntityType);

            if (prototype.CanSpawnAt(coordinates.Grid, coordinates.Position))
            {
                entity = SpawnEntity(EntityType);
                entity.GetComponent <TransformComponent>().LocalPosition = coordinates;
                entity.Initialize();
                return(true);
            }
            entity = null;
            return(false);
        }
Exemple #28
0
        public void Land(LandEventArgs eventArgs)
        {
            if (State == LightBulbState.Broken)
            {
                return;
            }

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

            IoCManager.Resolve <IEntitySystemManager>().GetEntitySystem <AudioSystem>().Play(file, Owner);

            State = LightBulbState.Broken;
        }
    //TODO: Figure out if everything in the player spawning region belongs somewhere else.
    #region Player spawning helpers

    /// <summary>
    /// Spawns in a player's mob according to their job and character information at the given coordinates.
    /// Used by systems that need to handle spawning players.
    /// </summary>
    /// <param name="coordinates">Coordinates to spawn the character at.</param>
    /// <param name="job">Job to assign to the character, if any.</param>
    /// <param name="profile">Appearance profile to use for the character.</param>
    /// <param name="station">The station this player is being spawned on.</param>
    /// <returns>The spawned entity</returns>
    public EntityUid SpawnPlayerMob(
        EntityCoordinates coordinates,
        Job?job,
        HumanoidCharacterProfile?profile,
        EntityUid?station)
    {
        var entity = EntityManager.SpawnEntity(
            _prototypeManager.Index <SpeciesPrototype>(profile?.Species ?? SpeciesManager.DefaultSpecies).Prototype,
            coordinates);

        if (job?.StartingGear != null)
        {
            var startingGear = _prototypeManager.Index <StartingGearPrototype>(job.StartingGear);
            EquipStartingGear(entity, startingGear, profile);
            if (profile != null)
            {
                EquipIdCard(entity, profile.Name, job.Prototype, station);
            }
        }

        if (profile != null)
        {
            _humanoidAppearanceSystem.UpdateFromProfile(entity, profile);
            EntityManager.GetComponent <MetaDataComponent>(entity).EntityName = profile.Name;
            if (profile.FlavorText != "" && _configurationManager.GetCVar(CCVars.FlavorText))
            {
                EntityManager.AddComponent <DetailExaminableComponent>(entity).Content = profile.FlavorText;
            }
        }

        foreach (var jobSpecial in job?.Prototype.Special ?? Array.Empty <JobSpecial>())
        {
            jobSpecial.AfterEquip(entity);
        }

        return(entity);
    }
        /// <summary>
        /// Gets called by an AreaEffectInceptionComponent.
        /// Makes this effect's reagents react with the tile its on and with the entities it covers. Also calls
        /// ReactWithEntity on the entities so inheritors can implement more specific behavior.
        /// </summary>
        /// <param name="averageExposures">How many times will this get called over this area effect's duration, averaged
        /// with the other area effects from the inception.</param>
        public void React(float averageExposures)
        {
            if (!_entities.EntitySysManager.GetEntitySystem <SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
            {
                return;
            }

            var xform = _entities.GetComponent <TransformComponent>(Owner);

            if (!MapManager.TryGetGrid(xform.GridUid, out var mapGrid))
            {
                return;
            }

            var tile      = mapGrid.GetTileRef(xform.Coordinates.ToVector2i(_entities, MapManager));
            var chemistry = _entities.EntitySysManager.GetEntitySystem <ReactiveSystem>();
            var lookup    = _entities.EntitySysManager.GetEntitySystem <EntityLookupSystem>();

            var solutionFraction = 1 / Math.Floor(averageExposures);

            foreach (var reagentQuantity in solution.Contents.ToArray())
            {
                if (reagentQuantity.Quantity == FixedPoint2.Zero)
                {
                    continue;
                }
                var reagent = PrototypeManager.Index <ReagentPrototype>(reagentQuantity.ReagentId);

                // React with the tile the effect is on
                // We don't multiply by solutionFraction here since the tile is only ever reacted once
                if (!ReactedTile)
                {
                    reagent.ReactionTile(tile, reagentQuantity.Quantity);
                    ReactedTile = true;
                }

                // Touch every entity on the tile
                foreach (var entity in lookup.GetEntitiesIntersecting(tile).ToArray())
                {
                    chemistry.ReactionEntity(entity, ReactionMethod.Touch, reagent,
                                             reagentQuantity.Quantity * solutionFraction, solution);
                }
            }

            foreach (var entity in lookup.GetEntitiesIntersecting(tile).ToArray())
            {
                ReactWithEntity(entity, solutionFraction);
            }
        }