EndsWith() public static method

public static EndsWith ( string a, string b ) : bool
a string
b string
return bool
Esempio n. 1
0
        public static GiveFlags GiveTo(
            this Item item, Mobile m, GiveFlags flags = GiveFlags.PackBankFeet, bool message = true)
        {
            if (item == null || item.Deleted || m == null || m.Deleted || flags == GiveFlags.None)
            {
                return(GiveFlags.None);
            }

            bool pack   = flags.HasFlag(GiveFlags.Pack);
            bool bank   = flags.HasFlag(GiveFlags.Bank);
            bool feet   = flags.HasFlag(GiveFlags.Feet);
            bool delete = flags.HasFlag(GiveFlags.Delete);

            GiveFlags result = VitaNexCore.TryCatchGet(
                () =>
            {
                if (pack && m.PlaceInBackpack(item))
                {
                    return(GiveFlags.Pack);
                }

                if (bank && m.BankBox.TryDropItem(m, item, false))
                {
                    return(GiveFlags.Bank);
                }

                if (feet)
                {
                    MapPoint mp = m.ToMapPoint();

                    if (!mp.Internal)
                    {
                        item.MoveToWorld(mp.Location, mp.Map);
                        return(GiveFlags.Feet);
                    }
                }

                if (delete)
                {
                    item.Delete();
                    return(GiveFlags.Delete);
                }

                return(GiveFlags.None);
            });

            if (message)
            {
                string amount = String.Empty;
                string name   = ResolveName(item, m);

                bool p = false;

                if (item.Stackable && item.Amount > 1)
                {
                    amount = item.Amount.ToString("#,0") + " ";
                    p      = true;

                    if (!Insensitive.EndsWith(name, "s") && !Insensitive.EndsWith(name, "z"))
                    {
                        name += "s";
                    }
                }

                switch (result)
                {
                case GiveFlags.Pack:
                    m.SendMessage("{0}{1} {2} been placed in your pack.", amount, name, p ? "have" : "has");
                    break;

                case GiveFlags.Bank:
                    m.SendMessage("{0}{1} {2} been placed in your bank.", amount, name, p ? "have" : "has");
                    break;

                case GiveFlags.Feet:
                    m.SendMessage("{0}{1} {2} been placed at your feet.", amount, name, p ? "have" : "has");
                    break;
                }
            }

            return(result);
        }
Esempio n. 2
0
        public static GiveFlags GiveTo(this Item item, Mobile m, GiveFlags flags = GiveFlags.All, bool message = true)
        {
            if (item == null || item.Deleted || m == null || m.Deleted || flags == GiveFlags.None)
            {
                return(GiveFlags.None);
            }

            var pack   = flags.HasFlag(GiveFlags.Pack);
            var bank   = flags.HasFlag(GiveFlags.Bank);
            var feet   = flags.HasFlag(GiveFlags.Feet);
            var corpse = flags.HasFlag(GiveFlags.Corpse);
            var delete = flags.HasFlag(GiveFlags.Delete);

            if (pack && (m.Backpack == null || m.Backpack.Deleted || !m.Backpack.CheckHold(m, item, false)))
            {
                pack   = false;
                flags &= ~GiveFlags.Pack;
            }

            if (bank && (!m.Player || !m.BankBox.CheckHold(m, item, false)))
            {
                bank   = false;
                flags &= ~GiveFlags.Bank;
            }

            if (corpse && (m.Alive || m.Corpse == null || m.Corpse.Deleted))
            {
                corpse = false;
                flags &= ~GiveFlags.Corpse;
            }

            if (feet && (m.Map == null || m.Map == Map.Internal) && (m.LogoutMap == null || m.LogoutMap == Map.Internal))
            {
                feet   = false;
                flags &= ~GiveFlags.Feet;
            }

            var result = VitaNexCore.TryCatchGet(
                f =>
            {
                if (pack && m.Backpack.DropItemStack(m, item))
                {
                    return(GiveFlags.Pack);
                }

                if (bank && m.BankBox.DropItemStack(m, item))
                {
                    return(GiveFlags.Bank);
                }

                if (corpse && m.Corpse.DropItemStack(m, item))
                {
                    return(GiveFlags.Corpse);
                }

                if (feet)
                {
                    if (m.Map != null && m.Map != Map.Internal)
                    {
                        item.MoveToWorld(m.Location, m.Map);

                        if (m.Player)
                        {
                            item.SendInfoTo(m.NetState);
                        }

                        return(GiveFlags.Feet);
                    }

                    if (m.LogoutMap != null && m.LogoutMap != Map.Internal)
                    {
                        item.MoveToWorld(m.LogoutLocation, m.LogoutMap);

                        return(GiveFlags.Feet);
                    }
                }

                if (delete)
                {
                    item.Delete();

                    return(GiveFlags.Delete);
                }

                return(GiveFlags.None);
            },
                flags);

            if (!message || result == GiveFlags.None || result == GiveFlags.Delete)
            {
                return(result);
            }

            var amount = String.Empty;
            var name   = ResolveName(item, m);

            var p = item.Stackable && item.Amount > 1;

            if (p)
            {
                amount = item.Amount.ToString("#,0") + " ";

                if (!Insensitive.EndsWith(name, "s") && !Insensitive.EndsWith(name, "z"))
                {
                    name += "s";
                }
            }

            switch (result)
            {
            case GiveFlags.Pack:
                m.SendMessage("{0}{1} {2} been placed in your pack.", amount, name, p ? "have" : "has");
                break;

            case GiveFlags.Bank:
                m.SendMessage("{0}{1} {2} been placed in your bank.", amount, name, p ? "have" : "has");
                break;

            case GiveFlags.Corpse:
                m.SendMessage("{0}{1} {2} been placed in your corpse.", amount, name, p ? "have" : "has");
                break;

            case GiveFlags.Feet:
                m.SendMessage("{0}{1} {2} been placed at your feet.", amount, name, p ? "have" : "has");
                break;
            }

            return(result);
        }