public static void SellItem(ZoneClient client, Packet packet) { byte slot; int sellcount; ZoneCharacter character = client.Character; if (packet.TryReadByte(out slot) && packet.TryReadInt(out sellcount)) { Item item; character.Inventory.InventoryItems.TryGetValue(slot, out item); if (item != null) { long fullSellPrice = sellcount * item.ItemInfo.SellPrice; if (item.Ammount > 1) { item.Ammount -= (ushort)sellcount; byte Slot = (byte)item.Slot; Handler12.ModifyInventorySlot(character, 0x24, Slot, Slot, item); character.Inventory.Money += fullSellPrice; character.ChangeMoney(character.Inventory.Money); } else { character.Inventory.Money += fullSellPrice; character.ChangeMoney(character.Inventory.Money); character.Inventory.InventoryItems.Remove(slot); ResetInventorySlot(character, slot); } System.Console.WriteLine(item.ItemInfo.Type); } } }
public static void ClientUnequippedItem(ZoneClient pClient, Packet pPacket) { byte sourceSlot, destinationSlot; if (!pPacket.TryReadByte(out sourceSlot) || !pPacket.TryReadByte(out destinationSlot)) { Log.WriteLine(LogLevel.Warn, "Could not read unequip values."); return; } Item sourceEquip = pClient.Character.Inventory.EquippedItems.Find(e => (byte)e.ItemInfo.Slot == sourceSlot); //Item destinationItem = pClient.Character.Inventory.EquippedItems.Find(i => i.Slot == destinationSlot);// Item was searched from wrong place Item destinationItem; pClient.Character.Inventory.InventoryItems.TryGetValue(destinationSlot, out destinationItem); // check if something there if (destinationItem != null && (destinationItem.ItemInfo.Slot == ItemSlot.None)) { Log.WriteLine(LogLevel.Warn, "Equipping an item, not possible."); // Failed to unequip message here, no need to log it return; } // TODO: If source and destination types are different return. // Except rings and costumes (But that can be done later). /* * if( sourceEquip.Type != destinationItem.Type ) { * Log.WriteLine(LogLevel.Warn, "SourceType != DestinationType, just debugging message, not important"); * // Failed to unequip message here, no need to log it * return; * } */ if (destinationItem != null) { Item destinationEquip = (Item)destinationItem; pClient.Character.SwapEquips(sourceEquip, destinationEquip); } else { if (sourceEquip == null) { Handler12.UpdateEquipSlot(pClient.Character, destinationSlot, 0x24, 0, null); return; } pClient.Character.UnequipItem(sourceEquip, destinationSlot); } }
public static void MoveItemHandler(ZoneClient pClient, Packet pPacket) { byte oldslot, oldstate, newslot, newstate; if (!pPacket.TryReadByte(out oldslot) || !pPacket.TryReadByte(out oldstate) || !pPacket.TryReadByte(out newslot) || !pPacket.TryReadByte(out newstate)) { Log.WriteLine(LogLevel.Warn, "Could not read item move."); return; } if (oldslot == newslot) { Log.WriteLine(LogLevel.Warn, "Client tried to dupe an item."); return; } Item source; if (!pClient.Character.Inventory.InventoryItems.TryGetValue(oldslot, out source) && newstate != 0x00 && oldstate != 0x00 || newstate == 0x00) { if (pClient.Character.Guild != null) { if (newstate == 0x00 && oldstate == 0x24) { source.Flags = Data.ItemFlags.GuildItem; } else if (newstate == 0x24 && oldstate == 0x00) { source.Flags = Data.ItemFlags.Normal; } else if (source == null || newstate != 0x24) { if (!pClient.Character.Guild.GuildStore.GuildStorageItems.TryGetValue(oldslot, out source)) { return; } } } if (source == null) { Log.WriteLine(LogLevel.Warn, "Client tried to move empty slot."); return; } } if (newslot == 0xff || newstate == 0xff) { pClient.Character.Inventory.InventoryItems.Remove(oldslot); source.Delete(); //TODO: make a drop Handler12.ModifyInventorySlot(pClient.Character, oldslot, oldstate, (byte)source.Slot, null); } else if (newstate == 0x00 && oldstate == 0x24 && pClient.Character.Guild != null) { if (!pClient.Character.Guild.GuildStore.GetHasFreeGuildStoreSlot()) { //todo GuildStorefuell return; } pClient.Character.Inventory.RemoveInventory(source); pClient.Character.Guild.GuildStore.GuildStorageItems.Add(newslot, source); pClient.Character.Guild.GuildStore.SendAddGuildStore(Data.GuildStoreAddFlags.Item, pClient.Character.Character.Name, source.Ammount, 0, source.ItemInfo.ItemID); pClient.Character.Guild.GuildStore.SaveStoreItem(pClient.Character.Guild.ID, source.ItemInfo.ItemID, newslot); Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, oldslot, null); Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, oldslot, newslot, source); return; } else if (oldstate == 0x00 && newstate == 0x24 && pClient.Character.Guild != null) { if (!pClient.Character.Guild.GuildStore.GuildStorageItems.TryGetValue(oldslot, out source)) { return; } source.Slot = (sbyte)newslot; pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(oldslot); pClient.Character.Inventory.AddToInventory(source); pClient.Character.Guild.GuildStore.SendRemoveFromGuildStore(Data.GuildStoreAddFlags.Item, pClient.Character.Character.Name, source.Ammount, 0, source.ItemInfo.ItemID); pClient.Character.Guild.GuildStore.RemoveStoreItem(pClient.Character.Guild.ID, source.ItemInfo.ItemID); Handler12.ModifyInventorySlot(pClient.Character, newstate, oldstate, newslot, oldslot, null); Handler12.ModifyInventorySlot(pClient.Character, newstate, newstate, newstate, newslot, source); return; } if (source.Flags == Data.ItemFlags.Normal) { Item destination; if (pClient.Character.Inventory.InventoryItems.TryGetValue(newslot, out destination)) { //item swap pClient.Character.Inventory.InventoryItems.Remove(oldslot); pClient.Character.Inventory.InventoryItems.Remove(newslot); source.Slot = (sbyte)newslot; destination.Slot = (sbyte)oldslot; pClient.Character.Inventory.InventoryItems.Add(newslot, source); pClient.Character.Inventory.InventoryItems.Add(oldslot, destination); source.Save(); destination.Save(); Handler12.ModifyInventorySlot(pClient.Character, newslot, 0x24, oldslot, destination); Handler12.ModifyInventorySlot(pClient.Character, oldslot, 0x24, newslot, source); } else { //item moved to empty slot pClient.Character.Inventory.InventoryItems.Remove(oldslot); pClient.Character.Inventory.InventoryItems.Add(newslot, source); source.Slot = (sbyte)newslot; source.Save(); Handler12.ModifyInventorySlot(pClient.Character, newslot, 0x24, oldslot, null); Handler12.ModifyInventorySlot(pClient.Character, oldslot, 0x24, newslot, source); } } else if (source.Flags == Data.ItemFlags.GuildItem) { Item destination; if (pClient.Character.Guild.GuildStore.GuildStorageItems.TryGetValue(newslot, out destination)) { //item swap pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(oldslot); pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(newslot); source.Slot = (sbyte)newslot; destination.Slot = (sbyte)oldslot; pClient.Character.Guild.GuildStore.GuildStorageItems.Add(newslot, source); pClient.Character.Guild.GuildStore.GuildStorageItems.Add(oldslot, destination); Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, newslot, oldslot, destination); Handler12.ModifyInventorySlot(pClient.Character, oldstate, oldstate, newstate, newslot, source); } else { //item moved to empty slot pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(oldslot); pClient.Character.Guild.GuildStore.GuildStorageItems.Add(newslot, source); source.Slot = (sbyte)newslot; Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, newslot, oldslot, null); Handler12.ModifyInventorySlot(pClient.Character, newstate, oldstate, newstate, newslot, source); } } }