Exemple #1
0
        protected override void Initialize()
        {
            base.Initialize();

            Contents = ContainerHelpers.EnsureContainer <Container>(Owner, Name);
            Owner.EnsureComponent <AnchorableComponent>();
        }
Exemple #2
0
 /// <summary>
 ///     Ensure item slots have containers.
 /// </summary>
 private void Oninitialize(EntityUid uid, ItemSlotsComponent itemSlots, ComponentInit args)
 {
     foreach (var(id, slot) in itemSlots.Slots)
     {
         slot.ContainerSlot = ContainerHelpers.EnsureContainer <ContainerSlot>(itemSlots.Owner, id);
     }
 }
Exemple #3
0
        /// <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 = ContainerHelpers.EnsureContainer <Container>(Owner, "board", 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}!");
            }

            if (Owner.TryGetComponent(out ConstructionComponent construction))
            {
                construction.AddContainer("board");
            }
        }
Exemple #4
0
        public override void Initialize()
        {
            base.Initialize();
            _unspawnedCount = Capacity;
            int idx = 0;

            _ammoContainer = ContainerHelpers.EnsureContainer <Container>(Owner, $"{Name}-ammoContainer", 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.Coordinates);
                _ammoSlots[idx] = entity;
                _ammoContainer.Insert(entity);
                idx++;
            }

            UpdateAppearance();
            Dirty();
        }
Exemple #5
0
        public override void Initialize()
        {
            base.Initialize();

            _boardContainer = ContainerHelpers.EnsureContainer <Container>(Owner, MachineFrameComponent.BoardContainer);
            _partContainer  = ContainerHelpers.EnsureContainer <Container>(Owner, MachineFrameComponent.PartContainer);
        }
        public override void Initialize()
        {
            base.Initialize();

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

            _boardContainer = ContainerHelpers.EnsureContainer <Container>(Owner, BoardContainer);
            _partContainer  = ContainerHelpers.EnsureContainer <Container>(Owner, PartContainer);
        }
        public override void Initialize()
        {
            base.Initialize();

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

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

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

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

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

            Owner.EnsureComponent <PowerReceiverComponent>();
            _container = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, $"{Name}-powerCellContainer");
            // Default state in the visualizer is OFF, so when this gets powered on during initialization it will generally show empty
        }
        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 = ContainerHelpers.EnsureContainer <Container>(computer, Container, 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();
        }
Exemple #11
0
        /// <summary>
        ///     Given a new item slot, store it in the <see cref="ItemSlotsComponent"/> and ensure the slot has an item
        ///     container.
        /// </summary>
        public void AddItemSlot(EntityUid uid, string id, ItemSlot slot)
        {
            var itemSlots = EntityManager.EnsureComponent <ItemSlotsComponent>(uid);

            slot.ContainerSlot = ContainerHelpers.EnsureContainer <ContainerSlot>(itemSlots.Owner, id);
            if (itemSlots.Slots.ContainsKey(id))
            {
                Logger.Error($"Duplicate item slot key. Entity: {EntityManager.GetComponent<MetaDataComponent>(itemSlots.Owner).EntityName} ({uid}), key: {id}");
            }
            itemSlots.Slots[id] = slot;
        }
        private void OnComponentInit(EntityUid uid, SharedItemSlotsComponent itemSlots, ComponentInit args)
        {
            // create container for each slot
            foreach (var pair in itemSlots.Slots)
            {
                var slotName = pair.Key;
                var slot     = pair.Value;

                slot.ContainerSlot = ContainerHelpers.EnsureContainer <ContainerSlot>(itemSlots.Owner, slotName);
            }
        }
        private void OnInit(EntityUid uid, SecretStashComponent component, ComponentInit args)
        {
            // set default secret part name
            if (component.SecretPartName == "")
            {
                var meta       = EntityManager.GetComponent <MetaDataComponent>(uid);
                var entityName = Loc.GetString("comp-secret-stash-secret-part-name", ("name", meta.EntityName));
                component.SecretPartName = entityName;
            }

            component.ItemContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(uid, "stash", out _);
        }
        protected override void Initialize()
        {
            base.Initialize();
            _idSlot  = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, "pda_entity_container");
            _penSlot = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, "pda_pen_slot");

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

            UpdatePDAAppearance();
        }
Exemple #15
0
        public override void Initialize()
        {
            base.Initialize();
            _ammoContainer = ContainerHelpers.EnsureContainer <Container>(Owner, $"{Name}-container", out var existing);

            if (existing)
            {
                foreach (var ammo in _ammoContainer.ContainedEntities)
                {
                    _unspawnedCount--;
                    _spawnedAmmo.Push(ammo);
                }
            }
        }
