All pastes #282576 Raw Edit

Untitled

public text v1 · immutable
#282576 ·published 2006-12-17 18:27 UTC
rendered paste body
using Server;
using Server.Items;
using Server.Spells;

namespace Server
{
    public static class Sphere
    {
        public static string dropStringFormat = "You put the {0} in your pack.";

        public static string ComputeName(Item i)
        {
            if (i is BaseWeapon)
                return ComputeName((i as BaseWeapon));
            else if (i is BaseArmor)
                return ComputeName((i as BaseArmor));
            else if (i is BaseClothing)
                return ComputeName((i as BaseClothing));
            else
                return GenericComputeName(i);
        }

        public static string ComputeName(BaseArmor ba)
        {
            string name = "";

            if (ba.Name == null)
                name = ClilocTranslator.GetString(ba.LabelNumber);
            else
                name = ba.Name;

            string resource = "";

            //Add spaces to the resources that needs it.
            switch (ba.Resource)
            {
                case CraftResource.DullCopper:
                    {
                        resource = "dull copper";
                        break;
                    }
                default:
                    {
                        resource = ba.Resource.ToString();
                        break;
                    }
            }

            if ((ba.ProtectionLevel != ArmorProtectionLevel.Regular) && ba.Resource == CraftResource.Iron)
            {//If the armor is magical
                name = string.Format("{0} of {1}", name, ClilocTranslator.GetString((1038005 + (int)ba.ProtectionLevel)));
            }
            else if (ba.Resource != CraftResource.None)
            {//If it's crafted by a player
                if (ba.Crafter != null)
                {
                    if (ba.Quality == ArmorQuality.Exceptional)
                    {
                        if (ba.Resource != CraftResource.Iron)
                            name = string.Format("{0} {1} {2} crafted by {3}", "exceptional", resource, name, ba.Crafter.Name);
                        else
                            name = string.Format("{0} {1} crafted by {2}", "exceptional", name, ba.Crafter.Name);
                    }
                    else
                    {
                        if (ba.Resource != CraftResource.Iron)
                            name = string.Format("{0} {1} crafted by {2}", resource, name, ba.Crafter.Name);
                        else
                            name = string.Format("{0} crafted by {1}", name, ba.Crafter.Name);
                    }
                }
                else if (ba.Resource != CraftResource.Iron)
                    name = string.Format("{0} {1}", resource, name); ;

            }

            //TODO: Add durability display?

            return name.ToLower();
        }

        public static string ComputeName(BaseWeapon bw)
        {
            string name = "";

            if (bw.Name == null)
                name = ClilocTranslator.GetString(bw.LabelNumber);
            else
                name = bw.Name;

            string resource = "";

            //Add spaces to the resources that needs it.
            switch (bw.Resource)
            {
                case CraftResource.DullCopper:
                    {
                        resource = "dull copper";
                        break;
                    }
                default:
                    {
                        resource = bw.Resource.ToString();
                        break;
                    }
            }

            if ((bw.DamageLevel != WeaponDamageLevel.Regular || bw.AccuracyLevel != WeaponAccuracyLevel.Regular) && bw.Resource == CraftResource.Iron)
            {//If the weapon is accurate or magical
                if (bw.DamageLevel != WeaponDamageLevel.Regular && bw.AccuracyLevel != WeaponAccuracyLevel.Regular)
                    name = string.Format("{0} {1} of {2}", ClilocTranslator.GetString((1038010 + (int)bw.AccuracyLevel)), name, ClilocTranslator.GetString((1038015 + (int)bw.DamageLevel)));
                else if (bw.AccuracyLevel != WeaponAccuracyLevel.Regular)
                    name = string.Format("{0} {1}", ClilocTranslator.GetString((1038010 + (int)bw.AccuracyLevel)), name);
                else
                    name = string.Format("{0} of {1}", name, ClilocTranslator.GetString((1038015 + (int)bw.DamageLevel)));
            }
            else if (bw.Resource != CraftResource.None)
            {//If it's crafted by a player
                if (bw.Crafter != null)
                {
                    if (bw.Quality == WeaponQuality.Exceptional)
                    {

                        if (bw.Resource != CraftResource.Iron)
                            name = string.Format("{0} {1} {2} crafted by {3}", "exceptional", resource, name, bw.Crafter.Name);
                        else
                            name = string.Format("{0} {1} crafted by {2}", "exceptional", name, bw.Crafter.Name);
                    }
                    else
                    {
                        if (bw.Resource != CraftResource.Iron)
                            name = string.Format("{0} {1} crafted by {2}", resource, name, bw.Crafter.Name);
                        else
                            name = string.Format("{0} crafted by {1}", name, bw.Crafter.Name);
                    }
                }
                else if (bw.Resource != CraftResource.Iron)
                    name = string.Format("{0} {1}", resource, name);
            }


            //TODO: Add durability display?

            return name.ToLower();
        }

