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 bool AddItem(int id, short quantity, bool randomStats) { if (quantity >= 0) { var ii = MapleItemInformationProvider.Instance; var item = ii.GetEquipById(id); var type = ii.GetInventoryType(id); string logInfo = $"{Player.Name} received {quantity} frome a scripted PlayerInteraction ({ToString()})"; if (!MapleInventoryManipulator.CheckSpace(Client, id, quantity, "")) { var invtype = ii.GetInventoryType(id); Client.Send(PacketCreator.ServerNotice(PacketCreator.ServerMessageType.Popup, "你的背包已满")); return(false); } if (type == MapleInventoryType.Equip && !ii.IsThrowingStar(item.ItemId) && !ii.IsBullet(item.ItemId)) { if (randomStats) { MapleInventoryManipulator.AddFromDrop(Client, ii.RandomizeStats((Equip)item), false, logInfo); } else { MapleInventoryManipulator.AddFromDrop(Client, (Equip)item, false, logInfo); } } else { MapleInventoryManipulator.AddById(Client, id, quantity, logInfo); } } else { MapleInventoryManipulator.RemoveById(Client, MapleItemInformationProvider.Instance.GetInventoryType(id), id, -quantity, true, false); } Client.Send(PacketCreator.GetShowItemGain(id, quantity, true)); return(true); }