Exemplo n.º 1
0
        public override void ExposeData(ObjectSerializer serializer)
        {
            base.ExposeData(serializer);
            // For shotty of whatever as well
            serializer.DataField(ref _projectileId, "projectile", null);
            serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified);
            serializer.DataField(ref _projectilesFired, "projectilesFired", 1);
            // Used for shotty to determine overall pellet spread
            serializer.DataField(ref _evenSpreadAngle, "ammoSpread", 0);
            serializer.DataField(ref _velocity, "ammoVelocity", 20.0f);
            serializer.DataField(ref _ammoIsProjectile, "isProjectile", false);
            serializer.DataField(ref _caseless, "caseless", false);
            // Being both caseless and shooting yourself doesn't make sense
            DebugTools.Assert(!(_ammoIsProjectile && _caseless));
            serializer.DataField(ref _muzzleFlashSprite, "muzzleFlash", "Objects/Guns/Projectiles/bullet_muzzle.png");
            serializer.DataField(ref _soundCollectionEject, "soundCollectionEject", "CasingEject");

            if (_projectilesFired < 1)
            {
                Logger.Error("Ammo can't have less than 1 projectile");
            }

            if (_evenSpreadAngle > 0 && _projectilesFired == 1)
            {
                Logger.Error("Can't have an even spread if only 1 projectile is fired");
                throw new InvalidOperationException();
            }
        }
        /// <summary>
        ///     Destroys the Owner <see cref="IEntity"/>, setting
        ///     <see cref="IDamageableComponent.CurrentState"/> to
        ///     <see cref="Shared.GameObjects.Components.Damage.DamageState.Dead"/>
        /// </summary>
        protected void PerformDestruction()
        {
            CurrentState = DamageState.Dead;

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

            DestructionBehavior();
        }
Exemplo n.º 3
0
        public override void Spawn()
        {
            if (RarePrototypes.Count > 0 && (RareChance == 1.0f || _robustRandom.Prob(RareChance)))
            {
                _entityManager.SpawnEntity(_robustRandom.Pick(RarePrototypes), Owner.Transform.GridPosition);
                return;
            }

            if (Chance != 1.0f && !_robustRandom.Prob(Chance))
            {
                return;
            }

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

            if (!Owner.Deleted)
            {
                var random = IoCManager.Resolve <IRobustRandom>();

                var x_negative = random.Prob(0.5f) ? -1 : 1;
                var y_negative = random.Prob(0.5f) ? -1 : 1;

                var entity = _entityManager.SpawnEntity(_robustRandom.Pick(Prototypes), Owner.Transform.GridPosition);
                entity.Transform.LocalPosition += new Vector2(random.NextFloat() * Offset * x_negative, random.NextFloat() * Offset * y_negative);
            }
        }
 public override void SetValue(IEntity value)
 {
     base.SetValue(value);
     if (value != null && !value.HasComponent <EntityStorageComponent>())
     {
         Logger.Warning("Set LastOpenedStorageState for an entity that doesn't have a storage component");
     }
 }
Exemplo n.º 5
0
        private void RequestVerbs(RequestVerbsMessage req, EntitySessionEventArgs eventArgs)
        {
            var player = (IPlayerSession)eventArgs.SenderSession;

            if (!_entityManager.TryGetEntity(req.EntityUid, out var entity))
            {
                Logger.Warning($"{nameof(RequestVerbs)} called on a nonexistant entity with id {req.EntityUid} by player {player}.");
                return;
            }

            var userEntity = player.AttachedEntity;

            var data = new List <VerbsResponseMessage.NetVerbData>();

            //Get verbs, component dependent.
            foreach (var(component, verb) in VerbUtility.GetVerbs(entity))
            {
                if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
                {
                    continue;
                }

                var verbData = verb.GetData(userEntity, component);
                if (verbData.IsInvisible)
                {
                    continue;
                }

                // TODO: These keys being giant strings is inefficient as hell.
                data.Add(new VerbsResponseMessage.NetVerbData(verbData, $"{component.GetType()}:{verb.GetType()}"));
            }

            //Get global verbs. Visible for all entities regardless of their components.
            foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
            {
                if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
                {
                    continue;
                }

                var verbData = globalVerb.GetData(userEntity, entity);
                if (verbData.IsInvisible)
                {
                    continue;
                }

                data.Add(new VerbsResponseMessage.NetVerbData(verbData, globalVerb.GetType().ToString()));
            }

            var response = new VerbsResponseMessage(data.ToArray(), req.EntityUid);

            RaiseNetworkEvent(response, player.ConnectedClient);
        }
        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);
        }
