Example #1
0
        /// <summary>
        /// Drops all currently picked entities to the real world
        /// </summary>
        public void DropToWorld()
        {
            if (!_pendingOperation)
            {
                throw new InvalidOperationException("Unable to put item without taking it first");
            }

            var srcPosition = _tempSlot.GridPosition;

            if (_sourceContainer is CharacterEquipment)
            {
                srcPosition.X = -1;
            }

            _server.ServerConnection.Send(new ItemTransferMessage
            {
                SourceContainerEntityLink = _sourceContainer.Parent.GetLink(),
                SourceContainerSlot       = srcPosition,
                ItemsCount   = _tempSlot.ItemsCount,
                ItemEntityId = _tempSlot.Item.StaticId,
                DestinationContainerEntityLink = EntityLink.Empty
            });

            _sourceContainer  = null;
            _pendingOperation = false;
        }
Example #2
0
 public static bool IsSlotAvailable <TSlot, TItem>(
     [NotNull] this ISlotContainer <TSlot, TItem> container,
     [NotNull] string slot)
     where TSlot : ISlot
     where TItem : Node, ISlotItem
 {
     return(OccupiedSlots(container).FirstOrDefault(s => s == slot) == null);
 }
Example #3
0
 public static bool IsSlotAvailable<TSlot, TItem>(
     this ISlotContainer<TSlot, TItem> container,
     string slot)
     where TSlot : ISlot
     where TItem : class, ISlotItem
 {
     return OccupiedSlots(container).Exists(s => s == slot);
 }
Example #4
0
            public static IEnumerable <string> OccupiedSlots <TSlot, TItem>(
                [NotNull] this ISlotContainer <TSlot, TItem> container)
                where TSlot : ISlot
                where TItem : Node, ISlotItem
            {
                Ensure.Any.IsNotNull(container, nameof(container));

                return(container.Values.SelectMany(t => t.GetAllSlots()).Distinct());
            }
Example #5
0
            public static Set<string> OccupiedSlots<TSlot, TItem>(
                this ISlotContainer<TSlot, TItem> container)
                where TSlot : ISlot
                where TItem : class, ISlotItem
            {
                Ensure.Any.IsNotNull(container, nameof(container));

                return toSet(container.Items.Values.Bind(t => t.GetAllSlots()).Distinct());
            }
Example #6
0
            public static Option<TItem> FindItemInSlot<TSlot, TItem>(
                this ISlotContainer<TSlot, TItem> container,
                string slot)
                where TSlot : ISlot
                where TItem : class, ISlotItem
            {
                Ensure.That(container, nameof(container)).IsNotNull();

                return container.Items.Values.Find(i => i.Slot == slot || i.AdditionalSlots.Contains(slot));
            }
Example #7
0
            public static Option<string> FindSlot<TSlot, TItem>(
                this ISlotContainer<TSlot, TItem> container,
                TItem item)
                where TSlot : ISlot
                where TItem : class, ISlotItem
            {
                Ensure.That(container, nameof(container)).IsNotNull();

                return container.Items.Filter(t => t.Item2 == item).Map(t => t.Item1).HeadOrNone();
            }
Example #8
0
            public static TItem FindItem <TSlot, TItem>(
                [NotNull] this ISlotContainer <TSlot, TItem> container,
                [NotNull] string slot)
                where TSlot : ISlot
                where TItem : Node, ISlotItem
            {
                Ensure.Any.IsNotNull(container, nameof(container));
                Ensure.Any.IsNotNull(slot, nameof(slot));

                return(container.Values.FirstOrDefault(i => i.Slot == slot || i.AdditionalSlots.Contains(slot)));
            }
Example #9
0
            public static string FindSlot <TSlot, TItem>(
                [NotNull] this ISlotContainer <TSlot, TItem> container,
                [NotNull] TItem item)
                where TSlot : ISlot
                where TItem : Node, ISlotItem
            {
                Ensure.Any.IsNotNull(container, nameof(container));
                Ensure.Any.IsNotNull(item, nameof(item));

                return(container.Where(t => t.Value == item).Select(t => t.Key).FirstOrDefault());
            }
Example #10
0
 public bool IsSelectFor(ISlotContainer container)
 {
     if (container == null)
     {
         return(false);
     }
     else
     {
         return(container.Equals(SourceContainer));
     }
 }
Example #11
0
            public static IEnumerable<TItem> Replace<TSlot, TItem>(
                this ISlotContainer<TSlot, TItem> container,
                TItem item)
                where TSlot : ISlot
                where TItem : class, ISlotItem
            {
                Ensure.Any.IsNotNull(item, nameof(item));

                var allSlots = item.GetAllSlots();
                var occupiedSlots = OccupiedSlots(container);
                var slotsToFree = allSlots.Intersect(occupiedSlots);

                var itemsToFree = toSet(
                    slotsToFree.Bind(s => FindItemInSlot(container, s)).Distinct());

                itemsToFree.Iter(container.Remove);

                container.Add(item);

                return itemsToFree;
            }
Example #12
0
        // handling player inventory requests
        private void InventoryItemTaken(object sender, EntityContainerEventArgs <ContainedSlot> e)
        {
            if (!Enabled)
            {
                return;
            }

            if (_skipInventoryEvents)
            {
                return;
            }

            // at this point we need to remember what was taken to create appropriate message
            if (_pendingOperation)
            {
                throw new InvalidOperationException("Unable to take another item, release first previous taken item");
            }

            _tempSlot         = e.Slot;
            _pendingOperation = true;
            _sourceContainer  = (ISlotContainer <ContainedSlot>)sender;
        }
