コード例 #1
0
        private bool HandleThrowItem(ICommonSession?session, EntityCoordinates coords, EntityUid uid)
        {
            if (session is not IPlayerSession playerSession)
            {
                return(false);
            }

            var playerEnt = playerSession.AttachedEntity;

            if (playerEnt == null || !playerEnt.IsValid() || !playerEnt.TryGetComponent(out SharedHandsComponent? hands))
            {
                return(false);
            }

            if (!hands.TryGetActiveHeldEntity(out var throwEnt))
            {
                return(false);
            }

            if (!_interactionSystem.TryThrowInteraction(hands.Owner, throwEnt))
            {
                return(false);
            }

            if (throwEnt.TryGetComponent(out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
            {
                var splitStack = _stackSystem.Split(throwEnt.Uid, stack, 1, playerEnt.Transform.Coordinates);

                if (splitStack == null)
                {
                    return(false);
                }

                throwEnt = splitStack;
            }
コード例 #2
0
        private bool HandleThrowItem(ICommonSession?session, EntityCoordinates coords, EntityUid uid)
        {
            if (session is not IPlayerSession playerSession)
            {
                return(false);
            }

            if (playerSession.AttachedEntity is not {
                Valid : true
            } player ||
                !Exists(player) ||
                player.IsInContainer() ||
                !TryComp(player, out SharedHandsComponent? hands) ||
                hands.ActiveHandEntity is not EntityUid throwEnt ||
                !_actionBlockerSystem.CanThrow(player))
            {
                return(false);
            }

            if (EntityManager.TryGetComponent(throwEnt, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
            {
                var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent <TransformComponent>(player).Coordinates, stack);

                if (splitStack is not {
                    Valid : true
                })
コード例 #3
0
    private void OnInteractUsing(EntityUid uid, MachineFrameComponent component, InteractUsingEvent args)
    {
        if (!component.HasBoard && TryComp <MachineBoardComponent?>(args.Used, out var machineBoard))
        {
            if (args.Used.TryRemoveFromContainer())
            {
                // Valid board!
                component.BoardContainer.Insert(args.Used);

                // Setup requirements and progress...
                ResetProgressAndRequirements(component, machineBoard);

                if (TryComp <AppearanceComponent?>(uid, out var appearance))
                {
                    appearance.SetData(MachineFrameVisuals.State, 2);
                }

                if (TryComp(uid, out ConstructionComponent? construction))
                {
                    // So prying the components off works correctly.
                    _construction.ResetEdge(uid, construction);
                }
            }
        }
        else if (component.HasBoard)
        {
            if (TryComp <MachinePartComponent>(args.Used, out var machinePart))
            {
                if (!component.Requirements.ContainsKey(machinePart.PartType))
                {
                    return;
                }

                if (component.Progress[machinePart.PartType] != component.Requirements[machinePart.PartType] &&
                    args.Used.TryRemoveFromContainer() && component.PartContainer.Insert(args.Used))
                {
                    component.Progress[machinePart.PartType]++;
                    args.Handled = true;
                    return;
                }
            }

            if (TryComp <StackComponent?>(args.Used, out var stack))
            {
                var type = stack.StackTypeId;
                if (!component.MaterialRequirements.ContainsKey(type))
                {
                    return;
                }

                if (component.MaterialProgress[type] == component.MaterialRequirements[type])
                {
                    return;
                }

                var needed = component.MaterialRequirements[type] - component.MaterialProgress[type];
                var count  = stack.Count;

                if (count < needed)
                {
                    if (!component.PartContainer.Insert(stack.Owner))
                    {
                        return;
                    }

                    component.MaterialProgress[type] += count;
                    args.Handled = true;
                    return;
                }

                var splitStack = _stack.Split(args.Used, needed,
                                              Comp <TransformComponent>(uid).Coordinates, stack);

                if (splitStack == null)
                {
                    return;
                }

                if (!component.PartContainer.Insert(splitStack.Value))
                {
                    return;
                }

                component.MaterialProgress[type] += needed;
                args.Handled = true;
                return;
            }

            foreach (var(compName, info) in component.ComponentRequirements)
            {
                if (component.ComponentProgress[compName] >= info.Amount)
                {
                    continue;
                }

                var registration = _factory.GetRegistration(compName);

                if (!HasComp(args.Used, registration.Type))
                {
                    continue;
                }

                if (!args.Used.TryRemoveFromContainer() || !component.PartContainer.Insert(args.Used))
                {
                    continue;
                }
                component.ComponentProgress[compName]++;
                args.Handled = true;
                return;
            }

            foreach (var(tagName, info) in component.TagRequirements)
            {
                if (component.TagProgress[tagName] >= info.Amount)
                {
                    continue;
                }

                if (!_tag.HasTag(args.Used, tagName))
                {
                    continue;
                }

                if (!args.Used.TryRemoveFromContainer() || !component.PartContainer.Insert(args.Used))
                {
                    continue;
                }
                component.TagProgress[tagName]++;
                args.Handled = true;
                return;
            }
        }
    }