protected override void OnHandle(IPacket packet, NetState netState, ServerWorldState worldState) { MoveItemPacket incomingPacket = (MoveItemPacket)packet; //if (incomingPacket.MobileId != netState.WorldId) //{ // netState.SendError(0, string.Format("Invalid CMD: '{0},{1},{2}'.", incomingPacket.PacketId, incomingPacket.MobileId, incomingPacket.ItemId)); // return; //} ServerCharacter serverCharacter = (ServerCharacter)worldState.GetCharacter(netState.WorldId); Item item = (Item)worldState.GetItem(incomingPacket.ItemID); if (serverCharacter != null && item != null) { if (incomingPacket.MoveToID.HasValue) //item.Data.IsWorldItem && { int containerID = incomingPacket.MoveToID.Value; ContainerItem moveTo = (ContainerItem)worldState.GetItem(containerID); if (moveTo != null) { if (serverCharacter.MoveItem(item, moveTo)) { worldState.SaveItemPosition(item); this.OnSuccessfulChange(serverCharacter.CurrentMapId, serverCharacter.Id, containerID, incomingPacket.ItemID, worldState); } } } else if (incomingPacket.MoveToPosition.HasValue) { Point moveToPostion = incomingPacket.MoveToPosition.Value; if (serverCharacter.MoveItem(item, moveToPostion)) { worldState.SaveItemPosition(item); this.OnSuccessfulChange(serverCharacter.CurrentMapId, serverCharacter.Id, moveToPostion, incomingPacket.ItemID, worldState); } } } }
protected override void OnHandle(IPacket packet, NetState netState, ServerWorldState worldState) { UseItemPacket incomingPacket = (UseItemPacket)packet; //if (incomingPacket.MobileId != netState.WorldId) //{ // netState.SendError(0, string.Format("Invalid CMD: '{0},{1},{2}'.", incomingPacket.PacketId, incomingPacket.MobileId, incomingPacket.ItemId)); // return; //} ServerCharacter serverCharacter = (ServerCharacter)worldState.GetCharacter(netState.WorldId); Item itemToUse = worldState.GetItem(incomingPacket.ItemId); if (serverCharacter != null && itemToUse != null) { if (itemToUse.IsWorldItem) { if (serverCharacter.PickupItem(itemToUse)) { worldState.SaveItemPosition(itemToUse); this.OnSuccessfulUse(serverCharacter.CurrentMapId, incomingPacket.MobileId, incomingPacket.ItemId, worldState); } } else { if (itemToUse.Category == ItemCategory.Consumable) { ConsumableItem consumable = (ConsumableItem)itemToUse; if (consumable.Use(serverCharacter, worldState)) { worldState.SaveItemUse(itemToUse); this.OnSuccessfulUse(serverCharacter.CurrentMapId, incomingPacket.MobileId, incomingPacket.ItemId, worldState); } } if (itemToUse.Category == ItemCategory.Armor || itemToUse.Category == ItemCategory.Weapon) { if (serverCharacter.Equip(itemToUse)) { worldState.SaveCharacterItems(serverCharacter); this.OnSuccessfulUse(serverCharacter.CurrentMapId, incomingPacket.MobileId, incomingPacket.ItemId, worldState); } } } } }