Exemple #16
0
        protected override void Initialize()
        {
            base.Initialize();

            _currentCookTimerTime = _cookTimeDefault;

            _storage = ContainerHelpers.EnsureContainer <Container>(Owner, "microwave_entity_container",
                                                                    out _);

            if (UserInterface != null)
            {
                UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
            }
        }
        protected override void Initialize()
        {
            base.Initialize();

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

            BodyContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, $"{Name}-bodyContainer");

            //TODO: write this so that it checks for a change in power events for GORE POD cases
            EntitySystem.Get <CloningSystem>().UpdateUserInterface(this);
        }
        protected override void Initialize()
        {
            base.Initialize();

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

            _entities.TryGetComponent(Owner, out _appearance);

            _entities.TryGetComponent(Owner, out _powerSupplier);

            _injecting      = false;
            InjectionAmount = 2;
            _jarSlot        = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, $"{Name}-fuelJarContainer");
        }
        public override void Initialize()
        {
            base.Initialize();

            _privilegedIdContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, $"{Name}-privilegedId");
            _targetIdContainer     = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, $"{Name}-targetId");

            Owner.EnsureComponentWarn <AccessReader>();
            Owner.EnsureComponentWarn <ServerUserInterfaceComponent>();

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

            UpdateUserInterface();
        }
Exemple #20
0
        protected override void Initialize()
        {
            base.Initialize();

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

            _bodyContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, $"{Name}-bodyContainer");

            // TODO: write this so that it checks for a change in power events and acts accordingly.
            var newState = GetUserInterfaceState();

            UserInterface?.SetState(newState);

            UpdateUserInterface();
        }
        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();
        }
Exemple #22
0
        public override void Initialize()
        {
            base.Initialize();

            _partContainer = ContainerHelpers.EnsureContainer <Container>(Owner, $"{Name}-{nameof(BodyComponent)}");

            foreach (var(slot, partId) in PartIds)
            {
                // Using MapPosition instead of Coordinates here prevents
                // a crash within the character preview menu in the lobby
                var entity = Owner.EntityManager.SpawnEntity(partId, Owner.Transform.MapPosition);

                if (!entity.TryGetComponent(out IBodyPart? part))
                {
                    Logger.Error($"Entity {partId} does not have a {nameof(IBodyPart)} component.");
                    continue;
                }

                TryAddPart(slot, part, true);
            }
        }
Exemple #23
0
 protected override void Initialize()
 {
     base.Initialize();
     _cellContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, "cellslot_cell_container", out _);
 }
Exemple #24
0
 protected override void Initialize()
 {
     base.Initialize();
     _itemContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, "stash", out _);
 }
Exemple #25
0
        public override void Initialize()
        {
            base.Initialize();

            _lightBulbContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, "light_bulb");
        }
        public async Task InsideContainerInteractionBlockTest()
        {
            var server = StartServerDummyTicker(new ServerContentIntegrationOption
            {
                ContentBeforeIoC = () =>
                {
                    IoCManager.Resolve <IEntitySystemManager>().LoadExtraSystemType <TestInteractionSystem>();
                },
                FailureLogLevel = Robust.Shared.Log.LogLevel.Error
            });

            await server.WaitIdleAsync();

            var entityManager = server.ResolveDependency <IEntityManager>();
            var mapManager    = server.ResolveDependency <IMapManager>();

            var mapId  = MapId.Nullspace;
            var coords = MapCoordinates.Nullspace;

            server.Assert(() =>
            {
                mapId  = mapManager.CreateMap();
                coords = new MapCoordinates(Vector2.Zero, mapId);
            });

            await server.WaitIdleAsync();

            IEntity    user            = null;
            IEntity    target          = null;
            IEntity    item            = null;
            IEntity    containerEntity = null;
            IContainer container       = null;

            server.Assert(() =>
            {
                user = entityManager.SpawnEntity(null, coords);
                user.EnsureComponent <HandsComponent>().AddHand("hand", HandLocation.Left);
                target = entityManager.SpawnEntity(null, coords);
                item   = entityManager.SpawnEntity(null, coords);
                item.EnsureComponent <ItemComponent>();
                containerEntity = entityManager.SpawnEntity(null, coords);
                container       = ContainerHelpers.EnsureContainer <Container>(containerEntity, "InteractionTestContainer");
            });

            await server.WaitRunTicks(1);

            var entitySystemManager = server.ResolveDependency <IEntitySystemManager>();

            Assert.That(entitySystemManager.TryGetEntitySystem <InteractionSystem>(out var interactionSystem));
            Assert.That(entitySystemManager.TryGetEntitySystem <TestInteractionSystem>(out var testInteractionSystem));

            await server.WaitIdleAsync();

            var attack        = false;
            var interactUsing = false;
            var interactHand  = false;

            server.Assert(() =>
            {
                Assert.That(container.Insert(user));
                Assert.That(user.Transform.Parent.Owner, Is.EqualTo(containerEntity));

                testInteractionSystem.AttackEvent        = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity.Uid)); attack = true; };
                testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); interactUsing = true; };
                testInteractionSystem.InteractHandEvent  = (ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); interactHand = true; };

                interactionSystem.DoAttack(user, target.Transform.Coordinates, false, target.Uid);
                interactionSystem.UserInteraction(user, target.Transform.Coordinates, target.Uid);
                Assert.That(attack, Is.False);
                Assert.That(interactUsing, Is.False);
                Assert.That(interactHand, Is.False);

                interactionSystem.DoAttack(user, containerEntity.Transform.Coordinates, false, containerEntity.Uid);
                interactionSystem.UserInteraction(user, containerEntity.Transform.Coordinates, containerEntity.Uid);
                Assert.That(attack);
                Assert.That(interactUsing, Is.False);
                Assert.That(interactHand);

                Assert.That(user.TryGetComponent <HandsComponent>(out var hands));
                Assert.That(hands.PutInHand(item.GetComponent <ItemComponent>()));

                interactionSystem.UserInteraction(user, target.Transform.Coordinates, target.Uid);
                Assert.That(interactUsing, Is.False);

                interactionSystem.UserInteraction(user, containerEntity.Transform.Coordinates, containerEntity.Uid);
                Assert.That(interactUsing, Is.True);
            });

            await server.WaitIdleAsync();
        }
 public override void Initialize()
 {
     base.Initialize();
     Appearance?.SetData(MorgueVisuals.Open, false);
     TrayContainer = ContainerHelpers.EnsureContainer <ContainerSlot>(Owner, "morgue_tray", out _);
 }
 private void OnInit(EntityUid uid, LightReplacerComponent replacer, ComponentInit args)
 {
     replacer.InsertedBulbs = ContainerHelpers.EnsureContainer <Container>(replacer.Owner, "light_replacer_storage");
 }
