Ejemplo n.º 1
0
        public void RelocateItems(Character character, Character issuer, IEnumerable <Item> items, Container targetContainer)
        {
            var itemArray = items.ToArray();

            if (itemArray.Length == 1)
            {
                RelocateItem(character, issuer.Eid, itemArray[0], targetContainer);
            }
            else
            {
                using (var n = new ItemErrorNotifier(true))
                {
                    foreach (var item in itemArray)
                    {
                        try
                        {
                            RelocateItem(character, issuer.Eid, item, targetContainer);
                        }
                        catch (PerpetuumException gex)
                        {
                            n.AddError(item, gex);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void TrashItems(Character issuerCharacter, IEnumerable <long> target)
        {
            var trashableItems = GetItems(target).Where(i => i.IsTrashable).ToList();

            using (var n = new ItemErrorNotifier(true))
            {
                foreach (var item in trashableItems)
                {
                    try
                    {
                        //selected robot now allowed
                        issuerCharacter.IsRobotSelectedForCharacter(item as Robot).ThrowIfTrue(ErrorCodes.RobotMustBeDeselected);

                        RemoveItemOrThrow(item);
                        Repository.Delete(item);

                        AddLogEntry(issuerCharacter, ContainerAccess.Delete, item.Definition, item.Quantity);
                        var b = TransactionLogEvent.Builder()
                                .SetTransactionType(TransactionType.TrashItem)
                                .SetCharacter(issuerCharacter)
                                .SetContainer(this)
                                .SetItem(item.Definition, item.Quantity);
                        issuerCharacter.LogTransaction(b);
                    }
                    catch (PerpetuumException gex)
                    {
                        Logger.Error("Failed to delete item:" + item.Eid + " " + item.ED.Name + " owner:" + item.Owner + " issuerCharacter:" + issuerCharacter.Id);
                        n.AddError(item, gex);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character          = request.Session.Character;
                var targetEid          = request.Data.GetOrDefault <long>(k.eid);
                var includeRobotCargos = request.Data.GetOrDefault <int>(k.inventory) == 1;
                var containerEid       = request.Data.GetOrDefault <long>(k.container);

                character.IsDocked.ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked);

                var container = Container.GetWithItems(containerEid, character, ContainerAccess.Remove);

                var targetItem = container.GetItemOrThrow(targetEid, true);
                targetItem.ED.AttributeFlags.AlwaysStackable.ThrowIfFalse(ErrorCodes.OnlyAlwaysStackableIsSupported);
                var parentContainerOfTarget = targetItem.GetOrLoadParentEntity().ThrowIfNotType <Container>(ErrorCodes.WTFErrorMedicalAttentionSuggested);
                parentContainerOfTarget.CheckAccessAndThrowIfFailed(character, ContainerAccess.Delete);

                //only from container and infinite box
                parentContainerOfTarget.IsCategory(CategoryFlags.cf_infinite_capacity_containers).ThrowIfFalse(ErrorCodes.ContainerHasToBeInfinite);

                var quantitySum = 0;
                using (var notifier = new ItemErrorNotifier(true))
                {
                    foreach (var item in container.GetItems(true))
                    {
                        try
                        {
                            if (item.Definition != targetItem.Definition || item.Eid == targetItem.Eid)
                            {
                                continue;
                            }

                            //get the parent of the current item
                            var currentParent = item.GetOrLoadParentEntity() as Container;
                            if (currentParent == null)
                            {
                                continue;
                            }

                            if (!includeRobotCargos)
                            {
                                if (currentParent is RobotInventory)
                                {
                                    //skip items in any robotcargo
                                    continue;
                                }
                            }

                            if (currentParent is VolumeWrapperContainer)
                            {
                                currentParent.CheckAccessAndThrowIfFailed(character, ContainerAccess.Delete);
                            }

                            quantitySum += item.Quantity;
                            Entity.Repository.Delete(item);
                        }
                        catch (PerpetuumException gex)
                        {
                            notifier.AddError(item, gex);
                        }
                    }
                }

                targetItem.Quantity += quantitySum;
                container.Save();

                Message.Builder.SetCommand(Commands.ListContainer).WithData(container.ToDictionary()).ToClient(request.Session).Send();

                scope.Complete();
            }
        }