示例#1
0
        public override void Initialize()
        {
            base.Initialize();
            _idSlot  = ContainerManagerComponent.Ensure <ContainerSlot>("pda_entity_container", Owner);
            _penSlot = ContainerManagerComponent.Ensure <ContainerSlot>("pda_pen_slot", Owner);

            if (UserInterface != null)
            {
                UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
            }

            if (!string.IsNullOrEmpty(_startingIdCard))
            {
                var idCard          = _entityManager.SpawnEntity(_startingIdCard, Owner.Transform.Coordinates);
                var idCardComponent = idCard.GetComponent <IdCardComponent>();
                _idSlot.Insert(idCardComponent.Owner);
                ContainedID = idCardComponent;
            }

            if (!string.IsNullOrEmpty(_startingPen))
            {
                var pen = _entityManager.SpawnEntity(_startingPen, Owner.Transform.Coordinates);
                _penSlot.Insert(pen);
            }

            UpdatePDAAppearance();
        }
 public bool InsertMagazine(IEntity magazine, bool playSound = true)
 {
     if (!magazine.TryGetComponent(out BallisticMagazineComponent magazinetype))
     {
         throw new ArgumentException("Not a magazine", nameof(magazine));
     }
     if (!MagazineTypes.Contains(magazinetype.MagazineType))
     {
         throw new ArgumentException("Wrong magazine type", nameof(magazine));
     }
     if (!_magazineSlot.Insert(magazine))
     {
         return(false);
     }
     if (_magInSound != null && playSound)
     {
         EntitySystem.Get <AudioSystem>().PlayFromEntity(_magInSound, Owner);
     }
     magazinetype.OnAmmoCountChanged += MagazineAmmoCountChanged;
     if (GetChambered(0) == null)
     {
         // No bullet in chamber, load one from magazine.
         var bullet = magazinetype.TakeBullet();
         if (bullet != null)
         {
             LoadIntoChamber(0, bullet);
         }
     }
     UpdateAppearance();
     Dirty();
     return(true);
 }
示例#3
0
        bool IAttackBy.AttackBy(AttackByEventArgs eventArgs)
        {
            if (!eventArgs.AttackWith.HasComponent <PowerCellComponent>())
            {
                return(false);
            }

            if (Cell != null)
            {
                return(false);
            }

            eventArgs.User.GetComponent <IHandsComponent>().Drop(eventArgs.AttackWith, _cellContainer);

            return(_cellContainer.Insert(eventArgs.AttackWith));
        }
示例#4
0
        public void MapInit()
        {
            if (!string.IsNullOrEmpty(_startingIdCard))
            {
                var idCard          = _entityManager.SpawnEntity(_startingIdCard, Owner.Transform.Coordinates);
                var idCardComponent = idCard.GetComponent <IdCardComponent>();
                _idSlot.Insert(idCardComponent.Owner);
                ContainedID = idCardComponent;
            }

            if (!string.IsNullOrEmpty(_startingPen))
            {
                var pen = _entityManager.SpawnEntity(_startingPen, Owner.Transform.Coordinates);
                _penSlot.Insert(pen);
            }
        }
        void IMapInit.MapInit()
        {
            if (_cellContainer.ContainedEntity != null)
            {
                return;
            }
            var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallHyper");

            _cellContainer.Insert(cell);
        }
        void IMapInit.MapInit()
        {
            if (_cellContainer.ContainedEntity != null)
            {
                return;
            }

            var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallStandard", Owner.Transform.Coordinates);

            _cellContainer.Insert(cell);
        }
示例#7
0
        public override void Initialize()
        {
            base.Initialize();

            Owner.GetComponent <PowerReceiverComponent>().OnPowerStateChanged += UpdateLight;

            _lightBulbContainer = ContainerManagerComponent.Ensure <ContainerSlot>("light_bulb", Owner, out var existed);

            if (!existed) // Insert a light tube if there wasn't any.
            {
                switch (BulbType)
                {
                case LightBulbType.Tube:
                    _lightBulbContainer.Insert(Owner.EntityManager.SpawnEntity("LightTube", Owner.Transform.GridPosition));
                    break;

                case LightBulbType.Bulb:
                    _lightBulbContainer.Insert(Owner.EntityManager.SpawnEntity("LightBulb", Owner.Transform.GridPosition));
                    break;
                }
            }
        }
        private void Cycle(bool manual = false)
        {
            var chamberedEntity = _chamberContainer.ContainedEntity;

            if (chamberedEntity != null)
            {
                _chamberContainer.Remove(chamberedEntity);
                var ammoComponent = chamberedEntity.GetComponent <AmmoComponent>();
                if (!ammoComponent.Caseless)
                {
                    EjectCasing(chamberedEntity);
                }
            }

            if (_spawnedAmmo.TryPop(out var next))
            {
                _ammoContainer.Remove(next);
                _chamberContainer.Insert(next);
            }

            if (_unspawnedCount > 0)
            {
                _unspawnedCount--;
                var ammoEntity = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.Coordinates);
                _chamberContainer.Insert(ammoEntity);
            }

            if (manual)
            {
                if (_soundCycle != null)
                {
                    EntitySystem.Get <AudioSystem>().PlayAtCoords(_soundCycle, Owner.Transform.Coordinates, AudioParams.Default.WithVolume(-2));
                }
            }

            Dirty();
            UpdateAppearance();
        }