Exemplo n.º 7
0
        public void DoAutoRegistrations()
        {
            var iComponent = typeof(ITextMacro);

            foreach (var type in _reflectionManager.FindTypesWithAttribute <RegisterTextMacroAttribute>())
            {
                if (!iComponent.IsAssignableFrom(type))
                {
                    Logger.Error("Type {0} has RegisterTextMacroAttribute but does not implement ITextMacro.", type);
                    continue;
                }

                RegisterTextMacroAttribute registerAttribute = (RegisterTextMacroAttribute)type.GetCustomAttributes(typeof(RegisterTextMacroAttribute), false)[0];
                Register(registerAttribute.MacroName, registerAttribute.LanguageTag, type);
            }
        }
        void IMapInit.MapInit()
        {
            if (_contents.Count == 0)
            {
                return;
            }

            if (!Owner.TryGetComponent(out IStorageComponent storage))
            {
                Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({Owner})");
                return;
            }
            var random = IoCManager.Resolve <IRobustRandom>();

            var alreadySpawnedGroups = new List <string>();

            foreach (var storageItem in _contents)
            {
                if (string.IsNullOrEmpty(storageItem.PrototypeName))
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(storageItem.GroupId) && alreadySpawnedGroups.Contains(storageItem.GroupId))
                {
                    continue;
                }

                if (storageItem.SpawnProbability != 1f &&
                    !random.Prob(storageItem.SpawnProbability))
                {
                    continue;
                }

                for (var i = 0; i < storageItem.Amount; i++)
                {
                    storage.Insert(_entityManager.SpawnEntity(storageItem.PrototypeName, Owner.Transform.Coordinates));
                }
                if (!string.IsNullOrEmpty(storageItem.GroupId))
                {
                    alreadySpawnedGroups.Add(storageItem.GroupId);
                }
            }
        }
Exemplo n.º 9
0
        private void InitializeFluidsynth()
        {
            if (FluidsynthInitialized || _failedInitialize)
            {
                return;
            }

            try
            {
                NFluidsynth.Logger.SetLoggerMethod(null); // Will cause a safe DllNotFoundException if not available.

                _settings = new Settings();
                _settings["synth.sample-rate"].DoubleValue      = 48000;
                _settings["player.timing-source"].StringValue   = "sample";
                _settings["synth.lock-memory"].IntValue         = 0;
                _settings["synth.threadsafe-api"].IntValue      = 1;
                _settings["synth.gain"].DoubleValue             = 0.5d;
                _settings["audio.driver"].StringValue           = "file";
                _settings["midi.autoconnect"].IntValue          = 1;
                _settings["player.reset-synth"].IntValue        = 0;
                _settings["synth.midi-bank-select"].StringValue = "gm";
            }
            catch (Exception e)
            {
                Logger.WarningS("midi",
                                "Failed to initialize fluidsynth due to exception, disabling MIDI support:\n{0}", e);
                _failedInitialize = true;
                return;
            }

            _midiThread = new Thread(ThreadUpdate);
            _midiThread.Start();

            _soundfontLoaderCallbacks = new ResourceLoaderCallbacks();

            FluidsynthInitialized = true;
        }