Server.Items.CraftResources.GetType C# (CSharp) Méthode

GetType() public static méthode

Returns a CraftResourceType value indiciating the type of 'resource'.
public static GetType ( CraftResource resource ) : CraftResourceType
resource CraftResource
Résultat CraftResourceType
		public static CraftResourceType GetType( CraftResource resource )
		{
			if ( resource >= CraftResource.Iron && resource <= CraftResource.Valorite )
				return CraftResourceType.Metal;

			if ( resource >= CraftResource.RegularLeather && resource <= CraftResource.BarbedLeather )
				return CraftResourceType.Leather;

			if ( resource >= CraftResource.RedScales && resource <= CraftResource.BlueScales )
				return CraftResourceType.Scales;

			if ( resource >= CraftResource.RegularWood && resource <= CraftResource.Frostwood )
				return CraftResourceType.Wood;

			return CraftResourceType.None;
		}

Usage Example

Exemple #1
0
        private bool Resmelt(Mobile from, Item item, CraftResource resource)
        {
            try
            {
                if (CraftResources.GetType(resource) != CraftResourceType.Metal)
                {
                    return(false);
                }

                CraftResourceInfo info = CraftResources.GetInfo(resource);

                if (info == null || info.ResourceTypes.Length == 0)
                {
                    return(false);
                }

                CraftItem craftItem = DefBlacksmithy.CraftSystem.CraftItems.SearchFor(item.GetType());

                if (craftItem == null || craftItem.Resources.Count == 0)
                {
                    return(false);
                }

                CraftRes craftResource = craftItem.Resources.GetAt(0);

                if (craftResource.Amount < 2)
                {
                    return(false); // Not enough metal to resmelt
                }
                var difficulty = resource switch
                {
                    CraftResource.DullCopper => 65.0,
                    CraftResource.ShadowIron => 70.0,
                    CraftResource.Copper => 75.0,
                    CraftResource.Bronze => 80.0,
                    CraftResource.Gold => 85.0,
                    CraftResource.Agapite => 90.0,
                    CraftResource.Verite => 95.0,
                    CraftResource.Valorite => 99.0,
                    _ => 0.0
                };

                Type resourceType = info.ResourceTypes[0];
                Item ingot        = (Item)Activator.CreateInstance(resourceType);

                if (item is DragonBardingDeed || item is BaseArmor armor && armor.PlayerConstructed ||
                    item is BaseWeapon weapon && weapon.PlayerConstructed ||
                    item is BaseClothing clothing && clothing.PlayerConstructed)
                {
                    double mining = from.Skills.Mining.Value;
                    if (mining > 100.0)
                    {
                        mining = 100.0;
                    }
                    double amount = ((4 + mining) * craftResource.Amount - 4) * 0.0068;
                    if (amount < 2)
                    {
                        ingot.Amount = 2;
                    }
                    else
                    {
                        ingot.Amount = (int)amount;
                    }
                }
                else
                {
                    ingot.Amount = 2;
                }

                if (difficulty > from.Skills.Mining.Value)
                {
                    m_Failure = true;
                    ingot.Delete();
                }
                else
                {
                    item.Delete();
                }

                from.AddToBackpack(ingot);

                from.PlaySound(0x2A);
                from.PlaySound(0x240);

                return(true);
            }
All Usage Examples Of Server.Items.CraftResources::GetType