示例#9
0
 public bool TryInsertItem(EntityUid entity)
 {
     if (!IsEntityCompatible(entity) || HasCell)
     {
         return(false);
     }
     if (!Container.Insert(entity))
     {
         return(false);
     }
     _heldBattery = GetBatteryFrom(entity);
     UpdateStatus();
     return(true);
 }
        public override IEntity PeekAmmo()
        {
            // Spawn a dummy entity because it's easier to work with I guess
            // This will get re-used for the projectile
            var ammo = _ammoContainer.ContainedEntity;

            if (ammo == null)
            {
                ammo = Owner.EntityManager.SpawnEntity(_ammoPrototype, Owner.Transform.GridPosition);
                _ammoContainer.Insert(ammo);
            }

            return(ammo);
        }
示例#11
0
 private bool TryInsertItem(IEntity entity)
 {
     if (!IsEntityCompatible(entity) || _container.ContainedEntity != null)
     {
         return(false);
     }
     if (!_container.Insert(entity))
     {
         return(false);
     }
     _heldBattery = GetBatteryFrom(entity);
     UpdateStatus();
     return(true);
 }
        public override EntityUid?PeekAmmo()
        {
            // Spawn a dummy entity because it's easier to work with I guess
            // This will get re-used for the projectile
            var ammo = _ammoContainer.ContainedEntity;

            if (ammo == null)
            {
                ammo = _entities.SpawnEntity(_ammoPrototype, _entities.GetComponent <TransformComponent>(Owner).Coordinates);
                _ammoContainer.Insert(ammo.Value);
            }

            return(ammo.Value);
        }
        /// <summary>
        ///     Inserts the bulb if possible.
        /// </summary>
        /// <returns>True if it could insert it, false if it couldn't.</returns>
        private bool InsertBulb(IEntity bulb)
        {
            if (LightBulb != null)
            {
                return(false);
            }
            if (!bulb.TryGetComponent(out LightBulbComponent? lightBulb))
            {
                return(false);
            }
            if (lightBulb.Type != _bulbType)
            {
                return(false);
            }

            var inserted = _lightBulbContainer.Insert(bulb);

            lightBulb.OnLightBulbStateChange += UpdateLight;
            lightBulb.OnLightColorChange     += UpdateLight;

            UpdateLight();

            return(inserted);
        }
示例#14
0
        public override void Initialize()
        {
            base.Initialize();

            _pointLight      = Owner.GetComponent <PointLightComponent>();
            _spriteComponent = Owner.GetComponent <SpriteComponent>();
            _cellContainer   =
                ContainerManagerComponent.Ensure <ContainerSlot>("flashlight_cell_container", Owner, out var existed);

            if (!existed)
            {
                var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallHyper");
                _cellContainer.Insert(cell);
            }
        }
        public bool InsertMagazine(IEntity magazine, bool playSound = true)
        {
            if (!magazine.TryGetComponent(out BallisticMagazineComponent component))
            {
                throw new ArgumentException("Not a magazine", nameof(magazine));
            }

            if (!MagazineTypes.Contains(component.MagazineType))
            {
                throw new ArgumentException("Wrong magazine type", nameof(magazine));
            }

            if (component.Caliber != Caliber)
            {
                throw new ArgumentException("Wrong caliber", nameof(magazine));
            }

            if (!_magazineSlot.Insert(magazine))
            {
                return(false);
            }

            if (_magInSound != null)
            {
                Owner.GetComponent <SoundComponent>().Play(_magInSound);
            }

            component.OnAmmoCountChanged += _magazineAmmoCountChanged;
            if (GetChambered(0) == null)
            {
                // No bullet in chamber, load one from magazine.
                var bullet = component.TakeBullet();
                if (bullet != null)
                {
                    LoadIntoChamber(0, bullet);
                }
            }

            _updateAppearance();
            Dirty();
            return(true);
        }
        public bool TryInsertPowerCell(IEntity entity)
        {
            if (_powerCellContainer.ContainedEntity != null)
            {
                return(false);
            }

            if (!entity.HasComponent <BatteryComponent>())
            {
                return(false);
            }

            SoundSystem.Play(Filter.Pvs(Owner), _soundPowerCellInsert.GetSound(), Owner, AudioParams.Default.WithVolume(-2));

            _powerCellContainer.Insert(entity);

            Dirty();
            UpdateAppearance();
            return(true);
        }
        public override void Initialize()
        {
            base.Initialize();

            if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
            {
                _appearanceComponent = appearanceComponent;
            }

            _chamberContainer  = ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-chamber", Owner);
            _magazineContainer = ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-magazine", Owner, out var existing);

            if (!existing && _magFillPrototype != null)
            {
                var magEntity = Owner.EntityManager.SpawnEntity(_magFillPrototype, Owner.Transform.GridPosition);
                _magazineContainer.Insert(magEntity);
            }

            Dirty();
            UpdateAppearance();
        }
        protected override void Initialize()
        {
            base.Initialize();
            _powerCellContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, $"{Name}-powercell-container", out var existing);
            if (!existing && _powerCellPrototype != null)
            {
                var powerCellEntity = Owner.EntityManager.SpawnEntity(_powerCellPrototype, Owner.Transform.Coordinates);
                _powerCellContainer.Insert(powerCellEntity);
            }

            if (_ammoPrototype != null)
            {
                _ammoContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, $"{Name}-ammo-container");
            }

            if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
            {
                _appearanceComponent = appearanceComponent;
            }
            Dirty();
        }