        public static string ComputeName(BaseClothing bc)
        {
            string name = "";

            if (bc.Name == null)
                name = ClilocTranslator.GetString(bc.LabelNumber);
            else
                name = bc.Name;

            string resource = "";

            //Add spaces to the resources that needs it.
            switch (bc.Resource)
            {
                default:
                    {
                        resource = bc.Resource.ToString();
                        break;
                    }
            }

            if (bc.Crafter != null)
            {
                if (bc.Quality == ClothingQuality.Exceptional)
                {
                    if (bc.Resource != CraftResource.None)
                        name = string.Format("{0} {1} {2} crafted by {3}", "exceptional", resource, name, bc.Crafter.Name);
                    else
                        name = string.Format("{0} {1} crafted by {2}", "exceptional", name, bc.Crafter.Name);
                }
                else
                {
                    if (bc.Resource != CraftResource.None)
                        name = string.Format("{0} {1} crafted by {2}", resource, name, bc.Crafter.Name);
                    else
                        name = string.Format("{0} crafted by {1}", name, bc.Crafter.Name);
                }
            }
            else if (bc.Resource != CraftResource.None)
                name = string.Format("{0} {1}", resource, name);

            //TODO: Add durability display?

            return name.ToLower();

        }

        public static string GenericComputeName(Item i)
        {
            string name = "";

            if (i.Name == null)
                name = ClilocTranslator.GetString(i.LabelNumber);
            else
                name = i.Name;

            return name.ToLower();
        }

        public static bool CanUse(Mobile from, Item toUse)
        {
            if (from.Frozen)
                from.SendAsciiMessage("You are frozen and you cannot do that.");
            else if (!toUse.Movable)
                from.SendAsciiMessage("You are frozen and you cannot do that.");
            else if (!toUse.IsChildOf(from.Backpack) && toUse.Parent != from && !from.InRange(toUse.Location, 4))
                from.SendAsciiMessage("You can't reach that.");
            else if (!from.InLOS(toUse))
                from.SendAsciiMessage("You can't see that.");
            else
                return toUse.CanEquip(from);

            return false;
        }

        public static bool EquipOnDouble(Mobile from, Item toEquip)
        {
            Item toDrop;

            //Can we use it?
            if (!CanUse(from, toEquip))
                return false;

            //Turn towards the item.
            if (toEquip.Parent == null)
                SpellHelper.Turn(from, toEquip);

            //Is the item equiped already?
            if (from.FindItemOnLayer(toEquip.Layer) == toEquip)
                return true;

            if (toEquip.Layer == Layer.TwoHanded)
            {
                //Always drop the 2 handed item, if it exists.
                toDrop = from.FindItemOnLayer(Layer.TwoHanded);
                if (toDrop != null)
                {
                    from.SendAsciiMessage(string.Format(dropStringFormat, ComputeName(toDrop)));
                    from.AddToBackpack(toDrop);
                }

                //All non sheild 2handed need all the hand players.
                if (!(toEquip is BaseArmor))
                {
                    toDrop = from.FindItemOnLayer(Layer.FirstValid);
                    if (toDrop != null)
                    {
                        from.SendAsciiMessage(string.Format(dropStringFormat, ComputeName(toDrop)));
                        from.AddToBackpack(toDrop);
                    }

                    toDrop = from.FindItemOnLayer(Layer.OneHanded);
                    if (toDrop != null)
                    {
                        from.SendAsciiMessage(string.Format(dropStringFormat, ComputeName(toDrop)));
                        from.AddToBackpack(toDrop);
                    }
                }

                from.EquipItem(toEquip);
                from.PlaySound(0x57);
            }
            else if (toEquip.Layer == Layer.OneHanded)
            {
                //All non shield 2 hands use both hands.
                toDrop = from.FindItemOnLayer(Layer.TwoHanded);
                if (!(toDrop is BaseArmor))
                {
                    from.SendAsciiMessage(string.Format(dropStringFormat, ComputeName(toDrop)));
                    from.AddToBackpack(toDrop);
                }

                //Drop first valid.
                toDrop = from.FindItemOnLayer(Layer.FirstValid);
                if (toDrop != null)
                {
                    from.SendAsciiMessage(string.Format(dropStringFormat, ComputeName(toDrop)));
                    from.AddToBackpack(toDrop);
                }

                //Drop onehand.
                toDrop = from.FindItemOnLayer(Layer.OneHanded);
                if (toDrop != null)
                {
                    from.SendAsciiMessage(string.Format(dropStringFormat, ComputeName(toDrop)));
                    from.AddToBackpack(toDrop);
                }

                from.EquipItem(toEquip);
                from.PlaySound(0x57);
            }
            else if ( toEquip.Layer == Layer.FirstValid)
            {
                //Drop first valid.
                toDrop = from.FindItemOnLayer(Layer.FirstValid);
                if (toDrop != null)
                {
                    from.SendAsciiMessage(string.Format(dropStringFormat, ComputeName(toDrop)));
                    from.AddToBackpack(toDrop);
                }

                //Drop onehand.
                toDrop = from.FindItemOnLayer(Layer.OneHanded);
                if (toDrop != null)
                {
                    from.SendAsciiMessage(string.Format(dropStringFormat, ComputeName(toDrop)));
                    from.AddToBackpack(toDrop);
                }

                from.EquipItem(toEquip);
                from.PlaySound(0x57);
            }
            return true;
        }
    }
}