public override void Initialize()
        {
            base.Initialize();

            _itemContainer =
                ContainerManagerComponent.Ensure <ContainerSlot>("flashlight_cell_container", Owner, out _);
        }
示例#2
0
        public void TestInsertion()
        {
            var owner     = EntityManager.SpawnEntity("dummy");
            var inserted  = EntityManager.SpawnEntity("dummy");
            var transform = inserted.Transform;

            var container = ContainerManagerComponent.Create <Container>("dummy", owner);

            Assert.That(container.Insert(inserted), Is.True);
            Assert.That(transform.Parent.Owner, Is.EqualTo(owner));

            var container2 = ContainerManagerComponent.Create <Container>("dummy", inserted);

            Assert.That(container2.Insert(owner), Is.False);

            var success = container.Remove(inserted);

            Assert.That(success, Is.True);

            success = container.Remove(inserted);
            Assert.That(success, Is.False);

            container.Insert(inserted);
            owner.Delete();
            // Make sure inserted was detached.
            Assert.That(transform.IsMapTransform, Is.True);
        }
示例#3
0
        public void TestCreation()
        {
            var entity = EntityManager.SpawnEntity("dummy");

            var container = ContainerManagerComponent.Create <Container>("dummy", entity);

            Assert.That(container.ID, Is.EqualTo("dummy"));
            Assert.That(container.Owner, Is.EqualTo(entity));

            var manager = entity.GetComponent <IContainerManager>();

            Assert.That(container.Manager, Is.EqualTo(manager));
            Assert.That(() => ContainerManagerComponent.Create <Container>("dummy", entity), Throws.ArgumentException);

            Assert.That(manager.HasContainer("dummy2"), Is.False);
            var container2 = ContainerManagerComponent.Create <Container>("dummy2", entity);

            Assert.That(container2.Manager, Is.EqualTo(manager));
            Assert.That(container2.Owner, Is.EqualTo(entity));
            Assert.That(container2.ID, Is.EqualTo("dummy2"));

            Assert.That(manager.HasContainer("dummy"), Is.True);
            Assert.That(manager.HasContainer("dummy2"), Is.True);
            Assert.That(manager.HasContainer("dummy3"), Is.False);

            Assert.That(manager.GetContainer("dummy"), Is.EqualTo(container));
            Assert.That(manager.GetContainer("dummy2"), Is.EqualTo(container2));
            Assert.That(() => manager.GetContainer("dummy3"), Throws.TypeOf <KeyNotFoundException>());

            entity.Delete();

            Assert.That(manager.Deleted, Is.True);
            Assert.That(container.Deleted, Is.True);
            Assert.That(container2.Deleted, Is.True);
        }
        public override void Initialize()
        {
            base.Initialize();

            // ReSharper disable once StringLiteralTypo
            _storage = ContainerManagerComponent.Ensure <Container>("storagebase", Owner);
        }
        public override void Initialize()
        {
            base.Initialize();
            _ammoContainer = ContainerManagerComponent.Ensure <Container>($"{Name}-magazine", Owner, out var existing);

            if (existing)
            {
                if (_ammoContainer.ContainedEntities.Count > Capacity)
                {
                    throw new InvalidOperationException("Initialized capacity of magazine higher than its actual capacity");
                }

                foreach (var entity in _ammoContainer.ContainedEntities)
                {
                    _spawnedAmmo.Push(entity);
                    _unspawnedCount--;
                }
            }

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

            _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
        }
示例#6
0
        public void TestNestedRemovalWithDenial()
        {
            var coordinates = new EntityCoordinates(new EntityUid(1), (0, 0));
            var entityOne   = EntityManager.SpawnEntity("dummy", coordinates);
            var entityTwo   = EntityManager.SpawnEntity("dummy", coordinates);
            var entityThree = EntityManager.SpawnEntity("dummy", coordinates);
            var entityItem  = EntityManager.SpawnEntity("dummy", coordinates);

            var container  = ContainerManagerComponent.Create <Container>("dummy", entityOne);
            var container2 = ContainerManagerComponent.Create <ContainerOnlyContainer>("dummy", entityTwo);
            var container3 = ContainerManagerComponent.Create <Container>("dummy", entityThree);

            Assert.That(container.Insert(entityTwo), Is.True);
            Assert.That(entityTwo.Transform.Parent !.Owner, Is.EqualTo(entityOne));

            Assert.That(container2.Insert(entityThree), Is.True);
            Assert.That(entityThree.Transform.Parent !.Owner, Is.EqualTo(entityTwo));

            Assert.That(container3.Insert(entityItem), Is.True);
            Assert.That(entityItem.Transform.Parent !.Owner, Is.EqualTo(entityThree));

            Assert.That(container3.Remove(entityItem), Is.True);
            Assert.That(container.Contains(entityItem), Is.True);
            Assert.That(entityItem.Transform.Parent !.Owner, Is.EqualTo(entityOne));

            entityOne.Delete();
            Assert.That(entityTwo.Transform.Deleted, Is.True);
        }
        public override void Initialize()
        {
            base.Initialize();
            _unspawnedCount = Capacity;
            int idx = 0;

            _ammoContainer = ContainerManagerComponent.Ensure <Container>($"{Name}-ammoContainer", Owner, out var existing);
            if (existing)
            {
                foreach (var entity in _ammoContainer.ContainedEntities)
                {
                    _unspawnedCount--;
                    _ammoSlots[idx] = entity;
                    idx++;
                }
            }

            for (var i = 0; i < _unspawnedCount; i++)
            {
                var entity = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.GridPosition);
                _ammoSlots[idx] = entity;
                _ammoContainer.Insert(entity);
                idx++;
            }

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

            UpdateAppearance();
            Dirty();
        }