示例#19
0
        /// <summary>
        /// Called when you click the owner entity with something in your active hand. If the entity in your hand
        /// contains a <see cref="SolutionComponent"/>, if you have hands, and if the dispenser doesn't already
        /// hold a container, it will be added to the dispenser.
        /// </summary>
        /// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
        /// <returns></returns>
        bool IAttackBy.AttackBy(AttackByEventArgs args)
        {
            if (!args.User.TryGetComponent(out IHandsComponent hands))
            {
                _notifyManager.PopupMessage(Owner.Transform.GridPosition, args.User,
                                            _localizationManager.GetString("You have no hands."));
                return(true);
            }

            var activeHandEntity = hands.GetActiveHand.Owner;

            if (activeHandEntity.TryGetComponent <SolutionComponent>(out var solution))
            {
                if (HasBeaker)
                {
                    _notifyManager.PopupMessage(Owner.Transform.GridPosition, args.User,
                                                _localizationManager.GetString("This dispenser already has a container in it."));
                }
                else if ((solution.Capabilities & SolutionCaps.FitsInDispenser) == 0)
                {
                    //If it can't fit in the dispenser, don't put it in. For example, buckets and mop buckets can't fit.
                    _notifyManager.PopupMessage(Owner.Transform.GridPosition, args.User,
                                                _localizationManager.GetString("That can't fit in the dispenser."));
                }
                else
                {
                    _beakerContainer.Insert(activeHandEntity);
                    Solution.SolutionChanged += HandleSolutionChangedEvent;
                    UpdateUserInterface();
                }
            }
            else
            {
                _notifyManager.PopupMessage(Owner.Transform.GridPosition, args.User,
                                            _localizationManager.GetString("You can't put this in the dispenser."));
            }

            return(true);
        }
        public override void Initialize()
        {
            base.Initialize();
            _powerCellContainer = ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-powercell-container", Owner, out var existing);
            if (!existing && _powerCellPrototype != null)
            {
                var powerCellEntity = Owner.EntityManager.SpawnEntity(_powerCellPrototype, Owner.Transform.GridPosition);
                _powerCellContainer.Insert(powerCellEntity);
            }

            if (_ammoPrototype != null)
            {
                _ammoContainer = ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-ammo-container", Owner);
            }

            if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
            {
                _appearanceComponent = appearanceComponent;
            }

            UpdateAppearance();
        }
        public bool TryInsertPowerCell(IEntity entity)
        {
            if (_powerCellContainer.ContainedEntity != null)
            {
                return(false);
            }

            if (!entity.HasComponent <BatteryComponent>())
            {
                return(false);
            }

            if (_soundPowerCellInsert != null)
            {
                EntitySystem.Get <AudioSystem>().PlayAtCoords(_soundPowerCellInsert, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
            }

            _powerCellContainer.Insert(entity);
            UpdateAppearance();
            //Dirty();
            return(true);
        }
示例#22
0
        private bool TryInsertPen(InteractUsingEventArgs eventArgs)
        {
            var item = eventArgs.Using;

            if (_penSlot.Contains(item))
            {
                return(false);
            }

            if (!eventArgs.User.TryGetComponent(out IHandsComponent? hands))
            {
                Owner.PopupMessage(eventArgs.User, Loc.GetString("You have no hands!"));
                return(true);
            }

            IEntity?swap = null;

            if (!PenSlotEmpty)
            {
                // Swap
                swap = _penSlot.ContainedEntities[0];
            }

            if (!hands.Drop(item))
            {
                return(true);
            }

            if (swap != null)
            {
                hands.PutInHand(swap.GetComponent <ItemComponent>());
            }

            // Insert Pen
            _penSlot.Insert(item);

            UpdatePDAUserInterface();
            return(true);
        }
        async Task <bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
        {
            if (!_entities.TryGetComponent(args.User, out HandsComponent? hands))
            {
                Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-no-hands-text"));
                return(true);
            }

            if (hands.GetActiveHandItem == null)
            {
                Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-nothing-in-hands-text"));
                return(false);
            }

            var activeHandEntity = hands.GetActiveHandItem.Owner;

            if (_entities.HasComponent <AMEFuelContainerComponent?>(activeHandEntity))
            {
                if (HasJar)
                {
                    Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-already-has-jar"));
                }

                else
                {
                    _jarSlot.Insert(activeHandEntity);
                    Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-success"));
                    UpdateUserInterface();
                }
            }
            else
            {
                Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-fail"));
            }

            return(true);
        }
示例#24
0
 public void InsertIdCard(IdCardComponent card)
 {
     _idSlot.Insert(card.Owner);
     ContainedID = card;
     EntitySystem.Get <AudioSystem>().PlayFromEntity("/Audio/Weapons/Guns/MagIn/batrifle_magin.ogg", Owner);
 }
        private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
        {
            if (obj.Message is not CloningPodUiButtonPressedMessage message || obj.Session.AttachedEntity == null)
            {
                return;
            }

            switch (message.Button)
            {
            case UiButton.Clone:
                if (BodyContainer.ContainedEntity != null)
                {
                    obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-occupied"));
                    return;
                }

                if (message.ScanId == null)
                {
                    obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-no-selection"));
                    return;
                }

                var cloningSystem = EntitySystem.Get <CloningSystem>();

                if (!cloningSystem.IdToDNA.TryGetValue(message.ScanId.Value, out var dna))
                {
                    obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-bad-selection"));
                    return;     // ScanId is not in database
                }

                var mind = dna.Mind;

                if (cloningSystem.ClonesWaitingForMind.TryGetValue(mind, out var clone))
                {
                    if (_entities.EntityExists(clone) &&
                        _entities.TryGetComponent <MobStateComponent?>(clone, out var cloneState) &&
                        !cloneState.IsDead() &&
                        _entities.TryGetComponent(clone, out MindComponent? cloneMindComp) &&
                        (cloneMindComp.Mind == null || cloneMindComp.Mind == mind))
                    {
                        obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-cloning"));
                        return;     // Mind already has clone
                    }

                    cloningSystem.ClonesWaitingForMind.Remove(mind);
                }

                if (mind.OwnedEntity != null &&
                    _entities.TryGetComponent <MobStateComponent?>(mind.OwnedEntity.Value, out var state) &&
                    !state.IsDead())
                {
                    obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-alive"));
                    return;     // Body controlled by mind is not dead
                }

                // Yes, we still need to track down the client because we need to open the Eui
                if (mind.UserId == null || !_playerManager.TryGetSessionById(mind.UserId.Value, out var client))
                {
                    obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-user-offline"));
                    return;     // If we can't track down the client, we can't offer transfer. That'd be quite bad.
                }

                var mob = _entities.SpawnEntity("MobHuman", _entities.GetComponent <TransformComponent>(Owner).MapPosition);


                EntitySystem.Get <SharedHumanoidAppearanceSystem>().UpdateFromProfile(mob, dna.Profile);
                _entities.GetComponent <MetaDataComponent>(mob).EntityName = dna.Profile.Name;

                var cloneMindReturn = _entities.AddComponent <BeingClonedComponent>(mob);
                cloneMindReturn.Mind   = mind;
                cloneMindReturn.Parent = Owner;

                BodyContainer.Insert(mob);
                CapturedMind = mind;
                cloningSystem.ClonesWaitingForMind.Add(mind, mob);

                UpdateStatus(CloningPodStatus.NoMind);

                var acceptMessage = new AcceptCloningEui(mind);
                _euiManager.OpenEui(acceptMessage, client);

                break;

            case UiButton.Eject:
                Eject();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public void InsertBody(IEntity user)
 {
     _bodyContainer.Insert(user);
     UpdateUserInterface();
     UpdateAppearance();
 }