Exemplo n.º 1
0
        /// <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
            {
            }
        }
Exemplo n.º 2
0
        /// <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
            {
            }
        }
Exemplo n.º 3
0
        /// <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));
            }
        }