示例#8
0
        public override void Initialize()
        {
            base.Initialize();

            _itemContainer =
                ContainerManagerComponent.Ensure <ContainerSlot>("potted_plant_hide", Owner, out _);
        }
        /// <summary>
        ///     Creates the corresponding computer board on the computer.
        ///     This exists so when you deconstruct computers that were serialized with the map,
        ///     you can retrieve the computer board.
        /// </summary>
        private void CreateComputerBoard()
        {
            // We don't do anything if this is null or empty.
            if (string.IsNullOrEmpty(_boardPrototype))
            {
                return;
            }

            var container = ContainerManagerComponent.Ensure <Container>("board", Owner, out var existed);

            if (existed)
            {
                // We already contain a board. Note: We don't check if it's the right one!
                if (container.ContainedEntities.Count != 0)
                {
                    return;
                }
            }

            var board = Owner.EntityManager.SpawnEntity(_boardPrototype, Owner.Transform.Coordinates);

            if (!container.Insert(board))
            {
                Logger.Warning($"Couldn't insert board {board} to computer {Owner}!");
            }
        }
        public override void Initialize()
        {
            base.Initialize();

            _ammoContainer =
                ContainerManagerComponent.Ensure <Container>($"{Name}-ammo-container", Owner, out var existing);

            if (existing)
            {
                foreach (var entity in _ammoContainer.ContainedEntities)
                {
                    _spawnedAmmo.Push(entity);
                    _unspawnedCount--;
                }
            }

            _chamberContainer =
                ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-chamber-container", Owner, out existing);
            if (existing)
            {
                _unspawnedCount--;
            }

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

            _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
            Dirty();
            UpdateAppearance();
        }
示例#11
0
        public override void Initialize()
        {
            base.Initialize();

            ItemContainer =
                ContainerManagerComponent.Ensure <ContainerSlot>("extinguisher_cabinet", Owner, out _);
        }
        public override void Initialize()
        {
            base.Initialize();

            _boardContainer = ContainerManagerComponent.Ensure <Container>(MachineFrameComponent.BoardContainer, Owner);
            _partContainer  = ContainerManagerComponent.Ensure <Container>(MachineFrameComponent.PartContainer, Owner);
        }
        public override void Startup()
        {
            base.Startup();

            _bulletContainer =
                ContainerManagerComponent.Ensure <Container>("magazine_bullet_container", Owner, out var existed);

            if (existed)
            {
                foreach (var entity in _bulletContainer.ContainedEntities)
                {
                    _loadedBullets.Push(entity);
                }
                _updateAppearance();
            }
            else if (_fillType != null)
            {
                // Load up bullets from fill.
                for (var i = 0; i < Capacity; i++)
                {
                    var bullet = Owner.EntityManager.SpawnEntity(_fillType);
                    AddBullet(bullet);
                }
            }

            OnAmmoCountChanged?.Invoke();
            _appearance.SetData(BallisticMagazineVisuals.AmmoCapacity, Capacity);
        }
示例#14
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();
        }
示例#15
0
        public override void Initialize()
        {
            base.Initialize();

            Owner.EnsureComponent <PowerReceiverComponent>();
            _container = ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-powerCellContainer", Owner);
            // Default state in the visualizer is OFF, so when this gets powered on during initialization it will generally show empty
        }
        public override void Initialize()
        {
            base.Initialize();

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

            _lightBulbContainer = ContainerManagerComponent.Ensure <ContainerSlot>("light_bulb", Owner);
        }
示例#17
0
 public override void Initialize()
 {
     base.Initialize();
     _appearance    = Owner.GetComponent <AppearanceComponent>();
     _userInterface = Owner.GetComponent <ServerUserInterfaceComponent>()
                      .GetBoundUserInterface(MedicalScannerUiKey.Key);
     _bodyContainer = ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-bodyContainer", Owner);
     UpdateUserInterface();
 }