Exemple #29
0
        public async Task PerformAction(IEntity entity, IEntity?user)
        {
            if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager))
            {
                Logger.Warning($"Machine frame entity {entity} did not have a container manager! Aborting build machine action.");
                return;
            }

            if (!entity.TryGetComponent(out MachineFrameComponent? machineFrame))
            {
                Logger.Warning($"Machine frame entity {entity} did not have a machine frame component! Aborting build machine action.");
                return;
            }

            if (!machineFrame.IsComplete)
            {
                Logger.Warning($"Machine frame entity {entity} doesn't have all required parts to be built! Aborting build machine action.");
                return;
            }

            if (!containerManager.TryGetContainer(MachineFrameComponent.BoardContainer, out var entBoardContainer))
            {
                Logger.Warning($"Machine frame entity {entity} did not have the '{MachineFrameComponent.BoardContainer}' container! Aborting build machine action.");
                return;
            }

            if (!containerManager.TryGetContainer(MachineFrameComponent.PartContainer, out var entPartContainer))
            {
                Logger.Warning($"Machine frame entity {entity} did not have the '{MachineFrameComponent.PartContainer}' container! Aborting build machine action.");
                return;
            }

            if (entBoardContainer.ContainedEntities.Count != 1)
            {
                Logger.Warning($"Machine frame entity {entity} did not have exactly one item in the '{MachineFrameComponent.BoardContainer}' container! Aborting build machine action.");
            }

            var board = entBoardContainer.ContainedEntities[0];

            if (!board.TryGetComponent(out MachineBoardComponent? boardComponent))
            {
                Logger.Warning($"Machine frame entity {entity} had an invalid entity in container \"{MachineFrameComponent.BoardContainer}\"! Aborting build machine action.");
                return;
            }

            var entityManager = entity.EntityManager;

            entBoardContainer.Remove(board);

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

            machine.Transform.LocalRotation = entity.Transform.LocalRotation;

            var boardContainer = ContainerHelpers.EnsureContainer <Container>(machine, MachineFrameComponent.BoardContainer, out var existed);

            if (existed)
            {
                // Clean that up...
                boardContainer.CleanContainer();
            }

            var partContainer = ContainerHelpers.EnsureContainer <Container>(machine, MachineFrameComponent.PartContainer, out existed);

            if (existed)
            {
                // Clean that up, too...
                partContainer.CleanContainer();
            }

            boardContainer.Insert(board);

            // Now we insert all parts.
            foreach (var part in entPartContainer.ContainedEntities.ToArray())
            {
                entPartContainer.ForceRemove(part);
                partContainer.Insert(part);
            }

            if (machine.TryGetComponent(out ConstructionComponent? construction))
            {
                // We only add these two container. If some construction needs to take other containers into account, fix this.
                construction.AddContainer(MachineFrameComponent.BoardContainer);
                construction.AddContainer(MachineFrameComponent.PartContainer);
            }

            if (machine.TryGetComponent(out MachineComponent? machineComp))
            {
                machineComp.RefreshParts();
            }

            entity.Delete();
        }
Exemple #30
0
        protected override void Initialize()
        {
            base.Initialize();

            _grenadesContainer = ContainerHelpers.EnsureContainer <Container>(Owner, "cluster-flash");
        }