public BaseItem PickupItem(int mapItemId, Character c) { MapItem m = null; try { m = mapItems.Where(x => x.MapItemID == mapItemId).First(); } catch (Exception) { return null; } BaseItem item = itemDataManager.GetItemByItemID(m.ItemID); BagSlot bagSlot = new BagSlot(); bool added = false; for (int i = 0; i < c.Bags.Count; i++) { if (!added) { if (c.Bags[i].PickItem(item, bagSlot)) { added = true; bagSlot.Bag = (byte)(i + 1); break; } } } if (!added) throw new BagIsFullException(Messages.BAGISFULLEXCEPTION); item.Slot = bagSlot.Slot; item.Bag = bagSlot.Bag; mapItemManager.DeleteMapItem(m.MapItemID); mapItems.Remove(m); item.OwnerID = c.CharacterId; itemDataManager.UpdateItem(item); return item; }
void c_ClientTradeAddItemInfo(object sender, ClientTradeAddItemEventArgs e) { Client c = (Client)sender; TradeAddItemInfo i = e.Info; Client p = null; BaseItem item = null; if (i.PlayerID != c.MyCharacter.CharacterId) p = GetClientByCharacterID(i.PlayerID); try { item = c.MyCharacter.Bags[i.FromBag - 1].Items.First(x => x.ItemID == i.ItemID); if (i.ToSlot != 255) { item.TradeSlot = i.ToSlot; if (!c.MyCharacter.TradeWindow.CheckTradeSlot(item, item.TradeSlot)) { c.MyCharacter.TradeWindow.AddItem(item); } else { BagSlot bagSlot = new BagSlot(); if (!c.MyCharacter.FindFreeSlotInTradeWindow(item, bagSlot)) { throw new BagIsFullException("BAG FULL"); //Throw exception here } item.TradeSlot = bagSlot.Slot; c.MyCharacter.TradeWindow.AddItem(item); } c.Send(PacketManager.SendRemoveItem(i.FromBag, i.FromSlot)); byte[] SendTradeAddItem = PacketManager.SendTradeAddItem(i, item); c.Send(SendTradeAddItem); p.Send(SendTradeAddItem); c.Send(PacketManager.SendAddItem(item)); } } catch { } }
/// <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 { } }
void c_ClientAddItemToWarehouseInfo(object sender, ClientAddItemToWarehouseEventargs e) { Client c = (Client)sender; AddItemToWarehouseInfo i = e.Info; if (i.ToSlot <= 65) { try { BaseItem item = c.MyCharacter.Bags[i.FromBag - 1].Items.First(x => x.ItemID == i.ItemID); int storagecost = Math.Abs(item.Price / 100); if (c.MyCharacter.Money >= storagecost) { if (!c.MyCharacter.Warehouse.CheckSlot(item, i.ToSlot)) { item.Slot = (byte)(i.ToSlot); item.Bag = 5; c.MyCharacter.Bags[i.FromBag - 1].RemoveItem(item); c.MyCharacter.Warehouse.AddItem(item); itemDataManager.UpdateItem(item); } else { BagSlot bagSlot = new BagSlot(); if (!c.MyCharacter.FindFreeSlotInWarehouse(item, bagSlot)) { throw new BagIsFullException("BAG FULL"); //Throw exception here } item.Slot = bagSlot.Slot; item.Bag = bagSlot.Bag; c.MyCharacter.Bags[i.FromBag - 1].RemoveItem(item); c.MyCharacter.Warehouse.AddItem(item); itemDataManager.UpdateItem(item); } c.MyCharacter.Money -= storagecost; c.Send(PacketManager.SendRemoveItem(i.FromBag, i.FromSlot)); c.Send(PacketManager.SendAddItemToWarehouse(1, item)); c.Send(PacketManager.SendMoneyLeft(c.MyCharacter.Money)); } else { c.Send(PacketManager.SendBuyOtherPlayerShopItemError((byte)BuyOtherPlayerShopItemError.NoMoney)); } } catch (BagIsFullException) { byte[] SendWarehouseError = PacketManager.SendWarehouseError(WarehouseError.YourStashIsFull); c.Send(SendWarehouseError); } } }
/// <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; MapEngine mapEngine = GetMapEngine(c.MyCharacter.MapId); try { npc = mapEngine.GetNpcByID(i.NpcID, c.MyCharacter.MapId); npcitem = npc.FindItem(i.ReferenceID, i.Slot); int price = npcitem.Price * i.Amount; if (c.MyCharacter.Money >= price) { BagSlot bagSlot = new BagSlot(); if (!c.MyCharacter.FindFreeSlotInBags(npcitem, bagSlot)) { throw new BagIsFullException("BAG FULL"); //Throw exception here } c.MyCharacter.Money -= price; c.Send(PacketManager.SendMoneyLeft(c.MyCharacter.Money)); c.Send(PacketManager.SendBuyItemState(BuyItemState.Success)); 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); if (npc.IsEliteShop) { if (buyitem is Equipment) { // later add chance to get these items blabla Equipment Item = buyitem as Equipment; ImbueStat stat = ImbueStat.None; ImbueItem imbueitem = new ImbueItem { ImbueChance = 1, IncreaseValue = 1, }; if (XiahRandom.PercentSuccess(40)) { // Possible plus for drop int plus = gameEngine.RandomChance(0, 9); for (int a = 0; a < plus; a++) { gameEngine.BlackImbue(Item, ref stat, imbueitem, 1); Item.Plus++; } } if (XiahRandom.PercentSuccess(40)) { // Possible slvl for drop int slvl = gameEngine.RandomChance(0, 9); for (int a = 0; a < slvl && !(Item is Cape); a++) { gameEngine.WhiteImbue(Item, ref stat, imbueitem); Item.Slvl++; } buyitem = Item; } itemDataManager.UpdateItem(buyitem); } } c.MyCharacter.Bags[buyitem.Bag - 1].AddItem(buyitem); characterManager.UpdateCharacter(c.MyCharacter); c.Send(PacketManager.SendAddItem(buyitem)); } else { c.Send(PacketManager.SendBuyItemState(BuyItemState.NoMoney)); } } catch (BagIsFullException) { c.Send(PacketManager.SendBuyItemState(BuyItemState.BagFull)); } }
public bool PickItem(BaseItem item, BagSlot newBagSlot) { bool added = false; if (FindFreeSlot(item, newBagSlot)) { added = true; items.Add(item); } return added; }
void c_ClientAddItemToShopInfo(object sender, ClientAddItemToShopEventArgs e) { Client c = (Client)sender; AddItemToShopInfo i = e.Info; BaseItem item = null; if (i.Slot <= 36) { try { item = c.MyCharacter.Bags[i.FromBag - 1].Items.First(x => x.ItemID == i.ItemID); if (!c.MyCharacter.Shop.CheckSlot(item, i.Slot)) { item.Slot = i.Slot; c.MyCharacter.Bags[i.FromBag - 1].RemoveItem(item); c.MyCharacter.Shop.AddItem(item); } else { BagSlot bagSlot = new BagSlot(); if (!c.MyCharacter.FindFreeSlotInShop(item, bagSlot)) { throw new BagIsFullException("BAG FULL"); //Throw exception here } item.Slot = bagSlot.Slot; item.Bag = bagSlot.Bag; c.MyCharacter.Bags[i.FromBag - 1].RemoveItem(item); c.MyCharacter.Shop.AddItem(item); // itemDataManager.UpdateItem(item); } item.SellPrice = i.Price; byte[] SendAddItemToShopError = PacketManager.SendAddItemToShopError(AddItemToShopError.Success, item.SellPrice); c.Send(SendAddItemToShopError); byte[] SendRemoveItem = PacketManager.SendRemoveItem(i.FromBag, i.FromSlot); c.Send(SendRemoveItem); byte[] SendAddItemToShop = PacketManager.SendAddItemToShop(item, item.SellPrice); c.Send(SendAddItemToShop); itemDataManager.InsertShopItem(c.MyCharacter.Shop.ShopID, item.Slot, item.ItemID, item.SellPrice); } catch { byte[] SendAddItemToShopError = PacketManager.SendAddItemToShopError(AddItemToShopError.CannotRegisterAnymoreBecauseYourStoreBagIsFull, 0); c.Send(SendAddItemToShopError); } } }
public bool FindFreeSlotInBags(BaseItem item, BagSlot bagSlot) { bool found = false; for (int i = 0; i < Bags.Count; i++) { if (Bags[i].FindFreeSlot(item, bagSlot)) { found = true; bagSlot.Bag = (byte)(i + 1); break; } } return found; }
public bool FindFreeSlot(BaseItem item, BagSlot newBagSlot) { bool found = false; newBagSlot.Slot = 255; List<BaseItem> conflictingItems = null; for (byte i = 0; i < slotCount; i++) { if (!IsSlotValid(item, i)) { continue; } if (!HasNoRoom(item, i, out conflictingItems)) { newBagSlot.Slot = i; found = true; break; } } return found; }
public bool FindFreeTradeSlot(BaseItem item, BagSlot newBagSlot) { bool found = false; newBagSlot.Slot = 255; for (byte i = 0; i < slotCount; i++) { if (!IsSlotValid(item, i)) { continue; } if (!CheckTradeSlot(item, i)) { newBagSlot.Slot = i; found = true; break; } } return found; }
public bool FindFreeSlotInWarehouse(BaseItem item, BagSlot bagSlot) { bool found = false; if (Warehouse.FindFreeSlot(item, bagSlot)) { found = true; bagSlot.Bag = 5; } return found; }
public bool FindFreeSlotInTradeWindow(BaseItem item, BagSlot bagSlot) { bool found = false; if (TradeWindow.FindFreeTradeSlot(item, bagSlot)) { found = true; bagSlot.Bag = 3; } return found; }
public bool FindFreeSlotInShop(BaseItem item, BagSlot bagSlot) { bool found = false; if (Shop.FindFreeSlot(item, bagSlot)) { found = true; bagSlot.Bag = 6; } return found; }
public BagSlot TryPickToBags(Bag[] playerBags, BaseItem item) { BagSlot bagSlot = new BagSlot(); bool added = false; for (int i = 0; i < playerBags.Length; i++) { if (!added) { if (playerBags[i].PickItem(item, bagSlot)) { added = true; bagSlot.Bag = (byte)(i + 1); break; } } } if (!added) throw new BagIsFullException(Messages.BAGISFULLEXCEPTION); return bagSlot; }