Example #13
0
        /// <summary>
        /// Takes currently locked item from the world
        /// </summary>
        public void TakeFromWorld()
        {
            if (_pendingOperation)
            {
                throw new InvalidOperationException("Unable to take another item, release first previous taken item");
            }

            if (_lockedEntity == null)
            {
                throw new InvalidOperationException("Lock world item before trying to take it");
            }

            if (!(_lockedEntity is IItem))
            {
                throw new InvalidOperationException("Locked entity should implement IItem interface");
            }

            _pendingOperation = true;
            _sourceContainer  = null;
            _tempSlot         = new ContainedSlot {
                Item = (IItem)_lockedEntity, ItemsCount = 1
            };
        }
Example #14
0
            public static IEnumerable <TItem> Replace <TSlot, TItem>(
                [NotNull] this ISlotContainer <TSlot, TItem> container,
                [NotNull] TItem item)
                where TSlot : ISlot
                where TItem : Node, ISlotItem
            {
                Ensure.Any.IsNotNull(item, nameof(item));

                var allSlots      = new HashSet <string>(item.GetAllSlots());
                var occupiedSlots = new HashSet <string>(OccupiedSlots(container));
                var slotsToFree   = allSlots.Intersect(occupiedSlots);

                var itemsToFree = slotsToFree
                                  .Select(s => FindItem(container, s))
                                  .Where(i => i != null)
                                  .Distinct()
                                  .ToList();

                itemsToFree.ForEach(container.Remove);

                container.Add(item);

                return(itemsToFree);
            }
Example #15
0
 /// <summary>
 /// 执行
 /// </summary>
 /// <param name="container"></param>
 /// <param name="onSuccess"></param>
 /// <param name="onError"></param>
 public void invoke(ISlotContainer container,
                    UnityAction onSuccess = null, UnityAction onError = null)
 {
     invoke(container, onSuccess, onError);
 }
Example #16
0
        // handling player inventory requests
        private void InventoryItemPut(object sender, EntityContainerEventArgs <ContainedSlot> e)
        {
            if (!Enabled)
            {
                return;
            }

            if (_skipInventoryEvents)
            {
                return;
            }

            if (!_pendingOperation)
            {
                throw new InvalidOperationException("Unable to put item without taking it first");
            }



            // check if no need to send anything
            if (_sourceContainer == sender && e.Slot.GridPosition == _tempSlot.GridPosition && e.Slot.ItemsCount == _tempSlot.ItemsCount)
            {
                _sourceContainer  = null;
                _pendingOperation = false;
                return;
            }

            // special check, if user puts items at the place where it just take the stack, we decrease that amount and wait
            if (_sourceContainer == sender && e.Slot.GridPosition == _tempSlot.GridPosition)
            {
                _tempSlot.ItemsCount -= e.Slot.ItemsCount;
                return;
            }

            var destContainer = (SlotContainer <ContainedSlot>)sender;

            var srcLink  = _sourceContainer.Parent.GetLink();
            var destLink = destContainer.Parent.GetLink();

            var srcPosition  = _tempSlot.GridPosition;
            var destPosition = e.Slot.GridPosition;

            if (_sourceContainer is CharacterEquipment)
            {
                srcPosition.X = -1;
            }
            if (destContainer is CharacterEquipment)
            {
                destPosition.X = -1;
            }

            var msg = new ItemTransferMessage
            {
                SourceContainerSlot       = srcPosition,
                SourceContainerEntityLink = srcLink,
                ItemsCount = e.Slot.ItemsCount,
                DestinationContainerSlot       = destPosition,
                DestinationContainerEntityLink = destLink
            };

            if (srcLink.IsEmpty)
            {
                msg.ItemEntityId = _tempSlot.Item.StaticId;
            }

            _server.ServerConnection.Send(msg);

            if (e.Slot.ItemsCount == _tempSlot.ItemsCount)
            {
                _sourceContainer  = null;
                _pendingOperation = false;
            }
            else
            {
                _tempSlot.ItemsCount -= e.Slot.ItemsCount;
            }
        }
Example #17
0
 public bool AllowedFor(ISlotContainer context) => true;
Example #18
0
 public override bool AllowedFor(ISlotContainer context) =>
 base.AllowedFor(context) && (context as IEquipmentContainer)?.Holder is IRigged;
Example #19
0
        public virtual bool AllowedFor(ISlotContainer context)
        {
            Ensure.Any.IsNotNull(context, nameof(context));

            return(_allowedFor == null || _allowedFor.Matches(context));
        }
Example #20
0
 public static ItemSelectionWindow StartSelection(ItemSelectionType selectionType, ISlotContainer container, IInventoryHandler handler, Action <List <ItemWithAmount> > confirm, string title = null, string confirmDialog = null,
                                                  int?typeLimit = null, int?amountLimit = null, Predicate <ItemSlotBase> selectCondition = null, Action cancel = null)
 {
     return(WindowsManager.OpenWindow <ItemSelectionWindow>(selectionType, container, handler, confirm, title, confirmDialog, typeLimit ?? default, amountLimit ?? default, selectCondition, cancel));
 }