コード例 #1
0
    private void OnPumpInit(EntityUid uid, PumpBarrelComponent component, ComponentInit args)
    {
        component.AmmoContainer =
            uid.EnsureContainer <Container>($"{component.GetType()}-ammo-container", out var existing);

        if (existing)
        {
            foreach (var entity in component.AmmoContainer.ContainedEntities)
            {
                component.SpawnedAmmo.Push(entity);
                component.UnspawnedCount--;
            }
        }

        component.ChamberContainer =
            uid.EnsureContainer <ContainerSlot>($"{component.GetType()}-chamber-container", out existing);

        if (existing)
        {
            component.UnspawnedCount--;
        }

        if (TryComp(uid, out AppearanceComponent? appearanceComponent))
        {
            appearanceComponent.SetData(MagazineBarrelVisuals.MagLoaded, true);
        }

        component.Dirty(EntityManager);
        UpdatePumpAppearance(component);
    }
コード例 #2
0
    private void OnMagazineInit(EntityUid uid, MagazineBarrelComponent component, ComponentInit args)
    {
        component.ChamberContainer  = uid.EnsureContainer <ContainerSlot>($"{component.GetType()}-chamber");
        component.MagazineContainer = uid.EnsureContainer <ContainerSlot>($"{component.GetType()}-magazine", out var existing);

        if (!existing && component.MagFillPrototype != null)
        {
            var magEntity = EntityManager.SpawnEntity(component.MagFillPrototype, Transform(uid).Coordinates);
            component.MagazineContainer.Insert(magEntity);
        }

        // Temporary coz client doesn't know about magfill.
        component.Dirty(EntityManager);
    }
コード例 #3
0
        private void OnCanisterInteractUsing(EntityUid canister, GasCanisterComponent component, InteractUsingEvent args)
        {
            var container = canister.EnsureContainer <ContainerSlot>(component.ContainerName);

            // Container full.
            if (container.ContainedEntity != null)
            {
                return;
            }

            // Check the used item is valid...
            if (!EntityManager.TryGetComponent(args.Used, out GasTankComponent? _))
            {
                return;
            }

            if (!_handsSystem.TryDropIntoContainer(args.User, args.Used, container))
            {
                return;
            }

            _adminLogger.Add(LogType.CanisterTankInserted, LogImpact.Medium, $"Player {ToPrettyString(args.User):player} inserted tank {ToPrettyString(container.ContainedEntities[0]):tank} into {ToPrettyString(canister):canister}");

            args.Handled = true;
        }
コード例 #4
0
    private void OnBatteryInit(EntityUid uid, BatteryBarrelComponent component, ComponentInit args)
    {
        if (component.AmmoPrototype != null)
        {
            component.AmmoContainer = uid.EnsureContainer <ContainerSlot>($"{component.GetType()}-ammo-container");
        }

        component.Dirty(EntityManager);
    }
コード例 #5
0
    private void OnSpeedLoaderInit(EntityUid uid, SpeedLoaderComponent component, ComponentInit args)
    {
        component.AmmoContainer = uid.EnsureContainer <Container>($"{component.GetType()}-container", out var existing);

        if (existing)
        {
            foreach (var ammo in component.AmmoContainer.ContainedEntities)
            {
                component.UnspawnedCount--;
                component.SpawnedAmmo.Push(ammo);
            }
        }
    }
コード例 #6
0
    private void OnAmmoBoxInit(EntityUid uid, AmmoBoxComponent component, ComponentInit args)
    {
        component.AmmoContainer = uid.EnsureContainer <Container>($"{component.Name}-container", out var existing);

        if (existing)
        {
            foreach (var entity in component.AmmoContainer.ContainedEntities)
            {
                component.UnspawnedCount--;
                component.SpawnedAmmo.Push(entity);
                component.AmmoContainer.Insert(entity);
            }
        }
    }
コード例 #7
0
    private void OnRangedMagInit(EntityUid uid, RangedMagazineComponent component, ComponentInit args)
    {
        component.AmmoContainer = uid.EnsureContainer <Container>($"{component.GetType()}-magazine", out var existing);

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

            foreach (var entity in component.AmmoContainer.ContainedEntities)
            {
                component.SpawnedAmmo.Push(entity);
                component.UnspawnedCount--;
            }
        }

        if (TryComp(component.Owner, out AppearanceComponent? appearanceComponent))
        {
            appearanceComponent.SetData(MagazineBarrelVisuals.MagLoaded, true);
        }
    }
コード例 #8
0
        private void OnCanisterInteractUsing(EntityUid canister, GasCanisterComponent component, InteractUsingEvent args)
        {
            var container = canister.EnsureContainer <ContainerSlot>(component.ContainerName);

            // Container full.
            if (container.ContainedEntity != null)
            {
                return;
            }

            // Check the used item is valid...
            if (!EntityManager.TryGetComponent(args.Used, out GasTankComponent? _))
            {
                return;
            }

            // Check the user has hands.
            if (!EntityManager.TryGetComponent(args.User, out HandsComponent? hands))
            {
                return;
            }

            if (!args.User.InRangeUnobstructed(canister, SharedInteractionSystem.InteractionRange, popup: true))
            {
                return;
            }

            if (!hands.Drop(args.Used, container))
            {
                return;
            }

            _adminLogSystem.Add(LogType.CanisterTankInserted, LogImpact.Medium, $"Player {args.User:player} inserted tank {container.ContainedEntities[0]} into {canister}");

            args.Handled = true;
        }
