/// <summary> /// SELL ITEM PRICE FOR PLAIN ITEMS IS ITEM.PRICE / 2.5 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void c_ClientBuyItemInfo(object sender, ClientBuyItemEventArgs e) { Client c = (Client)sender; BuyItemInfo i = e.Info; BaseItem buyitem = null; BaseItem npcitem = null; Npc npc = null; try { npc = mapEngine.GetNpcByID(i.NpcID, c.MyCharacter.MapId); npcitem = npc.Bags[i.Bag].Items.Single(x => (x.ReferenceID == i.ReferenceID)); if (c.MyCharacter.Money >= npcitem.Price) { c.MyCharacter.Money -= npcitem.Price; c.Send(PacketManager.SendMoneyLeft(c.MyCharacter.Money)); c.Send(PacketManager.SendBuyItemState(BuyItemState.Success)); BagSlot bagSlot = new BagSlot(); if (!c.MyCharacter.FindFreeSlotInBags(npcitem, bagSlot)) { //Throw exception here } MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, npcitem); stream.Position = 0; buyitem = (BaseItem)formatter.Deserialize(stream); stream.Close(); buyitem.Bag = bagSlot.Bag; buyitem.Slot = bagSlot.Slot; buyitem.OwnerID = c.MyCharacter.CharacterId; buyitem.Amount = i.Amount; buyitem.ItemID = itemDataManager.InsertItem(buyitem); c.MyCharacter.Bags[buyitem.Bag - 1].AddItem(buyitem); c.Send(PacketManager.SendAddItem(buyitem)); } else { c.Send(PacketManager.SendBuyItemState(BuyItemState.NoMoney)); } } catch { } }
public BaseItem PickupItem(int mapItemId, Client c, short mapItemAmount) { MapItem m = null; try { m = mapItems.Where(x => x.MapItemID == mapItemId).First(); } catch (Exception) { return(null); } BaseItem item = null; if (m.DroppedByCharacterID == 0 || m.DroppedByCharacterID == c.MyCharacter.CharacterId) { if (m.bType != (byte)bType.Jeon) { if (m.ItemID != 0) { item = itemDataManager.GetItemByItemID(m.ItemID); } else { item = itemDataManager.GetItemByReferenceID(m.ReferenceID); } BagSlot bagSlot = gameEngine.TryPickToBags(c.MyCharacter.Bags.ToArray(), item); item.Slot = bagSlot.Slot; item.Bag = bagSlot.Bag; mapItemManager.DeleteMapItem(m.MapItemID, 0); mapItems.Remove(m); item.OwnerID = c.MyCharacter.CharacterId; if (item.ItemID != 0) { itemDataManager.UpdateItem(item); } else { item.ItemID = itemDataManager.InsertItem(item); if (item is Equipment) { // later add chance to get these items blabla Equipment Item = item as Equipment; ImbueStat stat = ImbueStat.None; ImbueItem imbueitem = new ImbueItem { ImbueChance = 1, IncreaseValue = 1, }; // Possible plus for drop if (XiahRandom.PercentSuccess(40)) { int plus = gameEngine.RandomChance(0, 5); for (int i = 0; i < plus; i++) { gameEngine.BlackImbue(Item, ref stat, imbueitem, 1); Item.Plus++; } } if (XiahRandom.PercentSuccess(40)) { // Possible slvl for drop int slvl = gameEngine.RandomChance(0, 5); for (int i = 0; i < slvl && !(Item is Cape); i++) { gameEngine.WhiteImbue(Item, ref stat, imbueitem); Item.Slvl++; } } item = Item; itemDataManager.UpdateItem(item); } } } else { item = itemDataManager.GetItemByReferenceID(m.ReferenceID); mapItemManager.DeleteMapItem(m.MapItemID, 0); mapItems.Remove(m); item.Amount = mapItemAmount; } } else { c.Send(PacketEngine.PacketManager.SendPickUpText(0, 0, 0)); // send pickuperror blabal } return(item); }