Example #1
0
        private static void GrabLoot(Mobile from, Container cont)
        {
            if (!from.Alive || cont == null)
            {
                return;
            }

            if (cont is Corpse && from == ((Corpse)cont).Owner)
            {
                Corpse corpse = (Corpse)cont;

                if (corpse.Killer == null || corpse.Killer is BaseCreature)
                {
                    corpse.Open(from, true);
                }
                else
                {
                    corpse.Open(from, false);
                }
            }
            else
            {
                bool        fullPack = false;
                List <Item> items    = new List <Item>(cont.Items);
                GrabOptions options  = Grab.GetOptions(from);

                for (int i = 0; !fullPack && i < items.Count; i++)
                {
                    Item item = items[i];

                    if (options.IsLootable(item))
                    {
                        Container dropCont = options.GetPlacementContainer(Grab.ParseType(item));

                        if (dropCont == null || dropCont.Deleted || !dropCont.IsChildOf(from.Backpack))
                        {
                            dropCont = from.Backpack;
                        }

                        if (!item.DropToItem(from, dropCont, new Point3D(-1, -1, 0)))
                        {
                            fullPack = true;
                        }
                    }
                }

                if (fullPack)
                {
                    from.SendMessage("You grabbed as many of the items as you could. The rest remain {0}.", (cont is Corpse ? "on the corpse" : "in the container"));
                }
                else
                {
                    from.SendMessage("You retrieve all of the items from the {0}.", (cont is Corpse ? "body" : "container"));
                }

                from.RevealingAction();
            }
        }