コード例 #9
0
        public async Task InsideContainerInteractionBlockTest()
        {
            var server = StartServer(new ServerContentIntegrationOption
            {
                ContentBeforeIoC = () =>
                {
                    IoCManager.Resolve <IEntitySystemManager>().LoadExtraSystemType <TestInteractionSystem>();
                },
                FailureLogLevel = Robust.Shared.Log.LogLevel.Error
            });

            await server.WaitIdleAsync();

            var sEntities  = 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();

            EntityUid  user            = default;
            EntityUid  target          = default;
            EntityUid  item            = default;
            EntityUid  containerEntity = default;
            IContainer container       = null;

            server.Assert(() =>
            {
                user = sEntities.SpawnEntity(null, coords);
                user.EnsureComponent <HandsComponent>().AddHand("hand", HandLocation.Left);
                target = sEntities.SpawnEntity(null, coords);
                item   = sEntities.SpawnEntity(null, coords);
                item.EnsureComponent <ItemComponent>();
                containerEntity = sEntities.SpawnEntity(null, coords);
                container       = containerEntity.EnsureContainer <Container>("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(sEntities.GetComponent <TransformComponent>(user).Parent.Owner, Is.EqualTo(containerEntity));

                testInteractionSystem.AttackEvent        = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); 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, sEntities.GetComponent <TransformComponent>(target).Coordinates, false, target);
                interactionSystem.UserInteraction(user, sEntities.GetComponent <TransformComponent>(target).Coordinates, target);
                Assert.That(attack, Is.False);
                Assert.That(interactUsing, Is.False);
                Assert.That(interactHand, Is.False);

                interactionSystem.DoAttack(user, sEntities.GetComponent <TransformComponent>(containerEntity).Coordinates, false, containerEntity);
                interactionSystem.UserInteraction(user, sEntities.GetComponent <TransformComponent>(containerEntity).Coordinates, containerEntity);
                Assert.That(attack);
                Assert.That(interactUsing, Is.False);
                Assert.That(interactHand);

                Assert.That(sEntities.TryGetComponent <HandsComponent?>(user, out var hands));
                Assert.That(hands.PutInHand(sEntities.GetComponent <SharedItemComponent>(item)));

                interactionSystem.UserInteraction(user, sEntities.GetComponent <TransformComponent>(target).Coordinates, target);
                Assert.That(interactUsing, Is.False);

                interactionSystem.UserInteraction(user, sEntities.GetComponent <TransformComponent>(containerEntity).Coordinates, containerEntity);
                Assert.That(interactUsing, Is.True);
            });

            await server.WaitIdleAsync();
        }
コード例 #10
0
 private void OnHostInit(EntityUid uid, GuardianHostComponent component, ComponentInit args)
 {
     component.GuardianContainer = uid.EnsureContainer <ContainerSlot>("GuardianContainer");
     _actionSystem.AddAction(uid, component.Action, null);
 }
コード例 #11
0
 private void OnHostInit(EntityUid uid, GuardianHostComponent component, ComponentInit args)
 {
     component.GuardianContainer = uid.EnsureContainer <ContainerSlot>("GuardianContainer");
 }
コード例 #12
0
        public async Task InsideContainerInteractionBlockTest()
        {
            await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true });

            var server = pairTracker.Pair.Server;

            var sEntities  = server.ResolveDependency <IEntityManager>();
            var mapManager = server.ResolveDependency <IMapManager>();
            var sysMan     = server.ResolveDependency <IEntitySystemManager>();
            var handSys    = sysMan.GetEntitySystem <SharedHandsSystem>();

            var mapId  = MapId.Nullspace;
            var coords = MapCoordinates.Nullspace;
            await server.WaitAssertion(() =>
            {
                mapId  = mapManager.CreateMap();
                coords = new MapCoordinates(Vector2.Zero, mapId);
            });

            await server.WaitIdleAsync();

            EntityUid  user            = default;
            EntityUid  target          = default;
            EntityUid  item            = default;
            EntityUid  containerEntity = default;
            IContainer container       = null;

            await server.WaitAssertion(() =>
            {
                user = sEntities.SpawnEntity(null, coords);
                user.EnsureComponent <HandsComponent>();
                handSys.AddHand(user, "hand", HandLocation.Left);
                target = sEntities.SpawnEntity(null, coords);
                item   = sEntities.SpawnEntity(null, coords);
                item.EnsureComponent <ItemComponent>();
                containerEntity = sEntities.SpawnEntity(null, coords);
                container       = containerEntity.EnsureContainer <Container>("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;
            await server.WaitAssertion(() =>
            {
                Assert.That(container.Insert(user));
                Assert.That(sEntities.GetComponent <TransformComponent>(user).Parent.Owner, Is.EqualTo(containerEntity));

                testInteractionSystem.AttackEvent        = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); 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, sEntities.GetComponent <TransformComponent>(target).Coordinates, false, target);
                interactionSystem.UserInteraction(user, sEntities.GetComponent <TransformComponent>(target).Coordinates, target);
                Assert.That(attack, Is.False);
                Assert.That(interactUsing, Is.False);
                Assert.That(interactHand, Is.False);

                interactionSystem.DoAttack(user, sEntities.GetComponent <TransformComponent>(containerEntity).Coordinates, false, containerEntity);
                interactionSystem.UserInteraction(user, sEntities.GetComponent <TransformComponent>(containerEntity).Coordinates, containerEntity);
                Assert.That(attack);
                Assert.That(interactUsing, Is.False);
                Assert.That(interactHand);

                Assert.That(handSys.TryPickup(user, item));

                interactionSystem.UserInteraction(user, sEntities.GetComponent <TransformComponent>(target).Coordinates, target);
                Assert.That(interactUsing, Is.False);

                interactionSystem.UserInteraction(user, sEntities.GetComponent <TransformComponent>(containerEntity).Coordinates, containerEntity);
                Assert.That(interactUsing, Is.True);
            });

            await pairTracker.CleanReturnAsync();
        }