private bool RollbackItem(ItemTransferMessage itm, Slot slot) { if (slot != null) { var position = itm.SourceContainerSlot; SlotContainer <ContainedSlot> container = null; if (itm.SourceContainerEntityLink.IsPointsTo(this)) { if (itm.SourceContainerSlot.X == -1) { container = Equipment; position.X = 0; } else { container = Inventory; } } if (container != null) { container.PutItem(slot.Item, position, slot.ItemsCount); } else { return(false); } } return(true); }
protected void OnMessageItemTransfer(ItemTransferMessage ea) { if (MessageItemTransfer != null) { MessageItemTransfer(this, new ProtocolMessageEventArgs <ItemTransferMessage> { Message = ea }); } }
protected void OnMessageItemTransfer(ItemTransferMessage ea) { var handler = MessageItemTransfer; if (handler != null) { handler(this, new ProtocolMessageEventArgs <ItemTransferMessage> { Message = ea }); } }
void InventoryItemExchanged(object sender, EntityContainerEventArgs <ContainedSlot> e) { if (!Enabled) { return; } if (!_pendingOperation) { throw new InvalidOperationException("Unable to exchange item without taking it first"); } 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, IsSwitch = true }; if (srcLink.IsEmpty) { msg.ItemEntityId = _tempSlot.Item.StaticId; } _server.ServerConnection.Send(msg); _tempSlot.Item = e.Exchanged.Item; _tempSlot.ItemsCount = e.Exchanged.ItemsCount; _pendingOperation = true; }
private bool TakeItem(ItemTransferMessage itemTransferMessage, out ContainedSlot slot) { slot = null; var position = itemTransferMessage.SourceContainerSlot; var srcLink = itemTransferMessage.SourceContainerEntityLink; // item from nowhere if (srcLink.IsEmpty) { slot = new ContainedSlot { Item = (IItem)EntityFactory.CreateFromBluePrint((ushort)itemTransferMessage.ItemEntityId), ItemsCount = itemTransferMessage.ItemsCount }; return(true); } // detect the container var container = FindContainer(srcLink, position, out position); if (container == null) { return(false); } slot = container.PeekSlot(position); if (!container.TakeItem(position, itemTransferMessage.ItemsCount)) { slot = null; return(false); } slot.ItemsCount = itemTransferMessage.ItemsCount; if (!itemTransferMessage.IsSwitch && container == Inventory) { var pos = itemTransferMessage.DestinationContainerSlot; var destContainer = FindContainer(itemTransferMessage.DestinationContainerEntityLink, itemTransferMessage.DestinationContainerSlot, out pos); if (destContainer == Equipment) { ActiveToolInventoryPosition = itemTransferMessage.SourceContainerSlot; } } return(true); }
public override void ItemTransfer(ItemTransferMessage itm) { _dontSendInventoryEvents = true; try { if (!PlayerCharacter.ReplayTransfer(itm)) { ItemError(); } } finally { _dontSendInventoryEvents = false; } }
private bool PutItem(ItemTransferMessage itemTransferMessage, Slot slot) { // detect the container var position = itemTransferMessage.DestinationContainerSlot; var destLink = itemTransferMessage.DestinationContainerEntityLink; var container = FindContainer(destLink, position, out position); if (container == null) { return(false); } return(container.PutItem(slot.Item, position, slot.ItemsCount)); }
void Inventory_ItemPut(object sender, EntityContainerEventArgs <ContainedSlot> e) { // skip player own messages if (_dontSendInventoryEvents) { return; } // inform client about his inventory change from outside var msg = new ItemTransferMessage { DestinationContainerEntityLink = PlayerCharacter.GetLink(), DestinationContainerSlot = e.Slot.GridPosition, ItemsCount = e.Slot.ItemsCount, ItemEntityId = e.Slot.Item.BluePrintId, SourceEntityId = PlayerCharacter.DynamicId }; Connection.Send(msg); CurrentArea.OnCustomMessage(PlayerCharacter.DynamicId, msg); }
public virtual void ItemTransfer(ItemTransferMessage itemTransferMessage) { }
public bool ReplayTransfer(ItemTransferMessage itm) { #region Switch if (itm.IsSwitch) { var srcPosition = itm.SourceContainerSlot; var dstPosition = itm.DestinationContainerSlot; var srcContainer = FindContainer(itm.SourceContainerEntityLink, srcPosition, out srcPosition); var dstContainer = FindContainer(itm.DestinationContainerEntityLink, dstPosition, out dstPosition); if (srcContainer == null || dstContainer == null) { return(false); } // switching is allowed only if we have both slots busy var srcSlot = srcContainer.PeekSlot(srcPosition); var dstSlot = dstContainer.PeekSlot(dstPosition); if (srcSlot == null || dstSlot == null) { return(false); } if (!srcContainer.TakeItem(srcSlot.GridPosition, srcSlot.ItemsCount)) { return(false); } if (!dstContainer.TakeItem(dstSlot.GridPosition, dstSlot.ItemsCount)) { return(false); } if (!srcContainer.PutItem(dstSlot.Item, srcSlot.GridPosition, dstSlot.ItemsCount)) { return(false); } if (!dstContainer.PutItem(srcSlot.Item, dstSlot.GridPosition, srcSlot.ItemsCount)) { return(false); } // ok return(true); } #endregion if (itm.SourceContainerSlot.X == -2) { // set toolbar slot var item = FindItemById(itm.ItemEntityId); if (item == null) { return(false); } Toolbar[itm.SourceContainerSlot.Y] = item.BluePrintId; return(true); } ContainedSlot slot; if (TakeItem(itm, out slot)) { if (PutItem(itm, slot)) { // ok return(true); } if (!RollbackItem(itm, slot)) { return(false); } } // impossible to transfer return(false); }
// 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; } }