public void Sell(MapleClient c, MapleInventoryType type, byte slot, short quantity) { if (quantity == short.MinValue || quantity == 0) { quantity = 1; } MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; IMapleItem item = c.Player.Inventorys[type.Value].Inventory[slot]; if (ii.IsThrowingStar(item.ItemId)) { quantity = item.Quantity; } if (quantity < 0) { AutobanManager.Instance.AddPoints(c, 1000, 0, "Selling " + quantity + " " + item.ItemId + " (" + type + "/" + slot + ")"); return; } short iQuant = item.Quantity; if (iQuant == short.MinValue) { iQuant = 1; } if (quantity <= iQuant && iQuant > 0) { MapleInventoryManipulator.RemoveFromSlot(c, type, slot, quantity, false); double price; if (ii.IsThrowingStar(item.ItemId)) { price = ii.GetWholePrice(item.ItemId) / (double)ii.GetSlotMax(c, item.ItemId); } else { price = ii.GetPrice(item.ItemId); } int recvMesos = (int)Math.Max(Math.Ceiling(price * quantity), 0); if (Math.Abs(price + 1) > 0.000001 && recvMesos > 0) { c.Player.GainMeso(recvMesos, true); } c.Send(PacketCreator.ConfirmShopTransaction(0x8)); } }
public static void Move(MapleClient c, MapleInventoryType type, short src, short dst) { byte srcSlot = (byte)src; byte dstSlot = (byte)dst; if (srcSlot > 127 || dstSlot > 127 || srcSlot > c.Player.Inventorys[type.Value].SlotLimit || dstSlot > c.Player.Inventorys[type.Value].SlotLimit) { return; } MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; IMapleItem source; IMapleItem initialTarget; if (!c.Player.Inventorys[type.Value].Inventory.TryGetValue(srcSlot, out source)) { return; } short olddstQ = -1; if (c.Player.Inventorys[type.Value].Inventory.TryGetValue(dstSlot, out initialTarget)) { olddstQ = initialTarget.Quantity; } short oldsrcQ = source.Quantity; short slotMax = ii.GetSlotMax(c, source.ItemId); bool op = c.Player.Inventorys[type.Value].Move(srcSlot, dstSlot, slotMax); if (!op) { c.Send(PacketCreator.EnableActions()); return; } if (type != MapleInventoryType.Equip && initialTarget != null && initialTarget.ItemId == source.ItemId && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId)) { c.Send(olddstQ + oldsrcQ > slotMax ? PacketCreator.MoveAndMergeWithRestInventoryItem(type, srcSlot, dstSlot, (short)((olddstQ + oldsrcQ) - slotMax), slotMax) : PacketCreator.MoveAndMergeInventoryItem(type, srcSlot, dstSlot, ((Item)c.Player.Inventorys[type.Value].Inventory[dstSlot]).Quantity)); } else { c.Send(PacketCreator.MoveInventoryItem(type, src, dst, 0)); } }
public void Buy(MapleClient c, int itemId, short quantity) { if (quantity <= 0) { Console.WriteLine($"{c.Player.Name} is buying an invalid amount: { quantity } of itemid: { itemId}"); c.Close(); return; } MapleShopItem item = FindByItemId(itemId); MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; if (item != null && item.Price > 0 && c.Player.Meso.Value >= item.Price * quantity) { if (MapleInventoryManipulator.CheckSpace(c, itemId, quantity, "")) { if (itemId >= 5000000 && itemId <= 5000100) { if (quantity > 1) { quantity = 1; } int petId = MaplePet.Create(itemId); MapleInventoryManipulator.AddById(c, itemId, quantity, "Pet was purchased.", null, petId); } else if (ii.IsRechargable(itemId)) { short rechquantity = ii.GetSlotMax(c, item.ItemId); MapleInventoryManipulator.AddById(c, itemId, rechquantity, "Rechargable item purchased.", null, -1); } else { MapleInventoryManipulator.AddById(c, itemId, quantity, c.Player.Name + " bought " + quantity + " for " + item.Price * quantity + " from shop " + ShopId); } c.Player.GainMeso(-(item.Price * quantity), false); c.Send(PacketCreator.ConfirmShopTransaction(0)); } else { c.Send(PacketCreator.ConfirmShopTransaction(3)); } } }
public static void Drop(MapleClient c, MapleInventoryType type, byte srcSlot, short quantity) { MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; if (srcSlot > 127) { type = MapleInventoryType.Equipped; } IMapleItem source = c.Player.Inventorys[type.Value].Inventory[srcSlot]; if (quantity > ii.GetSlotMax(c, source.ItemId)) { //try //{ // c.getChannelServer().getWorldInterface().broadcastGMMessage(c.Player.getName(), PacketCreator.serverNotice(0, c.Player.getName() + " is dropping more than slotMax.").getBytes()); //} //catch (Throwable u) //{ //} } if (quantity < 0 || quantity == 0 && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId)) { //String message = "Dropping " + quantity + " " + (source == null ? "?" : source.ItemId) + " (" +type.name() + "/" + srcSlot + ")"; //log.info(MapleClient.getLogMessage(c, message)); c.Close(); // disconnect the client as is inventory is inconsistent with the serverside inventory return; } Point dropPos = c.Player.Position; if (quantity < source.Quantity && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId)) { IMapleItem target = source.Copy(); target.Quantity = quantity; source.Quantity -= quantity; c.Send(PacketCreator.DropInventoryItemUpdate(type, source)); bool weddingRing = source.ItemId == 1112804; bool liRing = source.ItemId == 1112405; if (weddingRing) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos); } else if (liRing) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos); } else if (c.Player.Map.Everlast) { if (ii.IsDropRestricted(target.ItemId)) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, target, dropPos, true, false); } } else { if (ii.IsDropRestricted(target.ItemId)) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, target, dropPos, true, false); } } } else { c.Player.Inventorys[type.Value].RemoveSlot(srcSlot); c.Send(PacketCreator.DropInventoryItem(srcSlot > 127 ? MapleInventoryType.Equip : type, srcSlot)); bool liRing = source.ItemId == 1112405; if (srcSlot > 127) { c.Player.EquipChanged(); } if (c.Player.Map.Everlast) { if (ii.IsDropRestricted(source.ItemId)) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, false); if (liRing) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, true); } } } else { if (ii.IsDropRestricted(source.ItemId)) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos); } else { if (liRing) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, true); } } } } }