/// <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; }
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); }
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); }
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()); }
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()); }
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)); }
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(); }
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))); }
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()); }
public bool IsSelectFor(ISlotContainer container) { if (container == null) { return(false); } else { return(container.Equals(SourceContainer)); } }
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; }
// 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; }
/// <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 }; }
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); }
/// <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); }
// 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; } }
public bool AllowedFor(ISlotContainer context) => true;
public override bool AllowedFor(ISlotContainer context) => base.AllowedFor(context) && (context as IEquipmentContainer)?.Holder is IRigged;
public virtual bool AllowedFor(ISlotContainer context) { Ensure.Any.IsNotNull(context, nameof(context)); return(_allowedFor == null || _allowedFor.Matches(context)); }
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)); }