示例#18
0
        public async Task PerformAction(IEntity entity, IEntity?user)
        {
            if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager))
            {
                Logger.Warning($"Computer entity {entity} did not have a container manager! Aborting build computer action.");
                return;
            }

            if (!containerManager.TryGetContainer(Container, out var container))
            {
                Logger.Warning($"Computer entity {entity} did not have the specified '{Container}' container! Aborting build computer action.");
                return;
            }

            if (container.ContainedEntities.Count != 1)
            {
                Logger.Warning($"Computer entity {entity} did not have exactly one item in the specified '{Container}' container! Aborting build computer action.");
            }

            var board = container.ContainedEntities[0];

            if (!board.TryGetComponent(out ComputerBoardComponent? boardComponent))
            {
                Logger.Warning($"Computer entity {entity} had an invalid entity in container \"{Container}\"! Aborting build computer action.");
                return;
            }

            var entityManager = entity.EntityManager;

            container.Remove(board);

            var computer = entityManager.SpawnEntity(boardComponent.Prototype, entity.Transform.Coordinates);

            computer.Transform.LocalRotation = entity.Transform.LocalRotation;

            var computerContainer = ContainerManagerComponent.Ensure <Container>(Container, computer, out var existed);

            if (existed)
            {
                // In case there are any entities inside this, delete them.
                foreach (var ent in computerContainer.ContainedEntities.ToArray())
                {
                    computerContainer.ForceRemove(ent);
                    ent.Delete();
                }
            }

            computerContainer.Insert(board);

            if (computer.TryGetComponent(out ConstructionComponent? construction))
            {
                // We only add this container. If some construction needs to take other containers into account, fix this.
                construction.AddContainer(Container);
            }

            entity.Delete();
        }
示例#19
0
 public override void Initialize()
 {
     base.Initialize();
     _powerReceiver       = Owner.GetComponent <PowerReceiverComponent>();
     _container           = ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-powerCellContainer", Owner);
     _appearanceComponent = Owner.GetComponent <AppearanceComponent>();
     // Default state in the visualizer is OFF, so when this gets powered on during initialization it will generally show empty
     _powerReceiver.OnPowerStateChanged += PowerUpdate;
 }
        /// <summary>
        ///     Adds a new slot to this inventory component.
        /// </summary>
        /// <param name="slot">The name of the slot to add.</param>
        /// <exception cref="InvalidOperationException">
        ///     Thrown if the slot with specified name already exists.
        /// </exception>
        public ContainerSlot AddSlot(Slots slot)
        {
            if (HasSlot(slot))
            {
                throw new InvalidOperationException($"Slot '{slot}' already exists.");
            }

            return(SlotContainers[slot] = ContainerManagerComponent.Create <ContainerSlot>(GetSlotString(slot), Owner));
        }
        public override void Initialize()
        {
            base.Initialize();

            Owner.EnsureComponent <PointLightComponent>();
            _cellContainer =
                ContainerManagerComponent.Ensure <ContainerSlot>("flashlight_cell_container", Owner, out _);

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

            _pointLight      = Owner.GetComponent <PointLightComponent>();
            _spriteComponent = Owner.GetComponent <SpriteComponent>();
            Owner.TryGetComponent(out _clothingComponent);
            _cellContainer =
                ContainerManagerComponent.Ensure <ContainerSlot>("flashlight_cell_container", Owner, out var existed);
        }
        public override void Initialize()
        {
            base.Initialize();

            _container = ContainerManagerComponent.Ensure <Container>(Name, Owner);

            Owner.EntityManager.EventBus.SubscribeEvent <HandCountChangedEvent>(EventSource.Local, this, HandleHandCountChange);

            Owner.EnsureComponentWarn <HandsComponent>();
        }
示例#24
0
        public override void Initialize()
        {
            base.Initialize();

            _chambers = new Chamber[ChamberCount];
            for (var i = 0; i < _chambers.Length; i++)
            {
                var container = ContainerManagerComponent.Ensure <ContainerSlot>($"ballistics_chamber_{i}", Owner);
                _chambers[i] = new Chamber(container);
            }
        }
示例#25
0
        /// <summary>
        /// Called once per instance of this component. Gets references to any other components needed
        /// by this component and initializes it's UI and other data.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            _userInterface = Owner.GetComponent <ServerUserInterfaceComponent>().GetBoundUserInterface(ReagentDispenserUiKey.Key);
            _userInterface.OnReceiveMessage += OnUiReceiveMessage;

            _beakerContainer = ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-reagentContainerContainer", Owner);

            InitializeFromPrototype();
            UpdateUserInterface();
        }
 /// <inheritdoc />
 protected override void Startup()
 {
     base.Startup();
     _magazineSlot = ContainerManagerComponent.Ensure <ContainerSlot>("ballistic_gun_magazine", Owner);
     if (Magazine != null)
     {
         // Already got magazine from loading a container.
         Magazine.GetComponent <BallisticMagazineComponent>().OnAmmoCountChanged += MagazineAmmoCountChanged;
     }
     UpdateAppearance();
 }
示例#27
0
        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);
        }
示例#28
0
        public override void Initialize()
        {
            base.Initialize();
            _ammoContainer = ContainerManagerComponent.Ensure <Container>($"{Name}-ammoContainer", Owner);

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

            _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
        }
示例#29
0
        public override void Initialize()
        {
            base.Initialize();

            _container     = ContainerManagerComponent.Ensure <Container>(Name, Owner);
            _interactRange = SharedInteractionSystem.InteractionRange / 2;

            if (!Owner.TryGetComponent(out _hands))
            {
                Logger.Warning("Player does not have an IHandsComponent!");
            }
        }
示例#30
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;
            }

            UpdatePDAAppearance();
        }