Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }